문제

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 ?

도움이 되었습니까?

해결책

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?

다른 팁

I faced the same situation a few years ago and again this year.

Two ways to deal with it are:

  1. Write your own 16-bit friendly linker (you need to parse .rel.text section at least).
  2. 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...).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top