openssl and coreutils and more

Robert Connolly robert at linuxfromscratch.org
Tue Dec 5 10:31:06 PST 2006


$ cat true-i386.S
/* Public Domain - i386 true.S */
.global _start
_start:
movl    $0,%ebx
movl    $1,%eax
int     $0x80

$ cat false-i386.S
/* Public Domain - i386 false.S */
.global _start
_start:
movl    $1,%ebx
movl    $1,%eax
int     $0x80

$ cat nologin-i386.S
/* Public Domain - i386 nologin.S */
.section .data
message:
   .ascii "This account is not available.\n"
   len = . - message
.section .text
.globl _start
_start:
   movl $4, %eax
   movl $len, %edx
   movl $message, %ecx
   movl $1, %ebx /* Use "$2" to write to stderr, "$1" for stdout */
   int $0x80
   movl $1, %eax
   movl $1, %ebx
   int $0x80

$ as -o true-i386.o true-i386.S && ld -o true-i386 true-i386.o
$ as -o false-i386.o false-i386.S && ld -o false-i386 false-i386.o
$ as -o nologin-i386.o nologin-i386.S && ld -o nologin-i386 nologin-i386.o
$ ./true-i386 ; echo $?
0
$ ./false-i386 ; echo $?
1
$ ./nologin-i386 ; echo $?
This account is not available.
1
$ bfbtester -d 2 -a nologin-i386 true-i386 false-i386
=> /home/ashes/temp/assembly/false-i386
   * Single argument testing
   * Multiple arguments testing
   * Environment variable testing
=> /home/ashes/temp/assembly/true-i386
   * Single argument testing
   * Multiple arguments testing
   * Environment variable testing
=> /home/ashes/temp/assembly/nologin-i386
   * Single argument testing
   * Multiple arguments testing
   * Environment variable testing
Cleaning up...might take a few seconds

I also "time { ; }"'d these. The assembly versions took 21 seconds. The C 
versions took 32 seconds. The libc overhead performs over 30% worse.

I'm guessing stdout is used for nologin because its not an error, it's 
expected behavior. But stderr works perfectly well too.

I couldn't find a hello.S that writes to syslog. It would be highly OS 
specific. Maybe a C program can be disassembled to figure something out.

I'd like a page in the appendix, or somewhere, with variations to these 
programs, like for non-i386 and syslog. The true-i386 program takes 0m0.001s 
to execute, so an SSE3 version would just be silly. Using C programs doesn't 
offer any serious advantage to the Coreutils version because of libc. Linking 
statically helps, but using assembly is far better.

robert

On Tuesday 05 December 2006 11:43, Osor Hirutonis wrote:
> A few suggestions:
> 1.) You don’t need the null byte at the end of message (because the last
>     argument of write() is how many bytes to be written — it doesn’t
>     care about null-terminated strings).
> 2.) Though it might increase the size a smidgen, you might not want to
>     hardcode the string size into the program (instead, add a symbol
>     len that is the length of the string. E.g.,
>
> message:
>     .ascii "This account is currently not available.\n"
>     len = . - message
>
>     And then use $len in place of $42.
> 3.) You are writing an error message to stdout. Why not change that to
>     stderr (I do know everyone else also writes to stdout, but why?)?
> 4.) The “real” nologin (from shadow) will write to syslog. That’s
>     helpful (at least to me) from a sysadmin standpoint.
>
> P.S.
> Just for fun, here’s one for x86-64 assembler:
>
> .section .data
> message:
>    .ascii "This account is currently not available.\n"
>    len = . - message
> .section .text
> .globl _start
> _start:
>    movq $len, %rdx
>    movq $message, %rsi
> #  movq $2, %rdi
>    movq $1, %rdi
>    movq $1, %rax
>    syscall
>
>    movq $1, %rdi
>    movq $60,%rax
>    syscall
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.linuxfromscratch.org/pipermail/hlfs-dev/attachments/20061205/0a9d352e/attachment.sig>


More information about the hlfs-dev mailing list