Default to PIC code on Linux #1664

Merged
merged 1 commit into from Aug 3, 2016

Conversation

Projects
None yet
3 participants
Contributor

ximion commented Aug 2, 2016

Modern Linux distributions have their toolchain generate PIC code for
additional security features (like ASLR).
Since there is no (sane) way to detect whether the toolchain defaults to
PIC code, we simply default to PIC code on all Linux
distributions to avoid linking issues on these OSes.

The relocation model can be switched back to non-PIC code manually at
any time.

This change resolves issue #1618

driver/targetmachine.cpp
@@ -530,6 +530,10 @@ llvm::TargetMachine *createTargetMachine(
relocModel = llvm::Reloc::PIC_;
} else if (triple.getEnvironment() == llvm::Triple::Android) {
relocModel = llvm::Reloc::PIC_;
+ } else if (triple.getOS() == llvm::Triple::Linux) {
@JohanEngelen

JohanEngelen Aug 2, 2016

Member

could you change it to use isOSLinux() like the Darwin check above?

@ximion

ximion Aug 2, 2016

Contributor

Will isOSLinux be true for Android too? (because in theory, the triplet should be something like <arch>-linux-android for Android (and <arch>-linux-gnu for traditional distros).
I don't know how LLVM handles this.

@ximion

ximion Aug 2, 2016

Contributor

The docs answer this: It's exactly as I expected and we can assume a Linux OSType for Android as well (which makes the code a bit simpler).
PR is updated, thanks!

Owner

klickverbot commented Aug 2, 2016

I'll manually merge this once green to tweak the comment a little bit – thanks for the patch!

Owner

klickverbot commented Aug 2, 2016

(The issue is not that Ubuntu 16.10 et al. "compile their toolchain with PIC for additional security", but that they set GCC to produce position-independent executables by default.)

Contributor

ximion commented Aug 2, 2016

Right, what I was actually wanting to write there was "have their toolchain output PIC code" :)

Default to PIC code on Linux
Modern Linux distributions have their toolchain generate PIC code for
additional security features (like ASLR).
Since there is no (sane) way to detect whether the toolchain defaults to
PIC code, we simply default to PIC code on all Linux
distributions to avoid linking issues on these OSes.

The relocation model can be switched back to non-PIC code manually at
any time.

@klickverbot klickverbot merged commit 8fcd497 into ldc-developers:master Aug 3, 2016

3 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@klickverbot klickverbot added this to the 1.1.0 milestone Aug 3, 2016

Member

JohanEngelen commented Sep 5, 2016

@redstar This is important to mention in the release notes. At least one project fails to build after this change, so it's good to know what to look for.

Member

JohanEngelen commented Sep 5, 2016

@redstar I see you already added something about it to 1.1.0-beta3 release notes. I will add a little more.

Owner

klickverbot commented Sep 5, 2016

At least one project fails to build after this change, so it's good to know what to look for.

How does this break stuff?

Owner

klickverbot commented Sep 5, 2016

Ah, Weka's binary instrumentation? That's a bit of a special case. It certainly should be mentioned prominently, but the change shouldn't be very disruptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment