compiler-explorer icon indicating copy to clipboard operation
compiler-explorer copied to clipboard

[BUG]: nasm addressing issue with 64 bit mode

Open Tease1234 opened this issue 1 year ago • 4 comments

Describe the bug

When writing 64 bit nasm, storing an address with the .rodata or .data sections, causes a "warning: 64-bit unsigned relocation zero-extended from 32 bits [-w+zext-reloc]".

Steps to reproduce

  1. Goto godbolt.org
  2. Switch language to Assembly
  3. Open nasm compiler(any should work)
  4. Type:" BITS 64 _start: ret section .data label: dq _start " into the file
  5. Assemble

Expected behavior

The aforementioned error shouldn't be there(I think its because the compile option is set to elf, not elf64).

Reproduction link

https://godbolt.org/z/xWjW35fEE

Screenshots

Not applicable/needed

Operating System

Not applicable/needed

Browser version

Not applicable/needed

Tease1234 avatar Nov 14 '25 19:11 Tease1234

I think the best fix is to either switch the default from elf to elf64, or to give the user knowledge that they can change from elf to elf64 manually like in "https://godbolt.org/z/3M1GoecsT" because I had to look at the nasm.ts file to find this.

Tease1234 avatar Nov 15 '25 21:11 Tease1234

32 bits is just the default for the nasm assembler itself, we don't explicitly set it. And there's not much we can do about it

partouf avatar Nov 17 '25 12:11 partouf

We could switch the default(to prevent the issue entirely because 64 bit elf can work in 32 and 16 bit modes) to 64 bits by switching "options = ['-g', '-f', 'elf', '-F', 'stabs'].concat(options);" in nasm.ts(line 68) to "options = ['-g', '-f', 'elf64', '-F', 'stabs'].concat(options);"

Tease1234 avatar Nov 19 '25 17:11 Tease1234

This is now live

compiler-explorer-bot avatar Feb 28 '26 15:02 compiler-explorer-bot