0012-static-pie.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. From 913497c615c1e3708f4c532301010e1a6164da0d 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/13] 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/gcc.c | 6 +++---
  14. 3 files changed, 10 insertions(+), 12 deletions(-)
  15. diff --git a/gcc/common.opt b/gcc/common.opt
  16. index d342c4f3749..2aae4a3cefb 100644
  17. --- a/gcc/common.opt
  18. +++ b/gcc/common.opt
  19. @@ -3287,11 +3287,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 055a4f0afec..7a671c6a49c 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. @@ -76,8 +75,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  52. "%{fvtable-verify=none:%s; \
  53. fvtable-verify=preinit:vtv_end_preinit.o%s; \
  54. fvtable-verify=std:vtv_end.o%s} \
  55. - %{static:crtend.o%s; \
  56. - shared|static-pie|" PIE_SPEC ":crtendS.o%s; \
  57. + %{shared|" PIE_SPEC ":crtendS.o%s; \
  58. :crtend.o%s} " \
  59. GNU_USER_TARGET_CRTN " " \
  60. CRTOFFLOADEND
  61. @@ -106,7 +104,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  62. #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
  63. #if defined(HAVE_LD_EH_FRAME_HDR)
  64. -#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
  65. +#define LINK_EH_SPEC "%{!static|" PIE_SPEC ":--eh-frame-hdr} "
  66. #endif
  67. #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \
  68. diff --git a/gcc/gcc.c b/gcc/gcc.c
  69. index d185c01b257..5d3f81c5fc5 100644
  70. --- a/gcc/gcc.c
  71. +++ b/gcc/gcc.c
  72. @@ -908,7 +908,7 @@ proper position among the other output files. */
  73. #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC
  74. #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;"
  75. #else
  76. -#define PIE_SPEC "pie"
  77. +#define PIE_SPEC "pie|static-pie"
  78. #define FPIE1_SPEC "fpie"
  79. #define NO_FPIE1_SPEC FPIE1_SPEC ":;"
  80. #define FPIE2_SPEC "fPIE"
  81. @@ -932,12 +932,12 @@ proper position among the other output files. */
  82. #ifndef LINK_PIE_SPEC
  83. #ifdef HAVE_LD_PIE
  84. #ifndef LD_PIE_SPEC
  85. -#define LD_PIE_SPEC "-pie"
  86. +#define LD_PIE_SPEC "-pie %{static|static-pie:--no-dynamic-linker -z text -Bsymbolic}"
  87. #endif
  88. #else
  89. #define LD_PIE_SPEC ""
  90. #endif
  91. -#define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
  92. +#define LINK_PIE_SPEC "%{shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} "
  93. #endif
  94. #ifndef LINK_BUILDID_SPEC
  95. --
  96. 2.21.0