r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-10-14 Thread Ed Maste via cfe-commits
Author: emaste
Date: Fri Oct 14 12:59:53 2016
New Revision: 284256

URL: http://llvm.org/viewvc/llvm-project?rev=284256&view=rev
Log:
Link static PIE programs against rcrt0.o on OpenBSD

Patch by Stefan Kempf.

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

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/openbsd.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256&r1=284255&r2=284256&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
@@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
   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")));

Modified: cfe/trunk/test/Driver/openbsd.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256&r1=284255&r2=284256&view=diff
==
--- cfe/trunk/test/Driver/openbsd.c (original)
+++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
@@ -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"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-10-14 Thread Brad Smith via cfe-commits
On Fri, Oct 14, 2016 at 05:59:54PM -, Ed Maste via cfe-commits wrote:
> Author: emaste
> Date: Fri Oct 14 12:59:53 2016
> New Revision: 284256
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=284256&view=rev
> Log:
> Link static PIE programs against rcrt0.o on OpenBSD
> 
> Patch by Stefan Kempf.
> 
> Differential Revision:https://reviews.llvm.org/D22130
> 
> Modified:
> cfe/trunk/lib/Driver/Tools.cpp
> cfe/trunk/test/Driver/openbsd.c
> 
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256&r1=284255&r2=284256&view=diff
> ==
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
> @@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
>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")));
> 
> Modified: cfe/trunk/test/Driver/openbsd.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256&r1=284255&r2=284256&view=diff
> ==
> --- cfe/trunk/test/Driver/openbsd.c (original)
> +++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
> @@ -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"

Ok, I see the obvious issue with -no-canonical-prefix vs -no-canonical-prefixes
and fix the typo with the target triples.


Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp(revision 284299)
+++ lib/Driver/Tools.cpp(working copy)
@@ -8519,6 +8519,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")));
Index: test/Driver/openbsd.c
===
--- test/Driver/openbsd.c   (revision 284299)
+++ test/Driver/openbsd.c   (working copy)
@@ -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:   | FileChe

Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-10-18 Thread Brad Smith via cfe-commits
On Fri, Oct 14, 2016 at 09:47:17PM -0400, Brad Smith via cfe-commits wrote:
> On Fri, Oct 14, 2016 at 05:59:54PM -, Ed Maste via cfe-commits wrote:
> > Author: emaste
> > Date: Fri Oct 14 12:59:53 2016
> > New Revision: 284256
> > 
> > URL: http://llvm.org/viewvc/llvm-project?rev=284256&view=rev
> > Log:
> > Link static PIE programs against rcrt0.o on OpenBSD
> > 
> > Patch by Stefan Kempf.
> > 
> > Differential Revision:  https://reviews.llvm.org/D22130
> > 
> > Modified:
> > cfe/trunk/lib/Driver/Tools.cpp
> > cfe/trunk/test/Driver/openbsd.c
> > 
> > Modified: cfe/trunk/lib/Driver/Tools.cpp
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256&r1=284255&r2=284256&view=diff
> > ==
> > --- cfe/trunk/lib/Driver/Tools.cpp (original)
> > +++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
> > @@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
> >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")));
> > 
> > Modified: cfe/trunk/test/Driver/openbsd.c
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256&r1=284255&r2=284256&view=diff
> > ==
> > --- cfe/trunk/test/Driver/openbsd.c (original)
> > +++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
> > @@ -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"
> 
> Ok, I see the obvious issue with -no-canonical-prefix vs 
> -no-canonical-prefixes
> and fix the typo with the target triples.
 
