]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Support PIE on Solaris
authorro <ro@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Sep 2015 09:00:22 +0000 (09:00 +0000)
committerro <ro@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 24 Sep 2015 09:00:22 +0000 (09:00 +0000)
gcc/testsuite:
* lib/target-supports.exp (check_effective_target_pie): Check for
PIE support on Solaris 11.x and 12.

libgcc:
* config.host (*-*-solaris2*): Add t-crtstuff-pic to tmake_file.
Add crtbeginS.o, crtendS.o to extra_parts if libgcc_cv_solaris_crts.
* config/sol2/gmon.c: (monstartup): Don't write trailing NUL of
messages.
(internal_mcount): Likewise.
* config/sol2/t-sol2 (crtp.o, crtpg.o, gmon.o): Compile with
crt_compile, add CRTSTUFF_T_CFLAGS_S.

gcc:
* configure.ac (gcc_cv_ld_pie): Check for gld >= 2.26 on Solaris.
Check for ld -type pie on Solaris 11.x and 12.
* configure: Regenerate.
* config.in: Regenerate.

* gcc.c (LD_PIE_SPEC): Allow redefinition.

* config/sol2.h (STARTFILE_CRTBEGIN_SPEC): Define.
(STARTFILE_SPEC): Use it.
(ENDFILE_CRTEND_SPEC): Define.
(ENDFILE_SPEC): Use it and ENDFILE_ARCH_SPEC.
(SUBTARGET_EXTRA_SPECS): Add STARTFILE_CRTBEGIN_SPEC,
ENDFILE_ARCH_SPEC, ENDFILE_CRTEND_SPEC.
[HAVE_LD_PIE && HAVE_SOLARIS_CRTS] (LD_PIE_SPEC): Define.
(!(HAVE_LD_PIE && HAVE_SOLARIS_CRTS)] (LINK_PIE_SPEC): Define.
* config/i386/sol2.h (ENDFILE_SPEC): Remove.
(ENDFILE_ARCH_SPEC): Define.
* config/sparc/sol2.h (ENDFILE_ARCH_SPEC): Define.

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

15 files changed:
gcc/ChangeLog
gcc/config.in
gcc/config/i386/sol2.h
gcc/config/sol2.h
gcc/config/sparc/sol2.h
gcc/configure
gcc/configure.ac
gcc/gcc.c
gcc/testsuite/ChangeLog
gcc/testsuite/lib/target-supports.exp
libgcc/ChangeLog
libgcc/config.host
libgcc/config.in
libgcc/config/sol2/gmon.c
libgcc/config/sol2/t-sol2

index e549506e6a9168eda053c9e8eefebe2adf7b7971..9c2ad9d5d2e8f1944a8587a04034912f8f633b22 100644 (file)
@@ -1,3 +1,24 @@
+2015-09-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
+
+       * configure.ac (gcc_cv_ld_pie): Check for gld >= 2.26 on Solaris.
+       Check for ld -type pie on Solaris 11.x and 12.
+       * configure: Regenerate.
+       * config.in: Regenerate.
+
+       * gcc.c (LD_PIE_SPEC): Allow redefinition.
+
+       * config/sol2.h (STARTFILE_CRTBEGIN_SPEC): Define.
+       (STARTFILE_SPEC): Use it.
+       (ENDFILE_CRTEND_SPEC): Define.
+       (ENDFILE_SPEC): Use it and ENDFILE_ARCH_SPEC.
+       (SUBTARGET_EXTRA_SPECS): Add STARTFILE_CRTBEGIN_SPEC,
+       ENDFILE_ARCH_SPEC, ENDFILE_CRTEND_SPEC.
+       [HAVE_LD_PIE && HAVE_SOLARIS_CRTS] (LD_PIE_SPEC): Define.
+       (!(HAVE_LD_PIE && HAVE_SOLARIS_CRTS)] (LINK_PIE_SPEC): Define.
+       * config/i386/sol2.h (ENDFILE_SPEC): Remove.
+       (ENDFILE_ARCH_SPEC): Define.
+       * config/sparc/sol2.h (ENDFILE_ARCH_SPEC): Define.
+
 2015-09-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * configure.ac (gcc_cv_solaris_crts): New test.
