0012-static-pie.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. From a4aa319f7c19e564dced3daeb7222c9315af936c 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 12/12] 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 | 12 +++++-------
  13. gcc/config/rs6000/sysv4.h | 11 +++++------
  14. gcc/gcc.c | 6 +++---
  15. 4 files changed, 15 insertions(+), 18 deletions(-)
  16. diff --git a/gcc/common.opt b/gcc/common.opt
  17. index b52ef0b38c8..0ce5857e01d 100644
  18. --- a/gcc/common.opt
  19. +++ b/gcc/common.opt
  20. @@ -3197,11 +3197,11 @@ Driver
  21. no-pie
  22. Driver RejectNegative Negative(shared)
  23. -Don't create a dynamically linked position independent executable.
  24. +Don't create a position independent executable.
  25. pie
  26. Driver RejectNegative Negative(no-pie)
  27. -Create a dynamically linked position independent executable.
  28. +Create a position independent executable.
  29. static-pie
  30. Driver RejectNegative Negative(pie)
  31. diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
  32. index 8620de3e42d..235328a2642 100644
  33. --- a/gcc/config/gnu-user.h
  34. +++ b/gcc/config/gnu-user.h
  35. @@ -52,13 +52,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  36. #define GNU_USER_TARGET_STARTFILE_SPEC \
  37. "%{shared:; \
  38. pg|p|profile:%{static-pie:grcrt1.o%s;:gcrt1.o%s}; \
  39. - static:crt1.o%s; \
  40. - static-pie:rcrt1.o%s; \
  41. + static|static-pie:%{" PIE_SPEC ":rcrt1.o%s;:crt1.o%s}; \
  42. " PIE_SPEC ":Scrt1.o%s; \
  43. :crt1.o%s} \
  44. crti.o%s \
  45. - %{static:crtbeginT.o%s; \
  46. - shared|static-pie|" PIE_SPEC ":crtbeginS.o%s; \
  47. + %{shared|" PIE_SPEC ":crtbeginS.o%s; \
  48. + static:crtbeginT.o%s; \
  49. :crtbegin.o%s} \
  50. %{fvtable-verify=none:%s; \
  51. fvtable-verify=preinit:vtv_start_preinit.o%s; \
  52. @@ -92,8 +91,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  53. "%{fvtable-verify=none:%s; \
  54. fvtable-verify=preinit:vtv_end_preinit.o%s; \
  55. fvtable-verify=std:vtv_end.o%s} \
  56. - %{static:crtend.o%s; \
  57. - shared|static-pie|" PIE_SPEC ":crtendS.o%s; \
  58. + %{shared|" PIE_SPEC ":crtendS.o%s; \
  59. :crtend.o%s} \
  60. crtn.o%s \
  61. " CRTOFFLOADEND
  62. @@ -133,7 +131,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  63. #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
  64. #if defined(HAVE_LD_EH_FRAME_HDR)
  65. -#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
  66. +#define LINK_EH_SPEC "%{!static|" PIE_SPEC ":--eh-frame-hdr} "
  67. #endif
  68. #undef LINK_GCC_C_SEQUENCE_SPEC
  69. diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
  70. index bb19d0dcd41..bb2a2324eb0 100644
  71. --- a/gcc/config/rs6000/sysv4.h
  72. +++ b/gcc/config/rs6000/sysv4.h
  73. @@ -763,12 +763,12 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
  74. #define STARTFILE_LINUX_SPEC \
  75. "%{shared:; \
  76. pg|p|profile:gcrt1.o%s; \
  77. - static:crt1.o%s; \
  78. - static-pie|" PIE_SPEC ":Scrt1.o%s; \
  79. + static|static-pie:%{" PIE_SPEC ":rcrt1.o%s;:crt1.o%s}; \
  80. + " PIE_SPEC ":Scrt1.o%s; \
  81. :crt1.o%s} \
  82. %{mnewlib:ecrti.o%s;:crti.o%s} \
  83. - %{static:crtbeginT.o%s; \
  84. - shared|static-pie|" PIE_SPEC ":crtbeginS.o%s; \
  85. + %{shared|" PIE_SPEC ":crtbeginS.o%s; \
  86. + static:crtbeginT.o%s; \
  87. :crtbegin.o%s} \
  88. %{fvtable-verify=none:%s; \
  89. fvtable-verify=preinit:vtv_start_preinit.o%s; \
  90. @@ -781,8 +781,7 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
  91. "%{fvtable-verify=none:%s; \
  92. fvtable-verify=preinit:vtv_end_preinit.o%s; \
  93. fvtable-verify=std:vtv_end.o%s} \
  94. - %{static:crtend.o%s; \
  95. - shared|static-pie|" PIE_SPEC ":crtendS.o%s; \
  96. + %{shared|" PIE_SPEC ":crtendS.o%s; \
  97. :crtend.o%s} \
  98. %{mnewlib:ecrtn.o%s;:crtn.o%s} \
  99. " CRTOFFLOADEND
  100. diff --git a/gcc/gcc.c b/gcc/gcc.c
  101. index eb1610ba8b0..87560afb03c 100644
  102. --- a/gcc/gcc.c
  103. +++ b/gcc/gcc.c
  104. @@ -900,7 +900,7 @@ proper position among the other output files. */
  105. #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
  106. #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
  107. #else
  108. -#define PIE_SPEC "pie"
  109. +#define PIE_SPEC "pie|static-pie"
  110. #define FPIE1_SPEC "fpie"
  111. #define NO_FPIE1_SPEC FPIE1_SPEC ":;"
  112. #define FPIE2_SPEC "fPIE"
  113. @@ -924,12 +924,12 @@ proper position among the other output files. */
  114. #ifndef LINK_PIE_SPEC
  115. #ifdef HAVE_LD_PIE
  116. #ifndef LD_PIE_SPEC
  117. -#define LD_PIE_SPEC "-pie"
  118. +#define LD_PIE_SPEC "-pie %{static|static-pie:--no-dynamic-linker -z text -Bsymbolic}"
  119. #endif
  120. #else
  121. #define LD_PIE_SPEC ""
  122. #endif
  123. -#define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
  124. +#define LINK_PIE_SPEC "%{shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
  125. #endif
  126. #ifndef LINK_BUILDID_SPEC
  127. --
  128. 2.17.1