0

I get an error in my code when I try the linking of my program. What does this mean and how do I fix it? I can compile using nasm just fine. It only happens when I attempt to link the file

progr.o: In function '_start' : progr.asm: (.text+0xb) : relocation truncated to fit: R_386_16 against '.data'

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
lazDoe
  • 1
  • This suggests you created a NASM file that had 16 bit code `bits 16` directive in it and that you linked to produce objects greater than 16-bit (probably 32-bit). This suggests that when the origin point was applied by the linker to resolve relocations that an address greater than 0xffff was generated. Any address over 0xffff won't fit in 16-bits and will be truncated (this your linker error). Are you writing a bootloader? To resolve we'd have to see your code, how you assemble it, and how you link it. – Michael Petch Mar 06 '17 at 04:58
  • Please show us the code that generates this error. – fuz Mar 06 '17 at 08:32
  • It means you link for different target platform then the source was compiled for. How to fix it... first make sure your source is valid for your target platform, then make sure you compile with nasm into your target platform type of object file (nasm supports all common x86 targets), and finally fix the target platform for linker (and use appropriate linker). If this is some "OS from scratch", reread some tutorial with examples and note how they prepare the binary boot sector, it's usually a bit more complex involving often binary ROM-like output instead of object files, skipping linking. – Ped7g Mar 06 '17 at 14:10
  • 1
    @Ped7g : If you set up your code a specific way and know what you are doing you can debug a bootloader in _QEMU_ through remote _GDB_. Unfortunately outputting binary output as BIN means you miss out on symbolic debugging in _GDB_. In that case I generate an object file with _NASM_ then link to an ELF32 executable and convert the ELF executable to binary. You can then use the ELF executable in GDB for symbolic debugging and the binary file to run in the emulator. – Michael Petch Mar 06 '17 at 14:45
  • I do something like that in this [Stackoverflow answer](http://stackoverflow.com/a/32960272/3857942) – Michael Petch Mar 06 '17 at 14:45

0 Answers0