3

I am trying to compile a piece of cpp code under linux, and got the following error:

/tmp/ccIeh7Ta.o: In function `model::MulPLSA::EStep()':
mul_plsa.cpp:(.text+0xb12): relocation truncated to fit: R_X86_64_32S against symbol `model::MulPLSA::mItemLatRatDeno' defined in .bss section in /tmp/ccIeh7Ta.o
mul_plsa.cpp:(.text+0xb42): relocation truncated to fit: R_X86_64_32S against symbol `model::MulPLSA::mItemLatRatDeno' defined in .bss section in /tmp/ccIeh7Ta.o
/tmp/ccIeh7Ta.o: In function `model::MulPLSA::MStep()':
mul_plsa.cpp:(.text+0xcec): relocation truncated to fit: R_X86_64_32S against symbol `model::MulPLSA::mItemLatRatDeno' defined in .bss section in /tmp/ccIeh7Ta.o
collect2: ld returned 1 exit status

My OS: Ubuntu 10.10
g++: gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)
Anyone has came across this error before? Thanks.

cheng

user572138
  • 463
  • 4
  • 6
  • 13
  • Look at http://amiatypist.blogspot.com/2010/05/relocation-truncated-to-fit-rx866432s.html might be useful... – Ferenc Deak May 20 '11 at 10:33
  • 1
    blogspot is invalid in china. I google this problem and find that adding options -mcmodel=medium when compiling can solve this problem. I did this and the compiler throw out a waring:/tmp/ccG10FOV.s:3107: Warning: ignoring incorrect section type for .lbss. Anyway, it works. – user572138 May 20 '11 at 10:41
  • Please give us a minimal example. Related: http://stackoverflow.com/questions/10486116/what-does-this-gcc-error-relocation-truncated-to-fit-mean – Ciro Santilli OurBigBook.com Sep 03 '15 at 21:24

1 Answers1

1

By default the program is generated in a small code model, which basically means that its symbols must be linked in the lower 2 GB of the address space.

If they don't fit, the solution can be to use a medium code model which means that program and small symbols are linked in the lower 2GB of the address space and large symbols are put into large data or bss sections located above 2BG (abstract from man gcc). Large symbols are defined using -mlarge-data-threshold so some optimizaiton can be done, but note that this value should be same accross all objects.

g++ -mcmodel=medium ....
Neuron
  • 5,141
  • 5
  • 38
  • 59
Mi-La
  • 685
  • 10
  • 18