From f6513810c9e5bb75336b69e08cf99cc8ba97175f Mon Sep 17 00:00:00 2001 From: Roman Divacky Date: Fri, 7 Sep 2012 13:36:21 +0000 Subject: [PATCH] Link to crtend.S when PIE in the FreeBSD driver. Patch by Brooks Davis! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163388 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 6 +++--- test/Driver/pic.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d4a537240f..1117202f93 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -5353,10 +5353,10 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nostartfiles)) { - if (!Args.hasArg(options::OPT_shared)) - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); - else + if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); + else + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); } diff --git a/test/Driver/pic.c b/test/Driver/pic.c index 3952f85ceb..636a4498a7 100644 --- a/test/Driver/pic.c +++ b/test/Driver/pic.c @@ -23,6 +23,11 @@ // CHECK-PIE2-NOT: "-mrelocation-model" // CHECK-PIE2: "-pie-level" "2" // +// CHECK-PIE3: "{{.*}}ld" +// CHECK-PIE3: "-pie" +// CHECK-PIE3: "Scrt1.o" "crti.o" "crtbeginS.o" +// CHECK-PIE3: "crtendS.o" "crtn.o" +// // RUN: %clang -c %s -target i386-unknown-unknown -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC // RUN: %clang -c %s -target i386-unknown-unknown -fpic -### 2>&1 \ @@ -70,6 +75,15 @@ // RUN: %clang -c %s -target i386-apple-darwin -fno-PIC -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC // +// Make sure -pie is passed to along to ld and that the right *crt* files +// are linked in. +// RUN: %clang %s -target i386-unknown-freebsd -fPIE -pie -### \ +// RUN: --sysroot=%S/Inputs/basic_freebsd_tree 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-PIE3 +// RUN: %clang %s -target i386-linux-gnu -fPIE -pie -### \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-PIE3 +// // Disregard any of the PIC-specific flags if we have a trump-card flag. // RUN: %clang -c %s -target i386-unknown-unknown -mkernel -fPIC -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-NO-PIC -- 2.40.0