Skip to content

Commit

Permalink
Don't use -pie in relocatable link.
Browse files Browse the repository at this point in the history
Summary:
Android, in particular, got PIE enabled by default in r316606. It resulted in
relocatable links passing both -r and -pie to the linker, which is not allowed.

Reviewers: srhines

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D44229

llvm-svn: 327165
  • Loading branch information
eugenis committed Mar 9, 2018
1 parent b0e4b91 commit d48c0cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) {
}

static bool getPIE(const ArgList &Args, const toolchains::Linux &ToolChain) {
if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static))
if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
Args.hasArg(options::OPT_r))
return false;

Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
Expand Down
17 changes: 17 additions & 0 deletions clang/test/Driver/android-pie.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,20 @@
// RUN: | FileCheck --check-prefix=NO-PIE %s
// RUN: %clang %s -### -o %t.o 2>&1 -pie -no-pie --target=arm-linux-androideabi24 \
// RUN: | FileCheck --check-prefix=NO-PIE %s

// Static/shared/relocatable disable -pie

// RUN: %clang %s -### --target=aarch64-linux-android -static 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-STATIC
// CHECK-STATIC-NOT: "-pie"
// CHECK-STATIC: -static

// RUN: %clang %s -### --target=aarch64-linux-android -shared 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-SHARED
// CHECK-SHARED-NOT: "-pie"
// CHECK-SHARED: "-shared"

// RUN: %clang %s -### --target=aarch64-linux-android -r 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-RELOCATABLE
// CHECK-RELOCATABLE-NOT: "-pie"
// CHECK-RELOCATABLE: "-r"

0 comments on commit d48c0cd

Please sign in to comment.