elf32-i386.c 133 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688
  1. /* Intel 80386/80486-specific support for 32-bit ELF
  2. Copyright (C) 1993-2022 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. #include "elfxx-x86.h"
  17. #include "elf-vxworks.h"
  18. #include "dwarf2.h"
  19. #include "opcode/i386.h"
  20. /* 386 uses REL relocations instead of RELA. */
  21. #define USE_REL 1
  22. static reloc_howto_type elf_howto_table[]=
  23. {
  24. HOWTO(R_386_NONE, 0, 3, 0, false, 0, complain_overflow_dont,
  25. bfd_elf_generic_reloc, "R_386_NONE",
  26. true, 0x00000000, 0x00000000, false),
  27. HOWTO(R_386_32, 0, 2, 32, false, 0, complain_overflow_dont,
  28. bfd_elf_generic_reloc, "R_386_32",
  29. true, 0xffffffff, 0xffffffff, false),
  30. HOWTO(R_386_PC32, 0, 2, 32, true, 0, complain_overflow_dont,
  31. bfd_elf_generic_reloc, "R_386_PC32",
  32. true, 0xffffffff, 0xffffffff, true),
  33. HOWTO(R_386_GOT32, 0, 2, 32, false, 0, complain_overflow_dont,
  34. bfd_elf_generic_reloc, "R_386_GOT32",
  35. true, 0xffffffff, 0xffffffff, false),
  36. HOWTO(R_386_PLT32, 0, 2, 32, true, 0, complain_overflow_dont,
  37. bfd_elf_generic_reloc, "R_386_PLT32",
  38. true, 0xffffffff, 0xffffffff, true),
  39. HOWTO(R_386_COPY, 0, 2, 32, false, 0, complain_overflow_dont,
  40. bfd_elf_generic_reloc, "R_386_COPY",
  41. true, 0xffffffff, 0xffffffff, false),
  42. HOWTO(R_386_GLOB_DAT, 0, 2, 32, false, 0, complain_overflow_dont,
  43. bfd_elf_generic_reloc, "R_386_GLOB_DAT",
  44. true, 0xffffffff, 0xffffffff, false),
  45. HOWTO(R_386_JUMP_SLOT, 0, 2, 32, false, 0, complain_overflow_dont,
  46. bfd_elf_generic_reloc, "R_386_JUMP_SLOT",
  47. true, 0xffffffff, 0xffffffff, false),
  48. HOWTO(R_386_RELATIVE, 0, 2, 32, false, 0, complain_overflow_dont,
  49. bfd_elf_generic_reloc, "R_386_RELATIVE",
  50. true, 0xffffffff, 0xffffffff, false),
  51. HOWTO(R_386_GOTOFF, 0, 2, 32, false, 0, complain_overflow_dont,
  52. bfd_elf_generic_reloc, "R_386_GOTOFF",
  53. true, 0xffffffff, 0xffffffff, false),
  54. HOWTO(R_386_GOTPC, 0, 2, 32, true, 0, complain_overflow_dont,
  55. bfd_elf_generic_reloc, "R_386_GOTPC",
  56. true, 0xffffffff, 0xffffffff, true),
  57. /* We have a gap in the reloc numbers here.
  58. R_386_standard counts the number up to this point, and
  59. R_386_ext_offset is the value to subtract from a reloc type of
  60. R_386_16 thru R_386_PC8 to form an index into this table. */
  61. #define R_386_standard (R_386_GOTPC + 1)
  62. #define R_386_ext_offset (R_386_TLS_TPOFF - R_386_standard)
  63. /* These relocs are a GNU extension. */
  64. HOWTO(R_386_TLS_TPOFF, 0, 2, 32, false, 0, complain_overflow_dont,
  65. bfd_elf_generic_reloc, "R_386_TLS_TPOFF",
  66. true, 0xffffffff, 0xffffffff, false),
  67. HOWTO(R_386_TLS_IE, 0, 2, 32, false, 0, complain_overflow_dont,
  68. bfd_elf_generic_reloc, "R_386_TLS_IE",
  69. true, 0xffffffff, 0xffffffff, false),
  70. HOWTO(R_386_TLS_GOTIE, 0, 2, 32, false, 0, complain_overflow_dont,
  71. bfd_elf_generic_reloc, "R_386_TLS_GOTIE",
  72. true, 0xffffffff, 0xffffffff, false),
  73. HOWTO(R_386_TLS_LE, 0, 2, 32, false, 0, complain_overflow_dont,
  74. bfd_elf_generic_reloc, "R_386_TLS_LE",
  75. true, 0xffffffff, 0xffffffff, false),
  76. HOWTO(R_386_TLS_GD, 0, 2, 32, false, 0, complain_overflow_dont,
  77. bfd_elf_generic_reloc, "R_386_TLS_GD",
  78. true, 0xffffffff, 0xffffffff, false),
  79. HOWTO(R_386_TLS_LDM, 0, 2, 32, false, 0, complain_overflow_dont,
  80. bfd_elf_generic_reloc, "R_386_TLS_LDM",
  81. true, 0xffffffff, 0xffffffff, false),
  82. HOWTO(R_386_16, 0, 1, 16, false, 0, complain_overflow_bitfield,
  83. bfd_elf_generic_reloc, "R_386_16",
  84. true, 0xffff, 0xffff, false),
  85. HOWTO(R_386_PC16, 0, 1, 16, true, 0, complain_overflow_bitfield,
  86. bfd_elf_generic_reloc, "R_386_PC16",
  87. true, 0xffff, 0xffff, true),
  88. HOWTO(R_386_8, 0, 0, 8, false, 0, complain_overflow_bitfield,
  89. bfd_elf_generic_reloc, "R_386_8",
  90. true, 0xff, 0xff, false),
  91. HOWTO(R_386_PC8, 0, 0, 8, true, 0, complain_overflow_signed,
  92. bfd_elf_generic_reloc, "R_386_PC8",
  93. true, 0xff, 0xff, true),
  94. #define R_386_ext (R_386_PC8 + 1 - R_386_ext_offset)
  95. #define R_386_tls_offset (R_386_TLS_LDO_32 - R_386_ext)
  96. /* These are common with Solaris TLS implementation. */
  97. HOWTO(R_386_TLS_LDO_32, 0, 2, 32, false, 0, complain_overflow_dont,
  98. bfd_elf_generic_reloc, "R_386_TLS_LDO_32",
  99. true, 0xffffffff, 0xffffffff, false),
  100. HOWTO(R_386_TLS_IE_32, 0, 2, 32, false, 0, complain_overflow_dont,
  101. bfd_elf_generic_reloc, "R_386_TLS_IE_32",
  102. true, 0xffffffff, 0xffffffff, false),
  103. HOWTO(R_386_TLS_LE_32, 0, 2, 32, false, 0, complain_overflow_dont,
  104. bfd_elf_generic_reloc, "R_386_TLS_LE_32",
  105. true, 0xffffffff, 0xffffffff, false),
  106. HOWTO(R_386_TLS_DTPMOD32, 0, 2, 32, false, 0, complain_overflow_dont,
  107. bfd_elf_generic_reloc, "R_386_TLS_DTPMOD32",
  108. true, 0xffffffff, 0xffffffff, false),
  109. HOWTO(R_386_TLS_DTPOFF32, 0, 2, 32, false, 0, complain_overflow_dont,
  110. bfd_elf_generic_reloc, "R_386_TLS_DTPOFF32",
  111. true, 0xffffffff, 0xffffffff, false),
  112. HOWTO(R_386_TLS_TPOFF32, 0, 2, 32, false, 0, complain_overflow_dont,
  113. bfd_elf_generic_reloc, "R_386_TLS_TPOFF32",
  114. true, 0xffffffff, 0xffffffff, false),
  115. HOWTO(R_386_SIZE32, 0, 2, 32, false, 0, complain_overflow_dont,
  116. bfd_elf_generic_reloc, "R_386_SIZE32",
  117. true, 0xffffffff, 0xffffffff, false),
  118. HOWTO(R_386_TLS_GOTDESC, 0, 2, 32, false, 0, complain_overflow_dont,
  119. bfd_elf_generic_reloc, "R_386_TLS_GOTDESC",
  120. true, 0xffffffff, 0xffffffff, false),
  121. HOWTO(R_386_TLS_DESC_CALL, 0, 3, 0, false, 0, complain_overflow_dont,
  122. bfd_elf_generic_reloc, "R_386_TLS_DESC_CALL",
  123. false, 0, 0, false),
  124. HOWTO(R_386_TLS_DESC, 0, 2, 32, false, 0, complain_overflow_dont,
  125. bfd_elf_generic_reloc, "R_386_TLS_DESC",
  126. true, 0xffffffff, 0xffffffff, false),
  127. HOWTO(R_386_IRELATIVE, 0, 2, 32, false, 0, complain_overflow_dont,
  128. bfd_elf_generic_reloc, "R_386_IRELATIVE",
  129. true, 0xffffffff, 0xffffffff, false),
  130. HOWTO(R_386_GOT32X, 0, 2, 32, false, 0, complain_overflow_dont,
  131. bfd_elf_generic_reloc, "R_386_GOT32X",
  132. true, 0xffffffff, 0xffffffff, false),
  133. /* Another gap. */
  134. #define R_386_ext2 (R_386_GOT32X + 1 - R_386_tls_offset)
  135. #define R_386_vt_offset (R_386_GNU_VTINHERIT - R_386_ext2)
  136. /* GNU extension to record C++ vtable hierarchy. */
  137. HOWTO (R_386_GNU_VTINHERIT, /* type */
  138. 0, /* rightshift */
  139. 2, /* size (0 = byte, 1 = short, 2 = long) */
  140. 0, /* bitsize */
  141. false, /* pc_relative */
  142. 0, /* bitpos */
  143. complain_overflow_dont, /* complain_on_overflow */
  144. NULL, /* special_function */
  145. "R_386_GNU_VTINHERIT", /* name */
  146. false, /* partial_inplace */
  147. 0, /* src_mask */
  148. 0, /* dst_mask */
  149. false), /* pcrel_offset */
  150. /* GNU extension to record C++ vtable member usage. */
  151. HOWTO (R_386_GNU_VTENTRY, /* type */
  152. 0, /* rightshift */
  153. 2, /* size (0 = byte, 1 = short, 2 = long) */
  154. 0, /* bitsize */
  155. false, /* pc_relative */
  156. 0, /* bitpos */
  157. complain_overflow_dont, /* complain_on_overflow */
  158. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  159. "R_386_GNU_VTENTRY", /* name */
  160. false, /* partial_inplace */
  161. 0, /* src_mask */
  162. 0, /* dst_mask */
  163. false) /* pcrel_offset */
  164. #define R_386_vt (R_386_GNU_VTENTRY + 1 - R_386_vt_offset)
  165. };
  166. #ifdef DEBUG_GEN_RELOC
  167. #define TRACE(str) \
  168. fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
  169. #else
  170. #define TRACE(str)
  171. #endif
  172. static reloc_howto_type *
  173. elf_i386_reloc_type_lookup (bfd *abfd,
  174. bfd_reloc_code_real_type code)
  175. {
  176. switch (code)
  177. {
  178. case BFD_RELOC_NONE:
  179. TRACE ("BFD_RELOC_NONE");
  180. return &elf_howto_table[R_386_NONE];
  181. case BFD_RELOC_32:
  182. TRACE ("BFD_RELOC_32");
  183. return &elf_howto_table[R_386_32];
  184. case BFD_RELOC_CTOR:
  185. TRACE ("BFD_RELOC_CTOR");
  186. return &elf_howto_table[R_386_32];
  187. case BFD_RELOC_32_PCREL:
  188. TRACE ("BFD_RELOC_PC32");
  189. return &elf_howto_table[R_386_PC32];
  190. case BFD_RELOC_386_GOT32:
  191. TRACE ("BFD_RELOC_386_GOT32");
  192. return &elf_howto_table[R_386_GOT32];
  193. case BFD_RELOC_386_PLT32:
  194. TRACE ("BFD_RELOC_386_PLT32");
  195. return &elf_howto_table[R_386_PLT32];
  196. case BFD_RELOC_386_COPY:
  197. TRACE ("BFD_RELOC_386_COPY");
  198. return &elf_howto_table[R_386_COPY];
  199. case BFD_RELOC_386_GLOB_DAT:
  200. TRACE ("BFD_RELOC_386_GLOB_DAT");
  201. return &elf_howto_table[R_386_GLOB_DAT];
  202. case BFD_RELOC_386_JUMP_SLOT:
  203. TRACE ("BFD_RELOC_386_JUMP_SLOT");
  204. return &elf_howto_table[R_386_JUMP_SLOT];
  205. case BFD_RELOC_386_RELATIVE:
  206. TRACE ("BFD_RELOC_386_RELATIVE");
  207. return &elf_howto_table[R_386_RELATIVE];
  208. case BFD_RELOC_386_GOTOFF:
  209. TRACE ("BFD_RELOC_386_GOTOFF");
  210. return &elf_howto_table[R_386_GOTOFF];
  211. case BFD_RELOC_386_GOTPC:
  212. TRACE ("BFD_RELOC_386_GOTPC");
  213. return &elf_howto_table[R_386_GOTPC];
  214. /* These relocs are a GNU extension. */
  215. case BFD_RELOC_386_TLS_TPOFF:
  216. TRACE ("BFD_RELOC_386_TLS_TPOFF");
  217. return &elf_howto_table[R_386_TLS_TPOFF - R_386_ext_offset];
  218. case BFD_RELOC_386_TLS_IE:
  219. TRACE ("BFD_RELOC_386_TLS_IE");
  220. return &elf_howto_table[R_386_TLS_IE - R_386_ext_offset];
  221. case BFD_RELOC_386_TLS_GOTIE:
  222. TRACE ("BFD_RELOC_386_TLS_GOTIE");
  223. return &elf_howto_table[R_386_TLS_GOTIE - R_386_ext_offset];
  224. case BFD_RELOC_386_TLS_LE:
  225. TRACE ("BFD_RELOC_386_TLS_LE");
  226. return &elf_howto_table[R_386_TLS_LE - R_386_ext_offset];
  227. case BFD_RELOC_386_TLS_GD:
  228. TRACE ("BFD_RELOC_386_TLS_GD");
  229. return &elf_howto_table[R_386_TLS_GD - R_386_ext_offset];
  230. case BFD_RELOC_386_TLS_LDM:
  231. TRACE ("BFD_RELOC_386_TLS_LDM");
  232. return &elf_howto_table[R_386_TLS_LDM - R_386_ext_offset];
  233. case BFD_RELOC_16:
  234. TRACE ("BFD_RELOC_16");
  235. return &elf_howto_table[R_386_16 - R_386_ext_offset];
  236. case BFD_RELOC_16_PCREL:
  237. TRACE ("BFD_RELOC_16_PCREL");
  238. return &elf_howto_table[R_386_PC16 - R_386_ext_offset];
  239. case BFD_RELOC_8:
  240. TRACE ("BFD_RELOC_8");
  241. return &elf_howto_table[R_386_8 - R_386_ext_offset];
  242. case BFD_RELOC_8_PCREL:
  243. TRACE ("BFD_RELOC_8_PCREL");
  244. return &elf_howto_table[R_386_PC8 - R_386_ext_offset];
  245. /* Common with Sun TLS implementation. */
  246. case BFD_RELOC_386_TLS_LDO_32:
  247. TRACE ("BFD_RELOC_386_TLS_LDO_32");
  248. return &elf_howto_table[R_386_TLS_LDO_32 - R_386_tls_offset];
  249. case BFD_RELOC_386_TLS_IE_32:
  250. TRACE ("BFD_RELOC_386_TLS_IE_32");
  251. return &elf_howto_table[R_386_TLS_IE_32 - R_386_tls_offset];
  252. case BFD_RELOC_386_TLS_LE_32:
  253. TRACE ("BFD_RELOC_386_TLS_LE_32");
  254. return &elf_howto_table[R_386_TLS_LE_32 - R_386_tls_offset];
  255. case BFD_RELOC_386_TLS_DTPMOD32:
  256. TRACE ("BFD_RELOC_386_TLS_DTPMOD32");
  257. return &elf_howto_table[R_386_TLS_DTPMOD32 - R_386_tls_offset];
  258. case BFD_RELOC_386_TLS_DTPOFF32:
  259. TRACE ("BFD_RELOC_386_TLS_DTPOFF32");
  260. return &elf_howto_table[R_386_TLS_DTPOFF32 - R_386_tls_offset];
  261. case BFD_RELOC_386_TLS_TPOFF32:
  262. TRACE ("BFD_RELOC_386_TLS_TPOFF32");
  263. return &elf_howto_table[R_386_TLS_TPOFF32 - R_386_tls_offset];
  264. case BFD_RELOC_SIZE32:
  265. TRACE ("BFD_RELOC_SIZE32");
  266. return &elf_howto_table[R_386_SIZE32 - R_386_tls_offset];
  267. case BFD_RELOC_386_TLS_GOTDESC:
  268. TRACE ("BFD_RELOC_386_TLS_GOTDESC");
  269. return &elf_howto_table[R_386_TLS_GOTDESC - R_386_tls_offset];
  270. case BFD_RELOC_386_TLS_DESC_CALL:
  271. TRACE ("BFD_RELOC_386_TLS_DESC_CALL");
  272. return &elf_howto_table[R_386_TLS_DESC_CALL - R_386_tls_offset];
  273. case BFD_RELOC_386_TLS_DESC:
  274. TRACE ("BFD_RELOC_386_TLS_DESC");
  275. return &elf_howto_table[R_386_TLS_DESC - R_386_tls_offset];
  276. case BFD_RELOC_386_IRELATIVE:
  277. TRACE ("BFD_RELOC_386_IRELATIVE");
  278. return &elf_howto_table[R_386_IRELATIVE - R_386_tls_offset];
  279. case BFD_RELOC_386_GOT32X:
  280. TRACE ("BFD_RELOC_386_GOT32X");
  281. return &elf_howto_table[R_386_GOT32X - R_386_tls_offset];
  282. case BFD_RELOC_VTABLE_INHERIT:
  283. TRACE ("BFD_RELOC_VTABLE_INHERIT");
  284. return &elf_howto_table[R_386_GNU_VTINHERIT - R_386_vt_offset];
  285. case BFD_RELOC_VTABLE_ENTRY:
  286. TRACE ("BFD_RELOC_VTABLE_ENTRY");
  287. return &elf_howto_table[R_386_GNU_VTENTRY - R_386_vt_offset];
  288. default:
  289. TRACE ("Unknown");
  290. /* xgettext:c-format */
  291. _bfd_error_handler (_("%pB: unsupported relocation type: %#x"),
  292. abfd, (int) code);
  293. bfd_set_error (bfd_error_bad_value);
  294. return NULL;
  295. }
  296. }
  297. static reloc_howto_type *
  298. elf_i386_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  299. const char *r_name)
  300. {
  301. unsigned int i;
  302. for (i = 0; i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]); i++)
  303. if (elf_howto_table[i].name != NULL
  304. && strcasecmp (elf_howto_table[i].name, r_name) == 0)
  305. return &elf_howto_table[i];
  306. return NULL;
  307. }
  308. static reloc_howto_type *
  309. elf_i386_rtype_to_howto (unsigned r_type)
  310. {
  311. unsigned int indx;
  312. if ((indx = r_type) >= R_386_standard
  313. && ((indx = r_type - R_386_ext_offset) - R_386_standard
  314. >= R_386_ext - R_386_standard)
  315. && ((indx = r_type - R_386_tls_offset) - R_386_ext
  316. >= R_386_ext2 - R_386_ext)
  317. && ((indx = r_type - R_386_vt_offset) - R_386_ext2
  318. >= R_386_vt - R_386_ext2))
  319. return NULL;
  320. /* PR 17512: file: 0f67f69d. */
  321. if (elf_howto_table [indx].type != r_type)
  322. return NULL;
  323. return &elf_howto_table[indx];
  324. }
  325. static bool
  326. elf_i386_info_to_howto_rel (bfd *abfd,
  327. arelent *cache_ptr,
  328. Elf_Internal_Rela *dst)
  329. {
  330. unsigned int r_type = ELF32_R_TYPE (dst->r_info);
  331. if ((cache_ptr->howto = elf_i386_rtype_to_howto (r_type)) == NULL)
  332. {
  333. /* xgettext:c-format */
  334. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  335. abfd, r_type);
  336. bfd_set_error (bfd_error_bad_value);
  337. return false;
  338. }
  339. return true;
  340. }
  341. /* Return whether a symbol name implies a local label. The UnixWare
  342. 2.1 cc generates temporary symbols that start with .X, so we
  343. recognize them here. FIXME: do other SVR4 compilers also use .X?.
  344. If so, we should move the .X recognition into
  345. _bfd_elf_is_local_label_name. */
  346. static bool
  347. elf_i386_is_local_label_name (bfd *abfd, const char *name)
  348. {
  349. if (name[0] == '.' && name[1] == 'X')
  350. return true;
  351. return _bfd_elf_is_local_label_name (abfd, name);
  352. }
  353. /* Support for core dump NOTE sections. */
  354. static bool
  355. elf_i386_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
  356. {
  357. int offset;
  358. size_t size;
  359. if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
  360. {
  361. int pr_version = bfd_get_32 (abfd, note->descdata);
  362. if (pr_version != 1)
  363. return false;
  364. /* pr_cursig */
  365. elf_tdata (abfd)->core->signal = bfd_get_32 (abfd, note->descdata + 20);
  366. /* pr_pid */
  367. elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
  368. /* pr_reg */
  369. offset = 28;
  370. size = bfd_get_32 (abfd, note->descdata + 8);
  371. }
  372. else
  373. {
  374. switch (note->descsz)
  375. {
  376. default:
  377. return false;
  378. case 144: /* Linux/i386 */
  379. /* pr_cursig */
  380. elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
  381. /* pr_pid */
  382. elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
  383. /* pr_reg */
  384. offset = 72;
  385. size = 68;
  386. break;
  387. }
  388. }
  389. /* Make a ".reg/999" section. */
  390. return _bfd_elfcore_make_pseudosection (abfd, ".reg",
  391. size, note->descpos + offset);
  392. }
  393. static bool
  394. elf_i386_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
  395. {
  396. if (note->namesz == 8 && strcmp (note->namedata, "FreeBSD") == 0)
  397. {
  398. int pr_version = bfd_get_32 (abfd, note->descdata);
  399. if (pr_version != 1)
  400. return false;
  401. elf_tdata (abfd)->core->program
  402. = _bfd_elfcore_strndup (abfd, note->descdata + 8, 17);
  403. elf_tdata (abfd)->core->command
  404. = _bfd_elfcore_strndup (abfd, note->descdata + 25, 81);
  405. }
  406. else
  407. {
  408. switch (note->descsz)
  409. {
  410. default:
  411. return false;
  412. case 124: /* Linux/i386 elf_prpsinfo. */
  413. elf_tdata (abfd)->core->pid
  414. = bfd_get_32 (abfd, note->descdata + 12);
  415. elf_tdata (abfd)->core->program
  416. = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
  417. elf_tdata (abfd)->core->command
  418. = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
  419. }
  420. }
  421. /* Note that for some reason, a spurious space is tacked
  422. onto the end of the args in some (at least one anyway)
  423. implementations, so strip it off if it exists. */
  424. {
  425. char *command = elf_tdata (abfd)->core->command;
  426. int n = strlen (command);
  427. if (0 < n && command[n - 1] == ' ')
  428. command[n - 1] = '\0';
  429. }
  430. return true;
  431. }
  432. /* Functions for the i386 ELF linker.
  433. In order to gain some understanding of code in this file without
  434. knowing all the intricate details of the linker, note the
  435. following:
  436. Functions named elf_i386_* are called by external routines, other
  437. functions are only called locally. elf_i386_* functions appear
  438. in this file more or less in the order in which they are called
  439. from external routines. eg. elf_i386_scan_relocs is called
  440. early in the link process, elf_i386_finish_dynamic_sections is
  441. one of the last functions. */
  442. /* The size in bytes of an entry in the lazy procedure linkage table. */
  443. #define LAZY_PLT_ENTRY_SIZE 16
  444. /* The size in bytes of an entry in the non-lazy procedure linkage
  445. table. */
  446. #define NON_LAZY_PLT_ENTRY_SIZE 8
  447. /* The first entry in an absolute lazy procedure linkage table looks
  448. like this. See the SVR4 ABI i386 supplement to see how this works.
  449. Will be padded to LAZY_PLT_ENTRY_SIZE with lazy_plt->plt0_pad_byte. */
  450. static const bfd_byte elf_i386_lazy_plt0_entry[12] =
  451. {
  452. 0xff, 0x35, /* pushl contents of address */
  453. 0, 0, 0, 0, /* replaced with address of .got + 4. */
  454. 0xff, 0x25, /* jmp indirect */
  455. 0, 0, 0, 0 /* replaced with address of .got + 8. */
  456. };
  457. /* Subsequent entries in an absolute lazy procedure linkage table look
  458. like this. */
  459. static const bfd_byte elf_i386_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] =
  460. {
  461. 0xff, 0x25, /* jmp indirect */
  462. 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
  463. 0x68, /* pushl immediate */
  464. 0, 0, 0, 0, /* replaced with offset into relocation table. */
  465. 0xe9, /* jmp relative */
  466. 0, 0, 0, 0 /* replaced with offset to start of .plt. */
  467. };
  468. /* The first entry in a PIC lazy procedure linkage table look like
  469. this. Will be padded to LAZY_PLT_ENTRY_SIZE with
  470. lazy_plt->plt0_pad_byte. */
  471. static const bfd_byte elf_i386_pic_lazy_plt0_entry[12] =
  472. {
  473. 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
  474. 0xff, 0xa3, 8, 0, 0, 0 /* jmp *8(%ebx) */
  475. };
  476. /* Subsequent entries in a PIC lazy procedure linkage table look like
  477. this. */
  478. static const bfd_byte elf_i386_pic_lazy_plt_entry[LAZY_PLT_ENTRY_SIZE] =
  479. {
  480. 0xff, 0xa3, /* jmp *offset(%ebx) */
  481. 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
  482. 0x68, /* pushl immediate */
  483. 0, 0, 0, 0, /* replaced with offset into relocation table. */
  484. 0xe9, /* jmp relative */
  485. 0, 0, 0, 0 /* replaced with offset to start of .plt. */
  486. };
  487. /* Entries in the non-lazy procedure linkage table look like this. */
  488. static const bfd_byte elf_i386_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
  489. {
  490. 0xff, 0x25, /* jmp indirect */
  491. 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
  492. 0x66, 0x90 /* xchg %ax,%ax */
  493. };
  494. /* Entries in the PIC non-lazy procedure linkage table look like
  495. this. */
  496. static const bfd_byte elf_i386_pic_non_lazy_plt_entry[NON_LAZY_PLT_ENTRY_SIZE] =
  497. {
  498. 0xff, 0xa3, /* jmp *offset(%ebx) */
  499. 0, 0, 0, 0, /* replaced with offset of this symbol in .got. */
  500. 0x66, 0x90 /* xchg %ax,%ax */
  501. };
  502. /* The first entry in an absolute IBT-enabled lazy procedure linkage
  503. table looks like this. */
  504. static const bfd_byte elf_i386_lazy_ibt_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
  505. {
  506. 0xff, 0x35, 0, 0, 0, 0, /* pushl GOT[1] */
  507. 0xff, 0x25, 0, 0, 0, 0, /* jmp *GOT[2] */
  508. 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
  509. };
  510. /* Subsequent entries for an absolute IBT-enabled lazy procedure linkage
  511. table look like this. Subsequent entries for a PIC IBT-enabled lazy
  512. procedure linkage table are the same. */
  513. static const bfd_byte elf_i386_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
  514. {
  515. 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
  516. 0x68, 0, 0, 0, 0, /* pushl immediate */
  517. 0xe9, 0, 0, 0, 0, /* jmp relative */
  518. 0x66, 0x90 /* xchg %ax,%ax */
  519. };
  520. /* The first entry in a PIC IBT-enabled lazy procedure linkage table
  521. look like. */
  522. static const bfd_byte elf_i386_pic_lazy_ibt_plt0_entry[LAZY_PLT_ENTRY_SIZE] =
  523. {
  524. 0xff, 0xb3, 4, 0, 0, 0, /* pushl 4(%ebx) */
  525. 0xff, 0xa3, 8, 0, 0, 0, /* jmp *8(%ebx) */
  526. 0x0f, 0x1f, 0x40, 0x00 /* nopl 0(%rax) */
  527. };
  528. /* Entries for branches with IBT-enabled in the absolute non-lazey
  529. procedure linkage table look like this. They have the same size
  530. as the lazy PLT entry. */
  531. static const bfd_byte elf_i386_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
  532. {
  533. 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
  534. 0xff, 0x25, 0, 0, 0, 0, /* jmp *name@GOT */
  535. 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
  536. };
  537. /* Entries for branches with IBT-enabled in the PIC non-lazey procedure
  538. linkage table look like this. They have the same size as the lazy
  539. PLT entry. */
  540. static const bfd_byte elf_i386_pic_non_lazy_ibt_plt_entry[LAZY_PLT_ENTRY_SIZE] =
  541. {
  542. 0xf3, 0x0f, 0x1e, 0xfb, /* endbr32 */
  543. 0xff, 0xa3, 0, 0, 0, 0, /* jmp *name@GOT(%ebx) */
  544. 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00 /* nopw 0x0(%rax,%rax,1) */
  545. };
  546. /* .eh_frame covering the lazy .plt section. */
  547. static const bfd_byte elf_i386_eh_frame_lazy_plt[] =
  548. {
  549. PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
  550. 0, 0, 0, 0, /* CIE ID */
  551. 1, /* CIE version */
  552. 'z', 'R', 0, /* Augmentation string */
  553. 1, /* Code alignment factor */
  554. 0x7c, /* Data alignment factor */
  555. 8, /* Return address column */
  556. 1, /* Augmentation size */
  557. DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
  558. DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
  559. DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
  560. DW_CFA_nop, DW_CFA_nop,
  561. PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
  562. PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
  563. 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
  564. 0, 0, 0, 0, /* .plt size goes here */
  565. 0, /* Augmentation size */
  566. DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
  567. DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
  568. DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
  569. DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
  570. DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
  571. 11, /* Block length */
  572. DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
  573. DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
  574. DW_OP_lit15, DW_OP_and, DW_OP_lit11, DW_OP_ge,
  575. DW_OP_lit2, DW_OP_shl, DW_OP_plus,
  576. DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
  577. };
  578. /* .eh_frame covering the lazy .plt section with IBT-enabled. */
  579. static const bfd_byte elf_i386_eh_frame_lazy_ibt_plt[] =
  580. {
  581. PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
  582. 0, 0, 0, 0, /* CIE ID */
  583. 1, /* CIE version */
  584. 'z', 'R', 0, /* Augmentation string */
  585. 1, /* Code alignment factor */
  586. 0x7c, /* Data alignment factor */
  587. 8, /* Return address column */
  588. 1, /* Augmentation size */
  589. DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
  590. DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
  591. DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
  592. DW_CFA_nop, DW_CFA_nop,
  593. PLT_FDE_LENGTH, 0, 0, 0, /* FDE length */
  594. PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
  595. 0, 0, 0, 0, /* R_386_PC32 .plt goes here */
  596. 0, 0, 0, 0, /* .plt size goes here */
  597. 0, /* Augmentation size */
  598. DW_CFA_def_cfa_offset, 8, /* DW_CFA_def_cfa_offset: 8 */
  599. DW_CFA_advance_loc + 6, /* DW_CFA_advance_loc: 6 to __PLT__+6 */
  600. DW_CFA_def_cfa_offset, 12, /* DW_CFA_def_cfa_offset: 12 */
  601. DW_CFA_advance_loc + 10, /* DW_CFA_advance_loc: 10 to __PLT__+16 */
  602. DW_CFA_def_cfa_expression, /* DW_CFA_def_cfa_expression */
  603. 11, /* Block length */
  604. DW_OP_breg4, 4, /* DW_OP_breg4 (esp): 4 */
  605. DW_OP_breg8, 0, /* DW_OP_breg8 (eip): 0 */
  606. DW_OP_lit15, DW_OP_and, DW_OP_lit9, DW_OP_ge,
  607. DW_OP_lit2, DW_OP_shl, DW_OP_plus,
  608. DW_CFA_nop, DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
  609. };
  610. /* .eh_frame covering the non-lazy .plt section. */
  611. static const bfd_byte elf_i386_eh_frame_non_lazy_plt[] =
  612. {
  613. #define PLT_GOT_FDE_LENGTH 16
  614. PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */
  615. 0, 0, 0, 0, /* CIE ID */
  616. 1, /* CIE version */
  617. 'z', 'R', 0, /* Augmentation string */
  618. 1, /* Code alignment factor */
  619. 0x7c, /* Data alignment factor */
  620. 8, /* Return address column */
  621. 1, /* Augmentation size */
  622. DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding */
  623. DW_CFA_def_cfa, 4, 4, /* DW_CFA_def_cfa: r4 (esp) ofs 4 */
  624. DW_CFA_offset + 8, 1, /* DW_CFA_offset: r8 (eip) at cfa-4 */
  625. DW_CFA_nop, DW_CFA_nop,
  626. PLT_GOT_FDE_LENGTH, 0, 0, 0, /* FDE length */
  627. PLT_CIE_LENGTH + 8, 0, 0, 0, /* CIE pointer */
  628. 0, 0, 0, 0, /* the start of non-lazy .plt goes here */
  629. 0, 0, 0, 0, /* non-lazy .plt size goes here */
  630. 0, /* Augmentation size */
  631. DW_CFA_nop, DW_CFA_nop, DW_CFA_nop
  632. };
  633. /* These are the standard parameters. */
  634. static const struct elf_x86_lazy_plt_layout elf_i386_lazy_plt =
  635. {
  636. elf_i386_lazy_plt0_entry, /* plt0_entry */
  637. sizeof (elf_i386_lazy_plt0_entry), /* plt0_entry_size */
  638. elf_i386_lazy_plt_entry, /* plt_entry */
  639. LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
  640. NULL, /* plt_tlsdesc_entry */
  641. 0, /* plt_tlsdesc_entry_size*/
  642. 0, /* plt_tlsdesc_got1_offset */
  643. 0, /* plt_tlsdesc_got2_offset */
  644. 0, /* plt_tlsdesc_got1_insn_end */
  645. 0, /* plt_tlsdesc_got2_insn_end */
  646. 2, /* plt0_got1_offset */
  647. 8, /* plt0_got2_offset */
  648. 0, /* plt0_got2_insn_end */
  649. 2, /* plt_got_offset */
  650. 7, /* plt_reloc_offset */
  651. 12, /* plt_plt_offset */
  652. 0, /* plt_got_insn_size */
  653. 0, /* plt_plt_insn_end */
  654. 6, /* plt_lazy_offset */
  655. elf_i386_pic_lazy_plt0_entry, /* pic_plt0_entry */
  656. elf_i386_pic_lazy_plt_entry, /* pic_plt_entry */
  657. elf_i386_eh_frame_lazy_plt, /* eh_frame_plt */
  658. sizeof (elf_i386_eh_frame_lazy_plt) /* eh_frame_plt_size */
  659. };
  660. static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_plt =
  661. {
  662. elf_i386_non_lazy_plt_entry, /* plt_entry */
  663. elf_i386_pic_non_lazy_plt_entry, /* pic_plt_entry */
  664. NON_LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
  665. 2, /* plt_got_offset */
  666. 0, /* plt_got_insn_size */
  667. elf_i386_eh_frame_non_lazy_plt, /* eh_frame_plt */
  668. sizeof (elf_i386_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
  669. };
  670. static const struct elf_x86_lazy_plt_layout elf_i386_lazy_ibt_plt =
  671. {
  672. elf_i386_lazy_ibt_plt0_entry, /* plt0_entry */
  673. sizeof (elf_i386_lazy_ibt_plt0_entry), /* plt0_entry_size */
  674. elf_i386_lazy_ibt_plt_entry, /* plt_entry */
  675. LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
  676. NULL, /* plt_tlsdesc_entry */
  677. 0, /* plt_tlsdesc_entry_size*/
  678. 0, /* plt_tlsdesc_got1_offset */
  679. 0, /* plt_tlsdesc_got2_offset */
  680. 0, /* plt_tlsdesc_got1_insn_end */
  681. 0, /* plt_tlsdesc_got2_insn_end */
  682. 2, /* plt0_got1_offset */
  683. 8, /* plt0_got2_offset */
  684. 0, /* plt0_got2_insn_end */
  685. 4+2, /* plt_got_offset */
  686. 4+1, /* plt_reloc_offset */
  687. 4+6, /* plt_plt_offset */
  688. 0, /* plt_got_insn_size */
  689. 0, /* plt_plt_insn_end */
  690. 0, /* plt_lazy_offset */
  691. elf_i386_pic_lazy_ibt_plt0_entry, /* pic_plt0_entry */
  692. elf_i386_lazy_ibt_plt_entry, /* pic_plt_entry */
  693. elf_i386_eh_frame_lazy_ibt_plt, /* eh_frame_plt */
  694. sizeof (elf_i386_eh_frame_lazy_ibt_plt) /* eh_frame_plt_size */
  695. };
  696. static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt =
  697. {
  698. elf_i386_non_lazy_ibt_plt_entry, /* plt_entry */
  699. elf_i386_pic_non_lazy_ibt_plt_entry,/* pic_plt_entry */
  700. LAZY_PLT_ENTRY_SIZE, /* plt_entry_size */
  701. 4+2, /* plt_got_offset */
  702. 0, /* plt_got_insn_size */
  703. elf_i386_eh_frame_non_lazy_plt, /* eh_frame_plt */
  704. sizeof (elf_i386_eh_frame_non_lazy_plt) /* eh_frame_plt_size */
  705. };
  706. /* On VxWorks, the .rel.plt.unloaded section has absolute relocations
  707. for the PLTResolve stub and then for each PLT entry. */
  708. #define PLTRESOLVE_RELOCS_SHLIB 0
  709. #define PLTRESOLVE_RELOCS 2
  710. #define PLT_NON_JUMP_SLOT_RELOCS 2
  711. /* Return TRUE if the TLS access code sequence support transition
  712. from R_TYPE. */
  713. static bool
  714. elf_i386_check_tls_transition (asection *sec,
  715. bfd_byte *contents,
  716. Elf_Internal_Shdr *symtab_hdr,
  717. struct elf_link_hash_entry **sym_hashes,
  718. unsigned int r_type,
  719. const Elf_Internal_Rela *rel,
  720. const Elf_Internal_Rela *relend)
  721. {
  722. unsigned int val, type, reg;
  723. unsigned long r_symndx;
  724. struct elf_link_hash_entry *h;
  725. bfd_vma offset;
  726. bfd_byte *call;
  727. bool indirect_call;
  728. offset = rel->r_offset;
  729. switch (r_type)
  730. {
  731. case R_386_TLS_GD:
  732. case R_386_TLS_LDM:
  733. if (offset < 2 || (rel + 1) >= relend)
  734. return false;
  735. indirect_call = false;
  736. call = contents + offset + 4;
  737. val = *(call - 5);
  738. type = *(call - 6);
  739. if (r_type == R_386_TLS_GD)
  740. {
  741. /* Check transition from GD access model. Only
  742. leal foo@tlsgd(,%ebx,1), %eax
  743. call ___tls_get_addr@PLT
  744. or
  745. leal foo@tlsgd(%ebx) %eax
  746. call ___tls_get_addr@PLT
  747. nop
  748. or
  749. leal foo@tlsgd(%reg), %eax
  750. call *___tls_get_addr@GOT(%reg)
  751. which may be converted to
  752. addr32 call ___tls_get_addr
  753. can transit to different access model. */
  754. if ((offset + 10) > sec->size
  755. || (type != 0x8d && type != 0x04))
  756. return false;
  757. if (type == 0x04)
  758. {
  759. /* leal foo@tlsgd(,%ebx,1), %eax
  760. call ___tls_get_addr@PLT */
  761. if (offset < 3)
  762. return false;
  763. if (*(call - 7) != 0x8d
  764. || val != 0x1d
  765. || call[0] != 0xe8)
  766. return false;
  767. }
  768. else
  769. {
  770. /* This must be
  771. leal foo@tlsgd(%ebx), %eax
  772. call ___tls_get_addr@PLT
  773. nop
  774. or
  775. leal foo@tlsgd(%reg), %eax
  776. call *___tls_get_addr@GOT(%reg)
  777. which may be converted to
  778. addr32 call ___tls_get_addr
  779. %eax can't be used as the GOT base register since it
  780. is used to pass parameter to ___tls_get_addr. */
  781. reg = val & 7;
  782. if ((val & 0xf8) != 0x80 || reg == 4 || reg == 0)
  783. return false;
  784. indirect_call = call[0] == 0xff;
  785. if (!(reg == 3 && call[0] == 0xe8 && call[5] == 0x90)
  786. && !(call[0] == 0x67 && call[1] == 0xe8)
  787. && !(indirect_call
  788. && (call[1] & 0xf8) == 0x90
  789. && (call[1] & 0x7) == reg))
  790. return false;
  791. }
  792. }
  793. else
  794. {
  795. /* Check transition from LD access model. Only
  796. leal foo@tlsldm(%ebx), %eax
  797. call ___tls_get_addr@PLT
  798. or
  799. leal foo@tlsldm(%reg), %eax
  800. call *___tls_get_addr@GOT(%reg)
  801. which may be converted to
  802. addr32 call ___tls_get_addr
  803. can transit to different access model. */
  804. if (type != 0x8d || (offset + 9) > sec->size)
  805. return false;
  806. /* %eax can't be used as the GOT base register since it is
  807. used to pass parameter to ___tls_get_addr. */
  808. reg = val & 7;
  809. if ((val & 0xf8) != 0x80 || reg == 4 || reg == 0)
  810. return false;
  811. indirect_call = call[0] == 0xff;
  812. if (!(reg == 3 && call[0] == 0xe8)
  813. && !(call[0] == 0x67 && call[1] == 0xe8)
  814. && !(indirect_call
  815. && (call[1] & 0xf8) == 0x90
  816. && (call[1] & 0x7) == reg))
  817. return false;
  818. }
  819. r_symndx = ELF32_R_SYM (rel[1].r_info);
  820. if (r_symndx < symtab_hdr->sh_info)
  821. return false;
  822. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  823. if (h == NULL
  824. || !((struct elf_x86_link_hash_entry *) h)->tls_get_addr)
  825. return false;
  826. else if (indirect_call)
  827. return (ELF32_R_TYPE (rel[1].r_info) == R_386_GOT32X);
  828. else
  829. return (ELF32_R_TYPE (rel[1].r_info) == R_386_PC32
  830. || ELF32_R_TYPE (rel[1].r_info) == R_386_PLT32);
  831. case R_386_TLS_IE:
  832. /* Check transition from IE access model:
  833. movl foo@indntpoff(%rip), %eax
  834. movl foo@indntpoff(%rip), %reg
  835. addl foo@indntpoff(%rip), %reg
  836. */
  837. if (offset < 1 || (offset + 4) > sec->size)
  838. return false;
  839. /* Check "movl foo@tpoff(%rip), %eax" first. */
  840. val = bfd_get_8 (abfd, contents + offset - 1);
  841. if (val == 0xa1)
  842. return true;
  843. if (offset < 2)
  844. return false;
  845. /* Check movl|addl foo@tpoff(%rip), %reg. */
  846. type = bfd_get_8 (abfd, contents + offset - 2);
  847. return ((type == 0x8b || type == 0x03)
  848. && (val & 0xc7) == 0x05);
  849. case R_386_TLS_GOTIE:
  850. case R_386_TLS_IE_32:
  851. /* Check transition from {IE_32,GOTIE} access model:
  852. subl foo@{tpoff,gontoff}(%reg1), %reg2
  853. movl foo@{tpoff,gontoff}(%reg1), %reg2
  854. addl foo@{tpoff,gontoff}(%reg1), %reg2
  855. */
  856. if (offset < 2 || (offset + 4) > sec->size)
  857. return false;
  858. val = bfd_get_8 (abfd, contents + offset - 1);
  859. if ((val & 0xc0) != 0x80 || (val & 7) == 4)
  860. return false;
  861. type = bfd_get_8 (abfd, contents + offset - 2);
  862. return type == 0x8b || type == 0x2b || type == 0x03;
  863. case R_386_TLS_GOTDESC:
  864. /* Check transition from GDesc access model:
  865. leal x@tlsdesc(%ebx), %eax
  866. Make sure it's a leal adding ebx to a 32-bit offset
  867. into any register, although it's probably almost always
  868. going to be eax. */
  869. if (offset < 2 || (offset + 4) > sec->size)
  870. return false;
  871. if (bfd_get_8 (abfd, contents + offset - 2) != 0x8d)
  872. return false;
  873. val = bfd_get_8 (abfd, contents + offset - 1);
  874. return (val & 0xc7) == 0x83;
  875. case R_386_TLS_DESC_CALL:
  876. /* Check transition from GDesc access model:
  877. call *x@tlsdesc(%eax)
  878. */
  879. if (offset + 2 <= sec->size)
  880. {
  881. /* Make sure that it's a call *x@tlsdesc(%eax). */
  882. call = contents + offset;
  883. return call[0] == 0xff && call[1] == 0x10;
  884. }
  885. return false;
  886. default:
  887. abort ();
  888. }
  889. }
  890. /* Return TRUE if the TLS access transition is OK or no transition
  891. will be performed. Update R_TYPE if there is a transition. */
  892. static bool
  893. elf_i386_tls_transition (struct bfd_link_info *info, bfd *abfd,
  894. asection *sec, bfd_byte *contents,
  895. Elf_Internal_Shdr *symtab_hdr,
  896. struct elf_link_hash_entry **sym_hashes,
  897. unsigned int *r_type, int tls_type,
  898. const Elf_Internal_Rela *rel,
  899. const Elf_Internal_Rela *relend,
  900. struct elf_link_hash_entry *h,
  901. unsigned long r_symndx,
  902. bool from_relocate_section)
  903. {
  904. unsigned int from_type = *r_type;
  905. unsigned int to_type = from_type;
  906. bool check = true;
  907. /* Skip TLS transition for functions. */
  908. if (h != NULL
  909. && (h->type == STT_FUNC
  910. || h->type == STT_GNU_IFUNC))
  911. return true;
  912. switch (from_type)
  913. {
  914. case R_386_TLS_GD:
  915. case R_386_TLS_GOTDESC:
  916. case R_386_TLS_DESC_CALL:
  917. case R_386_TLS_IE_32:
  918. case R_386_TLS_IE:
  919. case R_386_TLS_GOTIE:
  920. if (bfd_link_executable (info))
  921. {
  922. if (h == NULL)
  923. to_type = R_386_TLS_LE_32;
  924. else if (from_type != R_386_TLS_IE
  925. && from_type != R_386_TLS_GOTIE)
  926. to_type = R_386_TLS_IE_32;
  927. }
  928. /* When we are called from elf_i386_relocate_section, there may
  929. be additional transitions based on TLS_TYPE. */
  930. if (from_relocate_section)
  931. {
  932. unsigned int new_to_type = to_type;
  933. if (TLS_TRANSITION_IE_TO_LE_P (info, h, tls_type))
  934. new_to_type = R_386_TLS_LE_32;
  935. if (to_type == R_386_TLS_GD
  936. || to_type == R_386_TLS_GOTDESC
  937. || to_type == R_386_TLS_DESC_CALL)
  938. {
  939. if (tls_type == GOT_TLS_IE_POS)
  940. new_to_type = R_386_TLS_GOTIE;
  941. else if (tls_type & GOT_TLS_IE)
  942. new_to_type = R_386_TLS_IE_32;
  943. }
  944. /* We checked the transition before when we were called from
  945. elf_i386_scan_relocs. We only want to check the new
  946. transition which hasn't been checked before. */
  947. check = new_to_type != to_type && from_type == to_type;
  948. to_type = new_to_type;
  949. }
  950. break;
  951. case R_386_TLS_LDM:
  952. if (bfd_link_executable (info))
  953. to_type = R_386_TLS_LE_32;
  954. break;
  955. default:
  956. return true;
  957. }
  958. /* Return TRUE if there is no transition. */
  959. if (from_type == to_type)
  960. return true;
  961. /* Check if the transition can be performed. */
  962. if (check
  963. && ! elf_i386_check_tls_transition (sec, contents,
  964. symtab_hdr, sym_hashes,
  965. from_type, rel, relend))
  966. {
  967. reloc_howto_type *from, *to;
  968. const char *name;
  969. from = elf_i386_rtype_to_howto (from_type);
  970. to = elf_i386_rtype_to_howto (to_type);
  971. if (h)
  972. name = h->root.root.string;
  973. else
  974. {
  975. struct elf_x86_link_hash_table *htab;
  976. htab = elf_x86_hash_table (info, I386_ELF_DATA);
  977. if (htab == NULL)
  978. name = "*unknown*";
  979. else
  980. {
  981. Elf_Internal_Sym *isym;
  982. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
  983. abfd, r_symndx);
  984. name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
  985. }
  986. }
  987. _bfd_error_handler
  988. /* xgettext:c-format */
  989. (_("%pB: TLS transition from %s to %s against `%s'"
  990. " at %#" PRIx64 " in section `%pA' failed"),
  991. abfd, from->name, to->name, name,
  992. (uint64_t) rel->r_offset, sec);
  993. bfd_set_error (bfd_error_bad_value);
  994. return false;
  995. }
  996. *r_type = to_type;
  997. return true;
  998. }
  999. /* With the local symbol, foo, we convert
  1000. mov foo@GOT[(%reg1)], %reg2
  1001. to
  1002. lea foo[@GOTOFF(%reg1)], %reg2
  1003. and convert
  1004. call/jmp *foo@GOT[(%reg)]
  1005. to
  1006. nop call foo/jmp foo nop
  1007. When PIC is false, convert
  1008. test %reg1, foo@GOT[(%reg2)]
  1009. to
  1010. test $foo, %reg1
  1011. and convert
  1012. binop foo@GOT[(%reg1)], %reg2
  1013. to
  1014. binop $foo, %reg2
  1015. where binop is one of adc, add, and, cmp, or, sbb, sub, xor
  1016. instructions. */
  1017. static
  1018. bool
  1019. elf_i386_convert_load_reloc (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
  1020. bfd_byte *contents,
  1021. unsigned int *r_type_p,
  1022. Elf_Internal_Rela *irel,
  1023. struct elf_link_hash_entry *h,
  1024. bool *converted,
  1025. struct bfd_link_info *link_info)
  1026. {
  1027. struct elf_x86_link_hash_table *htab;
  1028. unsigned int opcode;
  1029. unsigned int modrm;
  1030. bool baseless;
  1031. Elf_Internal_Sym *isym;
  1032. unsigned int addend;
  1033. unsigned int nop;
  1034. bfd_vma nop_offset;
  1035. bool is_pic;
  1036. bool to_reloc_32;
  1037. bool abs_symbol;
  1038. unsigned int r_type;
  1039. unsigned int r_symndx;
  1040. bfd_vma roff = irel->r_offset;
  1041. bool local_ref;
  1042. struct elf_x86_link_hash_entry *eh;
  1043. if (roff < 2)
  1044. return true;
  1045. /* Addend for R_386_GOT32X relocations must be 0. */
  1046. addend = bfd_get_32 (abfd, contents + roff);
  1047. if (addend != 0)
  1048. return true;
  1049. htab = elf_x86_hash_table (link_info, I386_ELF_DATA);
  1050. is_pic = bfd_link_pic (link_info);
  1051. r_type = *r_type_p;
  1052. r_symndx = ELF32_R_SYM (irel->r_info);
  1053. modrm = bfd_get_8 (abfd, contents + roff - 1);
  1054. baseless = (modrm & 0xc7) == 0x5;
  1055. if (h)
  1056. {
  1057. /* NB: Also set linker_def via SYMBOL_REFERENCES_LOCAL_P. */
  1058. local_ref = SYMBOL_REFERENCES_LOCAL_P (link_info, h);
  1059. isym = NULL;
  1060. abs_symbol = ABS_SYMBOL_P (h);
  1061. }
  1062. else
  1063. {
  1064. local_ref = true;
  1065. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache, abfd,
  1066. r_symndx);
  1067. abs_symbol = isym->st_shndx == SHN_ABS;
  1068. }
  1069. if (baseless && is_pic)
  1070. {
  1071. /* For PIC, disallow R_386_GOT32X without a base register
  1072. since we don't know what the GOT base is. */
  1073. const char *name;
  1074. if (h == NULL)
  1075. name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
  1076. else
  1077. name = h->root.root.string;
  1078. _bfd_error_handler
  1079. /* xgettext:c-format */
  1080. (_("%pB: direct GOT relocation R_386_GOT32X against `%s' without base"
  1081. " register can not be used when making a shared object"),
  1082. abfd, name);
  1083. return false;
  1084. }
  1085. opcode = bfd_get_8 (abfd, contents + roff - 2);
  1086. /* Convert to R_386_32 if PIC is false or there is no base
  1087. register. */
  1088. to_reloc_32 = !is_pic || baseless;
  1089. eh = elf_x86_hash_entry (h);
  1090. /* Try to convert R_386_GOT32X. Get the symbol referred to by the
  1091. reloc. */
  1092. if (h == NULL)
  1093. {
  1094. if (opcode == 0x0ff)
  1095. /* Convert "call/jmp *foo@GOT[(%reg)]". */
  1096. goto convert_branch;
  1097. else
  1098. /* Convert "mov foo@GOT[(%reg1)], %reg2",
  1099. "test %reg1, foo@GOT(%reg2)" and
  1100. "binop foo@GOT[(%reg1)], %reg2". */
  1101. goto convert_load;
  1102. }
  1103. /* Undefined weak symbol is only bound locally in executable
  1104. and its reference is resolved as 0. */
  1105. if (h->root.type == bfd_link_hash_undefweak
  1106. && !eh->linker_def
  1107. && local_ref)
  1108. {
  1109. if (opcode == 0xff)
  1110. {
  1111. /* No direct branch to 0 for PIC. */
  1112. if (is_pic)
  1113. return true;
  1114. else
  1115. goto convert_branch;
  1116. }
  1117. else
  1118. {
  1119. /* We can convert load of address 0 to R_386_32. */
  1120. to_reloc_32 = true;
  1121. goto convert_load;
  1122. }
  1123. }
  1124. if (opcode == 0xff)
  1125. {
  1126. /* We have "call/jmp *foo@GOT[(%reg)]". */
  1127. if ((h->root.type == bfd_link_hash_defined
  1128. || h->root.type == bfd_link_hash_defweak)
  1129. && local_ref)
  1130. {
  1131. /* The function is locally defined. */
  1132. convert_branch:
  1133. /* Convert R_386_GOT32X to R_386_PC32. */
  1134. if (modrm == 0x15 || (modrm & 0xf8) == 0x90)
  1135. {
  1136. /* Convert to "nop call foo". ADDR_PREFIX_OPCODE
  1137. is a nop prefix. */
  1138. modrm = 0xe8;
  1139. /* To support TLS optimization, always use addr32 prefix
  1140. for "call *___tls_get_addr@GOT(%reg)". */
  1141. if (eh && eh->tls_get_addr)
  1142. {
  1143. nop = 0x67;
  1144. nop_offset = irel->r_offset - 2;
  1145. }
  1146. else
  1147. {
  1148. nop = htab->params->call_nop_byte;
  1149. if (htab->params->call_nop_as_suffix)
  1150. {
  1151. nop_offset = roff + 3;
  1152. irel->r_offset -= 1;
  1153. }
  1154. else
  1155. nop_offset = roff - 2;
  1156. }
  1157. }
  1158. else
  1159. {
  1160. /* Convert to "jmp foo nop". */
  1161. modrm = 0xe9;
  1162. nop = NOP_OPCODE;
  1163. nop_offset = roff + 3;
  1164. irel->r_offset -= 1;
  1165. }
  1166. bfd_put_8 (abfd, nop, contents + nop_offset);
  1167. bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1);
  1168. /* When converting to PC-relative relocation, we
  1169. need to adjust addend by -4. */
  1170. bfd_put_32 (abfd, -4, contents + irel->r_offset);
  1171. irel->r_info = ELF32_R_INFO (r_symndx, R_386_PC32);
  1172. *r_type_p = R_386_PC32;
  1173. *converted = true;
  1174. }
  1175. }
  1176. else
  1177. {
  1178. /* We have "mov foo@GOT[(%re1g)], %reg2",
  1179. "test %reg1, foo@GOT(%reg2)" and
  1180. "binop foo@GOT[(%reg1)], %reg2".
  1181. Avoid optimizing _DYNAMIC since ld.so may use its
  1182. link-time address. */
  1183. if (h == htab->elf.hdynamic)
  1184. return true;
  1185. /* def_regular is set by an assignment in a linker script in
  1186. bfd_elf_record_link_assignment. start_stop is set on
  1187. __start_SECNAME/__stop_SECNAME which mark section SECNAME. */
  1188. if (h->start_stop
  1189. || eh->linker_def
  1190. || ((h->def_regular
  1191. || h->root.type == bfd_link_hash_defined
  1192. || h->root.type == bfd_link_hash_defweak)
  1193. && local_ref))
  1194. {
  1195. convert_load:
  1196. if (opcode == 0x8b)
  1197. {
  1198. if (abs_symbol && local_ref)
  1199. to_reloc_32 = true;
  1200. if (to_reloc_32)
  1201. {
  1202. /* Convert "mov foo@GOT[(%reg1)], %reg2" to
  1203. "mov $foo, %reg2" with R_386_32. */
  1204. r_type = R_386_32;
  1205. modrm = 0xc0 | (modrm & 0x38) >> 3;
  1206. bfd_put_8 (abfd, modrm, contents + roff - 1);
  1207. opcode = 0xc7;
  1208. }
  1209. else
  1210. {
  1211. /* Convert "mov foo@GOT(%reg1), %reg2" to
  1212. "lea foo@GOTOFF(%reg1), %reg2". */
  1213. r_type = R_386_GOTOFF;
  1214. opcode = 0x8d;
  1215. }
  1216. }
  1217. else
  1218. {
  1219. /* Only R_386_32 is supported. */
  1220. if (!to_reloc_32)
  1221. return true;
  1222. if (opcode == 0x85)
  1223. {
  1224. /* Convert "test %reg1, foo@GOT(%reg2)" to
  1225. "test $foo, %reg1". */
  1226. modrm = 0xc0 | (modrm & 0x38) >> 3;
  1227. opcode = 0xf7;
  1228. }
  1229. else
  1230. {
  1231. /* Convert "binop foo@GOT(%reg1), %reg2" to
  1232. "binop $foo, %reg2". */
  1233. modrm = (0xc0
  1234. | (modrm & 0x38) >> 3
  1235. | (opcode & 0x3c));
  1236. opcode = 0x81;
  1237. }
  1238. bfd_put_8 (abfd, modrm, contents + roff - 1);
  1239. r_type = R_386_32;
  1240. }
  1241. bfd_put_8 (abfd, opcode, contents + roff - 2);
  1242. irel->r_info = ELF32_R_INFO (r_symndx, r_type);
  1243. *r_type_p = r_type;
  1244. *converted = true;
  1245. }
  1246. }
  1247. return true;
  1248. }
  1249. /* Look through the relocs for a section during the first phase, and
  1250. calculate needed space in the global offset table, and procedure
  1251. linkage table. */
  1252. static bool
  1253. elf_i386_scan_relocs (bfd *abfd,
  1254. struct bfd_link_info *info,
  1255. asection *sec,
  1256. const Elf_Internal_Rela *relocs)
  1257. {
  1258. struct elf_x86_link_hash_table *htab;
  1259. Elf_Internal_Shdr *symtab_hdr;
  1260. struct elf_link_hash_entry **sym_hashes;
  1261. const Elf_Internal_Rela *rel;
  1262. const Elf_Internal_Rela *rel_end;
  1263. bfd_byte *contents;
  1264. bool converted;
  1265. if (bfd_link_relocatable (info))
  1266. return true;
  1267. htab = elf_x86_hash_table (info, I386_ELF_DATA);
  1268. if (htab == NULL)
  1269. {
  1270. sec->check_relocs_failed = 1;
  1271. return false;
  1272. }
  1273. BFD_ASSERT (is_x86_elf (abfd, htab));
  1274. /* Get the section contents. */
  1275. if (elf_section_data (sec)->this_hdr.contents != NULL)
  1276. contents = elf_section_data (sec)->this_hdr.contents;
  1277. else if (!bfd_malloc_and_get_section (abfd, sec, &contents))
  1278. {
  1279. sec->check_relocs_failed = 1;
  1280. return false;
  1281. }
  1282. symtab_hdr = &elf_symtab_hdr (abfd);
  1283. sym_hashes = elf_sym_hashes (abfd);
  1284. converted = false;
  1285. rel_end = relocs + sec->reloc_count;
  1286. for (rel = relocs; rel < rel_end; rel++)
  1287. {
  1288. unsigned int r_type;
  1289. unsigned int r_symndx;
  1290. struct elf_link_hash_entry *h;
  1291. struct elf_x86_link_hash_entry *eh;
  1292. Elf_Internal_Sym *isym;
  1293. const char *name;
  1294. bool size_reloc;
  1295. bool no_dynreloc;
  1296. r_symndx = ELF32_R_SYM (rel->r_info);
  1297. r_type = ELF32_R_TYPE (rel->r_info);
  1298. if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
  1299. {
  1300. /* xgettext:c-format */
  1301. _bfd_error_handler (_("%pB: bad symbol index: %d"),
  1302. abfd, r_symndx);
  1303. goto error_return;
  1304. }
  1305. if (r_symndx < symtab_hdr->sh_info)
  1306. {
  1307. /* A local symbol. */
  1308. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
  1309. abfd, r_symndx);
  1310. if (isym == NULL)
  1311. goto error_return;
  1312. /* Check relocation against local STT_GNU_IFUNC symbol. */
  1313. if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
  1314. {
  1315. h = _bfd_elf_x86_get_local_sym_hash (htab, abfd, rel, true);
  1316. if (h == NULL)
  1317. goto error_return;
  1318. /* Fake a STT_GNU_IFUNC symbol. */
  1319. h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr,
  1320. isym, NULL);
  1321. h->type = STT_GNU_IFUNC;
  1322. h->def_regular = 1;
  1323. h->ref_regular = 1;
  1324. h->forced_local = 1;
  1325. h->root.type = bfd_link_hash_defined;
  1326. }
  1327. else
  1328. h = NULL;
  1329. }
  1330. else
  1331. {
  1332. isym = NULL;
  1333. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1334. while (h->root.type == bfd_link_hash_indirect
  1335. || h->root.type == bfd_link_hash_warning)
  1336. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1337. }
  1338. eh = (struct elf_x86_link_hash_entry *) h;
  1339. if (h != NULL)
  1340. {
  1341. if (r_type == R_386_GOTOFF)
  1342. eh->gotoff_ref = 1;
  1343. /* It is referenced by a non-shared object. */
  1344. h->ref_regular = 1;
  1345. }
  1346. if (r_type == R_386_GOT32X
  1347. && (h == NULL || h->type != STT_GNU_IFUNC))
  1348. {
  1349. Elf_Internal_Rela *irel = (Elf_Internal_Rela *) rel;
  1350. if (!elf_i386_convert_load_reloc (abfd, symtab_hdr, contents,
  1351. &r_type, irel, h,
  1352. &converted, info))
  1353. goto error_return;
  1354. }
  1355. if (!_bfd_elf_x86_valid_reloc_p (sec, info, htab, rel, h, isym,
  1356. symtab_hdr, &no_dynreloc))
  1357. return false;
  1358. if (! elf_i386_tls_transition (info, abfd, sec, contents,
  1359. symtab_hdr, sym_hashes,
  1360. &r_type, GOT_UNKNOWN,
  1361. rel, rel_end, h, r_symndx, false))
  1362. goto error_return;
  1363. /* Check if _GLOBAL_OFFSET_TABLE_ is referenced. */
  1364. if (h == htab->elf.hgot)
  1365. htab->got_referenced = true;
  1366. switch (r_type)
  1367. {
  1368. case R_386_TLS_LDM:
  1369. htab->tls_ld_or_ldm_got.refcount = 1;
  1370. goto create_got;
  1371. case R_386_PLT32:
  1372. /* This symbol requires a procedure linkage table entry. We
  1373. actually build the entry in adjust_dynamic_symbol,
  1374. because this might be a case of linking PIC code which is
  1375. never referenced by a dynamic object, in which case we
  1376. don't need to generate a procedure linkage table entry
  1377. after all. */
  1378. /* If this is a local symbol, we resolve it directly without
  1379. creating a procedure linkage table entry. */
  1380. if (h == NULL)
  1381. continue;
  1382. eh->zero_undefweak &= 0x2;
  1383. h->needs_plt = 1;
  1384. h->plt.refcount = 1;
  1385. break;
  1386. case R_386_SIZE32:
  1387. size_reloc = true;
  1388. goto do_size;
  1389. case R_386_TLS_IE_32:
  1390. case R_386_TLS_IE:
  1391. case R_386_TLS_GOTIE:
  1392. if (!bfd_link_executable (info))
  1393. info->flags |= DF_STATIC_TLS;
  1394. /* Fall through */
  1395. case R_386_GOT32:
  1396. case R_386_GOT32X:
  1397. case R_386_TLS_GD:
  1398. case R_386_TLS_GOTDESC:
  1399. case R_386_TLS_DESC_CALL:
  1400. /* This symbol requires a global offset table entry. */
  1401. {
  1402. int tls_type, old_tls_type;
  1403. switch (r_type)
  1404. {
  1405. default:
  1406. case R_386_GOT32:
  1407. case R_386_GOT32X:
  1408. tls_type = GOT_NORMAL;
  1409. break;
  1410. case R_386_TLS_GD: tls_type = GOT_TLS_GD; break;
  1411. case R_386_TLS_GOTDESC:
  1412. case R_386_TLS_DESC_CALL:
  1413. tls_type = GOT_TLS_GDESC; break;
  1414. case R_386_TLS_IE_32:
  1415. if (ELF32_R_TYPE (rel->r_info) == r_type)
  1416. tls_type = GOT_TLS_IE_NEG;
  1417. else
  1418. /* If this is a GD->IE transition, we may use either of
  1419. R_386_TLS_TPOFF and R_386_TLS_TPOFF32. */
  1420. tls_type = GOT_TLS_IE;
  1421. break;
  1422. case R_386_TLS_IE:
  1423. case R_386_TLS_GOTIE:
  1424. tls_type = GOT_TLS_IE_POS; break;
  1425. }
  1426. if (h != NULL)
  1427. {
  1428. h->got.refcount = 1;
  1429. old_tls_type = elf_x86_hash_entry (h)->tls_type;
  1430. }
  1431. else
  1432. {
  1433. bfd_signed_vma *local_got_refcounts;
  1434. if (!elf_x86_allocate_local_got_info (abfd,
  1435. symtab_hdr->sh_info))
  1436. goto error_return;
  1437. /* This is a global offset table entry for a local symbol. */
  1438. local_got_refcounts = elf_local_got_refcounts (abfd);
  1439. local_got_refcounts[r_symndx] = 1;
  1440. old_tls_type = elf_x86_local_got_tls_type (abfd) [r_symndx];
  1441. }
  1442. if ((old_tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_IE))
  1443. tls_type |= old_tls_type;
  1444. /* If a TLS symbol is accessed using IE at least once,
  1445. there is no point to use dynamic model for it. */
  1446. else if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
  1447. && (! GOT_TLS_GD_ANY_P (old_tls_type)
  1448. || (tls_type & GOT_TLS_IE) == 0))
  1449. {
  1450. if ((old_tls_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (tls_type))
  1451. tls_type = old_tls_type;
  1452. else if (GOT_TLS_GD_ANY_P (old_tls_type)
  1453. && GOT_TLS_GD_ANY_P (tls_type))
  1454. tls_type |= old_tls_type;
  1455. else
  1456. {
  1457. if (h)
  1458. name = h->root.root.string;
  1459. else
  1460. name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
  1461. NULL);
  1462. _bfd_error_handler
  1463. /* xgettext:c-format */
  1464. (_("%pB: `%s' accessed both as normal and "
  1465. "thread local symbol"),
  1466. abfd, name);
  1467. bfd_set_error (bfd_error_bad_value);
  1468. goto error_return;
  1469. }
  1470. }
  1471. if (old_tls_type != tls_type)
  1472. {
  1473. if (h != NULL)
  1474. elf_x86_hash_entry (h)->tls_type = tls_type;
  1475. else
  1476. elf_x86_local_got_tls_type (abfd) [r_symndx] = tls_type;
  1477. }
  1478. }
  1479. /* Fall through */
  1480. case R_386_GOTOFF:
  1481. case R_386_GOTPC:
  1482. create_got:
  1483. if (r_type != R_386_TLS_IE)
  1484. {
  1485. if (eh != NULL)
  1486. {
  1487. eh->zero_undefweak &= 0x2;
  1488. /* Need GOT to resolve undefined weak symbol to 0. */
  1489. if (r_type == R_386_GOTOFF
  1490. && h->root.type == bfd_link_hash_undefweak
  1491. && bfd_link_executable (info))
  1492. htab->got_referenced = true;
  1493. }
  1494. break;
  1495. }
  1496. /* Fall through */
  1497. case R_386_TLS_LE_32:
  1498. case R_386_TLS_LE:
  1499. if (eh != NULL)
  1500. eh->zero_undefweak &= 0x2;
  1501. if (bfd_link_executable (info))
  1502. break;
  1503. info->flags |= DF_STATIC_TLS;
  1504. goto do_relocation;
  1505. case R_386_32:
  1506. case R_386_PC32:
  1507. if (eh != NULL && (sec->flags & SEC_CODE) != 0)
  1508. eh->zero_undefweak |= 0x2;
  1509. do_relocation:
  1510. /* We are called after all symbols have been resolved. Only
  1511. relocation against STT_GNU_IFUNC symbol must go through
  1512. PLT. */
  1513. if (h != NULL
  1514. && (bfd_link_executable (info)
  1515. || h->type == STT_GNU_IFUNC))
  1516. {
  1517. bool func_pointer_ref = false;
  1518. if (r_type == R_386_PC32)
  1519. {
  1520. /* Since something like ".long foo - ." may be used
  1521. as pointer, make sure that PLT is used if foo is
  1522. a function defined in a shared library. */
  1523. if ((sec->flags & SEC_CODE) == 0)
  1524. h->pointer_equality_needed = 1;
  1525. else if (h->type == STT_GNU_IFUNC
  1526. && bfd_link_pic (info))
  1527. {
  1528. _bfd_error_handler
  1529. /* xgettext:c-format */
  1530. (_("%pB: unsupported non-PIC call to IFUNC `%s'"),
  1531. abfd, h->root.root.string);
  1532. bfd_set_error (bfd_error_bad_value);
  1533. goto error_return;
  1534. }
  1535. }
  1536. else
  1537. {
  1538. h->pointer_equality_needed = 1;
  1539. /* R_386_32 can be resolved at run-time. */
  1540. if (r_type == R_386_32
  1541. && (sec->flags & SEC_READONLY) == 0)
  1542. func_pointer_ref = true;
  1543. }
  1544. if (h->pointer_equality_needed
  1545. && h->type == STT_FUNC
  1546. && eh->def_protected
  1547. && elf_has_indirect_extern_access (h->root.u.def.section->owner))
  1548. {
  1549. /* Disallow non-canonical reference to canonical
  1550. protected function. */
  1551. _bfd_error_handler
  1552. /* xgettext:c-format */
  1553. (_("%pB: non-canonical reference to canonical "
  1554. "protected function `%s' in %pB"),
  1555. abfd, h->root.root.string,
  1556. h->root.u.def.section->owner);
  1557. bfd_set_error (bfd_error_bad_value);
  1558. goto error_return;
  1559. }
  1560. if (!func_pointer_ref)
  1561. {
  1562. /* If this reloc is in a read-only section, we might
  1563. need a copy reloc. We can't check reliably at this
  1564. stage whether the section is read-only, as input
  1565. sections have not yet been mapped to output sections.
  1566. Tentatively set the flag for now, and correct in
  1567. adjust_dynamic_symbol. */
  1568. h->non_got_ref = 1;
  1569. if (!elf_has_indirect_extern_access (sec->owner))
  1570. eh->non_got_ref_without_indirect_extern_access = 1;
  1571. /* We may need a .plt entry if the symbol is a function
  1572. defined in a shared lib or is a function referenced
  1573. from the code or read-only section. */
  1574. if (!h->def_regular
  1575. || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
  1576. h->plt.refcount = 1;
  1577. }
  1578. }
  1579. size_reloc = false;
  1580. do_size:
  1581. if (!no_dynreloc
  1582. && NEED_DYNAMIC_RELOCATION_P (false, info, false, h, sec,
  1583. r_type, R_386_32))
  1584. {
  1585. struct elf_dyn_relocs *p;
  1586. struct elf_dyn_relocs **head;
  1587. /* If this is a global symbol, we count the number of
  1588. relocations we need for this symbol. */
  1589. if (h != NULL)
  1590. {
  1591. head = &h->dyn_relocs;
  1592. }
  1593. else
  1594. {
  1595. /* Track dynamic relocs needed for local syms too.
  1596. We really need local syms available to do this
  1597. easily. Oh well. */
  1598. void **vpp;
  1599. asection *s;
  1600. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
  1601. abfd, r_symndx);
  1602. if (isym == NULL)
  1603. goto error_return;
  1604. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1605. if (s == NULL)
  1606. s = sec;
  1607. vpp = &elf_section_data (s)->local_dynrel;
  1608. head = (struct elf_dyn_relocs **)vpp;
  1609. }
  1610. p = *head;
  1611. if (p == NULL || p->sec != sec)
  1612. {
  1613. size_t amt = sizeof *p;
  1614. p = (struct elf_dyn_relocs *) bfd_alloc (htab->elf.dynobj,
  1615. amt);
  1616. if (p == NULL)
  1617. goto error_return;
  1618. p->next = *head;
  1619. *head = p;
  1620. p->sec = sec;
  1621. p->count = 0;
  1622. p->pc_count = 0;
  1623. }
  1624. p->count += 1;
  1625. /* Count size relocation as PC-relative relocation. */
  1626. if (r_type == R_386_PC32 || size_reloc)
  1627. p->pc_count += 1;
  1628. }
  1629. break;
  1630. /* This relocation describes the C++ object vtable hierarchy.
  1631. Reconstruct it for later use during GC. */
  1632. case R_386_GNU_VTINHERIT:
  1633. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  1634. goto error_return;
  1635. break;
  1636. /* This relocation describes which C++ vtable entries are actually
  1637. used. Record for later use during GC. */
  1638. case R_386_GNU_VTENTRY:
  1639. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
  1640. goto error_return;
  1641. break;
  1642. default:
  1643. break;
  1644. }
  1645. }
  1646. if (elf_section_data (sec)->this_hdr.contents != contents)
  1647. {
  1648. if (!converted && !_bfd_link_keep_memory (info))
  1649. free (contents);
  1650. else
  1651. {
  1652. /* Cache the section contents for elf_link_input_bfd if any
  1653. load is converted or --no-keep-memory isn't used. */
  1654. elf_section_data (sec)->this_hdr.contents = contents;
  1655. info->cache_size += sec->size;
  1656. }
  1657. }
  1658. /* Cache relocations if any load is converted. */
  1659. if (elf_section_data (sec)->relocs != relocs && converted)
  1660. elf_section_data (sec)->relocs = (Elf_Internal_Rela *) relocs;
  1661. return true;
  1662. error_return:
  1663. if (elf_section_data (sec)->this_hdr.contents != contents)
  1664. free (contents);
  1665. sec->check_relocs_failed = 1;
  1666. return false;
  1667. }
  1668. static bool
  1669. elf_i386_always_size_sections (bfd *output_bfd,
  1670. struct bfd_link_info *info)
  1671. {
  1672. bfd *abfd;
  1673. /* Scan relocations after rel_from_abs has been set on __ehdr_start. */
  1674. for (abfd = info->input_bfds;
  1675. abfd != (bfd *) NULL;
  1676. abfd = abfd->link.next)
  1677. if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
  1678. && !_bfd_elf_link_iterate_on_relocs (abfd, info,
  1679. elf_i386_scan_relocs))
  1680. return false;
  1681. return _bfd_x86_elf_always_size_sections (output_bfd, info);
  1682. }
  1683. /* Set the correct type for an x86 ELF section. We do this by the
  1684. section name, which is a hack, but ought to work. */
  1685. static bool
  1686. elf_i386_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
  1687. Elf_Internal_Shdr *hdr,
  1688. asection *sec)
  1689. {
  1690. const char *name;
  1691. name = bfd_section_name (sec);
  1692. /* This is an ugly, but unfortunately necessary hack that is
  1693. needed when producing EFI binaries on x86. It tells
  1694. elf.c:elf_fake_sections() not to consider ".reloc" as a section
  1695. containing ELF relocation info. We need this hack in order to
  1696. be able to generate ELF binaries that can be translated into
  1697. EFI applications (which are essentially COFF objects). Those
  1698. files contain a COFF ".reloc" section inside an ELFNN object,
  1699. which would normally cause BFD to segfault because it would
  1700. attempt to interpret this section as containing relocation
  1701. entries for section "oc". With this hack enabled, ".reloc"
  1702. will be treated as a normal data section, which will avoid the
  1703. segfault. However, you won't be able to create an ELFNN binary
  1704. with a section named "oc" that needs relocations, but that's
  1705. the kind of ugly side-effects you get when detecting section
  1706. types based on their names... In practice, this limitation is
  1707. unlikely to bite. */
  1708. if (strcmp (name, ".reloc") == 0)
  1709. hdr->sh_type = SHT_PROGBITS;
  1710. return true;
  1711. }
  1712. /* Return the relocation value for @tpoff relocation
  1713. if STT_TLS virtual address is ADDRESS. */
  1714. static bfd_vma
  1715. elf_i386_tpoff (struct bfd_link_info *info, bfd_vma address)
  1716. {
  1717. struct elf_link_hash_table *htab = elf_hash_table (info);
  1718. const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
  1719. bfd_vma static_tls_size;
  1720. /* If tls_sec is NULL, we should have signalled an error already. */
  1721. if (htab->tls_sec == NULL)
  1722. return 0;
  1723. /* Consider special static TLS alignment requirements. */
  1724. static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
  1725. return static_tls_size + htab->tls_sec->vma - address;
  1726. }
  1727. /* Relocate an i386 ELF section. */
  1728. static int
  1729. elf_i386_relocate_section (bfd *output_bfd,
  1730. struct bfd_link_info *info,
  1731. bfd *input_bfd,
  1732. asection *input_section,
  1733. bfd_byte *contents,
  1734. Elf_Internal_Rela *relocs,
  1735. Elf_Internal_Sym *local_syms,
  1736. asection **local_sections)
  1737. {
  1738. struct elf_x86_link_hash_table *htab;
  1739. Elf_Internal_Shdr *symtab_hdr;
  1740. struct elf_link_hash_entry **sym_hashes;
  1741. bfd_vma *local_got_offsets;
  1742. bfd_vma *local_tlsdesc_gotents;
  1743. Elf_Internal_Rela *rel;
  1744. Elf_Internal_Rela *wrel;
  1745. Elf_Internal_Rela *relend;
  1746. bool is_vxworks_tls;
  1747. unsigned plt_entry_size;
  1748. /* Skip if check_relocs or scan_relocs failed. */
  1749. if (input_section->check_relocs_failed)
  1750. return false;
  1751. htab = elf_x86_hash_table (info, I386_ELF_DATA);
  1752. if (htab == NULL)
  1753. return false;
  1754. if (!is_x86_elf (input_bfd, htab))
  1755. {
  1756. bfd_set_error (bfd_error_wrong_format);
  1757. return false;
  1758. }
  1759. symtab_hdr = &elf_symtab_hdr (input_bfd);
  1760. sym_hashes = elf_sym_hashes (input_bfd);
  1761. local_got_offsets = elf_local_got_offsets (input_bfd);
  1762. local_tlsdesc_gotents = elf_x86_local_tlsdesc_gotent (input_bfd);
  1763. /* We have to handle relocations in vxworks .tls_vars sections
  1764. specially, because the dynamic loader is 'weird'. */
  1765. is_vxworks_tls = (htab->elf.target_os == is_vxworks
  1766. && bfd_link_pic (info)
  1767. && !strcmp (input_section->output_section->name,
  1768. ".tls_vars"));
  1769. _bfd_x86_elf_set_tls_module_base (info);
  1770. plt_entry_size = htab->plt.plt_entry_size;
  1771. rel = wrel = relocs;
  1772. relend = relocs + input_section->reloc_count;
  1773. for (; rel < relend; wrel++, rel++)
  1774. {
  1775. unsigned int r_type, r_type_tls;
  1776. reloc_howto_type *howto;
  1777. unsigned long r_symndx;
  1778. struct elf_link_hash_entry *h;
  1779. struct elf_x86_link_hash_entry *eh;
  1780. Elf_Internal_Sym *sym;
  1781. asection *sec;
  1782. bfd_vma off, offplt, plt_offset;
  1783. bfd_vma relocation;
  1784. bool unresolved_reloc;
  1785. bfd_reloc_status_type r;
  1786. unsigned int indx;
  1787. int tls_type;
  1788. bfd_vma st_size;
  1789. asection *resolved_plt;
  1790. bool resolved_to_zero;
  1791. bool relative_reloc;
  1792. r_type = ELF32_R_TYPE (rel->r_info);
  1793. if (r_type == R_386_GNU_VTINHERIT
  1794. || r_type == R_386_GNU_VTENTRY)
  1795. {
  1796. if (wrel != rel)
  1797. *wrel = *rel;
  1798. continue;
  1799. }
  1800. howto = elf_i386_rtype_to_howto (r_type);
  1801. if (howto == NULL)
  1802. return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
  1803. r_symndx = ELF32_R_SYM (rel->r_info);
  1804. h = NULL;
  1805. sym = NULL;
  1806. sec = NULL;
  1807. unresolved_reloc = false;
  1808. if (r_symndx < symtab_hdr->sh_info)
  1809. {
  1810. sym = local_syms + r_symndx;
  1811. sec = local_sections[r_symndx];
  1812. relocation = (sec->output_section->vma
  1813. + sec->output_offset
  1814. + sym->st_value);
  1815. st_size = sym->st_size;
  1816. if (ELF_ST_TYPE (sym->st_info) == STT_SECTION
  1817. && ((sec->flags & SEC_MERGE) != 0
  1818. || (bfd_link_relocatable (info)
  1819. && sec->output_offset != 0)))
  1820. {
  1821. bfd_vma addend;
  1822. bfd_byte *where = contents + rel->r_offset;
  1823. switch (howto->size)
  1824. {
  1825. case 0:
  1826. addend = bfd_get_8 (input_bfd, where);
  1827. if (howto->pc_relative)
  1828. {
  1829. addend = (addend ^ 0x80) - 0x80;
  1830. addend += 1;
  1831. }
  1832. break;
  1833. case 1:
  1834. addend = bfd_get_16 (input_bfd, where);
  1835. if (howto->pc_relative)
  1836. {
  1837. addend = (addend ^ 0x8000) - 0x8000;
  1838. addend += 2;
  1839. }
  1840. break;
  1841. case 2:
  1842. addend = bfd_get_32 (input_bfd, where);
  1843. if (howto->pc_relative)
  1844. {
  1845. addend = (addend ^ 0x80000000) - 0x80000000;
  1846. addend += 4;
  1847. }
  1848. break;
  1849. default:
  1850. abort ();
  1851. }
  1852. if (bfd_link_relocatable (info))
  1853. addend += sec->output_offset;
  1854. else
  1855. {
  1856. asection *msec = sec;
  1857. addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec,
  1858. addend);
  1859. addend -= relocation;
  1860. addend += msec->output_section->vma + msec->output_offset;
  1861. }
  1862. switch (howto->size)
  1863. {
  1864. case 0:
  1865. /* FIXME: overflow checks. */
  1866. if (howto->pc_relative)
  1867. addend -= 1;
  1868. bfd_put_8 (input_bfd, addend, where);
  1869. break;
  1870. case 1:
  1871. if (howto->pc_relative)
  1872. addend -= 2;
  1873. bfd_put_16 (input_bfd, addend, where);
  1874. break;
  1875. case 2:
  1876. if (howto->pc_relative)
  1877. addend -= 4;
  1878. bfd_put_32 (input_bfd, addend, where);
  1879. break;
  1880. }
  1881. }
  1882. else if (!bfd_link_relocatable (info)
  1883. && ELF32_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
  1884. {
  1885. /* Relocate against local STT_GNU_IFUNC symbol. */
  1886. h = _bfd_elf_x86_get_local_sym_hash (htab, input_bfd, rel,
  1887. false);
  1888. if (h == NULL)
  1889. abort ();
  1890. /* Set STT_GNU_IFUNC symbol value. */
  1891. h->root.u.def.value = sym->st_value;
  1892. h->root.u.def.section = sec;
  1893. }
  1894. }
  1895. else
  1896. {
  1897. bool warned ATTRIBUTE_UNUSED;
  1898. bool ignored ATTRIBUTE_UNUSED;
  1899. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  1900. r_symndx, symtab_hdr, sym_hashes,
  1901. h, sec, relocation,
  1902. unresolved_reloc, warned, ignored);
  1903. st_size = h->size;
  1904. }
  1905. if (sec != NULL && discarded_section (sec))
  1906. {
  1907. _bfd_clear_contents (howto, input_bfd, input_section,
  1908. contents, rel->r_offset);
  1909. wrel->r_offset = rel->r_offset;
  1910. wrel->r_info = 0;
  1911. wrel->r_addend = 0;
  1912. /* For ld -r, remove relocations in debug sections against
  1913. sections defined in discarded sections. Not done for
  1914. eh_frame editing code expects to be present. */
  1915. if (bfd_link_relocatable (info)
  1916. && (input_section->flags & SEC_DEBUGGING))
  1917. wrel--;
  1918. continue;
  1919. }
  1920. if (bfd_link_relocatable (info))
  1921. {
  1922. if (wrel != rel)
  1923. *wrel = *rel;
  1924. continue;
  1925. }
  1926. eh = (struct elf_x86_link_hash_entry *) h;
  1927. /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
  1928. it here if it is defined in a non-shared object. */
  1929. if (h != NULL
  1930. && h->type == STT_GNU_IFUNC
  1931. && h->def_regular)
  1932. {
  1933. asection *gotplt, *base_got;
  1934. bfd_vma plt_index;
  1935. const char *name;
  1936. if ((input_section->flags & SEC_ALLOC) == 0)
  1937. {
  1938. /* If this is a SHT_NOTE section without SHF_ALLOC, treat
  1939. STT_GNU_IFUNC symbol as STT_FUNC. */
  1940. if (elf_section_type (input_section) == SHT_NOTE)
  1941. goto skip_ifunc;
  1942. /* Dynamic relocs are not propagated for SEC_DEBUGGING
  1943. sections because such sections are not SEC_ALLOC and
  1944. thus ld.so will not process them. */
  1945. if ((input_section->flags & SEC_DEBUGGING) != 0)
  1946. continue;
  1947. abort ();
  1948. }
  1949. /* STT_GNU_IFUNC symbol must go through PLT. */
  1950. if (htab->elf.splt != NULL)
  1951. {
  1952. if (htab->plt_second != NULL)
  1953. {
  1954. resolved_plt = htab->plt_second;
  1955. plt_offset = eh->plt_second.offset;
  1956. }
  1957. else
  1958. {
  1959. resolved_plt = htab->elf.splt;
  1960. plt_offset = h->plt.offset;
  1961. }
  1962. gotplt = htab->elf.sgotplt;
  1963. }
  1964. else
  1965. {
  1966. resolved_plt = htab->elf.iplt;
  1967. plt_offset = h->plt.offset;
  1968. gotplt = htab->elf.igotplt;
  1969. }
  1970. switch (r_type)
  1971. {
  1972. default:
  1973. break;
  1974. case R_386_GOT32:
  1975. case R_386_GOT32X:
  1976. base_got = htab->elf.sgot;
  1977. off = h->got.offset;
  1978. if (base_got == NULL)
  1979. abort ();
  1980. if (off == (bfd_vma) -1)
  1981. {
  1982. /* We can't use h->got.offset here to save state, or
  1983. even just remember the offset, as finish_dynamic_symbol
  1984. would use that as offset into .got. */
  1985. if (h->plt.offset == (bfd_vma) -1)
  1986. abort ();
  1987. if (htab->elf.splt != NULL)
  1988. {
  1989. plt_index = (h->plt.offset / plt_entry_size
  1990. - htab->plt.has_plt0);
  1991. off = (plt_index + 3) * 4;
  1992. base_got = htab->elf.sgotplt;
  1993. }
  1994. else
  1995. {
  1996. plt_index = h->plt.offset / plt_entry_size;
  1997. off = plt_index * 4;
  1998. base_got = htab->elf.igotplt;
  1999. }
  2000. if (h->dynindx == -1
  2001. || h->forced_local
  2002. || info->symbolic)
  2003. {
  2004. /* This references the local defitionion. We must
  2005. initialize this entry in the global offset table.
  2006. Since the offset must always be a multiple of 4,
  2007. we use the least significant bit to record
  2008. whether we have initialized it already.
  2009. When doing a dynamic link, we create a .rela.got
  2010. relocation entry to initialize the value. This
  2011. is done in the finish_dynamic_symbol routine. */
  2012. if ((off & 1) != 0)
  2013. off &= ~1;
  2014. else
  2015. {
  2016. bfd_put_32 (output_bfd, relocation,
  2017. base_got->contents + off);
  2018. h->got.offset |= 1;
  2019. }
  2020. }
  2021. relocation = off;
  2022. }
  2023. else
  2024. relocation = (base_got->output_section->vma
  2025. + base_got->output_offset + off
  2026. - gotplt->output_section->vma
  2027. - gotplt->output_offset);
  2028. if (rel->r_offset > 1
  2029. && (*(contents + rel->r_offset - 1) & 0xc7) == 0x5
  2030. && *(contents + rel->r_offset - 2) != 0x8d)
  2031. {
  2032. if (bfd_link_pic (info))
  2033. goto disallow_got32;
  2034. /* Add the GOT base if there is no base register. */
  2035. relocation += (gotplt->output_section->vma
  2036. + gotplt->output_offset);
  2037. }
  2038. else if (htab->elf.splt == NULL)
  2039. {
  2040. /* Adjust for static executables. */
  2041. relocation += gotplt->output_offset;
  2042. }
  2043. goto do_relocation;
  2044. }
  2045. if (h->plt.offset == (bfd_vma) -1)
  2046. {
  2047. /* Handle static pointers of STT_GNU_IFUNC symbols. */
  2048. if (r_type == R_386_32
  2049. && (input_section->flags & SEC_CODE) == 0)
  2050. goto do_ifunc_pointer;
  2051. goto bad_ifunc_reloc;
  2052. }
  2053. relocation = (resolved_plt->output_section->vma
  2054. + resolved_plt->output_offset + plt_offset);
  2055. switch (r_type)
  2056. {
  2057. default:
  2058. bad_ifunc_reloc:
  2059. if (h->root.root.string)
  2060. name = h->root.root.string;
  2061. else
  2062. name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
  2063. NULL);
  2064. _bfd_error_handler
  2065. /* xgettext:c-format */
  2066. (_("%pB: relocation %s against STT_GNU_IFUNC "
  2067. "symbol `%s' isn't supported"), input_bfd,
  2068. howto->name, name);
  2069. bfd_set_error (bfd_error_bad_value);
  2070. return false;
  2071. case R_386_32:
  2072. /* Generate dynamic relcoation only when there is a
  2073. non-GOT reference in a shared object. */
  2074. if ((bfd_link_pic (info) && h->non_got_ref)
  2075. || h->plt.offset == (bfd_vma) -1)
  2076. {
  2077. Elf_Internal_Rela outrel;
  2078. asection *sreloc;
  2079. bfd_vma offset;
  2080. do_ifunc_pointer:
  2081. /* Need a dynamic relocation to get the real function
  2082. adddress. */
  2083. offset = _bfd_elf_section_offset (output_bfd,
  2084. info,
  2085. input_section,
  2086. rel->r_offset);
  2087. if (offset == (bfd_vma) -1
  2088. || offset == (bfd_vma) -2)
  2089. abort ();
  2090. outrel.r_offset = (input_section->output_section->vma
  2091. + input_section->output_offset
  2092. + offset);
  2093. if (POINTER_LOCAL_IFUNC_P (info, h))
  2094. {
  2095. info->callbacks->minfo (_("Local IFUNC function `%s' in %pB\n"),
  2096. h->root.root.string,
  2097. h->root.u.def.section->owner);
  2098. /* This symbol is resolved locally. */
  2099. outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
  2100. if (htab->params->report_relative_reloc)
  2101. _bfd_x86_elf_link_report_relative_reloc
  2102. (info, input_section, h, sym,
  2103. "R_386_IRELATIVE", &outrel);
  2104. bfd_put_32 (output_bfd,
  2105. (h->root.u.def.value
  2106. + h->root.u.def.section->output_section->vma
  2107. + h->root.u.def.section->output_offset),
  2108. contents + offset);
  2109. }
  2110. else
  2111. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  2112. /* Dynamic relocations are stored in
  2113. 1. .rel.ifunc section in PIC object.
  2114. 2. .rel.got section in dynamic executable.
  2115. 3. .rel.iplt section in static executable. */
  2116. if (bfd_link_pic (info))
  2117. sreloc = htab->elf.irelifunc;
  2118. else if (htab->elf.splt != NULL)
  2119. sreloc = htab->elf.srelgot;
  2120. else
  2121. sreloc = htab->elf.irelplt;
  2122. elf_append_rel (output_bfd, sreloc, &outrel);
  2123. /* If this reloc is against an external symbol, we
  2124. do not want to fiddle with the addend. Otherwise,
  2125. we need to include the symbol value so that it
  2126. becomes an addend for the dynamic reloc. For an
  2127. internal symbol, we have updated addend. */
  2128. continue;
  2129. }
  2130. /* FALLTHROUGH */
  2131. case R_386_PC32:
  2132. case R_386_PLT32:
  2133. goto do_relocation;
  2134. case R_386_GOTOFF:
  2135. relocation -= (gotplt->output_section->vma
  2136. + gotplt->output_offset);
  2137. goto do_relocation;
  2138. }
  2139. }
  2140. skip_ifunc:
  2141. resolved_to_zero = (eh != NULL
  2142. && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh));
  2143. switch (r_type)
  2144. {
  2145. case R_386_GOT32X:
  2146. case R_386_GOT32:
  2147. /* Relocation is to the entry for this symbol in the global
  2148. offset table. */
  2149. if (htab->elf.sgot == NULL)
  2150. abort ();
  2151. relative_reloc = false;
  2152. if (h != NULL)
  2153. {
  2154. off = h->got.offset;
  2155. if (RESOLVED_LOCALLY_P (info, h, htab))
  2156. {
  2157. /* We must initialize this entry in the global offset
  2158. table. Since the offset must always be a multiple
  2159. of 4, we use the least significant bit to record
  2160. whether we have initialized it already.
  2161. When doing a dynamic link, we create a .rel.got
  2162. relocation entry to initialize the value. This
  2163. is done in the finish_dynamic_symbol routine. */
  2164. if ((off & 1) != 0)
  2165. off &= ~1;
  2166. else
  2167. {
  2168. bfd_put_32 (output_bfd, relocation,
  2169. htab->elf.sgot->contents + off);
  2170. h->got.offset |= 1;
  2171. /* NB: Don't generate relative relocation here if
  2172. it has been generated by DT_RELR. */
  2173. if (!info->enable_dt_relr
  2174. && GENERATE_RELATIVE_RELOC_P (info, h))
  2175. {
  2176. /* PR ld/21402: If this symbol isn't dynamic
  2177. in PIC, generate R_386_RELATIVE here. */
  2178. eh->no_finish_dynamic_symbol = 1;
  2179. relative_reloc = true;
  2180. }
  2181. }
  2182. }
  2183. else
  2184. unresolved_reloc = false;
  2185. }
  2186. else
  2187. {
  2188. if (local_got_offsets == NULL)
  2189. abort ();
  2190. off = local_got_offsets[r_symndx];
  2191. /* The offset must always be a multiple of 4. We use
  2192. the least significant bit to record whether we have
  2193. already generated the necessary reloc. */
  2194. if ((off & 1) != 0)
  2195. off &= ~1;
  2196. else
  2197. {
  2198. bfd_put_32 (output_bfd, relocation,
  2199. htab->elf.sgot->contents + off);
  2200. local_got_offsets[r_symndx] |= 1;
  2201. /* NB: Don't generate relative relocation here if it
  2202. has been generated by DT_RELR. */
  2203. if (!info->enable_dt_relr && bfd_link_pic (info))
  2204. relative_reloc = true;
  2205. }
  2206. }
  2207. if (relative_reloc)
  2208. {
  2209. asection *s;
  2210. Elf_Internal_Rela outrel;
  2211. s = htab->elf.srelgot;
  2212. if (s == NULL)
  2213. abort ();
  2214. outrel.r_offset = (htab->elf.sgot->output_section->vma
  2215. + htab->elf.sgot->output_offset
  2216. + off);
  2217. outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
  2218. if (htab->params->report_relative_reloc)
  2219. _bfd_x86_elf_link_report_relative_reloc
  2220. (info, input_section, h, sym, "R_386_RELATIVE",
  2221. &outrel);
  2222. elf_append_rel (output_bfd, s, &outrel);
  2223. }
  2224. if (off >= (bfd_vma) -2)
  2225. abort ();
  2226. relocation = (htab->elf.sgot->output_section->vma
  2227. + htab->elf.sgot->output_offset + off);
  2228. if (rel->r_offset > 1
  2229. && (*(contents + rel->r_offset - 1) & 0xc7) == 0x5
  2230. && *(contents + rel->r_offset - 2) != 0x8d)
  2231. {
  2232. if (bfd_link_pic (info))
  2233. {
  2234. /* For PIC, disallow R_386_GOT32 without a base
  2235. register, except for "lea foo@GOT, %reg", since
  2236. we don't know what the GOT base is. */
  2237. const char *name;
  2238. disallow_got32:
  2239. if (h == NULL || h->root.root.string == NULL)
  2240. name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
  2241. NULL);
  2242. else
  2243. name = h->root.root.string;
  2244. _bfd_error_handler
  2245. /* xgettext:c-format */
  2246. (_("%pB: direct GOT relocation %s against `%s'"
  2247. " without base register can not be used"
  2248. " when making a shared object"),
  2249. input_bfd, howto->name, name);
  2250. bfd_set_error (bfd_error_bad_value);
  2251. return false;
  2252. }
  2253. }
  2254. else
  2255. {
  2256. /* Subtract the .got.plt section address only with a base
  2257. register. */
  2258. relocation -= (htab->elf.sgotplt->output_section->vma
  2259. + htab->elf.sgotplt->output_offset);
  2260. }
  2261. break;
  2262. case R_386_GOTOFF:
  2263. /* Relocation is relative to the start of the global offset
  2264. table. */
  2265. /* Check to make sure it isn't a protected function or data
  2266. symbol for shared library since it may not be local when
  2267. used as function address or with copy relocation. We also
  2268. need to make sure that a symbol is referenced locally. */
  2269. if (!bfd_link_executable (info) && h)
  2270. {
  2271. if (!h->def_regular)
  2272. {
  2273. const char *v;
  2274. switch (ELF_ST_VISIBILITY (h->other))
  2275. {
  2276. case STV_HIDDEN:
  2277. v = _("hidden symbol");
  2278. break;
  2279. case STV_INTERNAL:
  2280. v = _("internal symbol");
  2281. break;
  2282. case STV_PROTECTED:
  2283. v = _("protected symbol");
  2284. break;
  2285. default:
  2286. v = _("symbol");
  2287. break;
  2288. }
  2289. _bfd_error_handler
  2290. /* xgettext:c-format */
  2291. (_("%pB: relocation R_386_GOTOFF against undefined %s"
  2292. " `%s' can not be used when making a shared object"),
  2293. input_bfd, v, h->root.root.string);
  2294. bfd_set_error (bfd_error_bad_value);
  2295. return false;
  2296. }
  2297. else if (!SYMBOL_REFERENCES_LOCAL_P (info, h)
  2298. && (h->type == STT_FUNC
  2299. || h->type == STT_OBJECT)
  2300. && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
  2301. {
  2302. _bfd_error_handler
  2303. /* xgettext:c-format */
  2304. (_("%pB: relocation R_386_GOTOFF against protected %s"
  2305. " `%s' can not be used when making a shared object"),
  2306. input_bfd,
  2307. h->type == STT_FUNC ? "function" : "data",
  2308. h->root.root.string);
  2309. bfd_set_error (bfd_error_bad_value);
  2310. return false;
  2311. }
  2312. }
  2313. /* Note that sgot is not involved in this
  2314. calculation. We always want the start of .got.plt. If we
  2315. defined _GLOBAL_OFFSET_TABLE_ in a different way, as is
  2316. permitted by the ABI, we might have to change this
  2317. calculation. */
  2318. relocation -= htab->elf.sgotplt->output_section->vma
  2319. + htab->elf.sgotplt->output_offset;
  2320. break;
  2321. case R_386_GOTPC:
  2322. /* Use global offset table as symbol value. */
  2323. relocation = htab->elf.sgotplt->output_section->vma
  2324. + htab->elf.sgotplt->output_offset;
  2325. unresolved_reloc = false;
  2326. break;
  2327. case R_386_PLT32:
  2328. /* Relocation is to the entry for this symbol in the
  2329. procedure linkage table. */
  2330. /* Resolve a PLT32 reloc against a local symbol directly,
  2331. without using the procedure linkage table. */
  2332. if (h == NULL)
  2333. break;
  2334. if ((h->plt.offset == (bfd_vma) -1
  2335. && eh->plt_got.offset == (bfd_vma) -1)
  2336. || htab->elf.splt == NULL)
  2337. {
  2338. /* We didn't make a PLT entry for this symbol. This
  2339. happens when statically linking PIC code, or when
  2340. using -Bsymbolic. */
  2341. break;
  2342. }
  2343. if (h->plt.offset != (bfd_vma) -1)
  2344. {
  2345. if (htab->plt_second != NULL)
  2346. {
  2347. resolved_plt = htab->plt_second;
  2348. plt_offset = eh->plt_second.offset;
  2349. }
  2350. else
  2351. {
  2352. resolved_plt = htab->elf.splt;
  2353. plt_offset = h->plt.offset;
  2354. }
  2355. }
  2356. else
  2357. {
  2358. resolved_plt = htab->plt_got;
  2359. plt_offset = eh->plt_got.offset;
  2360. }
  2361. relocation = (resolved_plt->output_section->vma
  2362. + resolved_plt->output_offset
  2363. + plt_offset);
  2364. unresolved_reloc = false;
  2365. break;
  2366. case R_386_SIZE32:
  2367. /* Set to symbol size. */
  2368. relocation = st_size;
  2369. /* Fall through. */
  2370. case R_386_32:
  2371. case R_386_PC32:
  2372. if ((input_section->flags & SEC_ALLOC) == 0
  2373. || is_vxworks_tls)
  2374. break;
  2375. if (GENERATE_DYNAMIC_RELOCATION_P (false, info, eh, r_type,
  2376. sec, false,
  2377. resolved_to_zero,
  2378. (r_type == R_386_PC32)))
  2379. {
  2380. Elf_Internal_Rela outrel;
  2381. bool skip, relocate;
  2382. bool generate_dynamic_reloc = true;
  2383. asection *sreloc;
  2384. /* When generating a shared object, these relocations
  2385. are copied into the output file to be resolved at run
  2386. time. */
  2387. skip = false;
  2388. relocate = false;
  2389. outrel.r_offset =
  2390. _bfd_elf_section_offset (output_bfd, info, input_section,
  2391. rel->r_offset);
  2392. if (outrel.r_offset == (bfd_vma) -1)
  2393. skip = true;
  2394. else if (outrel.r_offset == (bfd_vma) -2)
  2395. skip = true, relocate = true;
  2396. outrel.r_offset += (input_section->output_section->vma
  2397. + input_section->output_offset);
  2398. if (skip)
  2399. memset (&outrel, 0, sizeof outrel);
  2400. else if (COPY_INPUT_RELOC_P (false, info, h, r_type))
  2401. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  2402. else
  2403. {
  2404. /* This symbol is local, or marked to become local. */
  2405. relocate = true;
  2406. /* NB: Don't generate relative relocation here if it
  2407. has been generated by DT_RELR. */
  2408. if (info->enable_dt_relr)
  2409. generate_dynamic_reloc = false;
  2410. else
  2411. {
  2412. outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
  2413. if (htab->params->report_relative_reloc)
  2414. _bfd_x86_elf_link_report_relative_reloc
  2415. (info, input_section, h, sym, "R_386_RELATIVE",
  2416. &outrel);
  2417. }
  2418. }
  2419. if (generate_dynamic_reloc)
  2420. {
  2421. sreloc = elf_section_data (input_section)->sreloc;
  2422. if (sreloc == NULL || sreloc->contents == NULL)
  2423. {
  2424. r = bfd_reloc_notsupported;
  2425. goto check_relocation_error;
  2426. }
  2427. elf_append_rel (output_bfd, sreloc, &outrel);
  2428. }
  2429. /* If this reloc is against an external symbol, we do
  2430. not want to fiddle with the addend. Otherwise, we
  2431. need to include the symbol value so that it becomes
  2432. an addend for the dynamic reloc. */
  2433. if (! relocate)
  2434. continue;
  2435. }
  2436. break;
  2437. case R_386_TLS_IE:
  2438. if (!bfd_link_executable (info))
  2439. {
  2440. Elf_Internal_Rela outrel;
  2441. asection *sreloc;
  2442. outrel.r_offset = rel->r_offset
  2443. + input_section->output_section->vma
  2444. + input_section->output_offset;
  2445. outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
  2446. if (htab->params->report_relative_reloc)
  2447. _bfd_x86_elf_link_report_relative_reloc
  2448. (info, input_section, h, sym, "R_386_RELATIVE",
  2449. &outrel);
  2450. sreloc = elf_section_data (input_section)->sreloc;
  2451. if (sreloc == NULL)
  2452. abort ();
  2453. elf_append_rel (output_bfd, sreloc, &outrel);
  2454. }
  2455. /* Fall through */
  2456. case R_386_TLS_GD:
  2457. case R_386_TLS_GOTDESC:
  2458. case R_386_TLS_DESC_CALL:
  2459. case R_386_TLS_IE_32:
  2460. case R_386_TLS_GOTIE:
  2461. tls_type = GOT_UNKNOWN;
  2462. if (h == NULL && local_got_offsets)
  2463. tls_type = elf_x86_local_got_tls_type (input_bfd) [r_symndx];
  2464. else if (h != NULL)
  2465. tls_type = elf_x86_hash_entry(h)->tls_type;
  2466. if (tls_type == GOT_TLS_IE)
  2467. tls_type = GOT_TLS_IE_NEG;
  2468. r_type_tls = r_type;
  2469. if (! elf_i386_tls_transition (info, input_bfd,
  2470. input_section, contents,
  2471. symtab_hdr, sym_hashes,
  2472. &r_type_tls, tls_type, rel,
  2473. relend, h, r_symndx, true))
  2474. return false;
  2475. if (r_type_tls == R_386_TLS_LE_32)
  2476. {
  2477. BFD_ASSERT (! unresolved_reloc);
  2478. if (r_type == R_386_TLS_GD)
  2479. {
  2480. unsigned int type;
  2481. bfd_vma roff;
  2482. /* GD->LE transition. */
  2483. type = *(contents + rel->r_offset - 2);
  2484. if (type == 0x04)
  2485. {
  2486. /* Change
  2487. leal foo@tlsgd(,%ebx,1), %eax
  2488. call ___tls_get_addr@PLT
  2489. into:
  2490. movl %gs:0, %eax
  2491. subl $foo@tpoff, %eax
  2492. (6 byte form of subl). */
  2493. roff = rel->r_offset + 5;
  2494. }
  2495. else
  2496. {
  2497. /* Change
  2498. leal foo@tlsgd(%ebx), %eax
  2499. call ___tls_get_addr@PLT
  2500. nop
  2501. or
  2502. leal foo@tlsgd(%reg), %eax
  2503. call *___tls_get_addr@GOT(%reg)
  2504. which may be converted to
  2505. addr32 call ___tls_get_addr
  2506. into:
  2507. movl %gs:0, %eax; subl $foo@tpoff, %eax
  2508. (6 byte form of subl). */
  2509. roff = rel->r_offset + 6;
  2510. }
  2511. memcpy (contents + roff - 8,
  2512. "\x65\xa1\0\0\0\0\x81\xe8\0\0\0", 12);
  2513. bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation),
  2514. contents + roff);
  2515. /* Skip R_386_PC32, R_386_PLT32 and R_386_GOT32X. */
  2516. rel++;
  2517. wrel++;
  2518. continue;
  2519. }
  2520. else if (r_type == R_386_TLS_GOTDESC)
  2521. {
  2522. /* GDesc -> LE transition.
  2523. It's originally something like:
  2524. leal x@tlsdesc(%ebx), %eax
  2525. leal x@ntpoff, %eax
  2526. Registers other than %eax may be set up here. */
  2527. unsigned int val;
  2528. bfd_vma roff;
  2529. roff = rel->r_offset;
  2530. val = bfd_get_8 (input_bfd, contents + roff - 1);
  2531. /* Now modify the instruction as appropriate. */
  2532. /* aoliva FIXME: remove the above and xor the byte
  2533. below with 0x86. */
  2534. bfd_put_8 (output_bfd, val ^ 0x86,
  2535. contents + roff - 1);
  2536. bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
  2537. contents + roff);
  2538. continue;
  2539. }
  2540. else if (r_type == R_386_TLS_DESC_CALL)
  2541. {
  2542. /* GDesc -> LE transition.
  2543. It's originally:
  2544. call *(%eax)
  2545. Turn it into:
  2546. xchg %ax,%ax */
  2547. bfd_vma roff;
  2548. roff = rel->r_offset;
  2549. bfd_put_8 (output_bfd, 0x66, contents + roff);
  2550. bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
  2551. continue;
  2552. }
  2553. else if (r_type == R_386_TLS_IE)
  2554. {
  2555. unsigned int val;
  2556. /* IE->LE transition:
  2557. Originally it can be one of:
  2558. movl foo, %eax
  2559. movl foo, %reg
  2560. addl foo, %reg
  2561. We change it into:
  2562. movl $foo, %eax
  2563. movl $foo, %reg
  2564. addl $foo, %reg. */
  2565. val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
  2566. if (val == 0xa1)
  2567. {
  2568. /* movl foo, %eax. */
  2569. bfd_put_8 (output_bfd, 0xb8,
  2570. contents + rel->r_offset - 1);
  2571. }
  2572. else
  2573. {
  2574. unsigned int type;
  2575. type = bfd_get_8 (input_bfd,
  2576. contents + rel->r_offset - 2);
  2577. switch (type)
  2578. {
  2579. case 0x8b:
  2580. /* movl */
  2581. bfd_put_8 (output_bfd, 0xc7,
  2582. contents + rel->r_offset - 2);
  2583. bfd_put_8 (output_bfd,
  2584. 0xc0 | ((val >> 3) & 7),
  2585. contents + rel->r_offset - 1);
  2586. break;
  2587. case 0x03:
  2588. /* addl */
  2589. bfd_put_8 (output_bfd, 0x81,
  2590. contents + rel->r_offset - 2);
  2591. bfd_put_8 (output_bfd,
  2592. 0xc0 | ((val >> 3) & 7),
  2593. contents + rel->r_offset - 1);
  2594. break;
  2595. default:
  2596. BFD_FAIL ();
  2597. break;
  2598. }
  2599. }
  2600. bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
  2601. contents + rel->r_offset);
  2602. continue;
  2603. }
  2604. else
  2605. {
  2606. unsigned int val, type;
  2607. /* {IE_32,GOTIE}->LE transition:
  2608. Originally it can be one of:
  2609. subl foo(%reg1), %reg2
  2610. movl foo(%reg1), %reg2
  2611. addl foo(%reg1), %reg2
  2612. We change it into:
  2613. subl $foo, %reg2
  2614. movl $foo, %reg2 (6 byte form)
  2615. addl $foo, %reg2. */
  2616. type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2);
  2617. val = bfd_get_8 (input_bfd, contents + rel->r_offset - 1);
  2618. if (type == 0x8b)
  2619. {
  2620. /* movl */
  2621. bfd_put_8 (output_bfd, 0xc7,
  2622. contents + rel->r_offset - 2);
  2623. bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
  2624. contents + rel->r_offset - 1);
  2625. }
  2626. else if (type == 0x2b)
  2627. {
  2628. /* subl */
  2629. bfd_put_8 (output_bfd, 0x81,
  2630. contents + rel->r_offset - 2);
  2631. bfd_put_8 (output_bfd, 0xe8 | ((val >> 3) & 7),
  2632. contents + rel->r_offset - 1);
  2633. }
  2634. else if (type == 0x03)
  2635. {
  2636. /* addl */
  2637. bfd_put_8 (output_bfd, 0x81,
  2638. contents + rel->r_offset - 2);
  2639. bfd_put_8 (output_bfd, 0xc0 | ((val >> 3) & 7),
  2640. contents + rel->r_offset - 1);
  2641. }
  2642. else
  2643. BFD_FAIL ();
  2644. if (r_type == R_386_TLS_GOTIE)
  2645. bfd_put_32 (output_bfd, -elf_i386_tpoff (info, relocation),
  2646. contents + rel->r_offset);
  2647. else
  2648. bfd_put_32 (output_bfd, elf_i386_tpoff (info, relocation),
  2649. contents + rel->r_offset);
  2650. continue;
  2651. }
  2652. }
  2653. if (htab->elf.sgot == NULL)
  2654. abort ();
  2655. if (h != NULL)
  2656. {
  2657. off = h->got.offset;
  2658. offplt = elf_x86_hash_entry (h)->tlsdesc_got;
  2659. }
  2660. else
  2661. {
  2662. if (local_got_offsets == NULL)
  2663. abort ();
  2664. off = local_got_offsets[r_symndx];
  2665. offplt = local_tlsdesc_gotents[r_symndx];
  2666. }
  2667. if ((off & 1) != 0)
  2668. off &= ~1;
  2669. else
  2670. {
  2671. Elf_Internal_Rela outrel;
  2672. int dr_type;
  2673. asection *sreloc;
  2674. if (htab->elf.srelgot == NULL)
  2675. abort ();
  2676. indx = h && h->dynindx != -1 ? h->dynindx : 0;
  2677. if (GOT_TLS_GDESC_P (tls_type))
  2678. {
  2679. bfd_byte *loc;
  2680. outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC);
  2681. BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8
  2682. <= htab->elf.sgotplt->size);
  2683. outrel.r_offset = (htab->elf.sgotplt->output_section->vma
  2684. + htab->elf.sgotplt->output_offset
  2685. + offplt
  2686. + htab->sgotplt_jump_table_size);
  2687. sreloc = htab->elf.srelplt;
  2688. loc = sreloc->contents;
  2689. loc += (htab->next_tls_desc_index++
  2690. * sizeof (Elf32_External_Rel));
  2691. BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
  2692. <= sreloc->contents + sreloc->size);
  2693. bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
  2694. if (indx == 0)
  2695. {
  2696. BFD_ASSERT (! unresolved_reloc);
  2697. bfd_put_32 (output_bfd,
  2698. relocation - _bfd_x86_elf_dtpoff_base (info),
  2699. htab->elf.sgotplt->contents + offplt
  2700. + htab->sgotplt_jump_table_size + 4);
  2701. }
  2702. else
  2703. {
  2704. bfd_put_32 (output_bfd, 0,
  2705. htab->elf.sgotplt->contents + offplt
  2706. + htab->sgotplt_jump_table_size + 4);
  2707. }
  2708. }
  2709. sreloc = htab->elf.srelgot;
  2710. outrel.r_offset = (htab->elf.sgot->output_section->vma
  2711. + htab->elf.sgot->output_offset + off);
  2712. if (GOT_TLS_GD_P (tls_type))
  2713. dr_type = R_386_TLS_DTPMOD32;
  2714. else if (GOT_TLS_GDESC_P (tls_type))
  2715. goto dr_done;
  2716. else if (tls_type == GOT_TLS_IE_POS)
  2717. dr_type = R_386_TLS_TPOFF;
  2718. else
  2719. dr_type = R_386_TLS_TPOFF32;
  2720. if (dr_type == R_386_TLS_TPOFF && indx == 0)
  2721. bfd_put_32 (output_bfd,
  2722. relocation - _bfd_x86_elf_dtpoff_base (info),
  2723. htab->elf.sgot->contents + off);
  2724. else if (dr_type == R_386_TLS_TPOFF32 && indx == 0)
  2725. bfd_put_32 (output_bfd,
  2726. _bfd_x86_elf_dtpoff_base (info) - relocation,
  2727. htab->elf.sgot->contents + off);
  2728. else if (dr_type != R_386_TLS_DESC)
  2729. bfd_put_32 (output_bfd, 0,
  2730. htab->elf.sgot->contents + off);
  2731. outrel.r_info = ELF32_R_INFO (indx, dr_type);
  2732. elf_append_rel (output_bfd, sreloc, &outrel);
  2733. if (GOT_TLS_GD_P (tls_type))
  2734. {
  2735. if (indx == 0)
  2736. {
  2737. BFD_ASSERT (! unresolved_reloc);
  2738. bfd_put_32 (output_bfd,
  2739. relocation - _bfd_x86_elf_dtpoff_base (info),
  2740. htab->elf.sgot->contents + off + 4);
  2741. }
  2742. else
  2743. {
  2744. bfd_put_32 (output_bfd, 0,
  2745. htab->elf.sgot->contents + off + 4);
  2746. outrel.r_info = ELF32_R_INFO (indx,
  2747. R_386_TLS_DTPOFF32);
  2748. outrel.r_offset += 4;
  2749. elf_append_rel (output_bfd, sreloc, &outrel);
  2750. }
  2751. }
  2752. else if (tls_type == GOT_TLS_IE_BOTH)
  2753. {
  2754. bfd_put_32 (output_bfd,
  2755. (indx == 0
  2756. ? relocation - _bfd_x86_elf_dtpoff_base (info)
  2757. : 0),
  2758. htab->elf.sgot->contents + off + 4);
  2759. outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
  2760. outrel.r_offset += 4;
  2761. elf_append_rel (output_bfd, sreloc, &outrel);
  2762. }
  2763. dr_done:
  2764. if (h != NULL)
  2765. h->got.offset |= 1;
  2766. else
  2767. local_got_offsets[r_symndx] |= 1;
  2768. }
  2769. if (off >= (bfd_vma) -2
  2770. && ! GOT_TLS_GDESC_P (tls_type))
  2771. abort ();
  2772. if (r_type_tls == R_386_TLS_GOTDESC
  2773. || r_type_tls == R_386_TLS_DESC_CALL)
  2774. {
  2775. relocation = htab->sgotplt_jump_table_size + offplt;
  2776. unresolved_reloc = false;
  2777. }
  2778. else if (r_type_tls == r_type)
  2779. {
  2780. bfd_vma g_o_t = htab->elf.sgotplt->output_section->vma
  2781. + htab->elf.sgotplt->output_offset;
  2782. relocation = htab->elf.sgot->output_section->vma
  2783. + htab->elf.sgot->output_offset + off - g_o_t;
  2784. if ((r_type == R_386_TLS_IE || r_type == R_386_TLS_GOTIE)
  2785. && tls_type == GOT_TLS_IE_BOTH)
  2786. relocation += 4;
  2787. if (r_type == R_386_TLS_IE)
  2788. relocation += g_o_t;
  2789. unresolved_reloc = false;
  2790. }
  2791. else if (r_type == R_386_TLS_GD)
  2792. {
  2793. unsigned int val, type;
  2794. bfd_vma roff;
  2795. /* GD->IE transition. */
  2796. type = *(contents + rel->r_offset - 2);
  2797. val = *(contents + rel->r_offset - 1);
  2798. if (type == 0x04)
  2799. {
  2800. /* Change
  2801. leal foo@tlsgd(,%ebx,1), %eax
  2802. call ___tls_get_addr@PLT
  2803. into:
  2804. movl %gs:0, %eax
  2805. subl $foo@gottpoff(%ebx), %eax. */
  2806. val >>= 3;
  2807. roff = rel->r_offset - 3;
  2808. }
  2809. else
  2810. {
  2811. /* Change
  2812. leal foo@tlsgd(%ebx), %eax
  2813. call ___tls_get_addr@PLT
  2814. nop
  2815. or
  2816. leal foo@tlsgd(%reg), %eax
  2817. call *___tls_get_addr@GOT(%reg)
  2818. which may be converted to
  2819. addr32 call ___tls_get_addr
  2820. into:
  2821. movl %gs:0, %eax;
  2822. subl $foo@gottpoff(%reg), %eax. */
  2823. roff = rel->r_offset - 2;
  2824. }
  2825. memcpy (contents + roff,
  2826. "\x65\xa1\0\0\0\0\x2b\x80\0\0\0", 12);
  2827. contents[roff + 7] = 0x80 | (val & 7);
  2828. /* If foo is used only with foo@gotntpoff(%reg) and
  2829. foo@indntpoff, but not with foo@gottpoff(%reg), change
  2830. subl $foo@gottpoff(%reg), %eax
  2831. into:
  2832. addl $foo@gotntpoff(%reg), %eax. */
  2833. if (tls_type == GOT_TLS_IE_POS)
  2834. contents[roff + 6] = 0x03;
  2835. bfd_put_32 (output_bfd,
  2836. htab->elf.sgot->output_section->vma
  2837. + htab->elf.sgot->output_offset + off
  2838. - htab->elf.sgotplt->output_section->vma
  2839. - htab->elf.sgotplt->output_offset,
  2840. contents + roff + 8);
  2841. /* Skip R_386_PLT32 and R_386_GOT32X. */
  2842. rel++;
  2843. wrel++;
  2844. continue;
  2845. }
  2846. else if (r_type == R_386_TLS_GOTDESC)
  2847. {
  2848. /* GDesc -> IE transition.
  2849. It's originally something like:
  2850. leal x@tlsdesc(%ebx), %eax
  2851. Change it to:
  2852. movl x@gotntpoff(%ebx), %eax # before xchg %ax,%ax
  2853. or:
  2854. movl x@gottpoff(%ebx), %eax # before negl %eax
  2855. Registers other than %eax may be set up here. */
  2856. bfd_vma roff;
  2857. /* First, make sure it's a leal adding ebx to a 32-bit
  2858. offset into any register, although it's probably
  2859. almost always going to be eax. */
  2860. roff = rel->r_offset;
  2861. /* Now modify the instruction as appropriate. */
  2862. /* To turn a leal into a movl in the form we use it, it
  2863. suffices to change the first byte from 0x8d to 0x8b.
  2864. aoliva FIXME: should we decide to keep the leal, all
  2865. we have to do is remove the statement below, and
  2866. adjust the relaxation of R_386_TLS_DESC_CALL. */
  2867. bfd_put_8 (output_bfd, 0x8b, contents + roff - 2);
  2868. if (tls_type == GOT_TLS_IE_BOTH)
  2869. off += 4;
  2870. bfd_put_32 (output_bfd,
  2871. htab->elf.sgot->output_section->vma
  2872. + htab->elf.sgot->output_offset + off
  2873. - htab->elf.sgotplt->output_section->vma
  2874. - htab->elf.sgotplt->output_offset,
  2875. contents + roff);
  2876. continue;
  2877. }
  2878. else if (r_type == R_386_TLS_DESC_CALL)
  2879. {
  2880. /* GDesc -> IE transition.
  2881. It's originally:
  2882. call *(%eax)
  2883. Change it to:
  2884. xchg %ax,%ax
  2885. or
  2886. negl %eax
  2887. depending on how we transformed the TLS_GOTDESC above.
  2888. */
  2889. bfd_vma roff;
  2890. roff = rel->r_offset;
  2891. /* Now modify the instruction as appropriate. */
  2892. if (tls_type != GOT_TLS_IE_NEG)
  2893. {
  2894. /* xchg %ax,%ax */
  2895. bfd_put_8 (output_bfd, 0x66, contents + roff);
  2896. bfd_put_8 (output_bfd, 0x90, contents + roff + 1);
  2897. }
  2898. else
  2899. {
  2900. /* negl %eax */
  2901. bfd_put_8 (output_bfd, 0xf7, contents + roff);
  2902. bfd_put_8 (output_bfd, 0xd8, contents + roff + 1);
  2903. }
  2904. continue;
  2905. }
  2906. else
  2907. BFD_ASSERT (false);
  2908. break;
  2909. case R_386_TLS_LDM:
  2910. if (! elf_i386_tls_transition (info, input_bfd,
  2911. input_section, contents,
  2912. symtab_hdr, sym_hashes,
  2913. &r_type, GOT_UNKNOWN, rel,
  2914. relend, h, r_symndx, true))
  2915. return false;
  2916. if (r_type != R_386_TLS_LDM)
  2917. {
  2918. /* LD->LE transition. Change
  2919. leal foo@tlsldm(%ebx) %eax
  2920. call ___tls_get_addr@PLT
  2921. into:
  2922. movl %gs:0, %eax
  2923. nop
  2924. leal 0(%esi,1), %esi
  2925. or change
  2926. leal foo@tlsldm(%reg) %eax
  2927. call *___tls_get_addr@GOT(%reg)
  2928. which may be converted to
  2929. addr32 call ___tls_get_addr
  2930. into:
  2931. movl %gs:0, %eax
  2932. leal 0(%esi), %esi */
  2933. BFD_ASSERT (r_type == R_386_TLS_LE_32);
  2934. if (*(contents + rel->r_offset + 4) == 0xff
  2935. || *(contents + rel->r_offset + 4) == 0x67)
  2936. memcpy (contents + rel->r_offset - 2,
  2937. "\x65\xa1\0\0\0\0\x8d\xb6\0\0\0", 12);
  2938. else
  2939. memcpy (contents + rel->r_offset - 2,
  2940. "\x65\xa1\0\0\0\0\x90\x8d\x74\x26", 11);
  2941. /* Skip R_386_PC32/R_386_PLT32. */
  2942. rel++;
  2943. wrel++;
  2944. continue;
  2945. }
  2946. if (htab->elf.sgot == NULL)
  2947. abort ();
  2948. off = htab->tls_ld_or_ldm_got.offset;
  2949. if (off & 1)
  2950. off &= ~1;
  2951. else
  2952. {
  2953. Elf_Internal_Rela outrel;
  2954. if (htab->elf.srelgot == NULL)
  2955. abort ();
  2956. outrel.r_offset = (htab->elf.sgot->output_section->vma
  2957. + htab->elf.sgot->output_offset + off);
  2958. bfd_put_32 (output_bfd, 0,
  2959. htab->elf.sgot->contents + off);
  2960. bfd_put_32 (output_bfd, 0,
  2961. htab->elf.sgot->contents + off + 4);
  2962. outrel.r_info = ELF32_R_INFO (0, R_386_TLS_DTPMOD32);
  2963. elf_append_rel (output_bfd, htab->elf.srelgot, &outrel);
  2964. htab->tls_ld_or_ldm_got.offset |= 1;
  2965. }
  2966. relocation = htab->elf.sgot->output_section->vma
  2967. + htab->elf.sgot->output_offset + off
  2968. - htab->elf.sgotplt->output_section->vma
  2969. - htab->elf.sgotplt->output_offset;
  2970. unresolved_reloc = false;
  2971. break;
  2972. case R_386_TLS_LDO_32:
  2973. if (!bfd_link_executable (info)
  2974. || (input_section->flags & SEC_CODE) == 0)
  2975. relocation -= _bfd_x86_elf_dtpoff_base (info);
  2976. else
  2977. /* When converting LDO to LE, we must negate. */
  2978. relocation = -elf_i386_tpoff (info, relocation);
  2979. break;
  2980. case R_386_TLS_LE_32:
  2981. case R_386_TLS_LE:
  2982. if (!bfd_link_executable (info))
  2983. {
  2984. Elf_Internal_Rela outrel;
  2985. asection *sreloc;
  2986. outrel.r_offset = rel->r_offset
  2987. + input_section->output_section->vma
  2988. + input_section->output_offset;
  2989. if (h != NULL && h->dynindx != -1)
  2990. indx = h->dynindx;
  2991. else
  2992. indx = 0;
  2993. if (r_type == R_386_TLS_LE_32)
  2994. outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF32);
  2995. else
  2996. outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
  2997. sreloc = elf_section_data (input_section)->sreloc;
  2998. if (sreloc == NULL)
  2999. abort ();
  3000. elf_append_rel (output_bfd, sreloc, &outrel);
  3001. if (indx)
  3002. continue;
  3003. else if (r_type == R_386_TLS_LE_32)
  3004. relocation = _bfd_x86_elf_dtpoff_base (info) - relocation;
  3005. else
  3006. relocation -= _bfd_x86_elf_dtpoff_base (info);
  3007. }
  3008. else if (r_type == R_386_TLS_LE_32)
  3009. relocation = elf_i386_tpoff (info, relocation);
  3010. else
  3011. relocation = -elf_i386_tpoff (info, relocation);
  3012. break;
  3013. default:
  3014. break;
  3015. }
  3016. /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
  3017. because such sections are not SEC_ALLOC and thus ld.so will
  3018. not process them. */
  3019. if (unresolved_reloc
  3020. && !((input_section->flags & SEC_DEBUGGING) != 0
  3021. && h->def_dynamic)
  3022. && _bfd_elf_section_offset (output_bfd, info, input_section,
  3023. rel->r_offset) != (bfd_vma) -1)
  3024. {
  3025. _bfd_error_handler
  3026. /* xgettext:c-format */
  3027. (_("%pB(%pA+%#" PRIx64 "): unresolvable %s relocation against symbol `%s'"),
  3028. input_bfd,
  3029. input_section,
  3030. (uint64_t) rel->r_offset,
  3031. howto->name,
  3032. h->root.root.string);
  3033. return false;
  3034. }
  3035. do_relocation:
  3036. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  3037. contents, rel->r_offset,
  3038. relocation, 0);
  3039. check_relocation_error:
  3040. if (r != bfd_reloc_ok)
  3041. {
  3042. const char *name;
  3043. if (h != NULL)
  3044. name = h->root.root.string;
  3045. else
  3046. {
  3047. name = bfd_elf_string_from_elf_section (input_bfd,
  3048. symtab_hdr->sh_link,
  3049. sym->st_name);
  3050. if (name == NULL)
  3051. return false;
  3052. if (*name == '\0')
  3053. name = bfd_section_name (sec);
  3054. }
  3055. if (r == bfd_reloc_overflow)
  3056. (*info->callbacks->reloc_overflow)
  3057. (info, (h ? &h->root : NULL), name, howto->name,
  3058. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  3059. else
  3060. {
  3061. _bfd_error_handler
  3062. /* xgettext:c-format */
  3063. (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
  3064. input_bfd, input_section,
  3065. (uint64_t) rel->r_offset, name, (int) r);
  3066. return false;
  3067. }
  3068. }
  3069. if (wrel != rel)
  3070. *wrel = *rel;
  3071. }
  3072. if (wrel != rel)
  3073. {
  3074. Elf_Internal_Shdr *rel_hdr;
  3075. size_t deleted = rel - wrel;
  3076. rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
  3077. rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
  3078. if (rel_hdr->sh_size == 0)
  3079. {
  3080. /* It is too late to remove an empty reloc section. Leave
  3081. one NONE reloc.
  3082. ??? What is wrong with an empty section??? */
  3083. rel_hdr->sh_size = rel_hdr->sh_entsize;
  3084. deleted -= 1;
  3085. }
  3086. rel_hdr = _bfd_elf_single_rel_hdr (input_section);
  3087. rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
  3088. input_section->reloc_count -= deleted;
  3089. }
  3090. return true;
  3091. }
  3092. /* Finish up dynamic symbol handling. We set the contents of various
  3093. dynamic sections here. */
  3094. static bool
  3095. elf_i386_finish_dynamic_symbol (bfd *output_bfd,
  3096. struct bfd_link_info *info,
  3097. struct elf_link_hash_entry *h,
  3098. Elf_Internal_Sym *sym)
  3099. {
  3100. struct elf_x86_link_hash_table *htab;
  3101. unsigned plt_entry_size;
  3102. struct elf_x86_link_hash_entry *eh;
  3103. bool local_undefweak;
  3104. bool use_plt_second;
  3105. htab = elf_x86_hash_table (info, I386_ELF_DATA);
  3106. if (htab == NULL)
  3107. return false;
  3108. plt_entry_size = htab->plt.plt_entry_size;
  3109. /* Use the second PLT section only if there is .plt section. */
  3110. use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL;
  3111. eh = (struct elf_x86_link_hash_entry *) h;
  3112. if (eh->no_finish_dynamic_symbol)
  3113. abort ();
  3114. /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
  3115. resolved undefined weak symbols in executable so that their
  3116. references have value 0 at run-time. */
  3117. local_undefweak = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
  3118. if (h->plt.offset != (bfd_vma) -1)
  3119. {
  3120. bfd_vma plt_index, plt_offset;
  3121. bfd_vma got_offset;
  3122. Elf_Internal_Rela rel;
  3123. bfd_byte *loc;
  3124. asection *plt, *resolved_plt, *gotplt, *relplt;
  3125. /* When building a static executable, use .iplt, .igot.plt and
  3126. .rel.iplt sections for STT_GNU_IFUNC symbols. */
  3127. if (htab->elf.splt != NULL)
  3128. {
  3129. plt = htab->elf.splt;
  3130. gotplt = htab->elf.sgotplt;
  3131. relplt = htab->elf.srelplt;
  3132. }
  3133. else
  3134. {
  3135. plt = htab->elf.iplt;
  3136. gotplt = htab->elf.igotplt;
  3137. relplt = htab->elf.irelplt;
  3138. }
  3139. VERIFY_PLT_ENTRY (info, h, plt, gotplt, relplt, local_undefweak)
  3140. /* Get the index in the procedure linkage table which
  3141. corresponds to this symbol. This is the index of this symbol
  3142. in all the symbols for which we are making plt entries. The
  3143. first entry in the procedure linkage table is reserved.
  3144. Get the offset into the .got table of the entry that
  3145. corresponds to this function. Each .got entry is 4 bytes.
  3146. The first three are reserved.
  3147. For static executables, we don't reserve anything. */
  3148. if (plt == htab->elf.splt)
  3149. {
  3150. got_offset = (h->plt.offset / plt_entry_size
  3151. - htab->plt.has_plt0);
  3152. got_offset = (got_offset + 3) * 4;
  3153. }
  3154. else
  3155. {
  3156. got_offset = h->plt.offset / plt_entry_size;
  3157. got_offset = got_offset * 4;
  3158. }
  3159. /* Fill in the entry in the procedure linkage table and update
  3160. the first slot. */
  3161. memcpy (plt->contents + h->plt.offset, htab->plt.plt_entry,
  3162. plt_entry_size);
  3163. if (use_plt_second)
  3164. {
  3165. const bfd_byte *plt_entry;
  3166. if (bfd_link_pic (info))
  3167. plt_entry = htab->non_lazy_plt->pic_plt_entry;
  3168. else
  3169. plt_entry = htab->non_lazy_plt->plt_entry;
  3170. memcpy (htab->plt_second->contents + eh->plt_second.offset,
  3171. plt_entry, htab->non_lazy_plt->plt_entry_size);
  3172. resolved_plt = htab->plt_second;
  3173. plt_offset = eh->plt_second.offset;
  3174. }
  3175. else
  3176. {
  3177. resolved_plt = plt;
  3178. plt_offset = h->plt.offset;
  3179. }
  3180. if (! bfd_link_pic (info))
  3181. {
  3182. bfd_put_32 (output_bfd,
  3183. (gotplt->output_section->vma
  3184. + gotplt->output_offset
  3185. + got_offset),
  3186. resolved_plt->contents + plt_offset
  3187. + htab->plt.plt_got_offset);
  3188. if (htab->elf.target_os == is_vxworks)
  3189. {
  3190. int s, k, reloc_index;
  3191. /* Create the R_386_32 relocation referencing the GOT
  3192. for this PLT entry. */
  3193. /* S: Current slot number (zero-based). */
  3194. s = ((h->plt.offset - htab->plt.plt_entry_size)
  3195. / htab->plt.plt_entry_size);
  3196. /* K: Number of relocations for PLTResolve. */
  3197. if (bfd_link_pic (info))
  3198. k = PLTRESOLVE_RELOCS_SHLIB;
  3199. else
  3200. k = PLTRESOLVE_RELOCS;
  3201. /* Skip the PLTresolve relocations, and the relocations for
  3202. the other PLT slots. */
  3203. reloc_index = k + s * PLT_NON_JUMP_SLOT_RELOCS;
  3204. loc = (htab->srelplt2->contents + reloc_index
  3205. * sizeof (Elf32_External_Rel));
  3206. rel.r_offset = (plt->output_section->vma
  3207. + plt->output_offset
  3208. + h->plt.offset + 2),
  3209. rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32);
  3210. bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
  3211. /* Create the R_386_32 relocation referencing the beginning of
  3212. the PLT for this GOT entry. */
  3213. rel.r_offset = (htab->elf.sgotplt->output_section->vma
  3214. + htab->elf.sgotplt->output_offset
  3215. + got_offset);
  3216. rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32);
  3217. bfd_elf32_swap_reloc_out (output_bfd, &rel,
  3218. loc + sizeof (Elf32_External_Rel));
  3219. }
  3220. }
  3221. else
  3222. {
  3223. bfd_put_32 (output_bfd, got_offset,
  3224. resolved_plt->contents + plt_offset
  3225. + htab->plt.plt_got_offset);
  3226. }
  3227. /* Fill in the entry in the global offset table. Leave the entry
  3228. as zero for undefined weak symbol in PIE. No PLT relocation
  3229. against undefined weak symbol in PIE. */
  3230. if (!local_undefweak)
  3231. {
  3232. if (htab->plt.has_plt0)
  3233. bfd_put_32 (output_bfd,
  3234. (plt->output_section->vma
  3235. + plt->output_offset
  3236. + h->plt.offset
  3237. + htab->lazy_plt->plt_lazy_offset),
  3238. gotplt->contents + got_offset);
  3239. /* Fill in the entry in the .rel.plt section. */
  3240. rel.r_offset = (gotplt->output_section->vma
  3241. + gotplt->output_offset
  3242. + got_offset);
  3243. if (PLT_LOCAL_IFUNC_P (info, h))
  3244. {
  3245. info->callbacks->minfo (_("Local IFUNC function `%s' in %pB\n"),
  3246. h->root.root.string,
  3247. h->root.u.def.section->owner);
  3248. /* If an STT_GNU_IFUNC symbol is locally defined, generate
  3249. R_386_IRELATIVE instead of R_386_JUMP_SLOT. Store addend
  3250. in the .got.plt section. */
  3251. bfd_put_32 (output_bfd,
  3252. (h->root.u.def.value
  3253. + h->root.u.def.section->output_section->vma
  3254. + h->root.u.def.section->output_offset),
  3255. gotplt->contents + got_offset);
  3256. rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
  3257. if (htab->params->report_relative_reloc)
  3258. _bfd_x86_elf_link_report_relative_reloc
  3259. (info, relplt, h, sym, "R_386_IRELATIVE", &rel);
  3260. /* R_386_IRELATIVE comes last. */
  3261. plt_index = htab->next_irelative_index--;
  3262. }
  3263. else
  3264. {
  3265. rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT);
  3266. plt_index = htab->next_jump_slot_index++;
  3267. }
  3268. loc = relplt->contents + plt_index * sizeof (Elf32_External_Rel);
  3269. bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
  3270. /* Don't fill the second and third slots in PLT entry for
  3271. static executables nor without PLT0. */
  3272. if (plt == htab->elf.splt && htab->plt.has_plt0)
  3273. {
  3274. bfd_put_32 (output_bfd,
  3275. plt_index * sizeof (Elf32_External_Rel),
  3276. plt->contents + h->plt.offset
  3277. + htab->lazy_plt->plt_reloc_offset);
  3278. bfd_put_32 (output_bfd,
  3279. - (h->plt.offset
  3280. + htab->lazy_plt->plt_plt_offset + 4),
  3281. (plt->contents + h->plt.offset
  3282. + htab->lazy_plt->plt_plt_offset));
  3283. }
  3284. }
  3285. }
  3286. else if (eh->plt_got.offset != (bfd_vma) -1)
  3287. {
  3288. bfd_vma got_offset, plt_offset;
  3289. asection *plt, *got, *gotplt;
  3290. const bfd_byte *got_plt_entry;
  3291. /* Set the entry in the GOT procedure linkage table. */
  3292. plt = htab->plt_got;
  3293. got = htab->elf.sgot;
  3294. gotplt = htab->elf.sgotplt;
  3295. got_offset = h->got.offset;
  3296. if (got_offset == (bfd_vma) -1
  3297. || plt == NULL
  3298. || got == NULL
  3299. || gotplt == NULL)
  3300. abort ();
  3301. /* Fill in the entry in the GOT procedure linkage table. */
  3302. if (! bfd_link_pic (info))
  3303. {
  3304. got_plt_entry = htab->non_lazy_plt->plt_entry;
  3305. got_offset += got->output_section->vma + got->output_offset;
  3306. }
  3307. else
  3308. {
  3309. got_plt_entry = htab->non_lazy_plt->pic_plt_entry;
  3310. got_offset += (got->output_section->vma
  3311. + got->output_offset
  3312. - gotplt->output_section->vma
  3313. - gotplt->output_offset);
  3314. }
  3315. plt_offset = eh->plt_got.offset;
  3316. memcpy (plt->contents + plt_offset, got_plt_entry,
  3317. htab->non_lazy_plt->plt_entry_size);
  3318. bfd_put_32 (output_bfd, got_offset,
  3319. (plt->contents + plt_offset
  3320. + htab->non_lazy_plt->plt_got_offset));
  3321. }
  3322. if (!local_undefweak
  3323. && !h->def_regular
  3324. && (h->plt.offset != (bfd_vma) -1
  3325. || eh->plt_got.offset != (bfd_vma) -1))
  3326. {
  3327. /* Mark the symbol as undefined, rather than as defined in
  3328. the .plt section. Leave the value if there were any
  3329. relocations where pointer equality matters (this is a clue
  3330. for the dynamic linker, to make function pointer
  3331. comparisons work between an application and shared
  3332. library), otherwise set it to zero. If a function is only
  3333. called from a binary, there is no need to slow down
  3334. shared libraries because of that. */
  3335. sym->st_shndx = SHN_UNDEF;
  3336. if (!h->pointer_equality_needed)
  3337. sym->st_value = 0;
  3338. }
  3339. _bfd_x86_elf_link_fixup_ifunc_symbol (info, htab, h, sym);
  3340. /* Don't generate dynamic GOT relocation against undefined weak
  3341. symbol in executable. */
  3342. if (h->got.offset != (bfd_vma) -1
  3343. && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry(h)->tls_type)
  3344. && (elf_x86_hash_entry(h)->tls_type & GOT_TLS_IE) == 0
  3345. && !local_undefweak)
  3346. {
  3347. Elf_Internal_Rela rel;
  3348. asection *relgot = htab->elf.srelgot;
  3349. const char *relative_reloc_name = NULL;
  3350. bool generate_dynamic_reloc = true;
  3351. /* This symbol has an entry in the global offset table. Set it
  3352. up. */
  3353. if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
  3354. abort ();
  3355. rel.r_offset = (htab->elf.sgot->output_section->vma
  3356. + htab->elf.sgot->output_offset
  3357. + (h->got.offset & ~(bfd_vma) 1));
  3358. /* If this is a static link, or it is a -Bsymbolic link and the
  3359. symbol is defined locally or was forced to be local because
  3360. of a version file, we just want to emit a RELATIVE reloc.
  3361. The entry in the global offset table will already have been
  3362. initialized in the relocate_section function. */
  3363. if (h->def_regular
  3364. && h->type == STT_GNU_IFUNC)
  3365. {
  3366. if (h->plt.offset == (bfd_vma) -1)
  3367. {
  3368. /* STT_GNU_IFUNC is referenced without PLT. */
  3369. if (htab->elf.splt == NULL)
  3370. {
  3371. /* use .rel[a].iplt section to store .got relocations
  3372. in static executable. */
  3373. relgot = htab->elf.irelplt;
  3374. }
  3375. if (SYMBOL_REFERENCES_LOCAL_P (info, h))
  3376. {
  3377. info->callbacks->minfo (_("Local IFUNC function `%s' in %pB\n"),
  3378. h->root.root.string,
  3379. h->root.u.def.section->owner);
  3380. bfd_put_32 (output_bfd,
  3381. (h->root.u.def.value
  3382. + h->root.u.def.section->output_section->vma
  3383. + h->root.u.def.section->output_offset),
  3384. htab->elf.sgot->contents + h->got.offset);
  3385. rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
  3386. relative_reloc_name = "R_386_IRELATIVE";
  3387. }
  3388. else
  3389. goto do_glob_dat;
  3390. }
  3391. else if (bfd_link_pic (info))
  3392. {
  3393. /* Generate R_386_GLOB_DAT. */
  3394. goto do_glob_dat;
  3395. }
  3396. else
  3397. {
  3398. asection *plt;
  3399. bfd_vma plt_offset;
  3400. if (!h->pointer_equality_needed)
  3401. abort ();
  3402. /* For non-shared object, we can't use .got.plt, which
  3403. contains the real function addres if we need pointer
  3404. equality. We load the GOT entry with the PLT entry. */
  3405. if (htab->plt_second != NULL)
  3406. {
  3407. plt = htab->plt_second;
  3408. plt_offset = eh->plt_second.offset;
  3409. }
  3410. else
  3411. {
  3412. plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
  3413. plt_offset = h->plt.offset;
  3414. }
  3415. bfd_put_32 (output_bfd,
  3416. (plt->output_section->vma
  3417. + plt->output_offset + plt_offset),
  3418. htab->elf.sgot->contents + h->got.offset);
  3419. return true;
  3420. }
  3421. }
  3422. else if (bfd_link_pic (info)
  3423. && SYMBOL_REFERENCES_LOCAL_P (info, h))
  3424. {
  3425. BFD_ASSERT((h->got.offset & 1) != 0);
  3426. if (info->enable_dt_relr)
  3427. generate_dynamic_reloc = false;
  3428. else
  3429. {
  3430. rel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
  3431. relative_reloc_name = "R_386_RELATIVE";
  3432. }
  3433. }
  3434. else
  3435. {
  3436. BFD_ASSERT((h->got.offset & 1) == 0);
  3437. do_glob_dat:
  3438. bfd_put_32 (output_bfd, (bfd_vma) 0,
  3439. htab->elf.sgot->contents + h->got.offset);
  3440. rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
  3441. }
  3442. if (generate_dynamic_reloc)
  3443. {
  3444. if (relative_reloc_name != NULL
  3445. && htab->params->report_relative_reloc)
  3446. _bfd_x86_elf_link_report_relative_reloc
  3447. (info, relgot, h, sym, relative_reloc_name, &rel);
  3448. elf_append_rel (output_bfd, relgot, &rel);
  3449. }
  3450. }
  3451. if (h->needs_copy)
  3452. {
  3453. Elf_Internal_Rela rel;
  3454. asection *s;
  3455. /* This symbol needs a copy reloc. Set it up. */
  3456. VERIFY_COPY_RELOC (h, htab)
  3457. rel.r_offset = (h->root.u.def.value
  3458. + h->root.u.def.section->output_section->vma
  3459. + h->root.u.def.section->output_offset);
  3460. rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY);
  3461. if (h->root.u.def.section == htab->elf.sdynrelro)
  3462. s = htab->elf.sreldynrelro;
  3463. else
  3464. s = htab->elf.srelbss;
  3465. elf_append_rel (output_bfd, s, &rel);
  3466. }
  3467. return true;
  3468. }
  3469. /* Finish up local dynamic symbol handling. We set the contents of
  3470. various dynamic sections here. */
  3471. static int
  3472. elf_i386_finish_local_dynamic_symbol (void **slot, void *inf)
  3473. {
  3474. struct elf_link_hash_entry *h
  3475. = (struct elf_link_hash_entry *) *slot;
  3476. struct bfd_link_info *info
  3477. = (struct bfd_link_info *) inf;
  3478. return elf_i386_finish_dynamic_symbol (info->output_bfd, info,
  3479. h, NULL);
  3480. }
  3481. /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
  3482. here since undefined weak symbol may not be dynamic and may not be
  3483. called for elf_i386_finish_dynamic_symbol. */
  3484. static bool
  3485. elf_i386_pie_finish_undefweak_symbol (struct bfd_hash_entry *bh,
  3486. void *inf)
  3487. {
  3488. struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh;
  3489. struct bfd_link_info *info = (struct bfd_link_info *) inf;
  3490. if (h->root.type != bfd_link_hash_undefweak
  3491. || h->dynindx != -1)
  3492. return true;
  3493. return elf_i386_finish_dynamic_symbol (info->output_bfd,
  3494. info, h, NULL);
  3495. }
  3496. /* Used to decide how to sort relocs in an optimal manner for the
  3497. dynamic linker, before writing them out. */
  3498. static enum elf_reloc_type_class
  3499. elf_i386_reloc_type_class (const struct bfd_link_info *info,
  3500. const asection *rel_sec ATTRIBUTE_UNUSED,
  3501. const Elf_Internal_Rela *rela)
  3502. {
  3503. bfd *abfd = info->output_bfd;
  3504. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  3505. struct elf_link_hash_table *htab = elf_hash_table (info);
  3506. if (htab->dynsym != NULL
  3507. && htab->dynsym->contents != NULL)
  3508. {
  3509. /* Check relocation against STT_GNU_IFUNC symbol if there are
  3510. dynamic symbols. */
  3511. unsigned long r_symndx = ELF32_R_SYM (rela->r_info);
  3512. if (r_symndx != STN_UNDEF)
  3513. {
  3514. Elf_Internal_Sym sym;
  3515. if (!bed->s->swap_symbol_in (abfd,
  3516. (htab->dynsym->contents
  3517. + r_symndx * sizeof (Elf32_External_Sym)),
  3518. 0, &sym))
  3519. abort ();
  3520. if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
  3521. return reloc_class_ifunc;
  3522. }
  3523. }
  3524. switch (ELF32_R_TYPE (rela->r_info))
  3525. {
  3526. case R_386_IRELATIVE:
  3527. return reloc_class_ifunc;
  3528. case R_386_RELATIVE:
  3529. return reloc_class_relative;
  3530. case R_386_JUMP_SLOT:
  3531. return reloc_class_plt;
  3532. case R_386_COPY:
  3533. return reloc_class_copy;
  3534. default:
  3535. return reloc_class_normal;
  3536. }
  3537. }
  3538. /* Finish up the dynamic sections. */
  3539. static bool
  3540. elf_i386_finish_dynamic_sections (bfd *output_bfd,
  3541. struct bfd_link_info *info)
  3542. {
  3543. struct elf_x86_link_hash_table *htab;
  3544. htab = _bfd_x86_elf_finish_dynamic_sections (output_bfd, info);
  3545. if (htab == NULL)
  3546. return false;
  3547. if (!htab->elf.dynamic_sections_created)
  3548. return true;
  3549. if (htab->elf.splt && htab->elf.splt->size > 0)
  3550. {
  3551. if (bfd_is_abs_section (htab->elf.splt->output_section))
  3552. {
  3553. info->callbacks->einfo
  3554. (_("%F%P: discarded output section: `%pA'\n"),
  3555. htab->elf.splt);
  3556. return false;
  3557. }
  3558. /* UnixWare sets the entsize of .plt to 4, although that doesn't
  3559. really seem like the right value. */
  3560. elf_section_data (htab->elf.splt->output_section)
  3561. ->this_hdr.sh_entsize = 4;
  3562. if (htab->plt.has_plt0)
  3563. {
  3564. /* Fill in the special first entry in the procedure linkage
  3565. table. */
  3566. memcpy (htab->elf.splt->contents, htab->plt.plt0_entry,
  3567. htab->lazy_plt->plt0_entry_size);
  3568. memset (htab->elf.splt->contents + htab->lazy_plt->plt0_entry_size,
  3569. htab->plt0_pad_byte,
  3570. htab->plt.plt_entry_size - htab->lazy_plt->plt0_entry_size);
  3571. if (!bfd_link_pic (info))
  3572. {
  3573. bfd_put_32 (output_bfd,
  3574. (htab->elf.sgotplt->output_section->vma
  3575. + htab->elf.sgotplt->output_offset
  3576. + 4),
  3577. htab->elf.splt->contents
  3578. + htab->lazy_plt->plt0_got1_offset);
  3579. bfd_put_32 (output_bfd,
  3580. (htab->elf.sgotplt->output_section->vma
  3581. + htab->elf.sgotplt->output_offset
  3582. + 8),
  3583. htab->elf.splt->contents
  3584. + htab->lazy_plt->plt0_got2_offset);
  3585. if (htab->elf.target_os == is_vxworks)
  3586. {
  3587. Elf_Internal_Rela rel;
  3588. int num_plts = (htab->elf.splt->size
  3589. / htab->plt.plt_entry_size) - 1;
  3590. unsigned char *p;
  3591. asection *srelplt2 = htab->srelplt2;
  3592. /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
  3593. + 4. On IA32 we use REL relocations so the
  3594. addend goes in the PLT directly. */
  3595. rel.r_offset = (htab->elf.splt->output_section->vma
  3596. + htab->elf.splt->output_offset
  3597. + htab->lazy_plt->plt0_got1_offset);
  3598. rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
  3599. R_386_32);
  3600. bfd_elf32_swap_reloc_out (output_bfd, &rel,
  3601. srelplt2->contents);
  3602. /* Generate a relocation for _GLOBAL_OFFSET_TABLE_
  3603. + 8. */
  3604. rel.r_offset = (htab->elf.splt->output_section->vma
  3605. + htab->elf.splt->output_offset
  3606. + htab->lazy_plt->plt0_got2_offset);
  3607. rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
  3608. R_386_32);
  3609. bfd_elf32_swap_reloc_out (output_bfd, &rel,
  3610. srelplt2->contents +
  3611. sizeof (Elf32_External_Rel));
  3612. /* Correct the .rel.plt.unloaded relocations. */
  3613. p = srelplt2->contents;
  3614. if (bfd_link_pic (info))
  3615. p += PLTRESOLVE_RELOCS_SHLIB * sizeof (Elf32_External_Rel);
  3616. else
  3617. p += PLTRESOLVE_RELOCS * sizeof (Elf32_External_Rel);
  3618. for (; num_plts; num_plts--)
  3619. {
  3620. bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
  3621. rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
  3622. R_386_32);
  3623. bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
  3624. p += sizeof (Elf32_External_Rel);
  3625. bfd_elf32_swap_reloc_in (output_bfd, p, &rel);
  3626. rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
  3627. R_386_32);
  3628. bfd_elf32_swap_reloc_out (output_bfd, &rel, p);
  3629. p += sizeof (Elf32_External_Rel);
  3630. }
  3631. }
  3632. }
  3633. }
  3634. }
  3635. /* Fill PLT entries for undefined weak symbols in PIE. */
  3636. if (bfd_link_pie (info))
  3637. bfd_hash_traverse (&info->hash->table,
  3638. elf_i386_pie_finish_undefweak_symbol,
  3639. info);
  3640. return true;
  3641. }
  3642. /* Fill PLT/GOT entries and allocate dynamic relocations for local
  3643. STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
  3644. It has to be done before elf_link_sort_relocs is called so that
  3645. dynamic relocations are properly sorted. */
  3646. static bool
  3647. elf_i386_output_arch_local_syms
  3648. (bfd *output_bfd ATTRIBUTE_UNUSED,
  3649. struct bfd_link_info *info,
  3650. void *flaginfo ATTRIBUTE_UNUSED,
  3651. int (*func) (void *, const char *,
  3652. Elf_Internal_Sym *,
  3653. asection *,
  3654. struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
  3655. {
  3656. struct elf_x86_link_hash_table *htab
  3657. = elf_x86_hash_table (info, I386_ELF_DATA);
  3658. if (htab == NULL)
  3659. return false;
  3660. /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
  3661. htab_traverse (htab->loc_hash_table,
  3662. elf_i386_finish_local_dynamic_symbol,
  3663. info);
  3664. return true;
  3665. }
  3666. /* Similar to _bfd_elf_get_synthetic_symtab. Support PLTs with all
  3667. dynamic relocations. */
  3668. static long
  3669. elf_i386_get_synthetic_symtab (bfd *abfd,
  3670. long symcount ATTRIBUTE_UNUSED,
  3671. asymbol **syms ATTRIBUTE_UNUSED,
  3672. long dynsymcount,
  3673. asymbol **dynsyms,
  3674. asymbol **ret)
  3675. {
  3676. long count, i, n;
  3677. int j;
  3678. bfd_byte *plt_contents;
  3679. long relsize;
  3680. const struct elf_x86_lazy_plt_layout *lazy_plt;
  3681. const struct elf_x86_non_lazy_plt_layout *non_lazy_plt;
  3682. const struct elf_x86_lazy_plt_layout *lazy_ibt_plt;
  3683. const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt;
  3684. asection *plt;
  3685. bfd_vma got_addr;
  3686. enum elf_x86_plt_type plt_type;
  3687. struct elf_x86_plt plts[] =
  3688. {
  3689. { ".plt", NULL, NULL, plt_unknown, 0, 0, 0, 0 },
  3690. { ".plt.got", NULL, NULL, plt_non_lazy, 0, 0, 0, 0 },
  3691. { ".plt.sec", NULL, NULL, plt_second, 0, 0, 0, 0 },
  3692. { NULL, NULL, NULL, plt_non_lazy, 0, 0, 0, 0 }
  3693. };
  3694. *ret = NULL;
  3695. if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
  3696. return 0;
  3697. if (dynsymcount <= 0)
  3698. return 0;
  3699. relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
  3700. if (relsize <= 0)
  3701. return -1;
  3702. non_lazy_plt = NULL;
  3703. /* Silence GCC 6. */
  3704. lazy_plt = NULL;
  3705. non_lazy_ibt_plt = NULL;
  3706. lazy_ibt_plt = NULL;
  3707. switch (get_elf_backend_data (abfd)->target_os)
  3708. {
  3709. case is_normal:
  3710. case is_solaris:
  3711. non_lazy_plt = &elf_i386_non_lazy_plt;
  3712. lazy_ibt_plt = &elf_i386_lazy_ibt_plt;
  3713. non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt;
  3714. /* Fall through */
  3715. case is_vxworks:
  3716. lazy_plt = &elf_i386_lazy_plt;
  3717. break;
  3718. default:
  3719. abort ();
  3720. }
  3721. got_addr = 0;
  3722. count = 0;
  3723. for (j = 0; plts[j].name != NULL; j++)
  3724. {
  3725. plt = bfd_get_section_by_name (abfd, plts[j].name);
  3726. if (plt == NULL || plt->size == 0)
  3727. continue;
  3728. /* Get the PLT section contents. */
  3729. plt_contents = (bfd_byte *) bfd_malloc (plt->size);
  3730. if (plt_contents == NULL)
  3731. break;
  3732. if (!bfd_get_section_contents (abfd, (asection *) plt,
  3733. plt_contents, 0, plt->size))
  3734. {
  3735. free (plt_contents);
  3736. break;
  3737. }
  3738. /* Check what kind of PLT it is. */
  3739. plt_type = plt_unknown;
  3740. if (plts[j].type == plt_unknown
  3741. && (plt->size >= (lazy_plt->plt0_entry_size
  3742. + lazy_plt->plt_entry_size)))
  3743. {
  3744. /* Match lazy PLT first. */
  3745. if (memcmp (plt_contents, lazy_plt->plt0_entry,
  3746. lazy_plt->plt0_got1_offset) == 0)
  3747. {
  3748. /* The fist entry in the lazy IBT PLT is the same as the
  3749. normal lazy PLT. */
  3750. if (lazy_ibt_plt != NULL
  3751. && (memcmp (plt_contents + lazy_ibt_plt->plt0_entry_size,
  3752. lazy_ibt_plt->plt_entry,
  3753. lazy_ibt_plt->plt_got_offset) == 0))
  3754. plt_type = plt_lazy | plt_second;
  3755. else
  3756. plt_type = plt_lazy;
  3757. }
  3758. else if (memcmp (plt_contents, lazy_plt->pic_plt0_entry,
  3759. lazy_plt->plt0_got1_offset) == 0)
  3760. {
  3761. /* The fist entry in the PIC lazy IBT PLT is the same as
  3762. the normal PIC lazy PLT. */
  3763. if (lazy_ibt_plt != NULL
  3764. && (memcmp (plt_contents + lazy_ibt_plt->plt0_entry_size,
  3765. lazy_ibt_plt->pic_plt_entry,
  3766. lazy_ibt_plt->plt_got_offset) == 0))
  3767. plt_type = plt_lazy | plt_pic | plt_second;
  3768. else
  3769. plt_type = plt_lazy | plt_pic;
  3770. }
  3771. }
  3772. if (non_lazy_plt != NULL
  3773. && (plt_type == plt_unknown || plt_type == plt_non_lazy)
  3774. && plt->size >= non_lazy_plt->plt_entry_size)
  3775. {
  3776. /* Match non-lazy PLT. */
  3777. if (memcmp (plt_contents, non_lazy_plt->plt_entry,
  3778. non_lazy_plt->plt_got_offset) == 0)
  3779. plt_type = plt_non_lazy;
  3780. else if (memcmp (plt_contents, non_lazy_plt->pic_plt_entry,
  3781. non_lazy_plt->plt_got_offset) == 0)
  3782. plt_type = plt_pic;
  3783. }
  3784. if ((non_lazy_ibt_plt != NULL)
  3785. && (plt_type == plt_unknown || plt_type == plt_second)
  3786. && plt->size >= non_lazy_ibt_plt->plt_entry_size)
  3787. {
  3788. if (memcmp (plt_contents,
  3789. non_lazy_ibt_plt->plt_entry,
  3790. non_lazy_ibt_plt->plt_got_offset) == 0)
  3791. {
  3792. /* Match IBT PLT. */
  3793. plt_type = plt_second;
  3794. non_lazy_plt = non_lazy_ibt_plt;
  3795. }
  3796. else if (memcmp (plt_contents,
  3797. non_lazy_ibt_plt->pic_plt_entry,
  3798. non_lazy_ibt_plt->plt_got_offset) == 0)
  3799. {
  3800. /* Match PIC IBT PLT. */
  3801. plt_type = plt_second | plt_pic;
  3802. non_lazy_plt = non_lazy_ibt_plt;
  3803. }
  3804. }
  3805. if (plt_type == plt_unknown)
  3806. {
  3807. free (plt_contents);
  3808. continue;
  3809. }
  3810. plts[j].sec = plt;
  3811. plts[j].type = plt_type;
  3812. if ((plt_type & plt_lazy))
  3813. {
  3814. plts[j].plt_got_offset = lazy_plt->plt_got_offset;
  3815. plts[j].plt_entry_size = lazy_plt->plt_entry_size;
  3816. /* Skip PLT0 in lazy PLT. */
  3817. i = 1;
  3818. }
  3819. else
  3820. {
  3821. plts[j].plt_got_offset = non_lazy_plt->plt_got_offset;
  3822. plts[j].plt_entry_size = non_lazy_plt->plt_entry_size;
  3823. i = 0;
  3824. }
  3825. /* Skip lazy PLT when the second PLT is used. */
  3826. if ((plt_type & (plt_lazy | plt_second))
  3827. == (plt_lazy | plt_second))
  3828. plts[j].count = 0;
  3829. else
  3830. {
  3831. n = plt->size / plts[j].plt_entry_size;
  3832. plts[j].count = n;
  3833. count += n - i;
  3834. }
  3835. plts[j].contents = plt_contents;
  3836. /* The _GLOBAL_OFFSET_TABLE_ address is needed. */
  3837. if ((plt_type & plt_pic))
  3838. got_addr = (bfd_vma) -1;
  3839. }
  3840. return _bfd_x86_elf_get_synthetic_symtab (abfd, count, relsize,
  3841. got_addr, plts, dynsyms,
  3842. ret);
  3843. }
  3844. /* Set up i386 GNU properties. Return the first relocatable ELF input
  3845. with GNU properties if found. Otherwise, return NULL. */
  3846. static bfd *
  3847. elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
  3848. {
  3849. struct elf_x86_init_table init_table;
  3850. switch (get_elf_backend_data (info->output_bfd)->target_os)
  3851. {
  3852. case is_normal:
  3853. case is_solaris:
  3854. init_table.plt0_pad_byte = 0x0;
  3855. init_table.lazy_plt = &elf_i386_lazy_plt;
  3856. init_table.non_lazy_plt = &elf_i386_non_lazy_plt;
  3857. init_table.lazy_ibt_plt = &elf_i386_lazy_ibt_plt;
  3858. init_table.non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt;
  3859. break;
  3860. case is_vxworks:
  3861. init_table.plt0_pad_byte = 0x90;
  3862. init_table.lazy_plt = &elf_i386_lazy_plt;
  3863. init_table.non_lazy_plt = NULL;
  3864. init_table.lazy_ibt_plt = NULL;
  3865. init_table.non_lazy_ibt_plt = NULL;
  3866. break;
  3867. default:
  3868. abort ();
  3869. }
  3870. init_table.r_info = elf32_r_info;
  3871. init_table.r_sym = elf32_r_sym;
  3872. return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
  3873. }
  3874. #define TARGET_LITTLE_SYM i386_elf32_vec
  3875. #define TARGET_LITTLE_NAME "elf32-i386"
  3876. #define ELF_ARCH bfd_arch_i386
  3877. #define ELF_TARGET_ID I386_ELF_DATA
  3878. #define ELF_MACHINE_CODE EM_386
  3879. #define ELF_MAXPAGESIZE 0x1000
  3880. #define elf_backend_can_gc_sections 1
  3881. #define elf_backend_can_refcount 1
  3882. #define elf_backend_want_got_plt 1
  3883. #define elf_backend_plt_readonly 1
  3884. #define elf_backend_want_plt_sym 0
  3885. #define elf_backend_got_header_size 12
  3886. #define elf_backend_plt_alignment 4
  3887. #define elf_backend_dtrel_excludes_plt 1
  3888. #define elf_backend_extern_protected_data 1
  3889. #define elf_backend_caches_rawsize 1
  3890. #define elf_backend_want_dynrelro 1
  3891. /* Support RELA for objdump of prelink objects. */
  3892. #define elf_info_to_howto elf_i386_info_to_howto_rel
  3893. #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
  3894. #define bfd_elf32_bfd_is_local_label_name elf_i386_is_local_label_name
  3895. #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
  3896. #define bfd_elf32_bfd_reloc_name_lookup elf_i386_reloc_name_lookup
  3897. #define bfd_elf32_get_synthetic_symtab elf_i386_get_synthetic_symtab
  3898. #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
  3899. #define elf_backend_always_size_sections elf_i386_always_size_sections
  3900. #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
  3901. #define elf_backend_fake_sections elf_i386_fake_sections
  3902. #define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
  3903. #define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
  3904. #define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
  3905. #define elf_backend_grok_prstatus elf_i386_grok_prstatus
  3906. #define elf_backend_grok_psinfo elf_i386_grok_psinfo
  3907. #define elf_backend_reloc_type_class elf_i386_reloc_type_class
  3908. #define elf_backend_relocate_section elf_i386_relocate_section
  3909. #define elf_backend_setup_gnu_properties elf_i386_link_setup_gnu_properties
  3910. #define elf_backend_hide_symbol _bfd_x86_elf_hide_symbol
  3911. #define elf_backend_linux_prpsinfo32_ugid16 true
  3912. #define elf32_bed elf32_i386_bed
  3913. #include "elf32-target.h"
  3914. /* FreeBSD support. */
  3915. #undef TARGET_LITTLE_SYM
  3916. #define TARGET_LITTLE_SYM i386_elf32_fbsd_vec
  3917. #undef TARGET_LITTLE_NAME
  3918. #define TARGET_LITTLE_NAME "elf32-i386-freebsd"
  3919. #undef ELF_OSABI
  3920. #define ELF_OSABI ELFOSABI_FREEBSD
  3921. /* The kernel recognizes executables as valid only if they carry a
  3922. "FreeBSD" label in the ELF header. So we put this label on all
  3923. executables and (for simplicity) also all other object files. */
  3924. static bool
  3925. elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
  3926. {
  3927. if (!_bfd_elf_init_file_header (abfd, info))
  3928. return false;
  3929. #ifdef OLD_FREEBSD_ABI_LABEL
  3930. {
  3931. /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
  3932. Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
  3933. memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
  3934. }
  3935. #endif
  3936. return true;
  3937. }
  3938. #undef elf_backend_init_file_header
  3939. #define elf_backend_init_file_header elf_i386_fbsd_init_file_header
  3940. #undef elf32_bed
  3941. #define elf32_bed elf32_i386_fbsd_bed
  3942. #undef elf_backend_add_symbol_hook
  3943. #include "elf32-target.h"
  3944. #undef elf_backend_init_file_header
  3945. /* Solaris 2. */
  3946. #undef TARGET_LITTLE_SYM
  3947. #define TARGET_LITTLE_SYM i386_elf32_sol2_vec
  3948. #undef TARGET_LITTLE_NAME
  3949. #define TARGET_LITTLE_NAME "elf32-i386-sol2"
  3950. #undef ELF_TARGET_OS
  3951. #define ELF_TARGET_OS is_solaris
  3952. /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
  3953. objects won't be recognized. */
  3954. #undef ELF_OSABI
  3955. #undef elf32_bed
  3956. #define elf32_bed elf32_i386_sol2_bed
  3957. /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
  3958. boundary. */
  3959. #undef elf_backend_static_tls_alignment
  3960. #define elf_backend_static_tls_alignment 8
  3961. /* The Solaris 2 ABI requires a plt symbol on all platforms.
  3962. Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
  3963. File, p.63. */
  3964. #undef elf_backend_want_plt_sym
  3965. #define elf_backend_want_plt_sym 1
  3966. #undef elf_backend_strtab_flags
  3967. #define elf_backend_strtab_flags SHF_STRINGS
  3968. /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
  3969. has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
  3970. FALSE otherwise. ISECTION is the best guess matching section from the
  3971. input bfd IBFD, but it might be NULL. */
  3972. static bool
  3973. elf32_i386_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
  3974. bfd *obfd ATTRIBUTE_UNUSED,
  3975. const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
  3976. Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
  3977. {
  3978. /* PR 19938: FIXME: Need to add code for setting the sh_info
  3979. and sh_link fields of Solaris specific section types. */
  3980. return false;
  3981. /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13,
  3982. Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation:
  3983. http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc
  3984. The following values should be set:
  3985. Type Link Info
  3986. -----------------------------------------------------------------------------
  3987. SHT_SUNW_ancillary The section header index of 0
  3988. [0x6fffffee] the associated string table.
  3989. SHT_SUNW_capinfo The section header index of For a dynamic object, the
  3990. [0x6ffffff0] the associated symbol table. section header index of
  3991. the associated
  3992. SHT_SUNW_capchain table,
  3993. otherwise 0.
  3994. SHT_SUNW_symsort The section header index of 0
  3995. [0x6ffffff1] the associated symbol table.
  3996. SHT_SUNW_tlssort The section header index of 0
  3997. [0x6ffffff2] the associated symbol table.
  3998. SHT_SUNW_LDYNSYM The section header index of One greater than the
  3999. [0x6ffffff3] the associated string table. symbol table index of the
  4000. This index is the same string last local symbol,
  4001. table used by the SHT_DYNSYM STB_LOCAL. Since
  4002. section. SHT_SUNW_LDYNSYM only
  4003. contains local symbols,
  4004. sh_info is equivalent to
  4005. the number of symbols in
  4006. the table.
  4007. SHT_SUNW_cap If symbol capabilities exist, If any capabilities refer
  4008. [0x6ffffff5] the section header index of to named strings, the
  4009. the associated section header index of
  4010. SHT_SUNW_capinfo table, the associated string
  4011. otherwise 0. table, otherwise 0.
  4012. SHT_SUNW_move The section header index of 0
  4013. [0x6ffffffa] the associated symbol table.
  4014. SHT_SUNW_COMDAT 0 0
  4015. [0x6ffffffb]
  4016. SHT_SUNW_syminfo The section header index of The section header index
  4017. [0x6ffffffc] the associated symbol table. of the associated
  4018. .dynamic section.
  4019. SHT_SUNW_verdef The section header index of The number of version
  4020. [0x6ffffffd] the associated string table. definitions within the
  4021. section.
  4022. SHT_SUNW_verneed The section header index of The number of version
  4023. [0x6ffffffe] the associated string table. dependencies within the
  4024. section.
  4025. SHT_SUNW_versym The section header index of 0
  4026. [0x6fffffff] the associated symbol table. */
  4027. }
  4028. #undef elf_backend_copy_special_section_fields
  4029. #define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields
  4030. #include "elf32-target.h"
  4031. /* Intel MCU support. */
  4032. static bool
  4033. elf32_iamcu_elf_object_p (bfd *abfd)
  4034. {
  4035. /* Set the right machine number for an IAMCU elf32 file. */
  4036. bfd_default_set_arch_mach (abfd, bfd_arch_iamcu, bfd_mach_i386_iamcu);
  4037. return true;
  4038. }
  4039. #undef TARGET_LITTLE_SYM
  4040. #define TARGET_LITTLE_SYM iamcu_elf32_vec
  4041. #undef TARGET_LITTLE_NAME
  4042. #define TARGET_LITTLE_NAME "elf32-iamcu"
  4043. #undef ELF_ARCH
  4044. #define ELF_ARCH bfd_arch_iamcu
  4045. #undef ELF_MACHINE_CODE
  4046. #define ELF_MACHINE_CODE EM_IAMCU
  4047. #undef ELF_TARGET_OS
  4048. #undef ELF_OSABI
  4049. #undef elf32_bed
  4050. #define elf32_bed elf32_iamcu_bed
  4051. #undef elf_backend_object_p
  4052. #define elf_backend_object_p elf32_iamcu_elf_object_p
  4053. #undef elf_backend_static_tls_alignment
  4054. #undef elf_backend_want_plt_sym
  4055. #define elf_backend_want_plt_sym 0
  4056. #undef elf_backend_strtab_flags
  4057. #undef elf_backend_copy_special_section_fields
  4058. #include "elf32-target.h"
  4059. /* Restore defaults. */
  4060. #undef ELF_ARCH
  4061. #define ELF_ARCH bfd_arch_i386
  4062. #undef ELF_MACHINE_CODE
  4063. #define ELF_MACHINE_CODE EM_386
  4064. #undef elf_backend_object_p
  4065. /* VxWorks support. */
  4066. #undef TARGET_LITTLE_SYM
  4067. #define TARGET_LITTLE_SYM i386_elf32_vxworks_vec
  4068. #undef TARGET_LITTLE_NAME
  4069. #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
  4070. #undef ELF_OSABI
  4071. #undef ELF_MAXPAGESIZE
  4072. #define ELF_MAXPAGESIZE 0x1000
  4073. #undef elf_backend_plt_alignment
  4074. #define elf_backend_plt_alignment 4
  4075. #undef ELF_TARGET_OS
  4076. #define ELF_TARGET_OS is_vxworks
  4077. #undef elf_backend_relocs_compatible
  4078. #undef elf_backend_add_symbol_hook
  4079. #define elf_backend_add_symbol_hook \
  4080. elf_vxworks_add_symbol_hook
  4081. #undef elf_backend_link_output_symbol_hook
  4082. #define elf_backend_link_output_symbol_hook \
  4083. elf_vxworks_link_output_symbol_hook
  4084. #undef elf_backend_emit_relocs
  4085. #define elf_backend_emit_relocs elf_vxworks_emit_relocs
  4086. #undef elf_backend_final_write_processing
  4087. #define elf_backend_final_write_processing \
  4088. elf_vxworks_final_write_processing
  4089. #undef elf_backend_static_tls_alignment
  4090. /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
  4091. define it. */
  4092. #undef elf_backend_want_plt_sym
  4093. #define elf_backend_want_plt_sym 1
  4094. #undef elf32_bed
  4095. #define elf32_bed elf32_i386_vxworks_bed
  4096. #include "elf32-target.h"