Wilfred/babyc

ld -s -o out out.o error

Opened this issue · 2 comments

ld -s -o out out.ocreates these warnings:


ld: warning: option -s is obsolete and being ignored
ld: warning: -macosx_version_min not specified, assuming 10.10
ld: warning: object file (out.o) was built for newer OSX version (10.11) than being linked (10.10)
Undefined symbols for architecture x86_64:
  "start", referenced from:
     implicit entry/start for main executable
     (maybe you meant: _start)
ld: symbol(s) not found for inferred architecture x86_64

Warnings aren't inherently bad, but the next step: ./out fails with ./out: No such file or directory

out.s:


.text
    .global _start

_start:
    movl    $0, %ebx
    movl    $1, %eax
    int     $0x80

The compiler emits 32-bit code (i386), not code for x86-64 . You must be explicit on the type of generated format.

$ as --32 -g -o out.o out.s
$ ld -m elf_i386 -e _start -g -o a.out out.o
$ file ./a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped