0001-staticpie.diff 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
  2. index bd4b576..41803c2 100644
  3. --- a/bfd/elf32-arm.c
  4. +++ b/bfd/elf32-arm.c
  5. @@ -13786,7 +13786,7 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
  6. if (elf_hash_table (info)->dynamic_sections_created)
  7. {
  8. /* Set the contents of the .interp section to the interpreter. */
  9. - if (info->executable)
  10. + if (info->executable && !info->nointerp)
  11. {
  12. s = bfd_get_linker_section (dynobj, ".interp");
  13. BFD_ASSERT (s != NULL);
  14. diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
  15. index 49ef360..8346d57 100644
  16. --- a/bfd/elf32-bfin.c
  17. +++ b/bfd/elf32-bfin.c
  18. @@ -4257,7 +4257,7 @@ elf32_bfinfdpic_size_dynamic_sections (bfd *output_bfd,
  19. if (htab->dynamic_sections_created)
  20. {
  21. /* Set the contents of the .interp section to the interpreter. */
  22. - if (info->executable)
  23. + if (info->executable && !info->nointerp)
  24. {
  25. s = bfd_get_linker_section (dynobj, ".interp");
  26. BFD_ASSERT (s != NULL);
  27. diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c
  28. index 3031173..5b40524 100644
  29. --- a/bfd/elf32-cris.c
  30. +++ b/bfd/elf32-cris.c
  31. @@ -3764,7 +3764,7 @@ elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  32. if (elf_hash_table (info)->dynamic_sections_created)
  33. {
  34. /* Set the contents of the .interp section to the interpreter. */
  35. - if (info->executable)
  36. + if (info->executable && !info->nointerp)
  37. {
  38. s = bfd_get_linker_section (dynobj, ".interp");
  39. BFD_ASSERT (s != NULL);
  40. diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c
  41. index b55a7ab..ef72c23 100644
  42. --- a/bfd/elf32-frv.c
  43. +++ b/bfd/elf32-frv.c
  44. @@ -5444,7 +5444,7 @@ elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
  45. if (elf_hash_table (info)->dynamic_sections_created)
  46. {
  47. /* Set the contents of the .interp section to the interpreter. */
  48. - if (info->executable)
  49. + if (info->executable && !info->nointerp)
  50. {
  51. s = bfd_get_linker_section (dynobj, ".interp");
  52. BFD_ASSERT (s != NULL);
  53. diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
  54. index 41bf5c5..62c7cf6 100644
  55. --- a/bfd/elf32-hppa.c
  56. +++ b/bfd/elf32-hppa.c
  57. @@ -2215,7 +2215,7 @@ elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  58. if (htab->etab.dynamic_sections_created)
  59. {
  60. /* Set the contents of the .interp section to the interpreter. */
  61. - if (info->executable)
  62. + if (info->executable && !info->nointerp)
  63. {
  64. sec = bfd_get_linker_section (dynobj, ".interp");
  65. if (sec == NULL)
  66. diff --git a/bfd/elf32-i370.c b/bfd/elf32-i370.c
  67. index 7fba4d1..458f694 100644
  68. --- a/bfd/elf32-i370.c
  69. +++ b/bfd/elf32-i370.c
  70. @@ -594,7 +594,7 @@ i370_elf_size_dynamic_sections (bfd *output_bfd,
  71. if (elf_hash_table (info)->dynamic_sections_created)
  72. {
  73. /* Set the contents of the .interp section to the interpreter. */
  74. - if (info->executable)
  75. + if (info->executable && !info->nointerp)
  76. {
  77. s = bfd_get_linker_section (dynobj, ".interp");
  78. BFD_ASSERT (s != NULL);
  79. diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
  80. index 7642d0f..b0844c8 100644
  81. --- a/bfd/elf32-i386.c
  82. +++ b/bfd/elf32-i386.c
  83. @@ -2834,7 +2834,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
  84. if (htab->elf.dynamic_sections_created)
  85. {
  86. /* Set the contents of the .interp section to the interpreter. */
  87. - if (info->executable)
  88. + if (info->executable && !info->nointerp)
  89. {
  90. s = bfd_get_linker_section (dynobj, ".interp");
  91. if (s == NULL)
  92. diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
  93. index 155d079..a2e3c7c 100644
  94. --- a/bfd/elf32-m32r.c
  95. +++ b/bfd/elf32-m32r.c
  96. @@ -2170,7 +2170,7 @@ m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  97. if (htab->root.dynamic_sections_created)
  98. {
  99. /* Set the contents of the .interp section to the interpreter. */
  100. - if (info->executable)
  101. + if (info->executable && !info->nointerp)
  102. {
  103. s = bfd_get_linker_section (dynobj, ".interp");
  104. BFD_ASSERT (s != NULL);
  105. diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
  106. index 10d2fcb..489f3f1 100644
  107. --- a/bfd/elf32-m68k.c
  108. +++ b/bfd/elf32-m68k.c
  109. @@ -3257,7 +3257,7 @@ elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  110. if (elf_hash_table (info)->dynamic_sections_created)
  111. {
  112. /* Set the contents of the .interp section to the interpreter. */
  113. - if (info->executable)
  114. + if (info->executable && !info->nointerp)
  115. {
  116. s = bfd_get_linker_section (dynobj, ".interp");
  117. BFD_ASSERT (s != NULL);
  118. diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
  119. index 8415f1e..5597051 100644
  120. --- a/bfd/elf32-ppc.c
  121. +++ b/bfd/elf32-ppc.c
  122. @@ -6191,7 +6191,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
  123. if (elf_hash_table (info)->dynamic_sections_created)
  124. {
  125. /* Set the contents of the .interp section to the interpreter. */
  126. - if (info->executable)
  127. + if (info->executable && !info->nointerp)
  128. {
  129. s = bfd_get_linker_section (htab->elf.dynobj, ".interp");
  130. BFD_ASSERT (s != NULL);
  131. diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
  132. index de37ca4..a1e628c 100644
  133. --- a/bfd/elf32-s390.c
  134. +++ b/bfd/elf32-s390.c
  135. @@ -2039,7 +2039,7 @@ elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  136. if (htab->elf.dynamic_sections_created)
  137. {
  138. /* Set the contents of the .interp section to the interpreter. */
  139. - if (info->executable)
  140. + if (info->executable && !info->nointerp)
  141. {
  142. s = bfd_get_linker_section (dynobj, ".interp");
  143. if (s == NULL)
  144. diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
  145. index 012ee4e..a51453f 100644
  146. --- a/bfd/elf32-sh.c
  147. +++ b/bfd/elf32-sh.c
  148. @@ -3349,7 +3349,7 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  149. if (htab->root.dynamic_sections_created)
  150. {
  151. /* Set the contents of the .interp section to the interpreter. */
  152. - if (info->executable)
  153. + if (info->executable && !info->nointerp)
  154. {
  155. s = bfd_get_linker_section (dynobj, ".interp");
  156. BFD_ASSERT (s != NULL);
  157. diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c
  158. index 6089e8c..893ea8d 100644
  159. --- a/bfd/elf32-vax.c
  160. +++ b/bfd/elf32-vax.c
  161. @@ -1124,7 +1124,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
  162. if (elf_hash_table (info)->dynamic_sections_created)
  163. {
  164. /* Set the contents of the .interp section to the interpreter. */
  165. - if (info->executable)
  166. + if (info->executable && !info->nointerp)
  167. {
  168. s = bfd_get_linker_section (dynobj, ".interp");
  169. BFD_ASSERT (s != NULL);
  170. diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
  171. index 73538cd..37ea5da 100644
  172. --- a/bfd/elf32-xtensa.c
  173. +++ b/bfd/elf32-xtensa.c
  174. @@ -1637,7 +1637,7 @@ elf_xtensa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  175. && htab->sgotloc != NULL);
  176. /* Set the contents of the .interp section to the interpreter. */
  177. - if (info->executable)
  178. + if (info->executable && !info->nointerp)
  179. {
  180. s = bfd_get_linker_section (dynobj, ".interp");
  181. if (s == NULL)
  182. diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
  183. index f67b0af..1973cd0 100644
  184. --- a/bfd/elf64-alpha.c
  185. +++ b/bfd/elf64-alpha.c
  186. @@ -2877,7 +2877,7 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  187. if (elf_hash_table (info)->dynamic_sections_created)
  188. {
  189. /* Set the contents of the .interp section to the interpreter. */
  190. - if (info->executable)
  191. + if (info->executable && !info->nointerp)
  192. {
  193. s = bfd_get_linker_section (dynobj, ".interp");
  194. BFD_ASSERT (s != NULL);
  195. diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
  196. index 6f40b88..3b628b4 100644
  197. --- a/bfd/elf64-hppa.c
  198. +++ b/bfd/elf64-hppa.c
  199. @@ -1558,7 +1558,7 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
  200. if (elf_hash_table (info)->dynamic_sections_created)
  201. {
  202. /* Set the contents of the .interp section to the interpreter. */
  203. - if (info->executable)
  204. + if (info->executable && !info->nointerp)
  205. {
  206. sec = bfd_get_linker_section (dynobj, ".interp");
  207. BFD_ASSERT (sec != NULL);
  208. diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
  209. index 8cff990..851845f 100644
  210. --- a/bfd/elf64-ppc.c
  211. +++ b/bfd/elf64-ppc.c
  212. @@ -9748,7 +9748,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
  213. if (htab->elf.dynamic_sections_created)
  214. {
  215. /* Set the contents of the .interp section to the interpreter. */
  216. - if (info->executable)
  217. + if (info->executable && !info->nointerp)
  218. {
  219. s = bfd_get_linker_section (dynobj, ".interp");
  220. if (s == NULL)
  221. diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
  222. index 2e505f3..406bb66 100644
  223. --- a/bfd/elf64-s390.c
  224. +++ b/bfd/elf64-s390.c
  225. @@ -1989,7 +1989,7 @@ elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  226. if (htab->elf.dynamic_sections_created)
  227. {
  228. /* Set the contents of the .interp section to the interpreter. */
  229. - if (info->executable)
  230. + if (info->executable && !info->nointerp)
  231. {
  232. s = bfd_get_linker_section (dynobj, ".interp");
  233. if (s == NULL)
  234. diff --git a/bfd/elf64-sh64.c b/bfd/elf64-sh64.c
  235. index e460895..d920598 100644
  236. --- a/bfd/elf64-sh64.c
  237. +++ b/bfd/elf64-sh64.c
  238. @@ -3404,7 +3404,7 @@ sh64_elf64_size_dynamic_sections (bfd *output_bfd,
  239. if (elf_hash_table (info)->dynamic_sections_created)
  240. {
  241. /* Set the contents of the .interp section to the interpreter. */
  242. - if (info->executable)
  243. + if (info->executable && !info->nointerp)
  244. {
  245. s = bfd_get_linker_section (dynobj, ".interp");
  246. BFD_ASSERT (s != NULL);
  247. diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
  248. index f15d33e..870aadf 100644
  249. --- a/bfd/elf64-x86-64.c
  250. +++ b/bfd/elf64-x86-64.c
  251. @@ -3181,7 +3181,7 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd,
  252. if (htab->elf.dynamic_sections_created)
  253. {
  254. /* Set the contents of the .interp section to the interpreter. */
  255. - if (info->executable)
  256. + if (info->executable && !info->nointerp)
  257. {
  258. s = bfd_get_linker_section (dynobj, ".interp");
  259. if (s == NULL)
  260. diff --git a/bfd/elflink.c b/bfd/elflink.c
  261. index 7f04271..5b3438d 100644
  262. --- a/bfd/elflink.c
  263. +++ b/bfd/elflink.c
  264. @@ -246,7 +246,7 @@ _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
  265. /* A dynamically linked executable has a .interp section, but a
  266. shared library does not. */
  267. - if (info->executable)
  268. + if (info->executable && !info->nointerp)
  269. {
  270. s = bfd_make_section_anyway_with_flags (abfd, ".interp",
  271. flags | SEC_READONLY);
  272. @@ -5763,7 +5763,7 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
  273. bfd_boolean all_defined;
  274. *sinterpptr = bfd_get_section_by_name (dynobj, ".interp");
  275. - BFD_ASSERT (*sinterpptr != NULL || !info->executable);
  276. + BFD_ASSERT (*sinterpptr != NULL || !info->executable || info->nointerp);
  277. if (soname != NULL)
  278. {
  279. diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
  280. index be1e59a..329dec3 100644
  281. --- a/bfd/elfxx-mips.c
  282. +++ b/bfd/elfxx-mips.c
  283. @@ -9579,7 +9579,7 @@ _bfd_mips_elf_size_dynamic_sections (bfd *output_bfd,
  284. if (elf_hash_table (info)->dynamic_sections_created)
  285. {
  286. /* Set the contents of the .interp section to the interpreter. */
  287. - if (info->executable)
  288. + if (info->executable && !info->nointerp)
  289. {
  290. s = bfd_get_linker_section (dynobj, ".interp");
  291. BFD_ASSERT (s != NULL);
  292. diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c
  293. index 9bb71a9..db0d4f1 100644
  294. --- a/bfd/elfxx-sparc.c
  295. +++ b/bfd/elfxx-sparc.c
  296. @@ -2559,7 +2559,7 @@ _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd,
  297. if (elf_hash_table (info)->dynamic_sections_created)
  298. {
  299. /* Set the contents of the .interp section to the interpreter. */
  300. - if (info->executable)
  301. + if (info->executable && !info->nointerp)
  302. {
  303. s = bfd_get_linker_section (dynobj, ".interp");
  304. BFD_ASSERT (s != NULL);
  305. diff --git a/include/bfdlink.h b/include/bfdlink.h
  306. index 797a465..cf533dd 100644
  307. --- a/include/bfdlink.h
  308. +++ b/include/bfdlink.h
  309. @@ -433,6 +433,9 @@ struct bfd_link_info
  310. /* TRUE if BND prefix in PLT entries is always generated. */
  311. unsigned int bndplt: 1;
  312. + /* TRUE if generation of .interp/PT_INTERP should be suppressed. */
  313. + unsigned int nointerp: 1;
  314. +
  315. /* Char that may appear as the first char of a symbol, but should be
  316. skipped (like symbol_leading_char) when looking up symbols in
  317. wrap_hash. Used by PowerPC Linux for 'dot' symbols. */
  318. diff --git a/ld/ld.texinfo b/ld/ld.texinfo
  319. index cf3b586..1e5e5cf 100644
  320. --- a/ld/ld.texinfo
  321. +++ b/ld/ld.texinfo
  322. @@ -1426,6 +1426,13 @@ generating dynamically linked ELF executables. The default dynamic
  323. linker is normally correct; don't use this unless you know what you are
  324. doing.
  325. +@kindex --no-dynamic-linker
  326. +@item --no-dynamic-linker
  327. +When producing an executable file, omit the request for a dynamic
  328. +linker to be used at load-time. This is only meaningful for ELF
  329. +executables that contain dynamic relocations, and usually requires
  330. +entry point code that is capable of processing these relocations.
  331. +
  332. @kindex --fatal-warnings
  333. @kindex --no-fatal-warnings
  334. @item --fatal-warnings
  335. diff --git a/ld/lexsup.c b/ld/lexsup.c
  336. index 59bd14f..8b57f84 100644
  337. --- a/ld/lexsup.c
  338. +++ b/ld/lexsup.c
  339. @@ -33,6 +33,7 @@ enum option_values
  340. OPTION_DEFSYM,
  341. OPTION_DEMANGLE,
  342. OPTION_DYNAMIC_LINKER,
  343. + OPTION_NO_DYNAMIC_LINKER,
  344. OPTION_SYSROOT,
  345. OPTION_EB,
  346. OPTION_EL,
  347. diff --git a/ld/lexsup.c b/ld/lexsup.c
  348. index 777d6e2..1b992f7 100644
  349. --- a/ld/lexsup.c
  350. +++ b/ld/lexsup.c
  351. @@ -138,6 +138,9 @@ static const struct ld_option ld_options[] =
  352. { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
  353. 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
  354. TWO_DASHES },
  355. + { {"no-dynamic-linker", no_argument, NULL, OPTION_NO_DYNAMIC_LINKER},
  356. + '\0', NULL, N_("Produce an executable with no program interpreter header"),
  357. + TWO_DASHES },
  358. { {"library", required_argument, NULL, 'l'},
  359. 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
  360. { {"library-path", required_argument, NULL, 'L'},
  361. @@ -762,6 +765,10 @@ parse_args (unsigned argc, char **argv)
  362. case 'I': /* Used on Solaris. */
  363. case OPTION_DYNAMIC_LINKER:
  364. command_line.interpreter = optarg;
  365. + link_info.nointerp = 0;
  366. + break;
  367. + case OPTION_NO_DYNAMIC_LINKER:
  368. + link_info.nointerp = 1;
  369. break;
  370. case OPTION_SYSROOT:
  371. /* Already handled in ldmain.c. */