coff-alpha.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478
  1. /* BFD back-end for ALPHA Extended-Coff files.
  2. Copyright (C) 1993-2022 Free Software Foundation, Inc.
  3. Modified from coff-mips.c by Steve Chamberlain <sac@cygnus.com> and
  4. Ian Lance Taylor <ian@cygnus.com>.
  5. This file is part of BFD, the Binary File Descriptor library.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  17. MA 02110-1301, USA. */
  18. #include "sysdep.h"
  19. #include "bfd.h"
  20. #include "bfdlink.h"
  21. #include "libbfd.h"
  22. #include "coff/internal.h"
  23. #include "coff/sym.h"
  24. #include "coff/symconst.h"
  25. #include "coff/ecoff.h"
  26. #include "coff/alpha.h"
  27. #include "aout/ar.h"
  28. #include "libcoff.h"
  29. #include "libecoff.h"
  30. /* Prototypes for static functions. */
  31. /* ECOFF has COFF sections, but the debugging information is stored in
  32. a completely different format. ECOFF targets use some of the
  33. swapping routines from coffswap.h, and some of the generic COFF
  34. routines in coffgen.c, but, unlike the real COFF targets, do not
  35. use coffcode.h itself.
  36. Get the generic COFF swapping routines, except for the reloc,
  37. symbol, and lineno ones. Give them ecoff names. Define some
  38. accessor macros for the large sizes used for Alpha ECOFF. */
  39. #define GET_FILEHDR_SYMPTR H_GET_64
  40. #define PUT_FILEHDR_SYMPTR H_PUT_64
  41. #define GET_AOUTHDR_TSIZE H_GET_64
  42. #define PUT_AOUTHDR_TSIZE H_PUT_64
  43. #define GET_AOUTHDR_DSIZE H_GET_64
  44. #define PUT_AOUTHDR_DSIZE H_PUT_64
  45. #define GET_AOUTHDR_BSIZE H_GET_64
  46. #define PUT_AOUTHDR_BSIZE H_PUT_64
  47. #define GET_AOUTHDR_ENTRY H_GET_64
  48. #define PUT_AOUTHDR_ENTRY H_PUT_64
  49. #define GET_AOUTHDR_TEXT_START H_GET_64
  50. #define PUT_AOUTHDR_TEXT_START H_PUT_64
  51. #define GET_AOUTHDR_DATA_START H_GET_64
  52. #define PUT_AOUTHDR_DATA_START H_PUT_64
  53. #define GET_SCNHDR_PADDR H_GET_64
  54. #define PUT_SCNHDR_PADDR H_PUT_64
  55. #define GET_SCNHDR_VADDR H_GET_64
  56. #define PUT_SCNHDR_VADDR H_PUT_64
  57. #define GET_SCNHDR_SIZE H_GET_64
  58. #define PUT_SCNHDR_SIZE H_PUT_64
  59. #define GET_SCNHDR_SCNPTR H_GET_64
  60. #define PUT_SCNHDR_SCNPTR H_PUT_64
  61. #define GET_SCNHDR_RELPTR H_GET_64
  62. #define PUT_SCNHDR_RELPTR H_PUT_64
  63. #define GET_SCNHDR_LNNOPTR H_GET_64
  64. #define PUT_SCNHDR_LNNOPTR H_PUT_64
  65. #define ALPHAECOFF
  66. #define NO_COFF_RELOCS
  67. #define NO_COFF_SYMBOLS
  68. #define NO_COFF_LINENOS
  69. #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in
  70. #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out
  71. #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in
  72. #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out
  73. #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in
  74. #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out
  75. #include "coffswap.h"
  76. /* Get the ECOFF swapping routines. */
  77. #define ECOFF_64
  78. #include "ecoffswap.h"
  79. /* How to process the various reloc types. */
  80. static bfd_reloc_status_type
  81. reloc_nil (bfd *abfd ATTRIBUTE_UNUSED,
  82. arelent *reloc ATTRIBUTE_UNUSED,
  83. asymbol *sym ATTRIBUTE_UNUSED,
  84. void * data ATTRIBUTE_UNUSED,
  85. asection *sec ATTRIBUTE_UNUSED,
  86. bfd *output_bfd ATTRIBUTE_UNUSED,
  87. char **error_message ATTRIBUTE_UNUSED)
  88. {
  89. return bfd_reloc_ok;
  90. }
  91. /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
  92. from smaller values. Start with zero, widen, *then* decrement. */
  93. #define MINUS_ONE (((bfd_vma)0) - 1)
  94. static reloc_howto_type alpha_howto_table[] =
  95. {
  96. /* Reloc type 0 is ignored by itself. However, it appears after a
  97. GPDISP reloc to identify the location where the low order 16 bits
  98. of the gp register are loaded. */
  99. HOWTO (ALPHA_R_IGNORE, /* type */
  100. 0, /* rightshift */
  101. 0, /* size (0 = byte, 1 = short, 2 = long) */
  102. 8, /* bitsize */
  103. true, /* pc_relative */
  104. 0, /* bitpos */
  105. complain_overflow_dont, /* complain_on_overflow */
  106. reloc_nil, /* special_function */
  107. "IGNORE", /* name */
  108. true, /* partial_inplace */
  109. 0, /* src_mask */
  110. 0, /* dst_mask */
  111. true), /* pcrel_offset */
  112. /* A 32 bit reference to a symbol. */
  113. HOWTO (ALPHA_R_REFLONG, /* type */
  114. 0, /* rightshift */
  115. 2, /* size (0 = byte, 1 = short, 2 = long) */
  116. 32, /* bitsize */
  117. false, /* pc_relative */
  118. 0, /* bitpos */
  119. complain_overflow_bitfield, /* complain_on_overflow */
  120. 0, /* special_function */
  121. "REFLONG", /* name */
  122. true, /* partial_inplace */
  123. 0xffffffff, /* src_mask */
  124. 0xffffffff, /* dst_mask */
  125. false), /* pcrel_offset */
  126. /* A 64 bit reference to a symbol. */
  127. HOWTO (ALPHA_R_REFQUAD, /* type */
  128. 0, /* rightshift */
  129. 4, /* size (0 = byte, 1 = short, 2 = long) */
  130. 64, /* bitsize */
  131. false, /* pc_relative */
  132. 0, /* bitpos */
  133. complain_overflow_bitfield, /* complain_on_overflow */
  134. 0, /* special_function */
  135. "REFQUAD", /* name */
  136. true, /* partial_inplace */
  137. MINUS_ONE, /* src_mask */
  138. MINUS_ONE, /* dst_mask */
  139. false), /* pcrel_offset */
  140. /* A 32 bit GP relative offset. This is just like REFLONG except
  141. that when the value is used the value of the gp register will be
  142. added in. */
  143. HOWTO (ALPHA_R_GPREL32, /* type */
  144. 0, /* rightshift */
  145. 2, /* size (0 = byte, 1 = short, 2 = long) */
  146. 32, /* bitsize */
  147. false, /* pc_relative */
  148. 0, /* bitpos */
  149. complain_overflow_bitfield, /* complain_on_overflow */
  150. 0, /* special_function */
  151. "GPREL32", /* name */
  152. true, /* partial_inplace */
  153. 0xffffffff, /* src_mask */
  154. 0xffffffff, /* dst_mask */
  155. false), /* pcrel_offset */
  156. /* Used for an instruction that refers to memory off the GP
  157. register. The offset is 16 bits of the 32 bit instruction. This
  158. reloc always seems to be against the .lita section. */
  159. HOWTO (ALPHA_R_LITERAL, /* type */
  160. 0, /* rightshift */
  161. 2, /* size (0 = byte, 1 = short, 2 = long) */
  162. 16, /* bitsize */
  163. false, /* pc_relative */
  164. 0, /* bitpos */
  165. complain_overflow_signed, /* complain_on_overflow */
  166. 0, /* special_function */
  167. "LITERAL", /* name */
  168. true, /* partial_inplace */
  169. 0xffff, /* src_mask */
  170. 0xffff, /* dst_mask */
  171. false), /* pcrel_offset */
  172. /* This reloc only appears immediately following a LITERAL reloc.
  173. It identifies a use of the literal. It seems that the linker can
  174. use this to eliminate a portion of the .lita section. The symbol
  175. index is special: 1 means the literal address is in the base
  176. register of a memory format instruction; 2 means the literal
  177. address is in the byte offset register of a byte-manipulation
  178. instruction; 3 means the literal address is in the target
  179. register of a jsr instruction. This does not actually do any
  180. relocation. */
  181. HOWTO (ALPHA_R_LITUSE, /* type */
  182. 0, /* rightshift */
  183. 2, /* size (0 = byte, 1 = short, 2 = long) */
  184. 32, /* bitsize */
  185. false, /* pc_relative */
  186. 0, /* bitpos */
  187. complain_overflow_dont, /* complain_on_overflow */
  188. reloc_nil, /* special_function */
  189. "LITUSE", /* name */
  190. false, /* partial_inplace */
  191. 0, /* src_mask */
  192. 0, /* dst_mask */
  193. false), /* pcrel_offset */
  194. /* Load the gp register. This is always used for a ldah instruction
  195. which loads the upper 16 bits of the gp register. The next reloc
  196. will be an IGNORE reloc which identifies the location of the lda
  197. instruction which loads the lower 16 bits. The symbol index of
  198. the GPDISP instruction appears to actually be the number of bytes
  199. between the ldah and lda instructions. This gives two different
  200. ways to determine where the lda instruction is; I don't know why
  201. both are used. The value to use for the relocation is the
  202. difference between the GP value and the current location; the
  203. load will always be done against a register holding the current
  204. address. */
  205. HOWTO (ALPHA_R_GPDISP, /* type */
  206. 16, /* rightshift */
  207. 2, /* size (0 = byte, 1 = short, 2 = long) */
  208. 16, /* bitsize */
  209. true, /* pc_relative */
  210. 0, /* bitpos */
  211. complain_overflow_dont, /* complain_on_overflow */
  212. reloc_nil, /* special_function */
  213. "GPDISP", /* name */
  214. true, /* partial_inplace */
  215. 0xffff, /* src_mask */
  216. 0xffff, /* dst_mask */
  217. true), /* pcrel_offset */
  218. /* A 21 bit branch. The native assembler generates these for
  219. branches within the text segment, and also fills in the PC
  220. relative offset in the instruction. */
  221. HOWTO (ALPHA_R_BRADDR, /* type */
  222. 2, /* rightshift */
  223. 2, /* size (0 = byte, 1 = short, 2 = long) */
  224. 21, /* bitsize */
  225. true, /* pc_relative */
  226. 0, /* bitpos */
  227. complain_overflow_signed, /* complain_on_overflow */
  228. 0, /* special_function */
  229. "BRADDR", /* name */
  230. true, /* partial_inplace */
  231. 0x1fffff, /* src_mask */
  232. 0x1fffff, /* dst_mask */
  233. false), /* pcrel_offset */
  234. /* A hint for a jump to a register. */
  235. HOWTO (ALPHA_R_HINT, /* type */
  236. 2, /* rightshift */
  237. 2, /* size (0 = byte, 1 = short, 2 = long) */
  238. 14, /* bitsize */
  239. true, /* pc_relative */
  240. 0, /* bitpos */
  241. complain_overflow_dont, /* complain_on_overflow */
  242. 0, /* special_function */
  243. "HINT", /* name */
  244. true, /* partial_inplace */
  245. 0x3fff, /* src_mask */
  246. 0x3fff, /* dst_mask */
  247. false), /* pcrel_offset */
  248. /* 16 bit PC relative offset. */
  249. HOWTO (ALPHA_R_SREL16, /* type */
  250. 0, /* rightshift */
  251. 1, /* size (0 = byte, 1 = short, 2 = long) */
  252. 16, /* bitsize */
  253. true, /* pc_relative */
  254. 0, /* bitpos */
  255. complain_overflow_signed, /* complain_on_overflow */
  256. 0, /* special_function */
  257. "SREL16", /* name */
  258. true, /* partial_inplace */
  259. 0xffff, /* src_mask */
  260. 0xffff, /* dst_mask */
  261. false), /* pcrel_offset */
  262. /* 32 bit PC relative offset. */
  263. HOWTO (ALPHA_R_SREL32, /* type */
  264. 0, /* rightshift */
  265. 2, /* size (0 = byte, 1 = short, 2 = long) */
  266. 32, /* bitsize */
  267. true, /* pc_relative */
  268. 0, /* bitpos */
  269. complain_overflow_signed, /* complain_on_overflow */
  270. 0, /* special_function */
  271. "SREL32", /* name */
  272. true, /* partial_inplace */
  273. 0xffffffff, /* src_mask */
  274. 0xffffffff, /* dst_mask */
  275. false), /* pcrel_offset */
  276. /* A 64 bit PC relative offset. */
  277. HOWTO (ALPHA_R_SREL64, /* type */
  278. 0, /* rightshift */
  279. 4, /* size (0 = byte, 1 = short, 2 = long) */
  280. 64, /* bitsize */
  281. true, /* pc_relative */
  282. 0, /* bitpos */
  283. complain_overflow_signed, /* complain_on_overflow */
  284. 0, /* special_function */
  285. "SREL64", /* name */
  286. true, /* partial_inplace */
  287. MINUS_ONE, /* src_mask */
  288. MINUS_ONE, /* dst_mask */
  289. false), /* pcrel_offset */
  290. /* Push a value on the reloc evaluation stack. */
  291. HOWTO (ALPHA_R_OP_PUSH, /* type */
  292. 0, /* rightshift */
  293. 0, /* size (0 = byte, 1 = short, 2 = long) */
  294. 0, /* bitsize */
  295. false, /* pc_relative */
  296. 0, /* bitpos */
  297. complain_overflow_dont, /* complain_on_overflow */
  298. 0, /* special_function */
  299. "OP_PUSH", /* name */
  300. false, /* partial_inplace */
  301. 0, /* src_mask */
  302. 0, /* dst_mask */
  303. false), /* pcrel_offset */
  304. /* Store the value from the stack at the given address. Store it in
  305. a bitfield of size r_size starting at bit position r_offset. */
  306. HOWTO (ALPHA_R_OP_STORE, /* type */
  307. 0, /* rightshift */
  308. 4, /* size (0 = byte, 1 = short, 2 = long) */
  309. 64, /* bitsize */
  310. false, /* pc_relative */
  311. 0, /* bitpos */
  312. complain_overflow_dont, /* complain_on_overflow */
  313. 0, /* special_function */
  314. "OP_STORE", /* name */
  315. false, /* partial_inplace */
  316. 0, /* src_mask */
  317. MINUS_ONE, /* dst_mask */
  318. false), /* pcrel_offset */
  319. /* Subtract the reloc address from the value on the top of the
  320. relocation stack. */
  321. HOWTO (ALPHA_R_OP_PSUB, /* type */
  322. 0, /* rightshift */
  323. 0, /* size (0 = byte, 1 = short, 2 = long) */
  324. 0, /* bitsize */
  325. false, /* pc_relative */
  326. 0, /* bitpos */
  327. complain_overflow_dont, /* complain_on_overflow */
  328. 0, /* special_function */
  329. "OP_PSUB", /* name */
  330. false, /* partial_inplace */
  331. 0, /* src_mask */
  332. 0, /* dst_mask */
  333. false), /* pcrel_offset */
  334. /* Shift the value on the top of the relocation stack right by the
  335. given value. */
  336. HOWTO (ALPHA_R_OP_PRSHIFT, /* type */
  337. 0, /* rightshift */
  338. 0, /* size (0 = byte, 1 = short, 2 = long) */
  339. 0, /* bitsize */
  340. false, /* pc_relative */
  341. 0, /* bitpos */
  342. complain_overflow_dont, /* complain_on_overflow */
  343. 0, /* special_function */
  344. "OP_PRSHIFT", /* name */
  345. false, /* partial_inplace */
  346. 0, /* src_mask */
  347. 0, /* dst_mask */
  348. false), /* pcrel_offset */
  349. /* Adjust the GP value for a new range in the object file. */
  350. HOWTO (ALPHA_R_GPVALUE, /* type */
  351. 0, /* rightshift */
  352. 0, /* size (0 = byte, 1 = short, 2 = long) */
  353. 0, /* bitsize */
  354. false, /* pc_relative */
  355. 0, /* bitpos */
  356. complain_overflow_dont, /* complain_on_overflow */
  357. 0, /* special_function */
  358. "GPVALUE", /* name */
  359. false, /* partial_inplace */
  360. 0, /* src_mask */
  361. 0, /* dst_mask */
  362. false) /* pcrel_offset */
  363. };
  364. /* Recognize an Alpha ECOFF file. */
  365. static bfd_cleanup
  366. alpha_ecoff_object_p (bfd *abfd)
  367. {
  368. bfd_cleanup ret;
  369. ret = coff_object_p (abfd);
  370. if (ret != NULL)
  371. {
  372. asection *sec;
  373. /* Alpha ECOFF has a .pdata section. The lnnoptr field of the
  374. .pdata section is the number of entries it contains. Each
  375. entry takes up 8 bytes. The number of entries is required
  376. since the section is aligned to a 16 byte boundary. When we
  377. link .pdata sections together, we do not want to include the
  378. alignment bytes. We handle this on input by faking the size
  379. of the .pdata section to remove the unwanted alignment bytes.
  380. On output we will set the lnnoptr field and force the
  381. alignment. */
  382. sec = bfd_get_section_by_name (abfd, _PDATA);
  383. if (sec != (asection *) NULL)
  384. {
  385. bfd_size_type size;
  386. size = (bfd_size_type) sec->line_filepos * 8;
  387. BFD_ASSERT (size == sec->size
  388. || size + 8 == sec->size);
  389. if (!bfd_set_section_size (sec, size))
  390. return NULL;
  391. }
  392. }
  393. return ret;
  394. }
  395. /* See whether the magic number matches. */
  396. static bool
  397. alpha_ecoff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED,
  398. void * filehdr)
  399. {
  400. struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  401. if (! ALPHA_ECOFF_BADMAG (*internal_f))
  402. return true;
  403. if (ALPHA_ECOFF_COMPRESSEDMAG (*internal_f))
  404. _bfd_error_handler
  405. (_("%pB: cannot handle compressed Alpha binaries; "
  406. "use compiler flags, or objZ, to generate uncompressed binaries"),
  407. abfd);
  408. return false;
  409. }
  410. /* This is a hook called by coff_real_object_p to create any backend
  411. specific information. */
  412. static void *
  413. alpha_ecoff_mkobject_hook (bfd *abfd, void * filehdr, void * aouthdr)
  414. {
  415. void * ecoff;
  416. ecoff = _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr);
  417. if (ecoff != NULL)
  418. {
  419. struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  420. /* Set additional BFD flags according to the object type from the
  421. machine specific file header flags. */
  422. switch (internal_f->f_flags & F_ALPHA_OBJECT_TYPE_MASK)
  423. {
  424. case F_ALPHA_SHARABLE:
  425. abfd->flags |= DYNAMIC;
  426. break;
  427. case F_ALPHA_CALL_SHARED:
  428. /* Always executable if using shared libraries as the run time
  429. loader might resolve undefined references. */
  430. abfd->flags |= (DYNAMIC | EXEC_P);
  431. break;
  432. }
  433. }
  434. return ecoff;
  435. }
  436. /* Reloc handling. */
  437. /* Swap a reloc in. */
  438. static void
  439. alpha_ecoff_swap_reloc_in (bfd *abfd,
  440. void * ext_ptr,
  441. struct internal_reloc *intern)
  442. {
  443. const RELOC *ext = (RELOC *) ext_ptr;
  444. intern->r_vaddr = H_GET_64 (abfd, ext->r_vaddr);
  445. intern->r_symndx = H_GET_32 (abfd, ext->r_symndx);
  446. BFD_ASSERT (bfd_header_little_endian (abfd));
  447. intern->r_type = ((ext->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
  448. >> RELOC_BITS0_TYPE_SH_LITTLE);
  449. intern->r_extern = (ext->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
  450. intern->r_offset = ((ext->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
  451. >> RELOC_BITS1_OFFSET_SH_LITTLE);
  452. /* Ignored the reserved bits. */
  453. intern->r_size = ((ext->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
  454. >> RELOC_BITS3_SIZE_SH_LITTLE);
  455. if (intern->r_type == ALPHA_R_LITUSE
  456. || intern->r_type == ALPHA_R_GPDISP)
  457. {
  458. /* Handle the LITUSE and GPDISP relocs specially. Its symndx
  459. value is not actually a symbol index, but is instead a
  460. special code. We put the code in the r_size field, and
  461. clobber the symndx. */
  462. if (intern->r_size != 0)
  463. abort ();
  464. intern->r_size = intern->r_symndx;
  465. intern->r_symndx = RELOC_SECTION_NONE;
  466. }
  467. else if (intern->r_type == ALPHA_R_IGNORE)
  468. {
  469. /* The IGNORE reloc generally follows a GPDISP reloc, and is
  470. against the .lita section. The section is irrelevant. */
  471. if (! intern->r_extern &&
  472. intern->r_symndx == RELOC_SECTION_ABS)
  473. abort ();
  474. if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA)
  475. intern->r_symndx = RELOC_SECTION_ABS;
  476. }
  477. }
  478. /* Swap a reloc out. */
  479. static void
  480. alpha_ecoff_swap_reloc_out (bfd *abfd,
  481. const struct internal_reloc *intern,
  482. void * dst)
  483. {
  484. RELOC *ext = (RELOC *) dst;
  485. long symndx;
  486. unsigned char size;
  487. /* Undo the hackery done in swap_reloc_in. */
  488. if (intern->r_type == ALPHA_R_LITUSE
  489. || intern->r_type == ALPHA_R_GPDISP)
  490. {
  491. symndx = intern->r_size;
  492. size = 0;
  493. }
  494. else if (intern->r_type == ALPHA_R_IGNORE
  495. && ! intern->r_extern
  496. && intern->r_symndx == RELOC_SECTION_ABS)
  497. {
  498. symndx = RELOC_SECTION_LITA;
  499. size = intern->r_size;
  500. }
  501. else
  502. {
  503. symndx = intern->r_symndx;
  504. size = intern->r_size;
  505. }
  506. /* XXX FIXME: The maximum symndx value used to be 14 but this
  507. fails with object files produced by DEC's C++ compiler.
  508. Where does the value 14 (or 15) come from anyway ? */
  509. BFD_ASSERT (intern->r_extern
  510. || (intern->r_symndx >= 0 && intern->r_symndx <= 15));
  511. H_PUT_64 (abfd, intern->r_vaddr, ext->r_vaddr);
  512. H_PUT_32 (abfd, symndx, ext->r_symndx);
  513. BFD_ASSERT (bfd_header_little_endian (abfd));
  514. ext->r_bits[0] = ((intern->r_type << RELOC_BITS0_TYPE_SH_LITTLE)
  515. & RELOC_BITS0_TYPE_LITTLE);
  516. ext->r_bits[1] = ((intern->r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0)
  517. | ((intern->r_offset << RELOC_BITS1_OFFSET_SH_LITTLE)
  518. & RELOC_BITS1_OFFSET_LITTLE));
  519. ext->r_bits[2] = 0;
  520. ext->r_bits[3] = ((size << RELOC_BITS3_SIZE_SH_LITTLE)
  521. & RELOC_BITS3_SIZE_LITTLE);
  522. }
  523. /* Finish canonicalizing a reloc. Part of this is generic to all
  524. ECOFF targets, and that part is in ecoff.c. The rest is done in
  525. this backend routine. It must fill in the howto field. */
  526. static void
  527. alpha_adjust_reloc_in (bfd *abfd,
  528. const struct internal_reloc *intern,
  529. arelent *rptr)
  530. {
  531. if (intern->r_type > ALPHA_R_GPVALUE)
  532. {
  533. /* xgettext:c-format */
  534. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  535. abfd, intern->r_type);
  536. bfd_set_error (bfd_error_bad_value);
  537. rptr->addend = 0;
  538. rptr->howto = NULL;
  539. return;
  540. }
  541. switch (intern->r_type)
  542. {
  543. case ALPHA_R_BRADDR:
  544. case ALPHA_R_SREL16:
  545. case ALPHA_R_SREL32:
  546. case ALPHA_R_SREL64:
  547. /* This relocs appear to be fully resolved when they are against
  548. internal symbols. Against external symbols, BRADDR at least
  549. appears to be resolved against the next instruction. */
  550. if (! intern->r_extern)
  551. rptr->addend = 0;
  552. else
  553. rptr->addend = - (intern->r_vaddr + 4);
  554. break;
  555. case ALPHA_R_GPREL32:
  556. case ALPHA_R_LITERAL:
  557. /* Copy the gp value for this object file into the addend, to
  558. ensure that we are not confused by the linker. */
  559. if (! intern->r_extern)
  560. rptr->addend += ecoff_data (abfd)->gp;
  561. break;
  562. case ALPHA_R_LITUSE:
  563. case ALPHA_R_GPDISP:
  564. /* The LITUSE and GPDISP relocs do not use a symbol, or an
  565. addend, but they do use a special code. Put this code in the
  566. addend field. */
  567. rptr->addend = intern->r_size;
  568. break;
  569. case ALPHA_R_OP_STORE:
  570. /* The STORE reloc needs the size and offset fields. We store
  571. them in the addend. */
  572. BFD_ASSERT (intern->r_offset <= 256);
  573. rptr->addend = (intern->r_offset << 8) + intern->r_size;
  574. break;
  575. case ALPHA_R_OP_PUSH:
  576. case ALPHA_R_OP_PSUB:
  577. case ALPHA_R_OP_PRSHIFT:
  578. /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
  579. address. I believe that the address supplied is really an
  580. addend. */
  581. rptr->addend = intern->r_vaddr;
  582. break;
  583. case ALPHA_R_GPVALUE:
  584. /* Set the addend field to the new GP value. */
  585. rptr->addend = intern->r_symndx + ecoff_data (abfd)->gp;
  586. break;
  587. case ALPHA_R_IGNORE:
  588. /* If the type is ALPHA_R_IGNORE, make sure this is a reference
  589. to the absolute section so that the reloc is ignored. For
  590. some reason the address of this reloc type is not adjusted by
  591. the section vma. We record the gp value for this object file
  592. here, for convenience when doing the GPDISP relocation. */
  593. rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
  594. rptr->address = intern->r_vaddr;
  595. rptr->addend = ecoff_data (abfd)->gp;
  596. break;
  597. default:
  598. break;
  599. }
  600. rptr->howto = &alpha_howto_table[intern->r_type];
  601. }
  602. /* When writing out a reloc we need to pull some values back out of
  603. the addend field into the reloc. This is roughly the reverse of
  604. alpha_adjust_reloc_in, except that there are several changes we do
  605. not need to undo. */
  606. static void
  607. alpha_adjust_reloc_out (bfd *abfd ATTRIBUTE_UNUSED,
  608. const arelent *rel,
  609. struct internal_reloc *intern)
  610. {
  611. switch (intern->r_type)
  612. {
  613. case ALPHA_R_LITUSE:
  614. case ALPHA_R_GPDISP:
  615. intern->r_size = rel->addend;
  616. break;
  617. case ALPHA_R_OP_STORE:
  618. intern->r_size = rel->addend & 0xff;
  619. intern->r_offset = (rel->addend >> 8) & 0xff;
  620. break;
  621. case ALPHA_R_OP_PUSH:
  622. case ALPHA_R_OP_PSUB:
  623. case ALPHA_R_OP_PRSHIFT:
  624. intern->r_vaddr = rel->addend;
  625. break;
  626. case ALPHA_R_IGNORE:
  627. intern->r_vaddr = rel->address;
  628. break;
  629. default:
  630. break;
  631. }
  632. }
  633. /* The size of the stack for the relocation evaluator. */
  634. #define RELOC_STACKSIZE (10)
  635. /* Alpha ECOFF relocs have a built in expression evaluator as well as
  636. other interdependencies. Rather than use a bunch of special
  637. functions and global variables, we use a single routine to do all
  638. the relocation for a section. I haven't yet worked out how the
  639. assembler is going to handle this. */
  640. static bfd_byte *
  641. alpha_ecoff_get_relocated_section_contents (bfd *abfd,
  642. struct bfd_link_info *link_info,
  643. struct bfd_link_order *link_order,
  644. bfd_byte *data,
  645. bool relocatable,
  646. asymbol **symbols)
  647. {
  648. bfd *input_bfd = link_order->u.indirect.section->owner;
  649. asection *input_section = link_order->u.indirect.section;
  650. long reloc_size;
  651. arelent **reloc_vector;
  652. long reloc_count;
  653. bfd *output_bfd = relocatable ? abfd : (bfd *) NULL;
  654. bfd_vma gp;
  655. bool gp_undefined;
  656. bfd_vma stack[RELOC_STACKSIZE];
  657. int tos = 0;
  658. reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
  659. if (reloc_size < 0)
  660. return NULL;
  661. if (!bfd_get_full_section_contents (input_bfd, input_section, &data))
  662. return NULL;
  663. if (data == NULL)
  664. return NULL;
  665. if (reloc_size == 0)
  666. return data;
  667. reloc_vector = (arelent **) bfd_malloc (reloc_size);
  668. if (reloc_vector == NULL)
  669. return NULL;
  670. reloc_count = bfd_canonicalize_reloc (input_bfd, input_section,
  671. reloc_vector, symbols);
  672. if (reloc_count < 0)
  673. goto error_return;
  674. if (reloc_count == 0)
  675. goto successful_return;
  676. /* Get the GP value for the output BFD. */
  677. gp_undefined = false;
  678. gp = _bfd_get_gp_value (abfd);
  679. if (gp == 0)
  680. {
  681. if (relocatable)
  682. {
  683. asection *sec;
  684. bfd_vma lo;
  685. /* Make up a value. */
  686. lo = (bfd_vma) -1;
  687. for (sec = abfd->sections; sec != NULL; sec = sec->next)
  688. {
  689. if (sec->vma < lo
  690. && (strcmp (sec->name, ".sbss") == 0
  691. || strcmp (sec->name, ".sdata") == 0
  692. || strcmp (sec->name, ".lit4") == 0
  693. || strcmp (sec->name, ".lit8") == 0
  694. || strcmp (sec->name, ".lita") == 0))
  695. lo = sec->vma;
  696. }
  697. gp = lo + 0x8000;
  698. _bfd_set_gp_value (abfd, gp);
  699. }
  700. else
  701. {
  702. struct bfd_link_hash_entry *h;
  703. h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false,
  704. true);
  705. if (h == (struct bfd_link_hash_entry *) NULL
  706. || h->type != bfd_link_hash_defined)
  707. gp_undefined = true;
  708. else
  709. {
  710. gp = (h->u.def.value
  711. + h->u.def.section->output_section->vma
  712. + h->u.def.section->output_offset);
  713. _bfd_set_gp_value (abfd, gp);
  714. }
  715. }
  716. }
  717. for (; *reloc_vector != (arelent *) NULL; reloc_vector++)
  718. {
  719. arelent *rel;
  720. bfd_reloc_status_type r;
  721. char *err;
  722. rel = *reloc_vector;
  723. r = bfd_reloc_ok;
  724. switch (rel->howto->type)
  725. {
  726. case ALPHA_R_IGNORE:
  727. rel->address += input_section->output_offset;
  728. break;
  729. case ALPHA_R_REFLONG:
  730. case ALPHA_R_REFQUAD:
  731. case ALPHA_R_BRADDR:
  732. case ALPHA_R_HINT:
  733. case ALPHA_R_SREL16:
  734. case ALPHA_R_SREL32:
  735. case ALPHA_R_SREL64:
  736. if (relocatable
  737. && ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)
  738. {
  739. rel->address += input_section->output_offset;
  740. break;
  741. }
  742. r = bfd_perform_relocation (input_bfd, rel, data, input_section,
  743. output_bfd, &err);
  744. break;
  745. case ALPHA_R_GPREL32:
  746. /* This relocation is used in a switch table. It is a 32
  747. bit offset from the current GP value. We must adjust it
  748. by the different between the original GP value and the
  749. current GP value. The original GP value is stored in the
  750. addend. We adjust the addend and let
  751. bfd_perform_relocation finish the job. */
  752. rel->addend -= gp;
  753. r = bfd_perform_relocation (input_bfd, rel, data, input_section,
  754. output_bfd, &err);
  755. if (r == bfd_reloc_ok && gp_undefined)
  756. {
  757. r = bfd_reloc_dangerous;
  758. err = (char *) _("GP relative relocation used when GP not defined");
  759. }
  760. break;
  761. case ALPHA_R_LITERAL:
  762. /* This is a reference to a literal value, generally
  763. (always?) in the .lita section. This is a 16 bit GP
  764. relative relocation. Sometimes the subsequent reloc is a
  765. LITUSE reloc, which indicates how this reloc is used.
  766. This sometimes permits rewriting the two instructions
  767. referred to by the LITERAL and the LITUSE into different
  768. instructions which do not refer to .lita. This can save
  769. a memory reference, and permits removing a value from
  770. .lita thus saving GP relative space.
  771. We do not these optimizations. To do them we would need
  772. to arrange to link the .lita section first, so that by
  773. the time we got here we would know the final values to
  774. use. This would not be particularly difficult, but it is
  775. not currently implemented. */
  776. {
  777. unsigned long insn;
  778. /* I believe that the LITERAL reloc will only apply to a
  779. ldq or ldl instruction, so check my assumption. */
  780. insn = bfd_get_32 (input_bfd, data + rel->address);
  781. BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29
  782. || ((insn >> 26) & 0x3f) == 0x28);
  783. rel->addend -= gp;
  784. r = bfd_perform_relocation (input_bfd, rel, data, input_section,
  785. output_bfd, &err);
  786. if (r == bfd_reloc_ok && gp_undefined)
  787. {
  788. r = bfd_reloc_dangerous;
  789. err =
  790. (char *) _("GP relative relocation used when GP not defined");
  791. }
  792. }
  793. break;
  794. case ALPHA_R_LITUSE:
  795. /* See ALPHA_R_LITERAL above for the uses of this reloc. It
  796. does not cause anything to happen, itself. */
  797. rel->address += input_section->output_offset;
  798. break;
  799. case ALPHA_R_GPDISP:
  800. /* This marks the ldah of an ldah/lda pair which loads the
  801. gp register with the difference of the gp value and the
  802. current location. The second of the pair is r_size bytes
  803. ahead; it used to be marked with an ALPHA_R_IGNORE reloc,
  804. but that no longer happens in OSF/1 3.2. */
  805. {
  806. unsigned long insn1, insn2;
  807. bfd_vma addend;
  808. /* Get the two instructions. */
  809. insn1 = bfd_get_32 (input_bfd, data + rel->address);
  810. insn2 = bfd_get_32 (input_bfd, data + rel->address + rel->addend);
  811. BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
  812. BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
  813. /* Get the existing addend. We must account for the sign
  814. extension done by lda and ldah. */
  815. addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff);
  816. if (insn1 & 0x8000)
  817. {
  818. addend -= 0x80000000;
  819. addend -= 0x80000000;
  820. }
  821. if (insn2 & 0x8000)
  822. addend -= 0x10000;
  823. /* The existing addend includes the different between the
  824. gp of the input BFD and the address in the input BFD.
  825. Subtract this out. */
  826. addend -= (ecoff_data (input_bfd)->gp
  827. - (input_section->vma + rel->address));
  828. /* Now add in the final gp value, and subtract out the
  829. final address. */
  830. addend += (gp
  831. - (input_section->output_section->vma
  832. + input_section->output_offset
  833. + rel->address));
  834. /* Change the instructions, accounting for the sign
  835. extension, and write them out. */
  836. if (addend & 0x8000)
  837. addend += 0x10000;
  838. insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff);
  839. insn2 = (insn2 & 0xffff0000) | (addend & 0xffff);
  840. bfd_put_32 (input_bfd, (bfd_vma) insn1, data + rel->address);
  841. bfd_put_32 (input_bfd, (bfd_vma) insn2,
  842. data + rel->address + rel->addend);
  843. rel->address += input_section->output_offset;
  844. }
  845. break;
  846. case ALPHA_R_OP_PUSH:
  847. /* Push a value on the reloc evaluation stack. */
  848. {
  849. asymbol *symbol;
  850. bfd_vma relocation;
  851. if (relocatable)
  852. {
  853. rel->address += input_section->output_offset;
  854. break;
  855. }
  856. /* Figure out the relocation of this symbol. */
  857. symbol = *rel->sym_ptr_ptr;
  858. if (bfd_is_und_section (symbol->section))
  859. r = bfd_reloc_undefined;
  860. if (bfd_is_com_section (symbol->section))
  861. relocation = 0;
  862. else
  863. relocation = symbol->value;
  864. relocation += symbol->section->output_section->vma;
  865. relocation += symbol->section->output_offset;
  866. relocation += rel->addend;
  867. if (tos >= RELOC_STACKSIZE)
  868. abort ();
  869. stack[tos++] = relocation;
  870. }
  871. break;
  872. case ALPHA_R_OP_STORE:
  873. /* Store a value from the reloc stack into a bitfield. */
  874. {
  875. bfd_vma val;
  876. int offset, size;
  877. if (relocatable)
  878. {
  879. rel->address += input_section->output_offset;
  880. break;
  881. }
  882. if (tos == 0)
  883. abort ();
  884. /* The offset and size for this reloc are encoded into the
  885. addend field by alpha_adjust_reloc_in. */
  886. offset = (rel->addend >> 8) & 0xff;
  887. size = rel->addend & 0xff;
  888. val = bfd_get_64 (abfd, data + rel->address);
  889. val &=~ (((1 << size) - 1) << offset);
  890. val |= (stack[--tos] & ((1 << size) - 1)) << offset;
  891. bfd_put_64 (abfd, val, data + rel->address);
  892. }
  893. break;
  894. case ALPHA_R_OP_PSUB:
  895. /* Subtract a value from the top of the stack. */
  896. {
  897. asymbol *symbol;
  898. bfd_vma relocation;
  899. if (relocatable)
  900. {
  901. rel->address += input_section->output_offset;
  902. break;
  903. }
  904. /* Figure out the relocation of this symbol. */
  905. symbol = *rel->sym_ptr_ptr;
  906. if (bfd_is_und_section (symbol->section))
  907. r = bfd_reloc_undefined;
  908. if (bfd_is_com_section (symbol->section))
  909. relocation = 0;
  910. else
  911. relocation = symbol->value;
  912. relocation += symbol->section->output_section->vma;
  913. relocation += symbol->section->output_offset;
  914. relocation += rel->addend;
  915. if (tos == 0)
  916. abort ();
  917. stack[tos - 1] -= relocation;
  918. }
  919. break;
  920. case ALPHA_R_OP_PRSHIFT:
  921. /* Shift the value on the top of the stack. */
  922. {
  923. asymbol *symbol;
  924. bfd_vma relocation;
  925. if (relocatable)
  926. {
  927. rel->address += input_section->output_offset;
  928. break;
  929. }
  930. /* Figure out the relocation of this symbol. */
  931. symbol = *rel->sym_ptr_ptr;
  932. if (bfd_is_und_section (symbol->section))
  933. r = bfd_reloc_undefined;
  934. if (bfd_is_com_section (symbol->section))
  935. relocation = 0;
  936. else
  937. relocation = symbol->value;
  938. relocation += symbol->section->output_section->vma;
  939. relocation += symbol->section->output_offset;
  940. relocation += rel->addend;
  941. if (tos == 0)
  942. abort ();
  943. stack[tos - 1] >>= relocation;
  944. }
  945. break;
  946. case ALPHA_R_GPVALUE:
  947. /* I really don't know if this does the right thing. */
  948. gp = rel->addend;
  949. gp_undefined = false;
  950. break;
  951. default:
  952. abort ();
  953. }
  954. if (relocatable)
  955. {
  956. asection *os = input_section->output_section;
  957. /* A partial link, so keep the relocs. */
  958. os->orelocation[os->reloc_count] = rel;
  959. os->reloc_count++;
  960. }
  961. if (r != bfd_reloc_ok)
  962. {
  963. switch (r)
  964. {
  965. case bfd_reloc_undefined:
  966. (*link_info->callbacks->undefined_symbol)
  967. (link_info, bfd_asymbol_name (*rel->sym_ptr_ptr),
  968. input_bfd, input_section, rel->address, true);
  969. break;
  970. case bfd_reloc_dangerous:
  971. (*link_info->callbacks->reloc_dangerous)
  972. (link_info, err, input_bfd, input_section, rel->address);
  973. break;
  974. case bfd_reloc_overflow:
  975. (*link_info->callbacks->reloc_overflow)
  976. (link_info, NULL, bfd_asymbol_name (*rel->sym_ptr_ptr),
  977. rel->howto->name, rel->addend, input_bfd,
  978. input_section, rel->address);
  979. break;
  980. case bfd_reloc_outofrange:
  981. default:
  982. abort ();
  983. break;
  984. }
  985. }
  986. }
  987. if (tos != 0)
  988. abort ();
  989. successful_return:
  990. free (reloc_vector);
  991. return data;
  992. error_return:
  993. free (reloc_vector);
  994. return NULL;
  995. }
  996. /* Get the howto structure for a generic reloc type. */
  997. static reloc_howto_type *
  998. alpha_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  999. bfd_reloc_code_real_type code)
  1000. {
  1001. int alpha_type;
  1002. switch (code)
  1003. {
  1004. case BFD_RELOC_32:
  1005. alpha_type = ALPHA_R_REFLONG;
  1006. break;
  1007. case BFD_RELOC_64:
  1008. case BFD_RELOC_CTOR:
  1009. alpha_type = ALPHA_R_REFQUAD;
  1010. break;
  1011. case BFD_RELOC_GPREL32:
  1012. alpha_type = ALPHA_R_GPREL32;
  1013. break;
  1014. case BFD_RELOC_ALPHA_LITERAL:
  1015. alpha_type = ALPHA_R_LITERAL;
  1016. break;
  1017. case BFD_RELOC_ALPHA_LITUSE:
  1018. alpha_type = ALPHA_R_LITUSE;
  1019. break;
  1020. case BFD_RELOC_ALPHA_GPDISP_HI16:
  1021. alpha_type = ALPHA_R_GPDISP;
  1022. break;
  1023. case BFD_RELOC_ALPHA_GPDISP_LO16:
  1024. alpha_type = ALPHA_R_IGNORE;
  1025. break;
  1026. case BFD_RELOC_23_PCREL_S2:
  1027. alpha_type = ALPHA_R_BRADDR;
  1028. break;
  1029. case BFD_RELOC_ALPHA_HINT:
  1030. alpha_type = ALPHA_R_HINT;
  1031. break;
  1032. case BFD_RELOC_16_PCREL:
  1033. alpha_type = ALPHA_R_SREL16;
  1034. break;
  1035. case BFD_RELOC_32_PCREL:
  1036. alpha_type = ALPHA_R_SREL32;
  1037. break;
  1038. case BFD_RELOC_64_PCREL:
  1039. alpha_type = ALPHA_R_SREL64;
  1040. break;
  1041. default:
  1042. return (reloc_howto_type *) NULL;
  1043. }
  1044. return &alpha_howto_table[alpha_type];
  1045. }
  1046. static reloc_howto_type *
  1047. alpha_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1048. const char *r_name)
  1049. {
  1050. unsigned int i;
  1051. for (i = 0;
  1052. i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]);
  1053. i++)
  1054. if (alpha_howto_table[i].name != NULL
  1055. && strcasecmp (alpha_howto_table[i].name, r_name) == 0)
  1056. return &alpha_howto_table[i];
  1057. return NULL;
  1058. }
  1059. /* A helper routine for alpha_relocate_section which converts an
  1060. external reloc when generating relocatable output. Returns the
  1061. relocation amount. */
  1062. static bfd_vma
  1063. alpha_convert_external_reloc (bfd *output_bfd ATTRIBUTE_UNUSED,
  1064. struct bfd_link_info *info,
  1065. bfd *input_bfd,
  1066. struct external_reloc *ext_rel,
  1067. struct ecoff_link_hash_entry *h)
  1068. {
  1069. unsigned long r_symndx;
  1070. bfd_vma relocation;
  1071. BFD_ASSERT (bfd_link_relocatable (info));
  1072. if (h->root.type == bfd_link_hash_defined
  1073. || h->root.type == bfd_link_hash_defweak)
  1074. {
  1075. asection *hsec;
  1076. const char *name;
  1077. /* This symbol is defined in the output. Convert the reloc from
  1078. being against the symbol to being against the section. */
  1079. /* Clear the r_extern bit. */
  1080. ext_rel->r_bits[1] &=~ RELOC_BITS1_EXTERN_LITTLE;
  1081. /* Compute a new r_symndx value. */
  1082. hsec = h->root.u.def.section;
  1083. name = bfd_section_name (hsec->output_section);
  1084. r_symndx = (unsigned long) -1;
  1085. switch (name[1])
  1086. {
  1087. case 'A':
  1088. if (strcmp (name, "*ABS*") == 0)
  1089. r_symndx = RELOC_SECTION_ABS;
  1090. break;
  1091. case 'b':
  1092. if (strcmp (name, ".bss") == 0)
  1093. r_symndx = RELOC_SECTION_BSS;
  1094. break;
  1095. case 'd':
  1096. if (strcmp (name, ".data") == 0)
  1097. r_symndx = RELOC_SECTION_DATA;
  1098. break;
  1099. case 'f':
  1100. if (strcmp (name, ".fini") == 0)
  1101. r_symndx = RELOC_SECTION_FINI;
  1102. break;
  1103. case 'i':
  1104. if (strcmp (name, ".init") == 0)
  1105. r_symndx = RELOC_SECTION_INIT;
  1106. break;
  1107. case 'l':
  1108. if (strcmp (name, ".lita") == 0)
  1109. r_symndx = RELOC_SECTION_LITA;
  1110. else if (strcmp (name, ".lit8") == 0)
  1111. r_symndx = RELOC_SECTION_LIT8;
  1112. else if (strcmp (name, ".lit4") == 0)
  1113. r_symndx = RELOC_SECTION_LIT4;
  1114. break;
  1115. case 'p':
  1116. if (strcmp (name, ".pdata") == 0)
  1117. r_symndx = RELOC_SECTION_PDATA;
  1118. break;
  1119. case 'r':
  1120. if (strcmp (name, ".rdata") == 0)
  1121. r_symndx = RELOC_SECTION_RDATA;
  1122. else if (strcmp (name, ".rconst") == 0)
  1123. r_symndx = RELOC_SECTION_RCONST;
  1124. break;
  1125. case 's':
  1126. if (strcmp (name, ".sdata") == 0)
  1127. r_symndx = RELOC_SECTION_SDATA;
  1128. else if (strcmp (name, ".sbss") == 0)
  1129. r_symndx = RELOC_SECTION_SBSS;
  1130. break;
  1131. case 't':
  1132. if (strcmp (name, ".text") == 0)
  1133. r_symndx = RELOC_SECTION_TEXT;
  1134. break;
  1135. case 'x':
  1136. if (strcmp (name, ".xdata") == 0)
  1137. r_symndx = RELOC_SECTION_XDATA;
  1138. break;
  1139. }
  1140. if (r_symndx == (unsigned long) -1)
  1141. abort ();
  1142. /* Add the section VMA and the symbol value. */
  1143. relocation = (h->root.u.def.value
  1144. + hsec->output_section->vma
  1145. + hsec->output_offset);
  1146. }
  1147. else
  1148. {
  1149. /* Change the symndx value to the right one for
  1150. the output BFD. */
  1151. r_symndx = h->indx;
  1152. if (r_symndx == (unsigned long) -1)
  1153. {
  1154. /* Caller must give an error. */
  1155. r_symndx = 0;
  1156. }
  1157. relocation = 0;
  1158. }
  1159. /* Write out the new r_symndx value. */
  1160. H_PUT_32 (input_bfd, r_symndx, ext_rel->r_symndx);
  1161. return relocation;
  1162. }
  1163. /* Relocate a section while linking an Alpha ECOFF file. This is
  1164. quite similar to get_relocated_section_contents. Perhaps they
  1165. could be combined somehow. */
  1166. static bool
  1167. alpha_relocate_section (bfd *output_bfd,
  1168. struct bfd_link_info *info,
  1169. bfd *input_bfd,
  1170. asection *input_section,
  1171. bfd_byte *contents,
  1172. void * external_relocs)
  1173. {
  1174. asection **symndx_to_section, *lita_sec;
  1175. struct ecoff_link_hash_entry **sym_hashes;
  1176. bfd_vma gp;
  1177. bool gp_undefined;
  1178. bfd_vma stack[RELOC_STACKSIZE];
  1179. int tos = 0;
  1180. struct external_reloc *ext_rel;
  1181. struct external_reloc *ext_rel_end;
  1182. bfd_size_type amt;
  1183. /* We keep a table mapping the symndx found in an internal reloc to
  1184. the appropriate section. This is faster than looking up the
  1185. section by name each time. */
  1186. symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
  1187. if (symndx_to_section == (asection **) NULL)
  1188. {
  1189. amt = NUM_RELOC_SECTIONS * sizeof (asection *);
  1190. symndx_to_section = (asection **) bfd_alloc (input_bfd, amt);
  1191. if (!symndx_to_section)
  1192. return false;
  1193. symndx_to_section[RELOC_SECTION_NONE] = NULL;
  1194. symndx_to_section[RELOC_SECTION_TEXT] =
  1195. bfd_get_section_by_name (input_bfd, ".text");
  1196. symndx_to_section[RELOC_SECTION_RDATA] =
  1197. bfd_get_section_by_name (input_bfd, ".rdata");
  1198. symndx_to_section[RELOC_SECTION_DATA] =
  1199. bfd_get_section_by_name (input_bfd, ".data");
  1200. symndx_to_section[RELOC_SECTION_SDATA] =
  1201. bfd_get_section_by_name (input_bfd, ".sdata");
  1202. symndx_to_section[RELOC_SECTION_SBSS] =
  1203. bfd_get_section_by_name (input_bfd, ".sbss");
  1204. symndx_to_section[RELOC_SECTION_BSS] =
  1205. bfd_get_section_by_name (input_bfd, ".bss");
  1206. symndx_to_section[RELOC_SECTION_INIT] =
  1207. bfd_get_section_by_name (input_bfd, ".init");
  1208. symndx_to_section[RELOC_SECTION_LIT8] =
  1209. bfd_get_section_by_name (input_bfd, ".lit8");
  1210. symndx_to_section[RELOC_SECTION_LIT4] =
  1211. bfd_get_section_by_name (input_bfd, ".lit4");
  1212. symndx_to_section[RELOC_SECTION_XDATA] =
  1213. bfd_get_section_by_name (input_bfd, ".xdata");
  1214. symndx_to_section[RELOC_SECTION_PDATA] =
  1215. bfd_get_section_by_name (input_bfd, ".pdata");
  1216. symndx_to_section[RELOC_SECTION_FINI] =
  1217. bfd_get_section_by_name (input_bfd, ".fini");
  1218. symndx_to_section[RELOC_SECTION_LITA] =
  1219. bfd_get_section_by_name (input_bfd, ".lita");
  1220. symndx_to_section[RELOC_SECTION_ABS] = bfd_abs_section_ptr;
  1221. symndx_to_section[RELOC_SECTION_RCONST] =
  1222. bfd_get_section_by_name (input_bfd, ".rconst");
  1223. ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
  1224. }
  1225. sym_hashes = ecoff_data (input_bfd)->sym_hashes;
  1226. /* On the Alpha, the .lita section must be addressable by the global
  1227. pointer. To support large programs, we need to allow multiple
  1228. global pointers. This works as long as each input .lita section
  1229. is <64KB big. This implies that when producing relocatable
  1230. output, the .lita section is limited to 64KB. . */
  1231. lita_sec = symndx_to_section[RELOC_SECTION_LITA];
  1232. gp = _bfd_get_gp_value (output_bfd);
  1233. if (! bfd_link_relocatable (info) && lita_sec != NULL)
  1234. {
  1235. struct ecoff_section_tdata *lita_sec_data;
  1236. /* Make sure we have a section data structure to which we can
  1237. hang on to the gp value we pick for the section. */
  1238. lita_sec_data = ecoff_section_data (input_bfd, lita_sec);
  1239. if (lita_sec_data == NULL)
  1240. {
  1241. amt = sizeof (struct ecoff_section_tdata);
  1242. lita_sec_data = ((struct ecoff_section_tdata *)
  1243. bfd_zalloc (input_bfd, amt));
  1244. lita_sec->used_by_bfd = lita_sec_data;
  1245. }
  1246. if (lita_sec_data->gp != 0)
  1247. {
  1248. /* If we already assigned a gp to this section, we better
  1249. stick with that value. */
  1250. gp = lita_sec_data->gp;
  1251. }
  1252. else
  1253. {
  1254. bfd_vma lita_vma;
  1255. bfd_size_type lita_size;
  1256. lita_vma = lita_sec->output_offset + lita_sec->output_section->vma;
  1257. lita_size = lita_sec->size;
  1258. if (gp == 0
  1259. || lita_vma < gp - 0x8000
  1260. || lita_vma + lita_size >= gp + 0x8000)
  1261. {
  1262. /* Either gp hasn't been set at all or the current gp
  1263. cannot address this .lita section. In both cases we
  1264. reset the gp to point into the "middle" of the
  1265. current input .lita section. */
  1266. if (gp && !ecoff_data (output_bfd)->issued_multiple_gp_warning)
  1267. {
  1268. (*info->callbacks->warning) (info,
  1269. _("using multiple gp values"),
  1270. (char *) NULL, output_bfd,
  1271. (asection *) NULL, (bfd_vma) 0);
  1272. ecoff_data (output_bfd)->issued_multiple_gp_warning = true;
  1273. }
  1274. if (lita_vma < gp - 0x8000)
  1275. gp = lita_vma + lita_size - 0x8000;
  1276. else
  1277. gp = lita_vma + 0x8000;
  1278. }
  1279. lita_sec_data->gp = gp;
  1280. }
  1281. _bfd_set_gp_value (output_bfd, gp);
  1282. }
  1283. gp_undefined = (gp == 0);
  1284. BFD_ASSERT (bfd_header_little_endian (output_bfd));
  1285. BFD_ASSERT (bfd_header_little_endian (input_bfd));
  1286. ext_rel = (struct external_reloc *) external_relocs;
  1287. ext_rel_end = ext_rel + input_section->reloc_count;
  1288. for (; ext_rel < ext_rel_end; ext_rel++)
  1289. {
  1290. bfd_vma r_vaddr;
  1291. unsigned long r_symndx;
  1292. int r_type;
  1293. int r_extern;
  1294. int r_offset;
  1295. int r_size;
  1296. bool relocatep;
  1297. bool adjust_addrp;
  1298. bool gp_usedp;
  1299. bfd_vma addend;
  1300. r_vaddr = H_GET_64 (input_bfd, ext_rel->r_vaddr);
  1301. r_symndx = H_GET_32 (input_bfd, ext_rel->r_symndx);
  1302. r_type = ((ext_rel->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
  1303. >> RELOC_BITS0_TYPE_SH_LITTLE);
  1304. r_extern = (ext_rel->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
  1305. r_offset = ((ext_rel->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
  1306. >> RELOC_BITS1_OFFSET_SH_LITTLE);
  1307. /* Ignored the reserved bits. */
  1308. r_size = ((ext_rel->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
  1309. >> RELOC_BITS3_SIZE_SH_LITTLE);
  1310. relocatep = false;
  1311. adjust_addrp = true;
  1312. gp_usedp = false;
  1313. addend = 0;
  1314. switch (r_type)
  1315. {
  1316. case ALPHA_R_GPRELHIGH:
  1317. _bfd_error_handler (_("%pB: %s unsupported"),
  1318. input_bfd, "ALPHA_R_GPRELHIGH");
  1319. bfd_set_error (bfd_error_bad_value);
  1320. continue;
  1321. case ALPHA_R_GPRELLOW:
  1322. _bfd_error_handler (_("%pB: %s unsupported"),
  1323. input_bfd, "ALPHA_R_GPRELLOW");
  1324. bfd_set_error (bfd_error_bad_value);
  1325. continue;
  1326. default:
  1327. /* xgettext:c-format */
  1328. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  1329. input_bfd, (int) r_type);
  1330. bfd_set_error (bfd_error_bad_value);
  1331. continue;
  1332. case ALPHA_R_IGNORE:
  1333. /* This reloc appears after a GPDISP reloc. On earlier
  1334. versions of OSF/1, It marked the position of the second
  1335. instruction to be altered by the GPDISP reloc, but it is
  1336. not otherwise used for anything. For some reason, the
  1337. address of the relocation does not appear to include the
  1338. section VMA, unlike the other relocation types. */
  1339. if (bfd_link_relocatable (info))
  1340. H_PUT_64 (input_bfd, input_section->output_offset + r_vaddr,
  1341. ext_rel->r_vaddr);
  1342. adjust_addrp = false;
  1343. break;
  1344. case ALPHA_R_REFLONG:
  1345. case ALPHA_R_REFQUAD:
  1346. case ALPHA_R_HINT:
  1347. relocatep = true;
  1348. break;
  1349. case ALPHA_R_BRADDR:
  1350. case ALPHA_R_SREL16:
  1351. case ALPHA_R_SREL32:
  1352. case ALPHA_R_SREL64:
  1353. if (r_extern)
  1354. addend += - (r_vaddr + 4);
  1355. relocatep = true;
  1356. break;
  1357. case ALPHA_R_GPREL32:
  1358. /* This relocation is used in a switch table. It is a 32
  1359. bit offset from the current GP value. We must adjust it
  1360. by the different between the original GP value and the
  1361. current GP value. */
  1362. relocatep = true;
  1363. addend = ecoff_data (input_bfd)->gp - gp;
  1364. gp_usedp = true;
  1365. break;
  1366. case ALPHA_R_LITERAL:
  1367. /* This is a reference to a literal value, generally
  1368. (always?) in the .lita section. This is a 16 bit GP
  1369. relative relocation. Sometimes the subsequent reloc is a
  1370. LITUSE reloc, which indicates how this reloc is used.
  1371. This sometimes permits rewriting the two instructions
  1372. referred to by the LITERAL and the LITUSE into different
  1373. instructions which do not refer to .lita. This can save
  1374. a memory reference, and permits removing a value from
  1375. .lita thus saving GP relative space.
  1376. We do not these optimizations. To do them we would need
  1377. to arrange to link the .lita section first, so that by
  1378. the time we got here we would know the final values to
  1379. use. This would not be particularly difficult, but it is
  1380. not currently implemented. */
  1381. /* I believe that the LITERAL reloc will only apply to a ldq
  1382. or ldl instruction, so check my assumption. */
  1383. {
  1384. unsigned long insn;
  1385. insn = bfd_get_32 (input_bfd,
  1386. contents + r_vaddr - input_section->vma);
  1387. BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29
  1388. || ((insn >> 26) & 0x3f) == 0x28);
  1389. }
  1390. relocatep = true;
  1391. addend = ecoff_data (input_bfd)->gp - gp;
  1392. gp_usedp = true;
  1393. break;
  1394. case ALPHA_R_LITUSE:
  1395. /* See ALPHA_R_LITERAL above for the uses of this reloc. It
  1396. does not cause anything to happen, itself. */
  1397. break;
  1398. case ALPHA_R_GPDISP:
  1399. /* This marks the ldah of an ldah/lda pair which loads the
  1400. gp register with the difference of the gp value and the
  1401. current location. The second of the pair is r_symndx
  1402. bytes ahead. It used to be marked with an ALPHA_R_IGNORE
  1403. reloc, but OSF/1 3.2 no longer does that. */
  1404. {
  1405. unsigned long insn1, insn2;
  1406. /* Get the two instructions. */
  1407. insn1 = bfd_get_32 (input_bfd,
  1408. contents + r_vaddr - input_section->vma);
  1409. insn2 = bfd_get_32 (input_bfd,
  1410. (contents
  1411. + r_vaddr
  1412. - input_section->vma
  1413. + r_symndx));
  1414. BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
  1415. BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
  1416. /* Get the existing addend. We must account for the sign
  1417. extension done by lda and ldah. */
  1418. addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff);
  1419. if (insn1 & 0x8000)
  1420. {
  1421. /* This is addend -= 0x100000000 without causing an
  1422. integer overflow on a 32 bit host. */
  1423. addend -= 0x80000000;
  1424. addend -= 0x80000000;
  1425. }
  1426. if (insn2 & 0x8000)
  1427. addend -= 0x10000;
  1428. /* The existing addend includes the difference between the
  1429. gp of the input BFD and the address in the input BFD.
  1430. We want to change this to the difference between the
  1431. final GP and the final address. */
  1432. addend += (gp
  1433. - ecoff_data (input_bfd)->gp
  1434. + input_section->vma
  1435. - (input_section->output_section->vma
  1436. + input_section->output_offset));
  1437. /* Change the instructions, accounting for the sign
  1438. extension, and write them out. */
  1439. if (addend & 0x8000)
  1440. addend += 0x10000;
  1441. insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff);
  1442. insn2 = (insn2 & 0xffff0000) | (addend & 0xffff);
  1443. bfd_put_32 (input_bfd, (bfd_vma) insn1,
  1444. contents + r_vaddr - input_section->vma);
  1445. bfd_put_32 (input_bfd, (bfd_vma) insn2,
  1446. contents + r_vaddr - input_section->vma + r_symndx);
  1447. gp_usedp = true;
  1448. }
  1449. break;
  1450. case ALPHA_R_OP_PUSH:
  1451. case ALPHA_R_OP_PSUB:
  1452. case ALPHA_R_OP_PRSHIFT:
  1453. /* Manipulate values on the reloc evaluation stack. The
  1454. r_vaddr field is not an address in input_section, it is
  1455. the current value (including any addend) of the object
  1456. being used. */
  1457. if (! r_extern)
  1458. {
  1459. asection *s;
  1460. s = symndx_to_section[r_symndx];
  1461. if (s == (asection *) NULL)
  1462. abort ();
  1463. addend = s->output_section->vma + s->output_offset - s->vma;
  1464. }
  1465. else
  1466. {
  1467. struct ecoff_link_hash_entry *h;
  1468. h = sym_hashes[r_symndx];
  1469. if (h == (struct ecoff_link_hash_entry *) NULL)
  1470. abort ();
  1471. if (! bfd_link_relocatable (info))
  1472. {
  1473. if (h->root.type == bfd_link_hash_defined
  1474. || h->root.type == bfd_link_hash_defweak)
  1475. addend = (h->root.u.def.value
  1476. + h->root.u.def.section->output_section->vma
  1477. + h->root.u.def.section->output_offset);
  1478. else
  1479. {
  1480. /* Note that we pass the address as 0, since we
  1481. do not have a meaningful number for the
  1482. location within the section that is being
  1483. relocated. */
  1484. (*info->callbacks->undefined_symbol)
  1485. (info, h->root.root.string, input_bfd,
  1486. input_section, (bfd_vma) 0, true);
  1487. addend = 0;
  1488. }
  1489. }
  1490. else
  1491. {
  1492. if (h->root.type != bfd_link_hash_defined
  1493. && h->root.type != bfd_link_hash_defweak
  1494. && h->indx == -1)
  1495. {
  1496. /* This symbol is not being written out. Pass
  1497. the address as 0, as with undefined_symbol,
  1498. above. */
  1499. (*info->callbacks->unattached_reloc)
  1500. (info, h->root.root.string,
  1501. input_bfd, input_section, (bfd_vma) 0);
  1502. }
  1503. addend = alpha_convert_external_reloc (output_bfd, info,
  1504. input_bfd,
  1505. ext_rel, h);
  1506. }
  1507. }
  1508. addend += r_vaddr;
  1509. if (bfd_link_relocatable (info))
  1510. {
  1511. /* Adjust r_vaddr by the addend. */
  1512. H_PUT_64 (input_bfd, addend, ext_rel->r_vaddr);
  1513. }
  1514. else
  1515. {
  1516. switch (r_type)
  1517. {
  1518. case ALPHA_R_OP_PUSH:
  1519. if (tos >= RELOC_STACKSIZE)
  1520. abort ();
  1521. stack[tos++] = addend;
  1522. break;
  1523. case ALPHA_R_OP_PSUB:
  1524. if (tos == 0)
  1525. abort ();
  1526. stack[tos - 1] -= addend;
  1527. break;
  1528. case ALPHA_R_OP_PRSHIFT:
  1529. if (tos == 0)
  1530. abort ();
  1531. stack[tos - 1] >>= addend;
  1532. break;
  1533. }
  1534. }
  1535. adjust_addrp = false;
  1536. break;
  1537. case ALPHA_R_OP_STORE:
  1538. /* Store a value from the reloc stack into a bitfield. If
  1539. we are generating relocatable output, all we do is
  1540. adjust the address of the reloc. */
  1541. if (! bfd_link_relocatable (info))
  1542. {
  1543. bfd_vma mask;
  1544. bfd_vma val;
  1545. if (tos == 0)
  1546. abort ();
  1547. /* Get the relocation mask. The separate steps and the
  1548. casts to bfd_vma are attempts to avoid a bug in the
  1549. Alpha OSF 1.3 C compiler. See reloc.c for more
  1550. details. */
  1551. mask = 1;
  1552. mask <<= (bfd_vma) r_size;
  1553. mask -= 1;
  1554. /* FIXME: I don't know what kind of overflow checking,
  1555. if any, should be done here. */
  1556. val = bfd_get_64 (input_bfd,
  1557. contents + r_vaddr - input_section->vma);
  1558. val &=~ mask << (bfd_vma) r_offset;
  1559. val |= (stack[--tos] & mask) << (bfd_vma) r_offset;
  1560. bfd_put_64 (input_bfd, val,
  1561. contents + r_vaddr - input_section->vma);
  1562. }
  1563. break;
  1564. case ALPHA_R_GPVALUE:
  1565. /* I really don't know if this does the right thing. */
  1566. gp = ecoff_data (input_bfd)->gp + r_symndx;
  1567. gp_undefined = false;
  1568. break;
  1569. }
  1570. if (relocatep)
  1571. {
  1572. reloc_howto_type *howto;
  1573. struct ecoff_link_hash_entry *h = NULL;
  1574. asection *s = NULL;
  1575. bfd_vma relocation;
  1576. bfd_reloc_status_type r;
  1577. /* Perform a relocation. */
  1578. howto = &alpha_howto_table[r_type];
  1579. if (r_extern)
  1580. {
  1581. h = sym_hashes[r_symndx];
  1582. /* If h is NULL, that means that there is a reloc
  1583. against an external symbol which we thought was just
  1584. a debugging symbol. This should not happen. */
  1585. if (h == (struct ecoff_link_hash_entry *) NULL)
  1586. abort ();
  1587. }
  1588. else
  1589. {
  1590. if (r_symndx >= NUM_RELOC_SECTIONS)
  1591. s = NULL;
  1592. else
  1593. s = symndx_to_section[r_symndx];
  1594. if (s == (asection *) NULL)
  1595. abort ();
  1596. }
  1597. if (bfd_link_relocatable (info))
  1598. {
  1599. /* We are generating relocatable output, and must
  1600. convert the existing reloc. */
  1601. if (r_extern)
  1602. {
  1603. if (h->root.type != bfd_link_hash_defined
  1604. && h->root.type != bfd_link_hash_defweak
  1605. && h->indx == -1)
  1606. {
  1607. /* This symbol is not being written out. */
  1608. (*info->callbacks->unattached_reloc)
  1609. (info, h->root.root.string, input_bfd,
  1610. input_section, r_vaddr - input_section->vma);
  1611. }
  1612. relocation = alpha_convert_external_reloc (output_bfd,
  1613. info,
  1614. input_bfd,
  1615. ext_rel,
  1616. h);
  1617. }
  1618. else
  1619. {
  1620. /* This is a relocation against a section. Adjust
  1621. the value by the amount the section moved. */
  1622. relocation = (s->output_section->vma
  1623. + s->output_offset
  1624. - s->vma);
  1625. }
  1626. /* If this is PC relative, the existing object file
  1627. appears to already have the reloc worked out. We
  1628. must subtract out the old value and add in the new
  1629. one. */
  1630. if (howto->pc_relative)
  1631. relocation -= (input_section->output_section->vma
  1632. + input_section->output_offset
  1633. - input_section->vma);
  1634. /* Put in any addend. */
  1635. relocation += addend;
  1636. /* Adjust the contents. */
  1637. r = _bfd_relocate_contents (howto, input_bfd, relocation,
  1638. (contents
  1639. + r_vaddr
  1640. - input_section->vma));
  1641. }
  1642. else
  1643. {
  1644. /* We are producing a final executable. */
  1645. if (r_extern)
  1646. {
  1647. /* This is a reloc against a symbol. */
  1648. if (h->root.type == bfd_link_hash_defined
  1649. || h->root.type == bfd_link_hash_defweak)
  1650. {
  1651. asection *hsec;
  1652. hsec = h->root.u.def.section;
  1653. relocation = (h->root.u.def.value
  1654. + hsec->output_section->vma
  1655. + hsec->output_offset);
  1656. }
  1657. else
  1658. {
  1659. (*info->callbacks->undefined_symbol)
  1660. (info, h->root.root.string, input_bfd, input_section,
  1661. r_vaddr - input_section->vma, true);
  1662. relocation = 0;
  1663. }
  1664. }
  1665. else
  1666. {
  1667. /* This is a reloc against a section. */
  1668. relocation = (s->output_section->vma
  1669. + s->output_offset
  1670. - s->vma);
  1671. /* Adjust a PC relative relocation by removing the
  1672. reference to the original source section. */
  1673. if (howto->pc_relative)
  1674. relocation += input_section->vma;
  1675. }
  1676. r = _bfd_final_link_relocate (howto,
  1677. input_bfd,
  1678. input_section,
  1679. contents,
  1680. r_vaddr - input_section->vma,
  1681. relocation,
  1682. addend);
  1683. }
  1684. if (r != bfd_reloc_ok)
  1685. {
  1686. switch (r)
  1687. {
  1688. default:
  1689. case bfd_reloc_outofrange:
  1690. abort ();
  1691. case bfd_reloc_overflow:
  1692. {
  1693. const char *name;
  1694. if (r_extern)
  1695. name = sym_hashes[r_symndx]->root.root.string;
  1696. else
  1697. name = bfd_section_name (symndx_to_section[r_symndx]);
  1698. (*info->callbacks->reloc_overflow)
  1699. (info, NULL, name, alpha_howto_table[r_type].name,
  1700. (bfd_vma) 0, input_bfd, input_section,
  1701. r_vaddr - input_section->vma);
  1702. }
  1703. break;
  1704. }
  1705. }
  1706. }
  1707. if (bfd_link_relocatable (info) && adjust_addrp)
  1708. {
  1709. /* Change the address of the relocation. */
  1710. H_PUT_64 (input_bfd,
  1711. (input_section->output_section->vma
  1712. + input_section->output_offset
  1713. - input_section->vma
  1714. + r_vaddr),
  1715. ext_rel->r_vaddr);
  1716. }
  1717. if (gp_usedp && gp_undefined)
  1718. {
  1719. (*info->callbacks->reloc_dangerous)
  1720. (info, _("GP relative relocation used when GP not defined"),
  1721. input_bfd, input_section, r_vaddr - input_section->vma);
  1722. /* Only give the error once per link. */
  1723. gp = 4;
  1724. _bfd_set_gp_value (output_bfd, gp);
  1725. gp_undefined = false;
  1726. }
  1727. }
  1728. if (tos != 0)
  1729. abort ();
  1730. return true;
  1731. }
  1732. /* Do final adjustments to the filehdr and the aouthdr. This routine
  1733. sets the dynamic bits in the file header. */
  1734. static bool
  1735. alpha_adjust_headers (bfd *abfd,
  1736. struct internal_filehdr *fhdr,
  1737. struct internal_aouthdr *ahdr ATTRIBUTE_UNUSED)
  1738. {
  1739. if ((abfd->flags & (DYNAMIC | EXEC_P)) == (DYNAMIC | EXEC_P))
  1740. fhdr->f_flags |= F_ALPHA_CALL_SHARED;
  1741. else if ((abfd->flags & DYNAMIC) != 0)
  1742. fhdr->f_flags |= F_ALPHA_SHARABLE;
  1743. return true;
  1744. }
  1745. /* Archive handling. In OSF/1 (or Digital Unix) v3.2, Digital
  1746. introduced archive packing, in which the elements in an archive are
  1747. optionally compressed using a simple dictionary scheme. We know
  1748. how to read such archives, but we don't write them. */
  1749. #define alpha_ecoff_slurp_armap _bfd_ecoff_slurp_armap
  1750. #define alpha_ecoff_slurp_extended_name_table \
  1751. _bfd_ecoff_slurp_extended_name_table
  1752. #define alpha_ecoff_construct_extended_name_table \
  1753. _bfd_ecoff_construct_extended_name_table
  1754. #define alpha_ecoff_truncate_arname _bfd_ecoff_truncate_arname
  1755. #define alpha_ecoff_write_armap _bfd_ecoff_write_armap
  1756. #define alpha_ecoff_write_ar_hdr _bfd_generic_write_ar_hdr
  1757. #define alpha_ecoff_generic_stat_arch_elt _bfd_ecoff_generic_stat_arch_elt
  1758. #define alpha_ecoff_update_armap_timestamp _bfd_ecoff_update_armap_timestamp
  1759. /* A compressed file uses this instead of ARFMAG. */
  1760. #define ARFZMAG "Z\012"
  1761. /* Read an archive header. This is like the standard routine, but it
  1762. also accepts ARFZMAG. */
  1763. static void *
  1764. alpha_ecoff_read_ar_hdr (bfd *abfd)
  1765. {
  1766. struct areltdata *ret;
  1767. struct ar_hdr *h;
  1768. ret = (struct areltdata *) _bfd_generic_read_ar_hdr_mag (abfd, ARFZMAG);
  1769. if (ret == NULL)
  1770. return NULL;
  1771. h = (struct ar_hdr *) ret->arch_header;
  1772. if (strncmp (h->ar_fmag, ARFZMAG, 2) == 0)
  1773. {
  1774. bfd_byte ab[8];
  1775. /* This is a compressed file. We must set the size correctly.
  1776. The size is the eight bytes after the dummy file header. */
  1777. if (bfd_seek (abfd, (file_ptr) FILHSZ, SEEK_CUR) != 0
  1778. || bfd_bread (ab, (bfd_size_type) 8, abfd) != 8
  1779. || bfd_seek (abfd, (file_ptr) (- (FILHSZ + 8)), SEEK_CUR) != 0)
  1780. {
  1781. free (ret);
  1782. return NULL;
  1783. }
  1784. ret->parsed_size = H_GET_64 (abfd, ab);
  1785. }
  1786. return ret;
  1787. }
  1788. /* Get an archive element at a specified file position. This is where
  1789. we uncompress the archive element if necessary. */
  1790. static bfd *
  1791. alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos,
  1792. struct bfd_link_info *info)
  1793. {
  1794. bfd *nbfd = NULL;
  1795. struct areltdata *tdata;
  1796. struct ar_hdr *hdr;
  1797. bfd_byte ab[8];
  1798. bfd_size_type size;
  1799. bfd_byte *buf, *p;
  1800. struct bfd_in_memory *bim;
  1801. ufile_ptr filesize;
  1802. buf = NULL;
  1803. nbfd = _bfd_get_elt_at_filepos (archive, filepos, info);
  1804. if (nbfd == NULL)
  1805. goto error_return;
  1806. if ((nbfd->flags & BFD_IN_MEMORY) != 0)
  1807. {
  1808. /* We have already expanded this BFD. */
  1809. return nbfd;
  1810. }
  1811. tdata = (struct areltdata *) nbfd->arelt_data;
  1812. hdr = (struct ar_hdr *) tdata->arch_header;
  1813. if (strncmp (hdr->ar_fmag, ARFZMAG, 2) != 0)
  1814. return nbfd;
  1815. /* We must uncompress this element. We do this by copying it into a
  1816. memory buffer, and making bfd_bread and bfd_seek use that buffer.
  1817. This can use a lot of memory, but it's simpler than getting a
  1818. temporary file, making that work with the file descriptor caching
  1819. code, and making sure that it is deleted at all appropriate
  1820. times. It can be changed if it ever becomes important. */
  1821. /* The compressed file starts with a dummy ECOFF file header. */
  1822. if (bfd_seek (nbfd, (file_ptr) FILHSZ, SEEK_SET) != 0)
  1823. goto error_return;
  1824. /* The next eight bytes are the real file size. */
  1825. if (bfd_bread (ab, (bfd_size_type) 8, nbfd) != 8)
  1826. goto error_return;
  1827. size = H_GET_64 (nbfd, ab);
  1828. /* The decompression algorithm will at most expand by eight times. */
  1829. filesize = bfd_get_file_size (archive);
  1830. if (filesize != 0 && size / 8 > filesize)
  1831. {
  1832. bfd_set_error (bfd_error_malformed_archive);
  1833. goto error_return;
  1834. }
  1835. if (size != 0)
  1836. {
  1837. bfd_size_type left;
  1838. bfd_byte dict[4096];
  1839. unsigned int h;
  1840. bfd_byte b;
  1841. buf = (bfd_byte *) bfd_malloc (size);
  1842. if (buf == NULL)
  1843. goto error_return;
  1844. p = buf;
  1845. left = size;
  1846. /* I don't know what the next eight bytes are for. */
  1847. if (bfd_bread (ab, (bfd_size_type) 8, nbfd) != 8)
  1848. goto error_return;
  1849. /* This is the uncompression algorithm. It's a simple
  1850. dictionary based scheme in which each character is predicted
  1851. by a hash of the previous three characters. A control byte
  1852. indicates whether the character is predicted or whether it
  1853. appears in the input stream; each control byte manages the
  1854. next eight bytes in the output stream. */
  1855. memset (dict, 0, sizeof dict);
  1856. h = 0;
  1857. while (bfd_bread (&b, (bfd_size_type) 1, nbfd) == 1)
  1858. {
  1859. unsigned int i;
  1860. for (i = 0; i < 8; i++, b >>= 1)
  1861. {
  1862. bfd_byte n;
  1863. if ((b & 1) == 0)
  1864. n = dict[h];
  1865. else
  1866. {
  1867. if (bfd_bread (&n, 1, nbfd) != 1)
  1868. goto error_return;
  1869. dict[h] = n;
  1870. }
  1871. *p++ = n;
  1872. --left;
  1873. if (left == 0)
  1874. break;
  1875. h <<= 4;
  1876. h ^= n;
  1877. h &= sizeof dict - 1;
  1878. }
  1879. if (left == 0)
  1880. break;
  1881. }
  1882. }
  1883. /* Now the uncompressed file contents are in buf. */
  1884. bim = ((struct bfd_in_memory *)
  1885. bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory)));
  1886. if (bim == NULL)
  1887. goto error_return;
  1888. bim->size = size;
  1889. bim->buffer = buf;
  1890. nbfd->mtime_set = true;
  1891. nbfd->mtime = strtol (hdr->ar_date, (char **) NULL, 10);
  1892. nbfd->flags |= BFD_IN_MEMORY;
  1893. nbfd->iostream = bim;
  1894. nbfd->iovec = &_bfd_memory_iovec;
  1895. nbfd->origin = 0;
  1896. BFD_ASSERT (! nbfd->cacheable);
  1897. return nbfd;
  1898. error_return:
  1899. free (buf);
  1900. if (nbfd != NULL)
  1901. bfd_close (nbfd);
  1902. return NULL;
  1903. }
  1904. /* Open the next archived file. */
  1905. static bfd *
  1906. alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file)
  1907. {
  1908. ufile_ptr filestart;
  1909. if (last_file == NULL)
  1910. filestart = bfd_ardata (archive)->first_file_filepos;
  1911. else
  1912. {
  1913. struct areltdata *t;
  1914. struct ar_hdr *h;
  1915. bfd_size_type size;
  1916. /* We can't use arelt_size here, because that uses parsed_size,
  1917. which is the uncompressed size. We need the compressed size. */
  1918. t = (struct areltdata *) last_file->arelt_data;
  1919. h = (struct ar_hdr *) t->arch_header;
  1920. size = strtol (h->ar_size, (char **) NULL, 10);
  1921. /* Pad to an even boundary...
  1922. Note that last_file->origin can be odd in the case of
  1923. BSD-4.4-style element with a long odd size. */
  1924. filestart = last_file->proxy_origin + size;
  1925. filestart += filestart % 2;
  1926. if (filestart < last_file->proxy_origin)
  1927. {
  1928. /* Prevent looping. See PR19256. */
  1929. bfd_set_error (bfd_error_malformed_archive);
  1930. return NULL;
  1931. }
  1932. }
  1933. return alpha_ecoff_get_elt_at_filepos (archive, filestart, NULL);
  1934. }
  1935. /* Open the archive file given an index into the armap. */
  1936. static bfd *
  1937. alpha_ecoff_get_elt_at_index (bfd *abfd, symindex sym_index)
  1938. {
  1939. carsym *entry;
  1940. entry = bfd_ardata (abfd)->symdefs + sym_index;
  1941. return alpha_ecoff_get_elt_at_filepos (abfd, entry->file_offset,
  1942. NULL);
  1943. }
  1944. static void
  1945. alpha_ecoff_swap_coff_aux_in (bfd *abfd ATTRIBUTE_UNUSED,
  1946. void *ext1 ATTRIBUTE_UNUSED,
  1947. int type ATTRIBUTE_UNUSED,
  1948. int in_class ATTRIBUTE_UNUSED,
  1949. int indx ATTRIBUTE_UNUSED,
  1950. int numaux ATTRIBUTE_UNUSED,
  1951. void *in1 ATTRIBUTE_UNUSED)
  1952. {
  1953. }
  1954. static void
  1955. alpha_ecoff_swap_coff_sym_in (bfd *abfd ATTRIBUTE_UNUSED,
  1956. void *ext1 ATTRIBUTE_UNUSED,
  1957. void *in1 ATTRIBUTE_UNUSED)
  1958. {
  1959. }
  1960. static void
  1961. alpha_ecoff_swap_coff_lineno_in (bfd *abfd ATTRIBUTE_UNUSED,
  1962. void *ext1 ATTRIBUTE_UNUSED,
  1963. void *in1 ATTRIBUTE_UNUSED)
  1964. {
  1965. }
  1966. static unsigned int
  1967. alpha_ecoff_swap_coff_aux_out (bfd *abfd ATTRIBUTE_UNUSED,
  1968. void *inp ATTRIBUTE_UNUSED,
  1969. int type ATTRIBUTE_UNUSED,
  1970. int in_class ATTRIBUTE_UNUSED,
  1971. int indx ATTRIBUTE_UNUSED,
  1972. int numaux ATTRIBUTE_UNUSED,
  1973. void *extp ATTRIBUTE_UNUSED)
  1974. {
  1975. return 0;
  1976. }
  1977. static unsigned int
  1978. alpha_ecoff_swap_coff_sym_out (bfd *abfd ATTRIBUTE_UNUSED,
  1979. void *inp ATTRIBUTE_UNUSED,
  1980. void *extp ATTRIBUTE_UNUSED)
  1981. {
  1982. return 0;
  1983. }
  1984. static unsigned int
  1985. alpha_ecoff_swap_coff_lineno_out (bfd *abfd ATTRIBUTE_UNUSED,
  1986. void *inp ATTRIBUTE_UNUSED,
  1987. void *extp ATTRIBUTE_UNUSED)
  1988. {
  1989. return 0;
  1990. }
  1991. static unsigned int
  1992. alpha_ecoff_swap_coff_reloc_out (bfd *abfd ATTRIBUTE_UNUSED,
  1993. void *inp ATTRIBUTE_UNUSED,
  1994. void *extp ATTRIBUTE_UNUSED)
  1995. {
  1996. return 0;
  1997. }
  1998. /* This is the ECOFF backend structure. The backend field of the
  1999. target vector points to this. */
  2000. static const struct ecoff_backend_data alpha_ecoff_backend_data =
  2001. {
  2002. /* COFF backend structure. */
  2003. {
  2004. alpha_ecoff_swap_coff_aux_in, alpha_ecoff_swap_coff_sym_in,
  2005. alpha_ecoff_swap_coff_lineno_in, alpha_ecoff_swap_coff_aux_out,
  2006. alpha_ecoff_swap_coff_sym_out, alpha_ecoff_swap_coff_lineno_out,
  2007. alpha_ecoff_swap_coff_reloc_out,
  2008. alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out,
  2009. alpha_ecoff_swap_scnhdr_out,
  2010. FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, 0, FILNMLEN, true,
  2011. ECOFF_NO_LONG_SECTION_NAMES, 4, false, 2, 32768,
  2012. alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in,
  2013. alpha_ecoff_swap_scnhdr_in, NULL,
  2014. alpha_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook,
  2015. alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
  2016. _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
  2017. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  2018. NULL, NULL, NULL, NULL
  2019. },
  2020. /* Supported architecture. */
  2021. bfd_arch_alpha,
  2022. /* Initial portion of armap string. */
  2023. "________64",
  2024. /* The page boundary used to align sections in a demand-paged
  2025. executable file. E.g., 0x1000. */
  2026. 0x2000,
  2027. /* TRUE if the .rdata section is part of the text segment, as on the
  2028. Alpha. FALSE if .rdata is part of the data segment, as on the
  2029. MIPS. */
  2030. true,
  2031. /* Bitsize of constructor entries. */
  2032. 64,
  2033. /* Reloc to use for constructor entries. */
  2034. &alpha_howto_table[ALPHA_R_REFQUAD],
  2035. {
  2036. /* Symbol table magic number. */
  2037. magicSym2,
  2038. /* Alignment of debugging information. E.g., 4. */
  2039. 8,
  2040. /* Sizes of external symbolic information. */
  2041. sizeof (struct hdr_ext),
  2042. sizeof (struct dnr_ext),
  2043. sizeof (struct pdr_ext),
  2044. sizeof (struct sym_ext),
  2045. sizeof (struct opt_ext),
  2046. sizeof (struct fdr_ext),
  2047. sizeof (struct rfd_ext),
  2048. sizeof (struct ext_ext),
  2049. /* Functions to swap in external symbolic data. */
  2050. ecoff_swap_hdr_in,
  2051. ecoff_swap_dnr_in,
  2052. ecoff_swap_pdr_in,
  2053. ecoff_swap_sym_in,
  2054. ecoff_swap_opt_in,
  2055. ecoff_swap_fdr_in,
  2056. ecoff_swap_rfd_in,
  2057. ecoff_swap_ext_in,
  2058. _bfd_ecoff_swap_tir_in,
  2059. _bfd_ecoff_swap_rndx_in,
  2060. /* Functions to swap out external symbolic data. */
  2061. ecoff_swap_hdr_out,
  2062. ecoff_swap_dnr_out,
  2063. ecoff_swap_pdr_out,
  2064. ecoff_swap_sym_out,
  2065. ecoff_swap_opt_out,
  2066. ecoff_swap_fdr_out,
  2067. ecoff_swap_rfd_out,
  2068. ecoff_swap_ext_out,
  2069. _bfd_ecoff_swap_tir_out,
  2070. _bfd_ecoff_swap_rndx_out,
  2071. /* Function to read in symbolic data. */
  2072. _bfd_ecoff_slurp_symbolic_info
  2073. },
  2074. /* External reloc size. */
  2075. RELSZ,
  2076. /* Reloc swapping functions. */
  2077. alpha_ecoff_swap_reloc_in,
  2078. alpha_ecoff_swap_reloc_out,
  2079. /* Backend reloc tweaking. */
  2080. alpha_adjust_reloc_in,
  2081. alpha_adjust_reloc_out,
  2082. /* Relocate section contents while linking. */
  2083. alpha_relocate_section,
  2084. /* Do final adjustments to filehdr and aouthdr. */
  2085. alpha_adjust_headers,
  2086. /* Read an element from an archive at a given file position. */
  2087. alpha_ecoff_get_elt_at_filepos
  2088. };
  2089. /* Looking up a reloc type is Alpha specific. */
  2090. #define _bfd_ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
  2091. #define _bfd_ecoff_bfd_reloc_name_lookup \
  2092. alpha_bfd_reloc_name_lookup
  2093. /* So is getting relocated section contents. */
  2094. #define _bfd_ecoff_bfd_get_relocated_section_contents \
  2095. alpha_ecoff_get_relocated_section_contents
  2096. /* Handling file windows is generic. */
  2097. #define _bfd_ecoff_get_section_contents_in_window \
  2098. _bfd_generic_get_section_contents_in_window
  2099. /* Input section flag lookup is generic. */
  2100. #define _bfd_ecoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
  2101. /* Relaxing sections is generic. */
  2102. #define _bfd_ecoff_bfd_relax_section bfd_generic_relax_section
  2103. #define _bfd_ecoff_bfd_gc_sections bfd_generic_gc_sections
  2104. #define _bfd_ecoff_bfd_merge_sections bfd_generic_merge_sections
  2105. #define _bfd_ecoff_bfd_is_group_section bfd_generic_is_group_section
  2106. #define _bfd_ecoff_bfd_group_name bfd_generic_group_name
  2107. #define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group
  2108. #define _bfd_ecoff_section_already_linked \
  2109. _bfd_coff_section_already_linked
  2110. #define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
  2111. #define _bfd_ecoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
  2112. #define _bfd_ecoff_bfd_define_start_stop bfd_generic_define_start_stop
  2113. #define _bfd_ecoff_bfd_link_check_relocs _bfd_generic_link_check_relocs
  2114. /* Installing internal relocations in a section is also generic. */
  2115. #define _bfd_ecoff_set_reloc _bfd_generic_set_reloc
  2116. const bfd_target alpha_ecoff_le_vec =
  2117. {
  2118. "ecoff-littlealpha", /* name */
  2119. bfd_target_ecoff_flavour,
  2120. BFD_ENDIAN_LITTLE, /* data byte order is little */
  2121. BFD_ENDIAN_LITTLE, /* header byte order is little */
  2122. (HAS_RELOC | EXEC_P /* object flags */
  2123. | HAS_LINENO | HAS_DEBUG
  2124. | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  2125. (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE
  2126. | SEC_DATA | SEC_SMALL_DATA),
  2127. 0, /* leading underscore */
  2128. ' ', /* ar_pad_char */
  2129. 15, /* ar_max_namelen */
  2130. 0, /* match priority. */
  2131. TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
  2132. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  2133. bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  2134. bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  2135. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  2136. bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  2137. bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
  2138. { /* bfd_check_format */
  2139. _bfd_dummy_target,
  2140. alpha_ecoff_object_p,
  2141. bfd_generic_archive_p,
  2142. _bfd_dummy_target
  2143. },
  2144. { /* bfd_set_format */
  2145. _bfd_bool_bfd_false_error,
  2146. _bfd_ecoff_mkobject,
  2147. _bfd_generic_mkarchive,
  2148. _bfd_bool_bfd_false_error
  2149. },
  2150. { /* bfd_write_contents */
  2151. _bfd_bool_bfd_false_error,
  2152. _bfd_ecoff_write_object_contents,
  2153. _bfd_write_archive_contents,
  2154. _bfd_bool_bfd_false_error
  2155. },
  2156. BFD_JUMP_TABLE_GENERIC (_bfd_ecoff),
  2157. BFD_JUMP_TABLE_COPY (_bfd_ecoff),
  2158. BFD_JUMP_TABLE_CORE (_bfd_nocore),
  2159. BFD_JUMP_TABLE_ARCHIVE (alpha_ecoff),
  2160. BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff),
  2161. BFD_JUMP_TABLE_RELOCS (_bfd_ecoff),
  2162. BFD_JUMP_TABLE_WRITE (_bfd_ecoff),
  2163. BFD_JUMP_TABLE_LINK (_bfd_ecoff),
  2164. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  2165. NULL,
  2166. &alpha_ecoff_backend_data
  2167. };