Papierkorb / bindgen

Binding and wrapper generator for C/C++ libraries
GNU General Public License v3.0
179 stars 18 forks source link

LLVM 7 - PIE / fPIC #44

Closed docelic closed 4 years ago

docelic commented 4 years ago

On Debian and LLVM 7, after bindgen is compiled, Qt specs fail with:

>>> Output of failed spec: virtual_override.yml
/usr/bin/ld: /home/x/bindgen/spec/integration/tmp/../tmp/virtual_override.o: relocation 
R_X86_64_32S against symbol `stderr@@GLIBC_2.2.5' can not be used when making a PIE 
object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status

>>> Output of failed spec: c_wrapper.yml
/usr/bin/ld: /home/x/bindgen/spec/integration/tmp/../tmp/c_wrapper.o: relocation R_X86_64_32S 
against `.bss' can not be used when making a PIE object; recompile with -fPIC

>>> Output of failed spec: containers.yml
/usr/bin/ld: /home/x/bindgen/spec/integration/tmp/../tmp/containers.o: relocation R_X86_64_32 
against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC

>>> Output of failed spec: basic.yml
/usr/bin/ld: /home/x/bindgen/spec/integration/tmp/../tmp/basic.o: relocation R_X86_64_32 against 
symbol `__gxx_personality_v0@@CXXABI_1.3' can not be used when making a PIE object; 
recompile with -fPIC

>>> Output of failed spec: qt.yml
/usr/bin/ld: /home/x/bindgen/spec/integration/tmp/../tmp/qt.o: relocation R_X86_64_32S against 
symbol `_ZN10SomeObject13stuffHappenedEv' can not be used when making a PIE object; 
recompile with -fPIC

An example of a CC line that's invoked is:

Error: execution of command failed with code: 1: `cc "${@}" -o '/home/x/.cache/crystal/crystal-run-
qt_test.tmp' -lgccpp -rdynamic  /home/x/bindgen/spec/integration/tmp/../tmp/qt.o -lstdc++ -lpcre 
-lm /opt/crystal-0.34.0-1/bin/../lib/crystal/lib/libgc.a -lpthread /opt/crystal-0.34.0-1/share/crystal
/src/ext/libcrystal.a -levent -lrt -ldl -L/opt/crystal-0.34.0-1/bin/../lib/crystal/lib -L/opt/crystal-0.34.0-1
/bin/../lib/crystal/lib`
ZaWertun commented 4 years ago

Which Debian version? I can check this in the VM.

docelic commented 4 years ago

Debian 10.0 (Actually this installation is Devuan, but it corresponds to Debian 10)

ZaWertun commented 4 years ago

Also try to remove "-fPIC" from the flags in the qt.yml.

docelic commented 4 years ago

Interesting, I just checked and -fPIC (or "fpic" at all, case insensitive) does not appear anywhere in my checkout of the bindgen repository.

docelic commented 4 years ago

Ah but of course, I had to add it. I added it to the build flags in spec/integration/spec_base.yml and all specs passed at this time!

docelic commented 4 years ago

So now to figure out why it's not detected automatically.

docelic commented 4 years ago

Hm, is there a way we can auto-detect the -fPIC setting? It does not appear in the output of any commands that find_clang runs, yet as evident from this issue, it was needed on this system for things to work.

ZaWertun commented 4 years ago

Maybe just add -fPIC to default flags? Adding it doesn't seem to break anything on my system (Fedora 32). Though more investigation needed.

docelic commented 4 years ago

In lack of a better solution, I think what we can do is enable -fPIC if BINDGEN_DYNAMIC is false.

docelic commented 4 years ago

The proposed fix is committed with: https://github.com/Papierkorb/bindgen/commit/4590da807e986b271160f72bdb0a8d8635533a3c

Let's see if it will be fine or cause issue reports from users.