ld: fatal: relocation error: R_AMD64_32: file on studio11 f95
We have a fortran 90 code which does not link and produces a series of errors as listed in the subject.. The code is linked using -xmodel=medium -xarch=amd64a :
ld: fatal: relocation error: R_AMD64_32: file processing.o: symbol grid.headg_: value 0xa29ae95c does not fit
...
ld: fatal: relocation error: R_AMD64_PC32: file processing.o: symbol grid.headg_: value 0xa25a0cf5 does not fit
The compiler is:
f95: Sun Fortran 95 8.2 Patch 121020-04 2006/10/26
A similar code, with arrays larger then the ones addressed here compiled (and ocmpiles) under this version of the compiler.
Any idea what else I could/should be doing?
# 1
Did you compile processing.o with -xmodel=medium? These relocation errors are for "small" offset types. (Medium model compilation produces both small and large offsets, so the relocation error does not indicate that the file was compiled using the small model.)
It is possible that you really need large model for this code. Unfortunately, the compiler doesn't yet support large model code generation.(I'm not sure that the large model ABI has been finalized yet.)
You could try compiling with -KPIC instead of or in addition to -xmodel=medium.
You could also try making some arrays larger. Medium model places arrays below a certain size (64k, if I remember correctly) in a "near" space, while larger arrays go in a "far" space. It is possible for the sum of the sizes of arrays in near space to exceed the limit on the size of near space. By making the arrays larger, you would move them from near space to far space.
igba at 2007-7-10 3:49:06 >

# 2
I have more to tell:
The compilation I did first was with -fast -xmodel=medium xarch=amd64a
and I got this error from a certain set of modules.
When I compiled the same code in the same order using -xmodel=medium xarch=amd64a or
-C -g -xmodel=medium xarch=amd64a
then I got the error from most if not all the modules in the code.
I just now read your reply and have appended -KPIC to my -fast -xmodel=medium xarch=amd64a and all works beautifully.
it also does work for using -KPIC with the plain and debug compilation.
Do you have an easy explanation why -KPIC would help?
# 3
When you use -KPIC, the compiler generates different code for accessing (global/static) variables and for calling functions. For variables, it uses something called a "global offset table", usually called GOT. The code finds the GOT by knowing the offset from the address of the code itself, something like this (in pseudo-C code):
label: gotptr = &label + (&got - &label)
The "&got - &label" is a constant whose value is determined when you link your code, so at run time the code just has to find the address of "label". The "relocation" (which is what the linker calls any value that it patches) that needs to fit is "&got - &label". The GOT is located near all the code, which makes the relocation more likely to fit.
By contrast, for -xmodel=medium the relocation is roughly equivalent to "&variable - &label" for small variables. The compiler attempts to put all those variables close to the code, but if the total size of the small variables and the code itself is too large, the relocation will not fit.
igba at 2007-7-10 3:49:06 >

# 4
Ooops, I forgot to explain how the GOT table is used. It is a table of pointers to variables, so when your program accesses a variable the compiled code executes "*got_ptr[var_index]". In most cases this has a negligible impact on performance, because the compiler is able to hoist address lookup out of loops.
igba at 2007-7-10 3:49:06 >