After seeing what the test failure was I have adjusted the tests as appropriate.


Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp(revision 283697)
+++ lib/Driver/Tools.cpp(working copy)
@@ -8469,6 +8469,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")));
Index: test/Driver/openbsd.c
===
--- test/Driver/openbsd.c   (revision 283697)
+++ test/Driver/openbsd.c   (working copy)
@@ -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-

Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-10-19 Thread Stefan Kempf via cfe-commits
Brad Smith wrote:
> On Fri, Oct 14, 2016 at 09:47:17PM -0400, Brad Smith via cfe-commits wrote:
> > On Fri, Oct 14, 2016 at 05:59:54PM -, Ed Maste via cfe-commits wrote:
> > > Author: emaste
> > > Date: Fri Oct 14 12:59:53 2016
> > > New Revision: 284256
> > > 
> > > URL: http://llvm.org/viewvc/llvm-project?rev=284256&view=rev
> > > Log:
> > > Link static PIE programs against rcrt0.o on OpenBSD
> > > 
> > > Patch by Stefan Kempf.
> > > 
> > > Differential Revision:https://reviews.llvm.org/D22130
> > > 
> > > Modified:
> > > cfe/trunk/lib/Driver/Tools.cpp
> > > cfe/trunk/test/Driver/openbsd.c
> > > 
> > > Modified: cfe/trunk/lib/Driver/Tools.cpp
> > > URL: 
> > > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256&r1=284255&r2=284256&view=diff
> > > ==
> > > --- cfe/trunk/lib/Driver/Tools.cpp (original)
> > > +++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
> > > @@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
> > >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")));
> > > 
> > > Modified: cfe/trunk/test/Driver/openbsd.c
> > > URL: 
> > > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256&r1=284255&r2=284256&view=diff
> > > ==
> > > --- cfe/trunk/test/Driver/openbsd.c (original)
> > > +++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
> > > @@ -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"
> > 
> > Ok, I see the obvious issue with -no-canonical-prefix vs 
> > -no-canonical-prefixes
> > and fix the typo with the target triples.
>  
> After seeing what the test failure was I have adjusted the tests as 
> appropriate.
 
