elfxx-sparc.c 149 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933
  1. /* SPARC-specific support for ELF
  2. Copyright (C) 2005-2015 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. /* This file handles functionality common to the different SPARC ABI's. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "bfdlink.h"
  20. #include "libbfd.h"
  21. #include "libiberty.h"
  22. #include "elf-bfd.h"
  23. #include "elf/sparc.h"
  24. #include "opcode/sparc.h"
  25. #include "elfxx-sparc.h"
  26. #include "elf-vxworks.h"
  27. #include "objalloc.h"
  28. #include "hashtab.h"
  29. /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
  30. #define MINUS_ONE (~ (bfd_vma) 0)
  31. #define ABI_64_P(abfd) \
  32. (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
  33. /* The relocation "howto" table. */
  34. /* Utility for performing the standard initial work of an instruction
  35. relocation.
  36. *PRELOCATION will contain the relocated item.
  37. *PINSN will contain the instruction from the input stream.
  38. If the result is `bfd_reloc_other' the caller can continue with
  39. performing the relocation. Otherwise it must stop and return the
  40. value to its caller. */
  41. static bfd_reloc_status_type
  42. init_insn_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  43. void * data, asection *input_section, bfd *output_bfd,
  44. bfd_vma *prelocation, bfd_vma *pinsn)
  45. {
  46. bfd_vma relocation;
  47. reloc_howto_type *howto = reloc_entry->howto;
  48. if (output_bfd != (bfd *) NULL
  49. && (symbol->flags & BSF_SECTION_SYM) == 0
  50. && (! howto->partial_inplace
  51. || reloc_entry->addend == 0))
  52. {
  53. reloc_entry->address += input_section->output_offset;
  54. return bfd_reloc_ok;
  55. }
  56. /* This works because partial_inplace is FALSE. */
  57. if (output_bfd != NULL)
  58. return bfd_reloc_continue;
  59. if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
  60. return bfd_reloc_outofrange;
  61. relocation = (symbol->value
  62. + symbol->section->output_section->vma
  63. + symbol->section->output_offset);
  64. relocation += reloc_entry->addend;
  65. if (howto->pc_relative)
  66. {
  67. relocation -= (input_section->output_section->vma
  68. + input_section->output_offset);
  69. relocation -= reloc_entry->address;
  70. }
  71. *prelocation = relocation;
  72. *pinsn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
  73. return bfd_reloc_other;
  74. }
  75. /* For unsupported relocs. */
  76. static bfd_reloc_status_type
  77. sparc_elf_notsup_reloc (bfd *abfd ATTRIBUTE_UNUSED,
  78. arelent *reloc_entry ATTRIBUTE_UNUSED,
  79. asymbol *symbol ATTRIBUTE_UNUSED,
  80. void * data ATTRIBUTE_UNUSED,
  81. asection *input_section ATTRIBUTE_UNUSED,
  82. bfd *output_bfd ATTRIBUTE_UNUSED,
  83. char **error_message ATTRIBUTE_UNUSED)
  84. {
  85. return bfd_reloc_notsupported;
  86. }
  87. /* Handle the WDISP16 reloc. */
  88. static bfd_reloc_status_type
  89. sparc_elf_wdisp16_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  90. void * data, asection *input_section, bfd *output_bfd,
  91. char **error_message ATTRIBUTE_UNUSED)
  92. {
  93. bfd_vma relocation;
  94. bfd_vma insn;
  95. bfd_reloc_status_type status;
  96. status = init_insn_reloc (abfd, reloc_entry, symbol, data,
  97. input_section, output_bfd, &relocation, &insn);
  98. if (status != bfd_reloc_other)
  99. return status;
  100. insn &= ~ (bfd_vma) 0x303fff;
  101. insn |= (((relocation >> 2) & 0xc000) << 6) | ((relocation >> 2) & 0x3fff);
  102. bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
  103. if ((bfd_signed_vma) relocation < - 0x40000
  104. || (bfd_signed_vma) relocation > 0x3ffff)
  105. return bfd_reloc_overflow;
  106. else
  107. return bfd_reloc_ok;
  108. }
  109. /* Handle the WDISP10 reloc. */
  110. static bfd_reloc_status_type
  111. sparc_elf_wdisp10_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  112. void * data, asection *input_section, bfd *output_bfd,
  113. char **error_message ATTRIBUTE_UNUSED)
  114. {
  115. bfd_vma relocation;
  116. bfd_vma insn;
  117. bfd_reloc_status_type status;
  118. status = init_insn_reloc (abfd, reloc_entry, symbol, data,
  119. input_section, output_bfd, &relocation, &insn);
  120. if (status != bfd_reloc_other)
  121. return status;
  122. insn &= ~ (bfd_vma) 0x181fe0;
  123. insn |= (((relocation >> 2) & 0x300) << 11)
  124. | (((relocation >> 2) & 0xff) << 5);
  125. bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
  126. if ((bfd_signed_vma) relocation < - 0x1000
  127. || (bfd_signed_vma) relocation > 0xfff)
  128. return bfd_reloc_overflow;
  129. else
  130. return bfd_reloc_ok;
  131. }
  132. /* Handle the HIX22 reloc. */
  133. static bfd_reloc_status_type
  134. sparc_elf_hix22_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  135. void * data, asection *input_section, bfd *output_bfd,
  136. char **error_message ATTRIBUTE_UNUSED)
  137. {
  138. bfd_vma relocation;
  139. bfd_vma insn;
  140. bfd_reloc_status_type status;
  141. status = init_insn_reloc (abfd, reloc_entry, symbol, data,
  142. input_section, output_bfd, &relocation, &insn);
  143. if (status != bfd_reloc_other)
  144. return status;
  145. relocation ^= MINUS_ONE;
  146. insn = (insn &~ (bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
  147. bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
  148. if ((relocation & ~ (bfd_vma) 0xffffffff) != 0)
  149. return bfd_reloc_overflow;
  150. else
  151. return bfd_reloc_ok;
  152. }
  153. /* Handle the LOX10 reloc. */
  154. static bfd_reloc_status_type
  155. sparc_elf_lox10_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  156. void * data, asection *input_section, bfd *output_bfd,
  157. char **error_message ATTRIBUTE_UNUSED)
  158. {
  159. bfd_vma relocation;
  160. bfd_vma insn;
  161. bfd_reloc_status_type status;
  162. status = init_insn_reloc (abfd, reloc_entry, symbol, data,
  163. input_section, output_bfd, &relocation, &insn);
  164. if (status != bfd_reloc_other)
  165. return status;
  166. insn = (insn &~ (bfd_vma) 0x1fff) | 0x1c00 | (relocation & 0x3ff);
  167. bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
  168. return bfd_reloc_ok;
  169. }
  170. static reloc_howto_type _bfd_sparc_elf_howto_table[] =
  171. {
  172. HOWTO(R_SPARC_NONE, 0,3, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
  173. HOWTO(R_SPARC_8, 0,0, 8,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_8", FALSE,0,0x000000ff,TRUE),
  174. HOWTO(R_SPARC_16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_16", FALSE,0,0x0000ffff,TRUE),
  175. HOWTO(R_SPARC_32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_32", FALSE,0,0xffffffff,TRUE),
  176. HOWTO(R_SPARC_DISP8, 0,0, 8,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP8", FALSE,0,0x000000ff,TRUE),
  177. HOWTO(R_SPARC_DISP16, 0,1,16,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP16", FALSE,0,0x0000ffff,TRUE),
  178. HOWTO(R_SPARC_DISP32, 0,2,32,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP32", FALSE,0,0xffffffff,TRUE),
  179. HOWTO(R_SPARC_WDISP30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP30", FALSE,0,0x3fffffff,TRUE),
  180. HOWTO(R_SPARC_WDISP22, 2,2,22,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP22", FALSE,0,0x003fffff,TRUE),
  181. HOWTO(R_SPARC_HI22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HI22", FALSE,0,0x003fffff,TRUE),
  182. HOWTO(R_SPARC_22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_22", FALSE,0,0x003fffff,TRUE),
  183. HOWTO(R_SPARC_13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_13", FALSE,0,0x00001fff,TRUE),
  184. HOWTO(R_SPARC_LO10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LO10", FALSE,0,0x000003ff,TRUE),
  185. HOWTO(R_SPARC_GOT10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT10", FALSE,0,0x000003ff,TRUE),
  186. HOWTO(R_SPARC_GOT13, 0,2,13,FALSE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_GOT13", FALSE,0,0x00001fff,TRUE),
  187. HOWTO(R_SPARC_GOT22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT22", FALSE,0,0x003fffff,TRUE),
  188. HOWTO(R_SPARC_PC10, 0,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC10", FALSE,0,0x000003ff,TRUE),
  189. HOWTO(R_SPARC_PC22, 10,2,22,TRUE, 0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PC22", FALSE,0,0x003fffff,TRUE),
  190. HOWTO(R_SPARC_WPLT30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WPLT30", FALSE,0,0x3fffffff,TRUE),
  191. HOWTO(R_SPARC_COPY, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_COPY", FALSE,0,0x00000000,TRUE),
  192. HOWTO(R_SPARC_GLOB_DAT, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GLOB_DAT",FALSE,0,0x00000000,TRUE),
  193. HOWTO(R_SPARC_JMP_SLOT, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_JMP_SLOT",FALSE,0,0x00000000,TRUE),
  194. HOWTO(R_SPARC_RELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_RELATIVE",FALSE,0,0x00000000,TRUE),
  195. HOWTO(R_SPARC_UA32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA32", FALSE,0,0xffffffff,TRUE),
  196. HOWTO(R_SPARC_PLT32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT32", FALSE,0,0xffffffff,TRUE),
  197. HOWTO(R_SPARC_HIPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_HIPLT22", FALSE,0,0x00000000,TRUE),
  198. HOWTO(R_SPARC_LOPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_LOPLT10", FALSE,0,0x00000000,TRUE),
  199. HOWTO(R_SPARC_PCPLT32, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT32", FALSE,0,0x00000000,TRUE),
  200. HOWTO(R_SPARC_PCPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT22", FALSE,0,0x00000000,TRUE),
  201. HOWTO(R_SPARC_PCPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT10", FALSE,0,0x00000000,TRUE),
  202. HOWTO(R_SPARC_10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_10", FALSE,0,0x000003ff,TRUE),
  203. HOWTO(R_SPARC_11, 0,2,11,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_11", FALSE,0,0x000007ff,TRUE),
  204. HOWTO(R_SPARC_64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_64", FALSE,0,MINUS_ONE, TRUE),
  205. HOWTO(R_SPARC_OLO10, 0,2,13,FALSE,0,complain_overflow_signed, sparc_elf_notsup_reloc, "R_SPARC_OLO10", FALSE,0,0x00001fff,TRUE),
  206. HOWTO(R_SPARC_HH22, 42,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_HH22", FALSE,0,0x003fffff,TRUE),
  207. HOWTO(R_SPARC_HM10, 32,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HM10", FALSE,0,0x000003ff,TRUE),
  208. HOWTO(R_SPARC_LM22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LM22", FALSE,0,0x003fffff,TRUE),
  209. HOWTO(R_SPARC_PC_HH22, 42,2,22,TRUE, 0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_PC_HH22", FALSE,0,0x003fffff,TRUE),
  210. HOWTO(R_SPARC_PC_HM10, 32,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC_HM10", FALSE,0,0x000003ff,TRUE),
  211. HOWTO(R_SPARC_PC_LM22, 10,2,22,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC_LM22", FALSE,0,0x003fffff,TRUE),
  212. HOWTO(R_SPARC_WDISP16, 2,2,16,TRUE, 0,complain_overflow_signed, sparc_elf_wdisp16_reloc,"R_SPARC_WDISP16", FALSE,0,0x00000000,TRUE),
  213. HOWTO(R_SPARC_WDISP19, 2,2,19,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP19", FALSE,0,0x0007ffff,TRUE),
  214. HOWTO(R_SPARC_UNUSED_42, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_UNUSED_42",FALSE,0,0x00000000,TRUE),
  215. HOWTO(R_SPARC_7, 0,2, 7,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_7", FALSE,0,0x0000007f,TRUE),
  216. HOWTO(R_SPARC_5, 0,2, 5,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_5", FALSE,0,0x0000001f,TRUE),
  217. HOWTO(R_SPARC_6, 0,2, 6,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_6", FALSE,0,0x0000003f,TRUE),
  218. HOWTO(R_SPARC_DISP64, 0,4,64,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP64", FALSE,0,MINUS_ONE, TRUE),
  219. HOWTO(R_SPARC_PLT64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT64", FALSE,0,MINUS_ONE, TRUE),
  220. HOWTO(R_SPARC_HIX22, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_HIX22", FALSE,0,MINUS_ONE, FALSE),
  221. HOWTO(R_SPARC_LOX10, 0,4, 0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_LOX10", FALSE,0,MINUS_ONE, FALSE),
  222. HOWTO(R_SPARC_H44, 22,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_H44", FALSE,0,0x003fffff,FALSE),
  223. HOWTO(R_SPARC_M44, 12,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_M44", FALSE,0,0x000003ff,FALSE),
  224. HOWTO(R_SPARC_L44, 0,2,13,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_L44", FALSE,0,0x00000fff,FALSE),
  225. HOWTO(R_SPARC_REGISTER, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_notsup_reloc, "R_SPARC_REGISTER",FALSE,0,MINUS_ONE, FALSE),
  226. HOWTO(R_SPARC_UA64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA64", FALSE,0,MINUS_ONE, TRUE),
  227. HOWTO(R_SPARC_UA16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA16", FALSE,0,0x0000ffff,TRUE),
  228. HOWTO(R_SPARC_TLS_GD_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_HI22",FALSE,0,0x003fffff,TRUE),
  229. HOWTO(R_SPARC_TLS_GD_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_LO10",FALSE,0,0x000003ff,TRUE),
  230. HOWTO(R_SPARC_TLS_GD_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_ADD",FALSE,0,0x00000000,TRUE),
  231. HOWTO(R_SPARC_TLS_GD_CALL,2,2,30,TRUE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_CALL",FALSE,0,0x3fffffff,TRUE),
  232. HOWTO(R_SPARC_TLS_LDM_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_HI22",FALSE,0,0x003fffff,TRUE),
  233. HOWTO(R_SPARC_TLS_LDM_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_LO10",FALSE,0,0x000003ff,TRUE),
  234. HOWTO(R_SPARC_TLS_LDM_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_ADD",FALSE,0,0x00000000,TRUE),
  235. HOWTO(R_SPARC_TLS_LDM_CALL,2,2,30,TRUE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_CALL",FALSE,0,0x3fffffff,TRUE),
  236. HOWTO(R_SPARC_TLS_LDO_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_TLS_LDO_HIX22",FALSE,0,0x003fffff, FALSE),
  237. HOWTO(R_SPARC_TLS_LDO_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_TLS_LDO_LOX10",FALSE,0,0x000003ff, FALSE),
  238. HOWTO(R_SPARC_TLS_LDO_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDO_ADD",FALSE,0,0x00000000,TRUE),
  239. HOWTO(R_SPARC_TLS_IE_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_HI22",FALSE,0,0x003fffff,TRUE),
  240. HOWTO(R_SPARC_TLS_IE_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LO10",FALSE,0,0x000003ff,TRUE),
  241. HOWTO(R_SPARC_TLS_IE_LD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LD",FALSE,0,0x00000000,TRUE),
  242. HOWTO(R_SPARC_TLS_IE_LDX,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LDX",FALSE,0,0x00000000,TRUE),
  243. HOWTO(R_SPARC_TLS_IE_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_ADD",FALSE,0,0x00000000,TRUE),
  244. HOWTO(R_SPARC_TLS_LE_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_TLS_LE_HIX22",FALSE,0,0x003fffff, FALSE),
  245. HOWTO(R_SPARC_TLS_LE_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_TLS_LE_LOX10",FALSE,0,0x000003ff, FALSE),
  246. HOWTO(R_SPARC_TLS_DTPMOD32,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPMOD32",FALSE,0,0x00000000,TRUE),
  247. HOWTO(R_SPARC_TLS_DTPMOD64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPMOD64",FALSE,0,0x00000000,TRUE),
  248. HOWTO(R_SPARC_TLS_DTPOFF32,0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF32",FALSE,0,0xffffffff,TRUE),
  249. HOWTO(R_SPARC_TLS_DTPOFF64,0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF64",FALSE,0,MINUS_ONE,TRUE),
  250. HOWTO(R_SPARC_TLS_TPOFF32,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_TPOFF32",FALSE,0,0x00000000,TRUE),
  251. HOWTO(R_SPARC_TLS_TPOFF64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_TPOFF64",FALSE,0,0x00000000,TRUE),
  252. HOWTO(R_SPARC_GOTDATA_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_GOTDATA_HIX22",FALSE,0,0x003fffff, FALSE),
  253. HOWTO(R_SPARC_GOTDATA_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_GOTDATA_LOX10",FALSE,0,0x000003ff, FALSE),
  254. HOWTO(R_SPARC_GOTDATA_OP_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_GOTDATA_OP_HIX22",FALSE,0,0x003fffff, FALSE),
  255. HOWTO(R_SPARC_GOTDATA_OP_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_GOTDATA_OP_LOX10",FALSE,0,0x000003ff, FALSE),
  256. HOWTO(R_SPARC_GOTDATA_OP,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOTDATA_OP",FALSE,0,0x00000000,TRUE),
  257. HOWTO(R_SPARC_H34,12,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc,"R_SPARC_H34",FALSE,0,0x003fffff,FALSE),
  258. HOWTO(R_SPARC_SIZE32,0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_SIZE32",FALSE,0,0xffffffff,TRUE),
  259. HOWTO(R_SPARC_SIZE64,0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_SIZE64",FALSE,0,MINUS_ONE, TRUE),
  260. HOWTO(R_SPARC_WDISP10,2,2,10,TRUE, 0,complain_overflow_signed,sparc_elf_wdisp10_reloc,"R_SPARC_WDISP10",FALSE,0,0x00000000,TRUE),
  261. };
  262. static reloc_howto_type sparc_jmp_irel_howto =
  263. HOWTO(R_SPARC_JMP_IREL, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_JMP_IREL",FALSE,0,0x00000000,TRUE);
  264. static reloc_howto_type sparc_irelative_howto =
  265. HOWTO(R_SPARC_IRELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_IRELATIVE",FALSE,0,0x00000000,TRUE);
  266. static reloc_howto_type sparc_vtinherit_howto =
  267. HOWTO (R_SPARC_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_SPARC_GNU_VTINHERIT", FALSE,0, 0, FALSE);
  268. static reloc_howto_type sparc_vtentry_howto =
  269. HOWTO (R_SPARC_GNU_VTENTRY, 0,2,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_SPARC_GNU_VTENTRY", FALSE,0,0, FALSE);
  270. static reloc_howto_type sparc_rev32_howto =
  271. HOWTO(R_SPARC_REV32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_REV32", FALSE,0,0xffffffff,TRUE);
  272. reloc_howto_type *
  273. _bfd_sparc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  274. bfd_reloc_code_real_type code)
  275. {
  276. /* We explicitly handle each relocation type in the switch
  277. instead of using a lookup table for efficiency. */
  278. switch (code)
  279. {
  280. case BFD_RELOC_NONE:
  281. return &_bfd_sparc_elf_howto_table[R_SPARC_NONE];
  282. case BFD_RELOC_8:
  283. return &_bfd_sparc_elf_howto_table[R_SPARC_8];
  284. case BFD_RELOC_16:
  285. return &_bfd_sparc_elf_howto_table[R_SPARC_16];
  286. case BFD_RELOC_32:
  287. return &_bfd_sparc_elf_howto_table[R_SPARC_32];
  288. case BFD_RELOC_8_PCREL:
  289. return &_bfd_sparc_elf_howto_table[R_SPARC_DISP8];
  290. case BFD_RELOC_16_PCREL:
  291. return &_bfd_sparc_elf_howto_table[R_SPARC_DISP16];
  292. case BFD_RELOC_32_PCREL:
  293. return &_bfd_sparc_elf_howto_table[R_SPARC_DISP32];
  294. case BFD_RELOC_32_PCREL_S2:
  295. return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP30];
  296. case BFD_RELOC_SPARC_WDISP22:
  297. return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP22];
  298. case BFD_RELOC_HI22:
  299. return &_bfd_sparc_elf_howto_table[R_SPARC_HI22];
  300. case BFD_RELOC_SPARC22:
  301. return &_bfd_sparc_elf_howto_table[R_SPARC_22];
  302. case BFD_RELOC_SPARC13:
  303. return &_bfd_sparc_elf_howto_table[R_SPARC_13];
  304. case BFD_RELOC_LO10:
  305. return &_bfd_sparc_elf_howto_table[R_SPARC_LO10];
  306. case BFD_RELOC_SPARC_GOT10:
  307. return &_bfd_sparc_elf_howto_table[R_SPARC_GOT10];
  308. case BFD_RELOC_SPARC_GOT13:
  309. return &_bfd_sparc_elf_howto_table[R_SPARC_GOT13];
  310. case BFD_RELOC_SPARC_GOT22:
  311. return &_bfd_sparc_elf_howto_table[R_SPARC_GOT22];
  312. case BFD_RELOC_SPARC_PC10:
  313. return &_bfd_sparc_elf_howto_table[R_SPARC_PC10];
  314. case BFD_RELOC_SPARC_PC22:
  315. return &_bfd_sparc_elf_howto_table[R_SPARC_PC22];
  316. case BFD_RELOC_SPARC_WPLT30:
  317. return &_bfd_sparc_elf_howto_table[R_SPARC_WPLT30];
  318. case BFD_RELOC_SPARC_COPY:
  319. return &_bfd_sparc_elf_howto_table[R_SPARC_COPY];
  320. case BFD_RELOC_SPARC_GLOB_DAT:
  321. return &_bfd_sparc_elf_howto_table[R_SPARC_GLOB_DAT];
  322. case BFD_RELOC_SPARC_JMP_SLOT:
  323. return &_bfd_sparc_elf_howto_table[R_SPARC_JMP_SLOT];
  324. case BFD_RELOC_SPARC_RELATIVE:
  325. return &_bfd_sparc_elf_howto_table[R_SPARC_RELATIVE];
  326. case BFD_RELOC_SPARC_UA32:
  327. return &_bfd_sparc_elf_howto_table[R_SPARC_UA32];
  328. case BFD_RELOC_SPARC_PLT32:
  329. return &_bfd_sparc_elf_howto_table[R_SPARC_PLT32];
  330. case BFD_RELOC_SPARC_10:
  331. return &_bfd_sparc_elf_howto_table[R_SPARC_10];
  332. case BFD_RELOC_SPARC_11:
  333. return &_bfd_sparc_elf_howto_table[R_SPARC_11];
  334. case BFD_RELOC_SPARC_64:
  335. return &_bfd_sparc_elf_howto_table[R_SPARC_64];
  336. case BFD_RELOC_SPARC_OLO10:
  337. return &_bfd_sparc_elf_howto_table[R_SPARC_OLO10];
  338. case BFD_RELOC_SPARC_HH22:
  339. return &_bfd_sparc_elf_howto_table[R_SPARC_HH22];
  340. case BFD_RELOC_SPARC_HM10:
  341. return &_bfd_sparc_elf_howto_table[R_SPARC_HM10];
  342. case BFD_RELOC_SPARC_LM22:
  343. return &_bfd_sparc_elf_howto_table[R_SPARC_LM22];
  344. case BFD_RELOC_SPARC_PC_HH22:
  345. return &_bfd_sparc_elf_howto_table[R_SPARC_PC_HH22];
  346. case BFD_RELOC_SPARC_PC_HM10:
  347. return &_bfd_sparc_elf_howto_table[R_SPARC_PC_HM10];
  348. case BFD_RELOC_SPARC_PC_LM22:
  349. return &_bfd_sparc_elf_howto_table[R_SPARC_PC_LM22];
  350. case BFD_RELOC_SPARC_WDISP16:
  351. return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP16];
  352. case BFD_RELOC_SPARC_WDISP19:
  353. return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP19];
  354. case BFD_RELOC_SPARC_7:
  355. return &_bfd_sparc_elf_howto_table[R_SPARC_7];
  356. case BFD_RELOC_SPARC_5:
  357. return &_bfd_sparc_elf_howto_table[R_SPARC_5];
  358. case BFD_RELOC_SPARC_6:
  359. return &_bfd_sparc_elf_howto_table[R_SPARC_6];
  360. case BFD_RELOC_SPARC_DISP64:
  361. return &_bfd_sparc_elf_howto_table[R_SPARC_DISP64];
  362. case BFD_RELOC_SPARC_PLT64:
  363. return &_bfd_sparc_elf_howto_table[R_SPARC_PLT64];
  364. case BFD_RELOC_SPARC_HIX22:
  365. return &_bfd_sparc_elf_howto_table[R_SPARC_HIX22];
  366. case BFD_RELOC_SPARC_LOX10:
  367. return &_bfd_sparc_elf_howto_table[R_SPARC_LOX10];
  368. case BFD_RELOC_SPARC_H44:
  369. return &_bfd_sparc_elf_howto_table[R_SPARC_H44];
  370. case BFD_RELOC_SPARC_M44:
  371. return &_bfd_sparc_elf_howto_table[R_SPARC_M44];
  372. case BFD_RELOC_SPARC_L44:
  373. return &_bfd_sparc_elf_howto_table[R_SPARC_L44];
  374. case BFD_RELOC_SPARC_REGISTER:
  375. return &_bfd_sparc_elf_howto_table[R_SPARC_REGISTER];
  376. case BFD_RELOC_SPARC_UA64:
  377. return &_bfd_sparc_elf_howto_table[R_SPARC_UA64];
  378. case BFD_RELOC_SPARC_UA16:
  379. return &_bfd_sparc_elf_howto_table[R_SPARC_UA16];
  380. case BFD_RELOC_SPARC_TLS_GD_HI22:
  381. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_HI22];
  382. case BFD_RELOC_SPARC_TLS_GD_LO10:
  383. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_LO10];
  384. case BFD_RELOC_SPARC_TLS_GD_ADD:
  385. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_ADD];
  386. case BFD_RELOC_SPARC_TLS_GD_CALL:
  387. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_CALL];
  388. case BFD_RELOC_SPARC_TLS_LDM_HI22:
  389. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_HI22];
  390. case BFD_RELOC_SPARC_TLS_LDM_LO10:
  391. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_LO10];
  392. case BFD_RELOC_SPARC_TLS_LDM_ADD:
  393. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_ADD];
  394. case BFD_RELOC_SPARC_TLS_LDM_CALL:
  395. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_CALL];
  396. case BFD_RELOC_SPARC_TLS_LDO_HIX22:
  397. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_HIX22];
  398. case BFD_RELOC_SPARC_TLS_LDO_LOX10:
  399. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_LOX10];
  400. case BFD_RELOC_SPARC_TLS_LDO_ADD:
  401. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_ADD];
  402. case BFD_RELOC_SPARC_TLS_IE_HI22:
  403. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_HI22];
  404. case BFD_RELOC_SPARC_TLS_IE_LO10:
  405. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LO10];
  406. case BFD_RELOC_SPARC_TLS_IE_LD:
  407. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LD];
  408. case BFD_RELOC_SPARC_TLS_IE_LDX:
  409. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LDX];
  410. case BFD_RELOC_SPARC_TLS_IE_ADD:
  411. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_ADD];
  412. case BFD_RELOC_SPARC_TLS_LE_HIX22:
  413. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LE_HIX22];
  414. case BFD_RELOC_SPARC_TLS_LE_LOX10:
  415. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LE_LOX10];
  416. case BFD_RELOC_SPARC_TLS_DTPMOD32:
  417. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPMOD32];
  418. case BFD_RELOC_SPARC_TLS_DTPMOD64:
  419. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPMOD64];
  420. case BFD_RELOC_SPARC_TLS_DTPOFF32:
  421. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPOFF32];
  422. case BFD_RELOC_SPARC_TLS_DTPOFF64:
  423. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPOFF64];
  424. case BFD_RELOC_SPARC_TLS_TPOFF32:
  425. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_TPOFF32];
  426. case BFD_RELOC_SPARC_TLS_TPOFF64:
  427. return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_TPOFF64];
  428. case BFD_RELOC_SPARC_GOTDATA_HIX22:
  429. return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_HIX22];
  430. case BFD_RELOC_SPARC_GOTDATA_LOX10:
  431. return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_LOX10];
  432. case BFD_RELOC_SPARC_GOTDATA_OP_HIX22:
  433. return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP_HIX22];
  434. case BFD_RELOC_SPARC_GOTDATA_OP_LOX10:
  435. return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP_LOX10];
  436. case BFD_RELOC_SPARC_GOTDATA_OP:
  437. return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP];
  438. case BFD_RELOC_SPARC_H34:
  439. return &_bfd_sparc_elf_howto_table[R_SPARC_H34];
  440. case BFD_RELOC_SPARC_SIZE32:
  441. return &_bfd_sparc_elf_howto_table[R_SPARC_SIZE32];
  442. case BFD_RELOC_SPARC_SIZE64:
  443. return &_bfd_sparc_elf_howto_table[R_SPARC_SIZE64];
  444. case BFD_RELOC_SPARC_WDISP10:
  445. return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP10];
  446. case BFD_RELOC_SPARC_JMP_IREL:
  447. return &sparc_jmp_irel_howto;
  448. case BFD_RELOC_SPARC_IRELATIVE:
  449. return &sparc_irelative_howto;
  450. case BFD_RELOC_VTABLE_INHERIT:
  451. return &sparc_vtinherit_howto;
  452. case BFD_RELOC_VTABLE_ENTRY:
  453. return &sparc_vtentry_howto;
  454. case BFD_RELOC_SPARC_REV32:
  455. return &sparc_rev32_howto;
  456. default:
  457. break;
  458. }
  459. bfd_set_error (bfd_error_bad_value);
  460. return NULL;
  461. }
  462. reloc_howto_type *
  463. _bfd_sparc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  464. const char *r_name)
  465. {
  466. unsigned int i;
  467. for (i = 0;
  468. i < (sizeof (_bfd_sparc_elf_howto_table)
  469. / sizeof (_bfd_sparc_elf_howto_table[0]));
  470. i++)
  471. if (_bfd_sparc_elf_howto_table[i].name != NULL
  472. && strcasecmp (_bfd_sparc_elf_howto_table[i].name, r_name) == 0)
  473. return &_bfd_sparc_elf_howto_table[i];
  474. if (strcasecmp (sparc_vtinherit_howto.name, r_name) == 0)
  475. return &sparc_vtinherit_howto;
  476. if (strcasecmp (sparc_vtentry_howto.name, r_name) == 0)
  477. return &sparc_vtentry_howto;
  478. if (strcasecmp (sparc_rev32_howto.name, r_name) == 0)
  479. return &sparc_rev32_howto;
  480. return NULL;
  481. }
  482. reloc_howto_type *
  483. _bfd_sparc_elf_info_to_howto_ptr (unsigned int r_type)
  484. {
  485. switch (r_type)
  486. {
  487. case R_SPARC_JMP_IREL:
  488. return &sparc_jmp_irel_howto;
  489. case R_SPARC_IRELATIVE:
  490. return &sparc_irelative_howto;
  491. case R_SPARC_GNU_VTINHERIT:
  492. return &sparc_vtinherit_howto;
  493. case R_SPARC_GNU_VTENTRY:
  494. return &sparc_vtentry_howto;
  495. case R_SPARC_REV32:
  496. return &sparc_rev32_howto;
  497. default:
  498. if (r_type >= (unsigned int) R_SPARC_max_std)
  499. {
  500. (*_bfd_error_handler) (_("invalid relocation type %d"),
  501. (int) r_type);
  502. r_type = R_SPARC_NONE;
  503. }
  504. return &_bfd_sparc_elf_howto_table[r_type];
  505. }
  506. }
  507. /* Both 32-bit and 64-bit sparc encode this in an identical manner,
  508. so just take advantage of that. */
  509. #define SPARC_ELF_R_TYPE(r_info) \
  510. ((r_info) & 0xff)
  511. void
  512. _bfd_sparc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
  513. Elf_Internal_Rela *dst)
  514. {
  515. unsigned int r_type = SPARC_ELF_R_TYPE (dst->r_info);
  516. cache_ptr->howto = _bfd_sparc_elf_info_to_howto_ptr (r_type);
  517. }
  518. /* The nop opcode we use. */
  519. #define SPARC_NOP 0x01000000
  520. #define SPARC_INSN_BYTES 4
  521. /* The SPARC linker needs to keep track of the number of relocs that it
  522. decides to copy as dynamic relocs in check_relocs for each symbol.
  523. This is so that it can later discard them if they are found to be
  524. unnecessary. We store the information in a field extending the
  525. regular ELF linker hash table. */
  526. struct _bfd_sparc_elf_dyn_relocs
  527. {
  528. struct _bfd_sparc_elf_dyn_relocs *next;
  529. /* The input section of the reloc. */
  530. asection *sec;
  531. /* Total number of relocs copied for the input section. */
  532. bfd_size_type count;
  533. /* Number of pc-relative relocs copied for the input section. */
  534. bfd_size_type pc_count;
  535. };
  536. /* SPARC ELF linker hash entry. */
  537. struct _bfd_sparc_elf_link_hash_entry
  538. {
  539. struct elf_link_hash_entry elf;
  540. /* Track dynamic relocs copied for this symbol. */
  541. struct _bfd_sparc_elf_dyn_relocs *dyn_relocs;
  542. #define GOT_UNKNOWN 0
  543. #define GOT_NORMAL 1
  544. #define GOT_TLS_GD 2
  545. #define GOT_TLS_IE 3
  546. unsigned char tls_type;
  547. };
  548. #define _bfd_sparc_elf_hash_entry(ent) ((struct _bfd_sparc_elf_link_hash_entry *)(ent))
  549. struct _bfd_sparc_elf_obj_tdata
  550. {
  551. struct elf_obj_tdata root;
  552. /* tls_type for each local got entry. */
  553. char *local_got_tls_type;
  554. /* TRUE if TLS GD relocs has been seen for this object. */
  555. bfd_boolean has_tlsgd;
  556. };
  557. #define _bfd_sparc_elf_tdata(abfd) \
  558. ((struct _bfd_sparc_elf_obj_tdata *) (abfd)->tdata.any)
  559. #define _bfd_sparc_elf_local_got_tls_type(abfd) \
  560. (_bfd_sparc_elf_tdata (abfd)->local_got_tls_type)
  561. #define is_sparc_elf(bfd) \
  562. (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  563. && elf_tdata (bfd) != NULL \
  564. && elf_object_id (bfd) == SPARC_ELF_DATA)
  565. bfd_boolean
  566. _bfd_sparc_elf_mkobject (bfd *abfd)
  567. {
  568. return bfd_elf_allocate_object (abfd, sizeof (struct _bfd_sparc_elf_obj_tdata),
  569. SPARC_ELF_DATA);
  570. }
  571. static void
  572. sparc_put_word_32 (bfd *abfd, bfd_vma val, void *ptr)
  573. {
  574. bfd_put_32 (abfd, val, ptr);
  575. }
  576. static void
  577. sparc_put_word_64 (bfd *abfd, bfd_vma val, void *ptr)
  578. {
  579. bfd_put_64 (abfd, val, ptr);
  580. }
  581. static void
  582. sparc_elf_append_rela (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
  583. {
  584. const struct elf_backend_data *bed;
  585. bfd_byte *loc;
  586. bed = get_elf_backend_data (abfd);
  587. loc = s->contents + (s->reloc_count++ * bed->s->sizeof_rela);
  588. bed->s->swap_reloca_out (abfd, rel, loc);
  589. }
  590. static bfd_vma
  591. sparc_elf_r_info_64 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
  592. bfd_vma rel_index ATTRIBUTE_UNUSED,
  593. bfd_vma type ATTRIBUTE_UNUSED)
  594. {
  595. return ELF64_R_INFO (rel_index,
  596. (in_rel ?
  597. ELF64_R_TYPE_INFO (ELF64_R_TYPE_DATA (in_rel->r_info),
  598. type) : type));
  599. }
  600. static bfd_vma
  601. sparc_elf_r_info_32 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
  602. bfd_vma rel_index, bfd_vma type)
  603. {
  604. return ELF32_R_INFO (rel_index, type);
  605. }
  606. static bfd_vma
  607. sparc_elf_r_symndx_64 (bfd_vma r_info)
  608. {
  609. bfd_vma r_symndx = ELF32_R_SYM (r_info);
  610. return (r_symndx >> 24);
  611. }
  612. static bfd_vma
  613. sparc_elf_r_symndx_32 (bfd_vma r_info)
  614. {
  615. return ELF32_R_SYM (r_info);
  616. }
  617. /* PLT/GOT stuff */
  618. #define PLT32_ENTRY_SIZE 12
  619. #define PLT32_HEADER_SIZE (4 * PLT32_ENTRY_SIZE)
  620. /* The first four entries in a 32-bit procedure linkage table are reserved,
  621. and the initial contents are unimportant (we zero them out).
  622. Subsequent entries look like this. See the SVR4 ABI SPARC
  623. supplement to see how this works. */
  624. /* sethi %hi(.-.plt0),%g1. We fill in the address later. */
  625. #define PLT32_ENTRY_WORD0 0x03000000
  626. /* b,a .plt0. We fill in the offset later. */
  627. #define PLT32_ENTRY_WORD1 0x30800000
  628. /* nop. */
  629. #define PLT32_ENTRY_WORD2 SPARC_NOP
  630. static int
  631. sparc32_plt_entry_build (bfd *output_bfd, asection *splt, bfd_vma offset,
  632. bfd_vma max ATTRIBUTE_UNUSED,
  633. bfd_vma *r_offset)
  634. {
  635. bfd_put_32 (output_bfd,
  636. PLT32_ENTRY_WORD0 + offset,
  637. splt->contents + offset);
  638. bfd_put_32 (output_bfd,
  639. (PLT32_ENTRY_WORD1
  640. + (((- (offset + 4)) >> 2) & 0x3fffff)),
  641. splt->contents + offset + 4);
  642. bfd_put_32 (output_bfd, (bfd_vma) PLT32_ENTRY_WORD2,
  643. splt->contents + offset + 8);
  644. *r_offset = offset;
  645. return offset / PLT32_ENTRY_SIZE - 4;
  646. }
  647. /* Both the headers and the entries are icache aligned. */
  648. #define PLT64_ENTRY_SIZE 32
  649. #define PLT64_HEADER_SIZE (4 * PLT64_ENTRY_SIZE)
  650. #define PLT64_LARGE_THRESHOLD 32768
  651. static int
  652. sparc64_plt_entry_build (bfd *output_bfd, asection *splt, bfd_vma offset,
  653. bfd_vma max, bfd_vma *r_offset)
  654. {
  655. unsigned char *entry = splt->contents + offset;
  656. const unsigned int nop = SPARC_NOP;
  657. int plt_index;
  658. if (offset < (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE))
  659. {
  660. unsigned int sethi, ba;
  661. *r_offset = offset;
  662. plt_index = (offset / PLT64_ENTRY_SIZE);
  663. sethi = 0x03000000 | (plt_index * PLT64_ENTRY_SIZE);
  664. ba = 0x30680000
  665. | (((splt->contents + PLT64_ENTRY_SIZE) - (entry + 4)) / 4 & 0x7ffff);
  666. bfd_put_32 (output_bfd, (bfd_vma) sethi, entry);
  667. bfd_put_32 (output_bfd, (bfd_vma) ba, entry + 4);
  668. bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 8);
  669. bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 12);
  670. bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 16);
  671. bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 20);
  672. bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 24);
  673. bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 28);
  674. }
  675. else
  676. {
  677. unsigned char *ptr;
  678. unsigned int ldx;
  679. int block, last_block, ofs, last_ofs, chunks_this_block;
  680. const int insn_chunk_size = (6 * 4);
  681. const int ptr_chunk_size = (1 * 8);
  682. const int entries_per_block = 160;
  683. const int block_size = entries_per_block * (insn_chunk_size
  684. + ptr_chunk_size);
  685. /* Entries 32768 and higher are grouped into blocks of 160.
  686. The blocks are further subdivided into 160 sequences of
  687. 6 instructions and 160 pointers. If a block does not require
  688. the full 160 entries, let's say it requires N, then there
  689. will be N sequences of 6 instructions and N pointers. */
  690. offset -= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE);
  691. max -= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE);
  692. block = offset / block_size;
  693. last_block = max / block_size;
  694. if (block != last_block)
  695. {
  696. chunks_this_block = 160;
  697. }
  698. else
  699. {
  700. last_ofs = max % block_size;
  701. chunks_this_block = last_ofs / (insn_chunk_size + ptr_chunk_size);
  702. }
  703. ofs = offset % block_size;
  704. plt_index = (PLT64_LARGE_THRESHOLD +
  705. (block * 160) +
  706. (ofs / insn_chunk_size));
  707. ptr = splt->contents
  708. + (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE)
  709. + (block * block_size)
  710. + (chunks_this_block * insn_chunk_size)
  711. + (ofs / insn_chunk_size) * ptr_chunk_size;
  712. *r_offset = (bfd_vma) (ptr - splt->contents);
  713. ldx = 0xc25be000 | ((ptr - (entry+4)) & 0x1fff);
  714. /* mov %o7,%g5
  715. call .+8
  716. nop
  717. ldx [%o7+P],%g1
  718. jmpl %o7+%g1,%g1
  719. mov %g5,%o7 */
  720. bfd_put_32 (output_bfd, (bfd_vma) 0x8a10000f, entry);
  721. bfd_put_32 (output_bfd, (bfd_vma) 0x40000002, entry + 4);
  722. bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP, entry + 8);
  723. bfd_put_32 (output_bfd, (bfd_vma) ldx, entry + 12);
  724. bfd_put_32 (output_bfd, (bfd_vma) 0x83c3c001, entry + 16);
  725. bfd_put_32 (output_bfd, (bfd_vma) 0x9e100005, entry + 20);
  726. bfd_put_64 (output_bfd, (bfd_vma) (splt->contents - (entry + 4)), ptr);
  727. }
  728. return plt_index - 4;
  729. }
  730. /* The format of the first PLT entry in a VxWorks executable. */
  731. static const bfd_vma sparc_vxworks_exec_plt0_entry[] =
  732. {
  733. 0x05000000, /* sethi %hi(_GLOBAL_OFFSET_TABLE_+8), %g2 */
  734. 0x8410a000, /* or %g2, %lo(_GLOBAL_OFFSET_TABLE_+8), %g2 */
  735. 0xc4008000, /* ld [ %g2 ], %g2 */
  736. 0x81c08000, /* jmp %g2 */
  737. 0x01000000 /* nop */
  738. };
  739. /* The format of subsequent PLT entries. */
  740. static const bfd_vma sparc_vxworks_exec_plt_entry[] =
  741. {
  742. 0x03000000, /* sethi %hi(_GLOBAL_OFFSET_TABLE_+f@got), %g1 */
  743. 0x82106000, /* or %g1, %lo(_GLOBAL_OFFSET_TABLE_+f@got), %g1 */
  744. 0xc2004000, /* ld [ %g1 ], %g1 */
  745. 0x81c04000, /* jmp %g1 */
  746. 0x01000000, /* nop */
  747. 0x03000000, /* sethi %hi(f@pltindex), %g1 */
  748. 0x10800000, /* b _PLT_resolve */
  749. 0x82106000 /* or %g1, %lo(f@pltindex), %g1 */
  750. };
  751. /* The format of the first PLT entry in a VxWorks shared object. */
  752. static const bfd_vma sparc_vxworks_shared_plt0_entry[] =
  753. {
  754. 0xc405e008, /* ld [ %l7 + 8 ], %g2 */
  755. 0x81c08000, /* jmp %g2 */
  756. 0x01000000 /* nop */
  757. };
  758. /* The format of subsequent PLT entries. */
  759. static const bfd_vma sparc_vxworks_shared_plt_entry[] =
  760. {
  761. 0x03000000, /* sethi %hi(f@got), %g1 */
  762. 0x82106000, /* or %g1, %lo(f@got), %g1 */
  763. 0xc205c001, /* ld [ %l7 + %g1 ], %g1 */
  764. 0x81c04000, /* jmp %g1 */
  765. 0x01000000, /* nop */
  766. 0x03000000, /* sethi %hi(f@pltindex), %g1 */
  767. 0x10800000, /* b _PLT_resolve */
  768. 0x82106000 /* or %g1, %lo(f@pltindex), %g1 */
  769. };
  770. #define SPARC_ELF_PUT_WORD(htab, bfd, val, ptr) \
  771. htab->put_word(bfd, val, ptr)
  772. #define SPARC_ELF_R_INFO(htab, in_rel, index, type) \
  773. htab->r_info(in_rel, index, type)
  774. #define SPARC_ELF_R_SYMNDX(htab, r_info) \
  775. htab->r_symndx(r_info)
  776. #define SPARC_ELF_WORD_BYTES(htab) \
  777. htab->bytes_per_word
  778. #define SPARC_ELF_RELA_BYTES(htab) \
  779. htab->bytes_per_rela
  780. #define SPARC_ELF_DTPOFF_RELOC(htab) \
  781. htab->dtpoff_reloc
  782. #define SPARC_ELF_DTPMOD_RELOC(htab) \
  783. htab->dtpmod_reloc
  784. #define SPARC_ELF_TPOFF_RELOC(htab) \
  785. htab->tpoff_reloc
  786. #define SPARC_ELF_BUILD_PLT_ENTRY(htab, obfd, splt, off, max, r_off) \
  787. htab->build_plt_entry (obfd, splt, off, max, r_off)
  788. /* Create an entry in an SPARC ELF linker hash table. */
  789. static struct bfd_hash_entry *
  790. link_hash_newfunc (struct bfd_hash_entry *entry,
  791. struct bfd_hash_table *table, const char *string)
  792. {
  793. /* Allocate the structure if it has not already been allocated by a
  794. subclass. */
  795. if (entry == NULL)
  796. {
  797. entry = bfd_hash_allocate (table,
  798. sizeof (struct _bfd_sparc_elf_link_hash_entry));
  799. if (entry == NULL)
  800. return entry;
  801. }
  802. /* Call the allocation method of the superclass. */
  803. entry = _bfd_elf_link_hash_newfunc (entry, table, string);
  804. if (entry != NULL)
  805. {
  806. struct _bfd_sparc_elf_link_hash_entry *eh;
  807. eh = (struct _bfd_sparc_elf_link_hash_entry *) entry;
  808. eh->dyn_relocs = NULL;
  809. eh->tls_type = GOT_UNKNOWN;
  810. }
  811. return entry;
  812. }
  813. /* The name of the dynamic interpreter. This is put in the .interp
  814. section. */
  815. #define ELF32_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
  816. #define ELF64_DYNAMIC_INTERPRETER "/usr/lib/sparcv9/ld.so.1"
  817. /* Compute a hash of a local hash entry. We use elf_link_hash_entry
  818. for local symbol so that we can handle local STT_GNU_IFUNC symbols
  819. as global symbol. We reuse indx and dynstr_index for local symbol
  820. hash since they aren't used by global symbols in this backend. */
  821. static hashval_t
  822. elf_sparc_local_htab_hash (const void *ptr)
  823. {
  824. struct elf_link_hash_entry *h
  825. = (struct elf_link_hash_entry *) ptr;
  826. return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
  827. }
  828. /* Compare local hash entries. */
  829. static int
  830. elf_sparc_local_htab_eq (const void *ptr1, const void *ptr2)
  831. {
  832. struct elf_link_hash_entry *h1
  833. = (struct elf_link_hash_entry *) ptr1;
  834. struct elf_link_hash_entry *h2
  835. = (struct elf_link_hash_entry *) ptr2;
  836. return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
  837. }
  838. /* Find and/or create a hash entry for local symbol. */
  839. static struct elf_link_hash_entry *
  840. elf_sparc_get_local_sym_hash (struct _bfd_sparc_elf_link_hash_table *htab,
  841. bfd *abfd, const Elf_Internal_Rela *rel,
  842. bfd_boolean create)
  843. {
  844. struct _bfd_sparc_elf_link_hash_entry e, *ret;
  845. asection *sec = abfd->sections;
  846. unsigned long r_symndx;
  847. hashval_t h;
  848. void **slot;
  849. r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
  850. h = ELF_LOCAL_SYMBOL_HASH (sec->id, r_symndx);
  851. e.elf.indx = sec->id;
  852. e.elf.dynstr_index = r_symndx;
  853. slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
  854. create ? INSERT : NO_INSERT);
  855. if (!slot)
  856. return NULL;
  857. if (*slot)
  858. {
  859. ret = (struct _bfd_sparc_elf_link_hash_entry *) *slot;
  860. return &ret->elf;
  861. }
  862. ret = (struct _bfd_sparc_elf_link_hash_entry *)
  863. objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
  864. sizeof (struct _bfd_sparc_elf_link_hash_entry));
  865. if (ret)
  866. {
  867. memset (ret, 0, sizeof (*ret));
  868. ret->elf.indx = sec->id;
  869. ret->elf.dynstr_index = r_symndx;
  870. ret->elf.dynindx = -1;
  871. ret->elf.plt.offset = (bfd_vma) -1;
  872. ret->elf.got.offset = (bfd_vma) -1;
  873. *slot = ret;
  874. }
  875. return &ret->elf;
  876. }
  877. /* Destroy a SPARC ELF linker hash table. */
  878. static void
  879. _bfd_sparc_elf_link_hash_table_free (bfd *obfd)
  880. {
  881. struct _bfd_sparc_elf_link_hash_table *htab
  882. = (struct _bfd_sparc_elf_link_hash_table *) obfd->link.hash;
  883. if (htab->loc_hash_table)
  884. htab_delete (htab->loc_hash_table);
  885. if (htab->loc_hash_memory)
  886. objalloc_free ((struct objalloc *) htab->loc_hash_memory);
  887. _bfd_elf_link_hash_table_free (obfd);
  888. }
  889. /* Create a SPARC ELF linker hash table. */
  890. struct bfd_link_hash_table *
  891. _bfd_sparc_elf_link_hash_table_create (bfd *abfd)
  892. {
  893. struct _bfd_sparc_elf_link_hash_table *ret;
  894. bfd_size_type amt = sizeof (struct _bfd_sparc_elf_link_hash_table);
  895. ret = (struct _bfd_sparc_elf_link_hash_table *) bfd_zmalloc (amt);
  896. if (ret == NULL)
  897. return NULL;
  898. if (ABI_64_P (abfd))
  899. {
  900. ret->put_word = sparc_put_word_64;
  901. ret->r_info = sparc_elf_r_info_64;
  902. ret->r_symndx = sparc_elf_r_symndx_64;
  903. ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF64;
  904. ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD64;
  905. ret->tpoff_reloc = R_SPARC_TLS_TPOFF64;
  906. ret->word_align_power = 3;
  907. ret->align_power_max = 4;
  908. ret->bytes_per_word = 8;
  909. ret->bytes_per_rela = sizeof (Elf64_External_Rela);
  910. ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
  911. ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
  912. ret->build_plt_entry = sparc64_plt_entry_build;
  913. ret->plt_header_size = PLT64_HEADER_SIZE;
  914. ret->plt_entry_size = PLT64_ENTRY_SIZE;
  915. }
  916. else
  917. {
  918. ret->put_word = sparc_put_word_32;
  919. ret->r_info = sparc_elf_r_info_32;
  920. ret->r_symndx = sparc_elf_r_symndx_32;
  921. ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF32;
  922. ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD32;
  923. ret->tpoff_reloc = R_SPARC_TLS_TPOFF32;
  924. ret->word_align_power = 2;
  925. ret->align_power_max = 3;
  926. ret->bytes_per_word = 4;
  927. ret->bytes_per_rela = sizeof (Elf32_External_Rela);
  928. ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
  929. ret->dynamic_interpreter_size = sizeof ELF32_DYNAMIC_INTERPRETER;
  930. ret->build_plt_entry = sparc32_plt_entry_build;
  931. ret->plt_header_size = PLT32_HEADER_SIZE;
  932. ret->plt_entry_size = PLT32_ENTRY_SIZE;
  933. }
  934. if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
  935. sizeof (struct _bfd_sparc_elf_link_hash_entry),
  936. SPARC_ELF_DATA))
  937. {
  938. free (ret);
  939. return NULL;
  940. }
  941. ret->loc_hash_table = htab_try_create (1024,
  942. elf_sparc_local_htab_hash,
  943. elf_sparc_local_htab_eq,
  944. NULL);
  945. ret->loc_hash_memory = objalloc_create ();
  946. if (!ret->loc_hash_table || !ret->loc_hash_memory)
  947. {
  948. _bfd_sparc_elf_link_hash_table_free (abfd);
  949. return NULL;
  950. }
  951. ret->elf.root.hash_table_free = _bfd_sparc_elf_link_hash_table_free;
  952. return &ret->elf.root;
  953. }
  954. /* Create .plt, .rela.plt, .got, .rela.got, .dynbss, and
  955. .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
  956. hash table. */
  957. bfd_boolean
  958. _bfd_sparc_elf_create_dynamic_sections (bfd *dynobj,
  959. struct bfd_link_info *info)
  960. {
  961. struct _bfd_sparc_elf_link_hash_table *htab;
  962. htab = _bfd_sparc_elf_hash_table (info);
  963. BFD_ASSERT (htab != NULL);
  964. if (!_bfd_elf_create_dynamic_sections (dynobj, info))
  965. return FALSE;
  966. htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
  967. if (!bfd_link_pic (info))
  968. htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
  969. if (htab->is_vxworks)
  970. {
  971. if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
  972. return FALSE;
  973. if (bfd_link_pic (info))
  974. {
  975. htab->plt_header_size
  976. = 4 * ARRAY_SIZE (sparc_vxworks_shared_plt0_entry);
  977. htab->plt_entry_size
  978. = 4 * ARRAY_SIZE (sparc_vxworks_shared_plt_entry);
  979. }
  980. else
  981. {
  982. htab->plt_header_size
  983. = 4 * ARRAY_SIZE (sparc_vxworks_exec_plt0_entry);
  984. htab->plt_entry_size
  985. = 4 * ARRAY_SIZE (sparc_vxworks_exec_plt_entry);
  986. }
  987. }
  988. if (!htab->elf.splt || !htab->elf.srelplt || !htab->sdynbss
  989. || (!bfd_link_pic (info) && !htab->srelbss))
  990. abort ();
  991. return TRUE;
  992. }
  993. static bfd_boolean
  994. create_ifunc_sections (bfd *abfd, struct bfd_link_info *info)
  995. {
  996. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  997. struct elf_link_hash_table *htab = elf_hash_table (info);
  998. flagword flags, pltflags;
  999. asection *s;
  1000. if (htab->irelifunc != NULL || htab->iplt != NULL)
  1001. return TRUE;
  1002. flags = bed->dynamic_sec_flags;
  1003. pltflags = flags | SEC_ALLOC | SEC_CODE | SEC_LOAD;
  1004. s = bfd_make_section_with_flags (abfd, ".iplt", pltflags);
  1005. if (s == NULL
  1006. || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
  1007. return FALSE;
  1008. htab->iplt = s;
  1009. s = bfd_make_section_with_flags (abfd, ".rela.iplt",
  1010. flags | SEC_READONLY);
  1011. if (s == NULL
  1012. || ! bfd_set_section_alignment (abfd, s,
  1013. bed->s->log_file_align))
  1014. return FALSE;
  1015. htab->irelplt = s;
  1016. return TRUE;
  1017. }
  1018. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  1019. void
  1020. _bfd_sparc_elf_copy_indirect_symbol (struct bfd_link_info *info,
  1021. struct elf_link_hash_entry *dir,
  1022. struct elf_link_hash_entry *ind)
  1023. {
  1024. struct _bfd_sparc_elf_link_hash_entry *edir, *eind;
  1025. edir = (struct _bfd_sparc_elf_link_hash_entry *) dir;
  1026. eind = (struct _bfd_sparc_elf_link_hash_entry *) ind;
  1027. if (eind->dyn_relocs != NULL)
  1028. {
  1029. if (edir->dyn_relocs != NULL)
  1030. {
  1031. struct _bfd_sparc_elf_dyn_relocs **pp;
  1032. struct _bfd_sparc_elf_dyn_relocs *p;
  1033. /* Add reloc counts against the indirect sym to the direct sym
  1034. list. Merge any entries against the same section. */
  1035. for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
  1036. {
  1037. struct _bfd_sparc_elf_dyn_relocs *q;
  1038. for (q = edir->dyn_relocs; q != NULL; q = q->next)
  1039. if (q->sec == p->sec)
  1040. {
  1041. q->pc_count += p->pc_count;
  1042. q->count += p->count;
  1043. *pp = p->next;
  1044. break;
  1045. }
  1046. if (q == NULL)
  1047. pp = &p->next;
  1048. }
  1049. *pp = edir->dyn_relocs;
  1050. }
  1051. edir->dyn_relocs = eind->dyn_relocs;
  1052. eind->dyn_relocs = NULL;
  1053. }
  1054. if (ind->root.type == bfd_link_hash_indirect
  1055. && dir->got.refcount <= 0)
  1056. {
  1057. edir->tls_type = eind->tls_type;
  1058. eind->tls_type = GOT_UNKNOWN;
  1059. }
  1060. _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  1061. }
  1062. static int
  1063. sparc_elf_tls_transition (struct bfd_link_info *info, bfd *abfd,
  1064. int r_type, int is_local)
  1065. {
  1066. if (! ABI_64_P (abfd)
  1067. && r_type == R_SPARC_TLS_GD_HI22
  1068. && ! _bfd_sparc_elf_tdata (abfd)->has_tlsgd)
  1069. r_type = R_SPARC_REV32;
  1070. if (bfd_link_pic (info))
  1071. return r_type;
  1072. switch (r_type)
  1073. {
  1074. case R_SPARC_TLS_GD_HI22:
  1075. if (is_local)
  1076. return R_SPARC_TLS_LE_HIX22;
  1077. return R_SPARC_TLS_IE_HI22;
  1078. case R_SPARC_TLS_GD_LO10:
  1079. if (is_local)
  1080. return R_SPARC_TLS_LE_LOX10;
  1081. return R_SPARC_TLS_IE_LO10;
  1082. case R_SPARC_TLS_IE_HI22:
  1083. if (is_local)
  1084. return R_SPARC_TLS_LE_HIX22;
  1085. return r_type;
  1086. case R_SPARC_TLS_IE_LO10:
  1087. if (is_local)
  1088. return R_SPARC_TLS_LE_LOX10;
  1089. return r_type;
  1090. case R_SPARC_TLS_LDM_HI22:
  1091. return R_SPARC_TLS_LE_HIX22;
  1092. case R_SPARC_TLS_LDM_LO10:
  1093. return R_SPARC_TLS_LE_LOX10;
  1094. }
  1095. return r_type;
  1096. }
  1097. /* Look through the relocs for a section during the first phase, and
  1098. allocate space in the global offset table or procedure linkage
  1099. table. */
  1100. bfd_boolean
  1101. _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
  1102. asection *sec, const Elf_Internal_Rela *relocs)
  1103. {
  1104. struct _bfd_sparc_elf_link_hash_table *htab;
  1105. Elf_Internal_Shdr *symtab_hdr;
  1106. struct elf_link_hash_entry **sym_hashes;
  1107. const Elf_Internal_Rela *rel;
  1108. const Elf_Internal_Rela *rel_end;
  1109. asection *sreloc;
  1110. int num_relocs;
  1111. bfd_boolean checked_tlsgd = FALSE;
  1112. if (bfd_link_relocatable (info))
  1113. return TRUE;
  1114. htab = _bfd_sparc_elf_hash_table (info);
  1115. BFD_ASSERT (htab != NULL);
  1116. symtab_hdr = &elf_symtab_hdr (abfd);
  1117. sym_hashes = elf_sym_hashes (abfd);
  1118. sreloc = NULL;
  1119. if (ABI_64_P (abfd))
  1120. num_relocs = NUM_SHDR_ENTRIES (_bfd_elf_single_rel_hdr (sec));
  1121. else
  1122. num_relocs = sec->reloc_count;
  1123. BFD_ASSERT (is_sparc_elf (abfd) || num_relocs == 0);
  1124. if (htab->elf.dynobj == NULL)
  1125. htab->elf.dynobj = abfd;
  1126. if (!create_ifunc_sections (htab->elf.dynobj, info))
  1127. return FALSE;
  1128. rel_end = relocs + num_relocs;
  1129. for (rel = relocs; rel < rel_end; rel++)
  1130. {
  1131. unsigned int r_type;
  1132. unsigned long r_symndx;
  1133. struct elf_link_hash_entry *h;
  1134. Elf_Internal_Sym *isym;
  1135. r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
  1136. r_type = SPARC_ELF_R_TYPE (rel->r_info);
  1137. if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
  1138. {
  1139. (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
  1140. abfd, r_symndx);
  1141. return FALSE;
  1142. }
  1143. isym = NULL;
  1144. if (r_symndx < symtab_hdr->sh_info)
  1145. {
  1146. /* A local symbol. */
  1147. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  1148. abfd, r_symndx);
  1149. if (isym == NULL)
  1150. return FALSE;
  1151. /* Check relocation against local STT_GNU_IFUNC symbol. */
  1152. if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
  1153. {
  1154. h = elf_sparc_get_local_sym_hash (htab, abfd, rel,
  1155. TRUE);
  1156. if (h == NULL)
  1157. return FALSE;
  1158. /* Fake a STT_GNU_IFUNC symbol. */
  1159. h->type = STT_GNU_IFUNC;
  1160. h->def_regular = 1;
  1161. h->ref_regular = 1;
  1162. h->forced_local = 1;
  1163. h->root.type = bfd_link_hash_defined;
  1164. }
  1165. else
  1166. h = NULL;
  1167. }
  1168. else
  1169. {
  1170. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1171. while (h->root.type == bfd_link_hash_indirect
  1172. || h->root.type == bfd_link_hash_warning)
  1173. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1174. /* PR15323, ref flags aren't set for references in the same
  1175. object. */
  1176. h->root.non_ir_ref = 1;
  1177. }
  1178. if (h && h->type == STT_GNU_IFUNC)
  1179. {
  1180. if (h->def_regular)
  1181. {
  1182. h->ref_regular = 1;
  1183. h->plt.refcount += 1;
  1184. }
  1185. }
  1186. /* Compatibility with old R_SPARC_REV32 reloc conflicting
  1187. with R_SPARC_TLS_GD_HI22. */
  1188. if (! ABI_64_P (abfd) && ! checked_tlsgd)
  1189. switch (r_type)
  1190. {
  1191. case R_SPARC_TLS_GD_HI22:
  1192. {
  1193. const Elf_Internal_Rela *relt;
  1194. for (relt = rel + 1; relt < rel_end; relt++)
  1195. if (ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_LO10
  1196. || ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_ADD
  1197. || ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_CALL)
  1198. break;
  1199. checked_tlsgd = TRUE;
  1200. _bfd_sparc_elf_tdata (abfd)->has_tlsgd = relt < rel_end;
  1201. }
  1202. break;
  1203. case R_SPARC_TLS_GD_LO10:
  1204. case R_SPARC_TLS_GD_ADD:
  1205. case R_SPARC_TLS_GD_CALL:
  1206. checked_tlsgd = TRUE;
  1207. _bfd_sparc_elf_tdata (abfd)->has_tlsgd = TRUE;
  1208. break;
  1209. }
  1210. r_type = sparc_elf_tls_transition (info, abfd, r_type, h == NULL);
  1211. switch (r_type)
  1212. {
  1213. case R_SPARC_TLS_LDM_HI22:
  1214. case R_SPARC_TLS_LDM_LO10:
  1215. htab->tls_ldm_got.refcount += 1;
  1216. break;
  1217. case R_SPARC_TLS_LE_HIX22:
  1218. case R_SPARC_TLS_LE_LOX10:
  1219. if (bfd_link_pic (info))
  1220. goto r_sparc_plt32;
  1221. break;
  1222. case R_SPARC_TLS_IE_HI22:
  1223. case R_SPARC_TLS_IE_LO10:
  1224. if (bfd_link_pic (info))
  1225. info->flags |= DF_STATIC_TLS;
  1226. /* Fall through */
  1227. case R_SPARC_GOT10:
  1228. case R_SPARC_GOT13:
  1229. case R_SPARC_GOT22:
  1230. case R_SPARC_GOTDATA_HIX22:
  1231. case R_SPARC_GOTDATA_LOX10:
  1232. case R_SPARC_GOTDATA_OP_HIX22:
  1233. case R_SPARC_GOTDATA_OP_LOX10:
  1234. case R_SPARC_TLS_GD_HI22:
  1235. case R_SPARC_TLS_GD_LO10:
  1236. /* This symbol requires a global offset table entry. */
  1237. {
  1238. int tls_type, old_tls_type;
  1239. switch (r_type)
  1240. {
  1241. default:
  1242. case R_SPARC_GOT10:
  1243. case R_SPARC_GOT13:
  1244. case R_SPARC_GOT22:
  1245. case R_SPARC_GOTDATA_OP_HIX22:
  1246. case R_SPARC_GOTDATA_OP_LOX10:
  1247. tls_type = GOT_NORMAL;
  1248. break;
  1249. case R_SPARC_TLS_GD_HI22:
  1250. case R_SPARC_TLS_GD_LO10:
  1251. tls_type = GOT_TLS_GD;
  1252. break;
  1253. case R_SPARC_TLS_IE_HI22:
  1254. case R_SPARC_TLS_IE_LO10:
  1255. tls_type = GOT_TLS_IE;
  1256. break;
  1257. }
  1258. if (h != NULL)
  1259. {
  1260. h->got.refcount += 1;
  1261. old_tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
  1262. }
  1263. else
  1264. {
  1265. bfd_signed_vma *local_got_refcounts;
  1266. /* This is a global offset table entry for a local symbol. */
  1267. local_got_refcounts = elf_local_got_refcounts (abfd);
  1268. if (local_got_refcounts == NULL)
  1269. {
  1270. bfd_size_type size;
  1271. size = symtab_hdr->sh_info;
  1272. size *= (sizeof (bfd_signed_vma) + sizeof(char));
  1273. local_got_refcounts = ((bfd_signed_vma *)
  1274. bfd_zalloc (abfd, size));
  1275. if (local_got_refcounts == NULL)
  1276. return FALSE;
  1277. elf_local_got_refcounts (abfd) = local_got_refcounts;
  1278. _bfd_sparc_elf_local_got_tls_type (abfd)
  1279. = (char *) (local_got_refcounts + symtab_hdr->sh_info);
  1280. }
  1281. switch (r_type)
  1282. {
  1283. case R_SPARC_GOTDATA_OP_HIX22:
  1284. case R_SPARC_GOTDATA_OP_LOX10:
  1285. break;
  1286. default:
  1287. local_got_refcounts[r_symndx] += 1;
  1288. break;
  1289. }
  1290. old_tls_type = _bfd_sparc_elf_local_got_tls_type (abfd) [r_symndx];
  1291. }
  1292. /* If a TLS symbol is accessed using IE at least once,
  1293. there is no point to use dynamic model for it. */
  1294. if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
  1295. && (old_tls_type != GOT_TLS_GD
  1296. || tls_type != GOT_TLS_IE))
  1297. {
  1298. if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
  1299. tls_type = old_tls_type;
  1300. else
  1301. {
  1302. (*_bfd_error_handler)
  1303. (_("%B: `%s' accessed both as normal and thread local symbol"),
  1304. abfd, h ? h->root.root.string : "<local>");
  1305. return FALSE;
  1306. }
  1307. }
  1308. if (old_tls_type != tls_type)
  1309. {
  1310. if (h != NULL)
  1311. _bfd_sparc_elf_hash_entry (h)->tls_type = tls_type;
  1312. else
  1313. _bfd_sparc_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
  1314. }
  1315. }
  1316. if (htab->elf.sgot == NULL)
  1317. {
  1318. if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
  1319. return FALSE;
  1320. }
  1321. break;
  1322. case R_SPARC_TLS_GD_CALL:
  1323. case R_SPARC_TLS_LDM_CALL:
  1324. if (bfd_link_pic (info))
  1325. {
  1326. /* These are basically R_SPARC_TLS_WPLT30 relocs against
  1327. __tls_get_addr. */
  1328. struct bfd_link_hash_entry *bh = NULL;
  1329. if (! _bfd_generic_link_add_one_symbol (info, abfd,
  1330. "__tls_get_addr", 0,
  1331. bfd_und_section_ptr, 0,
  1332. NULL, FALSE, FALSE,
  1333. &bh))
  1334. return FALSE;
  1335. h = (struct elf_link_hash_entry *) bh;
  1336. }
  1337. else
  1338. break;
  1339. /* Fall through */
  1340. case R_SPARC_PLT32:
  1341. case R_SPARC_WPLT30:
  1342. case R_SPARC_HIPLT22:
  1343. case R_SPARC_LOPLT10:
  1344. case R_SPARC_PCPLT32:
  1345. case R_SPARC_PCPLT22:
  1346. case R_SPARC_PCPLT10:
  1347. case R_SPARC_PLT64:
  1348. /* This symbol requires a procedure linkage table entry. We
  1349. actually build the entry in adjust_dynamic_symbol,
  1350. because this might be a case of linking PIC code without
  1351. linking in any dynamic objects, in which case we don't
  1352. need to generate a procedure linkage table after all. */
  1353. if (h == NULL)
  1354. {
  1355. if (! ABI_64_P (abfd))
  1356. {
  1357. /* The Solaris native assembler will generate a WPLT30
  1358. reloc for a local symbol if you assemble a call from
  1359. one section to another when using -K pic. We treat
  1360. it as WDISP30. */
  1361. if (ELF32_R_TYPE (rel->r_info) == R_SPARC_PLT32)
  1362. goto r_sparc_plt32;
  1363. break;
  1364. }
  1365. /* PR 7027: We need similar behaviour for 64-bit binaries. */
  1366. else if (r_type == R_SPARC_WPLT30)
  1367. break;
  1368. /* It does not make sense to have a procedure linkage
  1369. table entry for a local symbol. */
  1370. bfd_set_error (bfd_error_bad_value);
  1371. return FALSE;
  1372. }
  1373. h->needs_plt = 1;
  1374. {
  1375. int this_r_type;
  1376. this_r_type = SPARC_ELF_R_TYPE (rel->r_info);
  1377. if (this_r_type == R_SPARC_PLT32
  1378. || this_r_type == R_SPARC_PLT64)
  1379. goto r_sparc_plt32;
  1380. }
  1381. h->plt.refcount += 1;
  1382. break;
  1383. case R_SPARC_PC10:
  1384. case R_SPARC_PC22:
  1385. case R_SPARC_PC_HH22:
  1386. case R_SPARC_PC_HM10:
  1387. case R_SPARC_PC_LM22:
  1388. if (h != NULL)
  1389. h->non_got_ref = 1;
  1390. if (h != NULL
  1391. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  1392. break;
  1393. /* Fall through. */
  1394. case R_SPARC_DISP8:
  1395. case R_SPARC_DISP16:
  1396. case R_SPARC_DISP32:
  1397. case R_SPARC_DISP64:
  1398. case R_SPARC_WDISP30:
  1399. case R_SPARC_WDISP22:
  1400. case R_SPARC_WDISP19:
  1401. case R_SPARC_WDISP16:
  1402. case R_SPARC_WDISP10:
  1403. case R_SPARC_8:
  1404. case R_SPARC_16:
  1405. case R_SPARC_32:
  1406. case R_SPARC_HI22:
  1407. case R_SPARC_22:
  1408. case R_SPARC_13:
  1409. case R_SPARC_LO10:
  1410. case R_SPARC_UA16:
  1411. case R_SPARC_UA32:
  1412. case R_SPARC_10:
  1413. case R_SPARC_11:
  1414. case R_SPARC_64:
  1415. case R_SPARC_OLO10:
  1416. case R_SPARC_HH22:
  1417. case R_SPARC_HM10:
  1418. case R_SPARC_LM22:
  1419. case R_SPARC_7:
  1420. case R_SPARC_5:
  1421. case R_SPARC_6:
  1422. case R_SPARC_HIX22:
  1423. case R_SPARC_LOX10:
  1424. case R_SPARC_H44:
  1425. case R_SPARC_M44:
  1426. case R_SPARC_L44:
  1427. case R_SPARC_H34:
  1428. case R_SPARC_UA64:
  1429. if (h != NULL)
  1430. h->non_got_ref = 1;
  1431. r_sparc_plt32:
  1432. if (h != NULL && !bfd_link_pic (info))
  1433. {
  1434. /* We may need a .plt entry if the function this reloc
  1435. refers to is in a shared lib. */
  1436. h->plt.refcount += 1;
  1437. }
  1438. /* If we are creating a shared library, and this is a reloc
  1439. against a global symbol, or a non PC relative reloc
  1440. against a local symbol, then we need to copy the reloc
  1441. into the shared library. However, if we are linking with
  1442. -Bsymbolic, we do not need to copy a reloc against a
  1443. global symbol which is defined in an object we are
  1444. including in the link (i.e., DEF_REGULAR is set). At
  1445. this point we have not seen all the input files, so it is
  1446. possible that DEF_REGULAR is not set now but will be set
  1447. later (it is never cleared). In case of a weak definition,
  1448. DEF_REGULAR may be cleared later by a strong definition in
  1449. a shared library. We account for that possibility below by
  1450. storing information in the relocs_copied field of the hash
  1451. table entry. A similar situation occurs when creating
  1452. shared libraries and symbol visibility changes render the
  1453. symbol local.
  1454. If on the other hand, we are creating an executable, we
  1455. may need to keep relocations for symbols satisfied by a
  1456. dynamic library if we manage to avoid copy relocs for the
  1457. symbol. */
  1458. if ((bfd_link_pic (info)
  1459. && (sec->flags & SEC_ALLOC) != 0
  1460. && (! _bfd_sparc_elf_howto_table[r_type].pc_relative
  1461. || (h != NULL
  1462. && (! SYMBOLIC_BIND (info, h)
  1463. || h->root.type == bfd_link_hash_defweak
  1464. || !h->def_regular))))
  1465. || (!bfd_link_pic (info)
  1466. && (sec->flags & SEC_ALLOC) != 0
  1467. && h != NULL
  1468. && (h->root.type == bfd_link_hash_defweak
  1469. || !h->def_regular))
  1470. || (!bfd_link_pic (info)
  1471. && h != NULL
  1472. && h->type == STT_GNU_IFUNC))
  1473. {
  1474. struct _bfd_sparc_elf_dyn_relocs *p;
  1475. struct _bfd_sparc_elf_dyn_relocs **head;
  1476. /* When creating a shared object, we must copy these
  1477. relocs into the output file. We create a reloc
  1478. section in dynobj and make room for the reloc. */
  1479. if (sreloc == NULL)
  1480. {
  1481. sreloc = _bfd_elf_make_dynamic_reloc_section
  1482. (sec, htab->elf.dynobj, htab->word_align_power,
  1483. abfd, /*rela?*/ TRUE);
  1484. if (sreloc == NULL)
  1485. return FALSE;
  1486. }
  1487. /* If this is a global symbol, we count the number of
  1488. relocations we need for this symbol. */
  1489. if (h != NULL)
  1490. head = &((struct _bfd_sparc_elf_link_hash_entry *) h)->dyn_relocs;
  1491. else
  1492. {
  1493. /* Track dynamic relocs needed for local syms too.
  1494. We really need local syms available to do this
  1495. easily. Oh well. */
  1496. asection *s;
  1497. void *vpp;
  1498. BFD_ASSERT (isym != NULL);
  1499. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1500. if (s == NULL)
  1501. s = sec;
  1502. vpp = &elf_section_data (s)->local_dynrel;
  1503. head = (struct _bfd_sparc_elf_dyn_relocs **) vpp;
  1504. }
  1505. p = *head;
  1506. if (p == NULL || p->sec != sec)
  1507. {
  1508. bfd_size_type amt = sizeof *p;
  1509. p = ((struct _bfd_sparc_elf_dyn_relocs *)
  1510. bfd_alloc (htab->elf.dynobj, amt));
  1511. if (p == NULL)
  1512. return FALSE;
  1513. p->next = *head;
  1514. *head = p;
  1515. p->sec = sec;
  1516. p->count = 0;
  1517. p->pc_count = 0;
  1518. }
  1519. p->count += 1;
  1520. if (_bfd_sparc_elf_howto_table[r_type].pc_relative)
  1521. p->pc_count += 1;
  1522. }
  1523. break;
  1524. case R_SPARC_GNU_VTINHERIT:
  1525. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  1526. return FALSE;
  1527. break;
  1528. case R_SPARC_GNU_VTENTRY:
  1529. BFD_ASSERT (h != NULL);
  1530. if (h != NULL
  1531. && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  1532. return FALSE;
  1533. break;
  1534. case R_SPARC_REGISTER:
  1535. /* Nothing to do. */
  1536. break;
  1537. default:
  1538. break;
  1539. }
  1540. }
  1541. return TRUE;
  1542. }
  1543. asection *
  1544. _bfd_sparc_elf_gc_mark_hook (asection *sec,
  1545. struct bfd_link_info *info,
  1546. Elf_Internal_Rela *rel,
  1547. struct elf_link_hash_entry *h,
  1548. Elf_Internal_Sym *sym)
  1549. {
  1550. if (h != NULL)
  1551. switch (SPARC_ELF_R_TYPE (rel->r_info))
  1552. {
  1553. case R_SPARC_GNU_VTINHERIT:
  1554. case R_SPARC_GNU_VTENTRY:
  1555. return NULL;
  1556. }
  1557. /* FIXME: The test here, in check_relocs and in relocate_section
  1558. dealing with TLS optimization, ought to be !bfd_link_executable (info). */
  1559. if (bfd_link_pic (info))
  1560. {
  1561. switch (SPARC_ELF_R_TYPE (rel->r_info))
  1562. {
  1563. case R_SPARC_TLS_GD_CALL:
  1564. case R_SPARC_TLS_LDM_CALL:
  1565. /* This reloc implicitly references __tls_get_addr. We know
  1566. another reloc will reference the same symbol as the one
  1567. on this reloc, so the real symbol and section will be
  1568. gc marked when processing the other reloc. That lets
  1569. us handle __tls_get_addr here. */
  1570. h = elf_link_hash_lookup (elf_hash_table (info), "__tls_get_addr",
  1571. FALSE, FALSE, TRUE);
  1572. BFD_ASSERT (h != NULL);
  1573. h->mark = 1;
  1574. if (h->u.weakdef != NULL)
  1575. h->u.weakdef->mark = 1;
  1576. sym = NULL;
  1577. }
  1578. }
  1579. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  1580. }
  1581. static Elf_Internal_Rela *
  1582. sparc_elf_find_reloc_at_ofs (Elf_Internal_Rela *rel,
  1583. Elf_Internal_Rela *relend,
  1584. bfd_vma offset)
  1585. {
  1586. while (rel < relend)
  1587. {
  1588. if (rel->r_offset == offset)
  1589. return rel;
  1590. rel++;
  1591. }
  1592. return NULL;
  1593. }
  1594. /* Update the got entry reference counts for the section being removed. */
  1595. bfd_boolean
  1596. _bfd_sparc_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
  1597. asection *sec, const Elf_Internal_Rela *relocs)
  1598. {
  1599. struct _bfd_sparc_elf_link_hash_table *htab;
  1600. Elf_Internal_Shdr *symtab_hdr;
  1601. struct elf_link_hash_entry **sym_hashes;
  1602. bfd_signed_vma *local_got_refcounts;
  1603. const Elf_Internal_Rela *rel, *relend;
  1604. if (bfd_link_relocatable (info))
  1605. return TRUE;
  1606. BFD_ASSERT (is_sparc_elf (abfd) || sec->reloc_count == 0);
  1607. elf_section_data (sec)->local_dynrel = NULL;
  1608. htab = _bfd_sparc_elf_hash_table (info);
  1609. BFD_ASSERT (htab != NULL);
  1610. symtab_hdr = &elf_symtab_hdr (abfd);
  1611. sym_hashes = elf_sym_hashes (abfd);
  1612. local_got_refcounts = elf_local_got_refcounts (abfd);
  1613. relend = relocs + sec->reloc_count;
  1614. for (rel = relocs; rel < relend; rel++)
  1615. {
  1616. unsigned long r_symndx;
  1617. unsigned int r_type;
  1618. struct elf_link_hash_entry *h = NULL;
  1619. r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
  1620. if (r_symndx >= symtab_hdr->sh_info)
  1621. {
  1622. struct _bfd_sparc_elf_link_hash_entry *eh;
  1623. struct _bfd_sparc_elf_dyn_relocs **pp;
  1624. struct _bfd_sparc_elf_dyn_relocs *p;
  1625. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1626. while (h->root.type == bfd_link_hash_indirect
  1627. || h->root.type == bfd_link_hash_warning)
  1628. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1629. eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
  1630. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
  1631. if (p->sec == sec)
  1632. {
  1633. /* Everything must go for SEC. */
  1634. *pp = p->next;
  1635. break;
  1636. }
  1637. }
  1638. r_type = SPARC_ELF_R_TYPE (rel->r_info);
  1639. r_type = sparc_elf_tls_transition (info, abfd, r_type, h == NULL);
  1640. switch (r_type)
  1641. {
  1642. case R_SPARC_TLS_LDM_HI22:
  1643. case R_SPARC_TLS_LDM_LO10:
  1644. if (_bfd_sparc_elf_hash_table (info)->tls_ldm_got.refcount > 0)
  1645. _bfd_sparc_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
  1646. break;
  1647. case R_SPARC_TLS_GD_HI22:
  1648. case R_SPARC_TLS_GD_LO10:
  1649. case R_SPARC_TLS_IE_HI22:
  1650. case R_SPARC_TLS_IE_LO10:
  1651. case R_SPARC_GOT10:
  1652. case R_SPARC_GOT13:
  1653. case R_SPARC_GOT22:
  1654. case R_SPARC_GOTDATA_HIX22:
  1655. case R_SPARC_GOTDATA_LOX10:
  1656. case R_SPARC_GOTDATA_OP_HIX22:
  1657. case R_SPARC_GOTDATA_OP_LOX10:
  1658. if (h != NULL)
  1659. {
  1660. if (h->got.refcount > 0)
  1661. h->got.refcount--;
  1662. }
  1663. else
  1664. {
  1665. switch (r_type)
  1666. {
  1667. case R_SPARC_GOTDATA_OP_HIX22:
  1668. case R_SPARC_GOTDATA_OP_LOX10:
  1669. break;
  1670. default:
  1671. if (local_got_refcounts[r_symndx] > 0)
  1672. local_got_refcounts[r_symndx]--;
  1673. break;
  1674. }
  1675. }
  1676. break;
  1677. case R_SPARC_PC10:
  1678. case R_SPARC_PC22:
  1679. case R_SPARC_PC_HH22:
  1680. case R_SPARC_PC_HM10:
  1681. case R_SPARC_PC_LM22:
  1682. if (h != NULL
  1683. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  1684. break;
  1685. /* Fall through. */
  1686. case R_SPARC_DISP8:
  1687. case R_SPARC_DISP16:
  1688. case R_SPARC_DISP32:
  1689. case R_SPARC_DISP64:
  1690. case R_SPARC_WDISP30:
  1691. case R_SPARC_WDISP22:
  1692. case R_SPARC_WDISP19:
  1693. case R_SPARC_WDISP16:
  1694. case R_SPARC_WDISP10:
  1695. case R_SPARC_8:
  1696. case R_SPARC_16:
  1697. case R_SPARC_32:
  1698. case R_SPARC_HI22:
  1699. case R_SPARC_22:
  1700. case R_SPARC_13:
  1701. case R_SPARC_LO10:
  1702. case R_SPARC_UA16:
  1703. case R_SPARC_UA32:
  1704. case R_SPARC_PLT32:
  1705. case R_SPARC_10:
  1706. case R_SPARC_11:
  1707. case R_SPARC_64:
  1708. case R_SPARC_OLO10:
  1709. case R_SPARC_HH22:
  1710. case R_SPARC_HM10:
  1711. case R_SPARC_LM22:
  1712. case R_SPARC_7:
  1713. case R_SPARC_5:
  1714. case R_SPARC_6:
  1715. case R_SPARC_HIX22:
  1716. case R_SPARC_LOX10:
  1717. case R_SPARC_H44:
  1718. case R_SPARC_M44:
  1719. case R_SPARC_L44:
  1720. case R_SPARC_H34:
  1721. case R_SPARC_UA64:
  1722. if (bfd_link_pic (info))
  1723. break;
  1724. /* Fall through. */
  1725. case R_SPARC_WPLT30:
  1726. if (h != NULL)
  1727. {
  1728. if (h->plt.refcount > 0)
  1729. h->plt.refcount--;
  1730. }
  1731. break;
  1732. default:
  1733. break;
  1734. }
  1735. }
  1736. return TRUE;
  1737. }
  1738. /* Adjust a symbol defined by a dynamic object and referenced by a
  1739. regular object. The current definition is in some section of the
  1740. dynamic object, but we're not including those sections. We have to
  1741. change the definition to something the rest of the link can
  1742. understand. */
  1743. bfd_boolean
  1744. _bfd_sparc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  1745. struct elf_link_hash_entry *h)
  1746. {
  1747. struct _bfd_sparc_elf_link_hash_table *htab;
  1748. struct _bfd_sparc_elf_link_hash_entry * eh;
  1749. struct _bfd_sparc_elf_dyn_relocs *p;
  1750. asection *s;
  1751. htab = _bfd_sparc_elf_hash_table (info);
  1752. BFD_ASSERT (htab != NULL);
  1753. /* Make sure we know what is going on here. */
  1754. BFD_ASSERT (htab->elf.dynobj != NULL
  1755. && (h->needs_plt
  1756. || h->type == STT_GNU_IFUNC
  1757. || h->u.weakdef != NULL
  1758. || (h->def_dynamic
  1759. && h->ref_regular
  1760. && !h->def_regular)));
  1761. /* If this is a function, put it in the procedure linkage table. We
  1762. will fill in the contents of the procedure linkage table later
  1763. (although we could actually do it here). The STT_NOTYPE
  1764. condition is a hack specifically for the Oracle libraries
  1765. delivered for Solaris; for some inexplicable reason, they define
  1766. some of their functions as STT_NOTYPE when they really should be
  1767. STT_FUNC. */
  1768. if (h->type == STT_FUNC
  1769. || h->type == STT_GNU_IFUNC
  1770. || h->needs_plt
  1771. || (h->type == STT_NOTYPE
  1772. && (h->root.type == bfd_link_hash_defined
  1773. || h->root.type == bfd_link_hash_defweak)
  1774. && (h->root.u.def.section->flags & SEC_CODE) != 0))
  1775. {
  1776. if (h->plt.refcount <= 0
  1777. || (h->type != STT_GNU_IFUNC
  1778. && (SYMBOL_CALLS_LOCAL (info, h)
  1779. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  1780. && h->root.type == bfd_link_hash_undefweak))))
  1781. {
  1782. /* This case can occur if we saw a WPLT30 reloc in an input
  1783. file, but the symbol was never referred to by a dynamic
  1784. object, or if all references were garbage collected. In
  1785. such a case, we don't actually need to build a procedure
  1786. linkage table, and we can just do a WDISP30 reloc instead. */
  1787. h->plt.offset = (bfd_vma) -1;
  1788. h->needs_plt = 0;
  1789. }
  1790. return TRUE;
  1791. }
  1792. else
  1793. h->plt.offset = (bfd_vma) -1;
  1794. /* If this is a weak symbol, and there is a real definition, the
  1795. processor independent code will have arranged for us to see the
  1796. real definition first, and we can just use the same value. */
  1797. if (h->u.weakdef != NULL)
  1798. {
  1799. BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
  1800. || h->u.weakdef->root.type == bfd_link_hash_defweak);
  1801. h->root.u.def.section = h->u.weakdef->root.u.def.section;
  1802. h->root.u.def.value = h->u.weakdef->root.u.def.value;
  1803. return TRUE;
  1804. }
  1805. /* This is a reference to a symbol defined by a dynamic object which
  1806. is not a function. */
  1807. /* If we are creating a shared library, we must presume that the
  1808. only references to the symbol are via the global offset table.
  1809. For such cases we need not do anything here; the relocations will
  1810. be handled correctly by relocate_section. */
  1811. if (bfd_link_pic (info))
  1812. return TRUE;
  1813. /* If there are no references to this symbol that do not use the
  1814. GOT, we don't need to generate a copy reloc. */
  1815. if (!h->non_got_ref)
  1816. return TRUE;
  1817. /* If -z nocopyreloc was given, we won't generate them either. */
  1818. if (info->nocopyreloc)
  1819. {
  1820. h->non_got_ref = 0;
  1821. return TRUE;
  1822. }
  1823. eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
  1824. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  1825. {
  1826. s = p->sec->output_section;
  1827. if (s != NULL && (s->flags & SEC_READONLY) != 0)
  1828. break;
  1829. }
  1830. /* If we didn't find any dynamic relocs in read-only sections, then
  1831. we'll be keeping the dynamic relocs and avoiding the copy reloc. */
  1832. if (p == NULL)
  1833. {
  1834. h->non_got_ref = 0;
  1835. return TRUE;
  1836. }
  1837. /* We must allocate the symbol in our .dynbss section, which will
  1838. become part of the .bss section of the executable. There will be
  1839. an entry for this symbol in the .dynsym section. The dynamic
  1840. object will contain position independent code, so all references
  1841. from the dynamic object to this symbol will go through the global
  1842. offset table. The dynamic linker will use the .dynsym entry to
  1843. determine the address it must put in the global offset table, so
  1844. both the dynamic object and the regular object will refer to the
  1845. same memory location for the variable. */
  1846. /* We must generate a R_SPARC_COPY reloc to tell the dynamic linker
  1847. to copy the initial value out of the dynamic object and into the
  1848. runtime process image. We need to remember the offset into the
  1849. .rel.bss section we are going to use. */
  1850. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  1851. {
  1852. htab->srelbss->size += SPARC_ELF_RELA_BYTES (htab);
  1853. h->needs_copy = 1;
  1854. }
  1855. s = htab->sdynbss;
  1856. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  1857. }
  1858. /* Allocate space in .plt, .got and associated reloc sections for
  1859. dynamic relocs. */
  1860. static bfd_boolean
  1861. allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
  1862. {
  1863. struct bfd_link_info *info;
  1864. struct _bfd_sparc_elf_link_hash_table *htab;
  1865. struct _bfd_sparc_elf_link_hash_entry *eh;
  1866. struct _bfd_sparc_elf_dyn_relocs *p;
  1867. if (h->root.type == bfd_link_hash_indirect)
  1868. return TRUE;
  1869. info = (struct bfd_link_info *) inf;
  1870. htab = _bfd_sparc_elf_hash_table (info);
  1871. BFD_ASSERT (htab != NULL);
  1872. if ((htab->elf.dynamic_sections_created
  1873. && h->plt.refcount > 0)
  1874. || (h->type == STT_GNU_IFUNC
  1875. && h->def_regular
  1876. && h->ref_regular))
  1877. {
  1878. /* Make sure this symbol is output as a dynamic symbol.
  1879. Undefined weak syms won't yet be marked as dynamic. */
  1880. if (h->dynindx == -1
  1881. && !h->forced_local)
  1882. {
  1883. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1884. return FALSE;
  1885. }
  1886. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h)
  1887. || (h->type == STT_GNU_IFUNC
  1888. && h->def_regular))
  1889. {
  1890. asection *s = htab->elf.splt;
  1891. if (s == NULL)
  1892. s = htab->elf.iplt;
  1893. /* Allocate room for the header. */
  1894. if (s->size == 0)
  1895. {
  1896. s->size = htab->plt_header_size;
  1897. /* Allocate space for the .rela.plt.unloaded relocations. */
  1898. if (htab->is_vxworks && !bfd_link_pic (info))
  1899. htab->srelplt2->size = sizeof (Elf32_External_Rela) * 2;
  1900. }
  1901. /* The procedure linkage table size is bounded by the magnitude
  1902. of the offset we can describe in the entry. */
  1903. if (s->size >= (SPARC_ELF_WORD_BYTES(htab) == 8 ?
  1904. (((bfd_vma)1 << 31) << 1) : 0x400000))
  1905. {
  1906. bfd_set_error (bfd_error_bad_value);
  1907. return FALSE;
  1908. }
  1909. if (SPARC_ELF_WORD_BYTES(htab) == 8
  1910. && s->size >= PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE)
  1911. {
  1912. bfd_vma off = s->size - PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE;
  1913. off = (off % (160 * PLT64_ENTRY_SIZE)) / PLT64_ENTRY_SIZE;
  1914. h->plt.offset = (s->size - (off * 8));
  1915. }
  1916. else
  1917. h->plt.offset = s->size;
  1918. /* If this symbol is not defined in a regular file, and we are
  1919. not generating a shared library, then set the symbol to this
  1920. location in the .plt. This is required to make function
  1921. pointers compare as equal between the normal executable and
  1922. the shared library. */
  1923. if (! bfd_link_pic (info)
  1924. && !h->def_regular)
  1925. {
  1926. h->root.u.def.section = s;
  1927. h->root.u.def.value = h->plt.offset;
  1928. }
  1929. /* Make room for this entry. */
  1930. s->size += htab->plt_entry_size;
  1931. /* We also need to make an entry in the .rela.plt section. */
  1932. if (s == htab->elf.splt)
  1933. htab->elf.srelplt->size += SPARC_ELF_RELA_BYTES (htab);
  1934. else
  1935. htab->elf.irelplt->size += SPARC_ELF_RELA_BYTES (htab);
  1936. if (htab->is_vxworks)
  1937. {
  1938. /* Allocate space for the .got.plt entry. */
  1939. htab->elf.sgotplt->size += 4;
  1940. /* ...and for the .rela.plt.unloaded relocations. */
  1941. if (!bfd_link_pic (info))
  1942. htab->srelplt2->size += sizeof (Elf32_External_Rela) * 3;
  1943. }
  1944. }
  1945. else
  1946. {
  1947. h->plt.offset = (bfd_vma) -1;
  1948. h->needs_plt = 0;
  1949. }
  1950. }
  1951. else
  1952. {
  1953. h->plt.offset = (bfd_vma) -1;
  1954. h->needs_plt = 0;
  1955. }
  1956. /* If R_SPARC_TLS_IE_{HI22,LO10} symbol is now local to the binary,
  1957. make it a R_SPARC_TLS_LE_{HI22,LO10} requiring no TLS entry. */
  1958. if (h->got.refcount > 0
  1959. && !bfd_link_pic (info)
  1960. && h->dynindx == -1
  1961. && _bfd_sparc_elf_hash_entry(h)->tls_type == GOT_TLS_IE)
  1962. h->got.offset = (bfd_vma) -1;
  1963. else if (h->got.refcount > 0)
  1964. {
  1965. asection *s;
  1966. bfd_boolean dyn;
  1967. int tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
  1968. /* Make sure this symbol is output as a dynamic symbol.
  1969. Undefined weak syms won't yet be marked as dynamic. */
  1970. if (h->dynindx == -1
  1971. && !h->forced_local)
  1972. {
  1973. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1974. return FALSE;
  1975. }
  1976. s = htab->elf.sgot;
  1977. h->got.offset = s->size;
  1978. s->size += SPARC_ELF_WORD_BYTES (htab);
  1979. /* R_SPARC_TLS_GD_HI{22,LO10} needs 2 consecutive GOT slots. */
  1980. if (tls_type == GOT_TLS_GD)
  1981. s->size += SPARC_ELF_WORD_BYTES (htab);
  1982. dyn = htab->elf.dynamic_sections_created;
  1983. /* R_SPARC_TLS_IE_{HI22,LO10} needs one dynamic relocation,
  1984. R_SPARC_TLS_GD_{HI22,LO10} needs one if local symbol and two if
  1985. global. */
  1986. if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
  1987. || tls_type == GOT_TLS_IE
  1988. || h->type == STT_GNU_IFUNC)
  1989. htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
  1990. else if (tls_type == GOT_TLS_GD)
  1991. htab->elf.srelgot->size += 2 * SPARC_ELF_RELA_BYTES (htab);
  1992. else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  1993. bfd_link_pic (info),
  1994. h))
  1995. htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
  1996. }
  1997. else
  1998. h->got.offset = (bfd_vma) -1;
  1999. eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
  2000. if (eh->dyn_relocs == NULL)
  2001. return TRUE;
  2002. /* In the shared -Bsymbolic case, discard space allocated for
  2003. dynamic pc-relative relocs against symbols which turn out to be
  2004. defined in regular objects. For the normal shared case, discard
  2005. space for pc-relative relocs that have become local due to symbol
  2006. visibility changes. */
  2007. if (bfd_link_pic (info))
  2008. {
  2009. if (SYMBOL_CALLS_LOCAL (info, h))
  2010. {
  2011. struct _bfd_sparc_elf_dyn_relocs **pp;
  2012. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
  2013. {
  2014. p->count -= p->pc_count;
  2015. p->pc_count = 0;
  2016. if (p->count == 0)
  2017. *pp = p->next;
  2018. else
  2019. pp = &p->next;
  2020. }
  2021. }
  2022. if (htab->is_vxworks)
  2023. {
  2024. struct _bfd_sparc_elf_dyn_relocs **pp;
  2025. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
  2026. {
  2027. if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
  2028. *pp = p->next;
  2029. else
  2030. pp = &p->next;
  2031. }
  2032. }
  2033. /* Also discard relocs on undefined weak syms with non-default
  2034. visibility. */
  2035. if (eh->dyn_relocs != NULL
  2036. && h->root.type == bfd_link_hash_undefweak)
  2037. {
  2038. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  2039. eh->dyn_relocs = NULL;
  2040. /* Make sure undefined weak symbols are output as a dynamic
  2041. symbol in PIEs. */
  2042. else if (h->dynindx == -1
  2043. && !h->forced_local)
  2044. {
  2045. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2046. return FALSE;
  2047. }
  2048. }
  2049. }
  2050. else
  2051. {
  2052. /* For the non-shared case, discard space for relocs against
  2053. symbols which turn out to need copy relocs or are not
  2054. dynamic. */
  2055. if (!h->non_got_ref
  2056. && ((h->def_dynamic
  2057. && !h->def_regular)
  2058. || (htab->elf.dynamic_sections_created
  2059. && (h->root.type == bfd_link_hash_undefweak
  2060. || h->root.type == bfd_link_hash_undefined))))
  2061. {
  2062. /* Make sure this symbol is output as a dynamic symbol.
  2063. Undefined weak syms won't yet be marked as dynamic. */
  2064. if (h->dynindx == -1
  2065. && !h->forced_local)
  2066. {
  2067. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2068. return FALSE;
  2069. }
  2070. /* If that succeeded, we know we'll be keeping all the
  2071. relocs. */
  2072. if (h->dynindx != -1)
  2073. goto keep;
  2074. }
  2075. eh->dyn_relocs = NULL;
  2076. keep: ;
  2077. }
  2078. /* Finally, allocate space. */
  2079. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  2080. {
  2081. asection *sreloc = elf_section_data (p->sec)->sreloc;
  2082. sreloc->size += p->count * SPARC_ELF_RELA_BYTES (htab);
  2083. }
  2084. return TRUE;
  2085. }
  2086. /* Allocate space in .plt, .got and associated reloc sections for
  2087. local dynamic relocs. */
  2088. static bfd_boolean
  2089. allocate_local_dynrelocs (void **slot, void *inf)
  2090. {
  2091. struct elf_link_hash_entry *h
  2092. = (struct elf_link_hash_entry *) *slot;
  2093. if (h->type != STT_GNU_IFUNC
  2094. || !h->def_regular
  2095. || !h->ref_regular
  2096. || !h->forced_local
  2097. || h->root.type != bfd_link_hash_defined)
  2098. abort ();
  2099. return allocate_dynrelocs (h, inf);
  2100. }
  2101. /* Find any dynamic relocs that apply to read-only sections. */
  2102. static bfd_boolean
  2103. readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
  2104. {
  2105. struct _bfd_sparc_elf_link_hash_entry *eh;
  2106. struct _bfd_sparc_elf_dyn_relocs *p;
  2107. eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
  2108. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  2109. {
  2110. asection *s = p->sec->output_section;
  2111. if (s != NULL && (s->flags & SEC_READONLY) != 0)
  2112. {
  2113. struct bfd_link_info *info = (struct bfd_link_info *) inf;
  2114. info->flags |= DF_TEXTREL;
  2115. /* Not an error, just cut short the traversal. */
  2116. return FALSE;
  2117. }
  2118. }
  2119. return TRUE;
  2120. }
  2121. /* Return true if the dynamic symbol for a given section should be
  2122. omitted when creating a shared library. */
  2123. bfd_boolean
  2124. _bfd_sparc_elf_omit_section_dynsym (bfd *output_bfd,
  2125. struct bfd_link_info *info,
  2126. asection *p)
  2127. {
  2128. /* We keep the .got section symbol so that explicit relocations
  2129. against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
  2130. can be turned into relocations against the .got symbol. */
  2131. if (strcmp (p->name, ".got") == 0)
  2132. return FALSE;
  2133. return _bfd_elf_link_omit_section_dynsym (output_bfd, info, p);
  2134. }
  2135. /* Set the sizes of the dynamic sections. */
  2136. bfd_boolean
  2137. _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd,
  2138. struct bfd_link_info *info)
  2139. {
  2140. struct _bfd_sparc_elf_link_hash_table *htab;
  2141. bfd *dynobj;
  2142. asection *s;
  2143. bfd *ibfd;
  2144. htab = _bfd_sparc_elf_hash_table (info);
  2145. BFD_ASSERT (htab != NULL);
  2146. dynobj = htab->elf.dynobj;
  2147. BFD_ASSERT (dynobj != NULL);
  2148. if (elf_hash_table (info)->dynamic_sections_created)
  2149. {
  2150. /* Set the contents of the .interp section to the interpreter. */
  2151. if (bfd_link_executable (info) && !info->nointerp)
  2152. {
  2153. s = bfd_get_linker_section (dynobj, ".interp");
  2154. BFD_ASSERT (s != NULL);
  2155. s->size = htab->dynamic_interpreter_size;
  2156. s->contents = (unsigned char *) htab->dynamic_interpreter;
  2157. }
  2158. }
  2159. /* Set up .got offsets for local syms, and space for local dynamic
  2160. relocs. */
  2161. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  2162. {
  2163. bfd_signed_vma *local_got;
  2164. bfd_signed_vma *end_local_got;
  2165. char *local_tls_type;
  2166. bfd_size_type locsymcount;
  2167. Elf_Internal_Shdr *symtab_hdr;
  2168. asection *srel;
  2169. if (! is_sparc_elf (ibfd))
  2170. continue;
  2171. for (s = ibfd->sections; s != NULL; s = s->next)
  2172. {
  2173. struct _bfd_sparc_elf_dyn_relocs *p;
  2174. for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
  2175. {
  2176. if (!bfd_is_abs_section (p->sec)
  2177. && bfd_is_abs_section (p->sec->output_section))
  2178. {
  2179. /* Input section has been discarded, either because
  2180. it is a copy of a linkonce section or due to
  2181. linker script /DISCARD/, so we'll be discarding
  2182. the relocs too. */
  2183. }
  2184. else if (htab->is_vxworks
  2185. && strcmp (p->sec->output_section->name,
  2186. ".tls_vars") == 0)
  2187. {
  2188. /* Relocations in vxworks .tls_vars sections are
  2189. handled specially by the loader. */
  2190. }
  2191. else if (p->count != 0)
  2192. {
  2193. srel = elf_section_data (p->sec)->sreloc;
  2194. if (!htab->elf.dynamic_sections_created)
  2195. srel = htab->elf.irelplt;
  2196. srel->size += p->count * SPARC_ELF_RELA_BYTES (htab);
  2197. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  2198. info->flags |= DF_TEXTREL;
  2199. }
  2200. }
  2201. }
  2202. local_got = elf_local_got_refcounts (ibfd);
  2203. if (!local_got)
  2204. continue;
  2205. symtab_hdr = &elf_symtab_hdr (ibfd);
  2206. locsymcount = symtab_hdr->sh_info;
  2207. end_local_got = local_got + locsymcount;
  2208. local_tls_type = _bfd_sparc_elf_local_got_tls_type (ibfd);
  2209. s = htab->elf.sgot;
  2210. srel = htab->elf.srelgot;
  2211. for (; local_got < end_local_got; ++local_got, ++local_tls_type)
  2212. {
  2213. if (*local_got > 0)
  2214. {
  2215. *local_got = s->size;
  2216. s->size += SPARC_ELF_WORD_BYTES (htab);
  2217. if (*local_tls_type == GOT_TLS_GD)
  2218. s->size += SPARC_ELF_WORD_BYTES (htab);
  2219. if (bfd_link_pic (info)
  2220. || *local_tls_type == GOT_TLS_GD
  2221. || *local_tls_type == GOT_TLS_IE)
  2222. srel->size += SPARC_ELF_RELA_BYTES (htab);
  2223. }
  2224. else
  2225. *local_got = (bfd_vma) -1;
  2226. }
  2227. }
  2228. if (htab->tls_ldm_got.refcount > 0)
  2229. {
  2230. /* Allocate 2 got entries and 1 dynamic reloc for
  2231. R_SPARC_TLS_LDM_{HI22,LO10} relocs. */
  2232. htab->tls_ldm_got.offset = htab->elf.sgot->size;
  2233. htab->elf.sgot->size += (2 * SPARC_ELF_WORD_BYTES (htab));
  2234. htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
  2235. }
  2236. else
  2237. htab->tls_ldm_got.offset = -1;
  2238. /* Allocate global sym .plt and .got entries, and space for global
  2239. sym dynamic relocs. */
  2240. elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
  2241. /* Allocate .plt and .got entries, and space for local symbols. */
  2242. htab_traverse (htab->loc_hash_table, allocate_local_dynrelocs, info);
  2243. if (! ABI_64_P (output_bfd)
  2244. && !htab->is_vxworks
  2245. && elf_hash_table (info)->dynamic_sections_created)
  2246. {
  2247. /* Make space for the trailing nop in .plt. */
  2248. if (htab->elf.splt->size > 0)
  2249. htab->elf.splt->size += 1 * SPARC_INSN_BYTES;
  2250. /* If the .got section is more than 0x1000 bytes, we add
  2251. 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
  2252. bit relocations have a greater chance of working.
  2253. FIXME: Make this optimization work for 64-bit too. */
  2254. if (htab->elf.sgot->size >= 0x1000
  2255. && elf_hash_table (info)->hgot->root.u.def.value == 0)
  2256. elf_hash_table (info)->hgot->root.u.def.value = 0x1000;
  2257. }
  2258. /* The check_relocs and adjust_dynamic_symbol entry points have
  2259. determined the sizes of the various dynamic sections. Allocate
  2260. memory for them. */
  2261. for (s = dynobj->sections; s != NULL; s = s->next)
  2262. {
  2263. if ((s->flags & SEC_LINKER_CREATED) == 0)
  2264. continue;
  2265. if (s == htab->elf.splt
  2266. || s == htab->elf.sgot
  2267. || s == htab->sdynbss
  2268. || s == htab->elf.iplt
  2269. || s == htab->elf.sgotplt)
  2270. {
  2271. /* Strip this section if we don't need it; see the
  2272. comment below. */
  2273. }
  2274. else if (CONST_STRNEQ (s->name, ".rela"))
  2275. {
  2276. if (s->size != 0)
  2277. {
  2278. /* We use the reloc_count field as a counter if we need
  2279. to copy relocs into the output file. */
  2280. s->reloc_count = 0;
  2281. }
  2282. }
  2283. else
  2284. {
  2285. /* It's not one of our sections. */
  2286. continue;
  2287. }
  2288. if (s->size == 0)
  2289. {
  2290. /* If we don't need this section, strip it from the
  2291. output file. This is mostly to handle .rela.bss and
  2292. .rela.plt. We must create both sections in
  2293. create_dynamic_sections, because they must be created
  2294. before the linker maps input sections to output
  2295. sections. The linker does that before
  2296. adjust_dynamic_symbol is called, and it is that
  2297. function which decides whether anything needs to go
  2298. into these sections. */
  2299. s->flags |= SEC_EXCLUDE;
  2300. continue;
  2301. }
  2302. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  2303. continue;
  2304. /* Allocate memory for the section contents. Zero the memory
  2305. for the benefit of .rela.plt, which has 4 unused entries
  2306. at the beginning, and we don't want garbage. */
  2307. s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
  2308. if (s->contents == NULL)
  2309. return FALSE;
  2310. }
  2311. if (elf_hash_table (info)->dynamic_sections_created)
  2312. {
  2313. /* Add some entries to the .dynamic section. We fill in the
  2314. values later, in _bfd_sparc_elf_finish_dynamic_sections, but we
  2315. must add the entries now so that we get the correct size for
  2316. the .dynamic section. The DT_DEBUG entry is filled in by the
  2317. dynamic linker and used by the debugger. */
  2318. #define add_dynamic_entry(TAG, VAL) \
  2319. _bfd_elf_add_dynamic_entry (info, TAG, VAL)
  2320. if (bfd_link_executable (info))
  2321. {
  2322. if (!add_dynamic_entry (DT_DEBUG, 0))
  2323. return FALSE;
  2324. }
  2325. if (htab->elf.srelplt->size != 0)
  2326. {
  2327. if (!add_dynamic_entry (DT_PLTGOT, 0)
  2328. || !add_dynamic_entry (DT_PLTRELSZ, 0)
  2329. || !add_dynamic_entry (DT_PLTREL, DT_RELA)
  2330. || !add_dynamic_entry (DT_JMPREL, 0))
  2331. return FALSE;
  2332. }
  2333. if (!add_dynamic_entry (DT_RELA, 0)
  2334. || !add_dynamic_entry (DT_RELASZ, 0)
  2335. || !add_dynamic_entry (DT_RELAENT,
  2336. SPARC_ELF_RELA_BYTES (htab)))
  2337. return FALSE;
  2338. /* If any dynamic relocs apply to a read-only section,
  2339. then we need a DT_TEXTREL entry. */
  2340. if ((info->flags & DF_TEXTREL) == 0)
  2341. elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
  2342. if (info->flags & DF_TEXTREL)
  2343. {
  2344. if (!add_dynamic_entry (DT_TEXTREL, 0))
  2345. return FALSE;
  2346. }
  2347. if (ABI_64_P (output_bfd))
  2348. {
  2349. int reg;
  2350. struct _bfd_sparc_elf_app_reg * app_regs;
  2351. struct elf_strtab_hash *dynstr;
  2352. struct elf_link_hash_table *eht = elf_hash_table (info);
  2353. /* Add dynamic STT_REGISTER symbols and corresponding DT_SPARC_REGISTER
  2354. entries if needed. */
  2355. app_regs = _bfd_sparc_elf_hash_table (info)->app_regs;
  2356. dynstr = eht->dynstr;
  2357. for (reg = 0; reg < 4; reg++)
  2358. if (app_regs [reg].name != NULL)
  2359. {
  2360. struct elf_link_local_dynamic_entry *entry, *e;
  2361. if (!add_dynamic_entry (DT_SPARC_REGISTER, 0))
  2362. return FALSE;
  2363. entry = (struct elf_link_local_dynamic_entry *)
  2364. bfd_hash_allocate (&info->hash->table, sizeof (*entry));
  2365. if (entry == NULL)
  2366. return FALSE;
  2367. /* We cheat here a little bit: the symbol will not be local, so we
  2368. put it at the end of the dynlocal linked list. We will fix it
  2369. later on, as we have to fix other fields anyway. */
  2370. entry->isym.st_value = reg < 2 ? reg + 2 : reg + 4;
  2371. entry->isym.st_size = 0;
  2372. if (*app_regs [reg].name != '\0')
  2373. entry->isym.st_name
  2374. = _bfd_elf_strtab_add (dynstr, app_regs[reg].name, FALSE);
  2375. else
  2376. entry->isym.st_name = 0;
  2377. entry->isym.st_other = 0;
  2378. entry->isym.st_info = ELF_ST_INFO (app_regs [reg].bind,
  2379. STT_REGISTER);
  2380. entry->isym.st_shndx = app_regs [reg].shndx;
  2381. entry->isym.st_target_internal = 0;
  2382. entry->next = NULL;
  2383. entry->input_bfd = output_bfd;
  2384. entry->input_indx = -1;
  2385. if (eht->dynlocal == NULL)
  2386. eht->dynlocal = entry;
  2387. else
  2388. {
  2389. for (e = eht->dynlocal; e->next; e = e->next)
  2390. ;
  2391. e->next = entry;
  2392. }
  2393. eht->dynsymcount++;
  2394. }
  2395. }
  2396. if (htab->is_vxworks
  2397. && !elf_vxworks_add_dynamic_entries (output_bfd, info))
  2398. return FALSE;
  2399. }
  2400. #undef add_dynamic_entry
  2401. return TRUE;
  2402. }
  2403. bfd_boolean
  2404. _bfd_sparc_elf_new_section_hook (bfd *abfd, asection *sec)
  2405. {
  2406. if (!sec->used_by_bfd)
  2407. {
  2408. struct _bfd_sparc_elf_section_data *sdata;
  2409. bfd_size_type amt = sizeof (*sdata);
  2410. sdata = bfd_zalloc (abfd, amt);
  2411. if (sdata == NULL)
  2412. return FALSE;
  2413. sec->used_by_bfd = sdata;
  2414. }
  2415. return _bfd_elf_new_section_hook (abfd, sec);
  2416. }
  2417. bfd_boolean
  2418. _bfd_sparc_elf_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
  2419. struct bfd_section *section,
  2420. struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
  2421. bfd_boolean *again)
  2422. {
  2423. if (bfd_link_relocatable (link_info))
  2424. (*link_info->callbacks->einfo)
  2425. (_("%P%F: --relax and -r may not be used together\n"));
  2426. *again = FALSE;
  2427. sec_do_relax (section) = 1;
  2428. return TRUE;
  2429. }
  2430. /* Return the base VMA address which should be subtracted from real addresses
  2431. when resolving @dtpoff relocation.
  2432. This is PT_TLS segment p_vaddr. */
  2433. static bfd_vma
  2434. dtpoff_base (struct bfd_link_info *info)
  2435. {
  2436. /* If tls_sec is NULL, we should have signalled an error already. */
  2437. if (elf_hash_table (info)->tls_sec == NULL)
  2438. return 0;
  2439. return elf_hash_table (info)->tls_sec->vma;
  2440. }
  2441. /* Return the relocation value for @tpoff relocation
  2442. if STT_TLS virtual address is ADDRESS. */
  2443. static bfd_vma
  2444. tpoff (struct bfd_link_info *info, bfd_vma address)
  2445. {
  2446. struct elf_link_hash_table *htab = elf_hash_table (info);
  2447. const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
  2448. bfd_vma static_tls_size;
  2449. /* If tls_sec is NULL, we should have signalled an error already. */
  2450. if (htab->tls_sec == NULL)
  2451. return 0;
  2452. /* Consider special static TLS alignment requirements. */
  2453. static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
  2454. return address - static_tls_size - htab->tls_sec->vma;
  2455. }
  2456. /* Return the relocation value for a %gdop relocation. */
  2457. static bfd_vma
  2458. gdopoff (struct bfd_link_info *info, bfd_vma address)
  2459. {
  2460. struct elf_link_hash_table *htab = elf_hash_table (info);
  2461. bfd_vma got_base;
  2462. got_base = (htab->hgot->root.u.def.value
  2463. + htab->hgot->root.u.def.section->output_offset
  2464. + htab->hgot->root.u.def.section->output_section->vma);
  2465. return address - got_base;
  2466. }
  2467. /* Relocate a SPARC ELF section. */
  2468. bfd_boolean
  2469. _bfd_sparc_elf_relocate_section (bfd *output_bfd,
  2470. struct bfd_link_info *info,
  2471. bfd *input_bfd,
  2472. asection *input_section,
  2473. bfd_byte *contents,
  2474. Elf_Internal_Rela *relocs,
  2475. Elf_Internal_Sym *local_syms,
  2476. asection **local_sections)
  2477. {
  2478. struct _bfd_sparc_elf_link_hash_table *htab;
  2479. Elf_Internal_Shdr *symtab_hdr;
  2480. struct elf_link_hash_entry **sym_hashes;
  2481. bfd_vma *local_got_offsets;
  2482. bfd_vma got_base;
  2483. asection *sreloc;
  2484. Elf_Internal_Rela *rel;
  2485. Elf_Internal_Rela *relend;
  2486. int num_relocs;
  2487. bfd_boolean is_vxworks_tls;
  2488. htab = _bfd_sparc_elf_hash_table (info);
  2489. BFD_ASSERT (htab != NULL);
  2490. symtab_hdr = &elf_symtab_hdr (input_bfd);
  2491. sym_hashes = elf_sym_hashes (input_bfd);
  2492. local_got_offsets = elf_local_got_offsets (input_bfd);
  2493. if (elf_hash_table (info)->hgot == NULL)
  2494. got_base = 0;
  2495. else
  2496. got_base = elf_hash_table (info)->hgot->root.u.def.value;
  2497. sreloc = elf_section_data (input_section)->sreloc;
  2498. /* We have to handle relocations in vxworks .tls_vars sections
  2499. specially, because the dynamic loader is 'weird'. */
  2500. is_vxworks_tls = (htab->is_vxworks && bfd_link_pic (info)
  2501. && !strcmp (input_section->output_section->name,
  2502. ".tls_vars"));
  2503. rel = relocs;
  2504. if (ABI_64_P (output_bfd))
  2505. num_relocs = NUM_SHDR_ENTRIES (_bfd_elf_single_rel_hdr (input_section));
  2506. else
  2507. num_relocs = input_section->reloc_count;
  2508. relend = relocs + num_relocs;
  2509. for (; rel < relend; rel++)
  2510. {
  2511. int r_type, tls_type;
  2512. reloc_howto_type *howto;
  2513. unsigned long r_symndx;
  2514. struct elf_link_hash_entry *h;
  2515. Elf_Internal_Sym *sym;
  2516. asection *sec;
  2517. bfd_vma relocation, off;
  2518. bfd_reloc_status_type r;
  2519. bfd_boolean is_plt = FALSE;
  2520. bfd_boolean unresolved_reloc;
  2521. r_type = SPARC_ELF_R_TYPE (rel->r_info);
  2522. if (r_type == R_SPARC_GNU_VTINHERIT
  2523. || r_type == R_SPARC_GNU_VTENTRY)
  2524. continue;
  2525. if (r_type < 0 || r_type >= (int) R_SPARC_max_std)
  2526. {
  2527. bfd_set_error (bfd_error_bad_value);
  2528. return FALSE;
  2529. }
  2530. howto = _bfd_sparc_elf_howto_table + r_type;
  2531. r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
  2532. h = NULL;
  2533. sym = NULL;
  2534. sec = NULL;
  2535. unresolved_reloc = FALSE;
  2536. if (r_symndx < symtab_hdr->sh_info)
  2537. {
  2538. sym = local_syms + r_symndx;
  2539. sec = local_sections[r_symndx];
  2540. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  2541. if (!bfd_link_relocatable (info)
  2542. && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
  2543. {
  2544. /* Relocate against local STT_GNU_IFUNC symbol. */
  2545. h = elf_sparc_get_local_sym_hash (htab, input_bfd,
  2546. rel, FALSE);
  2547. if (h == NULL)
  2548. abort ();
  2549. /* Set STT_GNU_IFUNC symbol value. */
  2550. h->root.u.def.value = sym->st_value;
  2551. h->root.u.def.section = sec;
  2552. }
  2553. }
  2554. else
  2555. {
  2556. bfd_boolean warned, ignored;
  2557. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  2558. r_symndx, symtab_hdr, sym_hashes,
  2559. h, sec, relocation,
  2560. unresolved_reloc, warned, ignored);
  2561. if (warned)
  2562. {
  2563. /* To avoid generating warning messages about truncated
  2564. relocations, set the relocation's address to be the same as
  2565. the start of this section. */
  2566. if (input_section->output_section != NULL)
  2567. relocation = input_section->output_section->vma;
  2568. else
  2569. relocation = 0;
  2570. }
  2571. }
  2572. if (sec != NULL && discarded_section (sec))
  2573. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  2574. rel, 1, relend, howto, 0, contents);
  2575. if (bfd_link_relocatable (info))
  2576. continue;
  2577. if (h != NULL
  2578. && h->type == STT_GNU_IFUNC
  2579. && h->def_regular)
  2580. {
  2581. asection *plt_sec;
  2582. const char *name;
  2583. if ((input_section->flags & SEC_ALLOC) == 0
  2584. || h->plt.offset == (bfd_vma) -1)
  2585. abort ();
  2586. plt_sec = htab->elf.splt;
  2587. if (! plt_sec)
  2588. plt_sec =htab->elf.iplt;
  2589. switch (r_type)
  2590. {
  2591. case R_SPARC_GOTDATA_OP:
  2592. continue;
  2593. case R_SPARC_GOTDATA_OP_HIX22:
  2594. case R_SPARC_GOTDATA_OP_LOX10:
  2595. r_type = (r_type == R_SPARC_GOTDATA_OP_HIX22
  2596. ? R_SPARC_GOT22
  2597. : R_SPARC_GOT10);
  2598. howto = _bfd_sparc_elf_howto_table + r_type;
  2599. /* Fall through. */
  2600. case R_SPARC_GOT10:
  2601. case R_SPARC_GOT13:
  2602. case R_SPARC_GOT22:
  2603. if (htab->elf.sgot == NULL)
  2604. abort ();
  2605. off = h->got.offset;
  2606. if (off == (bfd_vma) -1)
  2607. abort();
  2608. relocation = htab->elf.sgot->output_offset + off - got_base;
  2609. goto do_relocation;
  2610. case R_SPARC_WPLT30:
  2611. case R_SPARC_WDISP30:
  2612. relocation = (plt_sec->output_section->vma
  2613. + plt_sec->output_offset + h->plt.offset);
  2614. goto do_relocation;
  2615. case R_SPARC_32:
  2616. case R_SPARC_64:
  2617. if (bfd_link_pic (info) && h->non_got_ref)
  2618. {
  2619. Elf_Internal_Rela outrel;
  2620. bfd_vma offset;
  2621. offset = _bfd_elf_section_offset (output_bfd, info,
  2622. input_section,
  2623. rel->r_offset);
  2624. if (offset == (bfd_vma) -1
  2625. || offset == (bfd_vma) -2)
  2626. abort();
  2627. outrel.r_offset = (input_section->output_section->vma
  2628. + input_section->output_offset
  2629. + offset);
  2630. if (h->dynindx == -1
  2631. || h->forced_local
  2632. || bfd_link_executable (info))
  2633. {
  2634. outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
  2635. 0, R_SPARC_IRELATIVE);
  2636. outrel.r_addend = relocation + rel->r_addend;
  2637. }
  2638. else
  2639. {
  2640. if (h->dynindx == -1)
  2641. abort();
  2642. outrel.r_info = SPARC_ELF_R_INFO (htab, rel, h->dynindx, r_type);
  2643. outrel.r_addend = rel->r_addend;
  2644. }
  2645. sparc_elf_append_rela (output_bfd, sreloc, &outrel);
  2646. continue;
  2647. }
  2648. relocation = (plt_sec->output_section->vma
  2649. + plt_sec->output_offset + h->plt.offset);
  2650. goto do_relocation;
  2651. case R_SPARC_HI22:
  2652. case R_SPARC_LO10:
  2653. /* We should only see such relocs in static links. */
  2654. if (bfd_link_pic (info))
  2655. abort();
  2656. relocation = (plt_sec->output_section->vma
  2657. + plt_sec->output_offset + h->plt.offset);
  2658. goto do_relocation;
  2659. default:
  2660. if (h->root.root.string)
  2661. name = h->root.root.string;
  2662. else
  2663. name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
  2664. NULL);
  2665. (*_bfd_error_handler)
  2666. (_("%B: relocation %s against STT_GNU_IFUNC "
  2667. "symbol `%s' isn't handled by %s"), input_bfd,
  2668. _bfd_sparc_elf_howto_table[r_type].name,
  2669. name, __FUNCTION__);
  2670. bfd_set_error (bfd_error_bad_value);
  2671. return FALSE;
  2672. }
  2673. }
  2674. switch (r_type)
  2675. {
  2676. case R_SPARC_GOTDATA_OP_HIX22:
  2677. case R_SPARC_GOTDATA_OP_LOX10:
  2678. if (SYMBOL_REFERENCES_LOCAL (info, h))
  2679. r_type = (r_type == R_SPARC_GOTDATA_OP_HIX22
  2680. ? R_SPARC_GOTDATA_HIX22
  2681. : R_SPARC_GOTDATA_LOX10);
  2682. else
  2683. r_type = (r_type == R_SPARC_GOTDATA_OP_HIX22
  2684. ? R_SPARC_GOT22
  2685. : R_SPARC_GOT10);
  2686. howto = _bfd_sparc_elf_howto_table + r_type;
  2687. break;
  2688. case R_SPARC_GOTDATA_OP:
  2689. if (SYMBOL_REFERENCES_LOCAL (info, h))
  2690. {
  2691. bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2692. /* {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd */
  2693. relocation = 0x80000000 | (insn & 0x3e07c01f);
  2694. bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
  2695. }
  2696. continue;
  2697. }
  2698. switch (r_type)
  2699. {
  2700. case R_SPARC_GOTDATA_HIX22:
  2701. case R_SPARC_GOTDATA_LOX10:
  2702. relocation = gdopoff (info, relocation);
  2703. break;
  2704. case R_SPARC_GOT10:
  2705. case R_SPARC_GOT13:
  2706. case R_SPARC_GOT22:
  2707. /* Relocation is to the entry for this symbol in the global
  2708. offset table. */
  2709. if (htab->elf.sgot == NULL)
  2710. abort ();
  2711. if (h != NULL)
  2712. {
  2713. bfd_boolean dyn;
  2714. off = h->got.offset;
  2715. BFD_ASSERT (off != (bfd_vma) -1);
  2716. dyn = elf_hash_table (info)->dynamic_sections_created;
  2717. if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  2718. bfd_link_pic (info),
  2719. h)
  2720. || (bfd_link_pic (info)
  2721. && SYMBOL_REFERENCES_LOCAL (info, h)))
  2722. {
  2723. /* This is actually a static link, or it is a
  2724. -Bsymbolic link and the symbol is defined
  2725. locally, or the symbol was forced to be local
  2726. because of a version file. We must initialize
  2727. this entry in the global offset table. Since the
  2728. offset must always be a multiple of 8 for 64-bit
  2729. and 4 for 32-bit, we use the least significant bit
  2730. to record whether we have initialized it already.
  2731. When doing a dynamic link, we create a .rela.got
  2732. relocation entry to initialize the value. This
  2733. is done in the finish_dynamic_symbol routine. */
  2734. if ((off & 1) != 0)
  2735. off &= ~1;
  2736. else
  2737. {
  2738. SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
  2739. htab->elf.sgot->contents + off);
  2740. h->got.offset |= 1;
  2741. }
  2742. }
  2743. else
  2744. unresolved_reloc = FALSE;
  2745. }
  2746. else
  2747. {
  2748. BFD_ASSERT (local_got_offsets != NULL
  2749. && local_got_offsets[r_symndx] != (bfd_vma) -1);
  2750. off = local_got_offsets[r_symndx];
  2751. /* The offset must always be a multiple of 8 on 64-bit and
  2752. 4 on 32-bit. We use the least significant bit to record
  2753. whether we have already processed this entry. */
  2754. if ((off & 1) != 0)
  2755. off &= ~1;
  2756. else
  2757. {
  2758. if (bfd_link_pic (info))
  2759. {
  2760. asection *s;
  2761. Elf_Internal_Rela outrel;
  2762. /* We need to generate a R_SPARC_RELATIVE reloc
  2763. for the dynamic linker. */
  2764. s = htab->elf.srelgot;
  2765. BFD_ASSERT (s != NULL);
  2766. outrel.r_offset = (htab->elf.sgot->output_section->vma
  2767. + htab->elf.sgot->output_offset
  2768. + off);
  2769. outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
  2770. 0, R_SPARC_RELATIVE);
  2771. outrel.r_addend = relocation;
  2772. relocation = 0;
  2773. sparc_elf_append_rela (output_bfd, s, &outrel);
  2774. }
  2775. SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
  2776. htab->elf.sgot->contents + off);
  2777. local_got_offsets[r_symndx] |= 1;
  2778. }
  2779. }
  2780. relocation = htab->elf.sgot->output_offset + off - got_base;
  2781. break;
  2782. case R_SPARC_PLT32:
  2783. case R_SPARC_PLT64:
  2784. if (h == NULL || h->plt.offset == (bfd_vma) -1)
  2785. {
  2786. r_type = (r_type == R_SPARC_PLT32) ? R_SPARC_32 : R_SPARC_64;
  2787. goto r_sparc_plt32;
  2788. }
  2789. /* Fall through. */
  2790. case R_SPARC_WPLT30:
  2791. case R_SPARC_HIPLT22:
  2792. case R_SPARC_LOPLT10:
  2793. case R_SPARC_PCPLT32:
  2794. case R_SPARC_PCPLT22:
  2795. case R_SPARC_PCPLT10:
  2796. r_sparc_wplt30:
  2797. /* Relocation is to the entry for this symbol in the
  2798. procedure linkage table. */
  2799. if (! ABI_64_P (output_bfd))
  2800. {
  2801. /* The Solaris native assembler will generate a WPLT30 reloc
  2802. for a local symbol if you assemble a call from one
  2803. section to another when using -K pic. We treat it as
  2804. WDISP30. */
  2805. if (h == NULL)
  2806. break;
  2807. }
  2808. /* PR 7027: We need similar behaviour for 64-bit binaries. */
  2809. else if (r_type == R_SPARC_WPLT30 && h == NULL)
  2810. break;
  2811. else
  2812. {
  2813. BFD_ASSERT (h != NULL);
  2814. }
  2815. if (h->plt.offset == (bfd_vma) -1 || htab->elf.splt == NULL)
  2816. {
  2817. /* We didn't make a PLT entry for this symbol. This
  2818. happens when statically linking PIC code, or when
  2819. using -Bsymbolic. */
  2820. break;
  2821. }
  2822. relocation = (htab->elf.splt->output_section->vma
  2823. + htab->elf.splt->output_offset
  2824. + h->plt.offset);
  2825. unresolved_reloc = FALSE;
  2826. if (r_type == R_SPARC_PLT32 || r_type == R_SPARC_PLT64)
  2827. {
  2828. r_type = r_type == R_SPARC_PLT32 ? R_SPARC_32 : R_SPARC_64;
  2829. is_plt = TRUE;
  2830. goto r_sparc_plt32;
  2831. }
  2832. break;
  2833. case R_SPARC_PC10:
  2834. case R_SPARC_PC22:
  2835. case R_SPARC_PC_HH22:
  2836. case R_SPARC_PC_HM10:
  2837. case R_SPARC_PC_LM22:
  2838. if (h != NULL
  2839. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  2840. break;
  2841. /* Fall through. */
  2842. case R_SPARC_DISP8:
  2843. case R_SPARC_DISP16:
  2844. case R_SPARC_DISP32:
  2845. case R_SPARC_DISP64:
  2846. case R_SPARC_WDISP30:
  2847. case R_SPARC_WDISP22:
  2848. case R_SPARC_WDISP19:
  2849. case R_SPARC_WDISP16:
  2850. case R_SPARC_WDISP10:
  2851. case R_SPARC_8:
  2852. case R_SPARC_16:
  2853. case R_SPARC_32:
  2854. case R_SPARC_HI22:
  2855. case R_SPARC_22:
  2856. case R_SPARC_13:
  2857. case R_SPARC_LO10:
  2858. case R_SPARC_UA16:
  2859. case R_SPARC_UA32:
  2860. case R_SPARC_10:
  2861. case R_SPARC_11:
  2862. case R_SPARC_64:
  2863. case R_SPARC_OLO10:
  2864. case R_SPARC_HH22:
  2865. case R_SPARC_HM10:
  2866. case R_SPARC_LM22:
  2867. case R_SPARC_7:
  2868. case R_SPARC_5:
  2869. case R_SPARC_6:
  2870. case R_SPARC_HIX22:
  2871. case R_SPARC_LOX10:
  2872. case R_SPARC_H44:
  2873. case R_SPARC_M44:
  2874. case R_SPARC_L44:
  2875. case R_SPARC_H34:
  2876. case R_SPARC_UA64:
  2877. r_sparc_plt32:
  2878. if ((input_section->flags & SEC_ALLOC) == 0
  2879. || is_vxworks_tls)
  2880. break;
  2881. if ((bfd_link_pic (info)
  2882. && (h == NULL
  2883. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  2884. || h->root.type != bfd_link_hash_undefweak)
  2885. && (! howto->pc_relative
  2886. || !SYMBOL_CALLS_LOCAL (info, h)))
  2887. || (!bfd_link_pic (info)
  2888. && h != NULL
  2889. && h->dynindx != -1
  2890. && !h->non_got_ref
  2891. && ((h->def_dynamic
  2892. && !h->def_regular)
  2893. || h->root.type == bfd_link_hash_undefweak
  2894. || h->root.type == bfd_link_hash_undefined)))
  2895. {
  2896. Elf_Internal_Rela outrel;
  2897. bfd_boolean skip, relocate = FALSE;
  2898. /* When generating a shared object, these relocations
  2899. are copied into the output file to be resolved at run
  2900. time. */
  2901. BFD_ASSERT (sreloc != NULL);
  2902. skip = FALSE;
  2903. outrel.r_offset =
  2904. _bfd_elf_section_offset (output_bfd, info, input_section,
  2905. rel->r_offset);
  2906. if (outrel.r_offset == (bfd_vma) -1)
  2907. skip = TRUE;
  2908. else if (outrel.r_offset == (bfd_vma) -2)
  2909. skip = TRUE, relocate = TRUE;
  2910. outrel.r_offset += (input_section->output_section->vma
  2911. + input_section->output_offset);
  2912. /* Optimize unaligned reloc usage now that we know where
  2913. it finally resides. */
  2914. switch (r_type)
  2915. {
  2916. case R_SPARC_16:
  2917. if (outrel.r_offset & 1)
  2918. r_type = R_SPARC_UA16;
  2919. break;
  2920. case R_SPARC_UA16:
  2921. if (!(outrel.r_offset & 1))
  2922. r_type = R_SPARC_16;
  2923. break;
  2924. case R_SPARC_32:
  2925. if (outrel.r_offset & 3)
  2926. r_type = R_SPARC_UA32;
  2927. break;
  2928. case R_SPARC_UA32:
  2929. if (!(outrel.r_offset & 3))
  2930. r_type = R_SPARC_32;
  2931. break;
  2932. case R_SPARC_64:
  2933. if (outrel.r_offset & 7)
  2934. r_type = R_SPARC_UA64;
  2935. break;
  2936. case R_SPARC_UA64:
  2937. if (!(outrel.r_offset & 7))
  2938. r_type = R_SPARC_64;
  2939. break;
  2940. case R_SPARC_DISP8:
  2941. case R_SPARC_DISP16:
  2942. case R_SPARC_DISP32:
  2943. case R_SPARC_DISP64:
  2944. /* If the symbol is not dynamic, we should not keep
  2945. a dynamic relocation. But an .rela.* slot has been
  2946. allocated for it, output R_SPARC_NONE.
  2947. FIXME: Add code tracking needed dynamic relocs as
  2948. e.g. i386 has. */
  2949. if (h->dynindx == -1)
  2950. skip = TRUE, relocate = TRUE;
  2951. break;
  2952. }
  2953. if (skip)
  2954. memset (&outrel, 0, sizeof outrel);
  2955. /* h->dynindx may be -1 if the symbol was marked to
  2956. become local. */
  2957. else if (h != NULL
  2958. && h->dynindx != -1
  2959. && (_bfd_sparc_elf_howto_table[r_type].pc_relative
  2960. || !bfd_link_pic (info)
  2961. || !SYMBOLIC_BIND (info, h)
  2962. || !h->def_regular))
  2963. {
  2964. BFD_ASSERT (h->dynindx != -1);
  2965. outrel.r_info = SPARC_ELF_R_INFO (htab, rel, h->dynindx, r_type);
  2966. outrel.r_addend = rel->r_addend;
  2967. }
  2968. else
  2969. {
  2970. if (r_type == R_SPARC_32 || r_type == R_SPARC_64)
  2971. {
  2972. outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
  2973. 0, R_SPARC_RELATIVE);
  2974. outrel.r_addend = relocation + rel->r_addend;
  2975. }
  2976. else
  2977. {
  2978. long indx;
  2979. outrel.r_addend = relocation + rel->r_addend;
  2980. if (is_plt)
  2981. sec = htab->elf.splt;
  2982. if (bfd_is_abs_section (sec))
  2983. indx = 0;
  2984. else if (sec == NULL || sec->owner == NULL)
  2985. {
  2986. bfd_set_error (bfd_error_bad_value);
  2987. return FALSE;
  2988. }
  2989. else
  2990. {
  2991. asection *osec;
  2992. /* We are turning this relocation into one
  2993. against a section symbol. It would be
  2994. proper to subtract the symbol's value,
  2995. osec->vma, from the emitted reloc addend,
  2996. but ld.so expects buggy relocs. */
  2997. osec = sec->output_section;
  2998. indx = elf_section_data (osec)->dynindx;
  2999. if (indx == 0)
  3000. {
  3001. osec = htab->elf.text_index_section;
  3002. indx = elf_section_data (osec)->dynindx;
  3003. }
  3004. /* FIXME: we really should be able to link non-pic
  3005. shared libraries. */
  3006. if (indx == 0)
  3007. {
  3008. BFD_FAIL ();
  3009. (*_bfd_error_handler)
  3010. (_("%B: probably compiled without -fPIC?"),
  3011. input_bfd);
  3012. bfd_set_error (bfd_error_bad_value);
  3013. return FALSE;
  3014. }
  3015. }
  3016. outrel.r_info = SPARC_ELF_R_INFO (htab, rel, indx,
  3017. r_type);
  3018. }
  3019. }
  3020. sparc_elf_append_rela (output_bfd, sreloc, &outrel);
  3021. /* This reloc will be computed at runtime, so there's no
  3022. need to do anything now. */
  3023. if (! relocate)
  3024. continue;
  3025. }
  3026. break;
  3027. case R_SPARC_TLS_GD_HI22:
  3028. if (! ABI_64_P (input_bfd)
  3029. && ! _bfd_sparc_elf_tdata (input_bfd)->has_tlsgd)
  3030. {
  3031. /* R_SPARC_REV32 used the same reloc number as
  3032. R_SPARC_TLS_GD_HI22. */
  3033. r_type = R_SPARC_REV32;
  3034. break;
  3035. }
  3036. /* Fall through */
  3037. case R_SPARC_TLS_GD_LO10:
  3038. case R_SPARC_TLS_IE_HI22:
  3039. case R_SPARC_TLS_IE_LO10:
  3040. r_type = sparc_elf_tls_transition (info, input_bfd, r_type, h == NULL);
  3041. tls_type = GOT_UNKNOWN;
  3042. if (h == NULL && local_got_offsets)
  3043. tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
  3044. else if (h != NULL)
  3045. {
  3046. tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
  3047. if (!bfd_link_pic (info)
  3048. && h->dynindx == -1
  3049. && tls_type == GOT_TLS_IE)
  3050. switch (SPARC_ELF_R_TYPE (rel->r_info))
  3051. {
  3052. case R_SPARC_TLS_GD_HI22:
  3053. case R_SPARC_TLS_IE_HI22:
  3054. r_type = R_SPARC_TLS_LE_HIX22;
  3055. break;
  3056. default:
  3057. r_type = R_SPARC_TLS_LE_LOX10;
  3058. break;
  3059. }
  3060. }
  3061. if (tls_type == GOT_TLS_IE)
  3062. switch (r_type)
  3063. {
  3064. case R_SPARC_TLS_GD_HI22:
  3065. r_type = R_SPARC_TLS_IE_HI22;
  3066. break;
  3067. case R_SPARC_TLS_GD_LO10:
  3068. r_type = R_SPARC_TLS_IE_LO10;
  3069. break;
  3070. }
  3071. if (r_type == R_SPARC_TLS_LE_HIX22)
  3072. {
  3073. relocation = tpoff (info, relocation);
  3074. break;
  3075. }
  3076. if (r_type == R_SPARC_TLS_LE_LOX10)
  3077. {
  3078. /* Change add into xor. */
  3079. relocation = tpoff (info, relocation);
  3080. bfd_put_32 (output_bfd, (bfd_get_32 (input_bfd,
  3081. contents + rel->r_offset)
  3082. | 0x80182000), contents + rel->r_offset);
  3083. break;
  3084. }
  3085. if (h != NULL)
  3086. {
  3087. off = h->got.offset;
  3088. h->got.offset |= 1;
  3089. }
  3090. else
  3091. {
  3092. BFD_ASSERT (local_got_offsets != NULL);
  3093. off = local_got_offsets[r_symndx];
  3094. local_got_offsets[r_symndx] |= 1;
  3095. }
  3096. r_sparc_tlsldm:
  3097. if (htab->elf.sgot == NULL)
  3098. abort ();
  3099. if ((off & 1) != 0)
  3100. off &= ~1;
  3101. else
  3102. {
  3103. Elf_Internal_Rela outrel;
  3104. int dr_type, indx;
  3105. if (htab->elf.srelgot == NULL)
  3106. abort ();
  3107. SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
  3108. htab->elf.sgot->contents + off);
  3109. outrel.r_offset = (htab->elf.sgot->output_section->vma
  3110. + htab->elf.sgot->output_offset + off);
  3111. indx = h && h->dynindx != -1 ? h->dynindx : 0;
  3112. if (r_type == R_SPARC_TLS_IE_HI22
  3113. || r_type == R_SPARC_TLS_IE_LO10)
  3114. dr_type = SPARC_ELF_TPOFF_RELOC (htab);
  3115. else
  3116. dr_type = SPARC_ELF_DTPMOD_RELOC (htab);
  3117. if (dr_type == SPARC_ELF_TPOFF_RELOC (htab) && indx == 0)
  3118. outrel.r_addend = relocation - dtpoff_base (info);
  3119. else
  3120. outrel.r_addend = 0;
  3121. outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx, dr_type);
  3122. sparc_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
  3123. if (r_type == R_SPARC_TLS_GD_HI22
  3124. || r_type == R_SPARC_TLS_GD_LO10)
  3125. {
  3126. if (indx == 0)
  3127. {
  3128. BFD_ASSERT (! unresolved_reloc);
  3129. SPARC_ELF_PUT_WORD (htab, output_bfd,
  3130. relocation - dtpoff_base (info),
  3131. (htab->elf.sgot->contents + off
  3132. + SPARC_ELF_WORD_BYTES (htab)));
  3133. }
  3134. else
  3135. {
  3136. SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
  3137. (htab->elf.sgot->contents + off
  3138. + SPARC_ELF_WORD_BYTES (htab)));
  3139. outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx,
  3140. SPARC_ELF_DTPOFF_RELOC (htab));
  3141. outrel.r_offset += SPARC_ELF_WORD_BYTES (htab);
  3142. sparc_elf_append_rela (output_bfd, htab->elf.srelgot,
  3143. &outrel);
  3144. }
  3145. }
  3146. else if (dr_type == SPARC_ELF_DTPMOD_RELOC (htab))
  3147. {
  3148. SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
  3149. (htab->elf.sgot->contents + off
  3150. + SPARC_ELF_WORD_BYTES (htab)));
  3151. }
  3152. }
  3153. if (off >= (bfd_vma) -2)
  3154. abort ();
  3155. relocation = htab->elf.sgot->output_offset + off - got_base;
  3156. unresolved_reloc = FALSE;
  3157. howto = _bfd_sparc_elf_howto_table + r_type;
  3158. break;
  3159. case R_SPARC_TLS_LDM_HI22:
  3160. case R_SPARC_TLS_LDM_LO10:
  3161. if (! bfd_link_pic (info))
  3162. {
  3163. bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
  3164. continue;
  3165. }
  3166. off = htab->tls_ldm_got.offset;
  3167. htab->tls_ldm_got.offset |= 1;
  3168. goto r_sparc_tlsldm;
  3169. case R_SPARC_TLS_LDO_HIX22:
  3170. case R_SPARC_TLS_LDO_LOX10:
  3171. if (bfd_link_pic (info))
  3172. {
  3173. relocation -= dtpoff_base (info);
  3174. break;
  3175. }
  3176. r_type = (r_type == R_SPARC_TLS_LDO_HIX22
  3177. ? R_SPARC_TLS_LE_HIX22 : R_SPARC_TLS_LE_LOX10);
  3178. /* Fall through. */
  3179. case R_SPARC_TLS_LE_HIX22:
  3180. case R_SPARC_TLS_LE_LOX10:
  3181. if (bfd_link_pic (info))
  3182. {
  3183. Elf_Internal_Rela outrel;
  3184. bfd_boolean skip;
  3185. BFD_ASSERT (sreloc != NULL);
  3186. skip = FALSE;
  3187. outrel.r_offset =
  3188. _bfd_elf_section_offset (output_bfd, info, input_section,
  3189. rel->r_offset);
  3190. if (outrel.r_offset == (bfd_vma) -1)
  3191. skip = TRUE;
  3192. else if (outrel.r_offset == (bfd_vma) -2)
  3193. skip = TRUE;
  3194. outrel.r_offset += (input_section->output_section->vma
  3195. + input_section->output_offset);
  3196. if (skip)
  3197. memset (&outrel, 0, sizeof outrel);
  3198. else
  3199. {
  3200. outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, r_type);
  3201. outrel.r_addend = relocation - dtpoff_base (info)
  3202. + rel->r_addend;
  3203. }
  3204. sparc_elf_append_rela (output_bfd, sreloc, &outrel);
  3205. continue;
  3206. }
  3207. relocation = tpoff (info, relocation);
  3208. break;
  3209. case R_SPARC_TLS_LDM_CALL:
  3210. if (! bfd_link_pic (info))
  3211. {
  3212. /* mov %g0, %o0 */
  3213. bfd_put_32 (output_bfd, 0x90100000, contents + rel->r_offset);
  3214. continue;
  3215. }
  3216. /* Fall through */
  3217. case R_SPARC_TLS_GD_CALL:
  3218. tls_type = GOT_UNKNOWN;
  3219. if (h == NULL && local_got_offsets)
  3220. tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
  3221. else if (h != NULL)
  3222. tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
  3223. if (! bfd_link_pic (info)
  3224. || (r_type == R_SPARC_TLS_GD_CALL && tls_type == GOT_TLS_IE))
  3225. {
  3226. Elf_Internal_Rela *rel2;
  3227. bfd_vma insn;
  3228. if (!bfd_link_pic (info) && (h == NULL || h->dynindx == -1))
  3229. {
  3230. /* GD -> LE */
  3231. bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
  3232. continue;
  3233. }
  3234. /* GD -> IE */
  3235. if (rel + 1 < relend
  3236. && SPARC_ELF_R_TYPE (rel[1].r_info) == R_SPARC_TLS_GD_ADD
  3237. && rel[1].r_offset == rel->r_offset + 4
  3238. && SPARC_ELF_R_SYMNDX (htab, rel[1].r_info) == r_symndx
  3239. && (((insn = bfd_get_32 (input_bfd,
  3240. contents + rel[1].r_offset))
  3241. >> 25) & 0x1f) == 8)
  3242. {
  3243. /* We have
  3244. call __tls_get_addr, %tgd_call(foo)
  3245. add %reg1, %reg2, %o0, %tgd_add(foo)
  3246. and change it into IE:
  3247. {ld,ldx} [%reg1 + %reg2], %o0, %tie_ldx(foo)
  3248. add %g7, %o0, %o0, %tie_add(foo).
  3249. add is 0x80000000 | (rd << 25) | (rs1 << 14) | rs2,
  3250. ld is 0xc0000000 | (rd << 25) | (rs1 << 14) | rs2,
  3251. ldx is 0xc0580000 | (rd << 25) | (rs1 << 14) | rs2. */
  3252. bfd_put_32 (output_bfd, insn | (ABI_64_P (output_bfd) ? 0xc0580000 : 0xc0000000),
  3253. contents + rel->r_offset);
  3254. bfd_put_32 (output_bfd, 0x9001c008,
  3255. contents + rel->r_offset + 4);
  3256. rel++;
  3257. continue;
  3258. }
  3259. /* We cannot just overwrite the delay slot instruction,
  3260. as it might be what puts the %o0 argument to
  3261. __tls_get_addr into place. So we have to transpose
  3262. the delay slot with the add we patch in. */
  3263. insn = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
  3264. bfd_put_32 (output_bfd, insn,
  3265. contents + rel->r_offset);
  3266. bfd_put_32 (output_bfd, 0x9001c008,
  3267. contents + rel->r_offset + 4);
  3268. rel2 = rel;
  3269. while ((rel2 = sparc_elf_find_reloc_at_ofs (rel2 + 1, relend,
  3270. rel->r_offset + 4))
  3271. != NULL)
  3272. {
  3273. /* If the instruction we moved has a relocation attached to
  3274. it, adjust the offset so that it will apply to the correct
  3275. instruction. */
  3276. rel2->r_offset -= 4;
  3277. }
  3278. continue;
  3279. }
  3280. h = (struct elf_link_hash_entry *)
  3281. bfd_link_hash_lookup (info->hash, "__tls_get_addr", FALSE,
  3282. FALSE, TRUE);
  3283. BFD_ASSERT (h != NULL);
  3284. r_type = R_SPARC_WPLT30;
  3285. howto = _bfd_sparc_elf_howto_table + r_type;
  3286. goto r_sparc_wplt30;
  3287. case R_SPARC_TLS_GD_ADD:
  3288. tls_type = GOT_UNKNOWN;
  3289. if (h == NULL && local_got_offsets)
  3290. tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
  3291. else if (h != NULL)
  3292. tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
  3293. if (! bfd_link_pic (info) || tls_type == GOT_TLS_IE)
  3294. {
  3295. /* add %reg1, %reg2, %reg3, %tgd_add(foo)
  3296. changed into IE:
  3297. {ld,ldx} [%reg1 + %reg2], %reg3, %tie_ldx(foo)
  3298. or LE:
  3299. add %g7, %reg2, %reg3. */
  3300. bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3301. if ((h != NULL && h->dynindx != -1) || bfd_link_pic (info))
  3302. relocation = insn | (ABI_64_P (output_bfd) ? 0xc0580000 : 0xc0000000);
  3303. else
  3304. relocation = (insn & ~0x7c000) | 0x1c000;
  3305. bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
  3306. }
  3307. continue;
  3308. case R_SPARC_TLS_LDM_ADD:
  3309. if (! bfd_link_pic (info))
  3310. bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
  3311. continue;
  3312. case R_SPARC_TLS_LDO_ADD:
  3313. if (! bfd_link_pic (info))
  3314. {
  3315. /* Change rs1 into %g7. */
  3316. bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3317. insn = (insn & ~0x7c000) | 0x1c000;
  3318. bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
  3319. }
  3320. continue;
  3321. case R_SPARC_TLS_IE_LD:
  3322. case R_SPARC_TLS_IE_LDX:
  3323. if (! bfd_link_pic (info) && (h == NULL || h->dynindx == -1))
  3324. {
  3325. bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3326. int rs2 = insn & 0x1f;
  3327. int rd = (insn >> 25) & 0x1f;
  3328. if (rs2 == rd)
  3329. relocation = SPARC_NOP;
  3330. else
  3331. relocation = 0x80100000 | (insn & 0x3e00001f);
  3332. bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
  3333. }
  3334. continue;
  3335. case R_SPARC_TLS_IE_ADD:
  3336. /* Totally useless relocation. */
  3337. continue;
  3338. case R_SPARC_TLS_DTPOFF32:
  3339. case R_SPARC_TLS_DTPOFF64:
  3340. relocation -= dtpoff_base (info);
  3341. break;
  3342. default:
  3343. break;
  3344. }
  3345. /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
  3346. because such sections are not SEC_ALLOC and thus ld.so will
  3347. not process them. */
  3348. if (unresolved_reloc
  3349. && !((input_section->flags & SEC_DEBUGGING) != 0
  3350. && h->def_dynamic)
  3351. && _bfd_elf_section_offset (output_bfd, info, input_section,
  3352. rel->r_offset) != (bfd_vma) -1)
  3353. (*_bfd_error_handler)
  3354. (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
  3355. input_bfd,
  3356. input_section,
  3357. (long) rel->r_offset,
  3358. howto->name,
  3359. h->root.root.string);
  3360. r = bfd_reloc_continue;
  3361. if (r_type == R_SPARC_OLO10)
  3362. {
  3363. bfd_vma x;
  3364. if (! ABI_64_P (output_bfd))
  3365. abort ();
  3366. relocation += rel->r_addend;
  3367. relocation = (relocation & 0x3ff) + ELF64_R_TYPE_DATA (rel->r_info);
  3368. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3369. x = (x & ~(bfd_vma) 0x1fff) | (relocation & 0x1fff);
  3370. bfd_put_32 (input_bfd, x, contents + rel->r_offset);
  3371. r = bfd_check_overflow (howto->complain_on_overflow,
  3372. howto->bitsize, howto->rightshift,
  3373. bfd_arch_bits_per_address (input_bfd),
  3374. relocation);
  3375. }
  3376. else if (r_type == R_SPARC_WDISP16)
  3377. {
  3378. bfd_vma x;
  3379. relocation += rel->r_addend;
  3380. relocation -= (input_section->output_section->vma
  3381. + input_section->output_offset);
  3382. relocation -= rel->r_offset;
  3383. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3384. x |= ((((relocation >> 2) & 0xc000) << 6)
  3385. | ((relocation >> 2) & 0x3fff));
  3386. bfd_put_32 (input_bfd, x, contents + rel->r_offset);
  3387. r = bfd_check_overflow (howto->complain_on_overflow,
  3388. howto->bitsize, howto->rightshift,
  3389. bfd_arch_bits_per_address (input_bfd),
  3390. relocation);
  3391. }
  3392. else if (r_type == R_SPARC_WDISP10)
  3393. {
  3394. bfd_vma x;
  3395. relocation += rel->r_addend;
  3396. relocation -= (input_section->output_section->vma
  3397. + input_section->output_offset);
  3398. relocation -= rel->r_offset;
  3399. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3400. x |= ((((relocation >> 2) & 0x300) << 11)
  3401. | (((relocation >> 2) & 0xff) << 5));
  3402. bfd_put_32 (input_bfd, x, contents + rel->r_offset);
  3403. r = bfd_check_overflow (howto->complain_on_overflow,
  3404. howto->bitsize, howto->rightshift,
  3405. bfd_arch_bits_per_address (input_bfd),
  3406. relocation);
  3407. }
  3408. else if (r_type == R_SPARC_REV32)
  3409. {
  3410. bfd_vma x;
  3411. relocation = relocation + rel->r_addend;
  3412. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3413. x = x + relocation;
  3414. bfd_putl32 (/*input_bfd,*/ x, contents + rel->r_offset);
  3415. r = bfd_reloc_ok;
  3416. }
  3417. else if (r_type == R_SPARC_TLS_LDO_HIX22
  3418. || r_type == R_SPARC_TLS_LE_HIX22)
  3419. {
  3420. bfd_vma x;
  3421. relocation += rel->r_addend;
  3422. if (r_type == R_SPARC_TLS_LE_HIX22)
  3423. relocation ^= MINUS_ONE;
  3424. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3425. x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
  3426. bfd_put_32 (input_bfd, x, contents + rel->r_offset);
  3427. r = bfd_reloc_ok;
  3428. }
  3429. else if (r_type == R_SPARC_TLS_LDO_LOX10
  3430. || r_type == R_SPARC_TLS_LE_LOX10)
  3431. {
  3432. bfd_vma x;
  3433. relocation += rel->r_addend;
  3434. relocation &= 0x3ff;
  3435. if (r_type == R_SPARC_TLS_LE_LOX10)
  3436. relocation |= 0x1c00;
  3437. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3438. x = (x & ~(bfd_vma) 0x1fff) | relocation;
  3439. bfd_put_32 (input_bfd, x, contents + rel->r_offset);
  3440. r = bfd_reloc_ok;
  3441. }
  3442. else if (r_type == R_SPARC_HIX22
  3443. || r_type == R_SPARC_GOTDATA_HIX22)
  3444. {
  3445. bfd_vma x;
  3446. relocation += rel->r_addend;
  3447. if (r_type == R_SPARC_HIX22
  3448. || (bfd_signed_vma) relocation < 0)
  3449. relocation = relocation ^ MINUS_ONE;
  3450. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3451. x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
  3452. bfd_put_32 (input_bfd, x, contents + rel->r_offset);
  3453. r = bfd_check_overflow (howto->complain_on_overflow,
  3454. howto->bitsize, howto->rightshift,
  3455. bfd_arch_bits_per_address (input_bfd),
  3456. relocation);
  3457. }
  3458. else if (r_type == R_SPARC_LOX10
  3459. || r_type == R_SPARC_GOTDATA_LOX10)
  3460. {
  3461. bfd_vma x;
  3462. relocation += rel->r_addend;
  3463. if (r_type == R_SPARC_LOX10
  3464. || (bfd_signed_vma) relocation < 0)
  3465. relocation = (relocation & 0x3ff) | 0x1c00;
  3466. else
  3467. relocation = (relocation & 0x3ff);
  3468. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3469. x = (x & ~(bfd_vma) 0x1fff) | relocation;
  3470. bfd_put_32 (input_bfd, x, contents + rel->r_offset);
  3471. r = bfd_reloc_ok;
  3472. }
  3473. else if ((r_type == R_SPARC_WDISP30 || r_type == R_SPARC_WPLT30)
  3474. && sec_do_relax (input_section)
  3475. && rel->r_offset + 4 < input_section->size)
  3476. {
  3477. #define G0 0
  3478. #define O7 15
  3479. #define XCC (2 << 20)
  3480. #define COND(x) (((x)&0xf)<<25)
  3481. #define CONDA COND(0x8)
  3482. #define INSN_BPA (F2(0,1) | CONDA | BPRED | XCC)
  3483. #define INSN_BA (F2(0,2) | CONDA)
  3484. #define INSN_OR F3(2, 0x2, 0)
  3485. #define INSN_NOP F2(0,4)
  3486. bfd_vma x, y;
  3487. /* If the instruction is a call with either:
  3488. restore
  3489. arithmetic instruction with rd == %o7
  3490. where rs1 != %o7 and rs2 if it is register != %o7
  3491. then we can optimize if the call destination is near
  3492. by changing the call into a branch always. */
  3493. x = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3494. y = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
  3495. if ((x & OP(~0)) == OP(1) && (y & OP(~0)) == OP(2))
  3496. {
  3497. if (((y & OP3(~0)) == OP3(0x3d) /* restore */
  3498. || ((y & OP3(0x28)) == 0 /* arithmetic */
  3499. && (y & RD(~0)) == RD(O7)))
  3500. && (y & RS1(~0)) != RS1(O7)
  3501. && ((y & F3I(~0))
  3502. || (y & RS2(~0)) != RS2(O7)))
  3503. {
  3504. bfd_vma reloc;
  3505. reloc = relocation + rel->r_addend - rel->r_offset;
  3506. reloc -= (input_section->output_section->vma
  3507. + input_section->output_offset);
  3508. /* Ensure the branch fits into simm22. */
  3509. if ((reloc & 3) == 0
  3510. && ((reloc & ~(bfd_vma)0x7fffff) == 0
  3511. || ((reloc | 0x7fffff) == ~(bfd_vma)0)))
  3512. {
  3513. reloc >>= 2;
  3514. /* Check whether it fits into simm19. */
  3515. if (((reloc & 0x3c0000) == 0
  3516. || (reloc & 0x3c0000) == 0x3c0000)
  3517. && (ABI_64_P (output_bfd)
  3518. || elf_elfheader (output_bfd)->e_flags & EF_SPARC_32PLUS))
  3519. x = INSN_BPA | (reloc & 0x7ffff); /* ba,pt %xcc */
  3520. else
  3521. x = INSN_BA | (reloc & 0x3fffff); /* ba */
  3522. bfd_put_32 (input_bfd, x, contents + rel->r_offset);
  3523. r = bfd_reloc_ok;
  3524. if (rel->r_offset >= 4
  3525. && (y & (0xffffffff ^ RS1(~0)))
  3526. == (INSN_OR | RD(O7) | RS2(G0)))
  3527. {
  3528. bfd_vma z;
  3529. unsigned int reg;
  3530. z = bfd_get_32 (input_bfd,
  3531. contents + rel->r_offset - 4);
  3532. if ((z & (0xffffffff ^ RD(~0)))
  3533. != (INSN_OR | RS1(O7) | RS2(G0)))
  3534. break;
  3535. /* The sequence was
  3536. or %o7, %g0, %rN
  3537. call foo
  3538. or %rN, %g0, %o7
  3539. If call foo was replaced with ba, replace
  3540. or %rN, %g0, %o7 with nop. */
  3541. reg = (y & RS1(~0)) >> 14;
  3542. if (reg != ((z & RD(~0)) >> 25)
  3543. || reg == G0 || reg == O7)
  3544. break;
  3545. bfd_put_32 (input_bfd, (bfd_vma) INSN_NOP,
  3546. contents + rel->r_offset + 4);
  3547. }
  3548. }
  3549. }
  3550. }
  3551. }
  3552. if (r == bfd_reloc_continue)
  3553. {
  3554. do_relocation:
  3555. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  3556. contents, rel->r_offset,
  3557. relocation, rel->r_addend);
  3558. }
  3559. if (r != bfd_reloc_ok)
  3560. {
  3561. switch (r)
  3562. {
  3563. default:
  3564. case bfd_reloc_outofrange:
  3565. abort ();
  3566. case bfd_reloc_overflow:
  3567. {
  3568. const char *name;
  3569. /* The Solaris native linker silently disregards overflows.
  3570. We don't, but this breaks stabs debugging info, whose
  3571. relocations are only 32-bits wide. Ignore overflows in
  3572. this case and also for discarded entries. */
  3573. if ((r_type == R_SPARC_32
  3574. || r_type == R_SPARC_UA32
  3575. || r_type == R_SPARC_DISP32)
  3576. && (((input_section->flags & SEC_DEBUGGING) != 0
  3577. && strcmp (bfd_section_name (input_bfd,
  3578. input_section),
  3579. ".stab") == 0)
  3580. || _bfd_elf_section_offset (output_bfd, info,
  3581. input_section,
  3582. rel->r_offset)
  3583. == (bfd_vma)-1))
  3584. break;
  3585. if (h != NULL)
  3586. {
  3587. /* Assume this is a call protected by other code that
  3588. detect the symbol is undefined. If this is the case,
  3589. we can safely ignore the overflow. If not, the
  3590. program is hosed anyway, and a little warning isn't
  3591. going to help. */
  3592. if (h->root.type == bfd_link_hash_undefweak
  3593. && howto->pc_relative)
  3594. break;
  3595. name = NULL;
  3596. }
  3597. else
  3598. {
  3599. name = bfd_elf_string_from_elf_section (input_bfd,
  3600. symtab_hdr->sh_link,
  3601. sym->st_name);
  3602. if (name == NULL)
  3603. return FALSE;
  3604. if (*name == '\0')
  3605. name = bfd_section_name (input_bfd, sec);
  3606. }
  3607. if (! ((*info->callbacks->reloc_overflow)
  3608. (info, (h ? &h->root : NULL), name, howto->name,
  3609. (bfd_vma) 0, input_bfd, input_section,
  3610. rel->r_offset)))
  3611. return FALSE;
  3612. }
  3613. break;
  3614. }
  3615. }
  3616. }
  3617. return TRUE;
  3618. }
  3619. /* Build a VxWorks PLT entry. PLT_INDEX is the index of the PLT entry
  3620. and PLT_OFFSET is the byte offset from the start of .plt. GOT_OFFSET
  3621. is the offset of the associated .got.plt entry from
  3622. _GLOBAL_OFFSET_TABLE_. */
  3623. static void
  3624. sparc_vxworks_build_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
  3625. bfd_vma plt_offset, bfd_vma plt_index,
  3626. bfd_vma got_offset)
  3627. {
  3628. bfd_vma got_base;
  3629. const bfd_vma *plt_entry;
  3630. struct _bfd_sparc_elf_link_hash_table *htab;
  3631. bfd_byte *loc;
  3632. Elf_Internal_Rela rela;
  3633. htab = _bfd_sparc_elf_hash_table (info);
  3634. BFD_ASSERT (htab != NULL);
  3635. if (bfd_link_pic (info))
  3636. {
  3637. plt_entry = sparc_vxworks_shared_plt_entry;
  3638. got_base = 0;
  3639. }
  3640. else
  3641. {
  3642. plt_entry = sparc_vxworks_exec_plt_entry;
  3643. got_base = (htab->elf.hgot->root.u.def.value
  3644. + htab->elf.hgot->root.u.def.section->output_offset
  3645. + htab->elf.hgot->root.u.def.section->output_section->vma);
  3646. }
  3647. /* Fill in the entry in the procedure linkage table. */
  3648. bfd_put_32 (output_bfd, plt_entry[0] + ((got_base + got_offset) >> 10),
  3649. htab->elf.splt->contents + plt_offset);
  3650. bfd_put_32 (output_bfd, plt_entry[1] + ((got_base + got_offset) & 0x3ff),
  3651. htab->elf.splt->contents + plt_offset + 4);
  3652. bfd_put_32 (output_bfd, plt_entry[2],
  3653. htab->elf.splt->contents + plt_offset + 8);
  3654. bfd_put_32 (output_bfd, plt_entry[3],
  3655. htab->elf.splt->contents + plt_offset + 12);
  3656. bfd_put_32 (output_bfd, plt_entry[4],
  3657. htab->elf.splt->contents + plt_offset + 16);
  3658. bfd_put_32 (output_bfd, plt_entry[5] + (plt_index >> 10),
  3659. htab->elf.splt->contents + plt_offset + 20);
  3660. /* PC-relative displacement for a branch to the start of
  3661. the PLT section. */
  3662. bfd_put_32 (output_bfd, plt_entry[6] + (((-plt_offset - 24) >> 2)
  3663. & 0x003fffff),
  3664. htab->elf.splt->contents + plt_offset + 24);
  3665. bfd_put_32 (output_bfd, plt_entry[7] + (plt_index & 0x3ff),
  3666. htab->elf.splt->contents + plt_offset + 28);
  3667. /* Fill in the .got.plt entry, pointing initially at the
  3668. second half of the PLT entry. */
  3669. BFD_ASSERT (htab->elf.sgotplt != NULL);
  3670. bfd_put_32 (output_bfd,
  3671. htab->elf.splt->output_section->vma
  3672. + htab->elf.splt->output_offset
  3673. + plt_offset + 20,
  3674. htab->elf.sgotplt->contents + got_offset);
  3675. /* Add relocations to .rela.plt.unloaded. */
  3676. if (!bfd_link_pic (info))
  3677. {
  3678. loc = (htab->srelplt2->contents
  3679. + (2 + 3 * plt_index) * sizeof (Elf32_External_Rela));
  3680. /* Relocate the initial sethi. */
  3681. rela.r_offset = (htab->elf.splt->output_section->vma
  3682. + htab->elf.splt->output_offset
  3683. + plt_offset);
  3684. rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
  3685. rela.r_addend = got_offset;
  3686. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  3687. loc += sizeof (Elf32_External_Rela);
  3688. /* Likewise the following or. */
  3689. rela.r_offset += 4;
  3690. rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
  3691. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  3692. loc += sizeof (Elf32_External_Rela);
  3693. /* Relocate the .got.plt entry. */
  3694. rela.r_offset = (htab->elf.sgotplt->output_section->vma
  3695. + htab->elf.sgotplt->output_offset
  3696. + got_offset);
  3697. rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_SPARC_32);
  3698. rela.r_addend = plt_offset + 20;
  3699. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  3700. }
  3701. }
  3702. /* Finish up dynamic symbol handling. We set the contents of various
  3703. dynamic sections here. */
  3704. bfd_boolean
  3705. _bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd,
  3706. struct bfd_link_info *info,
  3707. struct elf_link_hash_entry *h,
  3708. Elf_Internal_Sym *sym)
  3709. {
  3710. struct _bfd_sparc_elf_link_hash_table *htab;
  3711. const struct elf_backend_data *bed;
  3712. htab = _bfd_sparc_elf_hash_table (info);
  3713. BFD_ASSERT (htab != NULL);
  3714. bed = get_elf_backend_data (output_bfd);
  3715. if (h->plt.offset != (bfd_vma) -1)
  3716. {
  3717. asection *splt;
  3718. asection *srela;
  3719. Elf_Internal_Rela rela;
  3720. bfd_byte *loc;
  3721. bfd_vma r_offset, got_offset;
  3722. int rela_index;
  3723. /* When building a static executable, use .iplt and
  3724. .rela.iplt sections for STT_GNU_IFUNC symbols. */
  3725. if (htab->elf.splt != NULL)
  3726. {
  3727. splt = htab->elf.splt;
  3728. srela = htab->elf.srelplt;
  3729. }
  3730. else
  3731. {
  3732. splt = htab->elf.iplt;
  3733. srela = htab->elf.irelplt;
  3734. }
  3735. if (splt == NULL || srela == NULL)
  3736. abort ();
  3737. /* Fill in the entry in the .rela.plt section. */
  3738. if (htab->is_vxworks)
  3739. {
  3740. /* Work out the index of this PLT entry. */
  3741. rela_index = ((h->plt.offset - htab->plt_header_size)
  3742. / htab->plt_entry_size);
  3743. /* Calculate the offset of the associated .got.plt entry.
  3744. The first three entries are reserved. */
  3745. got_offset = (rela_index + 3) * 4;
  3746. sparc_vxworks_build_plt_entry (output_bfd, info, h->plt.offset,
  3747. rela_index, got_offset);
  3748. /* On VxWorks, the relocation points to the .got.plt entry,
  3749. not the .plt entry. */
  3750. rela.r_offset = (htab->elf.sgotplt->output_section->vma
  3751. + htab->elf.sgotplt->output_offset
  3752. + got_offset);
  3753. rela.r_addend = 0;
  3754. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
  3755. R_SPARC_JMP_SLOT);
  3756. }
  3757. else
  3758. {
  3759. bfd_boolean ifunc = FALSE;
  3760. /* Fill in the entry in the procedure linkage table. */
  3761. rela_index = SPARC_ELF_BUILD_PLT_ENTRY (htab, output_bfd, splt,
  3762. h->plt.offset, splt->size,
  3763. &r_offset);
  3764. if (h == NULL
  3765. || h->dynindx == -1
  3766. || ((bfd_link_executable (info)
  3767. || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  3768. && h->def_regular
  3769. && h->type == STT_GNU_IFUNC))
  3770. {
  3771. ifunc = TRUE;
  3772. BFD_ASSERT (h == NULL
  3773. || (h->type == STT_GNU_IFUNC
  3774. && h->def_regular
  3775. && (h->root.type == bfd_link_hash_defined
  3776. || h->root.type == bfd_link_hash_defweak)));
  3777. }
  3778. rela.r_offset = r_offset
  3779. + (splt->output_section->vma + splt->output_offset);
  3780. if (ABI_64_P (output_bfd)
  3781. && h->plt.offset >= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE))
  3782. {
  3783. if (ifunc)
  3784. {
  3785. rela.r_addend = (h->root.u.def.section->output_section->vma
  3786. + h->root.u.def.section->output_offset
  3787. + h->root.u.def.value);
  3788. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0,
  3789. R_SPARC_IRELATIVE);
  3790. }
  3791. else
  3792. {
  3793. rela.r_addend = (-(h->plt.offset + 4)
  3794. - splt->output_section->vma
  3795. - splt->output_offset);
  3796. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
  3797. R_SPARC_JMP_SLOT);
  3798. }
  3799. }
  3800. else
  3801. {
  3802. if (ifunc)
  3803. {
  3804. rela.r_addend = (h->root.u.def.section->output_section->vma
  3805. + h->root.u.def.section->output_offset
  3806. + h->root.u.def.value);
  3807. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0,
  3808. R_SPARC_JMP_IREL);
  3809. }
  3810. else
  3811. {
  3812. rela.r_addend = 0;
  3813. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
  3814. R_SPARC_JMP_SLOT);
  3815. }
  3816. }
  3817. }
  3818. /* Adjust for the first 4 reserved elements in the .plt section
  3819. when setting the offset in the .rela.plt section.
  3820. Sun forgot to read their own ABI and copied elf32-sparc behaviour,
  3821. thus .plt[4] has corresponding .rela.plt[0] and so on. */
  3822. loc = srela->contents;
  3823. loc += rela_index * bed->s->sizeof_rela;
  3824. bed->s->swap_reloca_out (output_bfd, &rela, loc);
  3825. if (!h->def_regular)
  3826. {
  3827. /* Mark the symbol as undefined, rather than as defined in
  3828. the .plt section. Leave the value alone. */
  3829. sym->st_shndx = SHN_UNDEF;
  3830. /* If the symbol is weak, we do need to clear the value.
  3831. Otherwise, the PLT entry would provide a definition for
  3832. the symbol even if the symbol wasn't defined anywhere,
  3833. and so the symbol would never be NULL. */
  3834. if (!h->ref_regular_nonweak)
  3835. sym->st_value = 0;
  3836. }
  3837. }
  3838. if (h->got.offset != (bfd_vma) -1
  3839. && _bfd_sparc_elf_hash_entry(h)->tls_type != GOT_TLS_GD
  3840. && _bfd_sparc_elf_hash_entry(h)->tls_type != GOT_TLS_IE)
  3841. {
  3842. asection *sgot;
  3843. asection *srela;
  3844. Elf_Internal_Rela rela;
  3845. /* This symbol has an entry in the GOT. Set it up. */
  3846. sgot = htab->elf.sgot;
  3847. srela = htab->elf.srelgot;
  3848. BFD_ASSERT (sgot != NULL && srela != NULL);
  3849. rela.r_offset = (sgot->output_section->vma
  3850. + sgot->output_offset
  3851. + (h->got.offset &~ (bfd_vma) 1));
  3852. /* If this is a -Bsymbolic link, and the symbol is defined
  3853. locally, we just want to emit a RELATIVE reloc. Likewise if
  3854. the symbol was forced to be local because of a version file.
  3855. The entry in the global offset table will already have been
  3856. initialized in the relocate_section function. */
  3857. if (! bfd_link_pic (info)
  3858. && h->type == STT_GNU_IFUNC
  3859. && h->def_regular)
  3860. {
  3861. asection *plt;
  3862. /* We load the GOT entry with the PLT entry. */
  3863. plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
  3864. SPARC_ELF_PUT_WORD (htab, output_bfd,
  3865. (plt->output_section->vma
  3866. + plt->output_offset + h->plt.offset),
  3867. htab->elf.sgot->contents
  3868. + (h->got.offset & ~(bfd_vma) 1));
  3869. return TRUE;
  3870. }
  3871. else if (bfd_link_pic (info)
  3872. && SYMBOL_REFERENCES_LOCAL (info, h))
  3873. {
  3874. asection *sec = h->root.u.def.section;
  3875. if (h->type == STT_GNU_IFUNC)
  3876. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, R_SPARC_IRELATIVE);
  3877. else
  3878. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, R_SPARC_RELATIVE);
  3879. rela.r_addend = (h->root.u.def.value
  3880. + sec->output_section->vma
  3881. + sec->output_offset);
  3882. }
  3883. else
  3884. {
  3885. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_GLOB_DAT);
  3886. rela.r_addend = 0;
  3887. }
  3888. SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
  3889. sgot->contents + (h->got.offset & ~(bfd_vma) 1));
  3890. sparc_elf_append_rela (output_bfd, srela, &rela);
  3891. }
  3892. if (h->needs_copy)
  3893. {
  3894. asection *s;
  3895. Elf_Internal_Rela rela;
  3896. /* This symbols needs a copy reloc. Set it up. */
  3897. BFD_ASSERT (h->dynindx != -1);
  3898. s = bfd_get_linker_section (h->root.u.def.section->owner,
  3899. ".rela.bss");
  3900. BFD_ASSERT (s != NULL);
  3901. rela.r_offset = (h->root.u.def.value
  3902. + h->root.u.def.section->output_section->vma
  3903. + h->root.u.def.section->output_offset);
  3904. rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_COPY);
  3905. rela.r_addend = 0;
  3906. sparc_elf_append_rela (output_bfd, s, &rela);
  3907. }
  3908. /* Mark some specially defined symbols as absolute. On VxWorks,
  3909. _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
  3910. ".got" section. Likewise _PROCEDURE_LINKAGE_TABLE_ and ".plt". */
  3911. if (sym != NULL
  3912. && (h == htab->elf.hdynamic
  3913. || (!htab->is_vxworks
  3914. && (h == htab->elf.hgot || h == htab->elf.hplt))))
  3915. sym->st_shndx = SHN_ABS;
  3916. return TRUE;
  3917. }
  3918. /* Finish up the dynamic sections. */
  3919. static bfd_boolean
  3920. sparc_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
  3921. bfd *dynobj, asection *sdyn,
  3922. asection *splt ATTRIBUTE_UNUSED)
  3923. {
  3924. struct _bfd_sparc_elf_link_hash_table *htab;
  3925. const struct elf_backend_data *bed;
  3926. bfd_byte *dyncon, *dynconend;
  3927. size_t dynsize;
  3928. int stt_regidx = -1;
  3929. bfd_boolean abi_64_p;
  3930. htab = _bfd_sparc_elf_hash_table (info);
  3931. BFD_ASSERT (htab != NULL);
  3932. bed = get_elf_backend_data (output_bfd);
  3933. dynsize = bed->s->sizeof_dyn;
  3934. dynconend = sdyn->contents + sdyn->size;
  3935. abi_64_p = ABI_64_P (output_bfd);
  3936. for (dyncon = sdyn->contents; dyncon < dynconend; dyncon += dynsize)
  3937. {
  3938. Elf_Internal_Dyn dyn;
  3939. const char *name;
  3940. bfd_boolean size;
  3941. bed->s->swap_dyn_in (dynobj, dyncon, &dyn);
  3942. if (htab->is_vxworks && dyn.d_tag == DT_RELASZ)
  3943. {
  3944. /* On VxWorks, DT_RELASZ should not include the relocations
  3945. in .rela.plt. */
  3946. if (htab->elf.srelplt)
  3947. {
  3948. dyn.d_un.d_val -= htab->elf.srelplt->size;
  3949. bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
  3950. }
  3951. }
  3952. else if (htab->is_vxworks && dyn.d_tag == DT_PLTGOT)
  3953. {
  3954. /* On VxWorks, DT_PLTGOT should point to the start of the GOT,
  3955. not to the start of the PLT. */
  3956. if (htab->elf.sgotplt)
  3957. {
  3958. dyn.d_un.d_val = (htab->elf.sgotplt->output_section->vma
  3959. + htab->elf.sgotplt->output_offset);
  3960. bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
  3961. }
  3962. }
  3963. else if (htab->is_vxworks
  3964. && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
  3965. bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
  3966. else if (abi_64_p && dyn.d_tag == DT_SPARC_REGISTER)
  3967. {
  3968. if (stt_regidx == -1)
  3969. {
  3970. stt_regidx =
  3971. _bfd_elf_link_lookup_local_dynindx (info, output_bfd, -1);
  3972. if (stt_regidx == -1)
  3973. return FALSE;
  3974. }
  3975. dyn.d_un.d_val = stt_regidx++;
  3976. bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
  3977. }
  3978. else
  3979. {
  3980. switch (dyn.d_tag)
  3981. {
  3982. case DT_PLTGOT: name = ".plt"; size = FALSE; break;
  3983. case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break;
  3984. case DT_JMPREL: name = ".rela.plt"; size = FALSE; break;
  3985. default: name = NULL; size = FALSE; break;
  3986. }
  3987. if (name != NULL)
  3988. {
  3989. asection *s;
  3990. s = bfd_get_section_by_name (output_bfd, name);
  3991. if (s == NULL)
  3992. dyn.d_un.d_val = 0;
  3993. else
  3994. {
  3995. if (! size)
  3996. dyn.d_un.d_ptr = s->vma;
  3997. else
  3998. dyn.d_un.d_val = s->size;
  3999. }
  4000. bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
  4001. }
  4002. }
  4003. }
  4004. return TRUE;
  4005. }
  4006. /* Install the first PLT entry in a VxWorks executable and make sure that
  4007. .rela.plt.unloaded relocations have the correct symbol indexes. */
  4008. static void
  4009. sparc_vxworks_finish_exec_plt (bfd *output_bfd, struct bfd_link_info *info)
  4010. {
  4011. struct _bfd_sparc_elf_link_hash_table *htab;
  4012. Elf_Internal_Rela rela;
  4013. bfd_vma got_base;
  4014. bfd_byte *loc;
  4015. htab = _bfd_sparc_elf_hash_table (info);
  4016. BFD_ASSERT (htab != NULL);
  4017. /* Calculate the absolute value of _GLOBAL_OFFSET_TABLE_. */
  4018. got_base = (htab->elf.hgot->root.u.def.section->output_section->vma
  4019. + htab->elf.hgot->root.u.def.section->output_offset
  4020. + htab->elf.hgot->root.u.def.value);
  4021. /* Install the initial PLT entry. */
  4022. bfd_put_32 (output_bfd,
  4023. sparc_vxworks_exec_plt0_entry[0] + ((got_base + 8) >> 10),
  4024. htab->elf.splt->contents);
  4025. bfd_put_32 (output_bfd,
  4026. sparc_vxworks_exec_plt0_entry[1] + ((got_base + 8) & 0x3ff),
  4027. htab->elf.splt->contents + 4);
  4028. bfd_put_32 (output_bfd,
  4029. sparc_vxworks_exec_plt0_entry[2],
  4030. htab->elf.splt->contents + 8);
  4031. bfd_put_32 (output_bfd,
  4032. sparc_vxworks_exec_plt0_entry[3],
  4033. htab->elf.splt->contents + 12);
  4034. bfd_put_32 (output_bfd,
  4035. sparc_vxworks_exec_plt0_entry[4],
  4036. htab->elf.splt->contents + 16);
  4037. loc = htab->srelplt2->contents;
  4038. /* Add an unloaded relocation for the initial entry's "sethi". */
  4039. rela.r_offset = (htab->elf.splt->output_section->vma
  4040. + htab->elf.splt->output_offset);
  4041. rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
  4042. rela.r_addend = 8;
  4043. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  4044. loc += sizeof (Elf32_External_Rela);
  4045. /* Likewise the following "or". */
  4046. rela.r_offset += 4;
  4047. rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
  4048. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  4049. loc += sizeof (Elf32_External_Rela);
  4050. /* Fix up the remaining .rela.plt.unloaded relocations. They may have
  4051. the wrong symbol index for _G_O_T_ or _P_L_T_ depending on the order
  4052. in which symbols were output. */
  4053. while (loc < htab->srelplt2->contents + htab->srelplt2->size)
  4054. {
  4055. Elf_Internal_Rela rel;
  4056. /* The entry's initial "sethi" (against _G_O_T_). */
  4057. bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
  4058. rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
  4059. bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
  4060. loc += sizeof (Elf32_External_Rela);
  4061. /* The following "or" (also against _G_O_T_). */
  4062. bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
  4063. rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
  4064. bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
  4065. loc += sizeof (Elf32_External_Rela);
  4066. /* The .got.plt entry (against _P_L_T_). */
  4067. bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
  4068. rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_SPARC_32);
  4069. bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
  4070. loc += sizeof (Elf32_External_Rela);
  4071. }
  4072. }
  4073. /* Install the first PLT entry in a VxWorks shared object. */
  4074. static void
  4075. sparc_vxworks_finish_shared_plt (bfd *output_bfd, struct bfd_link_info *info)
  4076. {
  4077. struct _bfd_sparc_elf_link_hash_table *htab;
  4078. unsigned int i;
  4079. htab = _bfd_sparc_elf_hash_table (info);
  4080. BFD_ASSERT (htab != NULL);
  4081. for (i = 0; i < ARRAY_SIZE (sparc_vxworks_shared_plt0_entry); i++)
  4082. bfd_put_32 (output_bfd, sparc_vxworks_shared_plt0_entry[i],
  4083. htab->elf.splt->contents + i * 4);
  4084. }
  4085. /* Finish up local dynamic symbol handling. We set the contents of
  4086. various dynamic sections here. */
  4087. static bfd_boolean
  4088. finish_local_dynamic_symbol (void **slot, void *inf)
  4089. {
  4090. struct elf_link_hash_entry *h
  4091. = (struct elf_link_hash_entry *) *slot;
  4092. struct bfd_link_info *info
  4093. = (struct bfd_link_info *) inf;
  4094. return _bfd_sparc_elf_finish_dynamic_symbol (info->output_bfd, info,
  4095. h, NULL);
  4096. }
  4097. bfd_boolean
  4098. _bfd_sparc_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
  4099. {
  4100. bfd *dynobj;
  4101. asection *sdyn;
  4102. struct _bfd_sparc_elf_link_hash_table *htab;
  4103. htab = _bfd_sparc_elf_hash_table (info);
  4104. BFD_ASSERT (htab != NULL);
  4105. dynobj = htab->elf.dynobj;
  4106. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  4107. if (elf_hash_table (info)->dynamic_sections_created)
  4108. {
  4109. asection *splt;
  4110. splt = htab->elf.splt;
  4111. BFD_ASSERT (splt != NULL && sdyn != NULL);
  4112. if (!sparc_finish_dyn (output_bfd, info, dynobj, sdyn, splt))
  4113. return FALSE;
  4114. /* Initialize the contents of the .plt section. */
  4115. if (splt->size > 0)
  4116. {
  4117. if (htab->is_vxworks)
  4118. {
  4119. if (bfd_link_pic (info))
  4120. sparc_vxworks_finish_shared_plt (output_bfd, info);
  4121. else
  4122. sparc_vxworks_finish_exec_plt (output_bfd, info);
  4123. }
  4124. else
  4125. {
  4126. memset (splt->contents, 0, htab->plt_header_size);
  4127. if (!ABI_64_P (output_bfd))
  4128. bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP,
  4129. splt->contents + splt->size - 4);
  4130. }
  4131. }
  4132. if (elf_section_data (splt->output_section) != NULL)
  4133. elf_section_data (splt->output_section)->this_hdr.sh_entsize
  4134. = ((htab->is_vxworks || !ABI_64_P (output_bfd))
  4135. ? 0 : htab->plt_entry_size);
  4136. }
  4137. /* Set the first entry in the global offset table to the address of
  4138. the dynamic section. */
  4139. if (htab->elf.sgot && htab->elf.sgot->size > 0)
  4140. {
  4141. bfd_vma val = (sdyn ?
  4142. sdyn->output_section->vma + sdyn->output_offset :
  4143. 0);
  4144. SPARC_ELF_PUT_WORD (htab, output_bfd, val, htab->elf.sgot->contents);
  4145. }
  4146. if (htab->elf.sgot)
  4147. elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize =
  4148. SPARC_ELF_WORD_BYTES (htab);
  4149. /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
  4150. htab_traverse (htab->loc_hash_table, finish_local_dynamic_symbol, info);
  4151. return TRUE;
  4152. }
  4153. /* Set the right machine number for a SPARC ELF file. */
  4154. bfd_boolean
  4155. _bfd_sparc_elf_object_p (bfd *abfd)
  4156. {
  4157. if (ABI_64_P (abfd))
  4158. {
  4159. unsigned long mach = bfd_mach_sparc_v9;
  4160. if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US3)
  4161. mach = bfd_mach_sparc_v9b;
  4162. else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US1)
  4163. mach = bfd_mach_sparc_v9a;
  4164. return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, mach);
  4165. }
  4166. else
  4167. {
  4168. if (elf_elfheader (abfd)->e_machine == EM_SPARC32PLUS)
  4169. {
  4170. if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US3)
  4171. return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
  4172. bfd_mach_sparc_v8plusb);
  4173. else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US1)
  4174. return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
  4175. bfd_mach_sparc_v8plusa);
  4176. else if (elf_elfheader (abfd)->e_flags & EF_SPARC_32PLUS)
  4177. return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
  4178. bfd_mach_sparc_v8plus);
  4179. else
  4180. return FALSE;
  4181. }
  4182. else if (elf_elfheader (abfd)->e_flags & EF_SPARC_LEDATA)
  4183. return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
  4184. bfd_mach_sparc_sparclite_le);
  4185. else
  4186. return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc);
  4187. }
  4188. }
  4189. /* Return address for Ith PLT stub in section PLT, for relocation REL
  4190. or (bfd_vma) -1 if it should not be included. */
  4191. bfd_vma
  4192. _bfd_sparc_elf_plt_sym_val (bfd_vma i, const asection *plt, const arelent *rel)
  4193. {
  4194. if (ABI_64_P (plt->owner))
  4195. {
  4196. bfd_vma j;
  4197. i += PLT64_HEADER_SIZE / PLT64_ENTRY_SIZE;
  4198. if (i < PLT64_LARGE_THRESHOLD)
  4199. return plt->vma + i * PLT64_ENTRY_SIZE;
  4200. j = (i - PLT64_LARGE_THRESHOLD) % 160;
  4201. i -= j;
  4202. return plt->vma + i * PLT64_ENTRY_SIZE + j * 4 * 6;
  4203. }
  4204. else
  4205. return rel->address;
  4206. }
  4207. /* Merge backend specific data from an object file to the output
  4208. object file when linking. */
  4209. bfd_boolean
  4210. _bfd_sparc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
  4211. {
  4212. obj_attribute *in_attr, *in_attrs;
  4213. obj_attribute *out_attr, *out_attrs;
  4214. if (!elf_known_obj_attributes_proc (obfd)[0].i)
  4215. {
  4216. /* This is the first object. Copy the attributes. */
  4217. _bfd_elf_copy_obj_attributes (ibfd, obfd);
  4218. /* Use the Tag_null value to indicate the attributes have been
  4219. initialized. */
  4220. elf_known_obj_attributes_proc (obfd)[0].i = 1;
  4221. return TRUE;
  4222. }
  4223. in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
  4224. out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
  4225. in_attr = &in_attrs[Tag_GNU_Sparc_HWCAPS];
  4226. out_attr = &out_attrs[Tag_GNU_Sparc_HWCAPS];
  4227. out_attr->i |= in_attr->i;
  4228. out_attr->type = 1;
  4229. in_attr = &in_attrs[Tag_GNU_Sparc_HWCAPS2];
  4230. out_attr = &out_attrs[Tag_GNU_Sparc_HWCAPS2];
  4231. out_attr->i |= in_attr->i;
  4232. out_attr->type = 1;
  4233. /* Merge Tag_compatibility attributes and any common GNU ones. */
  4234. _bfd_elf_merge_object_attributes (ibfd, obfd);
  4235. return TRUE;
  4236. }