index a1987cc9bd9bdde9db85741c5bb557d350df2ef1..8556986ccfa29c0ef7cffb917842eef72821d8d5 100644 (file)
 #endif
 
 
-/* Define if your linker supports -pie option. */
+/* Define if your linker supports PIE option. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_LD_PIE
 #endif
index 9b725adc9df3b285b5116ce8f5fa03c768d9dc63..ed963f8920122299e16fc2f74613c732684ec23e 100644 (file)
@@ -86,13 +86,10 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 #endif
 
-#undef  ENDFILE_SPEC
-#define ENDFILE_SPEC \
-  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
-   %{mpc32:crtprec32.o%s} \
+#define ENDFILE_ARCH_SPEC \
+  "%{mpc32:crtprec32.o%s} \
    %{mpc64:crtprec64.o%s} \
-   %{mpc80:crtprec80.o%s} \
-   crtend.o%s crtn.o%s"
+   %{mpc80:crtprec80.o%s}"
 
 #define SUBTARGET_CPU_EXTRA_SPECS \
   { "cpp_subtarget",    CPP_SUBTARGET_SPEC },          \
index d31a25133766d8fcba8629e7bec647b0f4a91907..f444e48659db7d9cc039b13d8eb1e34fd0332217 100644 (file)
@@ -154,6 +154,14 @@ along with GCC; see the file COPYING3.  If not see
 #define STARTFILE_ARCH_SPEC "%{ansi:values-Xc.o%s} \
                            %{!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}"
+#else
+#define STARTFILE_CRTBEGIN_SPEC        "crtbegin.o%s"
+#endif
+
 /* We don't use the standard svr4 STARTFILE_SPEC because it's wrong for us.  */
 #undef STARTFILE_SPEC
 #ifdef HAVE_SOLARIS_CRTS
@@ -164,21 +172,27 @@ along with GCC; see the file COPYING3.  If not see
                          %{p:%e-p is not supported; \
                            pg:crtpg.o%s gmon.o%s; \
                              :crtp.o%s}}} \
-                       crti.o%s %(startfile_arch) \
-                       crtbegin.o%s"
+                       crti.o%s %(startfile_arch) %(startfile_crtbegin)"
 #else
 #define STARTFILE_SPEC "%{!shared:%{!symbolic: \
                          %{p:mcrt1.o%s; \
                             pg:gcrt1.o%s gmon.o%s; \
                               :crt1.o%s}}} \
-                       crti.o%s %(startfile_arch) \
-                       crtbegin.o%s"
+                       crti.o%s %(startfile_arch) %(startfile_crtbegin)"
+#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}}"
+#else
+#define ENDFILE_CRTEND_SPEC "crtend.o%s"
 #endif
 
 #undef  ENDFILE_SPEC
 #define ENDFILE_SPEC \
   "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
-   crtend.o%s crtn.o%s"
+   %(endfile_arch) %(endfile_crtend) crtn.o%s"
 
 #undef LINK_ARCH32_SPEC_BASE
 #define LINK_ARCH32_SPEC_BASE \
@@ -251,11 +265,14 @@ along with GCC; see the file COPYING3.  If not see
 
 #undef SUBTARGET_EXTRA_SPECS
 #define SUBTARGET_EXTRA_SPECS \
-  { "startfile_arch",   STARTFILE_ARCH_SPEC },         \
-  { "link_arch32",       LINK_ARCH32_SPEC },            \
-  { "link_arch64",       LINK_ARCH64_SPEC },            \
-  { "link_arch_default", LINK_ARCH_DEFAULT_SPEC },     \
-  { "link_arch",        LINK_ARCH_SPEC },              \
+  { "startfile_arch",          STARTFILE_ARCH_SPEC },          \
+  { "startfile_crtbegin",      STARTFILE_CRTBEGIN_SPEC },      \
+  { "link_arch32",             LINK_ARCH32_SPEC },             \
+  { "link_arch64",             LINK_ARCH64_SPEC },             \
+  { "link_arch_default",       LINK_ARCH_DEFAULT_SPEC },       \
+  { "link_arch",               LINK_ARCH_SPEC },               \
+  { "endfile_arch",            ENDFILE_ARCH_SPEC },            \
+  { "endfile_crtend",          ENDFILE_CRTEND_SPEC },  \
   SUBTARGET_CPU_EXTRA_SPECS
 
 /* C++11 programs need -lrt for nanosleep.  */
