Many thanks! Yes, a static binary is perfectly fine at this time :) A
couple of follow-up questions, if y'all would please indulge me:

1. Now that I am reminded of this handy new `readelf` tool, I go
running it on the new static executable I just generated.

```
$ cat exit.s  # repeating for your convenience
# 
https://web.archive.org/web/20120509101207/http://lucifer.phiral.net/openbsdasm.htm
.section ".note.openbsd.ident", "a"
  .p2align 2
  .long   0x8
  .long   0x4
  .long   0x1
  .ascii "OpenBSD\0"
  .long   0x
  .p2align 2

.section .text
.globl _start
_start:
  xorl %eax, %eax
  pushl %eax  # exit status
  pushl %eax  # extra long for C ABI
  movl $1, %eax  # exit syscall
  int $0x80
$ as exit.s -o exit.o
$ ld exit.o -static -o exit
$ ./exit
$ echo $?
0  # success!
$ readelf -l ./exit
Elf file type is DYN (Shared object file)
...
```

Why is the file type showing up as a shared object file in spite of it
being a statically compiled binary?

2. I tried running the above file in a 64-bit OpenBSD, and got a
couple of reasonable looking errors:

```
$ uname -a
OpenBSD x.my.domain 5.9 GENERIC#1761 amd64
$ as exit.s -o exit.o
exit.s: Assembler messages:
exit.s:17: Error: suffix or operands invalid for `push'
exit.s:18: Error: suffix or operands invalid for `push'
```

In response I tried some ham-handed modifications, basically replacing
the registers with 64-bit variants, and letting the assembler figure
out operand-size suffixes.

```
$ cat exit64.s
.section ".note.openbsd.ident", "a"
  .p2align 2
  .long   0x8
  .long   0x4
  .long   0x1
  .ascii "OpenBSD\0"
  .long   0x
  .p2align 2

.section .text
.globl _start
_start:
  xor %rax, %rax
  push %rax  # exit status
  push %rax  # extra long for C ABI
  mov $1, %rax  # exit syscall
  int $0x80
```

Could you please point me at why this fails?

```
$ as exit64.s -o exit64.o
$ ld exit64.o -static -o exit64
$ ./exit64
zsh: bus error (core dumped)  ./exit64
```

Reply via email to