]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR driver/81523: Make -static override -pie
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Aug 2017 22:06:21 +0000 (22:06 +0000)
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Aug 2017 22:06:21 +0000 (22:06 +0000)
-static and -pie together behave differently depending on whether GCC is
configured with --enable-default-pie.  On x86, "-static -pie" fails to
create executable when --enable-default-pie isn't used, but creates a
static executable when --enable-default-pie is used.  This patch makes
-static completely override -pie to create a static executable, regardless
if --enable-default-pie is used to configure GCC.

gcc/

PR driver/81523
* gcc.c (NO_PIE_SPEC): Delete.
(PIE_SPEC): Define as !no-pie/pie.  Move static|shared|r
exclusion..
(LINK_PIE_SPEC): ..to here.
(LINK_COMMAND_SPEC): Support -no-pie.
* config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Correct
chain of crtbegin*.o selection, update for PIE_SPEC changes and
format.
(GNU_USER_TARGET_ENDFILE_SPEC): Similarly.
* config/sol2.h (STARTFILE_CRTBEGIN_SPEC): Similarly.
(ENDFILE_CRTEND_SPEC): Similarly.

gcc/testsuite/

PR driver/81523
* gcc.dg/pie-7.c: New test.
* gcc.dg/pie-static-1.c: Likewise.
* gcc.dg/pie-static-2.c: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@250974 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/gnu-user.h
gcc/config/sol2.h
gcc/gcc.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pie-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pie-static-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pie-static-2.c [new file with mode: 0644]

index 321861a6d8c633978b56f381b90c31abfff54c22..448f98cf26ea52a2735ca084566c19ee0a479c0c 100644 (file)
@@ -1,3 +1,19 @@
+2017-08-08  Alan Modra  <amodra@gmail.com>
+           H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR driver/81523
+       * gcc.c (NO_PIE_SPEC): Delete.
+       (PIE_SPEC): Define as !no-pie/pie.  Move static|shared|r
+       exclusion..
+       (LINK_PIE_SPEC): ..to here.
+       (LINK_COMMAND_SPEC): Support -no-pie.
+       * config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Correct
+       chain of crtbegin*.o selection, update for PIE_SPEC changes and
+       format.
+       (GNU_USER_TARGET_ENDFILE_SPEC): Similarly.
+       * config/sol2.h (STARTFILE_CRTBEGIN_SPEC): Similarly.
+       (ENDFILE_CRTEND_SPEC): Similarly.
+
 2017-08-08  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/81708
index 2787a3d16be9e0cbbdcb49696213f496338d9a5f..de605b0c46657f37dfff2ee2cd1c575bbe880a03 100644 (file)
@@ -50,19 +50,28 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if defined HAVE_LD_PIE
 #define GNU_USER_TARGET_STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt1.o%s;: \
-    %{" PIE_SPEC ":Scrt1.o%s} %{" NO_PIE_SPEC ":crt1.o%s}}} \
-   crti.o%s %{static:crtbeginT.o%s;: %{shared:crtbeginS.o%s} \
-             %{" PIE_SPEC ":crtbeginS.o%s} \
-             %{" NO_PIE_SPEC ":crtbegin.o%s}} \
+  "%{shared:; \
+     pg|p|profile:gcrt1.o%s; \
+     static:crt1.o%s; \
+     " PIE_SPEC ":Scrt1.o%s; \
+     :crt1.o%s} \
+   crti.o%s \
+   %{static:crtbeginT.o%s; \
+     shared|" PIE_SPEC ":crtbeginS.o%s; \
+     :crtbegin.o%s} \
    %{fvtable-verify=none:%s; \
      fvtable-verify=preinit:vtv_start_preinit.o%s; \
      fvtable-verify=std:vtv_start.o%s} \
    " CRTOFFLOADBEGIN
 #else
 #define GNU_USER_TARGET_STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
+  "%{shared:; \
+     pg|p|profile:gcrt1.o%s; \
+     :crt1.o%s} \
+   crti.o%s \
+   %{static:crtbeginT.o%s; \
+     shared|pie:crtbeginS.o%s; \
+     :crtbegin.o%s} \
    %{fvtable-verify=none:%s; \
      fvtable-verify=preinit:vtv_start_preinit.o%s; \
      fvtable-verify=std:vtv_start.o%s} \
@@ -82,15 +91,20 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
   "%{fvtable-verify=none:%s; \
      fvtable-verify=preinit:vtv_end_preinit.o%s; \
      fvtable-verify=std:vtv_end.o%s} \
-   %{shared:crtendS.o%s;: %{" PIE_SPEC ":crtendS.o%s} \
-   %{" NO_PIE_SPEC ":crtend.o%s}} crtn.o%s \
+   %{static:crtend.o%s; \
+     shared|" PIE_SPEC ":crtendS.o%s; \
+     :crtend.o%s} \
+   crtn.o%s \
    " CRTOFFLOADEND
 #else
 #define GNU_USER_TARGET_ENDFILE_SPEC \
   "%{fvtable-verify=none:%s; \
      fvtable-verify=preinit:vtv_end_preinit.o%s; \
      fvtable-verify=std:vtv_end.o%s} \
-   %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s \
+   %{static:crtend.o%s; \
+     shared|pie:crtendS.o%s; \
+     :crtend.o%s} \
+   crtn.o%s \
    " CRTOFFLOADEND
 #endif
 #undef  ENDFILE_SPEC
