16-bit linking under linux
Pergunta
I'm using NASM Assembler under linux when I use the command "nasm -f elf -l hello.lst hello.asm" it works fine but when linking with gcc "gcc -o hello hello.o" it generates an error :
hello.asm:(.text+0x4): relocation truncated to fit: R_386_16 against `.data' collect2: ld returned 1 exit status
I learned that this is some problem with gcc and 16-bit
any solutions ?
Solução
Linux doesn't even have a 16-bit subsystem - even if you got gcc to link it, you still couldn't execute it! Why don't you just use .bits 32
?
Outras dicas
I faced the same situation a few years ago and again this year.
Two ways to deal with it are:
- Write your own 16-bit friendly linker (you need to parse .rel.text section at least).
- Use a base symbol (or symbols) to calculate the absolute addresses manually (the .rel sections are still created, but can be removed). However, this method is very error prone.
I always end up doing 2, but I should probably make time to write a linker (or patching GNU ld...).
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow