elf64-s390.c 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897
  1. /* IBM S/390-specific support for 64-bit ELF
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. Contributed Martin Schwidefsky (schwidefsky@de.ibm.com).
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  16. 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "bfdlink.h"
  20. #include "libbfd.h"
  21. #include "elf-bfd.h"
  22. #include "elf/s390.h"
  23. #include "elf-s390.h"
  24. #include <stdarg.h>
  25. /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
  26. from smaller values. Start with zero, widen, *then* decrement. */
  27. #define MINUS_ONE (((bfd_vma)0) - 1)
  28. static bfd_reloc_status_type
  29. s390_tls_reloc (bfd *, arelent *, asymbol *, void *,
  30. asection *, bfd *, char **);
  31. static bfd_reloc_status_type
  32. s390_elf_ldisp_reloc (bfd *, arelent *, asymbol *, void *,
  33. asection *, bfd *, char **);
  34. /* The relocation "howto" table. */
  35. static reloc_howto_type elf_howto_table[] =
  36. {
  37. HOWTO (R_390_NONE, /* type */
  38. 0, /* rightshift */
  39. 3, /* size (0 = byte, 1 = 2 byte, 2 = 4 byte) */
  40. 0, /* bitsize */
  41. false, /* pc_relative */
  42. 0, /* bitpos */
  43. complain_overflow_dont, /* complain_on_overflow */
  44. bfd_elf_generic_reloc, /* special_function */
  45. "R_390_NONE", /* name */
  46. false, /* partial_inplace */
  47. 0, /* src_mask */
  48. 0, /* dst_mask */
  49. false), /* pcrel_offset */
  50. HOWTO(R_390_8, 0, 0, 8, false, 0, complain_overflow_bitfield,
  51. bfd_elf_generic_reloc, "R_390_8", false, 0,0x000000ff, false),
  52. HOWTO(R_390_12, 0, 1, 12, false, 0, complain_overflow_dont,
  53. bfd_elf_generic_reloc, "R_390_12", false, 0,0x00000fff, false),
  54. HOWTO(R_390_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
  55. bfd_elf_generic_reloc, "R_390_16", false, 0,0x0000ffff, false),
  56. HOWTO(R_390_32, 0, 2, 32, false, 0, complain_overflow_bitfield,
  57. bfd_elf_generic_reloc, "R_390_32", false, 0,0xffffffff, false),
  58. HOWTO(R_390_PC32, 0, 2, 32, true, 0, complain_overflow_bitfield,
  59. bfd_elf_generic_reloc, "R_390_PC32", false, 0,0xffffffff, true),
  60. HOWTO(R_390_GOT12, 0, 1, 12, false, 0, complain_overflow_bitfield,
  61. bfd_elf_generic_reloc, "R_390_GOT12", false, 0,0x00000fff, false),
  62. HOWTO(R_390_GOT32, 0, 2, 32, false, 0, complain_overflow_bitfield,
  63. bfd_elf_generic_reloc, "R_390_GOT32", false, 0,0xffffffff, false),
  64. HOWTO(R_390_PLT32, 0, 2, 32, true, 0, complain_overflow_bitfield,
  65. bfd_elf_generic_reloc, "R_390_PLT32", false, 0,0xffffffff, true),
  66. HOWTO(R_390_COPY, 0, 4, 64, false, 0, complain_overflow_bitfield,
  67. bfd_elf_generic_reloc, "R_390_COPY", false, 0,MINUS_ONE, false),
  68. HOWTO(R_390_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_bitfield,
  69. bfd_elf_generic_reloc, "R_390_GLOB_DAT", false, 0,MINUS_ONE, false),
  70. HOWTO(R_390_JMP_SLOT, 0, 4, 64, false, 0, complain_overflow_bitfield,
  71. bfd_elf_generic_reloc, "R_390_JMP_SLOT", false, 0,MINUS_ONE, false),
  72. HOWTO(R_390_RELATIVE, 0, 4, 64, true, 0, complain_overflow_bitfield,
  73. bfd_elf_generic_reloc, "R_390_RELATIVE", false, 0,MINUS_ONE, false),
  74. HOWTO(R_390_GOTOFF32, 0, 2, 32, false, 0, complain_overflow_bitfield,
  75. bfd_elf_generic_reloc, "R_390_GOTOFF32", false, 0,MINUS_ONE, false),
  76. HOWTO(R_390_GOTPC, 0, 4, 64, true, 0, complain_overflow_bitfield,
  77. bfd_elf_generic_reloc, "R_390_GOTPC", false, 0,MINUS_ONE, true),
  78. HOWTO(R_390_GOT16, 0, 1, 16, false, 0, complain_overflow_bitfield,
  79. bfd_elf_generic_reloc, "R_390_GOT16", false, 0,0x0000ffff, false),
  80. HOWTO(R_390_PC16, 0, 1, 16, true, 0, complain_overflow_bitfield,
  81. bfd_elf_generic_reloc, "R_390_PC16", false, 0,0x0000ffff, true),
  82. HOWTO(R_390_PC16DBL, 1, 1, 16, true, 0, complain_overflow_bitfield,
  83. bfd_elf_generic_reloc, "R_390_PC16DBL", false, 0,0x0000ffff, true),
  84. HOWTO(R_390_PLT16DBL, 1, 1, 16, true, 0, complain_overflow_bitfield,
  85. bfd_elf_generic_reloc, "R_390_PLT16DBL", false, 0,0x0000ffff, true),
  86. HOWTO(R_390_PC32DBL, 1, 2, 32, true, 0, complain_overflow_bitfield,
  87. bfd_elf_generic_reloc, "R_390_PC32DBL", false, 0,0xffffffff, true),
  88. HOWTO(R_390_PLT32DBL, 1, 2, 32, true, 0, complain_overflow_bitfield,
  89. bfd_elf_generic_reloc, "R_390_PLT32DBL", false, 0,0xffffffff, true),
  90. HOWTO(R_390_GOTPCDBL, 1, 2, 32, true, 0, complain_overflow_bitfield,
  91. bfd_elf_generic_reloc, "R_390_GOTPCDBL", false, 0,MINUS_ONE, true),
  92. HOWTO(R_390_64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  93. bfd_elf_generic_reloc, "R_390_64", false, 0,MINUS_ONE, false),
  94. HOWTO(R_390_PC64, 0, 4, 64, true, 0, complain_overflow_bitfield,
  95. bfd_elf_generic_reloc, "R_390_PC64", false, 0,MINUS_ONE, true),
  96. HOWTO(R_390_GOT64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  97. bfd_elf_generic_reloc, "R_390_GOT64", false, 0,MINUS_ONE, false),
  98. HOWTO(R_390_PLT64, 0, 4, 64, true, 0, complain_overflow_bitfield,
  99. bfd_elf_generic_reloc, "R_390_PLT64", false, 0,MINUS_ONE, true),
  100. HOWTO(R_390_GOTENT, 1, 2, 32, true, 0, complain_overflow_bitfield,
  101. bfd_elf_generic_reloc, "R_390_GOTENT", false, 0,MINUS_ONE, true),
  102. HOWTO(R_390_GOTOFF16, 0, 1, 16, false, 0, complain_overflow_bitfield,
  103. bfd_elf_generic_reloc, "R_390_GOTOFF16", false, 0,0x0000ffff, false),
  104. HOWTO(R_390_GOTOFF64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  105. bfd_elf_generic_reloc, "R_390_GOTOFF64", false, 0,MINUS_ONE, false),
  106. HOWTO(R_390_GOTPLT12, 0, 1, 12, false, 0, complain_overflow_dont,
  107. bfd_elf_generic_reloc, "R_390_GOTPLT12", false, 0,0x00000fff, false),
  108. HOWTO(R_390_GOTPLT16, 0, 1, 16, false, 0, complain_overflow_bitfield,
  109. bfd_elf_generic_reloc, "R_390_GOTPLT16", false, 0,0x0000ffff, false),
  110. HOWTO(R_390_GOTPLT32, 0, 2, 32, false, 0, complain_overflow_bitfield,
  111. bfd_elf_generic_reloc, "R_390_GOTPLT32", false, 0,0xffffffff, false),
  112. HOWTO(R_390_GOTPLT64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  113. bfd_elf_generic_reloc, "R_390_GOTPLT64", false, 0,MINUS_ONE, false),
  114. HOWTO(R_390_GOTPLTENT, 1, 2, 32, true, 0, complain_overflow_bitfield,
  115. bfd_elf_generic_reloc, "R_390_GOTPLTENT",false, 0,MINUS_ONE, true),
  116. HOWTO(R_390_PLTOFF16, 0, 1, 16, false, 0, complain_overflow_bitfield,
  117. bfd_elf_generic_reloc, "R_390_PLTOFF16", false, 0,0x0000ffff, false),
  118. HOWTO(R_390_PLTOFF32, 0, 2, 32, false, 0, complain_overflow_bitfield,
  119. bfd_elf_generic_reloc, "R_390_PLTOFF32", false, 0,0xffffffff, false),
  120. HOWTO(R_390_PLTOFF64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  121. bfd_elf_generic_reloc, "R_390_PLTOFF64", false, 0,MINUS_ONE, false),
  122. HOWTO(R_390_TLS_LOAD, 0, 0, 0, false, 0, complain_overflow_dont,
  123. s390_tls_reloc, "R_390_TLS_LOAD", false, 0, 0, false),
  124. HOWTO(R_390_TLS_GDCALL, 0, 0, 0, false, 0, complain_overflow_dont,
  125. s390_tls_reloc, "R_390_TLS_GDCALL", false, 0, 0, false),
  126. HOWTO(R_390_TLS_LDCALL, 0, 0, 0, false, 0, complain_overflow_dont,
  127. s390_tls_reloc, "R_390_TLS_LDCALL", false, 0, 0, false),
  128. EMPTY_HOWTO (R_390_TLS_GD32), /* Empty entry for R_390_TLS_GD32. */
  129. HOWTO(R_390_TLS_GD64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  130. bfd_elf_generic_reloc, "R_390_TLS_GD64", false, 0, MINUS_ONE, false),
  131. HOWTO(R_390_TLS_GOTIE12, 0, 1, 12, false, 0, complain_overflow_dont,
  132. bfd_elf_generic_reloc, "R_390_TLS_GOTIE12", false, 0, 0x00000fff, false),
  133. EMPTY_HOWTO (R_390_TLS_GOTIE32), /* Empty entry for R_390_TLS_GOTIE32. */
  134. HOWTO(R_390_TLS_GOTIE64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  135. bfd_elf_generic_reloc, "R_390_TLS_GOTIE64", false, 0, MINUS_ONE, false),
  136. EMPTY_HOWTO (R_390_TLS_LDM32), /* Empty entry for R_390_TLS_LDM32. */
  137. HOWTO(R_390_TLS_LDM64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  138. bfd_elf_generic_reloc, "R_390_TLS_LDM64", false, 0, MINUS_ONE, false),
  139. EMPTY_HOWTO (R_390_TLS_IE32), /* Empty entry for R_390_TLS_IE32. */
  140. HOWTO(R_390_TLS_IE64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  141. bfd_elf_generic_reloc, "R_390_TLS_IE64", false, 0, MINUS_ONE, false),
  142. HOWTO(R_390_TLS_IEENT, 1, 2, 32, true, 0, complain_overflow_bitfield,
  143. bfd_elf_generic_reloc, "R_390_TLS_IEENT", false, 0, MINUS_ONE, true),
  144. EMPTY_HOWTO (R_390_TLS_LE32), /* Empty entry for R_390_TLS_LE32. */
  145. HOWTO(R_390_TLS_LE64, 0, 2, 32, false, 0, complain_overflow_bitfield,
  146. bfd_elf_generic_reloc, "R_390_TLS_LE64", false, 0, MINUS_ONE, false),
  147. EMPTY_HOWTO (R_390_TLS_LDO32), /* Empty entry for R_390_TLS_LDO32. */
  148. HOWTO(R_390_TLS_LDO64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  149. bfd_elf_generic_reloc, "R_390_TLS_LDO64", false, 0, MINUS_ONE, false),
  150. HOWTO(R_390_TLS_DTPMOD, 0, 4, 64, false, 0, complain_overflow_bitfield,
  151. bfd_elf_generic_reloc, "R_390_TLS_DTPMOD", false, 0, MINUS_ONE, false),
  152. HOWTO(R_390_TLS_DTPOFF, 0, 4, 64, false, 0, complain_overflow_bitfield,
  153. bfd_elf_generic_reloc, "R_390_TLS_DTPOFF", false, 0, MINUS_ONE, false),
  154. HOWTO(R_390_TLS_TPOFF, 0, 4, 64, false, 0, complain_overflow_bitfield,
  155. bfd_elf_generic_reloc, "R_390_TLS_TPOFF", false, 0, MINUS_ONE, false),
  156. HOWTO(R_390_20, 0, 2, 20, false, 8, complain_overflow_dont,
  157. s390_elf_ldisp_reloc, "R_390_20", false, 0,0x0fffff00, false),
  158. HOWTO(R_390_GOT20, 0, 2, 20, false, 8, complain_overflow_dont,
  159. s390_elf_ldisp_reloc, "R_390_GOT20", false, 0,0x0fffff00, false),
  160. HOWTO(R_390_GOTPLT20, 0, 2, 20, false, 8, complain_overflow_dont,
  161. s390_elf_ldisp_reloc, "R_390_GOTPLT20", false, 0,0x0fffff00, false),
  162. HOWTO(R_390_TLS_GOTIE20, 0, 2, 20, false, 8, complain_overflow_dont,
  163. s390_elf_ldisp_reloc, "R_390_TLS_GOTIE20", false, 0,0x0fffff00, false),
  164. HOWTO(R_390_IRELATIVE, 0, 4, 64, false, 0, complain_overflow_bitfield,
  165. bfd_elf_generic_reloc, "R_390_IRELATIVE", false, 0, MINUS_ONE, false),
  166. HOWTO(R_390_PC12DBL, 1, 1, 12, true, 0, complain_overflow_bitfield,
  167. bfd_elf_generic_reloc, "R_390_PC12DBL", false, 0,0x00000fff, true),
  168. HOWTO(R_390_PLT12DBL, 1, 1, 12, true, 0, complain_overflow_bitfield,
  169. bfd_elf_generic_reloc, "R_390_PLT12DBL", false, 0,0x00000fff, true),
  170. HOWTO(R_390_PC24DBL, 1, 2, 24, true, 0, complain_overflow_bitfield,
  171. bfd_elf_generic_reloc, "R_390_PC24DBL", false, 0,0x00ffffff, true),
  172. HOWTO(R_390_PLT24DBL, 1, 2, 24, true, 0, complain_overflow_bitfield,
  173. bfd_elf_generic_reloc, "R_390_PLT24DBL", false, 0,0x00ffffff, true),
  174. };
  175. /* GNU extension to record C++ vtable hierarchy. */
  176. static reloc_howto_type elf64_s390_vtinherit_howto =
  177. HOWTO (R_390_GNU_VTINHERIT, 0,4,0,false,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", false,0, 0, false);
  178. static reloc_howto_type elf64_s390_vtentry_howto =
  179. HOWTO (R_390_GNU_VTENTRY, 0,4,0,false,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", false,0,0, false);
  180. static reloc_howto_type *
  181. elf_s390_reloc_type_lookup (bfd *abfd,
  182. bfd_reloc_code_real_type code)
  183. {
  184. switch (code)
  185. {
  186. case BFD_RELOC_NONE:
  187. return &elf_howto_table[(int) R_390_NONE];
  188. case BFD_RELOC_8:
  189. return &elf_howto_table[(int) R_390_8];
  190. case BFD_RELOC_390_12:
  191. return &elf_howto_table[(int) R_390_12];
  192. case BFD_RELOC_16:
  193. return &elf_howto_table[(int) R_390_16];
  194. case BFD_RELOC_32:
  195. return &elf_howto_table[(int) R_390_32];
  196. case BFD_RELOC_CTOR:
  197. return &elf_howto_table[(int) R_390_32];
  198. case BFD_RELOC_32_PCREL:
  199. return &elf_howto_table[(int) R_390_PC32];
  200. case BFD_RELOC_390_GOT12:
  201. return &elf_howto_table[(int) R_390_GOT12];
  202. case BFD_RELOC_32_GOT_PCREL:
  203. return &elf_howto_table[(int) R_390_GOT32];
  204. case BFD_RELOC_390_PLT32:
  205. return &elf_howto_table[(int) R_390_PLT32];
  206. case BFD_RELOC_390_COPY:
  207. return &elf_howto_table[(int) R_390_COPY];
  208. case BFD_RELOC_390_GLOB_DAT:
  209. return &elf_howto_table[(int) R_390_GLOB_DAT];
  210. case BFD_RELOC_390_JMP_SLOT:
  211. return &elf_howto_table[(int) R_390_JMP_SLOT];
  212. case BFD_RELOC_390_RELATIVE:
  213. return &elf_howto_table[(int) R_390_RELATIVE];
  214. case BFD_RELOC_32_GOTOFF:
  215. return &elf_howto_table[(int) R_390_GOTOFF32];
  216. case BFD_RELOC_390_GOTPC:
  217. return &elf_howto_table[(int) R_390_GOTPC];
  218. case BFD_RELOC_390_GOT16:
  219. return &elf_howto_table[(int) R_390_GOT16];
  220. case BFD_RELOC_16_PCREL:
  221. return &elf_howto_table[(int) R_390_PC16];
  222. case BFD_RELOC_390_PC12DBL:
  223. return &elf_howto_table[(int) R_390_PC12DBL];
  224. case BFD_RELOC_390_PLT12DBL:
  225. return &elf_howto_table[(int) R_390_PLT12DBL];
  226. case BFD_RELOC_390_PC16DBL:
  227. return &elf_howto_table[(int) R_390_PC16DBL];
  228. case BFD_RELOC_390_PLT16DBL:
  229. return &elf_howto_table[(int) R_390_PLT16DBL];
  230. case BFD_RELOC_390_PC24DBL:
  231. return &elf_howto_table[(int) R_390_PC24DBL];
  232. case BFD_RELOC_390_PLT24DBL:
  233. return &elf_howto_table[(int) R_390_PLT24DBL];
  234. case BFD_RELOC_390_PC32DBL:
  235. return &elf_howto_table[(int) R_390_PC32DBL];
  236. case BFD_RELOC_390_PLT32DBL:
  237. return &elf_howto_table[(int) R_390_PLT32DBL];
  238. case BFD_RELOC_390_GOTPCDBL:
  239. return &elf_howto_table[(int) R_390_GOTPCDBL];
  240. case BFD_RELOC_64:
  241. return &elf_howto_table[(int) R_390_64];
  242. case BFD_RELOC_64_PCREL:
  243. return &elf_howto_table[(int) R_390_PC64];
  244. case BFD_RELOC_390_GOT64:
  245. return &elf_howto_table[(int) R_390_GOT64];
  246. case BFD_RELOC_390_PLT64:
  247. return &elf_howto_table[(int) R_390_PLT64];
  248. case BFD_RELOC_390_GOTENT:
  249. return &elf_howto_table[(int) R_390_GOTENT];
  250. case BFD_RELOC_16_GOTOFF:
  251. return &elf_howto_table[(int) R_390_GOTOFF16];
  252. case BFD_RELOC_390_GOTOFF64:
  253. return &elf_howto_table[(int) R_390_GOTOFF64];
  254. case BFD_RELOC_390_GOTPLT12:
  255. return &elf_howto_table[(int) R_390_GOTPLT12];
  256. case BFD_RELOC_390_GOTPLT16:
  257. return &elf_howto_table[(int) R_390_GOTPLT16];
  258. case BFD_RELOC_390_GOTPLT32:
  259. return &elf_howto_table[(int) R_390_GOTPLT32];
  260. case BFD_RELOC_390_GOTPLT64:
  261. return &elf_howto_table[(int) R_390_GOTPLT64];
  262. case BFD_RELOC_390_GOTPLTENT:
  263. return &elf_howto_table[(int) R_390_GOTPLTENT];
  264. case BFD_RELOC_390_PLTOFF16:
  265. return &elf_howto_table[(int) R_390_PLTOFF16];
  266. case BFD_RELOC_390_PLTOFF32:
  267. return &elf_howto_table[(int) R_390_PLTOFF32];
  268. case BFD_RELOC_390_PLTOFF64:
  269. return &elf_howto_table[(int) R_390_PLTOFF64];
  270. case BFD_RELOC_390_TLS_LOAD:
  271. return &elf_howto_table[(int) R_390_TLS_LOAD];
  272. case BFD_RELOC_390_TLS_GDCALL:
  273. return &elf_howto_table[(int) R_390_TLS_GDCALL];
  274. case BFD_RELOC_390_TLS_LDCALL:
  275. return &elf_howto_table[(int) R_390_TLS_LDCALL];
  276. case BFD_RELOC_390_TLS_GD64:
  277. return &elf_howto_table[(int) R_390_TLS_GD64];
  278. case BFD_RELOC_390_TLS_GOTIE12:
  279. return &elf_howto_table[(int) R_390_TLS_GOTIE12];
  280. case BFD_RELOC_390_TLS_GOTIE64:
  281. return &elf_howto_table[(int) R_390_TLS_GOTIE64];
  282. case BFD_RELOC_390_TLS_LDM64:
  283. return &elf_howto_table[(int) R_390_TLS_LDM64];
  284. case BFD_RELOC_390_TLS_IE64:
  285. return &elf_howto_table[(int) R_390_TLS_IE64];
  286. case BFD_RELOC_390_TLS_IEENT:
  287. return &elf_howto_table[(int) R_390_TLS_IEENT];
  288. case BFD_RELOC_390_TLS_LE64:
  289. return &elf_howto_table[(int) R_390_TLS_LE64];
  290. case BFD_RELOC_390_TLS_LDO64:
  291. return &elf_howto_table[(int) R_390_TLS_LDO64];
  292. case BFD_RELOC_390_TLS_DTPMOD:
  293. return &elf_howto_table[(int) R_390_TLS_DTPMOD];
  294. case BFD_RELOC_390_TLS_DTPOFF:
  295. return &elf_howto_table[(int) R_390_TLS_DTPOFF];
  296. case BFD_RELOC_390_TLS_TPOFF:
  297. return &elf_howto_table[(int) R_390_TLS_TPOFF];
  298. case BFD_RELOC_390_20:
  299. return &elf_howto_table[(int) R_390_20];
  300. case BFD_RELOC_390_GOT20:
  301. return &elf_howto_table[(int) R_390_GOT20];
  302. case BFD_RELOC_390_GOTPLT20:
  303. return &elf_howto_table[(int) R_390_GOTPLT20];
  304. case BFD_RELOC_390_TLS_GOTIE20:
  305. return &elf_howto_table[(int) R_390_TLS_GOTIE20];
  306. case BFD_RELOC_390_IRELATIVE:
  307. return &elf_howto_table[(int) R_390_IRELATIVE];
  308. case BFD_RELOC_VTABLE_INHERIT:
  309. return &elf64_s390_vtinherit_howto;
  310. case BFD_RELOC_VTABLE_ENTRY:
  311. return &elf64_s390_vtentry_howto;
  312. default:
  313. break;
  314. }
  315. /* xgettext:c-format */
  316. _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, (int) code);
  317. bfd_set_error (bfd_error_bad_value);
  318. return NULL;
  319. }
  320. static reloc_howto_type *
  321. elf_s390_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  322. const char *r_name)
  323. {
  324. unsigned int i;
  325. for (i = 0;
  326. i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]);
  327. i++)
  328. if (elf_howto_table[i].name != NULL
  329. && strcasecmp (elf_howto_table[i].name, r_name) == 0)
  330. return &elf_howto_table[i];
  331. if (strcasecmp (elf64_s390_vtinherit_howto.name, r_name) == 0)
  332. return &elf64_s390_vtinherit_howto;
  333. if (strcasecmp (elf64_s390_vtentry_howto.name, r_name) == 0)
  334. return &elf64_s390_vtentry_howto;
  335. return NULL;
  336. }
  337. /* We need to use ELF64_R_TYPE so we have our own copy of this function,
  338. and elf64-s390.c has its own copy. */
  339. static bool
  340. elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
  341. arelent *cache_ptr,
  342. Elf_Internal_Rela *dst)
  343. {
  344. unsigned int r_type = ELF64_R_TYPE(dst->r_info);
  345. switch (r_type)
  346. {
  347. case R_390_GNU_VTINHERIT:
  348. cache_ptr->howto = &elf64_s390_vtinherit_howto;
  349. break;
  350. case R_390_GNU_VTENTRY:
  351. cache_ptr->howto = &elf64_s390_vtentry_howto;
  352. break;
  353. default:
  354. if (r_type >= sizeof (elf_howto_table) / sizeof (elf_howto_table[0]))
  355. {
  356. /* xgettext:c-format */
  357. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  358. abfd, r_type);
  359. bfd_set_error (bfd_error_bad_value);
  360. return false;
  361. }
  362. cache_ptr->howto = &elf_howto_table[r_type];
  363. }
  364. return true;
  365. }
  366. /* A relocation function which doesn't do anything. */
  367. static bfd_reloc_status_type
  368. s390_tls_reloc (bfd *abfd ATTRIBUTE_UNUSED,
  369. arelent *reloc_entry,
  370. asymbol *symbol ATTRIBUTE_UNUSED,
  371. void * data ATTRIBUTE_UNUSED,
  372. asection *input_section,
  373. bfd *output_bfd,
  374. char **error_message ATTRIBUTE_UNUSED)
  375. {
  376. if (output_bfd)
  377. reloc_entry->address += input_section->output_offset;
  378. return bfd_reloc_ok;
  379. }
  380. /* Handle the large displacement relocs. */
  381. static bfd_reloc_status_type
  382. s390_elf_ldisp_reloc (bfd *abfd,
  383. arelent *reloc_entry,
  384. asymbol *symbol,
  385. void * data,
  386. asection *input_section,
  387. bfd *output_bfd,
  388. char **error_message ATTRIBUTE_UNUSED)
  389. {
  390. reloc_howto_type *howto = reloc_entry->howto;
  391. bfd_vma relocation;
  392. bfd_vma insn;
  393. if (output_bfd != (bfd *) NULL
  394. && (symbol->flags & BSF_SECTION_SYM) == 0
  395. && (! howto->partial_inplace
  396. || reloc_entry->addend == 0))
  397. {
  398. reloc_entry->address += input_section->output_offset;
  399. return bfd_reloc_ok;
  400. }
  401. if (output_bfd != NULL)
  402. return bfd_reloc_continue;
  403. if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
  404. return bfd_reloc_outofrange;
  405. relocation = (symbol->value
  406. + symbol->section->output_section->vma
  407. + symbol->section->output_offset);
  408. relocation += reloc_entry->addend;
  409. if (howto->pc_relative)
  410. {
  411. relocation -= (input_section->output_section->vma
  412. + input_section->output_offset);
  413. relocation -= reloc_entry->address;
  414. }
  415. insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
  416. insn |= (relocation & 0xfff) << 16 | (relocation & 0xff000) >> 4;
  417. bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
  418. if ((bfd_signed_vma) relocation < - 0x80000
  419. || (bfd_signed_vma) relocation > 0x7ffff)
  420. return bfd_reloc_overflow;
  421. else
  422. return bfd_reloc_ok;
  423. }
  424. static bool
  425. elf_s390_is_local_label_name (bfd *abfd, const char *name)
  426. {
  427. if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L'))
  428. return true;
  429. return _bfd_elf_is_local_label_name (abfd, name);
  430. }
  431. /* Functions for the 390 ELF linker. */
  432. /* The name of the dynamic interpreter. This is put in the .interp
  433. section. */
  434. #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
  435. /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
  436. copying dynamic variables from a shared lib into an app's dynbss
  437. section, and instead use a dynamic relocation to point into the
  438. shared lib. */
  439. #define ELIMINATE_COPY_RELOCS 1
  440. /* The size in bytes of the first entry in the procedure linkage table. */
  441. #define PLT_FIRST_ENTRY_SIZE 32
  442. /* The size in bytes of an entry in the procedure linkage table. */
  443. #define PLT_ENTRY_SIZE 32
  444. #define GOT_ENTRY_SIZE 8
  445. #define RELA_ENTRY_SIZE sizeof (Elf64_External_Rela)
  446. /* The first three entries in a global offset table are reserved,
  447. and the initial contents are unimportant (we zero them out).
  448. Subsequent entries look like this. See the SVR4 ABI 386
  449. supplement to see how this works. */
  450. /* For the s390, simple addr offset can only be 0 - 4096.
  451. To use the full 16777216 TB address space, several instructions
  452. are needed to load an address in a register and execute
  453. a branch( or just saving the address)
  454. Furthermore, only r 0 and 1 are free to use!!! */
  455. /* The first 3 words in the GOT are then reserved.
  456. Word 0 is the address of the dynamic table.
  457. Word 1 is a pointer to a structure describing the object
  458. Word 2 is used to point to the loader entry address.
  459. The code for PLT entries looks like this:
  460. The GOT holds the address in the PLT to be executed.
  461. The loader then gets:
  462. 48(15) = Pointer to the structure describing the object.
  463. 56(15) = Offset in symbol table
  464. The loader must then find the module where the function is
  465. and insert the address in the GOT.
  466. PLT1: LARL 1,<fn>@GOTENT # 6 bytes Load address of GOT entry in r1
  467. LG 1,0(1) # 6 bytes Load address from GOT in r1
  468. BCR 15,1 # 2 bytes Jump to address
  469. RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
  470. LGF 1,12(1) # 6 bytes Load rela.plt offset into r1
  471. BRCL 15,-x # 6 bytes Jump to first PLT entry
  472. .long ? # 4 bytes offset into .rela.plt
  473. Total = 32 bytes per PLT entry
  474. Fixup at offset 2: relative address to GOT entry
  475. Fixup at offset 22: relative branch to PLT0
  476. Fixup at offset 28: 32 bit offset into .rela.plt
  477. A 32 bit offset into the symbol table is enough. It allows for
  478. .rela.plt sections up to a size of 2 gigabyte. A single dynamic
  479. object (the main program, any shared library) is limited to 4GB in
  480. size. Having a .rela.plt of 2GB would already make the .plt
  481. section bigger than 8GB. */
  482. static const bfd_byte elf_s390x_plt_entry[PLT_ENTRY_SIZE] =
  483. {
  484. 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, /* larl %r1,. */
  485. 0xe3, 0x10, 0x10, 0x00, 0x00, 0x04, /* lg %r1,0(%r1) */
  486. 0x07, 0xf1, /* br %r1 */
  487. 0x0d, 0x10, /* basr %r1,%r0 */
  488. 0xe3, 0x10, 0x10, 0x0c, 0x00, 0x14, /* lgf %r1,12(%r1) */
  489. 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg first plt */
  490. 0x00, 0x00, 0x00, 0x00 /* .long 0x00000000 */
  491. };
  492. /* The first PLT entry pushes the offset into the symbol table
  493. from R1 onto the stack at 56(15) and the loader object info
  494. at 48(15), loads the loader address in R1 and jumps to it. */
  495. /* The first entry in the PLT:
  496. PLT0:
  497. STG 1,56(15) # r1 contains the offset into the symbol table
  498. LARL 1,_GLOBAL_OFFSET_TABLE # load address of global offset table
  499. MVC 48(8,15),8(1) # move loader ino (object struct address) to stack
  500. LG 1,16(1) # get entry address of loader
  501. BCR 15,1 # jump to loader
  502. Fixup at offset 8: relative address to start of GOT. */
  503. static const bfd_byte elf_s390x_first_plt_entry[PLT_FIRST_ENTRY_SIZE] =
  504. {
  505. 0xe3, 0x10, 0xf0, 0x38, 0x00, 0x24, /* stg %r1,56(%r15) */
  506. 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, /* larl %r1,. */
  507. 0xd2, 0x07, 0xf0, 0x30, 0x10, 0x08, /* mvc 48(8,%r15),8(%r1) */
  508. 0xe3, 0x10, 0x10, 0x10, 0x00, 0x04, /* lg %r1,16(%r1) */
  509. 0x07, 0xf1, /* br %r1 */
  510. 0x07, 0x00, /* nopr %r0 */
  511. 0x07, 0x00, /* nopr %r0 */
  512. 0x07, 0x00 /* nopr %r0 */
  513. };
  514. /* s390 ELF linker hash entry. */
  515. struct elf_s390_link_hash_entry
  516. {
  517. struct elf_link_hash_entry elf;
  518. /* Number of GOTPLT references for a function. */
  519. bfd_signed_vma gotplt_refcount;
  520. #define GOT_UNKNOWN 0
  521. #define GOT_NORMAL 1
  522. #define GOT_TLS_GD 2
  523. #define GOT_TLS_IE 3
  524. #define GOT_TLS_IE_NLT 3
  525. unsigned char tls_type;
  526. /* For pointer equality reasons we might need to change the symbol
  527. type from STT_GNU_IFUNC to STT_FUNC together with its value and
  528. section entry. So after alloc_dynrelocs only these values should
  529. be used. In order to check whether a symbol is IFUNC use
  530. s390_is_ifunc_symbol_p. */
  531. bfd_vma ifunc_resolver_address;
  532. asection *ifunc_resolver_section;
  533. };
  534. #define elf_s390_hash_entry(ent) \
  535. ((struct elf_s390_link_hash_entry *)(ent))
  536. /* This structure represents an entry in the local PLT list needed for
  537. local IFUNC symbols. */
  538. struct plt_entry
  539. {
  540. /* The section of the local symbol.
  541. Set in relocate_section and used in finish_dynamic_sections. */
  542. asection *sec;
  543. union
  544. {
  545. bfd_signed_vma refcount;
  546. bfd_vma offset;
  547. } plt;
  548. };
  549. /* NOTE: Keep this structure in sync with
  550. the one declared in elf32-s390.c. */
  551. struct elf_s390_obj_tdata
  552. {
  553. struct elf_obj_tdata root;
  554. /* A local PLT is needed for ifunc symbols. */
  555. struct plt_entry *local_plt;
  556. /* TLS type for each local got entry. */
  557. char *local_got_tls_type;
  558. };
  559. #define elf_s390_tdata(abfd) \
  560. ((struct elf_s390_obj_tdata *) (abfd)->tdata.any)
  561. #define elf_s390_local_plt(abfd) \
  562. (elf_s390_tdata (abfd)->local_plt)
  563. #define elf_s390_local_got_tls_type(abfd) \
  564. (elf_s390_tdata (abfd)->local_got_tls_type)
  565. #define is_s390_elf(bfd) \
  566. (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  567. && elf_tdata (bfd) != NULL \
  568. && elf_object_id (bfd) == S390_ELF_DATA)
  569. static bool
  570. elf_s390_mkobject (bfd *abfd)
  571. {
  572. return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata),
  573. S390_ELF_DATA);
  574. }
  575. static bool
  576. elf_s390_object_p (bfd *abfd)
  577. {
  578. /* Set the right machine number for an s390 elf32 file. */
  579. return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_64);
  580. }
  581. /* s390 ELF linker hash table. */
  582. struct elf_s390_link_hash_table
  583. {
  584. struct elf_link_hash_table elf;
  585. /* Short-cuts to get to dynamic linker sections. */
  586. asection *irelifunc;
  587. union {
  588. bfd_signed_vma refcount;
  589. bfd_vma offset;
  590. } tls_ldm_got;
  591. /* Options passed from the linker. */
  592. struct s390_elf_params *params;
  593. };
  594. /* Get the s390 ELF linker hash table from a link_info structure. */
  595. #define elf_s390_hash_table(p) \
  596. ((is_elf_hash_table ((p)->hash) \
  597. && elf_hash_table_id (elf_hash_table (p)) == S390_ELF_DATA) \
  598. ? (struct elf_s390_link_hash_table *) (p)->hash : NULL)
  599. #define ELF64 1
  600. #include "elf-s390-common.c"
  601. /* Create an entry in an s390 ELF linker hash table. */
  602. static struct bfd_hash_entry *
  603. link_hash_newfunc (struct bfd_hash_entry *entry,
  604. struct bfd_hash_table *table,
  605. const char *string)
  606. {
  607. /* Allocate the structure if it has not already been allocated by a
  608. subclass. */
  609. if (entry == NULL)
  610. {
  611. entry = bfd_hash_allocate (table,
  612. sizeof (struct elf_s390_link_hash_entry));
  613. if (entry == NULL)
  614. return entry;
  615. }
  616. /* Call the allocation method of the superclass. */
  617. entry = _bfd_elf_link_hash_newfunc (entry, table, string);
  618. if (entry != NULL)
  619. {
  620. struct elf_s390_link_hash_entry *eh;
  621. eh = (struct elf_s390_link_hash_entry *) entry;
  622. eh->gotplt_refcount = 0;
  623. eh->tls_type = GOT_UNKNOWN;
  624. eh->ifunc_resolver_address = 0;
  625. eh->ifunc_resolver_section = NULL;
  626. }
  627. return entry;
  628. }
  629. /* Create an s390 ELF linker hash table. */
  630. static struct bfd_link_hash_table *
  631. elf_s390_link_hash_table_create (bfd *abfd)
  632. {
  633. struct elf_s390_link_hash_table *ret;
  634. size_t amt = sizeof (struct elf_s390_link_hash_table);
  635. ret = (struct elf_s390_link_hash_table *) bfd_zmalloc (amt);
  636. if (ret == NULL)
  637. return NULL;
  638. if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
  639. sizeof (struct elf_s390_link_hash_entry),
  640. S390_ELF_DATA))
  641. {
  642. free (ret);
  643. return NULL;
  644. }
  645. return &ret->elf.root;
  646. }
  647. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  648. static void
  649. elf_s390_copy_indirect_symbol (struct bfd_link_info *info,
  650. struct elf_link_hash_entry *dir,
  651. struct elf_link_hash_entry *ind)
  652. {
  653. struct elf_s390_link_hash_entry *edir, *eind;
  654. edir = (struct elf_s390_link_hash_entry *) dir;
  655. eind = (struct elf_s390_link_hash_entry *) ind;
  656. if (ind->root.type == bfd_link_hash_indirect
  657. && dir->got.refcount <= 0)
  658. {
  659. edir->tls_type = eind->tls_type;
  660. eind->tls_type = GOT_UNKNOWN;
  661. }
  662. if (ELIMINATE_COPY_RELOCS
  663. && ind->root.type != bfd_link_hash_indirect
  664. && dir->dynamic_adjusted)
  665. {
  666. /* If called to transfer flags for a weakdef during processing
  667. of elf_adjust_dynamic_symbol, don't copy non_got_ref.
  668. We clear it ourselves for ELIMINATE_COPY_RELOCS. */
  669. if (dir->versioned != versioned_hidden)
  670. dir->ref_dynamic |= ind->ref_dynamic;
  671. dir->ref_regular |= ind->ref_regular;
  672. dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
  673. dir->needs_plt |= ind->needs_plt;
  674. }
  675. else
  676. _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  677. }
  678. static int
  679. elf_s390_tls_transition (struct bfd_link_info *info,
  680. int r_type,
  681. int is_local)
  682. {
  683. if (bfd_link_pic (info))
  684. return r_type;
  685. switch (r_type)
  686. {
  687. case R_390_TLS_GD64:
  688. case R_390_TLS_IE64:
  689. if (is_local)
  690. return R_390_TLS_LE64;
  691. return R_390_TLS_IE64;
  692. case R_390_TLS_GOTIE64:
  693. if (is_local)
  694. return R_390_TLS_LE64;
  695. return R_390_TLS_GOTIE64;
  696. case R_390_TLS_LDM64:
  697. return R_390_TLS_LE64;
  698. }
  699. return r_type;
  700. }
  701. /* Look through the relocs for a section during the first phase, and
  702. allocate space in the global offset table or procedure linkage
  703. table. */
  704. static bool
  705. elf_s390_check_relocs (bfd *abfd,
  706. struct bfd_link_info *info,
  707. asection *sec,
  708. const Elf_Internal_Rela *relocs)
  709. {
  710. struct elf_s390_link_hash_table *htab;
  711. Elf_Internal_Shdr *symtab_hdr;
  712. struct elf_link_hash_entry **sym_hashes;
  713. const Elf_Internal_Rela *rel;
  714. const Elf_Internal_Rela *rel_end;
  715. asection *sreloc;
  716. bfd_signed_vma *local_got_refcounts;
  717. int tls_type, old_tls_type;
  718. if (bfd_link_relocatable (info))
  719. return true;
  720. BFD_ASSERT (is_s390_elf (abfd));
  721. htab = elf_s390_hash_table (info);
  722. if (htab == NULL)
  723. return false;
  724. symtab_hdr = &elf_symtab_hdr (abfd);
  725. sym_hashes = elf_sym_hashes (abfd);
  726. local_got_refcounts = elf_local_got_refcounts (abfd);
  727. sreloc = NULL;
  728. rel_end = relocs + sec->reloc_count;
  729. for (rel = relocs; rel < rel_end; rel++)
  730. {
  731. unsigned int r_type;
  732. unsigned int r_symndx;
  733. struct elf_link_hash_entry *h;
  734. Elf_Internal_Sym *isym;
  735. r_symndx = ELF64_R_SYM (rel->r_info);
  736. if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
  737. {
  738. /* xgettext:c-format */
  739. _bfd_error_handler (_("%pB: bad symbol index: %d"),
  740. abfd, r_symndx);
  741. return false;
  742. }
  743. if (r_symndx < symtab_hdr->sh_info)
  744. {
  745. /* A local symbol. */
  746. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
  747. abfd, r_symndx);
  748. if (isym == NULL)
  749. return false;
  750. if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
  751. {
  752. struct plt_entry *plt;
  753. if (htab->elf.dynobj == NULL)
  754. htab->elf.dynobj = abfd;
  755. if (!s390_elf_create_ifunc_sections (htab->elf.dynobj, info))
  756. return false;
  757. if (local_got_refcounts == NULL)
  758. {
  759. if (!elf_s390_allocate_local_syminfo (abfd, symtab_hdr))
  760. return false;
  761. local_got_refcounts = elf_local_got_refcounts (abfd);
  762. }
  763. plt = elf_s390_local_plt (abfd);
  764. plt[r_symndx].plt.refcount++;
  765. }
  766. h = NULL;
  767. }
  768. else
  769. {
  770. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  771. while (h->root.type == bfd_link_hash_indirect
  772. || h->root.type == bfd_link_hash_warning)
  773. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  774. }
  775. /* Create got section and local_got_refcounts array if they
  776. are needed. */
  777. r_type = elf_s390_tls_transition (info,
  778. ELF64_R_TYPE (rel->r_info),
  779. h == NULL);
  780. switch (r_type)
  781. {
  782. case R_390_GOT12:
  783. case R_390_GOT16:
  784. case R_390_GOT20:
  785. case R_390_GOT32:
  786. case R_390_GOT64:
  787. case R_390_GOTENT:
  788. case R_390_GOTPLT12:
  789. case R_390_GOTPLT16:
  790. case R_390_GOTPLT20:
  791. case R_390_GOTPLT32:
  792. case R_390_GOTPLT64:
  793. case R_390_GOTPLTENT:
  794. case R_390_TLS_GD64:
  795. case R_390_TLS_GOTIE12:
  796. case R_390_TLS_GOTIE20:
  797. case R_390_TLS_GOTIE64:
  798. case R_390_TLS_IEENT:
  799. case R_390_TLS_IE64:
  800. case R_390_TLS_LDM64:
  801. if (h == NULL
  802. && local_got_refcounts == NULL)
  803. {
  804. if (!elf_s390_allocate_local_syminfo (abfd, symtab_hdr))
  805. return false;
  806. local_got_refcounts = elf_local_got_refcounts (abfd);
  807. }
  808. /* Fall through. */
  809. case R_390_GOTOFF16:
  810. case R_390_GOTOFF32:
  811. case R_390_GOTOFF64:
  812. case R_390_GOTPC:
  813. case R_390_GOTPCDBL:
  814. if (htab->elf.sgot == NULL)
  815. {
  816. if (htab->elf.dynobj == NULL)
  817. htab->elf.dynobj = abfd;
  818. if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
  819. return false;
  820. }
  821. }
  822. if (h != NULL)
  823. {
  824. if (htab->elf.dynobj == NULL)
  825. htab->elf.dynobj = abfd;
  826. if (!s390_elf_create_ifunc_sections (htab->elf.dynobj, info))
  827. return false;
  828. /* Make sure an IFUNC symbol defined in a non-shared object
  829. always gets a PLT slot. */
  830. if (s390_is_ifunc_symbol_p (h) && h->def_regular)
  831. {
  832. /* The symbol is called by the dynamic loader in order
  833. to resolve the relocation. So it is in fact also
  834. referenced. */
  835. h->ref_regular = 1;
  836. h->needs_plt = 1;
  837. }
  838. }
  839. switch (r_type)
  840. {
  841. case R_390_GOTPC:
  842. case R_390_GOTPCDBL:
  843. /* These relocs do not need a GOT slot. They just load the
  844. GOT pointer itself or address something else relative to
  845. the GOT. Since the GOT pointer has been set up above we
  846. are done. */
  847. break;
  848. case R_390_GOTOFF16:
  849. case R_390_GOTOFF32:
  850. case R_390_GOTOFF64:
  851. if (h == NULL || !s390_is_ifunc_symbol_p (h) || !h->def_regular)
  852. break;
  853. /* Fall through. */
  854. case R_390_PLT12DBL:
  855. case R_390_PLT16DBL:
  856. case R_390_PLT24DBL:
  857. case R_390_PLT32:
  858. case R_390_PLT32DBL:
  859. case R_390_PLT64:
  860. case R_390_PLTOFF16:
  861. case R_390_PLTOFF32:
  862. case R_390_PLTOFF64:
  863. /* This symbol requires a procedure linkage table entry. We
  864. actually build the entry in adjust_dynamic_symbol,
  865. because this might be a case of linking PIC code which is
  866. never referenced by a dynamic object, in which case we
  867. don't need to generate a procedure linkage table entry
  868. after all. */
  869. /* If this is a local symbol, we resolve it directly without
  870. creating a procedure linkage table entry. */
  871. if (h != NULL)
  872. {
  873. h->needs_plt = 1;
  874. h->plt.refcount += 1;
  875. }
  876. break;
  877. case R_390_GOTPLT12:
  878. case R_390_GOTPLT16:
  879. case R_390_GOTPLT20:
  880. case R_390_GOTPLT32:
  881. case R_390_GOTPLT64:
  882. case R_390_GOTPLTENT:
  883. /* This symbol requires either a procedure linkage table entry
  884. or an entry in the local got. We actually build the entry
  885. in adjust_dynamic_symbol because whether this is really a
  886. global reference can change and with it the fact if we have
  887. to create a plt entry or a local got entry. To be able to
  888. make a once global symbol a local one we have to keep track
  889. of the number of gotplt references that exist for this
  890. symbol. */
  891. if (h != NULL)
  892. {
  893. ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount++;
  894. h->needs_plt = 1;
  895. h->plt.refcount += 1;
  896. }
  897. else
  898. local_got_refcounts[r_symndx] += 1;
  899. break;
  900. case R_390_TLS_LDM64:
  901. htab->tls_ldm_got.refcount += 1;
  902. break;
  903. case R_390_TLS_IE64:
  904. case R_390_TLS_GOTIE12:
  905. case R_390_TLS_GOTIE20:
  906. case R_390_TLS_GOTIE64:
  907. case R_390_TLS_IEENT:
  908. if (bfd_link_pic (info))
  909. info->flags |= DF_STATIC_TLS;
  910. /* Fall through */
  911. case R_390_GOT12:
  912. case R_390_GOT16:
  913. case R_390_GOT20:
  914. case R_390_GOT32:
  915. case R_390_GOT64:
  916. case R_390_GOTENT:
  917. case R_390_TLS_GD64:
  918. /* This symbol requires a global offset table entry. */
  919. switch (r_type)
  920. {
  921. default:
  922. case R_390_GOT12:
  923. case R_390_GOT16:
  924. case R_390_GOT20:
  925. case R_390_GOT32:
  926. case R_390_GOTENT:
  927. tls_type = GOT_NORMAL;
  928. break;
  929. case R_390_TLS_GD64:
  930. tls_type = GOT_TLS_GD;
  931. break;
  932. case R_390_TLS_IE64:
  933. case R_390_TLS_GOTIE64:
  934. tls_type = GOT_TLS_IE;
  935. break;
  936. case R_390_TLS_GOTIE12:
  937. case R_390_TLS_GOTIE20:
  938. case R_390_TLS_IEENT:
  939. tls_type = GOT_TLS_IE_NLT;
  940. break;
  941. }
  942. if (h != NULL)
  943. {
  944. h->got.refcount += 1;
  945. old_tls_type = elf_s390_hash_entry(h)->tls_type;
  946. }
  947. else
  948. {
  949. local_got_refcounts[r_symndx] += 1;
  950. old_tls_type = elf_s390_local_got_tls_type (abfd) [r_symndx];
  951. }
  952. /* If a TLS symbol is accessed using IE at least once,
  953. there is no point to use dynamic model for it. */
  954. if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN)
  955. {
  956. if (old_tls_type == GOT_NORMAL || tls_type == GOT_NORMAL)
  957. {
  958. _bfd_error_handler
  959. /* xgettext:c-format */
  960. (_("%pB: `%s' accessed both as normal and thread local symbol"),
  961. abfd, h->root.root.string);
  962. return false;
  963. }
  964. if (old_tls_type > tls_type)
  965. tls_type = old_tls_type;
  966. }
  967. if (old_tls_type != tls_type)
  968. {
  969. if (h != NULL)
  970. elf_s390_hash_entry (h)->tls_type = tls_type;
  971. else
  972. elf_s390_local_got_tls_type (abfd) [r_symndx] = tls_type;
  973. }
  974. if (r_type != R_390_TLS_IE64)
  975. break;
  976. /* Fall through */
  977. case R_390_TLS_LE64:
  978. /* For static linking and executables this reloc will be
  979. calculated at linktime otherwise a TLS_TPOFF runtime
  980. reloc will be generated. */
  981. if (r_type == R_390_TLS_LE64 && bfd_link_pie (info))
  982. break;
  983. if (!bfd_link_pic (info))
  984. break;
  985. info->flags |= DF_STATIC_TLS;
  986. /* Fall through */
  987. case R_390_8:
  988. case R_390_16:
  989. case R_390_32:
  990. case R_390_64:
  991. case R_390_PC12DBL:
  992. case R_390_PC16:
  993. case R_390_PC16DBL:
  994. case R_390_PC24DBL:
  995. case R_390_PC32:
  996. case R_390_PC32DBL:
  997. case R_390_PC64:
  998. if (h != NULL && bfd_link_executable (info))
  999. {
  1000. /* If this reloc is in a read-only section, we might
  1001. need a copy reloc. We can't check reliably at this
  1002. stage whether the section is read-only, as input
  1003. sections have not yet been mapped to output sections.
  1004. Tentatively set the flag for now, and correct in
  1005. adjust_dynamic_symbol. */
  1006. h->non_got_ref = 1;
  1007. if (!bfd_link_pic (info))
  1008. {
  1009. /* We may need a .plt entry if the function this reloc
  1010. refers to is in a shared lib. */
  1011. h->plt.refcount += 1;
  1012. }
  1013. }
  1014. /* If we are creating a shared library, and this is a reloc
  1015. against a global symbol, or a non PC relative reloc
  1016. against a local symbol, then we need to copy the reloc
  1017. into the shared library. However, if we are linking with
  1018. -Bsymbolic, we do not need to copy a reloc against a
  1019. global symbol which is defined in an object we are
  1020. including in the link (i.e., DEF_REGULAR is set). At
  1021. this point we have not seen all the input files, so it is
  1022. possible that DEF_REGULAR is not set now but will be set
  1023. later (it is never cleared). In case of a weak definition,
  1024. DEF_REGULAR may be cleared later by a strong definition in
  1025. a shared library. We account for that possibility below by
  1026. storing information in the relocs_copied field of the hash
  1027. table entry. A similar situation occurs when creating
  1028. shared libraries and symbol visibility changes render the
  1029. symbol local.
  1030. If on the other hand, we are creating an executable, we
  1031. may need to keep relocations for symbols satisfied by a
  1032. dynamic library if we manage to avoid copy relocs for the
  1033. symbol. */
  1034. if ((bfd_link_pic (info)
  1035. && (sec->flags & SEC_ALLOC) != 0
  1036. && ((ELF64_R_TYPE (rel->r_info) != R_390_PC16
  1037. && ELF64_R_TYPE (rel->r_info) != R_390_PC12DBL
  1038. && ELF64_R_TYPE (rel->r_info) != R_390_PC16DBL
  1039. && ELF64_R_TYPE (rel->r_info) != R_390_PC24DBL
  1040. && ELF64_R_TYPE (rel->r_info) != R_390_PC32
  1041. && ELF64_R_TYPE (rel->r_info) != R_390_PC32DBL
  1042. && ELF64_R_TYPE (rel->r_info) != R_390_PC64)
  1043. || (h != NULL
  1044. && (! SYMBOLIC_BIND (info, h)
  1045. || h->root.type == bfd_link_hash_defweak
  1046. || !h->def_regular))))
  1047. || (ELIMINATE_COPY_RELOCS
  1048. && !bfd_link_pic (info)
  1049. && (sec->flags & SEC_ALLOC) != 0
  1050. && h != NULL
  1051. && (h->root.type == bfd_link_hash_defweak
  1052. || !h->def_regular)))
  1053. {
  1054. struct elf_dyn_relocs *p;
  1055. struct elf_dyn_relocs **head;
  1056. /* We must copy these reloc types into the output file.
  1057. Create a reloc section in dynobj and make room for
  1058. this reloc. */
  1059. if (sreloc == NULL)
  1060. {
  1061. if (htab->elf.dynobj == NULL)
  1062. htab->elf.dynobj = abfd;
  1063. sreloc = _bfd_elf_make_dynamic_reloc_section
  1064. (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ true);
  1065. if (sreloc == NULL)
  1066. return false;
  1067. }
  1068. /* If this is a global symbol, we count the number of
  1069. relocations we need for this symbol. */
  1070. if (h != NULL)
  1071. {
  1072. head = &h->dyn_relocs;
  1073. }
  1074. else
  1075. {
  1076. /* Track dynamic relocs needed for local syms too.
  1077. We really need local syms available to do this
  1078. easily. Oh well. */
  1079. asection *s;
  1080. void *vpp;
  1081. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
  1082. abfd, r_symndx);
  1083. if (isym == NULL)
  1084. return false;
  1085. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1086. if (s == NULL)
  1087. s = sec;
  1088. vpp = &elf_section_data (s)->local_dynrel;
  1089. head = (struct elf_dyn_relocs **) vpp;
  1090. }
  1091. p = *head;
  1092. if (p == NULL || p->sec != sec)
  1093. {
  1094. size_t amt = sizeof *p;
  1095. p = ((struct elf_dyn_relocs *)
  1096. bfd_alloc (htab->elf.dynobj, amt));
  1097. if (p == NULL)
  1098. return false;
  1099. p->next = *head;
  1100. *head = p;
  1101. p->sec = sec;
  1102. p->count = 0;
  1103. p->pc_count = 0;
  1104. }
  1105. p->count += 1;
  1106. if (ELF64_R_TYPE (rel->r_info) == R_390_PC16
  1107. || ELF64_R_TYPE (rel->r_info) == R_390_PC12DBL
  1108. || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL
  1109. || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL
  1110. || ELF64_R_TYPE (rel->r_info) == R_390_PC32
  1111. || ELF64_R_TYPE (rel->r_info) == R_390_PC32DBL
  1112. || ELF64_R_TYPE (rel->r_info) == R_390_PC64)
  1113. p->pc_count += 1;
  1114. }
  1115. break;
  1116. /* This relocation describes the C++ object vtable hierarchy.
  1117. Reconstruct it for later use during GC. */
  1118. case R_390_GNU_VTINHERIT:
  1119. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  1120. return false;
  1121. break;
  1122. /* This relocation describes which C++ vtable entries are actually
  1123. used. Record for later use during GC. */
  1124. case R_390_GNU_VTENTRY:
  1125. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  1126. return false;
  1127. break;
  1128. default:
  1129. break;
  1130. }
  1131. }
  1132. return true;
  1133. }
  1134. /* Return the section that should be marked against GC for a given
  1135. relocation. */
  1136. static asection *
  1137. elf_s390_gc_mark_hook (asection *sec,
  1138. struct bfd_link_info *info,
  1139. Elf_Internal_Rela *rel,
  1140. struct elf_link_hash_entry *h,
  1141. Elf_Internal_Sym *sym)
  1142. {
  1143. if (h != NULL)
  1144. switch (ELF64_R_TYPE (rel->r_info))
  1145. {
  1146. case R_390_GNU_VTINHERIT:
  1147. case R_390_GNU_VTENTRY:
  1148. return NULL;
  1149. }
  1150. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  1151. }
  1152. /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
  1153. entry but we found we will not create any. Called when we find we will
  1154. not have any PLT for this symbol, by for example
  1155. elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
  1156. or elf_s390_size_dynamic_sections if no dynamic sections will be
  1157. created (we're only linking static objects). */
  1158. static void
  1159. elf_s390_adjust_gotplt (struct elf_s390_link_hash_entry *h)
  1160. {
  1161. if (h->elf.root.type == bfd_link_hash_warning)
  1162. h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link;
  1163. if (h->gotplt_refcount <= 0)
  1164. return;
  1165. /* We simply add the number of gotplt references to the number
  1166. * of got references for this symbol. */
  1167. h->elf.got.refcount += h->gotplt_refcount;
  1168. h->gotplt_refcount = -1;
  1169. }
  1170. /* Adjust a symbol defined by a dynamic object and referenced by a
  1171. regular object. The current definition is in some section of the
  1172. dynamic object, but we're not including those sections. We have to
  1173. change the definition to something the rest of the link can
  1174. understand. */
  1175. static bool
  1176. elf_s390_adjust_dynamic_symbol (struct bfd_link_info *info,
  1177. struct elf_link_hash_entry *h)
  1178. {
  1179. struct elf_s390_link_hash_table *htab;
  1180. asection *s, *srel;
  1181. /* STT_GNU_IFUNC symbol must go through PLT. */
  1182. if (s390_is_ifunc_symbol_p (h))
  1183. {
  1184. /* All local STT_GNU_IFUNC references must be treated as local
  1185. calls via local PLT. */
  1186. if (h->ref_regular && SYMBOL_CALLS_LOCAL (info, h))
  1187. {
  1188. bfd_size_type pc_count = 0, count = 0;
  1189. struct elf_dyn_relocs **pp;
  1190. struct elf_dyn_relocs *p;
  1191. for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
  1192. {
  1193. pc_count += p->pc_count;
  1194. p->count -= p->pc_count;
  1195. p->pc_count = 0;
  1196. count += p->count;
  1197. if (p->count == 0)
  1198. *pp = p->next;
  1199. else
  1200. pp = &p->next;
  1201. }
  1202. if (pc_count || count)
  1203. {
  1204. h->needs_plt = 1;
  1205. h->non_got_ref = 1;
  1206. if (h->plt.refcount <= 0)
  1207. h->plt.refcount = 1;
  1208. else
  1209. h->plt.refcount += 1;
  1210. }
  1211. }
  1212. if (h->plt.refcount <= 0)
  1213. {
  1214. h->plt.offset = (bfd_vma) -1;
  1215. h->needs_plt = 0;
  1216. }
  1217. return true;
  1218. }
  1219. /* If this is a function, put it in the procedure linkage table. We
  1220. will fill in the contents of the procedure linkage table later
  1221. (although we could actually do it here). */
  1222. if (h->type == STT_FUNC
  1223. || h->needs_plt)
  1224. {
  1225. if (h->plt.refcount <= 0
  1226. || SYMBOL_CALLS_LOCAL (info, h)
  1227. || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  1228. {
  1229. /* This case can occur if we saw a PLT32 reloc in an input
  1230. file, but the symbol was never referred to by a dynamic
  1231. object, or if all references were garbage collected. In
  1232. such a case, we don't actually need to build a procedure
  1233. linkage table, and we can just do a PC32 reloc instead. */
  1234. h->plt.offset = (bfd_vma) -1;
  1235. h->needs_plt = 0;
  1236. elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
  1237. }
  1238. return true;
  1239. }
  1240. else
  1241. /* It's possible that we incorrectly decided a .plt reloc was
  1242. needed for an R_390_PC32 reloc to a non-function sym in
  1243. check_relocs. We can't decide accurately between function and
  1244. non-function syms in check-relocs; Objects loaded later in
  1245. the link may change h->type. So fix it now. */
  1246. h->plt.offset = (bfd_vma) -1;
  1247. /* If this is a weak symbol, and there is a real definition, the
  1248. processor independent code will have arranged for us to see the
  1249. real definition first, and we can just use the same value. */
  1250. if (h->is_weakalias)
  1251. {
  1252. struct elf_link_hash_entry *def = weakdef (h);
  1253. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  1254. h->root.u.def.section = def->root.u.def.section;
  1255. h->root.u.def.value = def->root.u.def.value;
  1256. if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
  1257. h->non_got_ref = def->non_got_ref;
  1258. return true;
  1259. }
  1260. /* This is a reference to a symbol defined by a dynamic object which
  1261. is not a function. */
  1262. /* If we are creating a shared library, we must presume that the
  1263. only references to the symbol are via the global offset table.
  1264. For such cases we need not do anything here; the relocations will
  1265. be handled correctly by relocate_section. */
  1266. if (bfd_link_pic (info))
  1267. return true;
  1268. /* If there are no references to this symbol that do not use the
  1269. GOT, we don't need to generate a copy reloc. */
  1270. if (!h->non_got_ref)
  1271. return true;
  1272. /* If -z nocopyreloc was given, we won't generate them either. */
  1273. if (info->nocopyreloc)
  1274. {
  1275. h->non_got_ref = 0;
  1276. return true;
  1277. }
  1278. /* If we don't find any dynamic relocs in read-only sections, then
  1279. we'll be keeping the dynamic relocs and avoiding the copy reloc. */
  1280. if (ELIMINATE_COPY_RELOCS && !_bfd_elf_readonly_dynrelocs (h))
  1281. {
  1282. h->non_got_ref = 0;
  1283. return true;
  1284. }
  1285. /* We must allocate the symbol in our .dynbss section, which will
  1286. become part of the .bss section of the executable. There will be
  1287. an entry for this symbol in the .dynsym section. The dynamic
  1288. object will contain position independent code, so all references
  1289. from the dynamic object to this symbol will go through the global
  1290. offset table. The dynamic linker will use the .dynsym entry to
  1291. determine the address it must put in the global offset table, so
  1292. both the dynamic object and the regular object will refer to the
  1293. same memory location for the variable. */
  1294. htab = elf_s390_hash_table (info);
  1295. if (htab == NULL)
  1296. return false;
  1297. /* We must generate a R_390_COPY reloc to tell the dynamic linker to
  1298. copy the initial value out of the dynamic object and into the
  1299. runtime process image. */
  1300. if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
  1301. {
  1302. s = htab->elf.sdynrelro;
  1303. srel = htab->elf.sreldynrelro;
  1304. }
  1305. else
  1306. {
  1307. s = htab->elf.sdynbss;
  1308. srel = htab->elf.srelbss;
  1309. }
  1310. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  1311. {
  1312. srel->size += sizeof (Elf64_External_Rela);
  1313. h->needs_copy = 1;
  1314. }
  1315. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  1316. }
  1317. /* Allocate space in .plt, .got and associated reloc sections for
  1318. dynamic relocs. */
  1319. static bool
  1320. allocate_dynrelocs (struct elf_link_hash_entry *h,
  1321. void * inf)
  1322. {
  1323. struct bfd_link_info *info;
  1324. struct elf_s390_link_hash_table *htab;
  1325. struct elf_dyn_relocs *p;
  1326. if (h->root.type == bfd_link_hash_indirect)
  1327. return true;
  1328. info = (struct bfd_link_info *) inf;
  1329. htab = elf_s390_hash_table (info);
  1330. if (htab == NULL)
  1331. return false;
  1332. /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
  1333. here if it is defined and referenced in a non-shared object. */
  1334. if (s390_is_ifunc_symbol_p (h) && h->def_regular)
  1335. return s390_elf_allocate_ifunc_dyn_relocs (info, h);
  1336. else if (htab->elf.dynamic_sections_created
  1337. && h->plt.refcount > 0)
  1338. {
  1339. /* Make sure this symbol is output as a dynamic symbol.
  1340. Undefined weak syms won't yet be marked as dynamic. */
  1341. if (h->dynindx == -1
  1342. && !h->forced_local)
  1343. {
  1344. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1345. return false;
  1346. }
  1347. if (bfd_link_pic (info)
  1348. || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
  1349. {
  1350. asection *s = htab->elf.splt;
  1351. /* If this is the first .plt entry, make room for the special
  1352. first entry. */
  1353. if (s->size == 0)
  1354. s->size += PLT_FIRST_ENTRY_SIZE;
  1355. h->plt.offset = s->size;
  1356. /* If this symbol is not defined in a regular file, and we are
  1357. not generating a shared library, then set the symbol to this
  1358. location in the .plt. This is required to make function
  1359. pointers compare as equal between the normal executable and
  1360. the shared library. */
  1361. if (! bfd_link_pic (info)
  1362. && !h->def_regular)
  1363. {
  1364. h->root.u.def.section = s;
  1365. h->root.u.def.value = h->plt.offset;
  1366. }
  1367. /* Make room for this entry. */
  1368. s->size += PLT_ENTRY_SIZE;
  1369. /* We also need to make an entry in the .got.plt section. */
  1370. htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
  1371. /* We also need to make an entry in the .rela.plt section. */
  1372. htab->elf.srelplt->size += sizeof (Elf64_External_Rela);
  1373. }
  1374. else
  1375. {
  1376. h->plt.offset = (bfd_vma) -1;
  1377. h->needs_plt = 0;
  1378. elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
  1379. }
  1380. }
  1381. else
  1382. {
  1383. h->plt.offset = (bfd_vma) -1;
  1384. h->needs_plt = 0;
  1385. elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
  1386. }
  1387. /* If R_390_TLS_{IE64,GOTIE64,GOTIE12,IEENT} symbol is now local to
  1388. the binary, we can optimize a bit. IE64 and GOTIE64 get converted
  1389. to R_390_TLS_LE64 requiring no TLS entry. For GOTIE12 and IEENT
  1390. we can save the dynamic TLS relocation. */
  1391. if (h->got.refcount > 0
  1392. && !bfd_link_pic (info)
  1393. && h->dynindx == -1
  1394. && elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE)
  1395. {
  1396. if (elf_s390_hash_entry(h)->tls_type == GOT_TLS_IE_NLT)
  1397. /* For the GOTIE access without a literal pool entry the offset has
  1398. to be stored somewhere. The immediate value in the instruction
  1399. is not bit enough so the value is stored in the got. */
  1400. {
  1401. h->got.offset = htab->elf.sgot->size;
  1402. htab->elf.sgot->size += GOT_ENTRY_SIZE;
  1403. }
  1404. else
  1405. h->got.offset = (bfd_vma) -1;
  1406. }
  1407. else if (h->got.refcount > 0)
  1408. {
  1409. asection *s;
  1410. bool dyn;
  1411. int tls_type = elf_s390_hash_entry(h)->tls_type;
  1412. /* Make sure this symbol is output as a dynamic symbol.
  1413. Undefined weak syms won't yet be marked as dynamic. */
  1414. if (h->dynindx == -1
  1415. && !h->forced_local)
  1416. {
  1417. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1418. return false;
  1419. }
  1420. s = htab->elf.sgot;
  1421. h->got.offset = s->size;
  1422. s->size += GOT_ENTRY_SIZE;
  1423. /* R_390_TLS_GD64 needs 2 consecutive GOT slots. */
  1424. if (tls_type == GOT_TLS_GD)
  1425. s->size += GOT_ENTRY_SIZE;
  1426. dyn = htab->elf.dynamic_sections_created;
  1427. /* R_390_TLS_IE64 needs one dynamic relocation,
  1428. R_390_TLS_GD64 needs one if local symbol and two if global. */
  1429. if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
  1430. || tls_type >= GOT_TLS_IE)
  1431. htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
  1432. else if (tls_type == GOT_TLS_GD)
  1433. htab->elf.srelgot->size += 2 * sizeof (Elf64_External_Rela);
  1434. else if (!UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)
  1435. && (bfd_link_pic (info)
  1436. || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
  1437. htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
  1438. }
  1439. else
  1440. h->got.offset = (bfd_vma) -1;
  1441. if (h->dyn_relocs == NULL)
  1442. return true;
  1443. /* In the shared -Bsymbolic case, discard space allocated for
  1444. dynamic pc-relative relocs against symbols which turn out to be
  1445. defined in regular objects. For the normal shared case, discard
  1446. space for pc-relative relocs that have become local due to symbol
  1447. visibility changes. */
  1448. if (bfd_link_pic (info))
  1449. {
  1450. if (SYMBOL_CALLS_LOCAL (info, h))
  1451. {
  1452. struct elf_dyn_relocs **pp;
  1453. for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
  1454. {
  1455. p->count -= p->pc_count;
  1456. p->pc_count = 0;
  1457. if (p->count == 0)
  1458. *pp = p->next;
  1459. else
  1460. pp = &p->next;
  1461. }
  1462. }
  1463. /* Also discard relocs on undefined weak syms with non-default
  1464. visibility. */
  1465. if (h->dyn_relocs != NULL
  1466. && h->root.type == bfd_link_hash_undefweak)
  1467. {
  1468. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  1469. || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  1470. h->dyn_relocs = NULL;
  1471. /* Make sure undefined weak symbols are output as a dynamic
  1472. symbol in PIEs. */
  1473. else if (h->dynindx == -1
  1474. && !h->forced_local)
  1475. {
  1476. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1477. return false;
  1478. }
  1479. }
  1480. }
  1481. else if (ELIMINATE_COPY_RELOCS)
  1482. {
  1483. /* For the non-shared case, discard space for relocs against
  1484. symbols which turn out to need copy relocs or are not
  1485. dynamic. */
  1486. if (!h->non_got_ref
  1487. && ((h->def_dynamic
  1488. && !h->def_regular)
  1489. || (htab->elf.dynamic_sections_created
  1490. && (h->root.type == bfd_link_hash_undefweak
  1491. || h->root.type == bfd_link_hash_undefined))))
  1492. {
  1493. /* Make sure this symbol is output as a dynamic symbol.
  1494. Undefined weak syms won't yet be marked as dynamic. */
  1495. if (h->dynindx == -1
  1496. && !h->forced_local)
  1497. {
  1498. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1499. return false;
  1500. }
  1501. /* If that succeeded, we know we'll be keeping all the
  1502. relocs. */
  1503. if (h->dynindx != -1)
  1504. goto keep;
  1505. }
  1506. h->dyn_relocs = NULL;
  1507. keep: ;
  1508. }
  1509. /* Finally, allocate space. */
  1510. for (p = h->dyn_relocs; p != NULL; p = p->next)
  1511. {
  1512. asection *sreloc = elf_section_data (p->sec)->sreloc;
  1513. sreloc->size += p->count * sizeof (Elf64_External_Rela);
  1514. }
  1515. return true;
  1516. }
  1517. /* Set the sizes of the dynamic sections. */
  1518. static bool
  1519. elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  1520. struct bfd_link_info *info)
  1521. {
  1522. struct elf_s390_link_hash_table *htab;
  1523. bfd *dynobj;
  1524. asection *s;
  1525. bool relocs;
  1526. bfd *ibfd;
  1527. htab = elf_s390_hash_table (info);
  1528. if (htab == NULL)
  1529. return false;
  1530. dynobj = htab->elf.dynobj;
  1531. if (dynobj == NULL)
  1532. abort ();
  1533. if (htab->elf.dynamic_sections_created)
  1534. {
  1535. /* Set the contents of the .interp section to the interpreter. */
  1536. if (bfd_link_executable (info) && !info->nointerp)
  1537. {
  1538. s = bfd_get_linker_section (dynobj, ".interp");
  1539. if (s == NULL)
  1540. abort ();
  1541. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  1542. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  1543. }
  1544. }
  1545. if (htab->elf.sgot && s390_gotplt_after_got_p (info))
  1546. {
  1547. /* _bfd_elf_create_got_section adds the got header size always
  1548. to .got.plt but we need it in .got if this section comes
  1549. first. */
  1550. htab->elf.sgot->size += 3 * GOT_ENTRY_SIZE;
  1551. htab->elf.sgotplt->size -= 3 * GOT_ENTRY_SIZE;
  1552. /* Make the _GLOBAL_OFFSET_TABLE_ symbol point to the .got
  1553. instead of .got.plt. */
  1554. htab->elf.hgot->root.u.def.section = htab->elf.sgot;
  1555. htab->elf.hgot->root.u.def.value = 0;
  1556. }
  1557. /* Set up .got offsets for local syms, and space for local dynamic
  1558. relocs. */
  1559. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  1560. {
  1561. bfd_signed_vma *local_got;
  1562. bfd_signed_vma *end_local_got;
  1563. char *local_tls_type;
  1564. bfd_size_type locsymcount;
  1565. Elf_Internal_Shdr *symtab_hdr;
  1566. asection *srela;
  1567. struct plt_entry *local_plt;
  1568. unsigned int i;
  1569. if (! is_s390_elf (ibfd))
  1570. continue;
  1571. for (s = ibfd->sections; s != NULL; s = s->next)
  1572. {
  1573. struct elf_dyn_relocs *p;
  1574. for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
  1575. {
  1576. if (!bfd_is_abs_section (p->sec)
  1577. && bfd_is_abs_section (p->sec->output_section))
  1578. {
  1579. /* Input section has been discarded, either because
  1580. it is a copy of a linkonce section or due to
  1581. linker script /DISCARD/, so we'll be discarding
  1582. the relocs too. */
  1583. }
  1584. else if (p->count != 0)
  1585. {
  1586. srela = elf_section_data (p->sec)->sreloc;
  1587. srela->size += p->count * sizeof (Elf64_External_Rela);
  1588. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  1589. info->flags |= DF_TEXTREL;
  1590. }
  1591. }
  1592. }
  1593. local_got = elf_local_got_refcounts (ibfd);
  1594. if (!local_got)
  1595. continue;
  1596. symtab_hdr = &elf_symtab_hdr (ibfd);
  1597. locsymcount = symtab_hdr->sh_info;
  1598. end_local_got = local_got + locsymcount;
  1599. local_tls_type = elf_s390_local_got_tls_type (ibfd);
  1600. s = htab->elf.sgot;
  1601. srela = htab->elf.srelgot;
  1602. for (; local_got < end_local_got; ++local_got, ++local_tls_type)
  1603. {
  1604. if (*local_got > 0)
  1605. {
  1606. *local_got = s->size;
  1607. s->size += GOT_ENTRY_SIZE;
  1608. if (*local_tls_type == GOT_TLS_GD)
  1609. s->size += GOT_ENTRY_SIZE;
  1610. if (bfd_link_pic (info))
  1611. srela->size += sizeof (Elf64_External_Rela);
  1612. }
  1613. else
  1614. *local_got = (bfd_vma) -1;
  1615. }
  1616. local_plt = elf_s390_local_plt (ibfd);
  1617. for (i = 0; i < symtab_hdr->sh_info; i++)
  1618. {
  1619. if (local_plt[i].plt.refcount > 0)
  1620. {
  1621. local_plt[i].plt.offset = htab->elf.iplt->size;
  1622. htab->elf.iplt->size += PLT_ENTRY_SIZE;
  1623. htab->elf.igotplt->size += GOT_ENTRY_SIZE;
  1624. htab->elf.irelplt->size += sizeof (Elf64_External_Rela);
  1625. }
  1626. else
  1627. local_plt[i].plt.offset = (bfd_vma) -1;
  1628. }
  1629. }
  1630. if (htab->tls_ldm_got.refcount > 0)
  1631. {
  1632. /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM64
  1633. relocs. */
  1634. htab->tls_ldm_got.offset = htab->elf.sgot->size;
  1635. htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
  1636. htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
  1637. }
  1638. else
  1639. htab->tls_ldm_got.offset = -1;
  1640. /* Allocate global sym .plt and .got entries, and space for global
  1641. sym dynamic relocs. */
  1642. elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
  1643. /* We now have determined the sizes of the various dynamic sections.
  1644. Allocate memory for them. */
  1645. relocs = false;
  1646. for (s = dynobj->sections; s != NULL; s = s->next)
  1647. {
  1648. if ((s->flags & SEC_LINKER_CREATED) == 0)
  1649. continue;
  1650. if (s == htab->elf.splt
  1651. || s == htab->elf.sgot
  1652. || s == htab->elf.sgotplt
  1653. || s == htab->elf.sdynbss
  1654. || s == htab->elf.sdynrelro
  1655. || s == htab->elf.iplt
  1656. || s == htab->elf.igotplt
  1657. || s == htab->irelifunc)
  1658. {
  1659. /* Strip this section if we don't need it; see the
  1660. comment below. */
  1661. }
  1662. else if (startswith (bfd_section_name (s), ".rela"))
  1663. {
  1664. if (s->size != 0 && s != htab->elf.srelplt)
  1665. relocs = true;
  1666. /* We use the reloc_count field as a counter if we need
  1667. to copy relocs into the output file. */
  1668. s->reloc_count = 0;
  1669. }
  1670. else
  1671. {
  1672. /* It's not one of our sections, so don't allocate space. */
  1673. continue;
  1674. }
  1675. if (s->size == 0)
  1676. {
  1677. /* If we don't need this section, strip it from the
  1678. output file. This is to handle .rela.bss and
  1679. .rela.plt. We must create it in
  1680. create_dynamic_sections, because it must be created
  1681. before the linker maps input sections to output
  1682. sections. The linker does that before
  1683. adjust_dynamic_symbol is called, and it is that
  1684. function which decides whether anything needs to go
  1685. into these sections. */
  1686. s->flags |= SEC_EXCLUDE;
  1687. continue;
  1688. }
  1689. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  1690. continue;
  1691. /* Allocate memory for the section contents. We use bfd_zalloc
  1692. here in case unused entries are not reclaimed before the
  1693. section's contents are written out. This should not happen,
  1694. but this way if it does, we get a R_390_NONE reloc instead
  1695. of garbage. */
  1696. s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
  1697. if (s->contents == NULL)
  1698. return false;
  1699. }
  1700. return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
  1701. }
  1702. /* Return the base VMA address which should be subtracted from real addresses
  1703. when resolving @dtpoff relocation.
  1704. This is PT_TLS segment p_vaddr. */
  1705. static bfd_vma
  1706. dtpoff_base (struct bfd_link_info *info)
  1707. {
  1708. /* If tls_sec is NULL, we should have signalled an error already. */
  1709. if (elf_hash_table (info)->tls_sec == NULL)
  1710. return 0;
  1711. return elf_hash_table (info)->tls_sec->vma;
  1712. }
  1713. /* Return the relocation value for @tpoff relocation
  1714. if STT_TLS virtual address is ADDRESS. */
  1715. static bfd_vma
  1716. tpoff (struct bfd_link_info *info, bfd_vma address)
  1717. {
  1718. struct elf_link_hash_table *htab = elf_hash_table (info);
  1719. /* If tls_sec is NULL, we should have signalled an error already. */
  1720. if (htab->tls_sec == NULL)
  1721. return 0;
  1722. return htab->tls_size + htab->tls_sec->vma - address;
  1723. }
  1724. /* Complain if TLS instruction relocation is against an invalid
  1725. instruction. */
  1726. static void
  1727. invalid_tls_insn (bfd *input_bfd,
  1728. asection *input_section,
  1729. Elf_Internal_Rela *rel)
  1730. {
  1731. reloc_howto_type *howto;
  1732. howto = elf_howto_table + ELF64_R_TYPE (rel->r_info);
  1733. _bfd_error_handler
  1734. /* xgettext:c-format */
  1735. (_("%pB(%pA+%#" PRIx64 "): invalid instruction for TLS relocation %s"),
  1736. input_bfd,
  1737. input_section,
  1738. (uint64_t) rel->r_offset,
  1739. howto->name);
  1740. bfd_set_error (bfd_error_bad_value);
  1741. }
  1742. /* Relocate a 390 ELF section. */
  1743. static int
  1744. elf_s390_relocate_section (bfd *output_bfd,
  1745. struct bfd_link_info *info,
  1746. bfd *input_bfd,
  1747. asection *input_section,
  1748. bfd_byte *contents,
  1749. Elf_Internal_Rela *relocs,
  1750. Elf_Internal_Sym *local_syms,
  1751. asection **local_sections)
  1752. {
  1753. struct elf_s390_link_hash_table *htab;
  1754. Elf_Internal_Shdr *symtab_hdr;
  1755. struct elf_link_hash_entry **sym_hashes;
  1756. bfd_vma *local_got_offsets;
  1757. Elf_Internal_Rela *rel;
  1758. Elf_Internal_Rela *relend;
  1759. if (!is_s390_elf (input_bfd))
  1760. {
  1761. bfd_set_error (bfd_error_wrong_format);
  1762. return false;
  1763. }
  1764. htab = elf_s390_hash_table (info);
  1765. if (htab == NULL)
  1766. return false;
  1767. symtab_hdr = &elf_symtab_hdr (input_bfd);
  1768. sym_hashes = elf_sym_hashes (input_bfd);
  1769. local_got_offsets = elf_local_got_offsets (input_bfd);
  1770. rel = relocs;
  1771. relend = relocs + input_section->reloc_count;
  1772. for (; rel < relend; rel++)
  1773. {
  1774. unsigned int r_type;
  1775. reloc_howto_type *howto;
  1776. unsigned long r_symndx;
  1777. struct elf_link_hash_entry *h;
  1778. Elf_Internal_Sym *sym;
  1779. asection *sec;
  1780. bfd_vma off;
  1781. bfd_vma relocation;
  1782. bool unresolved_reloc;
  1783. bfd_reloc_status_type r;
  1784. int tls_type;
  1785. bool resolved_to_zero;
  1786. r_type = ELF64_R_TYPE (rel->r_info);
  1787. if (r_type == (int) R_390_GNU_VTINHERIT
  1788. || r_type == (int) R_390_GNU_VTENTRY)
  1789. continue;
  1790. if (r_type >= (int) R_390_max)
  1791. {
  1792. bfd_set_error (bfd_error_bad_value);
  1793. return false;
  1794. }
  1795. howto = elf_howto_table + r_type;
  1796. r_symndx = ELF64_R_SYM (rel->r_info);
  1797. h = NULL;
  1798. sym = NULL;
  1799. sec = NULL;
  1800. unresolved_reloc = false;
  1801. if (r_symndx < symtab_hdr->sh_info)
  1802. {
  1803. sym = local_syms + r_symndx;
  1804. sec = local_sections[r_symndx];
  1805. if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
  1806. {
  1807. struct plt_entry *local_plt = elf_s390_local_plt (input_bfd);
  1808. if (local_plt == NULL)
  1809. return false;
  1810. /* Address of the PLT slot. */
  1811. relocation = (htab->elf.iplt->output_section->vma
  1812. + htab->elf.iplt->output_offset
  1813. + local_plt[r_symndx].plt.offset);
  1814. switch (r_type)
  1815. {
  1816. case R_390_PLTOFF16:
  1817. case R_390_PLTOFF32:
  1818. case R_390_PLTOFF64:
  1819. relocation -= s390_got_pointer (info);
  1820. break;
  1821. case R_390_GOTPLT12:
  1822. case R_390_GOTPLT16:
  1823. case R_390_GOTPLT20:
  1824. case R_390_GOTPLT32:
  1825. case R_390_GOTPLT64:
  1826. case R_390_GOTPLTENT:
  1827. case R_390_GOT12:
  1828. case R_390_GOT16:
  1829. case R_390_GOT20:
  1830. case R_390_GOT32:
  1831. case R_390_GOT64:
  1832. case R_390_GOTENT:
  1833. {
  1834. /* Write the PLT slot address into the GOT slot. */
  1835. bfd_put_64 (output_bfd, relocation,
  1836. htab->elf.sgot->contents +
  1837. local_got_offsets[r_symndx]);
  1838. relocation = (local_got_offsets[r_symndx] +
  1839. s390_got_offset (info));
  1840. if (r_type == R_390_GOTENT || r_type == R_390_GOTPLTENT)
  1841. relocation += s390_got_pointer (info);
  1842. break;
  1843. }
  1844. default:
  1845. break;
  1846. }
  1847. /* The output section is needed later in
  1848. finish_dynamic_section when creating the dynamic
  1849. relocation. */
  1850. local_plt[r_symndx].sec = sec;
  1851. goto do_relocation;
  1852. }
  1853. else
  1854. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  1855. }
  1856. else
  1857. {
  1858. bool warned ATTRIBUTE_UNUSED;
  1859. bool ignored ATTRIBUTE_UNUSED;
  1860. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  1861. r_symndx, symtab_hdr, sym_hashes,
  1862. h, sec, relocation,
  1863. unresolved_reloc, warned, ignored);
  1864. }
  1865. if (sec != NULL && discarded_section (sec))
  1866. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  1867. rel, 1, relend, howto, 0, contents);
  1868. if (bfd_link_relocatable (info))
  1869. continue;
  1870. resolved_to_zero = (h != NULL
  1871. && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
  1872. switch (r_type)
  1873. {
  1874. case R_390_GOTPLT12:
  1875. case R_390_GOTPLT16:
  1876. case R_390_GOTPLT20:
  1877. case R_390_GOTPLT32:
  1878. case R_390_GOTPLT64:
  1879. case R_390_GOTPLTENT:
  1880. /* There are three cases for a GOTPLT relocation. 1) The
  1881. relocation is against the jump slot entry of a plt that
  1882. will get emitted to the output file. 2) The relocation
  1883. is against the jump slot of a plt entry that has been
  1884. removed. elf_s390_adjust_gotplt has created a GOT entry
  1885. as replacement. 3) The relocation is against a local symbol.
  1886. Cases 2) and 3) are the same as the GOT relocation code
  1887. so we just have to test for case 1 and fall through for
  1888. the other two. */
  1889. if (h != NULL && h->plt.offset != (bfd_vma) -1)
  1890. {
  1891. bfd_vma plt_index;
  1892. if (s390_is_ifunc_symbol_p (h))
  1893. {
  1894. /* Entry indices of .iplt and .igot.plt match
  1895. 1:1. No magic PLT first entry here. */
  1896. plt_index = h->plt.offset / PLT_ENTRY_SIZE;
  1897. relocation = (plt_index * GOT_ENTRY_SIZE
  1898. + s390_gotplt_offset (info)
  1899. + htab->elf.igotplt->output_offset);
  1900. }
  1901. else
  1902. {
  1903. plt_index = ((h->plt.offset - PLT_FIRST_ENTRY_SIZE)
  1904. / PLT_ENTRY_SIZE);
  1905. relocation = (plt_index * GOT_ENTRY_SIZE
  1906. + s390_gotplt_offset (info));
  1907. }
  1908. if (r_type == R_390_GOTPLTENT)
  1909. relocation += s390_got_pointer (info);
  1910. unresolved_reloc = false;
  1911. break;
  1912. }
  1913. /* Fall through. */
  1914. case R_390_GOT12:
  1915. case R_390_GOT16:
  1916. case R_390_GOT20:
  1917. case R_390_GOT32:
  1918. case R_390_GOT64:
  1919. case R_390_GOTENT:
  1920. /* Relocation is to the entry for this symbol in the global
  1921. offset table. */
  1922. if (htab->elf.sgot == NULL)
  1923. abort ();
  1924. if (h != NULL)
  1925. {
  1926. bool dyn;
  1927. off = h->got.offset;
  1928. dyn = htab->elf.dynamic_sections_created;
  1929. if (s390_is_ifunc_symbol_p (h))
  1930. {
  1931. BFD_ASSERT (h->plt.offset != (bfd_vma) -1);
  1932. if (off == (bfd_vma)-1)
  1933. {
  1934. /* No explicit GOT usage so redirect to the
  1935. got.iplt slot. */
  1936. relocation = (s390_gotplt_offset (info)
  1937. + htab->elf.igotplt->output_offset
  1938. + (h->plt.offset / PLT_ENTRY_SIZE
  1939. * GOT_ENTRY_SIZE));
  1940. /* For @GOTENT the relocation is against the offset between
  1941. the instruction and the symbols entry in the GOT and not
  1942. between the start of the GOT and the symbols entry. We
  1943. add the vma of the GOT to get the correct value. */
  1944. if (r_type == R_390_GOTENT || r_type == R_390_GOTPLTENT)
  1945. relocation += s390_got_pointer (info);
  1946. break;
  1947. }
  1948. else
  1949. {
  1950. /* Explicit GOT slots must contain the address
  1951. of the PLT slot. This will be handled in
  1952. finish_dynamic_symbol. */
  1953. }
  1954. }
  1955. else if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  1956. bfd_link_pic (info),
  1957. h)
  1958. || (bfd_link_pic (info)
  1959. && SYMBOL_REFERENCES_LOCAL (info, h))
  1960. || resolved_to_zero)
  1961. {
  1962. Elf_Internal_Sym *isym;
  1963. asection *sym_sec;
  1964. /* This is actually a static link, or it is a
  1965. -Bsymbolic link and the symbol is defined
  1966. locally, or the symbol was forced to be local
  1967. because of a version file. We must initialize
  1968. this entry in the global offset table. Since the
  1969. offset must always be a multiple of 2, we use the
  1970. least significant bit to record whether we have
  1971. initialized it already.
  1972. When doing a dynamic link, we create a .rel.got
  1973. relocation entry to initialize the value. This
  1974. is done in the finish_dynamic_symbol routine. */
  1975. if ((off & 1) != 0)
  1976. off &= ~1;
  1977. else
  1978. {
  1979. bfd_put_64 (output_bfd, relocation,
  1980. htab->elf.sgot->contents + off);
  1981. h->got.offset |= 1;
  1982. }
  1983. /* When turning a GOT slot dereference into a direct
  1984. reference using larl we have to make sure that
  1985. the symbol is 1. properly aligned and 2. it is no
  1986. ABS symbol or will become one. */
  1987. if ((h->def_regular
  1988. && bfd_link_pic (info)
  1989. && SYMBOL_REFERENCES_LOCAL (info, h))
  1990. /* lgrl rx,sym@GOTENT -> larl rx, sym */
  1991. && ((r_type == R_390_GOTENT
  1992. && (bfd_get_16 (input_bfd,
  1993. contents + rel->r_offset - 2)
  1994. & 0xff0f) == 0xc408)
  1995. /* lg rx, sym@GOT(r12) -> larl rx, sym */
  1996. || (r_type == R_390_GOT20
  1997. && (bfd_get_32 (input_bfd,
  1998. contents + rel->r_offset - 2)
  1999. & 0xff00f000) == 0xe300c000
  2000. && bfd_get_8 (input_bfd,
  2001. contents + rel->r_offset + 3) == 0x04))
  2002. && (isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
  2003. input_bfd, r_symndx))
  2004. && isym->st_shndx != SHN_ABS
  2005. && h != htab->elf.hdynamic
  2006. && h != htab->elf.hgot
  2007. && h != htab->elf.hplt
  2008. && !(isym->st_value & 1)
  2009. && (sym_sec = bfd_section_from_elf_index (input_bfd,
  2010. isym->st_shndx))
  2011. && sym_sec->alignment_power)
  2012. {
  2013. unsigned short new_insn =
  2014. (0xc000 | (bfd_get_8 (input_bfd,
  2015. contents + rel->r_offset - 1) & 0xf0));
  2016. bfd_put_16 (output_bfd, new_insn,
  2017. contents + rel->r_offset - 2);
  2018. r_type = R_390_PC32DBL;
  2019. rel->r_addend = 2;
  2020. howto = elf_howto_table + r_type;
  2021. relocation = h->root.u.def.value
  2022. + h->root.u.def.section->output_section->vma
  2023. + h->root.u.def.section->output_offset;
  2024. goto do_relocation;
  2025. }
  2026. }
  2027. else
  2028. unresolved_reloc = false;
  2029. }
  2030. else
  2031. {
  2032. if (local_got_offsets == NULL)
  2033. abort ();
  2034. off = local_got_offsets[r_symndx];
  2035. /* The offset must always be a multiple of 8. We use
  2036. the least significant bit to record whether we have
  2037. already generated the necessary reloc. */
  2038. if ((off & 1) != 0)
  2039. off &= ~1;
  2040. else
  2041. {
  2042. bfd_put_64 (output_bfd, relocation,
  2043. htab->elf.sgot->contents + off);
  2044. if (bfd_link_pic (info))
  2045. {
  2046. asection *s;
  2047. Elf_Internal_Rela outrel;
  2048. bfd_byte *loc;
  2049. s = htab->elf.srelgot;
  2050. if (s == NULL)
  2051. abort ();
  2052. outrel.r_offset = (htab->elf.sgot->output_section->vma
  2053. + htab->elf.sgot->output_offset
  2054. + off);
  2055. outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
  2056. outrel.r_addend = relocation;
  2057. loc = s->contents;
  2058. loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
  2059. bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
  2060. }
  2061. local_got_offsets[r_symndx] |= 1;
  2062. }
  2063. }
  2064. if (off >= (bfd_vma) -2)
  2065. abort ();
  2066. relocation = s390_got_offset (info) + off;
  2067. /* For @GOTENT the relocation is against the offset between
  2068. the instruction and the symbols entry in the GOT and not
  2069. between the start of the GOT and the symbols entry. We
  2070. add the vma of the GOT to get the correct value. */
  2071. if ( r_type == R_390_GOTENT
  2072. || r_type == R_390_GOTPLTENT)
  2073. relocation += s390_got_pointer (info);
  2074. break;
  2075. case R_390_GOTOFF16:
  2076. case R_390_GOTOFF32:
  2077. case R_390_GOTOFF64:
  2078. /* Relocation is relative to the start of the global offset
  2079. table. */
  2080. if (h != NULL
  2081. && s390_is_ifunc_symbol_p (h)
  2082. && h->def_regular
  2083. && !bfd_link_executable (info))
  2084. {
  2085. relocation = (htab->elf.iplt->output_section->vma
  2086. + htab->elf.iplt->output_offset
  2087. + h->plt.offset
  2088. - s390_got_pointer (info));
  2089. goto do_relocation;
  2090. }
  2091. relocation -= s390_got_pointer (info);
  2092. break;
  2093. case R_390_GOTPC:
  2094. case R_390_GOTPCDBL:
  2095. /* Use global offset table as symbol value. */
  2096. relocation = s390_got_pointer (info);
  2097. unresolved_reloc = false;
  2098. break;
  2099. case R_390_PLT12DBL:
  2100. case R_390_PLT16DBL:
  2101. case R_390_PLT24DBL:
  2102. case R_390_PLT32:
  2103. case R_390_PLT32DBL:
  2104. case R_390_PLT64:
  2105. /* Relocation is to the entry for this symbol in the
  2106. procedure linkage table. */
  2107. /* Resolve a PLT32 reloc against a local symbol directly,
  2108. without using the procedure linkage table. */
  2109. if (h == NULL)
  2110. break;
  2111. if (h->plt.offset == (bfd_vma) -1
  2112. || (htab->elf.splt == NULL && !s390_is_ifunc_symbol_p (h)))
  2113. {
  2114. /* We didn't make a PLT entry for this symbol. This
  2115. happens when statically linking PIC code, or when
  2116. using -Bsymbolic. */
  2117. break;
  2118. }
  2119. if (s390_is_ifunc_symbol_p (h))
  2120. relocation = (htab->elf.iplt->output_section->vma
  2121. + htab->elf.iplt->output_offset
  2122. + h->plt.offset);
  2123. else
  2124. relocation = (htab->elf.splt->output_section->vma
  2125. + htab->elf.splt->output_offset
  2126. + h->plt.offset);
  2127. unresolved_reloc = false;
  2128. break;
  2129. case R_390_PLTOFF16:
  2130. case R_390_PLTOFF32:
  2131. case R_390_PLTOFF64:
  2132. /* Relocation is to the entry for this symbol in the
  2133. procedure linkage table relative to the start of the GOT. */
  2134. /* For local symbols or if we didn't make a PLT entry for
  2135. this symbol resolve the symbol directly. */
  2136. if (h == NULL
  2137. || h->plt.offset == (bfd_vma) -1
  2138. || (htab->elf.splt == NULL && !s390_is_ifunc_symbol_p (h)))
  2139. {
  2140. relocation -= s390_got_pointer (info);
  2141. break;
  2142. }
  2143. if (s390_is_ifunc_symbol_p (h))
  2144. relocation = (htab->elf.iplt->output_section->vma
  2145. + htab->elf.iplt->output_offset
  2146. + h->plt.offset
  2147. - s390_got_pointer (info));
  2148. else
  2149. relocation = (htab->elf.splt->output_section->vma
  2150. + htab->elf.splt->output_offset
  2151. + h->plt.offset
  2152. - s390_got_pointer (info));
  2153. unresolved_reloc = false;
  2154. break;
  2155. case R_390_PC16:
  2156. case R_390_PC12DBL:
  2157. case R_390_PC16DBL:
  2158. case R_390_PC24DBL:
  2159. case R_390_PC32:
  2160. case R_390_PC32DBL:
  2161. case R_390_PC64:
  2162. if (h != NULL
  2163. && bfd_link_pie (info)
  2164. && !h->def_regular)
  2165. {
  2166. _bfd_error_handler (_("%pB: `%s' non-PLT reloc for symbol defined "
  2167. "in shared library and accessed "
  2168. "from executable "
  2169. "(rebuild file with -fPIC ?)"),
  2170. input_bfd, h->root.root.string);
  2171. bfd_set_error (bfd_error_bad_value);
  2172. return false;
  2173. }
  2174. /* The target of these relocs are instruction operands
  2175. residing in read-only sections. We cannot emit a runtime
  2176. reloc for it. */
  2177. if (h != NULL
  2178. && s390_is_ifunc_symbol_p (h)
  2179. && h->def_regular
  2180. && bfd_link_pic (info))
  2181. {
  2182. relocation = (htab->elf.iplt->output_section->vma
  2183. + htab->elf.iplt->output_offset
  2184. + h->plt.offset);
  2185. goto do_relocation;
  2186. }
  2187. /* Fall through. */
  2188. case R_390_8:
  2189. case R_390_16:
  2190. case R_390_32:
  2191. case R_390_64:
  2192. if ((input_section->flags & SEC_ALLOC) == 0)
  2193. break;
  2194. if (h != NULL
  2195. && s390_is_ifunc_symbol_p (h)
  2196. && h->def_regular)
  2197. {
  2198. if (!bfd_link_pic (info))
  2199. {
  2200. /* For a non-shared object the symbol will not
  2201. change. Hence we can write the address of the
  2202. target IPLT slot now. */
  2203. relocation = (htab->elf.iplt->output_section->vma
  2204. + htab->elf.iplt->output_offset
  2205. + h ->plt.offset);
  2206. goto do_relocation;
  2207. }
  2208. else
  2209. {
  2210. /* For shared objects a runtime relocation is needed. */
  2211. Elf_Internal_Rela outrel;
  2212. asection *sreloc;
  2213. /* Need a dynamic relocation to get the real function
  2214. address. */
  2215. outrel.r_offset = _bfd_elf_section_offset (output_bfd,
  2216. info,
  2217. input_section,
  2218. rel->r_offset);
  2219. if (outrel.r_offset == (bfd_vma) -1
  2220. || outrel.r_offset == (bfd_vma) -2)
  2221. abort ();
  2222. outrel.r_offset += (input_section->output_section->vma
  2223. + input_section->output_offset);
  2224. if (h->dynindx == -1
  2225. || h->forced_local
  2226. || bfd_link_executable (info))
  2227. {
  2228. /* This symbol is resolved locally. */
  2229. outrel.r_info = ELF64_R_INFO (0, R_390_IRELATIVE);
  2230. outrel.r_addend = (h->root.u.def.value
  2231. + h->root.u.def.section->output_section->vma
  2232. + h->root.u.def.section->output_offset);
  2233. }
  2234. else
  2235. {
  2236. outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
  2237. outrel.r_addend = 0;
  2238. }
  2239. sreloc = htab->elf.irelifunc;
  2240. elf_append_rela (output_bfd, sreloc, &outrel);
  2241. /* If this reloc is against an external symbol, we
  2242. do not want to fiddle with the addend. Otherwise,
  2243. we need to include the symbol value so that it
  2244. becomes an addend for the dynamic reloc. For an
  2245. internal symbol, we have updated addend. */
  2246. continue;
  2247. }
  2248. }
  2249. if ((bfd_link_pic (info)
  2250. && (h == NULL
  2251. || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  2252. && !resolved_to_zero)
  2253. || h->root.type != bfd_link_hash_undefweak)
  2254. && ((r_type != R_390_PC16
  2255. && r_type != R_390_PC12DBL
  2256. && r_type != R_390_PC16DBL
  2257. && r_type != R_390_PC24DBL
  2258. && r_type != R_390_PC32
  2259. && r_type != R_390_PC32DBL
  2260. && r_type != R_390_PC64)
  2261. || !SYMBOL_CALLS_LOCAL (info, h)))
  2262. || (ELIMINATE_COPY_RELOCS
  2263. && !bfd_link_pic (info)
  2264. && h != NULL
  2265. && h->dynindx != -1
  2266. && !h->non_got_ref
  2267. && ((h->def_dynamic
  2268. && !h->def_regular)
  2269. || h->root.type == bfd_link_hash_undefweak
  2270. || h->root.type == bfd_link_hash_undefined)))
  2271. {
  2272. Elf_Internal_Rela outrel;
  2273. bool skip, relocate;
  2274. asection *sreloc;
  2275. bfd_byte *loc;
  2276. /* When generating a shared object, these relocations
  2277. are copied into the output file to be resolved at run
  2278. time. */
  2279. skip = false;
  2280. relocate = false;
  2281. outrel.r_offset =
  2282. _bfd_elf_section_offset (output_bfd, info, input_section,
  2283. rel->r_offset);
  2284. if (outrel.r_offset == (bfd_vma) -1)
  2285. skip = true;
  2286. else if (outrel.r_offset == (bfd_vma) -2)
  2287. skip = true, relocate = true;
  2288. outrel.r_offset += (input_section->output_section->vma
  2289. + input_section->output_offset);
  2290. if (skip)
  2291. memset (&outrel, 0, sizeof outrel);
  2292. else if (h != NULL
  2293. && h->dynindx != -1
  2294. && (r_type == R_390_PC16
  2295. || r_type == R_390_PC12DBL
  2296. || r_type == R_390_PC16DBL
  2297. || r_type == R_390_PC24DBL
  2298. || r_type == R_390_PC32
  2299. || r_type == R_390_PC32DBL
  2300. || r_type == R_390_PC64
  2301. || !bfd_link_pic (info)
  2302. || !SYMBOLIC_BIND (info, h)
  2303. || !h->def_regular))
  2304. {
  2305. outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
  2306. outrel.r_addend = rel->r_addend;
  2307. }
  2308. else
  2309. {
  2310. /* This symbol is local, or marked to become local. */
  2311. outrel.r_addend = relocation + rel->r_addend;
  2312. if (r_type == R_390_64)
  2313. {
  2314. relocate = true;
  2315. outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
  2316. }
  2317. else
  2318. {
  2319. long sindx;
  2320. if (bfd_is_abs_section (sec))
  2321. sindx = 0;
  2322. else if (sec == NULL || sec->owner == NULL)
  2323. {
  2324. bfd_set_error(bfd_error_bad_value);
  2325. return false;
  2326. }
  2327. else
  2328. {
  2329. asection *osec;
  2330. osec = sec->output_section;
  2331. sindx = elf_section_data (osec)->dynindx;
  2332. if (sindx == 0)
  2333. {
  2334. osec = htab->elf.text_index_section;
  2335. sindx = elf_section_data (osec)->dynindx;
  2336. }
  2337. BFD_ASSERT (sindx != 0);
  2338. /* We are turning this relocation into one
  2339. against a section symbol, so subtract out
  2340. the output section's address but not the
  2341. offset of the input section in the output
  2342. section. */
  2343. outrel.r_addend -= osec->vma;
  2344. }
  2345. outrel.r_info = ELF64_R_INFO (sindx, r_type);
  2346. }
  2347. }
  2348. sreloc = elf_section_data (input_section)->sreloc;
  2349. if (sreloc == NULL)
  2350. abort ();
  2351. loc = sreloc->contents;
  2352. loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
  2353. bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
  2354. /* If this reloc is against an external symbol, we do
  2355. not want to fiddle with the addend. Otherwise, we
  2356. need to include the symbol value so that it becomes
  2357. an addend for the dynamic reloc. */
  2358. if (! relocate)
  2359. continue;
  2360. }
  2361. break;
  2362. /* Relocations for tls literal pool entries. */
  2363. case R_390_TLS_IE64:
  2364. if (bfd_link_pic (info))
  2365. {
  2366. Elf_Internal_Rela outrel;
  2367. asection *sreloc;
  2368. bfd_byte *loc;
  2369. outrel.r_offset = rel->r_offset
  2370. + input_section->output_section->vma
  2371. + input_section->output_offset;
  2372. outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
  2373. sreloc = elf_section_data (input_section)->sreloc;
  2374. if (sreloc == NULL)
  2375. abort ();
  2376. loc = sreloc->contents;
  2377. loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
  2378. bfd_elf64_swap_reloc_out (output_bfd, &outrel, loc);
  2379. }
  2380. /* Fall through. */
  2381. case R_390_TLS_GD64:
  2382. case R_390_TLS_GOTIE64:
  2383. r_type = elf_s390_tls_transition (info, r_type, h == NULL);
  2384. tls_type = GOT_UNKNOWN;
  2385. if (h == NULL && local_got_offsets)
  2386. tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
  2387. else if (h != NULL)
  2388. {
  2389. tls_type = elf_s390_hash_entry(h)->tls_type;
  2390. if (!bfd_link_pic (info) && h->dynindx == -1 && tls_type >= GOT_TLS_IE)
  2391. r_type = R_390_TLS_LE64;
  2392. }
  2393. if (r_type == R_390_TLS_GD64 && tls_type >= GOT_TLS_IE)
  2394. r_type = R_390_TLS_IE64;
  2395. if (r_type == R_390_TLS_LE64)
  2396. {
  2397. /* This relocation gets optimized away by the local exec
  2398. access optimization. */
  2399. BFD_ASSERT (! unresolved_reloc);
  2400. bfd_put_64 (output_bfd, -tpoff (info, relocation),
  2401. contents + rel->r_offset);
  2402. continue;
  2403. }
  2404. if (htab->elf.sgot == NULL)
  2405. abort ();
  2406. if (h != NULL)
  2407. off = h->got.offset;
  2408. else
  2409. {
  2410. if (local_got_offsets == NULL)
  2411. abort ();
  2412. off = local_got_offsets[r_symndx];
  2413. }
  2414. emit_tls_relocs:
  2415. if ((off & 1) != 0)
  2416. off &= ~1;
  2417. else
  2418. {
  2419. Elf_Internal_Rela outrel;
  2420. bfd_byte *loc;
  2421. int dr_type, indx;
  2422. if (htab->elf.srelgot == NULL)
  2423. abort ();
  2424. outrel.r_offset = (htab->elf.sgot->output_section->vma
  2425. + htab->elf.sgot->output_offset + off);
  2426. indx = h && h->dynindx != -1 ? h->dynindx : 0;
  2427. if (r_type == R_390_TLS_GD64)
  2428. dr_type = R_390_TLS_DTPMOD;
  2429. else
  2430. dr_type = R_390_TLS_TPOFF;
  2431. if (dr_type == R_390_TLS_TPOFF && indx == 0)
  2432. outrel.r_addend = relocation - dtpoff_base (info);
  2433. else
  2434. outrel.r_addend = 0;
  2435. outrel.r_info = ELF64_R_INFO (indx, dr_type);
  2436. loc = htab->elf.srelgot->contents;
  2437. loc += htab->elf.srelgot->reloc_count++
  2438. * sizeof (Elf64_External_Rela);
  2439. bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
  2440. if (r_type == R_390_TLS_GD64)
  2441. {
  2442. if (indx == 0)
  2443. {
  2444. BFD_ASSERT (! unresolved_reloc);
  2445. bfd_put_64 (output_bfd,
  2446. relocation - dtpoff_base (info),
  2447. htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
  2448. }
  2449. else
  2450. {
  2451. outrel.r_info = ELF64_R_INFO (indx, R_390_TLS_DTPOFF);
  2452. outrel.r_offset += GOT_ENTRY_SIZE;
  2453. outrel.r_addend = 0;
  2454. htab->elf.srelgot->reloc_count++;
  2455. loc += sizeof (Elf64_External_Rela);
  2456. bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
  2457. }
  2458. }
  2459. if (h != NULL)
  2460. h->got.offset |= 1;
  2461. else
  2462. local_got_offsets[r_symndx] |= 1;
  2463. }
  2464. if (off >= (bfd_vma) -2)
  2465. abort ();
  2466. if (r_type == ELF64_R_TYPE (rel->r_info))
  2467. {
  2468. relocation = htab->elf.sgot->output_offset + off;
  2469. if (r_type == R_390_TLS_IE64 || r_type == R_390_TLS_IEENT)
  2470. relocation += htab->elf.sgot->output_section->vma;
  2471. unresolved_reloc = false;
  2472. }
  2473. else
  2474. {
  2475. bfd_put_64 (output_bfd, htab->elf.sgot->output_offset + off,
  2476. contents + rel->r_offset);
  2477. continue;
  2478. }
  2479. break;
  2480. case R_390_TLS_GOTIE12:
  2481. case R_390_TLS_GOTIE20:
  2482. case R_390_TLS_IEENT:
  2483. if (h == NULL)
  2484. {
  2485. if (local_got_offsets == NULL)
  2486. abort();
  2487. off = local_got_offsets[r_symndx];
  2488. if (bfd_link_pic (info))
  2489. goto emit_tls_relocs;
  2490. }
  2491. else
  2492. {
  2493. off = h->got.offset;
  2494. tls_type = elf_s390_hash_entry(h)->tls_type;
  2495. if (bfd_link_pic (info) || h->dynindx != -1 || tls_type < GOT_TLS_IE)
  2496. goto emit_tls_relocs;
  2497. }
  2498. if (htab->elf.sgot == NULL)
  2499. abort ();
  2500. BFD_ASSERT (! unresolved_reloc);
  2501. bfd_put_64 (output_bfd, -tpoff (info, relocation),
  2502. htab->elf.sgot->contents + off);
  2503. relocation = htab->elf.sgot->output_offset + off;
  2504. if (r_type == R_390_TLS_IEENT)
  2505. relocation += htab->elf.sgot->output_section->vma;
  2506. unresolved_reloc = false;
  2507. break;
  2508. case R_390_TLS_LDM64:
  2509. if (! bfd_link_pic (info))
  2510. /* The literal pool entry this relocation refers to gets ignored
  2511. by the optimized code of the local exec model. Do nothing
  2512. and the value will turn out zero. */
  2513. continue;
  2514. if (htab->elf.sgot == NULL)
  2515. abort ();
  2516. off = htab->tls_ldm_got.offset;
  2517. if (off & 1)
  2518. off &= ~1;
  2519. else
  2520. {
  2521. Elf_Internal_Rela outrel;
  2522. bfd_byte *loc;
  2523. if (htab->elf.srelgot == NULL)
  2524. abort ();
  2525. outrel.r_offset = (htab->elf.sgot->output_section->vma
  2526. + htab->elf.sgot->output_offset + off);
  2527. bfd_put_64 (output_bfd, 0,
  2528. htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
  2529. outrel.r_info = ELF64_R_INFO (0, R_390_TLS_DTPMOD);
  2530. outrel.r_addend = 0;
  2531. loc = htab->elf.srelgot->contents;
  2532. loc += htab->elf.srelgot->reloc_count++
  2533. * sizeof (Elf64_External_Rela);
  2534. bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
  2535. htab->tls_ldm_got.offset |= 1;
  2536. }
  2537. relocation = htab->elf.sgot->output_offset + off;
  2538. unresolved_reloc = false;
  2539. break;
  2540. case R_390_TLS_LE64:
  2541. if (bfd_link_dll (info))
  2542. {
  2543. /* Linking a shared library with non-fpic code requires
  2544. a R_390_TLS_TPOFF relocation. */
  2545. Elf_Internal_Rela outrel;
  2546. asection *sreloc;
  2547. bfd_byte *loc;
  2548. int indx;
  2549. outrel.r_offset = rel->r_offset
  2550. + input_section->output_section->vma
  2551. + input_section->output_offset;
  2552. if (h != NULL && h->dynindx != -1)
  2553. indx = h->dynindx;
  2554. else
  2555. indx = 0;
  2556. outrel.r_info = ELF64_R_INFO (indx, R_390_TLS_TPOFF);
  2557. if (indx == 0)
  2558. outrel.r_addend = relocation - dtpoff_base (info);
  2559. else
  2560. outrel.r_addend = 0;
  2561. sreloc = elf_section_data (input_section)->sreloc;
  2562. if (sreloc == NULL)
  2563. abort ();
  2564. loc = sreloc->contents;
  2565. loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
  2566. bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
  2567. }
  2568. else
  2569. {
  2570. BFD_ASSERT (! unresolved_reloc);
  2571. bfd_put_64 (output_bfd, -tpoff (info, relocation),
  2572. contents + rel->r_offset);
  2573. }
  2574. continue;
  2575. case R_390_TLS_LDO64:
  2576. if (bfd_link_pic (info) || (input_section->flags & SEC_DEBUGGING))
  2577. relocation -= dtpoff_base (info);
  2578. else
  2579. /* When converting LDO to LE, we must negate. */
  2580. relocation = -tpoff (info, relocation);
  2581. break;
  2582. /* Relocations for tls instructions. */
  2583. case R_390_TLS_LOAD:
  2584. case R_390_TLS_GDCALL:
  2585. case R_390_TLS_LDCALL:
  2586. tls_type = GOT_UNKNOWN;
  2587. if (h == NULL && local_got_offsets)
  2588. tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
  2589. else if (h != NULL)
  2590. tls_type = elf_s390_hash_entry(h)->tls_type;
  2591. if (tls_type == GOT_TLS_GD)
  2592. continue;
  2593. if (r_type == R_390_TLS_LOAD)
  2594. {
  2595. if (!bfd_link_pic (info) && (h == NULL || h->dynindx == -1))
  2596. {
  2597. /* IE->LE transition. Four valid cases:
  2598. lg %rx,(0,%ry) -> sllg %rx,%ry,0
  2599. lg %rx,(%ry,0) -> sllg %rx,%ry,0
  2600. lg %rx,(%ry,%r12) -> sllg %rx,%ry,0
  2601. lg %rx,(%r12,%ry) -> sllg %rx,%ry,0 */
  2602. unsigned int insn0, insn1, ry;
  2603. insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2604. insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
  2605. if (insn1 != 0x0004)
  2606. {
  2607. invalid_tls_insn (input_bfd, input_section, rel);
  2608. return false;
  2609. }
  2610. if ((insn0 & 0xff00f000) == 0xe3000000)
  2611. /* lg %rx,0(%ry,0) -> sllg %rx,%ry,0 */
  2612. ry = (insn0 & 0x000f0000);
  2613. else if ((insn0 & 0xff0f0000) == 0xe3000000)
  2614. /* lg %rx,0(0,%ry) -> sllg %rx,%ry,0 */
  2615. ry = (insn0 & 0x0000f000) << 4;
  2616. else if ((insn0 & 0xff00f000) == 0xe300c000)
  2617. /* lg %rx,0(%ry,%r12) -> sllg %rx,%ry,0 */
  2618. ry = (insn0 & 0x000f0000);
  2619. else if ((insn0 & 0xff0f0000) == 0xe30c0000)
  2620. /* lg %rx,0(%r12,%ry) -> sllg %rx,%ry,0 */
  2621. ry = (insn0 & 0x0000f000) << 4;
  2622. else
  2623. {
  2624. invalid_tls_insn (input_bfd, input_section, rel);
  2625. return false;
  2626. }
  2627. insn0 = 0xeb000000 | (insn0 & 0x00f00000) | ry;
  2628. insn1 = 0x000d;
  2629. bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
  2630. bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
  2631. }
  2632. }
  2633. else if (r_type == R_390_TLS_GDCALL)
  2634. {
  2635. unsigned int insn0, insn1;
  2636. insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2637. insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
  2638. if ((insn0 & 0xffff0000) != 0xc0e50000)
  2639. {
  2640. invalid_tls_insn (input_bfd, input_section, rel);
  2641. return false;
  2642. }
  2643. if (!bfd_link_pic (info) && (h == NULL || h->dynindx == -1))
  2644. {
  2645. /* GD->LE transition.
  2646. brasl %r14,__tls_get_addr@plt -> brcl 0,. */
  2647. insn0 = 0xc0040000;
  2648. insn1 = 0x0000;
  2649. }
  2650. else
  2651. {
  2652. /* GD->IE transition.
  2653. brasl %r14,__tls_get_addr@plt -> lg %r2,0(%r2,%r12) */
  2654. insn0 = 0xe322c000;
  2655. insn1 = 0x0004;
  2656. }
  2657. bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
  2658. bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
  2659. }
  2660. else if (r_type == R_390_TLS_LDCALL)
  2661. {
  2662. if (!bfd_link_pic (info))
  2663. {
  2664. unsigned int insn0, insn1;
  2665. insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2666. insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
  2667. if ((insn0 & 0xffff0000) != 0xc0e50000)
  2668. {
  2669. invalid_tls_insn (input_bfd, input_section, rel);
  2670. return false;
  2671. }
  2672. /* LD->LE transition.
  2673. brasl %r14,__tls_get_addr@plt -> brcl 0,. */
  2674. insn0 = 0xc0040000;
  2675. insn1 = 0x0000;
  2676. bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
  2677. bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
  2678. }
  2679. }
  2680. continue;
  2681. default:
  2682. break;
  2683. }
  2684. /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
  2685. because such sections are not SEC_ALLOC and thus ld.so will
  2686. not process them. */
  2687. if (unresolved_reloc
  2688. && !((input_section->flags & SEC_DEBUGGING) != 0
  2689. && h->def_dynamic)
  2690. && _bfd_elf_section_offset (output_bfd, info, input_section,
  2691. rel->r_offset) != (bfd_vma) -1)
  2692. _bfd_error_handler
  2693. /* xgettext:c-format */
  2694. (_("%pB(%pA+%#" PRIx64 "): "
  2695. "unresolvable %s relocation against symbol `%s'"),
  2696. input_bfd,
  2697. input_section,
  2698. (uint64_t) rel->r_offset,
  2699. howto->name,
  2700. h->root.root.string);
  2701. do_relocation:
  2702. /* When applying a 24 bit reloc we need to start one byte
  2703. earlier. Otherwise the 32 bit get/put bfd operations might
  2704. access a byte after the actual section. */
  2705. if (r_type == R_390_PC24DBL
  2706. || r_type == R_390_PLT24DBL)
  2707. rel->r_offset--;
  2708. if (r_type == R_390_20
  2709. || r_type == R_390_GOT20
  2710. || r_type == R_390_GOTPLT20
  2711. || r_type == R_390_TLS_GOTIE20)
  2712. {
  2713. relocation += rel->r_addend;
  2714. relocation = (relocation&0xfff) << 8 | (relocation&0xff000) >> 12;
  2715. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  2716. contents, rel->r_offset,
  2717. relocation, 0);
  2718. }
  2719. else
  2720. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  2721. contents, rel->r_offset,
  2722. relocation, rel->r_addend);
  2723. if (r != bfd_reloc_ok)
  2724. {
  2725. const char *name;
  2726. if (h != NULL)
  2727. name = h->root.root.string;
  2728. else
  2729. {
  2730. name = bfd_elf_string_from_elf_section (input_bfd,
  2731. symtab_hdr->sh_link,
  2732. sym->st_name);
  2733. if (name == NULL)
  2734. return false;
  2735. if (*name == '\0')
  2736. name = bfd_section_name (sec);
  2737. }
  2738. if (r == bfd_reloc_overflow)
  2739. (*info->callbacks->reloc_overflow)
  2740. (info, (h ? &h->root : NULL), name, howto->name,
  2741. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  2742. else
  2743. {
  2744. _bfd_error_handler
  2745. /* xgettext:c-format */
  2746. (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
  2747. input_bfd, input_section,
  2748. (uint64_t) rel->r_offset, name, (int) r);
  2749. return false;
  2750. }
  2751. }
  2752. }
  2753. return true;
  2754. }
  2755. /* Generate the PLT slots together with the dynamic relocations needed
  2756. for IFUNC symbols. */
  2757. static void
  2758. elf_s390_finish_ifunc_symbol (bfd *output_bfd,
  2759. struct bfd_link_info *info,
  2760. struct elf_link_hash_entry *h,
  2761. struct elf_s390_link_hash_table *htab,
  2762. bfd_vma plt_offset,
  2763. bfd_vma resolver_address)
  2764. {
  2765. bfd_vma plt_index;
  2766. bfd_vma got_offset;
  2767. Elf_Internal_Rela rela;
  2768. bfd_byte *loc;
  2769. asection *plt, *gotplt, *relplt;
  2770. if (htab->elf.iplt == NULL
  2771. || htab->elf.igotplt == NULL
  2772. || htab->elf.irelplt == NULL)
  2773. abort ();
  2774. /* Index of the PLT slot within iplt section. */
  2775. plt_index = plt_offset / PLT_ENTRY_SIZE;
  2776. plt = htab->elf.iplt;
  2777. /* Offset into the igot.plt section. */
  2778. got_offset = plt_index * GOT_ENTRY_SIZE;
  2779. gotplt = htab->elf.igotplt;
  2780. relplt = htab->elf.irelplt;
  2781. /* Fill in the blueprint of a PLT. */
  2782. memcpy (plt->contents + plt_offset, elf_s390x_plt_entry,
  2783. PLT_ENTRY_SIZE);
  2784. /* Fixup the relative address to the GOT entry */
  2785. bfd_put_32 (output_bfd,
  2786. (gotplt->output_section->vma +
  2787. gotplt->output_offset + got_offset
  2788. - (plt->output_section->vma +
  2789. plt->output_offset +
  2790. plt_offset))/2,
  2791. plt->contents + plt_offset + 2);
  2792. /* Fixup the relative branch to PLT 0 */
  2793. bfd_put_32 (output_bfd, - (plt->output_offset +
  2794. (PLT_ENTRY_SIZE * plt_index) + 22)/2,
  2795. plt->contents + plt_offset + 24);
  2796. /* Fixup offset into .rela.plt section. */
  2797. bfd_put_32 (output_bfd, relplt->output_offset +
  2798. plt_index * sizeof (Elf64_External_Rela),
  2799. plt->contents + plt_offset + 28);
  2800. /* Fill in the entry in the global offset table.
  2801. Points to instruction after GOT offset. */
  2802. bfd_put_64 (output_bfd,
  2803. (plt->output_section->vma
  2804. + plt->output_offset
  2805. + plt_offset
  2806. + 14),
  2807. gotplt->contents + got_offset);
  2808. /* Fill in the entry in the .rela.plt section. */
  2809. rela.r_offset = (gotplt->output_section->vma
  2810. + gotplt->output_offset
  2811. + got_offset);
  2812. if (!h
  2813. || h->dynindx == -1
  2814. || ((bfd_link_executable (info)
  2815. || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  2816. && h->def_regular))
  2817. {
  2818. /* The symbol can be locally resolved. */
  2819. rela.r_info = ELF64_R_INFO (0, R_390_IRELATIVE);
  2820. rela.r_addend = resolver_address;
  2821. }
  2822. else
  2823. {
  2824. rela.r_info = ELF64_R_INFO (h->dynindx, R_390_JMP_SLOT);
  2825. rela.r_addend = 0;
  2826. }
  2827. loc = relplt->contents + plt_index * sizeof (Elf64_External_Rela);
  2828. bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
  2829. }
  2830. /* Finish up dynamic symbol handling. We set the contents of various
  2831. dynamic sections here. */
  2832. static bool
  2833. elf_s390_finish_dynamic_symbol (bfd *output_bfd,
  2834. struct bfd_link_info *info,
  2835. struct elf_link_hash_entry *h,
  2836. Elf_Internal_Sym *sym)
  2837. {
  2838. struct elf_s390_link_hash_table *htab;
  2839. struct elf_s390_link_hash_entry *eh = (struct elf_s390_link_hash_entry*)h;
  2840. htab = elf_s390_hash_table (info);
  2841. if (htab == NULL)
  2842. return false;
  2843. if (h->plt.offset != (bfd_vma) -1)
  2844. {
  2845. bfd_vma plt_index;
  2846. bfd_vma gotplt_offset;
  2847. Elf_Internal_Rela rela;
  2848. bfd_byte *loc;
  2849. /* This symbol has an entry in the procedure linkage table. Set
  2850. it up. */
  2851. if (s390_is_ifunc_symbol_p (h) && h->def_regular)
  2852. {
  2853. elf_s390_finish_ifunc_symbol (output_bfd, info, h,
  2854. htab, h->plt.offset,
  2855. eh->ifunc_resolver_address +
  2856. eh->ifunc_resolver_section->output_offset +
  2857. eh->ifunc_resolver_section->output_section->vma);
  2858. /* Do not return yet. Handling of explicit GOT slots of
  2859. IFUNC symbols is below. */
  2860. }
  2861. else
  2862. {
  2863. if (h->dynindx == -1
  2864. || htab->elf.splt == NULL
  2865. || htab->elf.sgotplt == NULL
  2866. || htab->elf.srelplt == NULL)
  2867. abort ();
  2868. /* Calc. index no.
  2869. Current offset - size first entry / entry size. */
  2870. plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE;
  2871. /* The slots in the .got.plt correspond to the PLT slots in
  2872. the same order. */
  2873. gotplt_offset = plt_index * GOT_ENTRY_SIZE;
  2874. /* If .got.plt comes first it needs to contain the 3 header
  2875. entries. */
  2876. if (!s390_gotplt_after_got_p (info))
  2877. gotplt_offset += 3 * GOT_ENTRY_SIZE;
  2878. /* Fill in the blueprint of a PLT. */
  2879. memcpy (htab->elf.splt->contents + h->plt.offset, elf_s390x_plt_entry,
  2880. PLT_ENTRY_SIZE);
  2881. /* The first instruction in the PLT entry is a LARL loading
  2882. the address of the GOT slot. We write the 4 byte
  2883. immediate operand of the LARL instruction here. */
  2884. bfd_put_32 (output_bfd,
  2885. (htab->elf.sgotplt->output_section->vma +
  2886. htab->elf.sgotplt->output_offset + gotplt_offset
  2887. - (htab->elf.splt->output_section->vma +
  2888. htab->elf.splt->output_offset +
  2889. h->plt.offset))/2,
  2890. htab->elf.splt->contents + h->plt.offset + 2);
  2891. /* Fixup the relative branch to PLT 0 */
  2892. bfd_put_32 (output_bfd, - (PLT_FIRST_ENTRY_SIZE +
  2893. (PLT_ENTRY_SIZE * plt_index) + 22)/2,
  2894. htab->elf.splt->contents + h->plt.offset + 24);
  2895. /* Fixup offset into .rela.plt section. */
  2896. bfd_put_32 (output_bfd, plt_index * sizeof (Elf64_External_Rela),
  2897. htab->elf.splt->contents + h->plt.offset + 28);
  2898. /* Fill in the entry in the global offset table.
  2899. Points to instruction after GOT offset. */
  2900. bfd_put_64 (output_bfd,
  2901. (htab->elf.splt->output_section->vma
  2902. + htab->elf.splt->output_offset
  2903. + h->plt.offset
  2904. + 14),
  2905. htab->elf.sgotplt->contents + gotplt_offset);
  2906. /* Fill in the entry in the .rela.plt section. */
  2907. rela.r_offset = (htab->elf.sgotplt->output_section->vma
  2908. + htab->elf.sgotplt->output_offset
  2909. + gotplt_offset);
  2910. rela.r_info = ELF64_R_INFO (h->dynindx, R_390_JMP_SLOT);
  2911. rela.r_addend = 0;
  2912. loc = htab->elf.srelplt->contents + plt_index *
  2913. sizeof (Elf64_External_Rela);
  2914. bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
  2915. if (!h->def_regular)
  2916. {
  2917. /* Mark the symbol as undefined, rather than as defined in
  2918. the .plt section. Leave the value alone. This is a clue
  2919. for the dynamic linker, to make function pointer
  2920. comparisons work between an application and shared
  2921. library. */
  2922. sym->st_shndx = SHN_UNDEF;
  2923. }
  2924. }
  2925. }
  2926. if (h->got.offset != (bfd_vma) -1
  2927. && elf_s390_hash_entry(h)->tls_type != GOT_TLS_GD
  2928. && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE
  2929. && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE_NLT)
  2930. {
  2931. Elf_Internal_Rela rela;
  2932. bfd_byte *loc;
  2933. /* This symbol has an entry in the global offset table. Set it
  2934. up. */
  2935. if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
  2936. abort ();
  2937. rela.r_offset = (htab->elf.sgot->output_section->vma
  2938. + htab->elf.sgot->output_offset
  2939. + (h->got.offset &~ (bfd_vma) 1));
  2940. if (h->def_regular && s390_is_ifunc_symbol_p (h))
  2941. {
  2942. if (bfd_link_pic (info))
  2943. {
  2944. /* An explicit GOT slot usage needs GLOB_DAT. If the
  2945. symbol references local the implicit got.iplt slot
  2946. will be used and the IRELATIVE reloc has been created
  2947. above. */
  2948. goto do_glob_dat;
  2949. }
  2950. else
  2951. {
  2952. /* For non-shared objects explicit GOT slots must be
  2953. filled with the PLT slot address for pointer
  2954. equality reasons. */
  2955. bfd_put_64 (output_bfd, (htab->elf.iplt->output_section->vma
  2956. + htab->elf.iplt->output_offset
  2957. + h->plt.offset),
  2958. htab->elf.sgot->contents + h->got.offset);
  2959. return true;
  2960. }
  2961. }
  2962. else if (bfd_link_pic (info)
  2963. && SYMBOL_REFERENCES_LOCAL (info, h))
  2964. {
  2965. if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  2966. return true;
  2967. /* If this is a static link, or it is a -Bsymbolic link and
  2968. the symbol is defined locally or was forced to be local
  2969. because of a version file, we just want to emit a
  2970. RELATIVE reloc. The entry in the global offset table
  2971. will already have been initialized in the
  2972. relocate_section function. */
  2973. if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
  2974. return false;
  2975. BFD_ASSERT((h->got.offset & 1) != 0);
  2976. rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
  2977. rela.r_addend = (h->root.u.def.value
  2978. + h->root.u.def.section->output_section->vma
  2979. + h->root.u.def.section->output_offset);
  2980. }
  2981. else
  2982. {
  2983. BFD_ASSERT((h->got.offset & 1) == 0);
  2984. do_glob_dat:
  2985. bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgot->contents + h->got.offset);
  2986. rela.r_info = ELF64_R_INFO (h->dynindx, R_390_GLOB_DAT);
  2987. rela.r_addend = 0;
  2988. }
  2989. loc = htab->elf.srelgot->contents;
  2990. loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
  2991. bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
  2992. }
  2993. if (h->needs_copy)
  2994. {
  2995. Elf_Internal_Rela rela;
  2996. asection *s;
  2997. bfd_byte *loc;
  2998. /* This symbols needs a copy reloc. Set it up. */
  2999. if (h->dynindx == -1
  3000. || (h->root.type != bfd_link_hash_defined
  3001. && h->root.type != bfd_link_hash_defweak)
  3002. || htab->elf.srelbss == NULL)
  3003. abort ();
  3004. rela.r_offset = (h->root.u.def.value
  3005. + h->root.u.def.section->output_section->vma
  3006. + h->root.u.def.section->output_offset);
  3007. rela.r_info = ELF64_R_INFO (h->dynindx, R_390_COPY);
  3008. rela.r_addend = 0;
  3009. if (h->root.u.def.section == htab->elf.sdynrelro)
  3010. s = htab->elf.sreldynrelro;
  3011. else
  3012. s = htab->elf.srelbss;
  3013. loc = s->contents + s->reloc_count++ * sizeof (Elf64_External_Rela);
  3014. bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
  3015. }
  3016. /* Mark some specially defined symbols as absolute. */
  3017. if (h == htab->elf.hdynamic
  3018. || h == htab->elf.hgot
  3019. || h == htab->elf.hplt)
  3020. sym->st_shndx = SHN_ABS;
  3021. return true;
  3022. }
  3023. /* Used to decide how to sort relocs in an optimal manner for the
  3024. dynamic linker, before writing them out. */
  3025. static enum elf_reloc_type_class
  3026. elf_s390_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  3027. const asection *rel_sec ATTRIBUTE_UNUSED,
  3028. const Elf_Internal_Rela *rela)
  3029. {
  3030. bfd *abfd = info->output_bfd;
  3031. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  3032. struct elf_s390_link_hash_table *htab = elf_s390_hash_table (info);
  3033. unsigned long r_symndx = ELF64_R_SYM (rela->r_info);
  3034. Elf_Internal_Sym sym;
  3035. if (htab->elf.dynsym == NULL
  3036. || !bed->s->swap_symbol_in (abfd,
  3037. (htab->elf.dynsym->contents
  3038. + r_symndx * bed->s->sizeof_sym),
  3039. 0, &sym))
  3040. abort ();
  3041. /* Check relocation against STT_GNU_IFUNC symbol. */
  3042. if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
  3043. return reloc_class_ifunc;
  3044. switch ((int) ELF64_R_TYPE (rela->r_info))
  3045. {
  3046. case R_390_RELATIVE:
  3047. return reloc_class_relative;
  3048. case R_390_JMP_SLOT:
  3049. return reloc_class_plt;
  3050. case R_390_COPY:
  3051. return reloc_class_copy;
  3052. default:
  3053. return reloc_class_normal;
  3054. }
  3055. }
  3056. /* Finish up the dynamic sections. */
  3057. static bool
  3058. elf_s390_finish_dynamic_sections (bfd *output_bfd,
  3059. struct bfd_link_info *info)
  3060. {
  3061. struct elf_s390_link_hash_table *htab;
  3062. bfd *dynobj;
  3063. asection *sdyn;
  3064. bfd *ibfd;
  3065. unsigned int i;
  3066. htab = elf_s390_hash_table (info);
  3067. if (htab == NULL)
  3068. return false;
  3069. dynobj = htab->elf.dynobj;
  3070. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  3071. if (htab->elf.dynamic_sections_created)
  3072. {
  3073. Elf64_External_Dyn *dyncon, *dynconend;
  3074. if (sdyn == NULL || htab->elf.sgot == NULL)
  3075. abort ();
  3076. dyncon = (Elf64_External_Dyn *) sdyn->contents;
  3077. dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
  3078. for (; dyncon < dynconend; dyncon++)
  3079. {
  3080. Elf_Internal_Dyn dyn;
  3081. asection *s;
  3082. bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
  3083. switch (dyn.d_tag)
  3084. {
  3085. default:
  3086. continue;
  3087. case DT_PLTGOT:
  3088. /* DT_PLTGOT matches _GLOBAL_OFFSET_TABLE_ */
  3089. dyn.d_un.d_ptr = s390_got_pointer (info);
  3090. break;
  3091. case DT_JMPREL:
  3092. s = htab->elf.srelplt;
  3093. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  3094. break;
  3095. case DT_PLTRELSZ:
  3096. dyn.d_un.d_val = htab->elf.srelplt->size;
  3097. if (htab->elf.irelplt)
  3098. dyn.d_un.d_val += htab->elf.irelplt->size;
  3099. break;
  3100. case DT_RELASZ:
  3101. /* The procedure linkage table relocs (DT_JMPREL) should
  3102. not be included in the overall relocs (DT_RELA).
  3103. Therefore, we override the DT_RELASZ entry here to
  3104. make it not include the JMPREL relocs. Since the
  3105. linker script arranges for .rela.plt to follow all
  3106. other relocation sections, we don't have to worry
  3107. about changing the DT_RELA entry. */
  3108. dyn.d_un.d_val -= htab->elf.srelplt->size;
  3109. if (htab->elf.irelplt)
  3110. dyn.d_un.d_val -= htab->elf.irelplt->size;
  3111. break;
  3112. }
  3113. bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
  3114. }
  3115. /* Fill in the special first entry in the procedure linkage table. */
  3116. if (htab->elf.splt && htab->elf.splt->size > 0)
  3117. {
  3118. /* fill in blueprint for plt 0 entry */
  3119. memcpy (htab->elf.splt->contents, elf_s390x_first_plt_entry,
  3120. PLT_FIRST_ENTRY_SIZE);
  3121. /* The second instruction in the first PLT entry is a LARL
  3122. loading the GOT pointer. Fill in the LARL immediate
  3123. address. */
  3124. bfd_put_32 (output_bfd,
  3125. (s390_got_pointer (info)
  3126. - htab->elf.splt->output_section->vma
  3127. - htab->elf.splt->output_offset - 6)/2,
  3128. htab->elf.splt->contents + 8);
  3129. }
  3130. if (elf_section_data (htab->elf.splt->output_section) != NULL)
  3131. elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize
  3132. = PLT_ENTRY_SIZE;
  3133. }
  3134. if (htab->elf.hgot && htab->elf.hgot->root.u.def.section)
  3135. {
  3136. /* Fill in the first three entries in the global offset table. */
  3137. if (htab->elf.hgot->root.u.def.section->size > 0)
  3138. {
  3139. bfd_put_64 (output_bfd,
  3140. (sdyn == NULL ? (bfd_vma) 0
  3141. : sdyn->output_section->vma + sdyn->output_offset),
  3142. htab->elf.hgot->root.u.def.section->contents);
  3143. /* One entry for shared object struct ptr. */
  3144. bfd_put_64 (output_bfd, (bfd_vma) 0,
  3145. htab->elf.hgot->root.u.def.section->contents + 8);
  3146. /* One entry for _dl_runtime_resolve. */
  3147. bfd_put_64 (output_bfd, (bfd_vma) 0,
  3148. htab->elf.hgot->root.u.def.section->contents + 16);
  3149. }
  3150. if (htab->elf.sgot != NULL && htab->elf.sgot->size > 0)
  3151. elf_section_data (htab->elf.sgot->output_section)
  3152. ->this_hdr.sh_entsize = 8;
  3153. }
  3154. /* Finish dynamic symbol for local IFUNC symbols. */
  3155. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  3156. {
  3157. struct plt_entry *local_plt;
  3158. Elf_Internal_Sym *isym;
  3159. Elf_Internal_Shdr *symtab_hdr;
  3160. symtab_hdr = &elf_symtab_hdr (ibfd);
  3161. if (!is_s390_elf (ibfd))
  3162. continue;
  3163. local_plt = elf_s390_local_plt (ibfd);
  3164. if (local_plt != NULL)
  3165. for (i = 0; i < symtab_hdr->sh_info; i++)
  3166. {
  3167. if (local_plt[i].plt.offset != (bfd_vma) -1)
  3168. {
  3169. asection *sec = local_plt[i].sec;
  3170. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache, ibfd, i);
  3171. if (isym == NULL)
  3172. return false;
  3173. if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
  3174. elf_s390_finish_ifunc_symbol (output_bfd, info, NULL, htab,
  3175. local_plt[i].plt.offset,
  3176. isym->st_value
  3177. + sec->output_section->vma
  3178. + sec->output_offset);
  3179. }
  3180. }
  3181. }
  3182. return true;
  3183. }
  3184. /* Support for core dump NOTE sections. */
  3185. static bool
  3186. elf_s390_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
  3187. {
  3188. int offset;
  3189. size_t size;
  3190. switch (note->descsz)
  3191. {
  3192. default:
  3193. return false;
  3194. case 336: /* sizeof(struct elf_prstatus) on s390x */
  3195. /* pr_cursig */
  3196. elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
  3197. /* pr_pid */
  3198. elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
  3199. /* pr_reg */
  3200. offset = 112;
  3201. size = 216;
  3202. break;
  3203. }
  3204. /* Make a ".reg/999" section. */
  3205. return _bfd_elfcore_make_pseudosection (abfd, ".reg",
  3206. size, note->descpos + offset);
  3207. }
  3208. static bool
  3209. elf_s390_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
  3210. {
  3211. switch (note->descsz)
  3212. {
  3213. default:
  3214. return false;
  3215. case 136: /* sizeof(struct elf_prpsinfo) on s390x */
  3216. elf_tdata (abfd)->core->pid
  3217. = bfd_get_32 (abfd, note->descdata + 24);
  3218. elf_tdata (abfd)->core->program
  3219. = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
  3220. elf_tdata (abfd)->core->command
  3221. = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
  3222. }
  3223. /* Note that for some reason, a spurious space is tacked
  3224. onto the end of the args in some (at least one anyway)
  3225. implementations, so strip it off if it exists. */
  3226. {
  3227. char *command = elf_tdata (abfd)->core->command;
  3228. int n = strlen (command);
  3229. if (0 < n && command[n - 1] == ' ')
  3230. command[n - 1] = '\0';
  3231. }
  3232. return true;
  3233. }
  3234. static char *
  3235. elf_s390_write_core_note (bfd *abfd, char *buf, int *bufsiz,
  3236. int note_type, ...)
  3237. {
  3238. va_list ap;
  3239. switch (note_type)
  3240. {
  3241. default:
  3242. return NULL;
  3243. case NT_PRPSINFO:
  3244. {
  3245. char data[136] ATTRIBUTE_NONSTRING = { 0 };
  3246. const char *fname, *psargs;
  3247. va_start (ap, note_type);
  3248. fname = va_arg (ap, const char *);
  3249. psargs = va_arg (ap, const char *);
  3250. va_end (ap);
  3251. strncpy (data + 40, fname, 16);
  3252. #if GCC_VERSION == 8000 || GCC_VERSION == 8001
  3253. DIAGNOSTIC_PUSH;
  3254. /* GCC 8.0 and 8.1 warn about 80 equals destination size with
  3255. -Wstringop-truncation:
  3256. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
  3257. */
  3258. DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
  3259. #endif
  3260. strncpy (data + 56, psargs, 80);
  3261. #if GCC_VERSION == 8000 || GCC_VERSION == 8001
  3262. DIAGNOSTIC_POP;
  3263. #endif
  3264. return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
  3265. &data, sizeof (data));
  3266. }
  3267. case NT_PRSTATUS:
  3268. {
  3269. char data[336] = { 0 };
  3270. long pid;
  3271. int cursig;
  3272. const void *gregs;
  3273. va_start (ap, note_type);
  3274. pid = va_arg (ap, long);
  3275. cursig = va_arg (ap, int);
  3276. gregs = va_arg (ap, const void *);
  3277. va_end (ap);
  3278. bfd_put_16 (abfd, cursig, data + 12);
  3279. bfd_put_32 (abfd, pid, data + 32);
  3280. memcpy (data + 112, gregs, 216);
  3281. return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
  3282. &data, sizeof (data));
  3283. }
  3284. }
  3285. /* NOTREACHED */
  3286. }
  3287. /* Return address for Ith PLT stub in section PLT, for relocation REL
  3288. or (bfd_vma) -1 if it should not be included. */
  3289. static bfd_vma
  3290. elf_s390_plt_sym_val (bfd_vma i, const asection *plt,
  3291. const arelent *rel ATTRIBUTE_UNUSED)
  3292. {
  3293. return plt->vma + PLT_FIRST_ENTRY_SIZE + i * PLT_ENTRY_SIZE;
  3294. }
  3295. /* Merge backend specific data from an object file to the output
  3296. object file when linking. */
  3297. static bool
  3298. elf64_s390_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
  3299. {
  3300. if (!is_s390_elf (ibfd) || !is_s390_elf (info->output_bfd))
  3301. return true;
  3302. return elf_s390_merge_obj_attributes (ibfd, info);
  3303. }
  3304. /* We may add a PT_S390_PGSTE program header. */
  3305. static int
  3306. elf_s390_additional_program_headers (bfd *abfd ATTRIBUTE_UNUSED,
  3307. struct bfd_link_info *info)
  3308. {
  3309. struct elf_s390_link_hash_table *htab;
  3310. if (info)
  3311. {
  3312. htab = elf_s390_hash_table (info);
  3313. if (htab)
  3314. return htab->params->pgste;
  3315. }
  3316. return 0;
  3317. }
  3318. /* Add the PT_S390_PGSTE program header. */
  3319. static bool
  3320. elf_s390_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
  3321. {
  3322. struct elf_s390_link_hash_table *htab;
  3323. struct elf_segment_map *m, *pm = NULL;
  3324. if (!abfd || !info)
  3325. return true;
  3326. htab = elf_s390_hash_table (info);
  3327. if (!htab || !htab->params->pgste)
  3328. return true;
  3329. /* If there is already a PT_S390_PGSTE header, avoid adding
  3330. another. */
  3331. m = elf_seg_map (abfd);
  3332. while (m && m->p_type != PT_S390_PGSTE)
  3333. {
  3334. pm = m;
  3335. m = m->next;
  3336. }
  3337. if (m)
  3338. return true;
  3339. m = (struct elf_segment_map *)
  3340. bfd_zalloc (abfd, sizeof (struct elf_segment_map));
  3341. if (m == NULL)
  3342. return false;
  3343. m->p_type = PT_S390_PGSTE;
  3344. m->count = 0;
  3345. m->next = NULL;
  3346. if (pm)
  3347. pm->next = m;
  3348. return true;
  3349. }
  3350. bool
  3351. bfd_elf_s390_set_options (struct bfd_link_info *info,
  3352. struct s390_elf_params *params)
  3353. {
  3354. struct elf_s390_link_hash_table *htab;
  3355. if (info)
  3356. {
  3357. htab = elf_s390_hash_table (info);
  3358. if (htab)
  3359. htab->params = params;
  3360. }
  3361. return true;
  3362. }
  3363. /* Why was the hash table entry size definition changed from
  3364. ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
  3365. this is the only reason for the s390_elf64_size_info structure. */
  3366. const struct elf_size_info s390_elf64_size_info =
  3367. {
  3368. sizeof (Elf64_External_Ehdr),
  3369. sizeof (Elf64_External_Phdr),
  3370. sizeof (Elf64_External_Shdr),
  3371. sizeof (Elf64_External_Rel),
  3372. sizeof (Elf64_External_Rela),
  3373. sizeof (Elf64_External_Sym),
  3374. sizeof (Elf64_External_Dyn),
  3375. sizeof (Elf_External_Note),
  3376. 8, /* hash-table entry size. */
  3377. 1, /* internal relocations per external relocations. */
  3378. 64, /* arch_size. */
  3379. 3, /* log_file_align. */
  3380. ELFCLASS64, EV_CURRENT,
  3381. bfd_elf64_write_out_phdrs,
  3382. bfd_elf64_write_shdrs_and_ehdr,
  3383. bfd_elf64_checksum_contents,
  3384. bfd_elf64_write_relocs,
  3385. bfd_elf64_swap_symbol_in,
  3386. bfd_elf64_swap_symbol_out,
  3387. bfd_elf64_slurp_reloc_table,
  3388. bfd_elf64_slurp_symbol_table,
  3389. bfd_elf64_swap_dyn_in,
  3390. bfd_elf64_swap_dyn_out,
  3391. bfd_elf64_swap_reloc_in,
  3392. bfd_elf64_swap_reloc_out,
  3393. bfd_elf64_swap_reloca_in,
  3394. bfd_elf64_swap_reloca_out
  3395. };
  3396. #define TARGET_BIG_SYM s390_elf64_vec
  3397. #define TARGET_BIG_NAME "elf64-s390"
  3398. #define ELF_ARCH bfd_arch_s390
  3399. #define ELF_TARGET_ID S390_ELF_DATA
  3400. #define ELF_MACHINE_CODE EM_S390
  3401. #define ELF_MACHINE_ALT1 EM_S390_OLD
  3402. #define ELF_MAXPAGESIZE 0x1000
  3403. #define elf_backend_size_info s390_elf64_size_info
  3404. #define elf_backend_can_gc_sections 1
  3405. #define elf_backend_can_refcount 1
  3406. #define elf_backend_want_got_plt 1
  3407. #define elf_backend_plt_readonly 1
  3408. #define elf_backend_want_plt_sym 0
  3409. #define elf_backend_got_header_size 24
  3410. #define elf_backend_want_dynrelro 1
  3411. #define elf_backend_rela_normal 1
  3412. #define elf_info_to_howto elf_s390_info_to_howto
  3413. #define bfd_elf64_bfd_is_local_label_name elf_s390_is_local_label_name
  3414. #define bfd_elf64_bfd_link_hash_table_create elf_s390_link_hash_table_create
  3415. #define bfd_elf64_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
  3416. #define bfd_elf64_bfd_reloc_name_lookup elf_s390_reloc_name_lookup
  3417. #define bfd_elf64_bfd_merge_private_bfd_data elf64_s390_merge_private_bfd_data
  3418. #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
  3419. #define elf_backend_check_relocs elf_s390_check_relocs
  3420. #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
  3421. #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
  3422. #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
  3423. #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
  3424. #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
  3425. #define elf_backend_reloc_type_class elf_s390_reloc_type_class
  3426. #define elf_backend_relocate_section elf_s390_relocate_section
  3427. #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
  3428. #define elf_backend_init_index_section _bfd_elf_init_1_index_section
  3429. #define elf_backend_grok_prstatus elf_s390_grok_prstatus
  3430. #define elf_backend_grok_psinfo elf_s390_grok_psinfo
  3431. #define elf_backend_write_core_note elf_s390_write_core_note
  3432. #define elf_backend_plt_sym_val elf_s390_plt_sym_val
  3433. #define elf_backend_sort_relocs_p elf_s390_elf_sort_relocs_p
  3434. #define elf_backend_additional_program_headers elf_s390_additional_program_headers
  3435. #define elf_backend_modify_segment_map elf_s390_modify_segment_map
  3436. #define bfd_elf64_mkobject elf_s390_mkobject
  3437. #define elf_backend_object_p elf_s390_object_p
  3438. #include "elf64-target.h"