Nasm / gcc for 64-bit Mac OS X Lion

I read this article , and at some point he 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 decided to guess what might be the problem, and changed the BITS line as follows:

  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 change the code to work on my machine?

Edit:

I took Alex's advice from the comments and uploaded a newer version. Nonetheless,

 ./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 
+6
source share
2 answers

To configure your application, specific OS X settings are required: The main method is added by the OS X builder:

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

Secondly, you should use the mach file format:

 nasm -f macho tiny.asm 

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

 gcc -m32 tiny.o 
+13
source

It seems you are still using the 32 bit version. If you are nasm -hf , it must specify macho64 . If not, you will need to update it again.

You can try the brew update console. If this performs an update, then brew search nasm , where nasm should appear. Then just brew install nasm . This should install nasm on your computer. Be sure to look at the place where it was installed. The mine was installed on /usr/local/cellar/nasm/2.11.02/bin/ . Then, by typing nasm -hf , it should display a list of the available formats that you should see macho64 .

+2
source

Source: https://habr.com/ru/post/908599/


All Articles