elf32-s390.c 128 KB

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