@@ -310,6 +327,20 @@ along with GCC; see the file COPYING3.  If not see
 #endif /* HAVE_LD_EH_FRAME && TARGET_DL_ITERATE_PHDR */
 #endif
 
+#if defined(HAVE_LD_PIE) && defined(HAVE_SOLARIS_CRTS)
+#ifdef USE_GLD
+/* Assert -z text by default to match Solaris ld.  */
+#define LD_PIE_SPEC "-pie %{!mimpure-text:-z text}"
+#else
+/* Solaris ld needs -z type=pie instead of -pie.  */
+#define LD_PIE_SPEC "-z type=pie %{mimpure-text:-z textoff}"
+#endif
+#else
+/* Error out if some part of PIE support is missing.  */
+#define LINK_PIE_SPEC \
+  "%{no-pie:} %{pie:%e-pie is not supported in this configuration} "
+#endif
+
 /* collect2.c can only parse GNU nm -n output.  Solaris nm needs -png to
    produce the same format.  */
 #define NM_FLAGS "-png"
index c169e7c69aa9e6f3e5f7fcec7afc8c0659f6ee9f..9912e8c517d66f112a16a277421dc350af148644 100644 (file)
@@ -280,6 +280,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 
 #define SUBTARGET_CPU_EXTRA_SPECS
 
+#define ENDFILE_ARCH_SPEC ""
+
 \f
 
 /* Register the Solaris-specific #pragma directives.  */
index a32bb64948d797a211a2e298ea542f58a01a85ea..608d2645c4cbb385e2debb3090b675fd45f67d85 100755 (executable)
@@ -27398,15 +27398,37 @@ $as_echo "$gcc_cv_ld_eh_frame_ciev3" >&6; }
 $as_echo_n "checking linker position independent executable support... " >&6; }
 gcc_cv_ld_pie=no
 if test $in_tree_ld = yes ; then
-  if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 15 -o "$gcc_cv_gld_major_version" -gt 2 \
+  case "$target" in
+    # Full PIE support on Solaris was only introduced in gld 2.26.
+    *-*-solaris2*)  gcc_gld_pie_min_version=26 ;;
+    *)                     gcc_gld_pie_min_version=15 ;;
+  esac
+  if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge "$gcc_gld_pie_min_version" -o "$gcc_cv_gld_major_version" -gt 2 \
      && test $in_tree_ld_is_elf = yes; then
     gcc_cv_ld_pie=yes
   fi
 elif test x$gcc_cv_ld != x; then
-       # Check if linker supports -pie option
-       if $gcc_cv_ld --help 2>/dev/null | grep -- -pie > /dev/null; then
-               gcc_cv_ld_pie=yes
+  # Check if linker supports -pie option
+  if $gcc_cv_ld --help 2>/dev/null | grep -- -pie > /dev/null; then
+    gcc_cv_ld_pie=yes
+    case "$target" in
+      *-*-solaris2*)
+       if echo "$ld_ver" | grep GNU > /dev/null \
+         && test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -lt 26; then
+         gcc_cv_ld_pie=no
        fi
+       ;;
+    esac
+  else
+    case "$target" in
+      *-*-solaris2.1[1-9]*)
+       # Solaris 11.x and Solaris 12 added PIE support.
+       if $gcc_cv_ld -z help 2>&1 | grep -- type.*pie > /dev/null; then
+         gcc_cv_ld_pie=yes
+       fi
+       ;;
+    esac
+  fi
 fi
 if test x"$gcc_cv_ld_pie" = xyes; then
 
index 4f8a44e51f140483da6a25583ada104931511222..65b5d704e3b74a19378b868018a0f3c4a61d6bca 100644 (file)
@@ -4751,19 +4751,41 @@ AC_MSG_RESULT($gcc_cv_ld_eh_frame_ciev3)
 AC_MSG_CHECKING(linker position independent executable support)
 gcc_cv_ld_pie=no
 if test $in_tree_ld = yes ; then
