coff64-rs6000.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919
  1. /* BFD back-end for IBM RS/6000 "XCOFF64" files.
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. Written Clinton Popetz.
  4. Contributed by Cygnus Support.
  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/xcoff.h"
  24. #include "coff/rs6k64.h"
  25. #include "libcoff.h"
  26. #include "libxcoff.h"
  27. #define GET_FILEHDR_SYMPTR H_GET_64
  28. #define PUT_FILEHDR_SYMPTR H_PUT_64
  29. #define GET_AOUTHDR_DATA_START H_GET_64
  30. #define PUT_AOUTHDR_DATA_START H_PUT_64
  31. #define GET_AOUTHDR_TEXT_START H_GET_64
  32. #define PUT_AOUTHDR_TEXT_START H_PUT_64
  33. #define GET_AOUTHDR_TSIZE H_GET_64
  34. #define PUT_AOUTHDR_TSIZE H_PUT_64
  35. #define GET_AOUTHDR_DSIZE H_GET_64
  36. #define PUT_AOUTHDR_DSIZE H_PUT_64
  37. #define GET_AOUTHDR_BSIZE H_GET_64
  38. #define PUT_AOUTHDR_BSIZE H_PUT_64
  39. #define GET_AOUTHDR_ENTRY H_GET_64
  40. #define PUT_AOUTHDR_ENTRY H_PUT_64
  41. #define GET_SCNHDR_PADDR H_GET_64
  42. #define PUT_SCNHDR_PADDR H_PUT_64
  43. #define GET_SCNHDR_VADDR H_GET_64
  44. #define PUT_SCNHDR_VADDR H_PUT_64
  45. #define GET_SCNHDR_SIZE H_GET_64
  46. #define PUT_SCNHDR_SIZE H_PUT_64
  47. #define GET_SCNHDR_SCNPTR H_GET_64
  48. #define PUT_SCNHDR_SCNPTR H_PUT_64
  49. #define GET_SCNHDR_RELPTR H_GET_64
  50. #define PUT_SCNHDR_RELPTR H_PUT_64
  51. #define GET_SCNHDR_LNNOPTR H_GET_64
  52. #define PUT_SCNHDR_LNNOPTR H_PUT_64
  53. #define GET_SCNHDR_NRELOC H_GET_32
  54. #define MAX_SCNHDR_NRELOC 0xffffffff
  55. #define PUT_SCNHDR_NRELOC H_PUT_32
  56. #define GET_SCNHDR_NLNNO H_GET_32
  57. #define MAX_SCNHDR_NLNNO 0xffffffff
  58. #define PUT_SCNHDR_NLNNO H_PUT_32
  59. #define GET_RELOC_VADDR H_GET_64
  60. #define PUT_RELOC_VADDR H_PUT_64
  61. #define COFF_FORCE_SYMBOLS_IN_STRINGS
  62. #define COFF_DEBUG_STRING_WIDE_PREFIX
  63. #define COFF_ADJUST_SCNHDR_OUT_POST(ABFD, INT, EXT) \
  64. do \
  65. { \
  66. memset (((SCNHDR *) EXT)->s_pad, 0, \
  67. sizeof (((SCNHDR *) EXT)->s_pad)); \
  68. } \
  69. while (0)
  70. #define NO_COFF_LINENOS
  71. #define coff_SWAP_lineno_in _bfd_xcoff64_swap_lineno_in
  72. #define coff_SWAP_lineno_out _bfd_xcoff64_swap_lineno_out
  73. static void _bfd_xcoff64_swap_lineno_in
  74. (bfd *, void *, void *);
  75. static unsigned int _bfd_xcoff64_swap_lineno_out
  76. (bfd *, void *, void *);
  77. static bool _bfd_xcoff64_put_symbol_name
  78. (struct bfd_link_info *, struct bfd_strtab_hash *,
  79. struct internal_syment *, const char *);
  80. static bool _bfd_xcoff64_put_ldsymbol_name
  81. (bfd *, struct xcoff_loader_info *, struct internal_ldsym *, const char *);
  82. static void _bfd_xcoff64_swap_sym_in
  83. (bfd *, void *, void *);
  84. static unsigned int _bfd_xcoff64_swap_sym_out
  85. (bfd *, void *, void *);
  86. static void _bfd_xcoff64_swap_aux_in
  87. (bfd *, void *, int, int, int, int, void *);
  88. static unsigned int _bfd_xcoff64_swap_aux_out
  89. (bfd *, void *, int, int, int, int, void *);
  90. static void xcoff64_swap_reloc_in
  91. (bfd *, void *, void *);
  92. static unsigned int xcoff64_swap_reloc_out
  93. (bfd *, void *, void *);
  94. extern bool _bfd_xcoff_mkobject
  95. (bfd *);
  96. extern bool _bfd_xcoff_copy_private_bfd_data
  97. (bfd *, bfd *);
  98. extern bool _bfd_xcoff_is_local_label_name
  99. (bfd *, const char *);
  100. extern void xcoff64_rtype2howto
  101. (arelent *, struct internal_reloc *);
  102. extern reloc_howto_type * xcoff64_reloc_type_lookup
  103. (bfd *, bfd_reloc_code_real_type);
  104. extern bool _bfd_xcoff_slurp_armap
  105. (bfd *);
  106. extern void *_bfd_xcoff_read_ar_hdr
  107. (bfd *);
  108. extern bfd *_bfd_xcoff_openr_next_archived_file
  109. (bfd *, bfd *);
  110. extern int _bfd_xcoff_stat_arch_elt
  111. (bfd *, struct stat *);
  112. extern bool _bfd_xcoff_write_armap
  113. (bfd *, unsigned int, struct orl *, unsigned int, int);
  114. extern bool _bfd_xcoff_write_archive_contents
  115. (bfd *);
  116. extern int _bfd_xcoff_sizeof_headers
  117. (bfd *, struct bfd_link_info *);
  118. extern void _bfd_xcoff_swap_sym_in
  119. (bfd *, void *, void *);
  120. extern unsigned int _bfd_xcoff_swap_sym_out
  121. (bfd *, void *, void *);
  122. extern void _bfd_xcoff_swap_aux_in
  123. (bfd *, void *, int, int, int, int, void *);
  124. extern unsigned int _bfd_xcoff_swap_aux_out
  125. (bfd *, void *, int, int, int, int, void *);
  126. static void xcoff64_swap_ldhdr_in
  127. (bfd *, const void *, struct internal_ldhdr *);
  128. static void xcoff64_swap_ldhdr_out
  129. (bfd *, const struct internal_ldhdr *, void *d);
  130. static void xcoff64_swap_ldsym_in
  131. (bfd *, const void *, struct internal_ldsym *);
  132. static void xcoff64_swap_ldsym_out
  133. (bfd *, const struct internal_ldsym *, void *d);
  134. static void xcoff64_swap_ldrel_in
  135. (bfd *, const void *, struct internal_ldrel *);
  136. static void xcoff64_swap_ldrel_out
  137. (bfd *, const struct internal_ldrel *, void *d);
  138. static bool xcoff64_ppc_relocate_section
  139. (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
  140. struct internal_reloc *, struct internal_syment *,
  141. asection **);
  142. static bool xcoff64_slurp_armap
  143. (bfd *);
  144. static bfd_cleanup xcoff64_archive_p
  145. (bfd *);
  146. static bfd *xcoff64_openr_next_archived_file
  147. (bfd *, bfd *);
  148. static int xcoff64_sizeof_headers
  149. (bfd *, struct bfd_link_info *);
  150. static asection *xcoff64_create_csect_from_smclas
  151. (bfd *, union internal_auxent *, const char *);
  152. static bool xcoff64_is_lineno_count_overflow
  153. (bfd *, bfd_vma);
  154. static bool xcoff64_is_reloc_count_overflow
  155. (bfd *, bfd_vma);
  156. static bfd_vma xcoff64_loader_symbol_offset
  157. (bfd *, struct internal_ldhdr *);
  158. static bfd_vma xcoff64_loader_reloc_offset
  159. (bfd *, struct internal_ldhdr *);
  160. static bool xcoff64_generate_rtinit
  161. (bfd *, const char *, const char *, bool);
  162. static bool xcoff64_bad_format_hook
  163. (bfd *, void *);
  164. /* Relocation functions */
  165. static xcoff_reloc_function xcoff64_reloc_type_br;
  166. xcoff_reloc_function *const
  167. xcoff64_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION] =
  168. {
  169. xcoff_reloc_type_pos, /* R_POS (0x00) */
  170. xcoff_reloc_type_neg, /* R_NEG (0x01) */
  171. xcoff_reloc_type_rel, /* R_REL (0x02) */
  172. xcoff_reloc_type_toc, /* R_TOC (0x03) */
  173. xcoff_reloc_type_toc, /* R_TRL (0x04) */
  174. xcoff_reloc_type_toc, /* R_GL (0x05) */
  175. xcoff_reloc_type_toc, /* R_TCL (0x06) */
  176. xcoff_reloc_type_fail, /* (0x07) */
  177. xcoff_reloc_type_ba, /* R_BA (0x08) */
  178. xcoff_reloc_type_fail, /* (0x09) */
  179. xcoff64_reloc_type_br, /* R_BR (0x0a) */
  180. xcoff_reloc_type_fail, /* (0x0b) */
  181. xcoff_reloc_type_pos, /* R_RL (0x0c) */
  182. xcoff_reloc_type_pos, /* R_RLA (0x0d) */
  183. xcoff_reloc_type_fail, /* (0x0e) */
  184. xcoff_reloc_type_noop, /* R_REF (0x0f) */
  185. xcoff_reloc_type_fail, /* (0x10) */
  186. xcoff_reloc_type_fail, /* (0x11) */
  187. xcoff_reloc_type_fail, /* (0x12) */
  188. xcoff_reloc_type_toc, /* R_TRLA (0x13) */
  189. xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
  190. xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
  191. xcoff_reloc_type_ba, /* R_CAI (0x16) */
  192. xcoff_reloc_type_crel, /* R_CREL (0x17) */
  193. xcoff_reloc_type_ba, /* R_RBA (0x18) */
  194. xcoff_reloc_type_ba, /* R_RBAC (0x19) */
  195. xcoff64_reloc_type_br, /* R_RBR (0x1a) */
  196. xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
  197. xcoff_reloc_type_fail, /* (0x1c) */
  198. xcoff_reloc_type_fail, /* (0x1d) */
  199. xcoff_reloc_type_fail, /* (0x1e) */
  200. xcoff_reloc_type_fail, /* (0x1f) */
  201. xcoff_reloc_type_tls, /* R_TLS (0x20) */
  202. xcoff_reloc_type_tls, /* R_TLS_IE (0x21) */
  203. xcoff_reloc_type_tls, /* R_TLS_LD (0x22) */
  204. xcoff_reloc_type_tls, /* R_TLS_LE (0x23) */
  205. xcoff_reloc_type_tls, /* R_TLSM (0x24) */
  206. xcoff_reloc_type_tls, /* R_TLSML (0x25) */
  207. xcoff_reloc_type_fail, /* (0x26) */
  208. xcoff_reloc_type_fail, /* (0x27) */
  209. xcoff_reloc_type_fail, /* (0x28) */
  210. xcoff_reloc_type_fail, /* (0x29) */
  211. xcoff_reloc_type_fail, /* (0x2a) */
  212. xcoff_reloc_type_fail, /* (0x2b) */
  213. xcoff_reloc_type_fail, /* (0x2c) */
  214. xcoff_reloc_type_fail, /* (0x2d) */
  215. xcoff_reloc_type_fail, /* (0x2e) */
  216. xcoff_reloc_type_fail, /* (0x2f) */
  217. xcoff_reloc_type_toc, /* R_TOCU (0x30) */
  218. xcoff_reloc_type_toc, /* R_TOCL (0x31) */
  219. };
  220. /* coffcode.h needs these to be defined. */
  221. /* Internalcoff.h and coffcode.h modify themselves based on these flags. */
  222. #define XCOFF64
  223. #define RS6000COFF_C 1
  224. #define SELECT_RELOC(internal, howto) \
  225. { \
  226. internal.r_type = howto->type; \
  227. internal.r_size = \
  228. ((howto->complain_on_overflow == complain_overflow_signed \
  229. ? 0x80 \
  230. : 0) \
  231. | (howto->bitsize - 1)); \
  232. }
  233. #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
  234. #define COFF_LONG_FILENAMES
  235. #define NO_COFF_SYMBOLS
  236. #define RTYPE2HOWTO(cache_ptr, dst) xcoff64_rtype2howto (cache_ptr, dst)
  237. #define coff_mkobject _bfd_xcoff_mkobject
  238. #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
  239. #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
  240. #define coff_bfd_reloc_type_lookup xcoff64_reloc_type_lookup
  241. #define coff_bfd_reloc_name_lookup xcoff64_reloc_name_lookup
  242. #ifdef AIX_CORE
  243. extern bfd_cleanup rs6000coff_core_p
  244. (bfd *abfd);
  245. extern bool rs6000coff_core_file_matches_executable_p
  246. (bfd *cbfd, bfd *ebfd);
  247. extern char *rs6000coff_core_file_failing_command
  248. (bfd *abfd);
  249. extern int rs6000coff_core_file_failing_signal
  250. (bfd *abfd);
  251. #define CORE_FILE_P rs6000coff_core_p
  252. #define coff_core_file_failing_command \
  253. rs6000coff_core_file_failing_command
  254. #define coff_core_file_failing_signal \
  255. rs6000coff_core_file_failing_signal
  256. #define coff_core_file_matches_executable_p \
  257. rs6000coff_core_file_matches_executable_p
  258. #define coff_core_file_pid \
  259. _bfd_nocore_core_file_pid
  260. #else
  261. #define CORE_FILE_P _bfd_dummy_target
  262. #define coff_core_file_failing_command \
  263. _bfd_nocore_core_file_failing_command
  264. #define coff_core_file_failing_signal \
  265. _bfd_nocore_core_file_failing_signal
  266. #define coff_core_file_matches_executable_p \
  267. _bfd_nocore_core_file_matches_executable_p
  268. #define coff_core_file_pid \
  269. _bfd_nocore_core_file_pid
  270. #endif
  271. #define coff_SWAP_sym_in _bfd_xcoff64_swap_sym_in
  272. #define coff_SWAP_sym_out _bfd_xcoff64_swap_sym_out
  273. #define coff_SWAP_aux_in _bfd_xcoff64_swap_aux_in
  274. #define coff_SWAP_aux_out _bfd_xcoff64_swap_aux_out
  275. #define coff_swap_reloc_in xcoff64_swap_reloc_in
  276. #define coff_swap_reloc_out xcoff64_swap_reloc_out
  277. #define NO_COFF_RELOCS
  278. #ifndef bfd_pe_print_pdata
  279. #define bfd_pe_print_pdata NULL
  280. #endif
  281. #include "coffcode.h"
  282. /* For XCOFF64, the effective width of symndx changes depending on
  283. whether we are the first entry. Sigh. */
  284. static void
  285. _bfd_xcoff64_swap_lineno_in (bfd *abfd, void *ext1, void *in1)
  286. {
  287. LINENO *ext = (LINENO *) ext1;
  288. struct internal_lineno *in = (struct internal_lineno *) in1;
  289. in->l_lnno = H_GET_32 (abfd, (ext->l_lnno));
  290. if (in->l_lnno == 0)
  291. in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx);
  292. else
  293. in->l_addr.l_paddr = H_GET_64 (abfd, ext->l_addr.l_paddr);
  294. }
  295. static unsigned int
  296. _bfd_xcoff64_swap_lineno_out (bfd *abfd, void *inp, void *outp)
  297. {
  298. struct internal_lineno *in = (struct internal_lineno *) inp;
  299. struct external_lineno *ext = (struct external_lineno *) outp;
  300. H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
  301. H_PUT_32 (abfd, in->l_lnno, (ext->l_lnno));
  302. if (in->l_lnno == 0)
  303. H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
  304. else
  305. H_PUT_64 (abfd, in->l_addr.l_paddr, ext->l_addr.l_paddr);
  306. return bfd_coff_linesz (abfd);
  307. }
  308. static void
  309. _bfd_xcoff64_swap_sym_in (bfd *abfd, void *ext1, void *in1)
  310. {
  311. struct external_syment *ext = (struct external_syment *) ext1;
  312. struct internal_syment *in = (struct internal_syment *) in1;
  313. in->_n._n_n._n_zeroes = 0;
  314. in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e_offset);
  315. in->n_value = H_GET_64 (abfd, ext->e_value);
  316. in->n_scnum = (short) H_GET_16 (abfd, ext->e_scnum);
  317. in->n_type = H_GET_16 (abfd, ext->e_type);
  318. in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
  319. in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
  320. }
  321. static unsigned int
  322. _bfd_xcoff64_swap_sym_out (bfd *abfd, void *inp, void *extp)
  323. {
  324. struct internal_syment *in = (struct internal_syment *) inp;
  325. struct external_syment *ext = (struct external_syment *) extp;
  326. H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e_offset);
  327. H_PUT_64 (abfd, in->n_value, ext->e_value);
  328. H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
  329. H_PUT_16 (abfd, in->n_type, ext->e_type);
  330. H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
  331. H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
  332. return bfd_coff_symesz (abfd);
  333. }
  334. static void
  335. _bfd_xcoff64_swap_aux_in (bfd *abfd, void *ext1, int type ATTRIBUTE_UNUSED,
  336. int in_class, int indx, int numaux, void *in1)
  337. {
  338. union external_auxent *ext = (union external_auxent *) ext1;
  339. union internal_auxent *in = (union internal_auxent *) in1;
  340. unsigned char auxtype;
  341. switch (in_class)
  342. {
  343. default:
  344. _bfd_error_handler
  345. /* xgettext: c-format */
  346. (_("%pB: unsupported swap_aux_in for storage class %#x"),
  347. abfd, (unsigned int) in_class);
  348. bfd_set_error (bfd_error_bad_value);
  349. break;
  350. case C_FILE:
  351. auxtype = H_GET_8 (abfd, ext->x_file.x_auxtype);
  352. if (auxtype != _AUX_FILE)
  353. goto error;
  354. if (ext->x_file.x_n.x_n.x_zeroes[0] == 0)
  355. {
  356. in->x_file.x_n.x_n.x_zeroes = 0;
  357. in->x_file.x_n.x_n.x_offset =
  358. H_GET_32 (abfd, ext->x_file.x_n.x_n.x_offset);
  359. }
  360. else
  361. memcpy (in->x_file.x_n.x_fname, ext->x_file.x_n.x_fname, FILNMLEN);
  362. in->x_file.x_ftype = H_GET_8 (abfd, ext->x_file.x_ftype);
  363. break;
  364. /* RS/6000 "csect" auxents.
  365. There is always a CSECT auxiliary entry. But functions can
  366. have FCN and EXCEPT ones too. In this case, CSECT is always the last
  367. one.
  368. For now, we only support FCN types. */
  369. case C_EXT:
  370. case C_AIX_WEAKEXT:
  371. case C_HIDEXT:
  372. if (indx + 1 == numaux)
  373. {
  374. /* C_EXT can have several aux enties. But the _AUX_CSECT is always
  375. the last one. */
  376. auxtype = H_GET_8 (abfd, ext->x_csect.x_auxtype);
  377. if (auxtype != _AUX_CSECT)
  378. goto error;
  379. bfd_vma h = H_GET_S32 (abfd, ext->x_csect.x_scnlen_hi);
  380. bfd_vma l = H_GET_32 (abfd, ext->x_csect.x_scnlen_lo);
  381. in->x_csect.x_scnlen.l = h << 32 | (l & 0xffffffff);
  382. in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
  383. in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
  384. /* We don't have to hack bitfields in x_smtyp because it's
  385. defined by shifts-and-ands, which are equivalent on all
  386. byte orders. */
  387. in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
  388. in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
  389. }
  390. else
  391. {
  392. /* It can also be a _AUX_EXCEPT entry. But it's not supported
  393. for now. */
  394. auxtype = H_GET_8 (abfd, ext->x_fcn.x_auxtype);
  395. if (auxtype != _AUX_FCN)
  396. goto error;
  397. in->x_sym.x_fcnary.x_fcn.x_lnnoptr
  398. = H_GET_64 (abfd, ext->x_fcn.x_lnnoptr);
  399. in->x_sym.x_misc.x_fsize
  400. = H_GET_32 (abfd, ext->x_fcn.x_fsize);
  401. in->x_sym.x_fcnary.x_fcn.x_endndx.l
  402. = H_GET_32 (abfd, ext->x_fcn.x_endndx);
  403. }
  404. break;
  405. case C_STAT:
  406. _bfd_error_handler
  407. /* xgettext: c-format */
  408. (_("%pB: C_STAT isn't supported by XCOFF64"),
  409. abfd);
  410. bfd_set_error (bfd_error_bad_value);
  411. break;
  412. case C_BLOCK:
  413. case C_FCN:
  414. auxtype = H_GET_8 (abfd, ext->x_sym.x_auxtype);
  415. if (auxtype != _AUX_SYM)
  416. goto error;
  417. in->x_sym.x_misc.x_lnsz.x_lnno
  418. = H_GET_32 (abfd, ext->x_sym.x_lnno);
  419. break;
  420. case C_DWARF:
  421. auxtype = H_GET_8 (abfd, ext->x_sect.x_auxtype);
  422. if (auxtype != _AUX_SECT)
  423. goto error;
  424. in->x_sect.x_scnlen = H_GET_64 (abfd, ext->x_sect.x_scnlen);
  425. in->x_sect.x_nreloc = H_GET_64 (abfd, ext->x_sect.x_nreloc);
  426. break;
  427. }
  428. return;
  429. error:
  430. _bfd_error_handler
  431. /* xgettext: c-format */
  432. (_("%pB: wrong auxtype %#x for storage class %#x"),
  433. abfd, auxtype, (unsigned int) in_class);
  434. bfd_set_error (bfd_error_bad_value);
  435. }
  436. static unsigned int
  437. _bfd_xcoff64_swap_aux_out (bfd *abfd, void *inp, int type ATTRIBUTE_UNUSED,
  438. int in_class, int indx, int numaux, void *extp)
  439. {
  440. union internal_auxent *in = (union internal_auxent *) inp;
  441. union external_auxent *ext = (union external_auxent *) extp;
  442. memset (ext, 0, bfd_coff_auxesz (abfd));
  443. switch (in_class)
  444. {
  445. default:
  446. _bfd_error_handler
  447. /* xgettext: c-format */
  448. (_("%pB: unsupported swap_aux_out for storage class %#x"),
  449. abfd, (unsigned int) in_class);
  450. bfd_set_error (bfd_error_bad_value);
  451. break;
  452. case C_FILE:
  453. if (in->x_file.x_n.x_n.x_zeroes == 0)
  454. {
  455. H_PUT_32 (abfd, 0, ext->x_file.x_n.x_n.x_zeroes);
  456. H_PUT_32 (abfd, in->x_file.x_n.x_n.x_offset,
  457. ext->x_file.x_n.x_n.x_offset);
  458. }
  459. else
  460. memcpy (ext->x_file.x_n.x_fname, in->x_file.x_n.x_fname, FILNMLEN);
  461. H_PUT_8 (abfd, in->x_file.x_ftype, ext->x_file.x_ftype);
  462. H_PUT_8 (abfd, _AUX_FILE, ext->x_file.x_auxtype);
  463. break;
  464. /* RS/6000 "csect" auxents.
  465. There is always a CSECT auxiliary entry. But functions can
  466. have FCN and EXCEPT ones too. In this case, CSECT is always the last
  467. one.
  468. For now, we only support FCN types. */
  469. case C_EXT:
  470. case C_AIX_WEAKEXT:
  471. case C_HIDEXT:
  472. if (indx + 1 == numaux)
  473. {
  474. bfd_vma temp;
  475. temp = in->x_csect.x_scnlen.l & 0xffffffff;
  476. H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_lo);
  477. temp = in->x_csect.x_scnlen.l >> 32;
  478. H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_hi);
  479. H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
  480. H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
  481. /* We don't have to hack bitfields in x_smtyp because it's
  482. defined by shifts-and-ands, which are equivalent on all
  483. byte orders. */
  484. H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
  485. H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
  486. H_PUT_8 (abfd, _AUX_CSECT, ext->x_csect.x_auxtype);
  487. }
  488. else
  489. {
  490. H_PUT_64 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
  491. ext->x_fcn.x_lnnoptr);
  492. H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_fcn.x_fsize);
  493. H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
  494. ext->x_fcn.x_endndx);
  495. H_PUT_8 (abfd, _AUX_FCN, ext->x_csect.x_auxtype);
  496. }
  497. break;
  498. case C_STAT:
  499. _bfd_error_handler
  500. /* xgettext: c-format */
  501. (_("%pB: C_STAT isn't supported by XCOFF64"),
  502. abfd);
  503. bfd_set_error (bfd_error_bad_value);
  504. break;
  505. case C_BLOCK:
  506. case C_FCN:
  507. H_PUT_32 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext->x_sym.x_lnno);
  508. H_PUT_8 (abfd, _AUX_SYM, ext->x_sym.x_auxtype);
  509. break;
  510. case C_DWARF:
  511. H_PUT_64 (abfd, in->x_sect.x_scnlen, ext->x_sect.x_scnlen);
  512. H_PUT_64 (abfd, in->x_sect.x_nreloc, ext->x_sect.x_nreloc);
  513. H_PUT_8 (abfd, _AUX_SECT, ext->x_sect.x_auxtype);
  514. break;
  515. }
  516. return bfd_coff_auxesz (abfd);
  517. }
  518. static bool
  519. _bfd_xcoff64_put_symbol_name (struct bfd_link_info *info,
  520. struct bfd_strtab_hash *strtab,
  521. struct internal_syment *sym,
  522. const char *name)
  523. {
  524. bool hash;
  525. bfd_size_type indx;
  526. hash = !info->traditional_format;
  527. indx = _bfd_stringtab_add (strtab, name, hash, false);
  528. if (indx == (bfd_size_type) -1)
  529. return false;
  530. sym->_n._n_n._n_zeroes = 0;
  531. sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
  532. return true;
  533. }
  534. static bool
  535. _bfd_xcoff64_put_ldsymbol_name (bfd *abfd ATTRIBUTE_UNUSED,
  536. struct xcoff_loader_info *ldinfo,
  537. struct internal_ldsym *ldsym,
  538. const char *name)
  539. {
  540. size_t len;
  541. len = strlen (name);
  542. if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
  543. {
  544. bfd_size_type newalc;
  545. char *newstrings;
  546. newalc = ldinfo->string_alc * 2;
  547. if (newalc == 0)
  548. newalc = 32;
  549. while (ldinfo->string_size + len + 3 > newalc)
  550. newalc *= 2;
  551. newstrings = bfd_realloc (ldinfo->strings, newalc);
  552. if (newstrings == NULL)
  553. {
  554. ldinfo->failed = true;
  555. return false;
  556. }
  557. ldinfo->string_alc = newalc;
  558. ldinfo->strings = newstrings;
  559. }
  560. bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
  561. ldinfo->strings + ldinfo->string_size);
  562. strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
  563. ldsym->_l._l_l._l_zeroes = 0;
  564. ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
  565. ldinfo->string_size += len + 3;
  566. return true;
  567. }
  568. /* Routines to swap information in the XCOFF .loader section. If we
  569. ever need to write an XCOFF loader, this stuff will need to be
  570. moved to another file shared by the linker (which XCOFF calls the
  571. ``binder'') and the loader. */
  572. /* Swap in the ldhdr structure. */
  573. static void
  574. xcoff64_swap_ldhdr_in (bfd *abfd,
  575. const void *s,
  576. struct internal_ldhdr *dst)
  577. {
  578. const struct external_ldhdr *src = (const struct external_ldhdr *) s;
  579. dst->l_version = bfd_get_32 (abfd, src->l_version);
  580. dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
  581. dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
  582. dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
  583. dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
  584. dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
  585. dst->l_impoff = bfd_get_64 (abfd, src->l_impoff);
  586. dst->l_stoff = bfd_get_64 (abfd, src->l_stoff);
  587. dst->l_symoff = bfd_get_64 (abfd, src->l_symoff);
  588. dst->l_rldoff = bfd_get_64 (abfd, src->l_rldoff);
  589. }
  590. /* Swap out the ldhdr structure. */
  591. static void
  592. xcoff64_swap_ldhdr_out (bfd *abfd, const struct internal_ldhdr *src, void *d)
  593. {
  594. struct external_ldhdr *dst = (struct external_ldhdr *) d;
  595. bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
  596. bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
  597. bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
  598. bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
  599. bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
  600. bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
  601. bfd_put_64 (abfd, src->l_impoff, dst->l_impoff);
  602. bfd_put_64 (abfd, src->l_stoff, dst->l_stoff);
  603. bfd_put_64 (abfd, src->l_symoff, dst->l_symoff);
  604. bfd_put_64 (abfd, src->l_rldoff, dst->l_rldoff);
  605. }
  606. /* Swap in the ldsym structure. */
  607. static void
  608. xcoff64_swap_ldsym_in (bfd *abfd, const void *s, struct internal_ldsym *dst)
  609. {
  610. const struct external_ldsym *src = (const struct external_ldsym *) s;
  611. /* XCOFF64 does not use l_zeroes like XCOFF32
  612. Set the internal l_zeroes to 0 so the common 32/64 code uses l_value
  613. as an offset into the loader symbol table. */
  614. dst->_l._l_l._l_zeroes = 0;
  615. dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->l_offset);
  616. dst->l_value = bfd_get_64 (abfd, src->l_value);
  617. dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
  618. dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
  619. dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
  620. dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
  621. dst->l_parm = bfd_get_32 (abfd, src->l_parm);
  622. }
  623. /* Swap out the ldsym structure. */
  624. static void
  625. xcoff64_swap_ldsym_out (bfd *abfd, const struct internal_ldsym *src, void *d)
  626. {
  627. struct external_ldsym *dst = (struct external_ldsym *) d;
  628. bfd_put_64 (abfd, src->l_value, dst->l_value);
  629. bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset, dst->l_offset);
  630. bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
  631. bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
  632. bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
  633. bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
  634. bfd_put_32 (abfd, src->l_parm, dst->l_parm);
  635. }
  636. static void
  637. xcoff64_swap_reloc_in (bfd *abfd, void *s, void *d)
  638. {
  639. struct external_reloc *src = (struct external_reloc *) s;
  640. struct internal_reloc *dst = (struct internal_reloc *) d;
  641. memset (dst, 0, sizeof (struct internal_reloc));
  642. dst->r_vaddr = bfd_get_64 (abfd, src->r_vaddr);
  643. dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
  644. dst->r_size = bfd_get_8 (abfd, src->r_size);
  645. dst->r_type = bfd_get_8 (abfd, src->r_type);
  646. }
  647. static unsigned int
  648. xcoff64_swap_reloc_out (bfd *abfd, void *s, void *d)
  649. {
  650. struct internal_reloc *src = (struct internal_reloc *) s;
  651. struct external_reloc *dst = (struct external_reloc *) d;
  652. bfd_put_64 (abfd, src->r_vaddr, dst->r_vaddr);
  653. bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
  654. bfd_put_8 (abfd, src->r_type, dst->r_type);
  655. bfd_put_8 (abfd, src->r_size, dst->r_size);
  656. return bfd_coff_relsz (abfd);
  657. }
  658. /* Swap in the ldrel structure. */
  659. static void
  660. xcoff64_swap_ldrel_in (bfd *abfd, const void *s, struct internal_ldrel *dst)
  661. {
  662. const struct external_ldrel *src = (const struct external_ldrel *) s;
  663. dst->l_vaddr = bfd_get_64 (abfd, src->l_vaddr);
  664. dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
  665. dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
  666. dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
  667. }
  668. /* Swap out the ldrel structure. */
  669. static void
  670. xcoff64_swap_ldrel_out (bfd *abfd, const struct internal_ldrel *src, void *d)
  671. {
  672. struct external_ldrel *dst = (struct external_ldrel *) d;
  673. bfd_put_64 (abfd, src->l_vaddr, dst->l_vaddr);
  674. bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
  675. bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
  676. bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
  677. }
  678. static bool
  679. xcoff64_reloc_type_br (bfd *input_bfd,
  680. asection *input_section,
  681. bfd *output_bfd ATTRIBUTE_UNUSED,
  682. struct internal_reloc *rel,
  683. struct internal_syment *sym ATTRIBUTE_UNUSED,
  684. struct reloc_howto_struct *howto,
  685. bfd_vma val,
  686. bfd_vma addend,
  687. bfd_vma *relocation,
  688. bfd_byte *contents)
  689. {
  690. struct xcoff_link_hash_entry *h;
  691. bfd_vma section_offset;
  692. if (0 > rel->r_symndx)
  693. return false;
  694. h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
  695. section_offset = rel->r_vaddr - input_section->vma;
  696. /* If we see an R_BR or R_RBR reloc which is jumping to global
  697. linkage code, and it is followed by an appropriate cror nop
  698. instruction, we replace the cror with ld r2,40(r1). This
  699. restores the TOC after the glink code. Contrariwise, if the
  700. call is followed by a ld r2,40(r1), but the call is not
  701. going to global linkage code, we can replace the load with a
  702. cror. */
  703. if (NULL != h
  704. && (bfd_link_hash_defined == h->root.type
  705. || bfd_link_hash_defweak == h->root.type)
  706. && section_offset + 8 <= input_section->size)
  707. {
  708. bfd_byte *pnext;
  709. unsigned long next;
  710. pnext = contents + section_offset + 4;
  711. next = bfd_get_32 (input_bfd, pnext);
  712. /* The _ptrgl function is magic. It is used by the AIX compiler to call
  713. a function through a pointer. */
  714. if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
  715. {
  716. if (next == 0x4def7b82 /* cror 15,15,15 */
  717. || next == 0x4ffffb82 /* cror 31,31,31 */
  718. || next == 0x60000000) /* ori r0,r0,0 */
  719. bfd_put_32 (input_bfd, 0xe8410028, pnext); /* ld r2,40(r1) */
  720. }
  721. else
  722. {
  723. if (next == 0xe8410028) /* ld r2,40(r1) */
  724. bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
  725. }
  726. }
  727. else if (NULL != h && bfd_link_hash_undefined == h->root.type)
  728. {
  729. /* Normally, this relocation is against a defined symbol. In the
  730. case where this is a partial link and the output section offset
  731. is greater than 2^25, the linker will return an invalid error
  732. message that the relocation has been truncated. Yes it has been
  733. truncated but no it not important. For this case, disable the
  734. overflow checking. */
  735. howto->complain_on_overflow = complain_overflow_dont;
  736. }
  737. /* The original PC-relative relocation is biased by -r_vaddr, so adding
  738. the value below will give the absolute target address. */
  739. *relocation = val + addend + rel->r_vaddr;
  740. howto->src_mask &= ~3;
  741. howto->dst_mask = howto->src_mask;
  742. if (h != NULL
  743. && (h->root.type == bfd_link_hash_defined
  744. || h->root.type == bfd_link_hash_defweak)
  745. && bfd_is_abs_section (h->root.u.def.section)
  746. && section_offset + 4 <= input_section->size)
  747. {
  748. bfd_byte *ptr;
  749. bfd_vma insn;
  750. /* Turn the relative branch into an absolute one by setting the
  751. AA bit. */
  752. ptr = contents + section_offset;
  753. insn = bfd_get_32 (input_bfd, ptr);
  754. insn |= 2;
  755. bfd_put_32 (input_bfd, insn, ptr);
  756. /* Make the howto absolute too. */
  757. howto->pc_relative = false;
  758. howto->complain_on_overflow = complain_overflow_bitfield;
  759. }
  760. else
  761. {
  762. /* Use a PC-relative howto and subtract the instruction's address
  763. from the target address we calculated above. */
  764. howto->pc_relative = true;
  765. *relocation -= (input_section->output_section->vma
  766. + input_section->output_offset
  767. + section_offset);
  768. }
  769. return true;
  770. }
  771. /* The XCOFF reloc table.
  772. Cf xcoff_howto_table comments. */
  773. reloc_howto_type xcoff64_howto_table[] =
  774. {
  775. /* 0x00: Standard 64 bit relocation. */
  776. HOWTO (R_POS, /* type */
  777. 0, /* rightshift */
  778. 4, /* size (0 = byte, 1 = short, 2 = long) */
  779. 64, /* bitsize */
  780. false, /* pc_relative */
  781. 0, /* bitpos */
  782. complain_overflow_bitfield, /* complain_on_overflow */
  783. 0, /* special_function */
  784. "R_POS_64", /* name */
  785. true, /* partial_inplace */
  786. MINUS_ONE, /* src_mask */
  787. MINUS_ONE, /* dst_mask */
  788. false), /* pcrel_offset */
  789. /* 0x01: 64 bit relocation, but store negative value. */
  790. HOWTO (R_NEG, /* type */
  791. 0, /* rightshift */
  792. -4, /* size (0 = byte, 1 = short, 2 = long) */
  793. 64, /* bitsize */
  794. false, /* pc_relative */
  795. 0, /* bitpos */
  796. complain_overflow_bitfield, /* complain_on_overflow */
  797. 0, /* special_function */
  798. "R_NEG", /* name */
  799. true, /* partial_inplace */
  800. MINUS_ONE, /* src_mask */
  801. MINUS_ONE, /* dst_mask */
  802. false), /* pcrel_offset */
  803. /* 0x02: 64 bit PC relative relocation. */
  804. HOWTO (R_REL, /* type */
  805. 0, /* rightshift */
  806. 4, /* size (0 = byte, 1 = short, 2 = long) */
  807. 64, /* bitsize */
  808. true, /* pc_relative */
  809. 0, /* bitpos */
  810. complain_overflow_signed, /* complain_on_overflow */
  811. 0, /* special_function */
  812. "R_REL", /* name */
  813. true, /* partial_inplace */
  814. MINUS_ONE, /* src_mask */
  815. MINUS_ONE, /* dst_mask */
  816. false), /* pcrel_offset */
  817. /* 0x03: 16 bit TOC relative relocation. */
  818. HOWTO (R_TOC, /* type */
  819. 0, /* rightshift */
  820. 1, /* size (0 = byte, 1 = short, 2 = long) */
  821. 16, /* bitsize */
  822. false, /* pc_relative */
  823. 0, /* bitpos */
  824. complain_overflow_bitfield, /* complain_on_overflow */
  825. 0, /* special_function */
  826. "R_TOC", /* name */
  827. true, /* partial_inplace */
  828. 0, /* src_mask */
  829. 0xffff, /* dst_mask */
  830. false), /* pcrel_offset */
  831. /* 0x04: Same as R_TOC. */
  832. HOWTO (R_TRL, /* type */
  833. 0, /* rightshift */
  834. 1, /* size (0 = byte, 1 = short, 2 = long) */
  835. 16, /* bitsize */
  836. false, /* pc_relative */
  837. 0, /* bitpos */
  838. complain_overflow_bitfield, /* complain_on_overflow */
  839. 0, /* special_function */
  840. "R_TRL", /* name */
  841. true, /* partial_inplace */
  842. 0, /* src_mask */
  843. 0xffff, /* dst_mask */
  844. false), /* pcrel_offset */
  845. /* 0x05: External TOC relative symbol. */
  846. HOWTO (R_GL, /* type */
  847. 0, /* rightshift */
  848. 1, /* size (0 = byte, 1 = short, 2 = long) */
  849. 16, /* bitsize */
  850. false, /* pc_relative */
  851. 0, /* bitpos */
  852. complain_overflow_bitfield, /* complain_on_overflow */
  853. 0, /* special_function */
  854. "R_GL", /* name */
  855. true, /* partial_inplace */
  856. 0, /* src_mask */
  857. 0xffff, /* dst_mask */
  858. false), /* pcrel_offset */
  859. /* 0x06: Local TOC relative symbol. */
  860. HOWTO (R_TCL, /* type */
  861. 0, /* rightshift */
  862. 1, /* size (0 = byte, 1 = short, 2 = long) */
  863. 16, /* bitsize */
  864. false, /* pc_relative */
  865. 0, /* bitpos */
  866. complain_overflow_bitfield, /* complain_on_overflow */
  867. 0, /* special_function */
  868. "R_TCL", /* name */
  869. true, /* partial_inplace */
  870. 0, /* src_mask */
  871. 0xffff, /* dst_mask */
  872. false), /* pcrel_offset */
  873. EMPTY_HOWTO (7),
  874. /* 0x08: Same as R_RBA. */
  875. HOWTO (R_BA, /* type */
  876. 0, /* rightshift */
  877. 2, /* size (0 = byte, 1 = short, 2 = long) */
  878. 26, /* bitsize */
  879. false, /* pc_relative */
  880. 0, /* bitpos */
  881. complain_overflow_bitfield, /* complain_on_overflow */
  882. 0, /* special_function */
  883. "R_BA_26", /* name */
  884. true, /* partial_inplace */
  885. 0x03fffffc, /* src_mask */
  886. 0x03fffffc, /* dst_mask */
  887. false), /* pcrel_offset */
  888. EMPTY_HOWTO (9),
  889. /* 0x0a: Same as R_RBR. */
  890. HOWTO (R_BR, /* type */
  891. 0, /* rightshift */
  892. 2, /* size (0 = byte, 1 = short, 2 = long) */
  893. 26, /* bitsize */
  894. true, /* pc_relative */
  895. 0, /* bitpos */
  896. complain_overflow_signed, /* complain_on_overflow */
  897. 0, /* special_function */
  898. "R_BR", /* name */
  899. true, /* partial_inplace */
  900. 0x03fffffc, /* src_mask */
  901. 0x03fffffc, /* dst_mask */
  902. false), /* pcrel_offset */
  903. EMPTY_HOWTO (0xb),
  904. /* 0x0c: Same as R_POS. */
  905. HOWTO (R_RL, /* type */
  906. 0, /* rightshift */
  907. 4, /* size (0 = byte, 1 = short, 2 = long) */
  908. 64, /* bitsize */
  909. false, /* pc_relative */
  910. 0, /* bitpos */
  911. complain_overflow_bitfield, /* complain_on_overflow */
  912. 0, /* special_function */
  913. "R_RL", /* name */
  914. true, /* partial_inplace */
  915. MINUS_ONE, /* src_mask */
  916. MINUS_ONE, /* dst_mask */
  917. false), /* pcrel_offset */
  918. /* 0x0d: Same as R_POS. */
  919. HOWTO (R_RLA, /* type */
  920. 0, /* rightshift */
  921. 4, /* size (0 = byte, 1 = short, 2 = long) */
  922. 64, /* bitsize */
  923. false, /* pc_relative */
  924. 0, /* bitpos */
  925. complain_overflow_bitfield, /* complain_on_overflow */
  926. 0, /* special_function */
  927. "R_RLA", /* name */
  928. true, /* partial_inplace */
  929. MINUS_ONE, /* src_mask */
  930. MINUS_ONE, /* dst_mask */
  931. false), /* pcrel_offset */
  932. EMPTY_HOWTO (0xe),
  933. /* 0x0f: Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
  934. HOWTO (R_REF, /* type */
  935. 0, /* rightshift */
  936. 0, /* size (0 = byte, 1 = short, 2 = long) */
  937. 1, /* bitsize */
  938. false, /* pc_relative */
  939. 0, /* bitpos */
  940. complain_overflow_dont, /* complain_on_overflow */
  941. 0, /* special_function */
  942. "R_REF", /* name */
  943. false, /* partial_inplace */
  944. 0, /* src_mask */
  945. 0, /* dst_mask */
  946. false), /* pcrel_offset */
  947. EMPTY_HOWTO (0x10),
  948. EMPTY_HOWTO (0x11),
  949. EMPTY_HOWTO (0x12),
  950. /* 0x13: Same as R_TOC */
  951. HOWTO (R_TRLA, /* type */
  952. 0, /* rightshift */
  953. 1, /* size (0 = byte, 1 = short, 2 = long) */
  954. 16, /* bitsize */
  955. false, /* pc_relative */
  956. 0, /* bitpos */
  957. complain_overflow_bitfield, /* complain_on_overflow */
  958. 0, /* special_function */
  959. "R_TRLA", /* name */
  960. true, /* partial_inplace */
  961. 0xffff, /* src_mask */
  962. 0xffff, /* dst_mask */
  963. false), /* pcrel_offset */
  964. /* 0x14: Modifiable relative branch. */
  965. HOWTO (R_RRTBI, /* type */
  966. 1, /* rightshift */
  967. 2, /* size (0 = byte, 1 = short, 2 = long) */
  968. 32, /* bitsize */
  969. false, /* pc_relative */
  970. 0, /* bitpos */
  971. complain_overflow_bitfield, /* complain_on_overflow */
  972. 0, /* special_function */
  973. "R_RRTBI", /* name */
  974. true, /* partial_inplace */
  975. 0xffffffff, /* src_mask */
  976. 0xffffffff, /* dst_mask */
  977. false), /* pcrel_offset */
  978. /* 0x15: Modifiable absolute branch. */
  979. HOWTO (R_RRTBA, /* type */
  980. 1, /* rightshift */
  981. 2, /* size (0 = byte, 1 = short, 2 = long) */
  982. 32, /* bitsize */
  983. false, /* pc_relative */
  984. 0, /* bitpos */
  985. complain_overflow_bitfield, /* complain_on_overflow */
  986. 0, /* special_function */
  987. "R_RRTBA", /* name */
  988. true, /* partial_inplace */
  989. 0xffffffff, /* src_mask */
  990. 0xffffffff, /* dst_mask */
  991. false), /* pcrel_offset */
  992. /* 0x16: Modifiable call absolute indirect. */
  993. HOWTO (R_CAI, /* type */
  994. 0, /* rightshift */
  995. 1, /* size (0 = byte, 1 = short, 2 = long) */
  996. 16, /* bitsize */
  997. false, /* pc_relative */
  998. 0, /* bitpos */
  999. complain_overflow_bitfield, /* complain_on_overflow */
  1000. 0, /* special_function */
  1001. "R_CAI", /* name */
  1002. true, /* partial_inplace */
  1003. 0xffff, /* src_mask */
  1004. 0xffff, /* dst_mask */
  1005. false), /* pcrel_offset */
  1006. /* 0x17: Modifiable call relative. */
  1007. HOWTO (R_CREL, /* type */
  1008. 0, /* rightshift */
  1009. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1010. 16, /* bitsize */
  1011. false, /* pc_relative */
  1012. 0, /* bitpos */
  1013. complain_overflow_bitfield, /* complain_on_overflow */
  1014. 0, /* special_function */
  1015. "R_CREL", /* name */
  1016. true, /* partial_inplace */
  1017. 0xffff, /* src_mask */
  1018. 0xffff, /* dst_mask */
  1019. false), /* pcrel_offset */
  1020. /* 0x18: Modifiable branch absolute. */
  1021. HOWTO (R_RBA, /* type */
  1022. 0, /* rightshift */
  1023. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1024. 26, /* bitsize */
  1025. false, /* pc_relative */
  1026. 0, /* bitpos */
  1027. complain_overflow_bitfield, /* complain_on_overflow */
  1028. 0, /* special_function */
  1029. "R_RBA", /* name */
  1030. true, /* partial_inplace */
  1031. 0x03fffffc, /* src_mask */
  1032. 0x03fffffc, /* dst_mask */
  1033. false), /* pcrel_offset */
  1034. /* 0x19: Modifiable branch absolute. */
  1035. HOWTO (R_RBAC, /* type */
  1036. 0, /* rightshift */
  1037. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1038. 32, /* bitsize */
  1039. false, /* pc_relative */
  1040. 0, /* bitpos */
  1041. complain_overflow_bitfield, /* complain_on_overflow */
  1042. 0, /* special_function */
  1043. "R_RBAC", /* name */
  1044. true, /* partial_inplace */
  1045. 0xffffffff, /* src_mask */
  1046. 0xffffffff, /* dst_mask */
  1047. false), /* pcrel_offset */
  1048. /* 0x1a: Modifiable branch relative. */
  1049. HOWTO (R_RBR, /* type */
  1050. 0, /* rightshift */
  1051. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1052. 26, /* bitsize */
  1053. false, /* pc_relative */
  1054. 0, /* bitpos */
  1055. complain_overflow_signed, /* complain_on_overflow */
  1056. 0, /* special_function */
  1057. "R_RBR_26", /* name */
  1058. true, /* partial_inplace */
  1059. 0x03fffffc, /* src_mask */
  1060. 0x03fffffc, /* dst_mask */
  1061. false), /* pcrel_offset */
  1062. /* 0x1b: Modifiable branch absolute. */
  1063. HOWTO (R_RBRC, /* type */
  1064. 0, /* rightshift */
  1065. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1066. 16, /* bitsize */
  1067. false, /* pc_relative */
  1068. 0, /* bitpos */
  1069. complain_overflow_bitfield, /* complain_on_overflow */
  1070. 0, /* special_function */
  1071. "R_RBRC", /* name */
  1072. true, /* partial_inplace */
  1073. 0xffff, /* src_mask */
  1074. 0xffff, /* dst_mask */
  1075. false), /* pcrel_offset */
  1076. /* 0x1c: Standard 32 bit relocation. */
  1077. HOWTO (R_POS, /* type */
  1078. 0, /* rightshift */
  1079. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1080. 32, /* bitsize */
  1081. false, /* pc_relative */
  1082. 0, /* bitpos */
  1083. complain_overflow_bitfield, /* complain_on_overflow */
  1084. 0, /* special_function */
  1085. "R_POS_32", /* name */
  1086. true, /* partial_inplace */
  1087. 0xffffffff, /* src_mask */
  1088. 0xffffffff, /* dst_mask */
  1089. false), /* pcrel_offset */
  1090. /* 0x1d: 16 bit Non modifiable absolute branch. */
  1091. HOWTO (R_BA, /* type */
  1092. 0, /* rightshift */
  1093. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1094. 16, /* bitsize */
  1095. false, /* pc_relative */
  1096. 0, /* bitpos */
  1097. complain_overflow_bitfield, /* complain_on_overflow */
  1098. 0, /* special_function */
  1099. "R_BA_16", /* name */
  1100. true, /* partial_inplace */
  1101. 0xfffc, /* src_mask */
  1102. 0xfffc, /* dst_mask */
  1103. false), /* pcrel_offset */
  1104. /* 0x1e: Modifiable branch relative. */
  1105. HOWTO (R_RBR, /* type */
  1106. 0, /* rightshift */
  1107. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1108. 16, /* bitsize */
  1109. true, /* pc_relative */
  1110. 0, /* bitpos */
  1111. complain_overflow_signed, /* complain_on_overflow */
  1112. 0, /* special_function */
  1113. "R_RBR_16", /* name */
  1114. true, /* partial_inplace */
  1115. 0xfffc, /* src_mask */
  1116. 0xfffc, /* dst_mask */
  1117. false), /* pcrel_offset */
  1118. /* 0x1f: Modifiable branch absolute. */
  1119. HOWTO (R_RBA, /* type */
  1120. 0, /* rightshift */
  1121. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1122. 16, /* bitsize */
  1123. false, /* pc_relative */
  1124. 0, /* bitpos */
  1125. complain_overflow_bitfield, /* complain_on_overflow */
  1126. 0, /* special_function */
  1127. "R_RBA_16", /* name */
  1128. true, /* partial_inplace */
  1129. 0xffff, /* src_mask */
  1130. 0xffff, /* dst_mask */
  1131. false), /* pcrel_offset */
  1132. /* 0x20: General-dynamic TLS relocation. */
  1133. HOWTO (R_TLS, /* type */
  1134. 0, /* rightshift */
  1135. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1136. 64, /* bitsize */
  1137. false, /* pc_relative */
  1138. 0, /* bitpos */
  1139. complain_overflow_bitfield, /* complain_on_overflow */
  1140. 0, /* special_function */
  1141. "R_TLS", /* name */
  1142. true, /* partial_inplace */
  1143. MINUS_ONE, /* src_mask */
  1144. MINUS_ONE, /* dst_mask */
  1145. false), /* pcrel_offset */
  1146. /* 0x21: Initial-exec TLS relocation. */
  1147. HOWTO (R_TLS_IE, /* type */
  1148. 0, /* rightshift */
  1149. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1150. 64, /* bitsize */
  1151. false, /* pc_relative */
  1152. 0, /* bitpos */
  1153. complain_overflow_bitfield, /* complain_on_overflow */
  1154. 0, /* special_function */
  1155. "R_TLS_IE", /* name */
  1156. true, /* partial_inplace */
  1157. MINUS_ONE, /* src_mask */
  1158. MINUS_ONE, /* dst_mask */
  1159. false), /* pcrel_offset */
  1160. /* 0x22: Local-dynamic TLS relocation. */
  1161. HOWTO (R_TLS_LD, /* type */
  1162. 0, /* rightshift */
  1163. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1164. 64, /* bitsize */
  1165. false, /* pc_relative */
  1166. 0, /* bitpos */
  1167. complain_overflow_bitfield, /* complain_on_overflow */
  1168. 0, /* special_function */
  1169. "R_TLS_LD", /* name */
  1170. true, /* partial_inplace */
  1171. MINUS_ONE, /* src_mask */
  1172. MINUS_ONE, /* dst_mask */
  1173. false), /* pcrel_offset */
  1174. /* 0x23: Local-exec TLS relocation. */
  1175. HOWTO (R_TLS_LE, /* type */
  1176. 0, /* rightshift */
  1177. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1178. 64, /* bitsize */
  1179. false, /* pc_relative */
  1180. 0, /* bitpos */
  1181. complain_overflow_bitfield, /* complain_on_overflow */
  1182. 0, /* special_function */
  1183. "R_TLS_LE", /* name */
  1184. true, /* partial_inplace */
  1185. MINUS_ONE, /* src_mask */
  1186. MINUS_ONE, /* dst_mask */
  1187. false), /* pcrel_offset */
  1188. /* 0x24: TLS relocation. */
  1189. HOWTO (R_TLSM, /* type */
  1190. 0, /* rightshift */
  1191. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1192. 64, /* bitsize */
  1193. false, /* pc_relative */
  1194. 0, /* bitpos */
  1195. complain_overflow_bitfield, /* complain_on_overflow */
  1196. 0, /* special_function */
  1197. "R_TLSM", /* name */
  1198. true, /* partial_inplace */
  1199. MINUS_ONE, /* src_mask */
  1200. MINUS_ONE, /* dst_mask */
  1201. false), /* pcrel_offset */
  1202. /* 0x25: TLS module relocation. */
  1203. HOWTO (R_TLSML, /* type */
  1204. 0, /* rightshift */
  1205. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1206. 64, /* bitsize */
  1207. false, /* pc_relative */
  1208. 0, /* bitpos */
  1209. complain_overflow_bitfield, /* complain_on_overflow */
  1210. 0, /* special_function */
  1211. "R_TLSML", /* name */
  1212. true, /* partial_inplace */
  1213. MINUS_ONE, /* src_mask */
  1214. MINUS_ONE, /* dst_mask */
  1215. false), /* pcrel_offset */
  1216. /* 0x26: 32 bit relocation, but store negative value. */
  1217. HOWTO (R_NEG, /* type */
  1218. 0, /* rightshift */
  1219. -2, /* size (0 = byte, 1 = short, 2 = long) */
  1220. 32, /* bitsize */
  1221. false, /* pc_relative */
  1222. 0, /* bitpos */
  1223. complain_overflow_bitfield, /* complain_on_overflow */
  1224. 0, /* special_function */
  1225. "R_NEG_32", /* name */
  1226. true, /* partial_inplace */
  1227. MINUS_ONE, /* src_mask */
  1228. MINUS_ONE, /* dst_mask */
  1229. false), /* pcrel_offset */
  1230. EMPTY_HOWTO(0x27),
  1231. EMPTY_HOWTO(0x28),
  1232. EMPTY_HOWTO(0x29),
  1233. EMPTY_HOWTO(0x2a),
  1234. EMPTY_HOWTO(0x2b),
  1235. EMPTY_HOWTO(0x2c),
  1236. EMPTY_HOWTO(0x2d),
  1237. EMPTY_HOWTO(0x2e),
  1238. EMPTY_HOWTO(0x2f),
  1239. HOWTO (R_TOCU, /* type */
  1240. 16, /* rightshift */
  1241. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1242. 16, /* bitsize */
  1243. false, /* pc_relative */
  1244. 0, /* bitpos */
  1245. complain_overflow_bitfield, /* complain_on_overflow */
  1246. 0, /* special_function */
  1247. "R_TOCU", /* name */
  1248. true, /* partial_inplace */
  1249. 0, /* src_mask */
  1250. 0xffff, /* dst_mask */
  1251. false), /* pcrel_offset */
  1252. /* 0x31: Low-order 16 bit TOC relative relocation. */
  1253. HOWTO (R_TOCL, /* type */
  1254. 0, /* rightshift */
  1255. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1256. 16, /* bitsize */
  1257. false, /* pc_relative */
  1258. 0, /* bitpos */
  1259. complain_overflow_dont, /* complain_on_overflow */
  1260. 0, /* special_function */
  1261. "R_TOCL", /* name */
  1262. true, /* partial_inplace */
  1263. 0, /* src_mask */
  1264. 0xffff, /* dst_mask */
  1265. false), /* pcrel_offset */
  1266. };
  1267. void
  1268. xcoff64_rtype2howto (arelent *relent, struct internal_reloc *internal)
  1269. {
  1270. if (internal->r_type > R_TOCL)
  1271. abort ();
  1272. /* Default howto layout works most of the time */
  1273. relent->howto = &xcoff64_howto_table[internal->r_type];
  1274. /* Special case some 16 bit reloc */
  1275. if (15 == (internal->r_size & 0x3f))
  1276. {
  1277. if (R_BA == internal->r_type)
  1278. relent->howto = &xcoff64_howto_table[0x1d];
  1279. else if (R_RBR == internal->r_type)
  1280. relent->howto = &xcoff64_howto_table[0x1e];
  1281. else if (R_RBA == internal->r_type)
  1282. relent->howto = &xcoff64_howto_table[0x1f];
  1283. }
  1284. /* Special case 32 bit */
  1285. else if (31 == (internal->r_size & 0x3f))
  1286. {
  1287. if (R_POS == internal->r_type)
  1288. relent->howto = &xcoff64_howto_table[0x1c];
  1289. if (R_NEG == internal->r_type)
  1290. relent->howto = &xcoff64_howto_table[0x26];
  1291. }
  1292. /* The r_size field of an XCOFF reloc encodes the bitsize of the
  1293. relocation, as well as indicating whether it is signed or not.
  1294. Doublecheck that the relocation information gathered from the
  1295. type matches this information. The bitsize is not significant
  1296. for R_REF relocs. */
  1297. if (relent->howto->dst_mask != 0
  1298. && (relent->howto->bitsize
  1299. != ((unsigned int) internal->r_size & 0x3f) + 1))
  1300. abort ();
  1301. }
  1302. reloc_howto_type *
  1303. xcoff64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1304. bfd_reloc_code_real_type code)
  1305. {
  1306. switch (code)
  1307. {
  1308. case BFD_RELOC_PPC_B26:
  1309. return &xcoff64_howto_table[0xa];
  1310. case BFD_RELOC_PPC_BA16:
  1311. return &xcoff64_howto_table[0x1d];
  1312. case BFD_RELOC_PPC_BA26:
  1313. return &xcoff64_howto_table[8];
  1314. case BFD_RELOC_PPC_TOC16:
  1315. return &xcoff64_howto_table[3];
  1316. case BFD_RELOC_PPC_TOC16_HI:
  1317. return &xcoff64_howto_table[0x30];
  1318. case BFD_RELOC_PPC_TOC16_LO:
  1319. return &xcoff64_howto_table[0x31];
  1320. case BFD_RELOC_PPC_B16:
  1321. return &xcoff64_howto_table[0x1e];
  1322. case BFD_RELOC_32:
  1323. case BFD_RELOC_CTOR:
  1324. return &xcoff64_howto_table[0x1c];
  1325. case BFD_RELOC_64:
  1326. return &xcoff64_howto_table[0];
  1327. case BFD_RELOC_NONE:
  1328. return &xcoff64_howto_table[0xf];
  1329. case BFD_RELOC_PPC_NEG:
  1330. return &xcoff64_howto_table[0x1];
  1331. case BFD_RELOC_PPC64_TLSGD:
  1332. return &xcoff64_howto_table[0x20];
  1333. case BFD_RELOC_PPC64_TLSIE:
  1334. return &xcoff64_howto_table[0x21];
  1335. case BFD_RELOC_PPC64_TLSLD:
  1336. return &xcoff64_howto_table[0x22];
  1337. case BFD_RELOC_PPC64_TLSLE:
  1338. return &xcoff64_howto_table[0x23];
  1339. case BFD_RELOC_PPC64_TLSM:
  1340. return &xcoff64_howto_table[0x24];
  1341. case BFD_RELOC_PPC64_TLSML:
  1342. return &xcoff64_howto_table[0x25];
  1343. default:
  1344. return NULL;
  1345. }
  1346. }
  1347. static reloc_howto_type *
  1348. xcoff64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1349. const char *r_name)
  1350. {
  1351. unsigned int i;
  1352. for (i = 0;
  1353. i < sizeof (xcoff64_howto_table) / sizeof (xcoff64_howto_table[0]);
  1354. i++)
  1355. if (xcoff64_howto_table[i].name != NULL
  1356. && strcasecmp (xcoff64_howto_table[i].name, r_name) == 0)
  1357. return &xcoff64_howto_table[i];
  1358. return NULL;
  1359. }
  1360. /* This is the relocation function for the PowerPC64.
  1361. See xcoff_ppc_relocation_section for more information. */
  1362. bool
  1363. xcoff64_ppc_relocate_section (bfd *output_bfd,
  1364. struct bfd_link_info *info,
  1365. bfd *input_bfd,
  1366. asection *input_section,
  1367. bfd_byte *contents,
  1368. struct internal_reloc *relocs,
  1369. struct internal_syment *syms,
  1370. asection **sections)
  1371. {
  1372. struct internal_reloc *rel;
  1373. struct internal_reloc *relend;
  1374. rel = relocs;
  1375. relend = rel + input_section->reloc_count;
  1376. for (; rel < relend; rel++)
  1377. {
  1378. long symndx;
  1379. struct xcoff_link_hash_entry *h;
  1380. struct internal_syment *sym;
  1381. bfd_vma addend;
  1382. bfd_vma val;
  1383. struct reloc_howto_struct howto;
  1384. bfd_vma relocation;
  1385. bfd_vma value_to_relocate;
  1386. bfd_vma address;
  1387. bfd_byte *location;
  1388. /* Relocation type R_REF is a special relocation type which is
  1389. merely used to prevent garbage collection from occurring for
  1390. the csect including the symbol which it references. */
  1391. if (rel->r_type == R_REF)
  1392. continue;
  1393. /* Retrieve default value in HOWTO table and fix up according
  1394. to r_size field, if it can be different.
  1395. This should be made during relocation reading but the algorithms
  1396. are expecting constant howtos. */
  1397. memcpy (&howto, &xcoff64_howto_table[rel->r_type], sizeof (howto));
  1398. if (howto.bitsize != (rel->r_size & 0x3f) + 1)
  1399. {
  1400. switch (rel->r_type)
  1401. {
  1402. case R_POS:
  1403. case R_NEG:
  1404. howto.bitsize = (rel->r_size & 0x3f) + 1;
  1405. howto.size = howto.bitsize > 16 ? (howto.bitsize > 32 ? 4 : 2) : 1;
  1406. howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
  1407. break;
  1408. default:
  1409. _bfd_error_handler
  1410. (_("%pB: relocation (%d) at (0x%" BFD_VMA_FMT "x) has wrong"
  1411. " r_rsize (0x%x)\n"),
  1412. input_bfd, rel->r_type, rel->r_vaddr, rel->r_size);
  1413. return false;
  1414. }
  1415. }
  1416. howto.complain_on_overflow = (rel->r_size & 0x80
  1417. ? complain_overflow_signed
  1418. : complain_overflow_bitfield);
  1419. /* symbol */
  1420. val = 0;
  1421. addend = 0;
  1422. h = NULL;
  1423. sym = NULL;
  1424. symndx = rel->r_symndx;
  1425. if (-1 != symndx)
  1426. {
  1427. asection *sec;
  1428. h = obj_xcoff_sym_hashes (input_bfd)[symndx];
  1429. sym = syms + symndx;
  1430. addend = - sym->n_value;
  1431. if (NULL == h)
  1432. {
  1433. sec = sections[symndx];
  1434. /* Hack to make sure we use the right TOC anchor value
  1435. if this reloc is against the TOC anchor. */
  1436. if (sec->name[3] == '0'
  1437. && strcmp (sec->name, ".tc0") == 0)
  1438. val = xcoff_data (output_bfd)->toc;
  1439. else
  1440. val = (sec->output_section->vma
  1441. + sec->output_offset
  1442. + sym->n_value
  1443. - sec->vma);
  1444. }
  1445. else
  1446. {
  1447. if (info->unresolved_syms_in_objects != RM_IGNORE
  1448. && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
  1449. info->callbacks->undefined_symbol
  1450. (info, h->root.root.string, input_bfd, input_section,
  1451. rel->r_vaddr - input_section->vma,
  1452. info->unresolved_syms_in_objects == RM_DIAGNOSE
  1453. && !info->warn_unresolved_syms);
  1454. if (h->root.type == bfd_link_hash_defined
  1455. || h->root.type == bfd_link_hash_defweak)
  1456. {
  1457. sec = h->root.u.def.section;
  1458. val = (h->root.u.def.value
  1459. + sec->output_section->vma
  1460. + sec->output_offset);
  1461. }
  1462. else if (h->root.type == bfd_link_hash_common)
  1463. {
  1464. sec = h->root.u.c.p->section;
  1465. val = (sec->output_section->vma
  1466. + sec->output_offset);
  1467. }
  1468. else
  1469. {
  1470. BFD_ASSERT (bfd_link_relocatable (info)
  1471. || (h->flags & XCOFF_DEF_DYNAMIC) != 0
  1472. || (h->flags & XCOFF_IMPORT) != 0);
  1473. }
  1474. }
  1475. }
  1476. if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
  1477. || !((*xcoff64_calculate_relocation[rel->r_type])
  1478. (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
  1479. addend, &relocation, contents)))
  1480. return false;
  1481. /* address */
  1482. address = rel->r_vaddr - input_section->vma;
  1483. location = contents + address;
  1484. if (address > input_section->size)
  1485. abort ();
  1486. /* Get the value we are going to relocate. */
  1487. if (1 == howto.size)
  1488. value_to_relocate = bfd_get_16 (input_bfd, location);
  1489. else if (2 == howto.size)
  1490. value_to_relocate = bfd_get_32 (input_bfd, location);
  1491. else
  1492. value_to_relocate = bfd_get_64 (input_bfd, location);
  1493. /* overflow.
  1494. FIXME: We may drop bits during the addition
  1495. which we don't check for. We must either check at every single
  1496. operation, which would be tedious, or we must do the computations
  1497. in a type larger than bfd_vma, which would be inefficient. */
  1498. if (((*xcoff_complain_overflow[howto.complain_on_overflow])
  1499. (input_bfd, value_to_relocate, relocation, &howto)))
  1500. {
  1501. const char *name;
  1502. char buf[SYMNMLEN + 1];
  1503. char reloc_type_name[10];
  1504. if (symndx == -1)
  1505. {
  1506. name = "*ABS*";
  1507. }
  1508. else if (h != NULL)
  1509. {
  1510. name = NULL;
  1511. }
  1512. else
  1513. {
  1514. name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
  1515. if (name == NULL)
  1516. name = "UNKNOWN";
  1517. }
  1518. sprintf (reloc_type_name, "0x%02x", rel->r_type);
  1519. (*info->callbacks->reloc_overflow)
  1520. (info, (h ? &h->root : NULL), name, reloc_type_name,
  1521. (bfd_vma) 0, input_bfd, input_section,
  1522. rel->r_vaddr - input_section->vma);
  1523. }
  1524. /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
  1525. value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
  1526. | (((value_to_relocate & howto.src_mask)
  1527. + relocation) & howto.dst_mask));
  1528. /* Put the value back in the object file. */
  1529. if (1 == howto.size)
  1530. bfd_put_16 (input_bfd, value_to_relocate, location);
  1531. else if (2 == howto.size)
  1532. bfd_put_32 (input_bfd, value_to_relocate, location);
  1533. else
  1534. bfd_put_64 (input_bfd, value_to_relocate, location);
  1535. }
  1536. return true;
  1537. }
  1538. /* PR 21786: The PE/COFF standard does not require NUL termination for any of
  1539. the ASCII fields in the archive headers. So in order to be able to extract
  1540. numerical values we provide our own versions of strtol and strtoll which
  1541. take a maximum length as an additional parameter. Also - just to save space,
  1542. we omit the endptr return parameter, since we know that it is never used. */
  1543. static long
  1544. _bfd_strntol (const char * nptr, int base, unsigned int maxlen)
  1545. {
  1546. char buf[24]; /* Should be enough. */
  1547. BFD_ASSERT (maxlen < (sizeof (buf) - 1));
  1548. memcpy (buf, nptr, maxlen);
  1549. buf[maxlen] = 0;
  1550. return strtol (buf, NULL, base);
  1551. }
  1552. static long long
  1553. _bfd_strntoll (const char * nptr, int base, unsigned int maxlen)
  1554. {
  1555. char buf[32]; /* Should be enough. */
  1556. BFD_ASSERT (maxlen < (sizeof (buf) - 1));
  1557. memcpy (buf, nptr, maxlen);
  1558. buf[maxlen] = 0;
  1559. return strtoll (buf, NULL, base);
  1560. }
  1561. /* Macro to read an ASCII value stored in an archive header field. */
  1562. #define GET_VALUE_IN_FIELD(VAR, FIELD, BASE) \
  1563. do \
  1564. { \
  1565. (VAR) = (sizeof (VAR) > sizeof (long) \
  1566. ? _bfd_strntoll (FIELD, BASE, sizeof FIELD) \
  1567. : _bfd_strntol (FIELD, BASE, sizeof FIELD)); \
  1568. } \
  1569. while (0)
  1570. /* Read in the armap of an XCOFF archive. */
  1571. static bool
  1572. xcoff64_slurp_armap (bfd *abfd)
  1573. {
  1574. file_ptr off;
  1575. size_t namlen;
  1576. bfd_size_type sz, amt;
  1577. bfd_byte *contents, *cend;
  1578. bfd_vma c, i;
  1579. carsym *arsym;
  1580. bfd_byte *p;
  1581. file_ptr pos;
  1582. /* This is for the new format. */
  1583. struct xcoff_ar_hdr_big hdr;
  1584. if (xcoff_ardata (abfd) == NULL)
  1585. {
  1586. abfd->has_armap = false;
  1587. return true;
  1588. }
  1589. off = bfd_scan_vma (xcoff_ardata_big (abfd)->symoff64,
  1590. (const char **) NULL, 10);
  1591. if (off == 0)
  1592. {
  1593. abfd->has_armap = false;
  1594. return true;
  1595. }
  1596. if (bfd_seek (abfd, off, SEEK_SET) != 0)
  1597. return false;
  1598. /* The symbol table starts with a normal archive header. */
  1599. if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
  1600. != SIZEOF_AR_HDR_BIG)
  1601. return false;
  1602. /* Skip the name (normally empty). */
  1603. GET_VALUE_IN_FIELD (namlen, hdr.namlen, 10);
  1604. pos = ((namlen + 1) & ~(size_t) 1) + SXCOFFARFMAG;
  1605. if (bfd_seek (abfd, pos, SEEK_CUR) != 0)
  1606. return false;
  1607. sz = bfd_scan_vma (hdr.size, (const char **) NULL, 10);
  1608. if (sz + 1 < 9)
  1609. {
  1610. bfd_set_error (bfd_error_bad_value);
  1611. return false;
  1612. }
  1613. /* Read in the entire symbol table. */
  1614. contents = (bfd_byte *) _bfd_alloc_and_read (abfd, sz + 1, sz);
  1615. if (contents == NULL)
  1616. return false;
  1617. /* Ensure strings are NULL terminated so we don't wander off the end
  1618. of the buffer. */
  1619. contents[sz] = 0;
  1620. /* The symbol table starts with an eight byte count. */
  1621. c = H_GET_64 (abfd, contents);
  1622. if (c >= sz / 8)
  1623. {
  1624. bfd_set_error (bfd_error_bad_value);
  1625. return false;
  1626. }
  1627. amt = c;
  1628. amt *= sizeof (carsym);
  1629. bfd_ardata (abfd)->symdefs = (carsym *) bfd_alloc (abfd, amt);
  1630. if (bfd_ardata (abfd)->symdefs == NULL)
  1631. return false;
  1632. /* After the count comes a list of eight byte file offsets. */
  1633. for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
  1634. i < c;
  1635. ++i, ++arsym, p += 8)
  1636. arsym->file_offset = H_GET_64 (abfd, p);
  1637. /* After the file offsets come null terminated symbol names. */
  1638. cend = contents + sz;
  1639. for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
  1640. i < c;
  1641. ++i, ++arsym, p += strlen ((char *) p) + 1)
  1642. {
  1643. if (p >= cend)
  1644. {
  1645. bfd_set_error (bfd_error_bad_value);
  1646. return false;
  1647. }
  1648. arsym->name = (char *) p;
  1649. }
  1650. bfd_ardata (abfd)->symdef_count = c;
  1651. abfd->has_armap = true;
  1652. return true;
  1653. }
  1654. /* See if this is an NEW XCOFF archive. */
  1655. static bfd_cleanup
  1656. xcoff64_archive_p (bfd *abfd)
  1657. {
  1658. struct artdata *tdata_hold;
  1659. char magic[SXCOFFARMAG];
  1660. /* This is the new format. */
  1661. struct xcoff_ar_file_hdr_big hdr;
  1662. size_t amt = SXCOFFARMAG;
  1663. if (bfd_bread (magic, amt, abfd) != amt)
  1664. {
  1665. if (bfd_get_error () != bfd_error_system_call)
  1666. bfd_set_error (bfd_error_wrong_format);
  1667. return NULL;
  1668. }
  1669. if (strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
  1670. {
  1671. bfd_set_error (bfd_error_wrong_format);
  1672. return NULL;
  1673. }
  1674. /* Copy over the magic string. */
  1675. memcpy (hdr.magic, magic, SXCOFFARMAG);
  1676. /* Now read the rest of the file header. */
  1677. amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
  1678. if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
  1679. {
  1680. if (bfd_get_error () != bfd_error_system_call)
  1681. bfd_set_error (bfd_error_wrong_format);
  1682. return NULL;
  1683. }
  1684. tdata_hold = bfd_ardata (abfd);
  1685. amt = sizeof (struct artdata);
  1686. bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
  1687. if (bfd_ardata (abfd) == (struct artdata *) NULL)
  1688. goto error_ret_restore;
  1689. /* Already cleared by bfd_zalloc above.
  1690. bfd_ardata (abfd)->cache = NULL;
  1691. bfd_ardata (abfd)->archive_head = NULL;
  1692. bfd_ardata (abfd)->symdefs = NULL;
  1693. bfd_ardata (abfd)->extended_names = NULL;
  1694. bfd_ardata (abfd)->extended_names_size = 0; */
  1695. bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
  1696. (const char **) NULL,
  1697. 10);
  1698. amt = SIZEOF_AR_FILE_HDR_BIG;
  1699. bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
  1700. if (bfd_ardata (abfd)->tdata == NULL)
  1701. goto error_ret;
  1702. memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
  1703. if (! xcoff64_slurp_armap (abfd))
  1704. {
  1705. error_ret:
  1706. bfd_release (abfd, bfd_ardata (abfd));
  1707. error_ret_restore:
  1708. bfd_ardata (abfd) = tdata_hold;
  1709. return NULL;
  1710. }
  1711. return _bfd_no_cleanup;
  1712. }
  1713. /* Open the next element in an XCOFF archive. */
  1714. static bfd *
  1715. xcoff64_openr_next_archived_file (bfd *archive, bfd *last_file)
  1716. {
  1717. if ((xcoff_ardata (archive) == NULL)
  1718. || ! xcoff_big_format_p (archive))
  1719. {
  1720. bfd_set_error (bfd_error_invalid_operation);
  1721. return NULL;
  1722. }
  1723. return _bfd_xcoff_openr_next_archived_file (archive, last_file);
  1724. }
  1725. /* We can't use the usual coff_sizeof_headers routine, because AIX
  1726. always uses an a.out header. */
  1727. static int
  1728. xcoff64_sizeof_headers (bfd *abfd,
  1729. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  1730. {
  1731. int size;
  1732. size = bfd_coff_filhsz (abfd);
  1733. /* Don't think the small aout header can be used since some of the
  1734. old elements have been reordered past the end of the old coff
  1735. small aout size. */
  1736. if (xcoff_data (abfd)->full_aouthdr)
  1737. size += bfd_coff_aoutsz (abfd);
  1738. size += abfd->section_count * bfd_coff_scnhsz (abfd);
  1739. return size;
  1740. }
  1741. static asection *
  1742. xcoff64_create_csect_from_smclas (bfd *abfd, union internal_auxent *aux,
  1743. const char *symbol_name)
  1744. {
  1745. asection *return_value = NULL;
  1746. /* Changes from 32 :
  1747. .sv == 8, is only for 32 bit programs
  1748. .ti == 12 and .tb == 13 are now reserved. */
  1749. static const char * const names[] =
  1750. {
  1751. ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
  1752. NULL, ".bs", ".ds", ".uc", NULL, NULL, NULL, ".tc0",
  1753. ".td", ".sv64", ".sv3264", NULL, ".tl", ".ul", ".te"
  1754. };
  1755. if ((aux->x_csect.x_smclas < ARRAY_SIZE (names))
  1756. && (NULL != names[aux->x_csect.x_smclas]))
  1757. {
  1758. return_value = bfd_make_section_anyway
  1759. (abfd, names[aux->x_csect.x_smclas]);
  1760. }
  1761. else
  1762. {
  1763. _bfd_error_handler
  1764. /* xgettext: c-format */
  1765. (_("%pB: symbol `%s' has unrecognized smclas %d"),
  1766. abfd, symbol_name, aux->x_csect.x_smclas);
  1767. bfd_set_error (bfd_error_bad_value);
  1768. }
  1769. return return_value;
  1770. }
  1771. static bool
  1772. xcoff64_is_lineno_count_overflow (bfd *abfd ATTRIBUTE_UNUSED,
  1773. bfd_vma value ATTRIBUTE_UNUSED)
  1774. {
  1775. return false;
  1776. }
  1777. static bool
  1778. xcoff64_is_reloc_count_overflow (bfd *abfd ATTRIBUTE_UNUSED,
  1779. bfd_vma value ATTRIBUTE_UNUSED)
  1780. {
  1781. return false;
  1782. }
  1783. static bfd_vma
  1784. xcoff64_loader_symbol_offset (bfd *abfd ATTRIBUTE_UNUSED,
  1785. struct internal_ldhdr *ldhdr)
  1786. {
  1787. return (ldhdr->l_symoff);
  1788. }
  1789. static bfd_vma
  1790. xcoff64_loader_reloc_offset (bfd *abfd ATTRIBUTE_UNUSED,
  1791. struct internal_ldhdr *ldhdr)
  1792. {
  1793. return (ldhdr->l_rldoff);
  1794. }
  1795. static bool
  1796. xcoff64_bad_format_hook (bfd * abfd, void *filehdr)
  1797. {
  1798. struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  1799. /* Check flavor first. */
  1800. if (bfd_get_flavour (abfd) != bfd_target_xcoff_flavour)
  1801. return false;
  1802. if (bfd_xcoff_magic_number (abfd) != internal_f->f_magic)
  1803. return false;
  1804. return true;
  1805. }
  1806. static bool
  1807. xcoff64_generate_rtinit (bfd *abfd, const char *init, const char *fini,
  1808. bool rtld)
  1809. {
  1810. bfd_byte filehdr_ext[FILHSZ];
  1811. bfd_byte scnhdr_ext[SCNHSZ * 3];
  1812. bfd_byte syment_ext[SYMESZ * 10];
  1813. bfd_byte reloc_ext[RELSZ * 3];
  1814. bfd_byte *data_buffer;
  1815. bfd_size_type data_buffer_size;
  1816. bfd_byte *string_table, *st_tmp;
  1817. bfd_size_type string_table_size;
  1818. bfd_vma val;
  1819. size_t initsz, finisz;
  1820. struct internal_filehdr filehdr;
  1821. struct internal_scnhdr text_scnhdr;
  1822. struct internal_scnhdr data_scnhdr;
  1823. struct internal_scnhdr bss_scnhdr;
  1824. struct internal_syment syment;
  1825. union internal_auxent auxent;
  1826. struct internal_reloc reloc;
  1827. char *text_name = ".text";
  1828. char *data_name = ".data";
  1829. char *bss_name = ".bss";
  1830. char *rtinit_name = "__rtinit";
  1831. char *rtld_name = "__rtld";
  1832. if (! bfd_xcoff_rtinit_size (abfd))
  1833. return false;
  1834. initsz = (init == NULL ? 0 : 1 + strlen (init));
  1835. finisz = (fini == NULL ? 0 : 1 + strlen (fini));
  1836. /* File header. */
  1837. memset (filehdr_ext, 0, FILHSZ);
  1838. memset (&filehdr, 0, sizeof (struct internal_filehdr));
  1839. filehdr.f_magic = bfd_xcoff_magic_number (abfd);
  1840. filehdr.f_nscns = 3;
  1841. filehdr.f_timdat = 0;
  1842. filehdr.f_nsyms = 0; /* at least 6, no more than 8 */
  1843. filehdr.f_symptr = 0; /* set below */
  1844. filehdr.f_opthdr = 0;
  1845. filehdr.f_flags = 0;
  1846. /* Section headers. */
  1847. memset (scnhdr_ext, 0, 3 * SCNHSZ);
  1848. /* Text. */
  1849. memset (&text_scnhdr, 0, sizeof (struct internal_scnhdr));
  1850. memcpy (text_scnhdr.s_name, text_name, strlen (text_name));
  1851. text_scnhdr.s_paddr = 0;
  1852. text_scnhdr.s_vaddr = 0;
  1853. text_scnhdr.s_size = 0;
  1854. text_scnhdr.s_scnptr = 0;
  1855. text_scnhdr.s_relptr = 0;
  1856. text_scnhdr.s_lnnoptr = 0;
  1857. text_scnhdr.s_nreloc = 0;
  1858. text_scnhdr.s_nlnno = 0;
  1859. text_scnhdr.s_flags = STYP_TEXT;
  1860. /* Data. */
  1861. memset (&data_scnhdr, 0, sizeof (struct internal_scnhdr));
  1862. memcpy (data_scnhdr.s_name, data_name, strlen (data_name));
  1863. data_scnhdr.s_paddr = 0;
  1864. data_scnhdr.s_vaddr = 0;
  1865. data_scnhdr.s_size = 0; /* set below */
  1866. data_scnhdr.s_scnptr = FILHSZ + 3 * SCNHSZ;
  1867. data_scnhdr.s_relptr = 0; /* set below */
  1868. data_scnhdr.s_lnnoptr = 0;
  1869. data_scnhdr.s_nreloc = 0; /* either 1 or 2 */
  1870. data_scnhdr.s_nlnno = 0;
  1871. data_scnhdr.s_flags = STYP_DATA;
  1872. /* Bss. */
  1873. memset (&bss_scnhdr, 0, sizeof (struct internal_scnhdr));
  1874. memcpy (bss_scnhdr.s_name, bss_name, strlen (bss_name));
  1875. bss_scnhdr.s_paddr = 0; /* set below */
  1876. bss_scnhdr.s_vaddr = 0; /* set below */
  1877. bss_scnhdr.s_size = 0; /* set below */
  1878. bss_scnhdr.s_scnptr = 0;
  1879. bss_scnhdr.s_relptr = 0;
  1880. bss_scnhdr.s_lnnoptr = 0;
  1881. bss_scnhdr.s_nreloc = 0;
  1882. bss_scnhdr.s_nlnno = 0;
  1883. bss_scnhdr.s_flags = STYP_BSS;
  1884. /* .data
  1885. 0x0000 0x00000000 : rtl
  1886. 0x0004 0x00000000 :
  1887. 0x0008 0x00000018 : offset to init, or 0
  1888. 0x000C 0x00000038 : offset to fini, or 0
  1889. 0x0010 0x00000010 : size of descriptor
  1890. 0x0014 0x00000000 : pad
  1891. 0x0018 0x00000000 : init, needs a reloc
  1892. 0x001C 0x00000000 :
  1893. 0x0020 0x00000058 : offset to init name
  1894. 0x0024 0x00000000 : flags, padded to a word
  1895. 0x0028 0x00000000 : empty init
  1896. 0x002C 0x00000000 :
  1897. 0x0030 0x00000000 :
  1898. 0x0034 0x00000000 :
  1899. 0x0038 0x00000000 : fini, needs a reloc
  1900. 0x003C 0x00000000 :
  1901. 0x0040 0x00000??? : offset to fini name
  1902. 0x0044 0x00000000 : flags, padded to a word
  1903. 0x0048 0x00000000 : empty fini
  1904. 0x004C 0x00000000 :
  1905. 0x0050 0x00000000 :
  1906. 0x0054 0x00000000 :
  1907. 0x0058 init name
  1908. 0x0058 + initsz fini name */
  1909. data_buffer_size = 0x0058 + initsz + finisz;
  1910. data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
  1911. data_buffer = NULL;
  1912. data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
  1913. if (data_buffer == NULL)
  1914. return false;
  1915. if (initsz)
  1916. {
  1917. val = 0x18;
  1918. bfd_put_32 (abfd, val, &data_buffer[0x08]);
  1919. val = 0x58;
  1920. bfd_put_32 (abfd, val, &data_buffer[0x20]);
  1921. memcpy (&data_buffer[val], init, initsz);
  1922. }
  1923. if (finisz)
  1924. {
  1925. val = 0x38;
  1926. bfd_put_32 (abfd, val, &data_buffer[0x0C]);
  1927. val = 0x58 + initsz;
  1928. bfd_put_32 (abfd, val, &data_buffer[0x40]);
  1929. memcpy (&data_buffer[val], fini, finisz);
  1930. }
  1931. val = 0x10;
  1932. bfd_put_32 (abfd, val, &data_buffer[0x10]);
  1933. data_scnhdr.s_size = data_buffer_size;
  1934. bss_scnhdr.s_paddr = bss_scnhdr.s_vaddr = data_scnhdr.s_size;
  1935. /* String table. */
  1936. string_table_size = 4;
  1937. string_table_size += strlen (data_name) + 1;
  1938. string_table_size += strlen (rtinit_name) + 1;
  1939. string_table_size += initsz;
  1940. string_table_size += finisz;
  1941. if (rtld)
  1942. string_table_size += strlen (rtld_name) + 1;
  1943. string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
  1944. if (string_table == NULL)
  1945. return false;
  1946. val = string_table_size;
  1947. bfd_put_32 (abfd, val, &string_table[0]);
  1948. st_tmp = string_table + 4;
  1949. /* symbols
  1950. 0. .data csect
  1951. 2. __rtinit
  1952. 4. init function
  1953. 6. fini function
  1954. 8. __rtld */
  1955. memset (syment_ext, 0, 10 * SYMESZ);
  1956. memset (reloc_ext, 0, 3 * RELSZ);
  1957. /* .data csect */
  1958. memset (&syment, 0, sizeof (struct internal_syment));
  1959. memset (&auxent, 0, sizeof (union internal_auxent));
  1960. syment._n._n_n._n_offset = st_tmp - string_table;
  1961. memcpy (st_tmp, data_name, strlen (data_name));
  1962. st_tmp += strlen (data_name) + 1;
  1963. syment.n_scnum = 2;
  1964. syment.n_sclass = C_HIDEXT;
  1965. syment.n_numaux = 1;
  1966. auxent.x_csect.x_scnlen.l = data_buffer_size;
  1967. auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
  1968. auxent.x_csect.x_smclas = XMC_RW;
  1969. bfd_coff_swap_sym_out (abfd, &syment,
  1970. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  1971. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  1972. syment.n_numaux,
  1973. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  1974. filehdr.f_nsyms += 2;
  1975. /* __rtinit */
  1976. memset (&syment, 0, sizeof (struct internal_syment));
  1977. memset (&auxent, 0, sizeof (union internal_auxent));
  1978. syment._n._n_n._n_offset = st_tmp - string_table;
  1979. memcpy (st_tmp, rtinit_name, strlen (rtinit_name));
  1980. st_tmp += strlen (rtinit_name) + 1;
  1981. syment.n_scnum = 2;
  1982. syment.n_sclass = C_EXT;
  1983. syment.n_numaux = 1;
  1984. auxent.x_csect.x_smtyp = XTY_LD;
  1985. auxent.x_csect.x_smclas = XMC_RW;
  1986. bfd_coff_swap_sym_out (abfd, &syment,
  1987. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  1988. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  1989. syment.n_numaux,
  1990. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  1991. filehdr.f_nsyms += 2;
  1992. /* Init. */
  1993. if (initsz)
  1994. {
  1995. memset (&syment, 0, sizeof (struct internal_syment));
  1996. memset (&auxent, 0, sizeof (union internal_auxent));
  1997. syment._n._n_n._n_offset = st_tmp - string_table;
  1998. memcpy (st_tmp, init, initsz);
  1999. st_tmp += initsz;
  2000. syment.n_sclass = C_EXT;
  2001. syment.n_numaux = 1;
  2002. bfd_coff_swap_sym_out (abfd, &syment,
  2003. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  2004. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  2005. syment.n_numaux,
  2006. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  2007. /* Reloc. */
  2008. memset (&reloc, 0, sizeof (struct internal_reloc));
  2009. reloc.r_vaddr = 0x0018;
  2010. reloc.r_symndx = filehdr.f_nsyms;
  2011. reloc.r_type = R_POS;
  2012. reloc.r_size = 63;
  2013. bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
  2014. filehdr.f_nsyms += 2;
  2015. data_scnhdr.s_nreloc += 1;
  2016. }
  2017. /* Finit. */
  2018. if (finisz)
  2019. {
  2020. memset (&syment, 0, sizeof (struct internal_syment));
  2021. memset (&auxent, 0, sizeof (union internal_auxent));
  2022. syment._n._n_n._n_offset = st_tmp - string_table;
  2023. memcpy (st_tmp, fini, finisz);
  2024. st_tmp += finisz;
  2025. syment.n_sclass = C_EXT;
  2026. syment.n_numaux = 1;
  2027. bfd_coff_swap_sym_out (abfd, &syment,
  2028. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  2029. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  2030. syment.n_numaux,
  2031. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  2032. /* Reloc. */
  2033. memset (&reloc, 0, sizeof (struct internal_reloc));
  2034. reloc.r_vaddr = 0x0038;
  2035. reloc.r_symndx = filehdr.f_nsyms;
  2036. reloc.r_type = R_POS;
  2037. reloc.r_size = 63;
  2038. bfd_coff_swap_reloc_out (abfd, &reloc,
  2039. &reloc_ext[data_scnhdr.s_nreloc * RELSZ]);
  2040. filehdr.f_nsyms += 2;
  2041. data_scnhdr.s_nreloc += 1;
  2042. }
  2043. if (rtld)
  2044. {
  2045. memset (&syment, 0, sizeof (struct internal_syment));
  2046. memset (&auxent, 0, sizeof (union internal_auxent));
  2047. syment._n._n_n._n_offset = st_tmp - string_table;
  2048. memcpy (st_tmp, rtld_name, strlen (rtld_name));
  2049. st_tmp += strlen (rtld_name) + 1;
  2050. syment.n_sclass = C_EXT;
  2051. syment.n_numaux = 1;
  2052. bfd_coff_swap_sym_out (abfd, &syment,
  2053. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  2054. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  2055. syment.n_numaux,
  2056. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  2057. /* Reloc. */
  2058. memset (&reloc, 0, sizeof (struct internal_reloc));
  2059. reloc.r_vaddr = 0x0000;
  2060. reloc.r_symndx = filehdr.f_nsyms;
  2061. reloc.r_type = R_POS;
  2062. reloc.r_size = 63;
  2063. bfd_coff_swap_reloc_out (abfd, &reloc,
  2064. &reloc_ext[data_scnhdr.s_nreloc * RELSZ]);
  2065. filehdr.f_nsyms += 2;
  2066. data_scnhdr.s_nreloc += 1;
  2067. bss_scnhdr.s_size = 0;
  2068. }
  2069. data_scnhdr.s_relptr = data_scnhdr.s_scnptr + data_buffer_size;
  2070. filehdr.f_symptr = data_scnhdr.s_relptr + data_scnhdr.s_nreloc * RELSZ;
  2071. bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
  2072. bfd_bwrite (filehdr_ext, FILHSZ, abfd);
  2073. bfd_coff_swap_scnhdr_out (abfd, &text_scnhdr, &scnhdr_ext[SCNHSZ * 0]);
  2074. bfd_coff_swap_scnhdr_out (abfd, &data_scnhdr, &scnhdr_ext[SCNHSZ * 1]);
  2075. bfd_coff_swap_scnhdr_out (abfd, &bss_scnhdr, &scnhdr_ext[SCNHSZ * 2]);
  2076. bfd_bwrite (scnhdr_ext, 3 * SCNHSZ, abfd);
  2077. bfd_bwrite (data_buffer, data_buffer_size, abfd);
  2078. bfd_bwrite (reloc_ext, data_scnhdr.s_nreloc * RELSZ, abfd);
  2079. bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
  2080. bfd_bwrite (string_table, string_table_size, abfd);
  2081. free (data_buffer);
  2082. data_buffer = NULL;
  2083. return true;
  2084. }
  2085. /* The typical dynamic reloc. */
  2086. static reloc_howto_type xcoff64_dynamic_reloc =
  2087. HOWTO (0, /* type */
  2088. 0, /* rightshift */
  2089. 4, /* size (0 = byte, 1 = short, 2 = long) */
  2090. 64, /* bitsize */
  2091. false, /* pc_relative */
  2092. 0, /* bitpos */
  2093. complain_overflow_bitfield, /* complain_on_overflow */
  2094. 0, /* special_function */
  2095. "R_POS", /* name */
  2096. true, /* partial_inplace */
  2097. MINUS_ONE, /* src_mask */
  2098. MINUS_ONE, /* dst_mask */
  2099. false); /* pcrel_offset */
  2100. static const unsigned long xcoff64_glink_code[10] =
  2101. {
  2102. 0xe9820000, /* ld r12,0(r2) */
  2103. 0xf8410028, /* std r2,40(r1) */
  2104. 0xe80c0000, /* ld r0,0(r12) */
  2105. 0xe84c0008, /* ld r0,8(r12) */
  2106. 0x7c0903a6, /* mtctr r0 */
  2107. 0x4e800420, /* bctr */
  2108. 0x00000000, /* start of traceback table */
  2109. 0x000ca000, /* traceback table */
  2110. 0x00000000, /* traceback table */
  2111. 0x00000018, /* ??? */
  2112. };
  2113. static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
  2114. {
  2115. { /* COFF backend, defined in libcoff.h. */
  2116. _bfd_xcoff64_swap_aux_in,
  2117. _bfd_xcoff64_swap_sym_in,
  2118. _bfd_xcoff64_swap_lineno_in,
  2119. _bfd_xcoff64_swap_aux_out,
  2120. _bfd_xcoff64_swap_sym_out,
  2121. _bfd_xcoff64_swap_lineno_out,
  2122. xcoff64_swap_reloc_out,
  2123. coff_swap_filehdr_out,
  2124. coff_swap_aouthdr_out,
  2125. coff_swap_scnhdr_out,
  2126. FILHSZ,
  2127. AOUTSZ,
  2128. SCNHSZ,
  2129. SYMESZ,
  2130. AUXESZ,
  2131. RELSZ,
  2132. LINESZ,
  2133. FILNMLEN,
  2134. true, /* _bfd_coff_long_filenames */
  2135. XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
  2136. 3, /* _bfd_coff_default_section_alignment_power */
  2137. true, /* _bfd_coff_force_symnames_in_strings */
  2138. 4, /* _bfd_coff_debug_string_prefix_length */
  2139. 32768, /* _bfd_coff_max_nscns */
  2140. coff_swap_filehdr_in,
  2141. coff_swap_aouthdr_in,
  2142. coff_swap_scnhdr_in,
  2143. xcoff64_swap_reloc_in,
  2144. xcoff64_bad_format_hook,
  2145. coff_set_arch_mach_hook,
  2146. coff_mkobject_hook,
  2147. styp_to_sec_flags,
  2148. coff_set_alignment_hook,
  2149. coff_slurp_symbol_table,
  2150. symname_in_debug_hook,
  2151. coff_pointerize_aux_hook,
  2152. coff_print_aux,
  2153. dummy_reloc16_extra_cases,
  2154. dummy_reloc16_estimate,
  2155. NULL, /* bfd_coff_symbol_classification */
  2156. coff_compute_section_file_positions,
  2157. NULL, /* _bfd_coff_start_final_link */
  2158. xcoff64_ppc_relocate_section,
  2159. coff_rtype_to_howto,
  2160. NULL, /* _bfd_coff_adjust_symndx */
  2161. _bfd_generic_link_add_one_symbol,
  2162. coff_link_output_has_begun,
  2163. coff_final_link_postscript,
  2164. NULL /* print_pdata. */
  2165. },
  2166. 0x01EF, /* magic number */
  2167. bfd_arch_powerpc,
  2168. bfd_mach_ppc_620,
  2169. /* Function pointers to xcoff specific swap routines. */
  2170. xcoff64_swap_ldhdr_in,
  2171. xcoff64_swap_ldhdr_out,
  2172. xcoff64_swap_ldsym_in,
  2173. xcoff64_swap_ldsym_out,
  2174. xcoff64_swap_ldrel_in,
  2175. xcoff64_swap_ldrel_out,
  2176. /* Sizes. */
  2177. LDHDRSZ,
  2178. LDSYMSZ,
  2179. LDRELSZ,
  2180. 24, /* _xcoff_function_descriptor_size */
  2181. 0, /* _xcoff_small_aout_header_size */
  2182. /* Versions. */
  2183. 2, /* _xcoff_ldhdr_version */
  2184. _bfd_xcoff64_put_symbol_name,
  2185. _bfd_xcoff64_put_ldsymbol_name,
  2186. &xcoff64_dynamic_reloc,
  2187. xcoff64_create_csect_from_smclas,
  2188. /* Lineno and reloc count overflow. */
  2189. xcoff64_is_lineno_count_overflow,
  2190. xcoff64_is_reloc_count_overflow,
  2191. xcoff64_loader_symbol_offset,
  2192. xcoff64_loader_reloc_offset,
  2193. /* glink. */
  2194. &xcoff64_glink_code[0],
  2195. 40, /* _xcoff_glink_size */
  2196. /* rtinit. */
  2197. 88, /* _xcoff_rtinit_size */
  2198. xcoff64_generate_rtinit,
  2199. };
  2200. /* The transfer vector that leads the outside world to all of the above. */
  2201. const bfd_target rs6000_xcoff64_vec =
  2202. {
  2203. "aixcoff64-rs6000",
  2204. bfd_target_xcoff_flavour,
  2205. BFD_ENDIAN_BIG, /* data byte order is big */
  2206. BFD_ENDIAN_BIG, /* header byte order is big */
  2207. (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
  2208. | HAS_SYMS | HAS_LOCALS | WP_TEXT),
  2209. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
  2210. 0, /* leading char */
  2211. '/', /* ar_pad_char */
  2212. 15, /* ar_max_namelen */
  2213. 0, /* match priority. */
  2214. TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
  2215. /* data */
  2216. bfd_getb64,
  2217. bfd_getb_signed_64,
  2218. bfd_putb64,
  2219. bfd_getb32,
  2220. bfd_getb_signed_32,
  2221. bfd_putb32,
  2222. bfd_getb16,
  2223. bfd_getb_signed_16,
  2224. bfd_putb16,
  2225. /* hdrs */
  2226. bfd_getb64,
  2227. bfd_getb_signed_64,
  2228. bfd_putb64,
  2229. bfd_getb32,
  2230. bfd_getb_signed_32,
  2231. bfd_putb32,
  2232. bfd_getb16,
  2233. bfd_getb_signed_16,
  2234. bfd_putb16,
  2235. { /* bfd_check_format */
  2236. _bfd_dummy_target,
  2237. coff_object_p,
  2238. xcoff64_archive_p,
  2239. CORE_FILE_P
  2240. },
  2241. { /* bfd_set_format */
  2242. _bfd_bool_bfd_false_error,
  2243. coff_mkobject,
  2244. _bfd_generic_mkarchive,
  2245. _bfd_bool_bfd_false_error
  2246. },
  2247. {/* bfd_write_contents */
  2248. _bfd_bool_bfd_false_error,
  2249. coff_write_object_contents,
  2250. _bfd_xcoff_write_archive_contents,
  2251. _bfd_bool_bfd_false_error
  2252. },
  2253. /* Generic */
  2254. _bfd_archive_close_and_cleanup,
  2255. _bfd_bool_bfd_true,
  2256. coff_new_section_hook,
  2257. _bfd_generic_get_section_contents,
  2258. _bfd_generic_get_section_contents_in_window,
  2259. /* Copy */
  2260. _bfd_xcoff_copy_private_bfd_data,
  2261. _bfd_generic_bfd_merge_private_bfd_data,
  2262. _bfd_generic_init_private_section_data,
  2263. _bfd_generic_bfd_copy_private_section_data,
  2264. _bfd_generic_bfd_copy_private_symbol_data,
  2265. _bfd_generic_bfd_copy_private_header_data,
  2266. _bfd_generic_bfd_set_private_flags,
  2267. _bfd_generic_bfd_print_private_bfd_data,
  2268. /* Core */
  2269. BFD_JUMP_TABLE_CORE (coff),
  2270. /* Archive */
  2271. xcoff64_slurp_armap,
  2272. _bfd_noarchive_slurp_extended_name_table,
  2273. _bfd_noarchive_construct_extended_name_table,
  2274. bfd_dont_truncate_arname,
  2275. _bfd_xcoff_write_armap,
  2276. _bfd_xcoff_read_ar_hdr,
  2277. _bfd_generic_write_ar_hdr,
  2278. xcoff64_openr_next_archived_file,
  2279. _bfd_generic_get_elt_at_index,
  2280. _bfd_xcoff_stat_arch_elt,
  2281. _bfd_bool_bfd_true,
  2282. /* Symbols */
  2283. coff_get_symtab_upper_bound,
  2284. coff_canonicalize_symtab,
  2285. coff_make_empty_symbol,
  2286. coff_print_symbol,
  2287. coff_get_symbol_info,
  2288. coff_get_symbol_version_string,
  2289. _bfd_xcoff_is_local_label_name,
  2290. coff_bfd_is_target_special_symbol,
  2291. coff_get_lineno,
  2292. coff_find_nearest_line,
  2293. coff_find_line,
  2294. coff_find_inliner_info,
  2295. coff_bfd_make_debug_symbol,
  2296. _bfd_generic_read_minisymbols,
  2297. _bfd_generic_minisymbol_to_symbol,
  2298. /* Reloc */
  2299. coff_get_reloc_upper_bound,
  2300. coff_canonicalize_reloc,
  2301. _bfd_generic_set_reloc,
  2302. xcoff64_reloc_type_lookup,
  2303. xcoff64_reloc_name_lookup,
  2304. /* Write */
  2305. coff_set_arch_mach,
  2306. coff_set_section_contents,
  2307. /* Link */
  2308. xcoff64_sizeof_headers,
  2309. bfd_generic_get_relocated_section_contents,
  2310. bfd_generic_relax_section,
  2311. _bfd_xcoff_bfd_link_hash_table_create,
  2312. _bfd_xcoff_bfd_link_add_symbols,
  2313. _bfd_generic_link_just_syms,
  2314. _bfd_generic_copy_link_hash_symbol_type,
  2315. _bfd_xcoff_bfd_final_link,
  2316. _bfd_generic_link_split_section,
  2317. _bfd_generic_link_check_relocs,
  2318. bfd_generic_gc_sections,
  2319. bfd_generic_lookup_section_flags,
  2320. bfd_generic_merge_sections,
  2321. bfd_generic_is_group_section,
  2322. bfd_generic_group_name,
  2323. bfd_generic_discard_group,
  2324. _bfd_generic_section_already_linked,
  2325. _bfd_xcoff_define_common_symbol,
  2326. _bfd_generic_link_hide_symbol,
  2327. bfd_generic_define_start_stop,
  2328. /* Dynamic */
  2329. _bfd_xcoff_get_dynamic_symtab_upper_bound,
  2330. _bfd_xcoff_canonicalize_dynamic_symtab,
  2331. _bfd_nodynamic_get_synthetic_symtab,
  2332. _bfd_xcoff_get_dynamic_reloc_upper_bound,
  2333. _bfd_xcoff_canonicalize_dynamic_reloc,
  2334. /* Opposite endian version, none exists */
  2335. NULL,
  2336. &bfd_xcoff_backend_data,
  2337. };
  2338. extern bfd_cleanup xcoff64_core_p
  2339. (bfd *);
  2340. extern bool xcoff64_core_file_matches_executable_p
  2341. (bfd *, bfd *);
  2342. extern char *xcoff64_core_file_failing_command
  2343. (bfd *);
  2344. extern int xcoff64_core_file_failing_signal
  2345. (bfd *);
  2346. #define xcoff64_core_file_pid _bfd_nocore_core_file_pid
  2347. /* AIX 5 */
  2348. static const struct xcoff_backend_data_rec bfd_xcoff_aix5_backend_data =
  2349. {
  2350. { /* COFF backend, defined in libcoff.h. */
  2351. _bfd_xcoff64_swap_aux_in,
  2352. _bfd_xcoff64_swap_sym_in,
  2353. _bfd_xcoff64_swap_lineno_in,
  2354. _bfd_xcoff64_swap_aux_out,
  2355. _bfd_xcoff64_swap_sym_out,
  2356. _bfd_xcoff64_swap_lineno_out,
  2357. xcoff64_swap_reloc_out,
  2358. coff_swap_filehdr_out,
  2359. coff_swap_aouthdr_out,
  2360. coff_swap_scnhdr_out,
  2361. FILHSZ,
  2362. AOUTSZ,
  2363. SCNHSZ,
  2364. SYMESZ,
  2365. AUXESZ,
  2366. RELSZ,
  2367. LINESZ,
  2368. FILNMLEN,
  2369. true, /* _bfd_coff_long_filenames */
  2370. XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
  2371. 3, /* _bfd_coff_default_section_alignment_power */
  2372. true, /* _bfd_coff_force_symnames_in_strings */
  2373. 4, /* _bfd_coff_debug_string_prefix_length */
  2374. 32768, /* _bfd_coff_max_nscns */
  2375. coff_swap_filehdr_in,
  2376. coff_swap_aouthdr_in,
  2377. coff_swap_scnhdr_in,
  2378. xcoff64_swap_reloc_in,
  2379. xcoff64_bad_format_hook,
  2380. coff_set_arch_mach_hook,
  2381. coff_mkobject_hook,
  2382. styp_to_sec_flags,
  2383. coff_set_alignment_hook,
  2384. coff_slurp_symbol_table,
  2385. symname_in_debug_hook,
  2386. coff_pointerize_aux_hook,
  2387. coff_print_aux,
  2388. dummy_reloc16_extra_cases,
  2389. dummy_reloc16_estimate,
  2390. NULL, /* bfd_coff_sym_is_global */
  2391. coff_compute_section_file_positions,
  2392. NULL, /* _bfd_coff_start_final_link */
  2393. xcoff64_ppc_relocate_section,
  2394. coff_rtype_to_howto,
  2395. NULL, /* _bfd_coff_adjust_symndx */
  2396. _bfd_generic_link_add_one_symbol,
  2397. coff_link_output_has_begun,
  2398. coff_final_link_postscript,
  2399. NULL /* print_pdata. */
  2400. },
  2401. U64_TOCMAGIC, /* magic number */
  2402. bfd_arch_powerpc,
  2403. bfd_mach_ppc_620,
  2404. /* Function pointers to xcoff specific swap routines. */
  2405. xcoff64_swap_ldhdr_in,
  2406. xcoff64_swap_ldhdr_out,
  2407. xcoff64_swap_ldsym_in,
  2408. xcoff64_swap_ldsym_out,
  2409. xcoff64_swap_ldrel_in,
  2410. xcoff64_swap_ldrel_out,
  2411. /* Sizes. */
  2412. LDHDRSZ,
  2413. LDSYMSZ,
  2414. LDRELSZ,
  2415. 24, /* _xcoff_function_descriptor_size */
  2416. 0, /* _xcoff_small_aout_header_size */
  2417. /* Versions. */
  2418. 2, /* _xcoff_ldhdr_version */
  2419. _bfd_xcoff64_put_symbol_name,
  2420. _bfd_xcoff64_put_ldsymbol_name,
  2421. &xcoff64_dynamic_reloc,
  2422. xcoff64_create_csect_from_smclas,
  2423. /* Lineno and reloc count overflow. */
  2424. xcoff64_is_lineno_count_overflow,
  2425. xcoff64_is_reloc_count_overflow,
  2426. xcoff64_loader_symbol_offset,
  2427. xcoff64_loader_reloc_offset,
  2428. /* glink. */
  2429. &xcoff64_glink_code[0],
  2430. 40, /* _xcoff_glink_size */
  2431. /* rtinit. */
  2432. 88, /* _xcoff_rtinit_size */
  2433. xcoff64_generate_rtinit,
  2434. };
  2435. /* The transfer vector that leads the outside world to all of the above. */
  2436. const bfd_target rs6000_xcoff64_aix_vec =
  2437. {
  2438. "aix5coff64-rs6000",
  2439. bfd_target_xcoff_flavour,
  2440. BFD_ENDIAN_BIG, /* data byte order is big */
  2441. BFD_ENDIAN_BIG, /* header byte order is big */
  2442. (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
  2443. | HAS_SYMS | HAS_LOCALS | WP_TEXT),
  2444. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
  2445. 0, /* leading char */
  2446. '/', /* ar_pad_char */
  2447. 15, /* ar_max_namelen */
  2448. 0, /* match priority. */
  2449. TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
  2450. /* data */
  2451. bfd_getb64,
  2452. bfd_getb_signed_64,
  2453. bfd_putb64,
  2454. bfd_getb32,
  2455. bfd_getb_signed_32,
  2456. bfd_putb32,
  2457. bfd_getb16,
  2458. bfd_getb_signed_16,
  2459. bfd_putb16,
  2460. /* hdrs */
  2461. bfd_getb64,
  2462. bfd_getb_signed_64,
  2463. bfd_putb64,
  2464. bfd_getb32,
  2465. bfd_getb_signed_32,
  2466. bfd_putb32,
  2467. bfd_getb16,
  2468. bfd_getb_signed_16,
  2469. bfd_putb16,
  2470. { /* bfd_check_format */
  2471. _bfd_dummy_target,
  2472. coff_object_p,
  2473. xcoff64_archive_p,
  2474. xcoff64_core_p
  2475. },
  2476. { /* bfd_set_format */
  2477. _bfd_bool_bfd_false_error,
  2478. coff_mkobject,
  2479. _bfd_generic_mkarchive,
  2480. _bfd_bool_bfd_false_error
  2481. },
  2482. {/* bfd_write_contents */
  2483. _bfd_bool_bfd_false_error,
  2484. coff_write_object_contents,
  2485. _bfd_xcoff_write_archive_contents,
  2486. _bfd_bool_bfd_false_error
  2487. },
  2488. /* Generic */
  2489. _bfd_archive_close_and_cleanup,
  2490. _bfd_bool_bfd_true,
  2491. coff_new_section_hook,
  2492. _bfd_generic_get_section_contents,
  2493. _bfd_generic_get_section_contents_in_window,
  2494. /* Copy */
  2495. _bfd_xcoff_copy_private_bfd_data,
  2496. _bfd_generic_bfd_merge_private_bfd_data,
  2497. _bfd_generic_init_private_section_data,
  2498. _bfd_generic_bfd_copy_private_section_data,
  2499. _bfd_generic_bfd_copy_private_symbol_data,
  2500. _bfd_generic_bfd_copy_private_header_data,
  2501. _bfd_generic_bfd_set_private_flags,
  2502. _bfd_generic_bfd_print_private_bfd_data,
  2503. /* Core */
  2504. BFD_JUMP_TABLE_CORE (xcoff64),
  2505. /* Archive */
  2506. xcoff64_slurp_armap,
  2507. _bfd_noarchive_slurp_extended_name_table,
  2508. _bfd_noarchive_construct_extended_name_table,
  2509. bfd_dont_truncate_arname,
  2510. _bfd_xcoff_write_armap,
  2511. _bfd_xcoff_read_ar_hdr,
  2512. _bfd_generic_write_ar_hdr,
  2513. xcoff64_openr_next_archived_file,
  2514. _bfd_generic_get_elt_at_index,
  2515. _bfd_xcoff_stat_arch_elt,
  2516. _bfd_bool_bfd_true,
  2517. /* Symbols */
  2518. coff_get_symtab_upper_bound,
  2519. coff_canonicalize_symtab,
  2520. coff_make_empty_symbol,
  2521. coff_print_symbol,
  2522. coff_get_symbol_info,
  2523. coff_get_symbol_version_string,
  2524. _bfd_xcoff_is_local_label_name,
  2525. coff_bfd_is_target_special_symbol,
  2526. coff_get_lineno,
  2527. coff_find_nearest_line,
  2528. coff_find_line,
  2529. coff_find_inliner_info,
  2530. coff_bfd_make_debug_symbol,
  2531. _bfd_generic_read_minisymbols,
  2532. _bfd_generic_minisymbol_to_symbol,
  2533. /* Reloc */
  2534. coff_get_reloc_upper_bound,
  2535. coff_canonicalize_reloc,
  2536. _bfd_generic_set_reloc,
  2537. xcoff64_reloc_type_lookup,
  2538. xcoff64_reloc_name_lookup,
  2539. /* Write */
  2540. coff_set_arch_mach,
  2541. coff_set_section_contents,
  2542. /* Link */
  2543. xcoff64_sizeof_headers,
  2544. bfd_generic_get_relocated_section_contents,
  2545. bfd_generic_relax_section,
  2546. _bfd_xcoff_bfd_link_hash_table_create,
  2547. _bfd_xcoff_bfd_link_add_symbols,
  2548. _bfd_generic_link_just_syms,
  2549. _bfd_generic_copy_link_hash_symbol_type,
  2550. _bfd_xcoff_bfd_final_link,
  2551. _bfd_generic_link_split_section,
  2552. _bfd_generic_link_check_relocs,
  2553. bfd_generic_gc_sections,
  2554. bfd_generic_lookup_section_flags,
  2555. bfd_generic_merge_sections,
  2556. bfd_generic_is_group_section,
  2557. bfd_generic_group_name,
  2558. bfd_generic_discard_group,
  2559. _bfd_generic_section_already_linked,
  2560. _bfd_xcoff_define_common_symbol,
  2561. _bfd_generic_link_hide_symbol,
  2562. bfd_generic_define_start_stop,
  2563. /* Dynamic */
  2564. _bfd_xcoff_get_dynamic_symtab_upper_bound,
  2565. _bfd_xcoff_canonicalize_dynamic_symtab,
  2566. _bfd_nodynamic_get_synthetic_symtab,
  2567. _bfd_xcoff_get_dynamic_reloc_upper_bound,
  2568. _bfd_xcoff_canonicalize_dynamic_reloc,
  2569. /* Opposite endian version, none exists. */
  2570. NULL,
  2571. & bfd_xcoff_aix5_backend_data,
  2572. };