Friday, 18 December 2009

ld: fatal: relocations remain against allocatable but non-writable sections

I recently came accross an issue while trying to compile some files on Solaris 10 with gcc-3.4.6

After running make I was getting the following error:

ld: fatal: relocations remain against allocatable but non-writable sections

The error is generated during the ld command which serves the following purpose:

"The ld command combines relocatable object files, performs
relocation, and resolves external symbols. ld operates in
two modes, static or dynamic"


So basically it is a linking error. As always googling the error reveal some solutions:
- Use static linking (Which I was already using "-G" )
- Use the GNU link editor instead of the Solaris one

To find out which ld version you are running :


>>ld -V

ld: Software Generation Utilities - Solaris Link Editors: 5.9-1.393


So I downloaded the GNU binutils from
http://www.gnu.org/directory/binutils.html


Or you can download the precompiled package from sunfreeware. When you have the two link editors installed:
- Solaris one in /usr/ccs/bin/
- GNU one in /usr/local/bin

You must configure you PATH variable to incude the /usr/local/bin before the ccs path. Or you can just incude the /usr/local/bin path and just rename the /usr/ccs/bin/ld to /usr/ccs/bin/ld.SOLARIS

Run make again and hurrey !!! Job done.

Some usefull commands for Solaris 10:



Adding Solaris 10 library paths
-------------------------------



ess:/export/home/ess> crle -c /var/ld/ld.config -l /your/library/paths/go/here



View internal version information of dynamic objects
------------------------------------------------------


ess:/export/home/ess> pvs /usr/ccs/bin/ld

libld.so.4 (SUNWprivate_4.2);
libelf.so.1 (SUNW_0.7);
libc.so.1 (SUNW_1.18, SUNWprivate_1.1);
ld;


List dynamic dependencies of executable files or shared objects
----------------------------------------------------------------


ess-stage:/export/home/ess> ldd /usr/ccs/bin/ld
libld.so.4 => /usr/ccs/bin/../../../lib/libld.so.4
libelf.so.1 => /usr/ccs/bin/../../../lib/libelf.so.1
libc.so.1 => /usr/ccs/bin/../../../lib/libc.so.1
liblddbg.so.4 => /lib/liblddbg.so.4
libm.so.2 => /lib/libm.so.2
/platform/SUNW,Sun-Fire-T1000/lib/libc_psr.so.1

1 comments:

Mike Armstrong said...

I installed the latest version on binutils as you suggested and it worked very well. Intead of worrying about changing paths on my Solaris box i renamed the original ld in /usr/css/bin and copied the new version in.

thanks,
Michael Armstrong