Assembly multiple definition -
giving code
section .data msg db "hello, world!",0xa len equ $ - msg section .text ;we must export entry point elf linker or global _start _start: mov eax,4 mov ebx,1 mov ecx,msg mov edx,len int 0x80 mov eax,1 xor ebx,ebx int 0x80
when try run it, shows command
linux1[8]% nasm -f elf -l hello.lst hello.asm linux1[9]% ls hello.asm hello.lst hello.o linux1[10]% gcc -o hello hello.o hello.o: in function `_start': hello.asm:(.text+0x0): multiple definition of `_start' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o:(.text+0x0): first defined here hello.o: not read symbols: file in wrong format collect2: ld returned 1 exit status
how fix multiple definition problem? define _start once, how comes out said multiple definition? thanks
you using gcc
link , default add c libraries expect entry point main
, contain _start
invokes main
. that's why have multiple definition.
if not need c library (and in code doesn't), still use gcc linking, try gcc -nostdlib -m32 -o hello hello.o
.
the wrong format
error due trying produce 64 bit executable 32 bit object file. adding -m32
fixes 32 bit executable (since code 32 bit). if intend create 64 bit program, use -f elf64
nasm
, of course write 64 bit compatible code.
Comments
Post a Comment