pgc++ - relocation R_X86_64_PC32 against "..." can

Hi all,

I used pgc++ to create the object files, (with -fPIC flag for all object files). At the linking stage, I received the following error message.

 /home/kzhu/pgi/linux86-64/13.5/bin/pgc++ -shared -o libcore.so
 -pthread -m64 -L/home/kzhu/pgi/linux86-64/13.5/lib64 -fPIC -lpthread -lc -lm -lcrypt -lrt -ldl -rpath /some_path xxx.o yyy.o zzz.o

... ...

/usr/bin/ld: zzz.o: relocation R_X86_64_PC32 against `... ...' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
*** Error code 2

Any suggestion on possible cause of this linking error is appreciated. For the reference, the linker that I used is

-bash-3.2$ /usr/bin/ld --version
GNU ld version 2.17.50.0.6-20.el5_8.3 20061020
Copyright 2005 Free Software Foundation, Inc.

Many thanks.


Kevin

Hi Kevin,

I typically see this error when you have a very large static array (>2GB) in the code. In this case, you need use the medium memory model (-mcmodel=medium).

If that doesn’t work, I’ll need you to send a report to PGI Customer Service (trs@pgroup.com) and include a reproducing example to determine the cause, or the the following information.

The output from:
pgc++ -c t.c -dryrun

As well as the post processed source files:
pgc++ -C -E <user_flags> xxx.c -o outx.i
pgc++ -C -E <user_flags> yyy.c -o outy.i
pgc++ -C -E <user_flags> zz.c -o outz.i

Note that pgc++ doesn’t accept the “-pthread” flag, hence you should be getting a compilation error if you use it.

  • Mat

Hi Mat,

Thank you for the pointers.

For the record, the object files are less than 2~GB. I tried the -mcmodel flag anyway, but it was not compatible with -fPIC that I needed.

Surprisingly, I did not get a compilation error with “-pthread”. To be on the safe side, I removed the -pthread flag when generating the object files. This did not affect the "relocation R_X86_64_PC32 against … " error at the linking stage.


Kevin

Always put the *.o files before any libs in a link line creating the shared libs.

xxx.o yyy.o and zzz.o should be compiled -fPICto be put into a shared library.

Objects compiled -mcmodel=medium can never be put into a shared library -
the have a 64-bit offset field, and linking with 32-bit offset fields causes
‘relocation R_X86_64_PC32 truncated to fit’ messages.

The only objects that can be linked with objects compiled -mcmodel=medium are

  1. other objects compiled -mcmodel=medium
  2. objects compiled -fPIC and put into a shared lib.

====================================
if you can avoid -mcmodel=medium in your main code, you are better off.

if you require large arrays, dynamically allocated them at runtime.

routines in shared libs like foo

subroutine foo(x,y,z,n)
integer8 n,i
real
8 x(n), y(n), z(n)
do i=1,n
z(i)-x(i)+y(i)
end do
return
end subroutine foo

should be compiled
-fPIC -Mlarge_arrays

before being put into a shared library.

Then you can pass small or large arrays to foo, and things
should work as expected.