elf32-s390.c 120 KB

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