From c9cde48f3a22572d292f6bbe47b52c2521244b59 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Mon, 10 Sep 2012 10:30:12 +0000 Subject: [PATCH] Wrong crtbegin/crtend pair used for PIE on Android. Android uses the same flavour of crt*.o for PIE and non-PIE executables, and a different one for DSOs. GNU/Linux, on the other hand, uses one set of crt*.o for non-PIE executables, and another for both PIE executables and DSOs. llvm-svn: 163500 --- clang/lib/Driver/Tools.cpp | 8 ++++++-- clang/test/Driver/linux-ld.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index b7ee6ab95519..1549d3dad19e 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -5741,8 +5741,10 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, const char *crtbegin; if (Args.hasArg(options::OPT_static)) crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o"; - else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) + else if (Args.hasArg(options::OPT_shared)) crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o"; + else if (Args.hasArg(options::OPT_pie)) + crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o"; else crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o"; CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); @@ -5808,8 +5810,10 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostartfiles)) { const char *crtend; - if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) + if (Args.hasArg(options::OPT_shared)) crtend = isAndroid ? "crtend_so.o" : "crtendS.o"; + else if (Args.hasArg(options::OPT_pie)) + crtend = isAndroid ? "crtend_android.o" : "crtendS.o"; else crtend = isAndroid ? "crtend_android.o" : "crtend.o"; diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index 003bc9f540f5..fc7b55858c68 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -412,3 +412,20 @@ // CHECK-ANDROID-STATIC: "-lgcc" // CHECK-ANDROID-STATIC-NOT: "gcc_s" // CHECK-ANDROID-STATIC: "{{.*}}/crtend_android.o" +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -target arm-linux-androideabi \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -pie \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PIE %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -target arm-linux-android \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -pie \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PIE %s +// CHECK-ANDROID-PIE: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" +// CHECK-ANDROID-PIE: "{{.*}}/crtbegin_dynamic.o" +// CHECK-ANDROID-PIE: "-L[[SYSROOT]]/usr/lib" +// CHECK-ANDROID-PIE-NOT: "gcc_s" +// CHECK-ANDROID-PIE: "-lgcc" +// CHECK-ANDROID-PIE-NOT: "gcc_s" +// CHECK-ANDROID-PIE: "{{.*}}/crtend_android.o"