Hi I've been trying to write a simple hello world program in assembly and compile it into a .o file, then link it with the standard C library to create a .exe so that I can view the disassembly for 'puts' on my system using gdb -tui
. I am using Cygwin with the following utility versions (got these with as --version && ld --version
). I am trying to do all this on Windows 8 x64.
as version 2.25
ld version 2.25
test.asm
I've seen several assembly standards on the internet while learning x86 assembly. I think the one I am writing here is GAS.
.extern puts
_start:
mov $msg, %rdi
call puts
xor %rax, %rax
ret
msg:
.ascii "hello world"
assembler
I can assemble the above file no problem, the as
utility doesn't give me a warning or any errors, here is the way I call the as
utility.
as test.asm -o test.o
linker
Here is where I am having trouble, the following command is how I think I should link the object file with the standard c library.
ld test.o -o test.exe -lc
This command produces the following errors, which I've been stumped by. I've tried to find the answer in other posts and through google, but maybe I'm missing something.
test.o:fake:(.text+0x3): relocation truncated to fit: R_X86_64_32S against `.text`
/usr/lib/libc.a(t-d000957.o):fake:(.text+0x2): undefined reference to `__imp_puts`
/usr/lib/libc.a(t-d000957.o):fake:(.text+0x2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_puts`