-  if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 15 -o "$gcc_cv_gld_major_version" -gt 2 \
+  case "$target" in
+    # Full PIE support on Solaris was only introduced in gld 2.26.
+    *-*-solaris2*)  gcc_gld_pie_min_version=26 ;;
+    *)                     gcc_gld_pie_min_version=15 ;;
+  esac
+  if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge "$gcc_gld_pie_min_version" -o "$gcc_cv_gld_major_version" -gt 2 \
      && test $in_tree_ld_is_elf = yes; then
     gcc_cv_ld_pie=yes
   fi
 elif test x$gcc_cv_ld != x; then
-       # Check if linker supports -pie option
-       if $gcc_cv_ld --help 2>/dev/null | grep -- -pie > /dev/null; then
-               gcc_cv_ld_pie=yes
+  # Check if linker supports -pie option
+  if $gcc_cv_ld --help 2>/dev/null | grep -- -pie > /dev/null; then
+    gcc_cv_ld_pie=yes
+    case "$target" in
+      *-*-solaris2*)
+       if echo "$ld_ver" | grep GNU > /dev/null \
+         && test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -lt 26; then
+         gcc_cv_ld_pie=no
        fi
+       ;;
+    esac
+  else
+    case "$target" in
+      *-*-solaris2.1[[1-9]]*)
+       # Solaris 11.x and Solaris 12 added PIE support.
+       if $gcc_cv_ld -z help 2>&1 | grep -- type.*pie > /dev/null; then
+         gcc_cv_ld_pie=yes
+       fi
+       ;;
+    esac
+  fi
 fi
 if test x"$gcc_cv_ld_pie" = xyes; then
        AC_DEFINE(HAVE_LD_PIE, 1,
-[Define if your linker supports -pie option.])
+[Define if your linker supports PIE option.])
 fi
 AC_MSG_RESULT($gcc_cv_ld_pie)
 
index ef132d6fecef34cd31b4c9ab0d4e7f9c749e7776..55a725583b87406e79c4f470d80fc0502e122d00 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -909,7 +909,9 @@ proper position among the other output files.  */
 
 #ifndef LINK_PIE_SPEC
 #ifdef HAVE_LD_PIE
+#ifndef LD_PIE_SPEC
 #define LD_PIE_SPEC "-pie"
+#endif
 #else
 #define LD_PIE_SPEC ""
 #endif
index c9ffa70d5adc6525e9e018977ac80384f3d214b3..68f4100e2758830f3571af99ed06c152e0930ce3 100644 (file)
@@ -1,3 +1,8 @@
+2015-09-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
+
+       * lib/target-supports.exp (check_effective_target_pie): Check for
+       PIE support on Solaris 11.x and 12.
+
 2015-09-24  Richard Biener  <rguenther@suse.de>
 
        * g++.dg/tree-ssa/restrict3.C: New testcase.
index 3088369ff0b447a922c305d89530c75354dee9cf..82697f4e4df4ff24c09a625e0692a1f89b5fe817 100644 (file)
@@ -1046,6 +1046,13 @@ proc check_effective_target_pie { } {
         || [istarget *-*-gnu*] } {
        return 1;
     }
+    if { [istarget *-*-solaris2.1\[1-9\]*] } {
+       # Full PIE support was added in Solaris 11.x and Solaris 12, but gcc
+       # errors out if missing, so check for that.
+       return [check_no_compiler_messages pie executable {
+           int main (void) { return 0; }
+       } "-pie -fpie"]
+    }
     return 0
 }
 
index 559f7726f7fb41b2036d565576b4ed13cb43fb1f..cc5c2c3903b1e4301f6c757e5f1721bbe83621b7 100644 (file)
@@ -1,3 +1,13 @@
+2015-09-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
+
+       * config.host (*-*-solaris2*): Add t-crtstuff-pic to tmake_file.
+       Add crtbeginS.o, crtendS.o to extra_parts if libgcc_cv_solaris_crts.
+       * config/sol2/gmon.c: (monstartup): Don't write trailing NUL of
+       messages.
+       (internal_mcount): Likewise.
+       * config/sol2/t-sol2 (crtp.o, crtpg.o, gmon.o): Compile with
+       crt_compile, add CRTSTUFF_T_CFLAGS_S.
+
 2015-09-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * configure.ac (libgcc_cv_solaris_crts): New test.
