elf64-s390.c 118 KB

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