Hello, I have some errors then linking with ld:
I am writing a simple 16-bit real-mode demo code to print some char on screen, and assemble with nasm:
[org 0x7c00]
mov ah, 0x0e
mov al, "1"
int 0x10
mov al, the_secret ; just want to demo a wrong usage
int 0x10
mov al, "2"
int 0x10
mov al, [the_secret] ; correct usage
int 0x10
jmp $ ; infinite loop
the_secret:
db "X"
times 510-($-$$) db 0
dw 0xaa55
I use nasm -f bin bootsect.asm -o bootsect.bin
, and it's ok
Then I tried to use gdb to trace the code, so I tried following:
I removed first line [org 0x7c00]
due to nasm will report "error: unrecognised directive [org]"
So I use ld to assign the load address with "-Ttext=0x7c00", following are my commands:
$ nasm bootsect.asm -f elf -g -F dwarf -o bootsect.o
$ i386-elf-ld -Ttext=0x7c00 bootsect.o -o bootsect.elf
But ld reports error:
bootsect.o:bootsect.asm:6:(.text+0x7): relocation truncated to fit: R_386_8 against `.text'
Checked code and I see this code line causes the problem
mov al, the_secret
I know it is not good writing, but I would have to keep this code due to I just want to write a demo and I know it could pass build with "nasm -f bin". So my question is how to pass building with ld so I can use gdb to trace this demo? Thanks in adv.