[Driver] Use --warn-shared-textrel for Android.
authorDan Albert <danalbert@google.com>
Fri, 29 Mar 2019 18:34:25 +0000 (18:34 +0000)
committerDan Albert <danalbert@google.com>
Fri, 29 Mar 2019 18:34:25 +0000 (18:34 +0000)
Android does not allow shared text relocations. Enable the linker
warning to detect them by default.

Reviewers: srhines, pirama

Reviewed By: srhines

Subscribers: cfe-commits

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

llvm-svn: 357296

clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/linux-ld.c

index 7b2dd67..9663b51 100644 (file)
@@ -387,6 +387,11 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
       CmdArgs.push_back("--fix-cortex-a53-843419");
   }
 
+  // Android does not allow shared text relocations. Emit a warning if the
+  // user's code contains any.
+  if (isAndroid)
+      CmdArgs.push_back("--warn-shared-textrel");
+
   for (const auto &Opt : ToolChain.ExtraOpts)
     CmdArgs.push_back(Opt.c_str());
 
index 4ace28b..c5041c9 100644 (file)
 // CHECK-ANDROID-NOEXECSTACK-NOT: "-z" "execstack"
 // CHECK-ANDROID-NOEXECSTACK-NOT: "-z,execstack"
 // CHECK-ANDROID-NOEXECSTACK-NOT: "-zexecstack"
-//
+
++// RUN: %clang %s -### -o %t.o 2>&1 \
++// RUN:     --target=armv7-linux-android21 \
++// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-WARN-SHARED-TEXTREL %s
++// CHECK-ANDROID-WARN-SHARED-TEXTREL: "{{.*}}ld{{(.exe)?}}"
++// CHECK-ANDROID-WARN-SHARED-TEXTREL: "--warn-shared-textrel"
+
 // RUN: %clang %s -### -o %t.o 2>&1 --target=mips64-linux-gnuabin32 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-GNUABIN32 %s
 // CHECK-MIPS64EL-GNUABIN32: "{{.*}}ld{{(.exe)?}}"