Re: ifunc function in home-build glibc, executables linked against that libm.a and PIE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/20/2013 06:59 AM, Ian Lance Taylor wrote:

On Sat, Jan 19, 2013 at 10:36 AM, Toon Moene<toon@xxxxxxxxx>  wrote:

gfortran -g -Wl,-M  master.o C_code.o _odb_glue.o -Wl,--start-group
-L/scratch/harmonie/hm_home/trunk/lib/linux.gfortran.mpi/src -lxrd -lxla
-ltfl -ltal -lsur -larp -lald -lbla -lmpa -lmse -lsurfex -lbip -lsat -luti
-lodb -lodbport -lCCMA -lECMA -Wl,--end-group dummies.o \
          -L/scratch/harmonie/hm_home/trunk/lib/linux.gfortran.mpi/src
-lodbdummy -L/scratch/harmonie/hm_home/trunk/lib/linux.gfortran.mpi/src
-lrgb -lgribex -lbufr -L/home/harmonie/grib_api -lgrib_api_f90 -lgrib_api
-lnetcdff -lnetcdf -llapack -lblas -lmpi_f90 -lmpi_f77 -lmpi -lpthread
/home/toon/myglibc/lib/libm.a -o
/scratch/harmonie/hm_home/trunk/lib/linux.gfortran.mpi/src/MASTERODB>
/scratch/harmonie/hm_home/trunk/lib/linux.gfortran.mpi/src/load.map
/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `cos' with pointer equality in
`/home/toon/myglibc/lib/libm.a(s_sin.o)' can not be used when making an
executable; recompile with -fPIE and relink with -pie
collect2: error: ld returned 1 exit status

I have no idea why this is happening to you but I can tell you what it
means.  The symbol "cos" has been defined as an IFUNC symbol in your
library.  That means that the actual value of "cos" will be selected
at runtime, presumably with a version of "cos" that will execute
quickly on the processor as detected at runtime.  Furthermore, some
piece of code in the library is using "cos" in some way other than
simply calling it, e.g., taking the address of the function.  As it
happens, taking the address of an IFUNC function in code not compiled
with -fpie or -fpic is problematic, because that code will produce
different addresses in different shared libraries, meaning that
function pointer equality will not work.  The linker is telling you
about this problem, and telling you to fix it by recompiling with
-fpie.

Would placing them in a table like this cause that problem ?

static funcs_t Func[] = {
  /* Compile-time evaluable functions */
  "sin", 1, (void *)sin, NULL, 1, 0,
  "cos", 1, (void *)cos, NULL, 1, 0,
  "tan", 1, (void *)tan, NULL, 1, 0,

I think the right fix for you is going to be to recompile the contents
of libm.a with the -fpie option.  In general since your C library is
using IFUNC symbols, and apparently using them in ways other than
calling them, it should be compiled with -fpie.  I don't know why your
library makes "cos" an IFUNC symbol; I don't see that in the glibc
sources I happen to have on hand.

This is what nm tells me of the s_sin.o object in the libm.a I constructed:

...
0000000000003f90 i cos
...

which, according to the nm manual, *is* an ifunc symbol:

"i" For PE format files this indicates that the symbol is in a section specific to the implementation of DLLs. For ELF format files this indicates that the symbol is an indirect function. This is a GNU extension to the standard set of ELF symbol types. It indicates a symbol which if referenced by a relocation does not evaluate to its address, but instead must be invoked at runtime. The runtime execution will then return the value to be used in the relocation.

Thanks for your explanation.

--
Toon Moene - e-mail: toon@xxxxxxxxx - phone: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
At home: http://moene.org/~toon/; weather: http://moene.org/~hirlam/
Progress of GNU Fortran: http://gcc.gnu.org/wiki/GFortran#news


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux