[PATCH] D22130: Link static PIE programs against rcrt0.o on OpenBSD

Stefan Kempf via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 15 09:33:54 PDT 2016


sisnkemp updated this revision to Diff 68046.
sisnkemp added a comment.

Now with test case.


https://reviews.llvm.org/D22130

Files:
  lib/Driver/Tools.cpp
  test/Driver/openbsd.c

Index: test/Driver/openbsd.c
===================================================================
--- test/Driver/openbsd.c
+++ 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"
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8301,6 +8301,10 @@
       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")));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22130.68046.patch
Type: text/x-patch
Size: 2357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160815/a4696e79/attachment.bin>


More information about the cfe-commits mailing list