Gcc 在OS X Yosemite上编译类ELF程序集

Gcc 在OS X Yosemite上编译类ELF程序集,gcc,assembly,compilation,osx-yosemite,Gcc,Assembly,Compilation,Osx Yosemite,在编译器构建项目的上下文中,我以前能够编译“ia32”代码,如下所示: $ gcc -m32 -ofoo foo.s 在foo.s看来: .file "tiger-runtime.c" .text .globl tc_init_array .type tc_init_array, @function tc_init_array: .LFB0: .cfi_startproc pushl

在编译器构建项目的上下文中,我以前能够编译“ia32”代码,如下所示:

$ gcc -m32 -ofoo foo.s
在foo.s看来:

        .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
现在我搬到了约塞米蒂和最新版本的Xcode,我得到了:

$ 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
还有更多这样的错误。这个问题已经被问过很多次了,但到目前为止,我所看到的答案都不适用于约塞米蒂(例如,)。特别是,即使我使用GCC(比如通过MacPorts使用gcc5)作为编译器驱动程序,它似乎使用
/usr/bin/as
,而不是它自己的汇编程序

我已经安装了几个版本的GCC/Clang/Binutils(通过MacPorts)来尝试找到正确的程序集,但没有成功。充其量,我得到:

$ /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'
我想我离完成还不太远,但是主函数的约定似乎有所不同,并且它没有找到libc(
-lc
没有帮助)


此处提供了用于正常工作的程序集文件的完整版本:。提前谢谢。

您可能需要
气体
?MacPorts似乎没有提供气体。事实上,这就是为什么我试图安装binutils来获取gas,我想我确实获得了gas(
/opt/local/i386 elf/bin/as
)。但这还不够。您可能需要在符号名称上加一个前导下划线。@Jester不,我用
\u malloc
等得到了相同的结果。谢谢!可能重复的