Ask Your Question
1

fedora24: 64-bit "-fPIC" shared lib relocation ("gcc -fPIC" -> "ld : recompile with -fPIC")

asked 2016-11-16 21:06:40 -0500

lovepump gravatar image

I am trying to compile (perhaps cross compile, when considering "EFI executables" are PE/COFF and not ELF) either efitools or any package for EDK2. Both of these are suggested as packages that will grant "access" to "advanced" UEFI features accompanying secure boot (that will allow for the signing of custom kernels, or kernel modules, etc..)

I am trying to build either of these packages and I continue to run into issues when gcc (via make or "python" build) has finished compiling the simpler "hello world" EFI binaries and has turned control over to "ld" for linkage to create shared libraries.

All of the "CFLAGS or C++FLAGS" compilation environment variables for everything contain the necessary flag (-fPIC) for gcc (Red Hat 6.2.1-2) to build position independent code. As far as all my "research" into the problem has given me to go on, the linkage options for "ld" to deal with position independent code are all now "default" linker options in fedora 24. Any of the "ld" options I've read about (for example -z,now) spit back that they are ignored by ld as they (position independent code) are now default options. These were explored because apparently it was common to have "hardened compiler" options and accidentally forget "hardened linker" options in the past. This does not seem to be the problem (but I won't ignore suggestions to the contrary).

The ld error I am receiving while using "(python) build" for the simple edk2 efi "HelloWorld" package MdeModulePkg is:

/usr/bin/ld "library(path)name": relocation R_X86_64_32 against '.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC. "library(path)name": error adding symbols: Bad Value

ld --version returns GNU ld version 2.26.1-1.fc24, and ld --help seems to indicate it can link "things EFI".

I would be happy to provide output from ld, gcc, readelf, objdump (or whatever is necessary) to help determine the linkage problem.

At the risk of complicating the question, when building efitools I get an extremely similar relocation error that is a little more specific about a particular "missing" symbol that seems to be “present” as far as I can tell when I look at the 'readelf --relocs' output.

I'm all ears!

Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2016-12-03 05:15:01 -0500

sergiomb gravatar image

Relocation R_X86_64_PC32 against undefined symbol , usually happens when LDFLAGS are set with hardening and CFLAGS not .
Maybe just user error:
If you are using -specs=/usr/lib/rpm/redhat/redhat-hardened-ld at link time, you also need to use -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 at compile time, and as you are compiling and linking at the same time, you need either both, or drop the -specs=/usr/lib/rpm/redhat/redhat-hardened-ld . Common fixes :
https://bugzilla.redhat.com/show_bug....
https://github.com/rpmfusion/lxdream/...

edit flag offensive delete link more

Comments

This was purely a linking (ld) problem, and it shouldn't have happened. All of the compilation/linkage flag options in any "common" fix were tried, ad nauseum, before I posted :) In fact, the linkage options in all of the "common solutions" are now "default options" for ld and are ignored. The whole "hardened" thing is now a "default" thing for x86_64 as far as I can tell.

lovepump gravatar imagelovepump ( 2016-12-03 22:40:34 -0500 )edit

yes "hardened" is default since F2x and if in your project you got CFLAGS="-Wall -O3" in configure.in instead += , it clean default CFLAGS and will lead to this problem .

sergiomb gravatar imagesergiomb ( 2016-12-04 09:40:49 -0500 )edit
0

answered 2016-12-02 16:23:26 -0500

lovepump gravatar image

OK - would like to update this question as "solved", however there was no "solution".

Updating to fedora 25 and trying again has "fixed" the issue.

I was able to compile efitools with a "default" install of fedora 25 (64). I was never able to compile anything in efitools with several massages given to fedora 24 (64).

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-16 21:06:40 -0500

Seen: 465 times

Last updated: Dec 03 '16