Author Topic: Unable to link nasm compiled object (ELF64) with gcc compiled 64bits objects.  (Read 10033 times)

Offline cedric_caron

  • Jr. Member
  • *
  • Posts: 2

First of all, I would like to apologize if this topic is a duplicate of an existing one.

We are currently using nasm to compile one object to be used in a shared library compiled with gcc. When compiling on a 32bits platform, everything is working fine but now I need to compile this library on a 64bits platform and I can't get the nasm compiled object to link with the gcc compiled objects.

- Ubuntu 11.04 64bits (with kernel 2.6.38-10)
- gcc 4.5.2 (Target: x86_64-linux-gnu)
- nasm 2.09.04
- libtool 2.2.6b
- autoconf 2.67-2

Command line:
compilation: nasm -d OBJ_FORMAT_ELF -f elf64 myobject.nasm -o myobject.o
linking: g++ -shared -nostdlib *.o myobject.o -Wl,-soname -Wl, -o
All the gcc objects are compiled with the -fPIC option

Code: [Select]
extern printf

SEGMENT .data align=16
// Some macro definitions


global myfunction
    //Do whatever needed
When compiling on the 64 bits platform, I get the following error message:
/usr/bin/ld: myobject.o: relocating R_X86_64_32 against '.data' can not be used when making a shared object; recompile with -fPIC
myobject.o: could not read symbols: Bad value

I would appreciate your help for solving this issue.

Thank you.


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Hi Cédric,

Looks like you're not getting an answer to this. I'm not very familiar with PIC in any case, and not familiar at all with 64-bit code, so I may not be much help. I was under the impression that "rip relative" addressing was the default in "-f elf64", but apparently this is not true. So using "default rel" may help(?). See:

Other possibly relevant sections of the manual:

I hope you've discovered a solution to this, and aren't stuck waiting for an answer here! If you can't get it, ask again and I'll pass it along to the developer's list (or do it yourself) - someone must know! It's "supposed to work", AFAIK. Sorry for the delayed reply!


Offline cedric_caron

  • Jr. Member
  • *
  • Posts: 2
Hi Frank,

I ended with the same "solution" by using the "DEFAULT REL". When using "DEFAULT REL", the library can be linked. However, I'm not sure yet that this is fully fonctionnal as I have other issues with the 64bits.

Thank you for your help


Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us

There is a wealth of information for you to digest at