In the context of a compiler construction project, I used to be able to compile "ia32" code like this before:
$ gcc -m32 -ofoo foo.s
with foo.s looking like:
.file "tiger-runtime.c"
.text
.globl tc_init_array
.type tc_init_array, @function
tc_init_array:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $40, %esp
movl 8(%ebp), %eax
sall $2, %eax
movl %eax, (%esp)
call malloc
movl %eax, -16(%ebp)
movl $0, -12(%ebp)
jmp .L2
Now that I moved to Yosemite and the latest version of Xcode, I get:
$ gcc-mp-5 -m32 -oadd-ia32 add-ia32.s
tiger-runtime.c:4:Unknown pseudo-op: .type
tiger-runtime.c:4:Rest of line ignored. 1st junk character valued 116 (t).
tiger-runtime.c:7:Unknown pseudo-op: .cfi_startproc
tiger-runtime.c:9:Unknown pseudo-op: .cfi_def_cfa_offset
tiger-runtime.c:9:Rest of line ignored. 1st junk character valued 56 (8).
tiger-runtime.c:10:Unknown pseudo-op: .cfi_offset
tiger-runtime.c:10:Rest of line ignored. 1st junk character valued 53 (5).
tiger-runtime.c:12:Unknown pseudo-op: .cfi_def_cfa_register
and more errors like this. This question has been asked many times, but none of the answers I've seen so far work on Yosemite (e.g., mac OSX Unknown pseudo-op: .type, I'm learning x86 assembly on OS X 10.6, how do I compile?). In particular, even if I use GCC (say GCC 5 via MacPorts) as a compiler driver, it appears to use /usr/bin/as
, not its own assembler.
I have installed several versions of GCC/Clang/Binutils (via MacPorts) to try to find the right assembly, but without success. At best, I get:
$ /opt/local/i386-elf/bin/as add-ia32.s -o add-ia32.o
$ /opt/local/i386-elf/bin/ld add-ia32.o -o add-ia32
/opt/local/i386-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 00000000
add-ia32.o: In function `tc_init_array':
tiger-runtime.c:(.text+0x10): undefined reference to `malloc'
add-ia32.o: In function `tc_malloc':
tiger-runtime.c:(.text+0x54): undefined reference to `malloc'
tiger-runtime.c:(.text+0x68): undefined reference to `stderr'
tiger-runtime.c:(.text+0x88): undefined reference to `fwrite'
tiger-runtime.c:(.text+0x94): undefined reference to `exit'
I guess I'm not too far from completion, yet the convention for the main function seems to differ, and it doesn't find the libc (-lc
does not help).
A full version of the assembly file that used to work properly is available here: http://pastebin.com/Xq8DTmf6. Thanks in advance.