0004-static-pie.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. From f2dc7594a780d945fc5b1532ab9609cf1d735457 Mon Sep 17 00:00:00 2001
  2. From: Szabolcs Nagy <nsz@port70.net>
  3. Date: Sat, 18 Aug 2018 23:58:45 +0000
  4. Subject: [PATCH 4/5] static-pie
  5. in gcc-8 -static means static non-pie, even if -pie or -static-pie
  6. are specified, -static-pie can be used to build static pie.
  7. in musl toolchains -static -pie always meant static pie, so this
  8. patch fixes the link specs accordingly, the new -static-pie is just
  9. an alias to -static -pie.
  10. ---
  11. gcc/common.opt | 4 ++--
  12. gcc/config/gnu-user.h | 17 ++++++++---------
  13. gcc/gcc.c | 6 +++---
  14. 3 files changed, 13 insertions(+), 14 deletions(-)
  15. diff --git a/gcc/common.opt b/gcc/common.opt
  16. index a75b44ee47e..7c564818b49 100644
  17. --- a/gcc/common.opt
  18. +++ b/gcc/common.opt
  19. @@ -3473,11 +3473,11 @@ Driver
  20. no-pie
  21. Driver RejectNegative Negative(shared)
  22. -Don't create a dynamically linked position independent executable.
  23. +Don't create a position independent executable.
  24. pie
  25. Driver RejectNegative Negative(no-pie)
  26. -Create a dynamically linked position independent executable.
  27. +Create a position independent executable.
  28. static-pie
  29. Driver RejectNegative Negative(pie)
  30. diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
  31. index 5ebbf42a13d..bb907d8e89a 100644
  32. --- a/gcc/config/gnu-user.h
  33. +++ b/gcc/config/gnu-user.h
  34. @@ -51,13 +51,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  35. #define GNU_USER_TARGET_STARTFILE_SPEC \
  36. "%{shared:; \
  37. pg|p|profile:%{static-pie:grcrt1.o%s;:gcrt1.o%s}; \
  38. - static:crt1.o%s; \
  39. - static-pie:rcrt1.o%s; \
  40. + static|static-pie:%{" PIE_SPEC ":rcrt1.o%s;:crt1.o%s}; \
  41. " PIE_SPEC ":Scrt1.o%s; \
  42. :crt1.o%s} " \
  43. GNU_USER_TARGET_CRTI " \
  44. - %{static:crtbeginT.o%s; \
  45. - shared|static-pie|" PIE_SPEC ":crtbeginS.o%s; \
  46. + %{shared|" PIE_SPEC ":crtbeginS.o%s; \
  47. + static:crtbeginT.o%s; \
  48. :crtbegin.o%s} \
  49. %{fvtable-verify=none:%s; \
  50. fvtable-verify=preinit:vtv_start_preinit.o%s; \
  51. @@ -73,11 +72,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  52. GNU userspace "finalizer" file, `crtn.o'. */
  53. #define GNU_USER_TARGET_ENDFILE_SPEC \
  54. - "%{!static:%{fvtable-verify=none:%s; \
  55. + "%{static|static-pie:; \
  56. + fvtable-verify=none:%s; \
  57. fvtable-verify=preinit:vtv_end_preinit.o%s; \
  58. - fvtable-verify=std:vtv_end.o%s}} \
  59. - %{static:crtend.o%s; \
  60. - shared|static-pie|" PIE_SPEC ":crtendS.o%s; \
  61. + fvtable-verify=std:vtv_end.o%s} \
  62. + %{shared|" PIE_SPEC ":crtendS.o%s; \
  63. :crtend.o%s} " \
  64. GNU_USER_TARGET_CRTN " " \
  65. CRTOFFLOADEND
  66. @@ -106,7 +105,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  67. #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
  68. #if defined(HAVE_LD_EH_FRAME_HDR)
  69. -#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
  70. +#define LINK_EH_SPEC "%{!static|" PIE_SPEC ":--eh-frame-hdr} "
  71. #endif
  72. #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \
  73. diff --git a/gcc/gcc.c b/gcc/gcc.c
  74. index 3c81c5798d8..cd96eac5d12 100644
  75. --- a/gcc/gcc.c
  76. +++ b/gcc/gcc.c
  77. @@ -1010,7 +1010,7 @@ proper position among the other output files. */
  78. #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
  79. #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
  80. #else
  81. -#define PIE_SPEC "pie"
  82. +#define PIE_SPEC "pie|static-pie"
  83. #define FPIE1_SPEC "fpie"
  84. #define NO_FPIE1_SPEC FPIE1_SPEC ":;"
  85. #define FPIE2_SPEC "fPIE"
  86. @@ -1034,12 +1034,12 @@ proper position among the other output files. */
  87. #ifndef LINK_PIE_SPEC
  88. #ifdef HAVE_LD_PIE
  89. #ifndef LD_PIE_SPEC
  90. -#define LD_PIE_SPEC "-pie"
  91. +#define LD_PIE_SPEC "-pie %{static|static-pie:--no-dynamic-linker -z text -Bsymbolic}"
  92. #endif
  93. #else
  94. #define LD_PIE_SPEC ""
  95. #endif
  96. -#define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
  97. +#define LINK_PIE_SPEC "%{shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
  98. #endif
  99. #ifndef LINK_BUILDID_SPEC
  100. --
  101. 2.31.1