0

I am working on a C++ project which uses a (legacy) static library (let's name it foo.a) which was compiled on an old Intel 32-bit architecture (with gcc-4). I don't have the source code of this library so I can't rebuild it.

Now I have to make a porting of the entire project to an x86-64 linux-based environment with gcc-6.5, and in a first phase I'm trying to compile all with -m32 flag in order to not change anything.

The compilation phase goes well, but during the linking phase I get this warning:

ld: (foo.a)(x.o) relocation of read-only section '.ro-data'

ld: warning: creating a DT_TEXTREL in object.

In any case the executable is created, but in this moment I'm not able to test it (Yes I know, it seems a a disaster announced!).

I read something about the lack of -fPIC flag when foo.a was built and on the fact that on old 32-bit architectures the -fPIC option was unnecessary.

My questions are:

  1. What is DT_TEXTREL? I can't find any documentation on this term, only fragments on manuals.
  2. How can I solve this problem without recompiling foo.a?
  3. In case (question 2) is impossible to achieve, what problems should I expect on final executable by ignoring this warnings?

Thank you!

gior91
  • 1,745
  • 1
  • 16
  • 19
  • 1
    You're going to want `gcc -fno-pie -no-pie` so you can link code build without `-fPIE` into an executable. 32-bit x86 PIE has a large performance penalty, unlike x86-64, because it lacks PC-relative addressing, so you'd probably want to disable PIE code-gen for legacy 32-bit code even if your static library had been build to be PIE-compatible. See [32-bit absolute addresses no longer allowed in x86-64 Linux?](https://stackoverflow.com/q/43367427) for more about PIEs (focusing on 64-bit mode where having a 32-bit absolute address makes linking impossible instead of needing a runtime fixup) – Peter Cordes Apr 22 '20 at 09:31
  • AFAIK, a TEXTREL is a text relocation: a runtime fixup of an absolute address in a section that's normally read-only, like `.text` or `.rodata`. – Peter Cordes Apr 22 '20 at 09:58
  • @PeterCordes I'll try this ASAP – gior91 Apr 22 '20 at 10:32
  • @PeterCordes thank you, problem solved. – gior91 Apr 22 '20 at 16:32

0 Answers0