Author Topic: x64 help needed!  (Read 8073 times)

Offline nasmman123

  • Jr. Member
  • *
  • Posts: 4
x64 help needed!
« on: October 14, 2013, 12:55:03 AM »
I am writing a compiler that outputs for NASM.  I have the compiler working for 32-bit windows and linux, I have 64-bit linux working and I am trying to get 64-bit windows working.

I have an issue with linking, it's a warning but I want to fix it and not ignore it.  For some reason, even though I have default rel in both files (also tried default abs), the label is incorrectly refered to as a 32-bit address (waning below)

java.lang.Object.obj : error LNK2017: 'ADDR32' relocation to 'int__array@SIT' invalid without /LARGEADDRESSAWARE:NO

file 1

default rel
bits 64
section .data
global int__array@SIT
int__array@SIT:

file 2:
default rel
bits 64
.text
...
extern int__array@SIT
mov qword [rax], int__array@SIT
...
In the nasm manual, it does not seem like this should be the case. (http://www.nasm.us/doc/nasmdo11.html) section 11.2

"mov rax,foo             ; 64-bit immediate" why is int__array@SIT not 64 bit?  I have tried adding qword in front but there was no change.

Any help would be greatly appreciated.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: x64 help needed!
« Reply #1 on: October 14, 2013, 02:03:06 AM »
Interesting. FWIW, I assembled your files as "-f elf64", and ld linked 'em without a peep (had to add a "_start" label). I have no idea what that's about. Any 64-bit gurus in earshot?

Best,
Frank


Offline nasmman123

  • Jr. Member
  • *
  • Posts: 4
Re: x64 help needed!
« Reply #2 on: October 14, 2013, 03:35:45 AM »
Thank you for your quick response, I have not tried linking with ld, I am using link.  It's a warning that I don't think ld gives because ld did not give  it when I compiled x64 linux code and it should be the same for that.  Link is much more sensitive to warnings and errors (which I think is good usually warnings are a good sign), for example if you exten something that does not exist, even if you don't use it, it won't  link.  I used the entry point as main in my compilation because that's more standard for windows.  I would also bet that the program will work as expected if the address is between the range of -2GB to 2GB away (in my cases it should be, but I don't want that to be a limitation and I want to be more technically correct in my assembly).

Interesting. FWIW, I assembled your files as "-f elf64", and ld linked 'em without a peep (had to add a "_start" label). I have no idea what that's about. Any 64-bit gurus in earshot?

Best,
Frank

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: x64 help needed!
« Reply #3 on: October 14, 2013, 03:17:37 PM »
extern int__array@SIT
mov qword [rax], int__array@SIT

If I recall correctly in x64 you cannot move an immediate 64-bit value directly to memory.
What does changing the above to the following give you:

Code: [Select]
mov rdx, int__array@SIT
mov qword [rax], rdx