index 6c8b97bfc013cc4c13697ed5f1140ab21f5e2984..2c6475625c9cb830b9a9d8598f406a5a03fa3793 100644 (file)
@@ -267,7 +267,7 @@ case ${host} in
 *-*-solaris2*)
   # Unless linker support and dl_iterate_phdr are present,
   # unwind-dw2-fde-dip.c automatically falls back to unwind-dw2-fde.c.
-  tmake_file="$tmake_file sol2/t-sol2 t-eh-dw2-dip t-libgcc-pic t-slibgcc t-slibgcc-elf-ver"
+  tmake_file="$tmake_file sol2/t-sol2 t-eh-dw2-dip t-crtstuff-pic t-libgcc-pic t-slibgcc t-slibgcc-elf-ver"
   if test $with_gnu_ld = yes; then
     tmake_file="$tmake_file t-slibgcc-gld"
   else
@@ -280,6 +280,8 @@ case ${host} in
     # Solaris 11.x and 12 provide crt1.o, crti.o, and crtn.o as part of the
     # base system.  crtp.o and crtpg.o implement the compiler-dependent parts.
     extra_parts="$extra_parts crtp.o crtpg.o"
+    # If the Solaris CRTs are present, both ld and gld will have PIE support.
+    extra_parts="$extra_parts crtbeginS.o crtendS.o"
   else
     case ${host} in
       i?86-*-solaris2.1[0-9]* | x86_64-*-solaris2.1[0-9]*)
index 25aa0d93bab8660e2e836caab1565860dee94ea9..4d33411e40857ffaa6448c14a385852f78c55d9f 100644 (file)
@@ -21,6 +21,9 @@
 /* Define if the system-provided CRTs are present on Solaris. */
 #undef HAVE_SOLARIS_CRTS
 
+/* Define if the system-provided CRTs are present on Solaris. */
+#undef HAVE_SOLARIS_CRTS
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
index f6419580a9660ce36e878ae616f603cc43d7c489..81a03468b6eae781ed9fc3e8adea600c98af8dcc 100644 (file)
@@ -114,12 +114,12 @@ monstartup (char *lowpc, char *highpc)
   monsize = (s_textsize / HISTFRACTION) + sizeof (struct phdr);
   buffer = sbrk (monsize);
   if (buffer == (void *) -1) {
-    write (STDERR_FILENO, MSG, sizeof (MSG));
+    write (STDERR_FILENO, MSG, sizeof (MSG) - 1);
     return;
   }
   froms = sbrk (s_textsize / HASHFRACTION);
   if (froms == (void *) -1) {
-    write (STDERR_FILENO, MSG, sizeof (MSG));
+    write (STDERR_FILENO, MSG, sizeof (MSG) - 1);
     froms = NULL;
     return;
   }
@@ -131,7 +131,7 @@ monstartup (char *lowpc, char *highpc)
   }
   tos = sbrk (tolimit * sizeof (struct tostruct));
   if (tos == (void *) -1) {
-    write (STDERR_FILENO, MSG, sizeof (MSG));
+    write (STDERR_FILENO, MSG, sizeof (MSG) - 1);
     froms = NULL;
     tos = NULL;
     return;
@@ -429,7 +429,7 @@ internal_mcount (char *selfpc, unsigned short *frompcindex)
   profiling++;
 
 #define        TOLIMIT "mcount: tos overflow\n"
-  write (STDERR_FILENO, TOLIMIT, sizeof (TOLIMIT));
+  write (STDERR_FILENO, TOLIMIT, sizeof (TOLIMIT) - 1);
   goto out;
 }
 
index 1f7324af21b8084a967df3afc54877411d486fb5..75b05883b14e9478eb42171c9e1f7d4e040639d3 100644 (file)
 
 # crtp, crtpg build rules
 crtp.o: $(srcdir)/config/sol2/crtp.c
-       $(gcc_compile) -c $<
+       $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $<
 crtpg.o: $(srcdir)/config/sol2/crtpg.c
-       $(gcc_compile) -c $<
+       $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $<
 
 # gmon build rule
 gmon.o:        $(srcdir)/config/sol2/gmon.c
-       $(gcc_compile) -c $<
+       $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $<
 
 # Assemble startup files.
 crt1.o: $(srcdir)/config/$(cpu_type)/sol2-c1.S