64位Mac OS X Lion上的nasm / gcc问题 [英] nasm/gcc issue on 64-bit Mac OS X Lion

查看:479
本文介绍了64位Mac OS X Lion上的nasm / gcc问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读这篇文章,
和有一次,它给了我这个nasm程序:

 ; tiny.asm 
BITS 32
GLOBAL main
SECTION .text
main:
mov eax,42
ret

并告诉我运行以下命令:

  $ nasm -f elf tiny.asm 
$ gcc -Wall -s tiny.o



  ld:warning:选项-s已过时且被忽略
ld :警告:忽略文件tiny.o,文件是为不支持的文件格式构建的,而不是被链接的架构(x86_64)
架构x86_64的未定义符号:
_main,引用来自:
从crt1.10.6.o开始
ld:找不到架构x86_64的符号
collect2:ld返回1退出状态

我冒险猜测可能存在的问题,并将BITS行更改为:

  BITS 64 

但是当我运行 nasm - flf tiny.asm 我得到:

  tiny.asm:2:错误:`64'不是有效的段大小;必须是16或32 

如何修改代码以在我的机器上工作?



编辑:



我从评论中拿出了Alex的建议并下载了一个更新的版本。但是,

  ./ nasm-2.09.10 / nasm -f elf tiny.asm 


$ b :错误:elf32输出格式不支持64位代码

另一方面,

  ./ nasm-2.09.10 / nasm -f elf64 tiny.asm 
gcc -Wall -s tiny.o

抱怨

  ld:warning:忽略文件tiny.o,文件是针对不支持的文件格式构建的,而不是被链接的架构(x86_64)
架构x86_64的未定义符号:
_main,引用来自:
开始于crt1.10.6.o
ld:架构x86_64未找到符号
collect2:ld返回1退出状态

解决方案

为了让您的示例正常工作,您必须对OS X进行特定的调整:
主要方法由OS X链接器预置了一个_:

 ; tiny.asm 
BITS 32
GLOBAL _main
SECTION .text
_main:
mov eax,42
ret

第二个是你必须使用mach文件格式:

  nasm -f macho tiny.asm 

现在您可以将其链接-m32表示一个32位的目标文件):

  gcc -m32 tiny.o 


I was reading this article, and at one point it gives me this nasm program:

; tiny.asm
BITS 32
GLOBAL main
SECTION .text
main:
              mov     eax, 42
              ret

And tells me to run the following commands:

$ nasm -f elf tiny.asm
$ gcc -Wall -s tiny.o

I got the following error:

ld: warning: option -s is obsolete and being ignored
ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I ventured a guess at what might be the problem, and changed the BITS line to read:

 BITS 64

But then when I run nasm -f elf tiny.asm I get:

tiny.asm:2: error: `64' is not a valid segment size; must be 16 or 32

How do I modify the code to work on my machine?

Edit:

I took Alex's advice from the comments and downloaded a newer version. However,

./nasm-2.09.10/nasm -f elf tiny.asm

complains

tiny.asm:2: error: elf32 output format does not support 64-bit code

On the other hand,

./nasm-2.09.10/nasm -f elf64 tiny.asm
gcc -Wall -s tiny.o

complains

ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

解决方案

There are OS X-specific adjustments you have to make in order for your example to work: The main method is prepended with a _ by the OS X linker:

; tiny.asm
BITS 32
GLOBAL _main
SECTION .text
_main:
    mov     eax, 42
    ret

The second is that you have to use the mach file format:

nasm -f macho tiny.asm

Now you can link it (using -m32 to indicate a 32 bit object file):

gcc -m32 tiny.o

这篇关于64位Mac OS X Lion上的nasm / gcc问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