intermezzOS / kernel

A hobby operating system, in Rust
http://intermezzos.github.io/
Apache License 2.0
1.39k stars 90 forks source link

relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC #110

Closed p-kraszewski closed 6 years ago

p-kraszewski commented 7 years ago

If compilation gives something like:

  = note: /usr/bin/ld: /storage/Projects/IntermezzOS_bare/target/x86_64-unknown-intermezzos-gnu/release/build/intermezzos-8ccbbf2f886be67d/out/libboot.a(boot.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
          /usr/bin/ld: final link failed: Nie da się wyświetlić sekcji na wyjściu!
          collect2: error: ld returned 1 exit status

this is due to hardened compiler chain: at least on Hardened-Gentoo and Ubuntu 16.10+.

To fix it, you need to change x86_64-unknown-intermezzos-gnu.json by adding "-no-pie" to "pre-link-args". This will disable hardening for the project.

Hope this helps!

steveklabnik commented 7 years ago

Thanks! I'm confused as to why a "hardened" gcc wouldn't want PIE.

p-kraszewski commented 7 years ago

Oh, it's the other way around. Hardened GCC wants PIC in so many places, that it can't be easily fulfilled due to conflicts between 32/64 bits and that's why you want to disable PIE (which effectively disables hardened path). I had the same situation with Haskell/stack on Ubuntu 16.10 - it refused to compile with quite the similar error. That's what pointed me in the right direction with Rust/IntermezzOS.