index b8398d082a93cdbc92d8280044e2ed9f347ad741..bf5203b8c163783fae3e83d87c723c52d49bae35 100644 (file)
@@ -174,9 +174,9 @@ along with GCC; see the file COPYING3.  If not see
                            %{!ansi:values-Xa.o%s}"
 
 #if defined(HAVE_LD_PIE) && defined(HAVE_SOLARIS_CRTS)
-#define STARTFILE_CRTBEGIN_SPEC "%{shared:crtbeginS.o%s} \
-                                %{" PIE_SPEC ":crtbeginS.o%s} \
-                                %{" NO_PIE_SPEC ":crtbegin.o%s}"
+#define STARTFILE_CRTBEGIN_SPEC "%{static:crtbegin.o%s; \
+                                  shared|" PIE_SPEC ":crtbeginS.o%s; \
+                                  :crtbegin.o%s}"
 #else
 #define STARTFILE_CRTBEGIN_SPEC        "crtbegin.o%s"
 #endif
@@ -224,9 +224,9 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 
 #if defined(HAVE_LD_PIE) && defined(HAVE_SOLARIS_CRTS)
-#define ENDFILE_CRTEND_SPEC "%{shared:crtendS.o%s;: \
-                              %{" PIE_SPEC ":crtendS.o%s} \
-                              %{" NO_PIE_SPEC ":crtend.o%s}}"
+#define ENDFILE_CRTEND_SPEC "%{static:crtend.o%s; \
+                              shared|" PIE_SPEC ":crtendS.o%s; \
+                              :crtend.o%s}"
 #else
 #define ENDFILE_CRTEND_SPEC "crtend.o%s"
 #endif
index d8c5260e36b56b08d1f2cf046dac58c1cb1a5cd9..987eff55aa63abeed9a0d935c97816821fe2943d 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -878,8 +878,7 @@ proper position among the other output files.  */
 #endif
 
 #ifdef ENABLE_DEFAULT_PIE
-#define NO_PIE_SPEC            "no-pie|static"
-#define PIE_SPEC               NO_PIE_SPEC "|r|shared:;"
+#define PIE_SPEC               "!no-pie"
 #define NO_FPIE1_SPEC          "fno-pie"
 #define FPIE1_SPEC             NO_FPIE1_SPEC ":;"
 #define NO_FPIE2_SPEC          "fno-PIE"
@@ -900,7 +899,6 @@ proper position among the other output files.  */
 #define FPIE_OR_FPIC_SPEC      NO_FPIE_AND_FPIC_SPEC ":;"
 #else
 #define PIE_SPEC               "pie"
-#define NO_PIE_SPEC            PIE_SPEC "|r|shared:;"
 #define FPIE1_SPEC             "fpie"
 #define NO_FPIE1_SPEC          FPIE1_SPEC ":;"
 #define FPIE2_SPEC             "fPIE"
@@ -929,7 +927,7 @@ proper position among the other output files.  */
 #else
 #define LD_PIE_SPEC ""
 #endif
-#define LINK_PIE_SPEC "%{no-pie:} " "%{" PIE_SPEC ":" LD_PIE_SPEC "} "
+#define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
 #endif
 
 #ifndef LINK_BUILDID_SPEC
@@ -1017,8 +1015,10 @@ proper position among the other output files.  */
 #endif
 
 /* -u* was put back because both BSD and SysV seem to support it.  */
-/* %{static:} simply prevents an error message if the target machine
-   doesn't handle -static.  */
+/* %{static|no-pie:} simply prevents an error message:
+   1. If the target machine doesn't handle -static.
+   2. If PIE isn't enabled by default.
+ */
 /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
    scripts which exist in user specified directories, or in standard
    directories.  */
@@ -1035,7 +1035,7 @@ proper position among the other output files.  */
    "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
    "%X %{o*} %{e*} %{N} %{n} %{r}\
     %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} \
-    %{static:} %{L*} %(mfwrap) %(link_libgcc) " \
+    %{static|no-pie:} %{L*} %(mfwrap) %(link_libgcc) " \
     VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o " CHKP_SPEC " \
     %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
        %:include(libgomp.spec)%(link_gomp)}\
index 2ec22e8fdca4b4c525d36544c7ae305bd50db17b..23fbb8c3377b53ba3a493f7649cc6634ed0ef770 100644 (file)
@@ -1,3 +1,10 @@
+2017-08-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR driver/81523
+       * gcc.dg/pie-7.c: New test.
+       * gcc.dg/pie-static-1.c: Likewise.
+       * gcc.dg/pie-static-2.c: Likewise.
+
 2017-08-08  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/81708
diff --git a/gcc/testsuite/gcc.dg/pie-7.c b/gcc/testsuite/gcc.dg/pie-7.c
new file mode 100644 (file)
index 0000000..e118a98
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do run { target pie } } */
+/* { dg-options "-fno-pie -no-pie" } */
+
+int main(void)
+{
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/pie-static-1.c b/gcc/testsuite/gcc.dg/pie-static-1.c
new file mode 100644 (file)
index 0000000..f3580ef
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do run { target pie } } */
+/* { dg-options "-static -fpie -pie" } */
+
+int main(void)
+{
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/pie-static-2.c b/gcc/testsuite/gcc.dg/pie-static-2.c
new file mode 100644 (file)
index 0000000..49608c5
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do run { target pie } } */
+/* { dg-options "-fpie -pie -static" } */
+
+int main(void)
+{
+  return 0;
+}