elf32-vax.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892
  1. /* VAX series support for 32-bit ELF
  2. Copyright (C) 1993-2022 Free Software Foundation, Inc.
  3. Contributed by Matt Thomas <matt@3am-software.com>.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "bfdlink.h"
  20. #include "libbfd.h"
  21. #include "elf-bfd.h"
  22. #include "elf/vax.h"
  23. static reloc_howto_type *reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
  24. static bool rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *);
  25. static struct bfd_hash_entry *elf_vax_link_hash_newfunc (struct bfd_hash_entry *,
  26. struct bfd_hash_table *,
  27. const char *);
  28. static struct bfd_link_hash_table *elf_vax_link_hash_table_create (bfd *);
  29. static bool elf_vax_check_relocs (bfd *, struct bfd_link_info *,
  30. asection *, const Elf_Internal_Rela *);
  31. static bool elf_vax_adjust_dynamic_symbol (struct bfd_link_info *,
  32. struct elf_link_hash_entry *);
  33. static bool elf_vax_size_dynamic_sections (bfd *, struct bfd_link_info *);
  34. static int elf_vax_relocate_section (bfd *, struct bfd_link_info *,
  35. bfd *, asection *, bfd_byte *,
  36. Elf_Internal_Rela *,
  37. Elf_Internal_Sym *, asection **);
  38. static bool elf_vax_finish_dynamic_symbol (bfd *, struct bfd_link_info *,
  39. struct elf_link_hash_entry *,
  40. Elf_Internal_Sym *);
  41. static bool elf_vax_finish_dynamic_sections (bfd *, struct bfd_link_info *);
  42. static bfd_vma elf_vax_plt_sym_val (bfd_vma, const asection *,
  43. const arelent *);
  44. static bool elf32_vax_set_private_flags (bfd *, flagword);
  45. static bool elf32_vax_print_private_bfd_data (bfd *, void *);
  46. static reloc_howto_type howto_table[] = {
  47. HOWTO (R_VAX_NONE, /* type */
  48. 0, /* rightshift */
  49. 3, /* size (0 = byte, 1 = short, 2 = long) */
  50. 0, /* bitsize */
  51. false, /* pc_relative */
  52. 0, /* bitpos */
  53. complain_overflow_dont, /* complain_on_overflow */
  54. bfd_elf_generic_reloc, /* special_function */
  55. "R_VAX_NONE", /* name */
  56. false, /* partial_inplace */
  57. 0, /* src_mask */
  58. 0x00000000, /* dst_mask */
  59. false), /* pcrel_offset */
  60. HOWTO (R_VAX_32, /* type */
  61. 0, /* rightshift */
  62. 2, /* size (0 = byte, 1 = short, 2 = long) */
  63. 32, /* bitsize */
  64. false, /* pc_relative */
  65. 0, /* bitpos */
  66. complain_overflow_bitfield, /* complain_on_overflow */
  67. bfd_elf_generic_reloc, /* special_function */
  68. "R_VAX_32", /* name */
  69. false, /* partial_inplace */
  70. 0, /* src_mask */
  71. 0xffffffff, /* dst_mask */
  72. false), /* pcrel_offset */
  73. HOWTO (R_VAX_16, /* type */
  74. 0, /* rightshift */
  75. 1, /* size (0 = byte, 1 = short, 2 = long) */
  76. 16, /* bitsize */
  77. false, /* pc_relative */
  78. 0, /* bitpos */
  79. complain_overflow_bitfield, /* complain_on_overflow */
  80. bfd_elf_generic_reloc, /* special_function */
  81. "R_VAX_16", /* name */
  82. false, /* partial_inplace */
  83. 0, /* src_mask */
  84. 0x0000ffff, /* dst_mask */
  85. false), /* pcrel_offset */
  86. HOWTO (R_VAX_8, /* type */
  87. 0, /* rightshift */
  88. 0, /* size (0 = byte, 1 = short, 2 = long) */
  89. 8, /* bitsize */
  90. false, /* pc_relative */
  91. 0, /* bitpos */
  92. complain_overflow_bitfield, /* complain_on_overflow */
  93. bfd_elf_generic_reloc, /* special_function */
  94. "R_VAX_8", /* name */
  95. false, /* partial_inplace */
  96. 0, /* src_mask */
  97. 0x000000ff, /* dst_mask */
  98. false), /* pcrel_offset */
  99. HOWTO (R_VAX_PC32, /* type */
  100. 0, /* rightshift */
  101. 2, /* size (0 = byte, 1 = short, 2 = long) */
  102. 32, /* bitsize */
  103. true, /* pc_relative */
  104. 0, /* bitpos */
  105. complain_overflow_bitfield, /* complain_on_overflow */
  106. bfd_elf_generic_reloc, /* special_function */
  107. "R_VAX_PC32", /* name */
  108. false, /* partial_inplace */
  109. 0, /* src_mask */
  110. 0xffffffff, /* dst_mask */
  111. true), /* pcrel_offset */
  112. HOWTO (R_VAX_PC16, /* type */
  113. 0, /* rightshift */
  114. 1, /* size (0 = byte, 1 = short, 2 = long) */
  115. 16, /* bitsize */
  116. true, /* pc_relative */
  117. 0, /* bitpos */
  118. complain_overflow_signed, /* complain_on_overflow */
  119. bfd_elf_generic_reloc, /* special_function */
  120. "R_VAX_PC16", /* name */
  121. false, /* partial_inplace */
  122. 0, /* src_mask */
  123. 0x0000ffff, /* dst_mask */
  124. true), /* pcrel_offset */
  125. HOWTO (R_VAX_PC8, /* type */
  126. 0, /* rightshift */
  127. 0, /* size (0 = byte, 1 = short, 2 = long) */
  128. 8, /* bitsize */
  129. true, /* pc_relative */
  130. 0, /* bitpos */
  131. complain_overflow_signed, /* complain_on_overflow */
  132. bfd_elf_generic_reloc, /* special_function */
  133. "R_VAX_PC8", /* name */
  134. false, /* partial_inplace */
  135. 0, /* src_mask */
  136. 0x000000ff, /* dst_mask */
  137. true), /* pcrel_offset */
  138. HOWTO (R_VAX_GOT32, /* type */
  139. 0, /* rightshift */
  140. 2, /* size (0 = byte, 1 = short, 2 = long) */
  141. 32, /* bitsize */
  142. true, /* pc_relative */
  143. 0, /* bitpos */
  144. complain_overflow_bitfield, /* complain_on_overflow */
  145. bfd_elf_generic_reloc, /* special_function */
  146. "R_VAX_GOT32", /* name */
  147. false, /* partial_inplace */
  148. 0, /* src_mask */
  149. 0xffffffff, /* dst_mask */
  150. true), /* pcrel_offset */
  151. EMPTY_HOWTO (-1),
  152. EMPTY_HOWTO (-1),
  153. EMPTY_HOWTO (-1),
  154. EMPTY_HOWTO (-1),
  155. EMPTY_HOWTO (-1),
  156. HOWTO (R_VAX_PLT32, /* type */
  157. 0, /* rightshift */
  158. 2, /* size (0 = byte, 1 = short, 2 = long) */
  159. 32, /* bitsize */
  160. true, /* pc_relative */
  161. 0, /* bitpos */
  162. complain_overflow_bitfield, /* complain_on_overflow */
  163. bfd_elf_generic_reloc, /* special_function */
  164. "R_VAX_PLT32", /* name */
  165. false, /* partial_inplace */
  166. 0, /* src_mask */
  167. 0xffffffff, /* dst_mask */
  168. true), /* pcrel_offset */
  169. EMPTY_HOWTO (-1),
  170. EMPTY_HOWTO (-1),
  171. EMPTY_HOWTO (-1),
  172. EMPTY_HOWTO (-1),
  173. EMPTY_HOWTO (-1),
  174. HOWTO (R_VAX_COPY, /* type */
  175. 0, /* rightshift */
  176. 0, /* size (0 = byte, 1 = short, 2 = long) */
  177. 0, /* bitsize */
  178. false, /* pc_relative */
  179. 0, /* bitpos */
  180. complain_overflow_dont, /* complain_on_overflow */
  181. bfd_elf_generic_reloc, /* special_function */
  182. "R_VAX_COPY", /* name */
  183. false, /* partial_inplace */
  184. 0, /* src_mask */
  185. 0xffffffff, /* dst_mask */
  186. false), /* pcrel_offset */
  187. HOWTO (R_VAX_GLOB_DAT, /* type */
  188. 0, /* rightshift */
  189. 2, /* size (0 = byte, 1 = short, 2 = long) */
  190. 32, /* bitsize */
  191. false, /* pc_relative */
  192. 0, /* bitpos */
  193. complain_overflow_dont, /* complain_on_overflow */
  194. bfd_elf_generic_reloc, /* special_function */
  195. "R_VAX_GLOB_DAT", /* name */
  196. false, /* partial_inplace */
  197. 0, /* src_mask */
  198. 0xffffffff, /* dst_mask */
  199. false), /* pcrel_offset */
  200. HOWTO (R_VAX_JMP_SLOT, /* type */
  201. 0, /* rightshift */
  202. 2, /* size (0 = byte, 1 = short, 2 = long) */
  203. 32, /* bitsize */
  204. false, /* pc_relative */
  205. 0, /* bitpos */
  206. complain_overflow_dont, /* complain_on_overflow */
  207. bfd_elf_generic_reloc, /* special_function */
  208. "R_VAX_JMP_SLOT", /* name */
  209. false, /* partial_inplace */
  210. 0, /* src_mask */
  211. 0xffffffff, /* dst_mask */
  212. false), /* pcrel_offset */
  213. HOWTO (R_VAX_RELATIVE, /* type */
  214. 0, /* rightshift */
  215. 2, /* size (0 = byte, 1 = short, 2 = long) */
  216. 32, /* bitsize */
  217. false, /* pc_relative */
  218. 0, /* bitpos */
  219. complain_overflow_dont, /* complain_on_overflow */
  220. bfd_elf_generic_reloc, /* special_function */
  221. "R_VAX_RELATIVE", /* name */
  222. false, /* partial_inplace */
  223. 0, /* src_mask */
  224. 0xffffffff, /* dst_mask */
  225. false), /* pcrel_offset */
  226. /* GNU extension to record C++ vtable hierarchy */
  227. HOWTO (R_VAX_GNU_VTINHERIT, /* type */
  228. 0, /* rightshift */
  229. 2, /* size (0 = byte, 1 = short, 2 = long) */
  230. 0, /* bitsize */
  231. false, /* pc_relative */
  232. 0, /* bitpos */
  233. complain_overflow_dont, /* complain_on_overflow */
  234. NULL, /* special_function */
  235. "R_VAX_GNU_VTINHERIT", /* name */
  236. false, /* partial_inplace */
  237. 0, /* src_mask */
  238. 0, /* dst_mask */
  239. false), /* pcrel_offset */
  240. /* GNU extension to record C++ vtable member usage */
  241. HOWTO (R_VAX_GNU_VTENTRY, /* type */
  242. 0, /* rightshift */
  243. 2, /* size (0 = byte, 1 = short, 2 = long) */
  244. 0, /* bitsize */
  245. false, /* pc_relative */
  246. 0, /* bitpos */
  247. complain_overflow_dont, /* complain_on_overflow */
  248. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  249. "R_VAX_GNU_VTENTRY", /* name */
  250. false, /* partial_inplace */
  251. 0, /* src_mask */
  252. 0, /* dst_mask */
  253. false), /* pcrel_offset */
  254. };
  255. static bool
  256. rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
  257. {
  258. unsigned int r_type;
  259. r_type = ELF32_R_TYPE (dst->r_info);
  260. if (r_type >= R_VAX_max)
  261. {
  262. /* xgettext:c-format */
  263. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  264. abfd, r_type);
  265. bfd_set_error (bfd_error_bad_value);
  266. return false;
  267. }
  268. cache_ptr->howto = &howto_table[r_type];
  269. return true;
  270. }
  271. #define elf_info_to_howto rtype_to_howto
  272. static const struct
  273. {
  274. bfd_reloc_code_real_type bfd_val;
  275. int elf_val;
  276. } reloc_map[] = {
  277. { BFD_RELOC_NONE, R_VAX_NONE },
  278. { BFD_RELOC_32, R_VAX_32 },
  279. { BFD_RELOC_16, R_VAX_16 },
  280. { BFD_RELOC_8, R_VAX_8 },
  281. { BFD_RELOC_32_PCREL, R_VAX_PC32 },
  282. { BFD_RELOC_16_PCREL, R_VAX_PC16 },
  283. { BFD_RELOC_8_PCREL, R_VAX_PC8 },
  284. { BFD_RELOC_32_GOT_PCREL, R_VAX_GOT32 },
  285. { BFD_RELOC_32_PLT_PCREL, R_VAX_PLT32 },
  286. { BFD_RELOC_NONE, R_VAX_COPY },
  287. { BFD_RELOC_VAX_GLOB_DAT, R_VAX_GLOB_DAT },
  288. { BFD_RELOC_VAX_JMP_SLOT, R_VAX_JMP_SLOT },
  289. { BFD_RELOC_VAX_RELATIVE, R_VAX_RELATIVE },
  290. { BFD_RELOC_CTOR, R_VAX_32 },
  291. { BFD_RELOC_VTABLE_INHERIT, R_VAX_GNU_VTINHERIT },
  292. { BFD_RELOC_VTABLE_ENTRY, R_VAX_GNU_VTENTRY },
  293. };
  294. static reloc_howto_type *
  295. reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
  296. {
  297. unsigned int i;
  298. for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
  299. {
  300. if (reloc_map[i].bfd_val == code)
  301. return &howto_table[reloc_map[i].elf_val];
  302. }
  303. return 0;
  304. }
  305. static reloc_howto_type *
  306. reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  307. const char *r_name)
  308. {
  309. unsigned int i;
  310. for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
  311. if (howto_table[i].name != NULL
  312. && strcasecmp (howto_table[i].name, r_name) == 0)
  313. return &howto_table[i];
  314. return NULL;
  315. }
  316. #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
  317. #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
  318. #define ELF_ARCH bfd_arch_vax
  319. /* end code generated by elf.el */
  320. /* Functions for the VAX ELF linker. */
  321. /* The name of the dynamic interpreter. This is put in the .interp
  322. section. */
  323. #define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
  324. /* The size in bytes of an entry in the procedure linkage table. */
  325. #define PLT_ENTRY_SIZE 12
  326. /* The first entry in a procedure linkage table looks like this. See
  327. the SVR4 ABI VAX supplement to see how this works. */
  328. static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] =
  329. {
  330. 0xdd, 0xef, /* pushl l^ */
  331. 0, 0, 0, 0, /* offset to .plt.got + 4 */
  332. 0x17, 0xff, /* jmp @L^(pc) */
  333. 0, 0, 0, 0, /* offset to .plt.got + 8 */
  334. };
  335. /* Subsequent entries in a procedure linkage table look like this. */
  336. static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] =
  337. {
  338. 0xfc, 0x0f, /* .word ^M<r11:r2> */
  339. 0x16, 0xef, /* jsb L^(pc) */
  340. 0, 0, 0, 0, /* replaced with offset to start of .plt */
  341. 0, 0, 0, 0, /* index into .rela.plt */
  342. };
  343. /* The VAX linker needs to keep track of the number of relocs that it
  344. decides to copy in check_relocs for each symbol. This is so that it
  345. can discard PC relative relocs if it doesn't need them when linking
  346. with -Bsymbolic. We store the information in a field extending the
  347. regular ELF linker hash table. */
  348. /* This structure keeps track of the number of PC relative relocs we have
  349. copied for a given symbol. */
  350. struct elf_vax_pcrel_relocs_copied
  351. {
  352. /* Next section. */
  353. struct elf_vax_pcrel_relocs_copied *next;
  354. /* A section in dynobj. */
  355. asection *section;
  356. /* Number of relocs copied in this section. */
  357. bfd_size_type count;
  358. };
  359. /* VAX ELF linker hash entry. */
  360. struct elf_vax_link_hash_entry
  361. {
  362. struct elf_link_hash_entry root;
  363. /* Number of PC relative relocs copied for this symbol. */
  364. struct elf_vax_pcrel_relocs_copied *pcrel_relocs_copied;
  365. bfd_vma got_addend;
  366. };
  367. /* Declare this now that the above structures are defined. */
  368. static bool elf_vax_discard_copies (struct elf_vax_link_hash_entry *,
  369. void *);
  370. /* Declare this now that the above structures are defined. */
  371. static bool elf_vax_instantiate_got_entries (struct elf_link_hash_entry *,
  372. void *);
  373. /* Traverse an VAX ELF linker hash table. */
  374. #define elf_vax_link_hash_traverse(table, func, info) \
  375. (elf_link_hash_traverse \
  376. ((table), \
  377. (bool (*) (struct elf_link_hash_entry *, void *)) (func), \
  378. (info)))
  379. /* Create an entry in an VAX ELF linker hash table. */
  380. static struct bfd_hash_entry *
  381. elf_vax_link_hash_newfunc (struct bfd_hash_entry *entry,
  382. struct bfd_hash_table *table,
  383. const char *string)
  384. {
  385. struct elf_vax_link_hash_entry *ret =
  386. (struct elf_vax_link_hash_entry *) entry;
  387. /* Allocate the structure if it has not already been allocated by a
  388. subclass. */
  389. if (ret == NULL)
  390. ret = ((struct elf_vax_link_hash_entry *)
  391. bfd_hash_allocate (table,
  392. sizeof (struct elf_vax_link_hash_entry)));
  393. if (ret == NULL)
  394. return (struct bfd_hash_entry *) ret;
  395. /* Call the allocation method of the superclass. */
  396. ret = ((struct elf_vax_link_hash_entry *)
  397. _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
  398. table, string));
  399. if (ret != NULL)
  400. {
  401. ret->pcrel_relocs_copied = NULL;
  402. }
  403. return (struct bfd_hash_entry *) ret;
  404. }
  405. /* Create an VAX ELF linker hash table. */
  406. static struct bfd_link_hash_table *
  407. elf_vax_link_hash_table_create (bfd *abfd)
  408. {
  409. struct elf_link_hash_table *ret;
  410. size_t amt = sizeof (struct elf_link_hash_table);
  411. ret = bfd_zmalloc (amt);
  412. if (ret == NULL)
  413. return NULL;
  414. if (!_bfd_elf_link_hash_table_init (ret, abfd,
  415. elf_vax_link_hash_newfunc,
  416. sizeof (struct elf_vax_link_hash_entry),
  417. GENERIC_ELF_DATA))
  418. {
  419. free (ret);
  420. return NULL;
  421. }
  422. return &ret->root;
  423. }
  424. /* Keep vax-specific flags in the ELF header */
  425. static bool
  426. elf32_vax_set_private_flags (bfd *abfd, flagword flags)
  427. {
  428. elf_elfheader (abfd)->e_flags = flags;
  429. elf_flags_init (abfd) = true;
  430. return true;
  431. }
  432. /* Merge backend specific data from an object file to the output
  433. object file when linking. */
  434. static bool
  435. elf32_vax_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
  436. {
  437. bfd *obfd = info->output_bfd;
  438. flagword in_flags;
  439. if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
  440. || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
  441. return true;
  442. in_flags = elf_elfheader (ibfd)->e_flags;
  443. if (!elf_flags_init (obfd))
  444. {
  445. elf_flags_init (obfd) = true;
  446. elf_elfheader (obfd)->e_flags = in_flags;
  447. }
  448. return true;
  449. }
  450. /* Display the flags field */
  451. static bool
  452. elf32_vax_print_private_bfd_data (bfd *abfd, void * ptr)
  453. {
  454. FILE *file = (FILE *) ptr;
  455. BFD_ASSERT (abfd != NULL && ptr != NULL);
  456. /* Print normal ELF private data. */
  457. _bfd_elf_print_private_bfd_data (abfd, ptr);
  458. /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
  459. /* xgettext:c-format */
  460. fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
  461. if (elf_elfheader (abfd)->e_flags & EF_VAX_NONPIC)
  462. fprintf (file, _(" [nonpic]"));
  463. if (elf_elfheader (abfd)->e_flags & EF_VAX_DFLOAT)
  464. fprintf (file, _(" [d-float]"));
  465. if (elf_elfheader (abfd)->e_flags & EF_VAX_GFLOAT)
  466. fprintf (file, _(" [g-float]"));
  467. fputc ('\n', file);
  468. return true;
  469. }
  470. /* Look through the relocs for a section during the first phase, and
  471. allocate space in the global offset table or procedure linkage
  472. table. */
  473. static bool
  474. elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
  475. const Elf_Internal_Rela *relocs)
  476. {
  477. bfd *dynobj;
  478. Elf_Internal_Shdr *symtab_hdr;
  479. struct elf_link_hash_entry **sym_hashes;
  480. const Elf_Internal_Rela *rel;
  481. const Elf_Internal_Rela *rel_end;
  482. asection *sreloc;
  483. if (bfd_link_relocatable (info))
  484. return true;
  485. dynobj = elf_hash_table (info)->dynobj;
  486. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  487. sym_hashes = elf_sym_hashes (abfd);
  488. sreloc = NULL;
  489. rel_end = relocs + sec->reloc_count;
  490. for (rel = relocs; rel < rel_end; rel++)
  491. {
  492. unsigned long r_symndx;
  493. struct elf_link_hash_entry *h;
  494. r_symndx = ELF32_R_SYM (rel->r_info);
  495. if (r_symndx < symtab_hdr->sh_info)
  496. h = NULL;
  497. else
  498. {
  499. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  500. while (h->root.type == bfd_link_hash_indirect
  501. || h->root.type == bfd_link_hash_warning)
  502. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  503. }
  504. switch (ELF32_R_TYPE (rel->r_info))
  505. {
  506. case R_VAX_GOT32:
  507. BFD_ASSERT (h != NULL);
  508. /* If this is a local symbol, we resolve it directly without
  509. creating a global offset table entry. */
  510. if (SYMBOL_REFERENCES_LOCAL (info, h)
  511. || h == elf_hash_table (info)->hgot
  512. || h == elf_hash_table (info)->hplt)
  513. break;
  514. /* This symbol requires a global offset table entry. */
  515. if (dynobj == NULL)
  516. {
  517. /* Create the .got section. */
  518. elf_hash_table (info)->dynobj = dynobj = abfd;
  519. if (!_bfd_elf_create_got_section (dynobj, info))
  520. return false;
  521. }
  522. if (h != NULL)
  523. {
  524. struct elf_vax_link_hash_entry *eh;
  525. eh = (struct elf_vax_link_hash_entry *) h;
  526. if (h->got.refcount == -1)
  527. {
  528. h->got.refcount = 1;
  529. eh->got_addend = rel->r_addend;
  530. }
  531. else
  532. {
  533. h->got.refcount++;
  534. if (eh->got_addend != (bfd_vma) rel->r_addend)
  535. _bfd_error_handler
  536. /* xgettext:c-format */
  537. (_("%pB: warning: GOT addend of %" PRId64 " to `%s' does"
  538. " not match previous GOT addend of %" PRId64),
  539. abfd, (int64_t) rel->r_addend, h->root.root.string,
  540. (int64_t) eh->got_addend);
  541. }
  542. }
  543. break;
  544. case R_VAX_PLT32:
  545. /* This symbol requires a procedure linkage table entry. We
  546. actually build the entry in adjust_dynamic_symbol,
  547. because this might be a case of linking PIC code which is
  548. never referenced by a dynamic object, in which case we
  549. don't need to generate a procedure linkage table entry
  550. after all. */
  551. BFD_ASSERT (h != NULL);
  552. /* If this is a local symbol, we resolve it directly without
  553. creating a procedure linkage table entry. */
  554. if (h->forced_local)
  555. break;
  556. h->needs_plt = 1;
  557. if (h->plt.refcount == -1)
  558. h->plt.refcount = 1;
  559. else
  560. h->plt.refcount++;
  561. break;
  562. case R_VAX_PC8:
  563. case R_VAX_PC16:
  564. case R_VAX_PC32:
  565. /* If we are creating a shared library and this is not a local
  566. symbol, we need to copy the reloc into the shared library.
  567. However when linking with -Bsymbolic and this is a global
  568. symbol which is defined in an object we are including in the
  569. link (i.e., DEF_REGULAR is set), then we can resolve the
  570. reloc directly. At this point we have not seen all the input
  571. files, so it is possible that DEF_REGULAR is not set now but
  572. will be set later (it is never cleared). We account for that
  573. possibility below by storing information in the
  574. pcrel_relocs_copied field of the hash table entry. */
  575. if (!(bfd_link_pic (info)
  576. && (sec->flags & SEC_ALLOC) != 0
  577. && h != NULL
  578. && (!info->symbolic
  579. || !h->def_regular)))
  580. {
  581. if (h != NULL
  582. && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  583. && !h->forced_local)
  584. {
  585. /* Make sure a plt entry is created for this symbol if
  586. it turns out to be a function defined by a dynamic
  587. object. */
  588. if (h->plt.refcount == -1)
  589. h->plt.refcount = 1;
  590. else
  591. h->plt.refcount++;
  592. }
  593. break;
  594. }
  595. /* If this is a local symbol, we can resolve it directly. */
  596. if (h != NULL
  597. && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  598. || h->forced_local))
  599. break;
  600. /* Fall through. */
  601. case R_VAX_8:
  602. case R_VAX_16:
  603. case R_VAX_32:
  604. if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
  605. {
  606. /* Make sure a plt entry is created for this symbol if it
  607. turns out to be a function defined by a dynamic object. */
  608. if (h->plt.refcount == -1)
  609. h->plt.refcount = 1;
  610. else
  611. h->plt.refcount++;
  612. }
  613. /* Non-GOT reference may need a copy reloc in executable or
  614. a dynamic reloc in shared library. */
  615. if (h != NULL)
  616. h->non_got_ref = 1;
  617. /* If we are creating a shared library, we need to copy the
  618. reloc into the shared library. */
  619. if (bfd_link_pic (info)
  620. && (sec->flags & SEC_ALLOC) != 0)
  621. {
  622. /* When creating a shared object, we must copy these
  623. reloc types into the output file. We create a reloc
  624. section in dynobj and make room for this reloc. */
  625. if (sreloc == NULL)
  626. {
  627. sreloc = _bfd_elf_make_dynamic_reloc_section
  628. (sec, dynobj, 2, abfd, /*rela?*/ true);
  629. if (sreloc == NULL)
  630. return false;
  631. if (sec->flags & SEC_READONLY)
  632. info->flags |= DF_TEXTREL;
  633. }
  634. sreloc->size += sizeof (Elf32_External_Rela);
  635. /* If we are linking with -Bsymbolic, we count the number of
  636. PC relative relocations we have entered for this symbol,
  637. so that we can discard them again if the symbol is later
  638. defined by a regular object. Note that this function is
  639. only called if we are using a vaxelf linker hash table,
  640. which means that h is really a pointer to an
  641. elf_vax_link_hash_entry. */
  642. if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
  643. || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
  644. || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
  645. && info->symbolic)
  646. {
  647. struct elf_vax_link_hash_entry *eh;
  648. struct elf_vax_pcrel_relocs_copied *p;
  649. eh = (struct elf_vax_link_hash_entry *) h;
  650. for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
  651. if (p->section == sreloc)
  652. break;
  653. if (p == NULL)
  654. {
  655. p = ((struct elf_vax_pcrel_relocs_copied *)
  656. bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
  657. if (p == NULL)
  658. return false;
  659. p->next = eh->pcrel_relocs_copied;
  660. eh->pcrel_relocs_copied = p;
  661. p->section = sreloc;
  662. p->count = 0;
  663. }
  664. ++p->count;
  665. }
  666. }
  667. break;
  668. /* This relocation describes the C++ object vtable hierarchy.
  669. Reconstruct it for later use during GC. */
  670. case R_VAX_GNU_VTINHERIT:
  671. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  672. return false;
  673. break;
  674. /* This relocation describes which C++ vtable entries are actually
  675. used. Record for later use during GC. */
  676. case R_VAX_GNU_VTENTRY:
  677. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  678. return false;
  679. break;
  680. default:
  681. break;
  682. }
  683. }
  684. return true;
  685. }
  686. /* Return the section that should be marked against GC for a given
  687. relocation. */
  688. static asection *
  689. elf_vax_gc_mark_hook (asection *sec,
  690. struct bfd_link_info *info,
  691. Elf_Internal_Rela *rel,
  692. struct elf_link_hash_entry *h,
  693. Elf_Internal_Sym *sym)
  694. {
  695. if (h != NULL)
  696. switch (ELF32_R_TYPE (rel->r_info))
  697. {
  698. case R_VAX_GNU_VTINHERIT:
  699. case R_VAX_GNU_VTENTRY:
  700. return NULL;
  701. }
  702. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  703. }
  704. /* Adjust a symbol defined by a dynamic object and referenced by a
  705. regular object. The current definition is in some section of the
  706. dynamic object, but we're not including those sections. We have to
  707. change the definition to something the rest of the link can
  708. understand. */
  709. static bool
  710. elf_vax_adjust_dynamic_symbol (struct bfd_link_info *info,
  711. struct elf_link_hash_entry *h)
  712. {
  713. bfd *dynobj;
  714. asection *s;
  715. dynobj = elf_hash_table (info)->dynobj;
  716. /* Make sure we know what is going on here. */
  717. BFD_ASSERT (dynobj != NULL
  718. && (h->needs_plt
  719. || h->is_weakalias
  720. || (h->def_dynamic
  721. && h->ref_regular
  722. && !h->def_regular)));
  723. /* If this is a function, put it in the procedure linkage table. We
  724. will fill in the contents of the procedure linkage table later,
  725. when we know the address of the .got section. */
  726. if (h->type == STT_FUNC
  727. || h->needs_plt)
  728. {
  729. if (h->plt.refcount <= 0
  730. || SYMBOL_CALLS_LOCAL (info, h)
  731. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  732. && h->root.type == bfd_link_hash_undefweak))
  733. {
  734. /* This case can occur if we saw a PLTxx reloc in an input
  735. file, but the symbol was never referred to by a dynamic
  736. object, or if all references were garbage collected. In
  737. such a case, we don't actually need to build a procedure
  738. linkage table, and we can just do a PCxx reloc instead. */
  739. h->plt.offset = (bfd_vma) -1;
  740. h->needs_plt = 0;
  741. return true;
  742. }
  743. s = elf_hash_table (info)->splt;
  744. BFD_ASSERT (s != NULL);
  745. /* If this is the first .plt entry, make room for the special
  746. first entry. */
  747. if (s->size == 0)
  748. {
  749. s->size += PLT_ENTRY_SIZE;
  750. }
  751. /* If this symbol is not defined in a regular file, and we are
  752. not generating a shared library, then set the symbol to this
  753. location in the .plt. This is required to make function
  754. pointers compare as equal between the normal executable and
  755. the shared library. */
  756. if (!bfd_link_pic (info)
  757. && !h->def_regular)
  758. {
  759. h->root.u.def.section = s;
  760. h->root.u.def.value = s->size;
  761. }
  762. h->plt.offset = s->size;
  763. /* Make room for this entry. */
  764. s->size += PLT_ENTRY_SIZE;
  765. /* We also need to make an entry in the .got.plt section, which
  766. will be placed in the .got section by the linker script. */
  767. s = elf_hash_table (info)->sgotplt;
  768. BFD_ASSERT (s != NULL);
  769. s->size += 4;
  770. /* We also need to make an entry in the .rela.plt section. */
  771. s = elf_hash_table (info)->srelplt;
  772. BFD_ASSERT (s != NULL);
  773. s->size += sizeof (Elf32_External_Rela);
  774. return true;
  775. }
  776. /* Reinitialize the plt offset now that it is not used as a reference
  777. count any more. */
  778. h->plt.offset = (bfd_vma) -1;
  779. /* If this is a weak symbol, and there is a real definition, the
  780. processor independent code will have arranged for us to see the
  781. real definition first, and we can just use the same value. */
  782. if (h->is_weakalias)
  783. {
  784. struct elf_link_hash_entry *def = weakdef (h);
  785. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  786. h->root.u.def.section = def->root.u.def.section;
  787. h->root.u.def.value = def->root.u.def.value;
  788. return true;
  789. }
  790. /* This is a reference to a symbol defined by a dynamic object which
  791. is not a function. */
  792. /* If we are creating a shared library, we must presume that the
  793. only references to the symbol are via the global offset table.
  794. For such cases we need not do anything here; the relocations will
  795. be handled correctly by relocate_section. */
  796. if (bfd_link_pic (info))
  797. return true;
  798. /* If there are no references to this symbol that do not use the
  799. GOT relocation, we don't need to generate a copy reloc. */
  800. if (!h->non_got_ref)
  801. return true;
  802. /* We must allocate the symbol in our .dynbss section, which will
  803. become part of the .bss section of the executable. There will be
  804. an entry for this symbol in the .dynsym section. The dynamic
  805. object will contain position independent code, so all references
  806. from the dynamic object to this symbol will go through the global
  807. offset table. The dynamic linker will use the .dynsym entry to
  808. determine the address it must put in the global offset table, so
  809. both the dynamic object and the regular object will refer to the
  810. same memory location for the variable. */
  811. s = bfd_get_linker_section (dynobj, ".dynbss");
  812. BFD_ASSERT (s != NULL);
  813. /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
  814. copy the initial value out of the dynamic object and into the
  815. runtime process image. We need to remember the offset into the
  816. .rela.bss section we are going to use. */
  817. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  818. {
  819. asection *srel;
  820. srel = bfd_get_linker_section (dynobj, ".rela.bss");
  821. BFD_ASSERT (srel != NULL);
  822. srel->size += sizeof (Elf32_External_Rela);
  823. h->needs_copy = 1;
  824. }
  825. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  826. }
  827. /* This function is called via elf_link_hash_traverse. It resets GOT
  828. and PLT (.GOT) reference counts back to -1 so normal PC32 relocation
  829. will be done. */
  830. static bool
  831. elf_vax_discard_got_entries (struct elf_link_hash_entry *h,
  832. void *infoptr ATTRIBUTE_UNUSED)
  833. {
  834. h->got.refcount = -1;
  835. h->plt.refcount = -1;
  836. return true;
  837. }
  838. /* Discard unused dynamic data if this is a static link. */
  839. static bool
  840. elf_vax_always_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  841. struct bfd_link_info *info)
  842. {
  843. bfd *dynobj;
  844. asection *s;
  845. dynobj = elf_hash_table (info)->dynobj;
  846. if (dynobj && !elf_hash_table (info)->dynamic_sections_created)
  847. {
  848. /* We may have created entries in the .rela.got and .got sections.
  849. However, if we are not creating the dynamic sections, we will
  850. not actually use these entries. Reset the size of .rela.got
  851. and .got, which will cause them to get stripped from the output
  852. file below. */
  853. s = elf_hash_table (info)->srelgot;
  854. if (s != NULL)
  855. s->size = 0;
  856. s = elf_hash_table (info)->sgotplt;
  857. if (s != NULL)
  858. s->size = 0;
  859. s = elf_hash_table (info)->sgot;
  860. if (s != NULL)
  861. s->size = 0;
  862. }
  863. /* If this is a static link, we need to discard all the got entries we've
  864. recorded. */
  865. if (!dynobj || !elf_hash_table (info)->dynamic_sections_created)
  866. elf_link_hash_traverse (elf_hash_table (info),
  867. elf_vax_discard_got_entries,
  868. info);
  869. return true;
  870. }
  871. /* Set the sizes of the dynamic sections. */
  872. static bool
  873. elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
  874. {
  875. bfd *dynobj;
  876. asection *s;
  877. bool relocs;
  878. dynobj = elf_hash_table (info)->dynobj;
  879. BFD_ASSERT (dynobj != NULL);
  880. if (elf_hash_table (info)->dynamic_sections_created)
  881. {
  882. /* Set the contents of the .interp section to the interpreter. */
  883. if (bfd_link_executable (info) && !info->nointerp)
  884. {
  885. s = bfd_get_linker_section (dynobj, ".interp");
  886. BFD_ASSERT (s != NULL);
  887. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  888. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  889. }
  890. }
  891. /* If this is a -Bsymbolic shared link, then we need to discard all PC
  892. relative relocs against symbols defined in a regular object. We
  893. allocated space for them in the check_relocs routine, but we will not
  894. fill them in in the relocate_section routine. */
  895. if (bfd_link_pic (info) && info->symbolic)
  896. elf_vax_link_hash_traverse (elf_hash_table (info),
  897. elf_vax_discard_copies,
  898. NULL);
  899. /* If this is a -Bsymbolic shared link, we need to discard all the got
  900. entries we've recorded. Otherwise, we need to instantiate (allocate
  901. space for them). */
  902. elf_link_hash_traverse (elf_hash_table (info),
  903. elf_vax_instantiate_got_entries,
  904. info);
  905. /* The check_relocs and adjust_dynamic_symbol entry points have
  906. determined the sizes of the various dynamic sections. Allocate
  907. memory for them. */
  908. relocs = false;
  909. for (s = dynobj->sections; s != NULL; s = s->next)
  910. {
  911. const char *name;
  912. if ((s->flags & SEC_LINKER_CREATED) == 0)
  913. continue;
  914. /* It's OK to base decisions on the section name, because none
  915. of the dynobj section names depend upon the input files. */
  916. name = bfd_section_name (s);
  917. if (strcmp (name, ".plt") == 0)
  918. {
  919. /* Remember whether there is a PLT. */
  920. ;
  921. }
  922. else if (startswith (name, ".rela"))
  923. {
  924. if (s->size != 0)
  925. {
  926. if (strcmp (name, ".rela.plt") != 0)
  927. relocs = true;
  928. /* We use the reloc_count field as a counter if we need
  929. to copy relocs into the output file. */
  930. s->reloc_count = 0;
  931. }
  932. }
  933. else if (! startswith (name, ".got")
  934. && strcmp (name, ".dynbss") != 0)
  935. {
  936. /* It's not one of our sections, so don't allocate space. */
  937. continue;
  938. }
  939. if (s->size == 0)
  940. {
  941. /* If we don't need this section, strip it from the
  942. output file. This is mostly to handle .rela.bss and
  943. .rela.plt. We must create both sections in
  944. create_dynamic_sections, because they must be created
  945. before the linker maps input sections to output
  946. sections. The linker does that before
  947. adjust_dynamic_symbol is called, and it is that
  948. function which decides whether anything needs to go
  949. into these sections. */
  950. s->flags |= SEC_EXCLUDE;
  951. continue;
  952. }
  953. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  954. continue;
  955. /* Allocate memory for the section contents. */
  956. s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
  957. if (s->contents == NULL)
  958. return false;
  959. }
  960. return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
  961. }
  962. /* This function is called via elf_vax_link_hash_traverse if we are
  963. creating a shared object with -Bsymbolic. It discards the space
  964. allocated to copy PC relative relocs against symbols which are defined
  965. in regular objects. We allocated space for them in the check_relocs
  966. routine, but we won't fill them in in the relocate_section routine. */
  967. static bool
  968. elf_vax_discard_copies (struct elf_vax_link_hash_entry *h,
  969. void * ignore ATTRIBUTE_UNUSED)
  970. {
  971. struct elf_vax_pcrel_relocs_copied *s;
  972. /* We only discard relocs for symbols defined in a regular object. */
  973. if (!h->root.def_regular)
  974. return true;
  975. for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
  976. s->section->size -= s->count * sizeof (Elf32_External_Rela);
  977. return true;
  978. }
  979. /* This function is called via elf_link_hash_traverse. It looks for
  980. entries that have GOT or PLT (.GOT) references. If creating a shared
  981. object with -Bsymbolic, or the symbol has been forced local, then it
  982. resets the reference count back to -1 so normal PC32 relocation will
  983. be done. Otherwise space in the .got and .rela.got will be reserved
  984. for the symbol. */
  985. static bool
  986. elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, void * infoptr)
  987. {
  988. struct bfd_link_info *info = (struct bfd_link_info *) infoptr;
  989. bfd *dynobj;
  990. asection *sgot;
  991. asection *srelgot;
  992. /* We don't care about non-GOT (and non-PLT) entries. */
  993. if (h->got.refcount <= 0 && h->plt.refcount <= 0)
  994. return true;
  995. dynobj = elf_hash_table (info)->dynobj;
  996. BFD_ASSERT (dynobj != NULL);
  997. sgot = elf_hash_table (info)->sgot;
  998. srelgot = elf_hash_table (info)->srelgot;
  999. if (SYMBOL_REFERENCES_LOCAL (info, h))
  1000. {
  1001. h->got.refcount = -1;
  1002. h->plt.refcount = -1;
  1003. }
  1004. else if (h->got.refcount > 0)
  1005. {
  1006. /* Make sure this symbol is output as a dynamic symbol. */
  1007. if (h->dynindx == -1)
  1008. {
  1009. if (!bfd_elf_link_record_dynamic_symbol (info, h))
  1010. return false;
  1011. }
  1012. /* Allocate space in the .got and .rela.got sections. */
  1013. sgot->size += 4;
  1014. srelgot->size += sizeof (Elf32_External_Rela);
  1015. }
  1016. return true;
  1017. }
  1018. /* Relocate an VAX ELF section. */
  1019. static int
  1020. elf_vax_relocate_section (bfd *output_bfd,
  1021. struct bfd_link_info *info,
  1022. bfd *input_bfd,
  1023. asection *input_section,
  1024. bfd_byte *contents,
  1025. Elf_Internal_Rela *relocs,
  1026. Elf_Internal_Sym *local_syms,
  1027. asection **local_sections)
  1028. {
  1029. Elf_Internal_Shdr *symtab_hdr;
  1030. struct elf_link_hash_entry **sym_hashes;
  1031. bfd_vma plt_index;
  1032. bfd_vma got_offset;
  1033. asection *sgot;
  1034. asection *splt;
  1035. asection *sgotplt;
  1036. asection *sreloc;
  1037. Elf_Internal_Rela *rel;
  1038. Elf_Internal_Rela *relend;
  1039. symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  1040. sym_hashes = elf_sym_hashes (input_bfd);
  1041. sgot = NULL;
  1042. splt = NULL;
  1043. sgotplt = NULL;
  1044. sreloc = NULL;
  1045. rel = relocs;
  1046. relend = relocs + input_section->reloc_count;
  1047. for (; rel < relend; rel++)
  1048. {
  1049. int r_type;
  1050. reloc_howto_type *howto;
  1051. unsigned long r_symndx;
  1052. struct elf_link_hash_entry *h;
  1053. Elf_Internal_Sym *sym;
  1054. asection *sec;
  1055. bfd_vma relocation;
  1056. bfd_reloc_status_type r;
  1057. r_type = ELF32_R_TYPE (rel->r_info);
  1058. if (r_type < 0 || r_type >= (int) R_VAX_max)
  1059. {
  1060. bfd_set_error (bfd_error_bad_value);
  1061. return false;
  1062. }
  1063. howto = howto_table + r_type;
  1064. r_symndx = ELF32_R_SYM (rel->r_info);
  1065. h = NULL;
  1066. sym = NULL;
  1067. sec = NULL;
  1068. if (r_symndx < symtab_hdr->sh_info)
  1069. {
  1070. sym = local_syms + r_symndx;
  1071. sec = local_sections[r_symndx];
  1072. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  1073. }
  1074. else
  1075. {
  1076. bool unresolved_reloc;
  1077. bool warned, ignored;
  1078. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  1079. r_symndx, symtab_hdr, sym_hashes,
  1080. h, sec, relocation,
  1081. unresolved_reloc, warned, ignored);
  1082. if ((h->root.type == bfd_link_hash_defined
  1083. || h->root.type == bfd_link_hash_defweak)
  1084. && ((r_type == R_VAX_PLT32
  1085. && h->plt.offset != (bfd_vma) -1
  1086. && !h->forced_local
  1087. && elf_hash_table (info)->dynamic_sections_created)
  1088. || (r_type == R_VAX_GOT32
  1089. && h->got.offset != (bfd_vma) -1
  1090. && !h->forced_local
  1091. && elf_hash_table (info)->dynamic_sections_created
  1092. && (! bfd_link_pic (info)
  1093. || (! info->symbolic && h->dynindx != -1)
  1094. || !h->def_regular))
  1095. || (bfd_link_pic (info)
  1096. && ((! info->symbolic && h->dynindx != -1)
  1097. || !h->def_regular)
  1098. && ((input_section->flags & SEC_ALLOC) != 0
  1099. /* DWARF will emit R_VAX_32 relocations in its
  1100. sections against symbols defined externally
  1101. in shared libraries. We can't do anything
  1102. with them here. */
  1103. || ((input_section->flags & SEC_DEBUGGING) != 0
  1104. && h->def_dynamic))
  1105. && (r_type == R_VAX_8
  1106. || r_type == R_VAX_16
  1107. || r_type == R_VAX_32))))
  1108. /* In these cases, we don't need the relocation
  1109. value. We check specially because in some
  1110. obscure cases sec->output_section will be NULL. */
  1111. relocation = 0;
  1112. }
  1113. if (sec != NULL && discarded_section (sec))
  1114. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  1115. rel, 1, relend, howto, 0, contents);
  1116. if (bfd_link_relocatable (info))
  1117. continue;
  1118. switch (r_type)
  1119. {
  1120. case R_VAX_GOT32:
  1121. /* Relocation is to the address of the entry for this symbol
  1122. in the global offset table. */
  1123. /* Resolve a GOTxx reloc against a local symbol directly,
  1124. without using the global offset table. */
  1125. if (h == NULL
  1126. || h->got.offset == (bfd_vma) -1)
  1127. break;
  1128. {
  1129. bfd_vma off;
  1130. sgot = elf_hash_table (info)->sgot;
  1131. BFD_ASSERT (sgot != NULL);
  1132. off = h->got.offset;
  1133. BFD_ASSERT (off < sgot->size);
  1134. bfd_put_32 (output_bfd, rel->r_addend, sgot->contents + off);
  1135. relocation = sgot->output_offset + off;
  1136. /* The GOT relocation uses the addend. */
  1137. rel->r_addend = 0;
  1138. /* Change the reference to be indirect. */
  1139. contents[rel->r_offset - 1] |= 0x10;
  1140. relocation += sgot->output_section->vma;
  1141. }
  1142. break;
  1143. case R_VAX_PC32:
  1144. /* If we are creating an executable and the function this
  1145. reloc refers to is in a shared lib, then we made a PLT
  1146. entry for this symbol and need to handle the reloc like
  1147. a PLT reloc. */
  1148. if (bfd_link_pic (info))
  1149. goto r_vax_pc32_shared;
  1150. /* Fall through. */
  1151. case R_VAX_PLT32:
  1152. /* Relocation is to the entry for this symbol in the
  1153. procedure linkage table. */
  1154. /* Resolve a PLTxx reloc against a local symbol directly,
  1155. without using the procedure linkage table. */
  1156. if (h == NULL
  1157. || h->plt.offset == (bfd_vma) -1)
  1158. break;
  1159. splt = elf_hash_table (info)->splt;
  1160. BFD_ASSERT (splt != NULL);
  1161. sgotplt = elf_hash_table (info)->sgotplt;
  1162. BFD_ASSERT (sgotplt != NULL);
  1163. plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
  1164. /* Get the offset into the .got table of the entry that
  1165. corresponds to this function. Each .got entry is 4 bytes.
  1166. The first two are reserved. */
  1167. got_offset = (plt_index + 3) * 4;
  1168. /* We want the relocation to point into the .got.plt instead
  1169. of the plt itself. */
  1170. relocation = (sgotplt->output_section->vma
  1171. + sgotplt->output_offset
  1172. + got_offset);
  1173. contents[rel->r_offset-1] |= 0x10; /* make indirect */
  1174. if (rel->r_addend == 2)
  1175. {
  1176. h->plt.offset |= 1;
  1177. }
  1178. else if (rel->r_addend != 0)
  1179. _bfd_error_handler
  1180. /* xgettext:c-format */
  1181. (_("%pB: warning: PLT addend of %" PRId64 " to `%s'"
  1182. " from %pA section ignored"),
  1183. input_bfd, (int64_t) rel->r_addend, h->root.root.string,
  1184. input_section);
  1185. rel->r_addend = 0;
  1186. break;
  1187. case R_VAX_PC8:
  1188. case R_VAX_PC16:
  1189. r_vax_pc32_shared:
  1190. if (h == NULL
  1191. || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  1192. || h->forced_local)
  1193. break;
  1194. /* Fall through. */
  1195. case R_VAX_8:
  1196. case R_VAX_16:
  1197. case R_VAX_32:
  1198. if (bfd_link_pic (info)
  1199. && r_symndx != STN_UNDEF
  1200. && (input_section->flags & SEC_ALLOC) != 0
  1201. && ((r_type != R_VAX_PC8
  1202. && r_type != R_VAX_PC16
  1203. && r_type != R_VAX_PC32)
  1204. || ((input_section->flags & SEC_CODE)
  1205. && (!info->symbolic
  1206. || (!h->def_regular && h->type != STT_SECTION)))))
  1207. {
  1208. Elf_Internal_Rela outrel;
  1209. bfd_byte *loc;
  1210. bool skip, relocate;
  1211. /* When generating a shared object, these relocations
  1212. are copied into the output file to be resolved at run
  1213. time. */
  1214. if (sreloc == NULL)
  1215. {
  1216. sreloc = _bfd_elf_get_dynamic_reloc_section
  1217. (input_bfd, input_section, /*rela?*/ true);
  1218. if (sreloc == NULL)
  1219. return false;
  1220. }
  1221. skip = false;
  1222. relocate = false;
  1223. outrel.r_offset =
  1224. _bfd_elf_section_offset (output_bfd, info, input_section,
  1225. rel->r_offset);
  1226. if (outrel.r_offset == (bfd_vma) -1)
  1227. skip = true;
  1228. if (outrel.r_offset == (bfd_vma) -2)
  1229. skip = true, relocate = true;
  1230. outrel.r_offset += (input_section->output_section->vma
  1231. + input_section->output_offset);
  1232. if (skip)
  1233. memset (&outrel, 0, sizeof outrel);
  1234. /* h->dynindx may be -1 if the symbol was marked to
  1235. become local. */
  1236. else if (h != NULL
  1237. && ((! info->symbolic && h->dynindx != -1)
  1238. || !h->def_regular))
  1239. {
  1240. BFD_ASSERT (h->dynindx != -1);
  1241. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  1242. outrel.r_addend = relocation + rel->r_addend;
  1243. }
  1244. else
  1245. {
  1246. if (r_type == R_VAX_32)
  1247. {
  1248. relocate = true;
  1249. outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
  1250. BFD_ASSERT (bfd_get_signed_32 (input_bfd,
  1251. &contents[rel->r_offset]) == 0);
  1252. outrel.r_addend = relocation + rel->r_addend;
  1253. }
  1254. else
  1255. {
  1256. long indx;
  1257. if (bfd_is_abs_section (sec))
  1258. indx = 0;
  1259. else if (sec == NULL || sec->owner == NULL)
  1260. {
  1261. bfd_set_error (bfd_error_bad_value);
  1262. return false;
  1263. }
  1264. else
  1265. {
  1266. asection *osec;
  1267. /* We are turning this relocation into one
  1268. against a section symbol. It would be
  1269. proper to subtract the symbol's value,
  1270. osec->vma, from the emitted reloc addend,
  1271. but ld.so expects buggy relocs. */
  1272. osec = sec->output_section;
  1273. indx = elf_section_data (osec)->dynindx;
  1274. if (indx == 0)
  1275. {
  1276. struct elf_link_hash_table *htab;
  1277. htab = elf_hash_table (info);
  1278. osec = htab->text_index_section;
  1279. indx = elf_section_data (osec)->dynindx;
  1280. }
  1281. BFD_ASSERT (indx != 0);
  1282. }
  1283. outrel.r_info = ELF32_R_INFO (indx, r_type);
  1284. outrel.r_addend = relocation + rel->r_addend;
  1285. }
  1286. }
  1287. if ((input_section->flags & SEC_CODE) != 0
  1288. || (ELF32_R_TYPE (outrel.r_info) != R_VAX_32
  1289. && ELF32_R_TYPE (outrel.r_info) != R_VAX_RELATIVE
  1290. && ELF32_R_TYPE (outrel.r_info) != R_VAX_COPY
  1291. && ELF32_R_TYPE (outrel.r_info) != R_VAX_JMP_SLOT
  1292. && ELF32_R_TYPE (outrel.r_info) != R_VAX_GLOB_DAT))
  1293. {
  1294. if (h != NULL)
  1295. _bfd_error_handler
  1296. /* xgettext:c-format */
  1297. (_("%pB: warning: %s relocation against symbol `%s'"
  1298. " from %pA section"),
  1299. input_bfd, howto->name, h->root.root.string,
  1300. input_section);
  1301. else
  1302. _bfd_error_handler
  1303. /* xgettext:c-format */
  1304. (_("%pB: warning: %s relocation to %#" PRIx64
  1305. " from %pA section"),
  1306. input_bfd, howto->name, (uint64_t) outrel.r_addend,
  1307. input_section);
  1308. }
  1309. loc = sreloc->contents;
  1310. loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
  1311. bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
  1312. /* This reloc will be computed at runtime, so there's no
  1313. need to do anything now, except for R_VAX_32
  1314. relocations that have been turned into
  1315. R_VAX_RELATIVE. */
  1316. if (!relocate)
  1317. continue;
  1318. }
  1319. break;
  1320. case R_VAX_GNU_VTINHERIT:
  1321. case R_VAX_GNU_VTENTRY:
  1322. /* These are no-ops in the end. */
  1323. continue;
  1324. default:
  1325. break;
  1326. }
  1327. /* VAX PCREL relocations are from the end of relocation, not the start.
  1328. So subtract the difference from the relocation amount since we can't
  1329. add it to the offset. */
  1330. if (howto->pc_relative && howto->pcrel_offset)
  1331. relocation -= bfd_get_reloc_size(howto);
  1332. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  1333. contents, rel->r_offset,
  1334. relocation, rel->r_addend);
  1335. if (r != bfd_reloc_ok)
  1336. {
  1337. switch (r)
  1338. {
  1339. default:
  1340. case bfd_reloc_outofrange:
  1341. abort ();
  1342. case bfd_reloc_overflow:
  1343. {
  1344. const char *name;
  1345. if (h != NULL)
  1346. name = NULL;
  1347. else
  1348. {
  1349. name = bfd_elf_string_from_elf_section (input_bfd,
  1350. symtab_hdr->sh_link,
  1351. sym->st_name);
  1352. if (name == NULL)
  1353. return false;
  1354. if (*name == '\0')
  1355. name = bfd_section_name (sec);
  1356. }
  1357. info->callbacks->reloc_overflow
  1358. (info, (h ? &h->root : NULL), name, howto->name,
  1359. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  1360. }
  1361. break;
  1362. }
  1363. }
  1364. }
  1365. return true;
  1366. }
  1367. /* Finish up dynamic symbol handling. We set the contents of various
  1368. dynamic sections here. */
  1369. static bool
  1370. elf_vax_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
  1371. struct elf_link_hash_entry *h,
  1372. Elf_Internal_Sym *sym)
  1373. {
  1374. bfd *dynobj;
  1375. dynobj = elf_hash_table (info)->dynobj;
  1376. if (h->plt.offset != (bfd_vma) -1)
  1377. {
  1378. asection *splt;
  1379. asection *sgot;
  1380. asection *srela;
  1381. bfd_vma plt_index;
  1382. bfd_vma got_offset;
  1383. bfd_vma addend;
  1384. Elf_Internal_Rela rela;
  1385. bfd_byte *loc;
  1386. /* This symbol has an entry in the procedure linkage table. Set
  1387. it up. */
  1388. BFD_ASSERT (h->dynindx != -1);
  1389. splt = elf_hash_table (info)->splt;
  1390. sgot = elf_hash_table (info)->sgotplt;
  1391. srela = elf_hash_table (info)->srelplt;
  1392. BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
  1393. addend = 2 * (h->plt.offset & 1);
  1394. h->plt.offset &= ~1;
  1395. /* Get the index in the procedure linkage table which
  1396. corresponds to this symbol. This is the index of this symbol
  1397. in all the symbols for which we are making plt entries. The
  1398. first entry in the procedure linkage table is reserved. */
  1399. plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
  1400. /* Get the offset into the .got table of the entry that
  1401. corresponds to this function. Each .got entry is 4 bytes.
  1402. The first two are reserved. */
  1403. got_offset = (plt_index + 3) * 4;
  1404. /* Fill in the entry in the procedure linkage table. */
  1405. memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry,
  1406. PLT_ENTRY_SIZE);
  1407. /* The offset is relative to the first extension word. */
  1408. bfd_put_32 (output_bfd,
  1409. -(h->plt.offset + 8),
  1410. splt->contents + h->plt.offset + 4);
  1411. bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
  1412. splt->contents + h->plt.offset + 8);
  1413. /* Fill in the entry in the global offset table. */
  1414. bfd_put_32 (output_bfd,
  1415. (splt->output_section->vma
  1416. + splt->output_offset
  1417. + h->plt.offset) + addend,
  1418. sgot->contents + got_offset);
  1419. /* Fill in the entry in the .rela.plt section. */
  1420. rela.r_offset = (sgot->output_section->vma
  1421. + sgot->output_offset
  1422. + got_offset);
  1423. rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT);
  1424. rela.r_addend = addend;
  1425. loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
  1426. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1427. if (!h->def_regular)
  1428. {
  1429. /* Mark the symbol as undefined, rather than as defined in
  1430. the .plt section. Leave the value alone. */
  1431. sym->st_shndx = SHN_UNDEF;
  1432. }
  1433. }
  1434. if (h->got.offset != (bfd_vma) -1)
  1435. {
  1436. asection *sgot;
  1437. asection *srela;
  1438. Elf_Internal_Rela rela;
  1439. bfd_byte *loc;
  1440. /* This symbol has an entry in the global offset table. Set it
  1441. up. */
  1442. sgot = elf_hash_table (info)->sgot;
  1443. srela = elf_hash_table (info)->srelgot;
  1444. BFD_ASSERT (sgot != NULL && srela != NULL);
  1445. rela.r_offset = (sgot->output_section->vma
  1446. + sgot->output_offset
  1447. + h->got.offset);
  1448. rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT);
  1449. rela.r_addend = bfd_get_signed_32 (output_bfd,
  1450. sgot->contents + h->got.offset);
  1451. loc = srela->contents;
  1452. loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
  1453. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1454. }
  1455. if (h->needs_copy)
  1456. {
  1457. asection *s;
  1458. Elf_Internal_Rela rela;
  1459. bfd_byte *loc;
  1460. /* This symbol needs a copy reloc. Set it up. */
  1461. BFD_ASSERT (h->dynindx != -1
  1462. && (h->root.type == bfd_link_hash_defined
  1463. || h->root.type == bfd_link_hash_defweak));
  1464. s = bfd_get_linker_section (dynobj, ".rela.bss");
  1465. BFD_ASSERT (s != NULL);
  1466. rela.r_offset = (h->root.u.def.value
  1467. + h->root.u.def.section->output_section->vma
  1468. + h->root.u.def.section->output_offset);
  1469. rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY);
  1470. rela.r_addend = 0;
  1471. loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
  1472. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1473. }
  1474. /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
  1475. if (h == elf_hash_table (info)->hdynamic
  1476. || h == elf_hash_table (info)->hgot)
  1477. sym->st_shndx = SHN_ABS;
  1478. return true;
  1479. }
  1480. /* Finish up the dynamic sections. */
  1481. static bool
  1482. elf_vax_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
  1483. {
  1484. bfd *dynobj;
  1485. asection *sgot;
  1486. asection *sdyn;
  1487. dynobj = elf_hash_table (info)->dynobj;
  1488. sgot = elf_hash_table (info)->sgotplt;
  1489. BFD_ASSERT (sgot != NULL);
  1490. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  1491. if (elf_hash_table (info)->dynamic_sections_created)
  1492. {
  1493. asection *splt;
  1494. Elf32_External_Dyn *dyncon, *dynconend;
  1495. splt = elf_hash_table (info)->splt;
  1496. BFD_ASSERT (splt != NULL && sdyn != NULL);
  1497. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  1498. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  1499. for (; dyncon < dynconend; dyncon++)
  1500. {
  1501. Elf_Internal_Dyn dyn;
  1502. asection *s;
  1503. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  1504. switch (dyn.d_tag)
  1505. {
  1506. default:
  1507. break;
  1508. case DT_PLTGOT:
  1509. s = elf_hash_table (info)->sgotplt;
  1510. goto get_vma;
  1511. case DT_JMPREL:
  1512. s = elf_hash_table (info)->srelplt;
  1513. get_vma:
  1514. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  1515. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  1516. break;
  1517. case DT_PLTRELSZ:
  1518. s = elf_hash_table (info)->srelplt;
  1519. dyn.d_un.d_val = s->size;
  1520. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  1521. break;
  1522. }
  1523. }
  1524. /* Fill in the first entry in the procedure linkage table. */
  1525. if (splt->size > 0)
  1526. {
  1527. memcpy (splt->contents, elf_vax_plt0_entry, PLT_ENTRY_SIZE);
  1528. bfd_put_32 (output_bfd,
  1529. (sgot->output_section->vma
  1530. + sgot->output_offset + 4
  1531. - (splt->output_section->vma + 6)),
  1532. splt->contents + 2);
  1533. bfd_put_32 (output_bfd,
  1534. (sgot->output_section->vma
  1535. + sgot->output_offset + 8
  1536. - (splt->output_section->vma + 12)),
  1537. splt->contents + 8);
  1538. elf_section_data (splt->output_section)->this_hdr.sh_entsize
  1539. = PLT_ENTRY_SIZE;
  1540. }
  1541. }
  1542. /* Fill in the first three entries in the global offset table. */
  1543. if (sgot->size > 0)
  1544. {
  1545. if (sdyn == NULL)
  1546. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
  1547. else
  1548. bfd_put_32 (output_bfd,
  1549. sdyn->output_section->vma + sdyn->output_offset,
  1550. sgot->contents);
  1551. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
  1552. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
  1553. }
  1554. if (elf_section_data (sgot->output_section) != NULL)
  1555. elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
  1556. return true;
  1557. }
  1558. static enum elf_reloc_type_class
  1559. elf_vax_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  1560. const asection *rel_sec ATTRIBUTE_UNUSED,
  1561. const Elf_Internal_Rela *rela)
  1562. {
  1563. switch ((int) ELF32_R_TYPE (rela->r_info))
  1564. {
  1565. case R_VAX_RELATIVE:
  1566. return reloc_class_relative;
  1567. case R_VAX_JMP_SLOT:
  1568. return reloc_class_plt;
  1569. case R_VAX_COPY:
  1570. return reloc_class_copy;
  1571. default:
  1572. return reloc_class_normal;
  1573. }
  1574. }
  1575. static bfd_vma
  1576. elf_vax_plt_sym_val (bfd_vma i, const asection *plt,
  1577. const arelent *rel ATTRIBUTE_UNUSED)
  1578. {
  1579. return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
  1580. }
  1581. #define TARGET_LITTLE_SYM vax_elf32_vec
  1582. #define TARGET_LITTLE_NAME "elf32-vax"
  1583. #define ELF_MACHINE_CODE EM_VAX
  1584. #define ELF_MAXPAGESIZE 0x1000
  1585. #define elf_backend_create_dynamic_sections \
  1586. _bfd_elf_create_dynamic_sections
  1587. #define bfd_elf32_bfd_link_hash_table_create \
  1588. elf_vax_link_hash_table_create
  1589. #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link
  1590. #define elf_backend_check_relocs elf_vax_check_relocs
  1591. #define elf_backend_adjust_dynamic_symbol \
  1592. elf_vax_adjust_dynamic_symbol
  1593. #define elf_backend_always_size_sections \
  1594. elf_vax_always_size_sections
  1595. #define elf_backend_size_dynamic_sections \
  1596. elf_vax_size_dynamic_sections
  1597. #define elf_backend_init_index_section _bfd_elf_init_1_index_section
  1598. #define elf_backend_relocate_section elf_vax_relocate_section
  1599. #define elf_backend_finish_dynamic_symbol \
  1600. elf_vax_finish_dynamic_symbol
  1601. #define elf_backend_finish_dynamic_sections \
  1602. elf_vax_finish_dynamic_sections
  1603. #define elf_backend_reloc_type_class elf_vax_reloc_type_class
  1604. #define elf_backend_gc_mark_hook elf_vax_gc_mark_hook
  1605. #define elf_backend_plt_sym_val elf_vax_plt_sym_val
  1606. #define bfd_elf32_bfd_merge_private_bfd_data \
  1607. elf32_vax_merge_private_bfd_data
  1608. #define bfd_elf32_bfd_set_private_flags \
  1609. elf32_vax_set_private_flags
  1610. #define bfd_elf32_bfd_print_private_bfd_data \
  1611. elf32_vax_print_private_bfd_data
  1612. #define elf_backend_can_gc_sections 1
  1613. #define elf_backend_want_got_plt 1
  1614. #define elf_backend_plt_readonly 1
  1615. #define elf_backend_want_plt_sym 0
  1616. #define elf_backend_got_header_size 16
  1617. #define elf_backend_rela_normal 1
  1618. #define elf_backend_dtrel_excludes_plt 1
  1619. #include "elf32-target.h"