Tuesday, May 18, 2010

relocation truncated to fit: R_X86_64_32S against `.bss' Error

"relocation truncated to fit: R_X86_64_32S against `.bss' Error"
This is a rare error but when you get it there is no way you can get out of it without doing something fancy. If you do an exhaustive search you will find people trying to upgrade their linkers as the issue is definitely with linker. People even tried rebuilding their linker to ignore the relocation errors. Even if you do that you will SEGFAULT at run time.

The reason for this error is the size of data that you are using. This is seen to happen when your program needs more than 2GB of data. Well, who needs such big data at compile time? I do for one and there are other people in the HPC world who do that too. For all of them the life saver or may be a day saver is the compiler option -mcmodel.

All you need to do is to compile your program with

-mcmodel medium option.

For example, I was working with STREAM benchmarking tool from university of Virginia and had this error. To rectify this, I compiled my program with following command:

 gcc -mcmodel=medium stream.c -o stream

I have removed additional flags for the sake of simplicity. You might want to use various flags for your program. Please comment if this was helpful.