From e1cf700362bdaf17474ba6905a26e7c9c4094bfc Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 14 Oct 2016 17:59:53 +0000 Subject: [PATCH] Link static PIE programs against rcrt0.o on OpenBSD Patch by Stefan Kempf. Differential Revision: https://reviews.llvm.org/D22130 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284256 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 4 ++++ test/Driver/openbsd.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index b7a323faa5..e073eddc36 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("gcrt0.o"))); + else if (Args.hasArg(options::OPT_static) && + !Args.hasArg(options::OPT_nopie)) + CmdArgs.push_back( + Args.MakeArgString(getToolChain().GetFilePath("rcrt0.o"))); else CmdArgs.push_back( Args.MakeArgString(getToolChain().GetFilePath("crt0.o"))); diff --git a/test/Driver/openbsd.c b/test/Driver/openbsd.c index 95b9e6ad4f..ff54f39215 100644 --- a/test/Driver/openbsd.c +++ b/test/Driver/openbsd.c @@ -67,3 +67,26 @@ // CHECK-MIPS64-PIC: as{{.*}}" "-mabi" "64" "-EB" "-KPIC" // CHECK-MIPS64EL: as{{.*}}" "-mabi" "64" "-EL" // CHECK-MIPS64EL-PIC: as{{.*}}" "-mabi" "64" "-EL" "-KPIC" + +// Check linking against correct startup code when (not) using PIE +// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-PIE %s +// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -fno-pie %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-PIE %s +// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -static %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-STATIC-PIE %s +// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -static -fno-pie %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-STATIC-PIE %s +// RUN: %clang -no-canonical-prefix -target i868-pc-openbsd -nopie %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-NOPIE %s +// RUN: %clang -no-canonical-prefix -target i868-pc-openbsd -fno-pie -nopie %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-NOPIE %s +// RUN: %clang -no-canonical-prefix -target i868-pc-openbsd -static -nopie %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-NOPIE %s +// RUN: %clang -no-canonical-prefix -target i868-pc-openbsd -fno-pie -static -nopie %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-NOPIE %s +// CHECK-PIE: "/usr/lib/crt0.o" +// CHECK-PIE-NOT: "-nopie" +// CHECK-STATIC-PIE: "/usr/lib/rcrt0.o" +// CHECK-STATIC-PIE-NOT: "-nopie" +// CHECK-NOPIE: "-nopie" {{.*}}"/usr/lib/crt0.o" -- 2.40.0