Oh, sorry for that failing test :-(

Thanks, your diff looks better. I wonder why running ./bin/llvm-lit
tools/clang/test/Driver/openbsd.c output PASS even with the broken test
case.
 
> Index: lib/Driver/Tools.cpp
> ===
> --- lib/Driver/Tools.cpp  (revision 283697)
> +++ lib/Driver/Tools.cpp  (working copy)
> @@ -8469,6 +8469,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")));
> Index: test/Driver/openbsd.c
> ===
> --- test

Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-10-25 Thread Brad Smith via cfe-commits

On 10/18/16 22:13, Brad Smith via cfe-commits wrote:

On Fri, Oct 14, 2016 at 09:47:17PM -0400, Brad Smith via cfe-commits wrote:

On Fri, Oct 14, 2016 at 05:59:54PM -, Ed Maste via cfe-commits wrote:

Author: emaste
Date: Fri Oct 14 12:59:53 2016
New Revision: 284256

URL: http://llvm.org/viewvc/llvm-project?rev=284256&view=rev
Log:
Link static PIE programs against rcrt0.o on OpenBSD

Patch by Stefan Kempf.

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

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/openbsd.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256&r1=284255&r2=284256&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
@@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
   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")));

Modified: cfe/trunk/test/Driver/openbsd.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256&r1=284255&r2=284256&view=diff
==
--- cfe/trunk/test/Driver/openbsd.c (original)
+++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
@@ -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"


Ok, I see the obvious issue with -no-canonical-prefix vs -no-canonical-prefixes
and fix the typo with the target triples.


After seeing what the test failure was I have adjusted the tests as appropriate.


ping.


Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp(revision 283697)
+++ lib/Driver/Tools.cpp(working copy)
@@ -8469,6 +8469,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")));
Index: test/Driver/openbsd.c
===
--- test/Driver/openbsd.c   (revision 283697)
+++ test/Driver/openbsd.c   (working copy)
@@ -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-prefix

Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-10-29 Thread Brad Smith via cfe-commits

On 10/25/16 19:34, Brad Smith via cfe-commits wrote:

On 10/18/16 22:13, Brad Smith via cfe-commits wrote:

On Fri, Oct 14, 2016 at 09:47:17PM -0400, Brad Smith via cfe-commits
wrote:

On Fri, Oct 14, 2016 at 05:59:54PM -, Ed Maste via cfe-commits
wrote:

Author: emaste
Date: Fri Oct 14 12:59:53 2016
New Revision: 284256

URL: http://llvm.org/viewvc/llvm-project?rev=284256&view=rev
Log:
Link static PIE programs against rcrt0.o on OpenBSD

Patch by Stefan Kempf.

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

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/openbsd.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256&r1=284255&r2=284256&view=diff

==

--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
@@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
   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")));

Modified: cfe/trunk/test/Driver/openbsd.c
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256&r1=284255&r2=284256&view=diff

==

--- cfe/trunk/test/Driver/openbsd.c (original)
+++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
@@ -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"


Ok, I see the obvious issue with -no-canonical-prefix vs
-no-canonical-prefixes
and fix the typo with the target triples.


After seeing what the test failure was I have adjusted the tests as
appropriate.


ping.


ping ping.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-10-29 Thread Hal Finkel via cfe-commits
- Original Message -
> From: "Brad Smith via cfe-commits" 
> To: "Ed Maste" , sisnk...@gmail.com, 
> cfe-commits@lists.llvm.org
> Sent: Sunday, October 30, 2016 12:57:44 AM
> Subject: Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD
> 
> On 10/25/16 19:34, Brad Smith via cfe-commits wrote:
> > On 10/18/16 22:13, Brad Smith via cfe-commits wrote:
> >> On Fri, Oct 14, 2016 at 09:47:17PM -0400, Brad Smith via
> >> cfe-commits
> >> wrote:
> >>> On Fri, Oct 14, 2016 at 05:59:54PM -, Ed Maste via
> >>> cfe-commits
> >>> wrote:
> >>>> Author: emaste
> >>>> Date: Fri Oct 14 12:59:53 2016
> >>>> New Revision: 284256
> >>>>
> >>>> URL: http://llvm.org/viewvc/llvm-project?rev=284256&view=rev
> >>>> Log:
> >>>> Link static PIE programs against rcrt0.o on OpenBSD
> >>>>
> >>>> Patch by Stefan Kempf.
> >>>>
> >>>> Differential Revision:https://reviews.llvm.org/D22130
> >>>>
> >>>> Modified:
> >>>> cfe/trunk/lib/Driver/Tools.cpp
> >>>> cfe/trunk/test/Driver/openbsd.c
> >>>>
> >>>> Modified: cfe/trunk/lib/Driver/Tools.cpp
> >>>> URL:
> >>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256&r1=284255&r2=284256&view=diff
> >>>>
> >>>> ==
> >>>>
> >>>> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> >>>> +++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
> >>>> @@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
> >>>>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")));
> >>>>
> >>>> Modified: cfe/trunk/test/Driver/openbsd.c
> >>>> URL:
> >>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256&r1=284255&r2=284256&view=diff
> >>>>
> >>>> ==
> >>>>
> >>>> --- cfe/trunk/test/Driver/openbsd.c (original)
> >>>> +++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
> >>>> @@ -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-cano

Re: r284256 - Link static PIE programs against rcrt0.o on OpenBSD

2016-11-01 Thread Brad Smith via cfe-commits

On 10/30/16 01:57, Brad Smith via cfe-commits wrote:

On 10/25/16 19:34, Brad Smith via cfe-commits wrote:

On 10/18/16 22:13, Brad Smith via cfe-commits wrote:

On Fri, Oct 14, 2016 at 09:47:17PM -0400, Brad Smith via cfe-commits
wrote:

On Fri, Oct 14, 2016 at 05:59:54PM -, Ed Maste via cfe-commits
wrote:

Author: emaste
Date: Fri Oct 14 12:59:53 2016
New Revision: 284256

URL: http://llvm.org/viewvc/llvm-project?rev=284256&view=rev
Log:
Link static PIE programs against rcrt0.o on OpenBSD

Patch by Stefan Kempf.

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

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/openbsd.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=284256&r1=284255&r2=284256&view=diff


==


--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 14 12:59:53 2016
@@ -8519,6 +8519,10 @@ void openbsd::Linker::ConstructJob(Compi
   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")));

Modified: cfe/trunk/test/Driver/openbsd.c
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openbsd.c?rev=284256&r1=284255&r2=284256&view=diff


==


--- cfe/trunk/test/Driver/openbsd.c (original)
+++ cfe/trunk/test/Driver/openbsd.c Fri Oct 14 12:59:53 2016
@@ -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"


Ok, I see the obvious issue with -no-canonical-prefix vs
-no-canonical-prefixes
and fix the typo with the target triples.


After seeing what the test failure was I have adjusted the tests as
appropriate.


ping.


ping ping.


The original patch to Tools.cpp was fine but the tests that were
written had issues, which should be fixed now. I am looking to be
able to re-commit the (updated) patch so Clang is no longer building
broken static binaries on OpenBSD.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits