elf64-ia64-vms.c 151 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627
  1. /* IA-64 support for OpenVMS
  2. Copyright (C) 1998-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 "sysdep.h"
  17. #include "bfd.h"
  18. #include "libbfd.h"
  19. #include "elf-bfd.h"
  20. #include "opcode/ia64.h"
  21. #include "elf/ia64.h"
  22. #include "objalloc.h"
  23. #include "hashtab.h"
  24. #include "elfxx-ia64.h"
  25. #include "vms.h"
  26. #include "bfdver.h"
  27. /* THE RULES for all the stuff the linker creates --
  28. GOT Entries created in response to LTOFF or LTOFF_FPTR
  29. relocations. Dynamic relocs created for dynamic
  30. symbols in an application; REL relocs for locals
  31. in a shared library.
  32. FPTR The canonical function descriptor. Created for local
  33. symbols in applications. Descriptors for dynamic symbols
  34. and local symbols in shared libraries are created by
  35. ld.so. Thus there are no dynamic relocs against these
  36. objects. The FPTR relocs for such _are_ passed through
  37. to the dynamic relocation tables.
  38. FULL_PLT Created for a PCREL21B relocation against a dynamic symbol.
  39. Requires the creation of a PLTOFF entry. This does not
  40. require any dynamic relocations.
  41. PLTOFF Created by PLTOFF relocations. For local symbols, this
  42. is an alternate function descriptor, and in shared libraries
  43. requires two REL relocations. Note that this cannot be
  44. transformed into an FPTR relocation, since it must be in
  45. range of the GP. For dynamic symbols, this is a function
  46. descriptor. */
  47. typedef struct bfd_hash_entry *(*new_hash_entry_func)
  48. (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
  49. /* In dynamically (linker-) created sections, we generally need to keep track
  50. of the place a symbol or expression got allocated to. This is done via hash
  51. tables that store entries of the following type. */
  52. struct elf64_ia64_dyn_sym_info
  53. {
  54. /* The addend for which this entry is relevant. */
  55. bfd_vma addend;
  56. bfd_vma got_offset;
  57. bfd_vma fptr_offset;
  58. bfd_vma pltoff_offset;
  59. bfd_vma plt_offset;
  60. bfd_vma plt2_offset;
  61. /* The symbol table entry, if any, that this was derived from. */
  62. struct elf_link_hash_entry *h;
  63. /* Used to count non-got, non-plt relocations for delayed sizing
  64. of relocation sections. */
  65. struct elf64_ia64_dyn_reloc_entry
  66. {
  67. struct elf64_ia64_dyn_reloc_entry *next;
  68. asection *srel;
  69. int type;
  70. int count;
  71. } *reloc_entries;
  72. /* TRUE when the section contents have been updated. */
  73. unsigned got_done : 1;
  74. unsigned fptr_done : 1;
  75. unsigned pltoff_done : 1;
  76. /* TRUE for the different kinds of linker data we want created. */
  77. unsigned want_got : 1;
  78. unsigned want_gotx : 1;
  79. unsigned want_fptr : 1;
  80. unsigned want_ltoff_fptr : 1;
  81. unsigned want_plt : 1; /* A MIN_PLT entry. */
  82. unsigned want_plt2 : 1; /* A FULL_PLT. */
  83. unsigned want_pltoff : 1;
  84. };
  85. struct elf64_ia64_local_hash_entry
  86. {
  87. int id;
  88. unsigned int r_sym;
  89. /* The number of elements in elf64_ia64_dyn_sym_info array. */
  90. unsigned int count;
  91. /* The number of sorted elements in elf64_ia64_dyn_sym_info array. */
  92. unsigned int sorted_count;
  93. /* The size of elf64_ia64_dyn_sym_info array. */
  94. unsigned int size;
  95. /* The array of elf64_ia64_dyn_sym_info. */
  96. struct elf64_ia64_dyn_sym_info *info;
  97. /* TRUE if this hash entry's addends was translated for
  98. SHF_MERGE optimization. */
  99. unsigned sec_merge_done : 1;
  100. };
  101. struct elf64_ia64_link_hash_entry
  102. {
  103. struct elf_link_hash_entry root;
  104. /* Set if this symbol is defined in a shared library.
  105. We can't use root.u.def.section->owner as the symbol is an absolute
  106. symbol. */
  107. bfd *shl;
  108. /* The number of elements in elf64_ia64_dyn_sym_info array. */
  109. unsigned int count;
  110. /* The number of sorted elements in elf64_ia64_dyn_sym_info array. */
  111. unsigned int sorted_count;
  112. /* The size of elf64_ia64_dyn_sym_info array. */
  113. unsigned int size;
  114. /* The array of elf64_ia64_dyn_sym_info. */
  115. struct elf64_ia64_dyn_sym_info *info;
  116. };
  117. struct elf64_ia64_link_hash_table
  118. {
  119. /* The main hash table. */
  120. struct elf_link_hash_table root;
  121. asection *fptr_sec; /* Function descriptor table (or NULL). */
  122. asection *rel_fptr_sec; /* Dynamic relocation section for same. */
  123. asection *pltoff_sec; /* Private descriptors for plt (or NULL). */
  124. asection *fixups_sec; /* Fixups section. */
  125. asection *transfer_sec; /* Transfer vector section. */
  126. asection *note_sec; /* .note section. */
  127. /* There are maybe R_IA64_GPREL22 relocations, including those
  128. optimized from R_IA64_LTOFF22X, against non-SHF_IA_64_SHORT
  129. sections. We need to record those sections so that we can choose
  130. a proper GP to cover all R_IA64_GPREL22 relocations. */
  131. asection *max_short_sec; /* Maximum short output section. */
  132. bfd_vma max_short_offset; /* Maximum short offset. */
  133. asection *min_short_sec; /* Minimum short output section. */
  134. bfd_vma min_short_offset; /* Minimum short offset. */
  135. htab_t loc_hash_table;
  136. void *loc_hash_memory;
  137. };
  138. struct elf64_ia64_allocate_data
  139. {
  140. struct bfd_link_info *info;
  141. bfd_size_type ofs;
  142. };
  143. #define elf64_ia64_hash_table(p) \
  144. ((is_elf_hash_table ((p)->hash) \
  145. && elf_hash_table_id (elf_hash_table (p)) == IA64_ELF_DATA) \
  146. ? (struct elf64_ia64_link_hash_table *) (p)->hash : NULL)
  147. struct elf64_ia64_vms_obj_tdata
  148. {
  149. struct elf_obj_tdata root;
  150. /* Ident for shared library. */
  151. bfd_uint64_t ident;
  152. /* Used only during link: offset in the .fixups section for this bfd. */
  153. bfd_vma fixups_off;
  154. /* Max number of shared libraries. */
  155. unsigned int needed_count;
  156. };
  157. #define elf_ia64_vms_tdata(abfd) \
  158. ((struct elf64_ia64_vms_obj_tdata *)((abfd)->tdata.any))
  159. #define elf_ia64_vms_ident(abfd) (elf_ia64_vms_tdata(abfd)->ident)
  160. struct elf64_vms_transfer
  161. {
  162. unsigned char size[4];
  163. unsigned char spare[4];
  164. unsigned char tfradr1[8];
  165. unsigned char tfradr2[8];
  166. unsigned char tfradr3[8];
  167. unsigned char tfradr4[8];
  168. unsigned char tfradr5[8];
  169. /* Local function descriptor for tfr3. */
  170. unsigned char tfr3_func[8];
  171. unsigned char tfr3_gp[8];
  172. };
  173. typedef struct
  174. {
  175. Elf64_External_Ehdr ehdr;
  176. unsigned char vms_needed_count[8];
  177. } Elf64_External_VMS_Ehdr;
  178. static struct elf64_ia64_dyn_sym_info * get_dyn_sym_info
  179. (struct elf64_ia64_link_hash_table *,
  180. struct elf_link_hash_entry *,
  181. bfd *, const Elf_Internal_Rela *, bool);
  182. static bool elf64_ia64_dynamic_symbol_p
  183. (struct elf_link_hash_entry *);
  184. static bool elf64_ia64_choose_gp
  185. (bfd *, struct bfd_link_info *, bool);
  186. static void elf64_ia64_dyn_sym_traverse
  187. (struct elf64_ia64_link_hash_table *,
  188. bool (*) (struct elf64_ia64_dyn_sym_info *, void *),
  189. void *);
  190. static bool allocate_global_data_got
  191. (struct elf64_ia64_dyn_sym_info *, void *);
  192. static bool allocate_global_fptr_got
  193. (struct elf64_ia64_dyn_sym_info *, void *);
  194. static bool allocate_local_got
  195. (struct elf64_ia64_dyn_sym_info *, void *);
  196. static bool allocate_dynrel_entries
  197. (struct elf64_ia64_dyn_sym_info *, void *);
  198. static asection *get_pltoff
  199. (bfd *, struct elf64_ia64_link_hash_table *);
  200. static asection *get_got
  201. (bfd *, struct elf64_ia64_link_hash_table *);
  202. /* Given a ELF reloc, return the matching HOWTO structure. */
  203. static bool
  204. elf64_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
  205. arelent *bfd_reloc,
  206. Elf_Internal_Rela *elf_reloc)
  207. {
  208. unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info);
  209. bfd_reloc->howto = ia64_elf_lookup_howto (r_type);
  210. if (bfd_reloc->howto == NULL)
  211. {
  212. /* xgettext:c-format */
  213. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  214. abfd, r_type);
  215. bfd_set_error (bfd_error_bad_value);
  216. return false;
  217. }
  218. return true;
  219. }
  220. #define PLT_FULL_ENTRY_SIZE (2 * 16)
  221. static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] =
  222. {
  223. 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
  224. 0x00, 0x41, 0x3c, 0x70, 0x29, 0xc0, /* ld8.acq r16=[r15],8*/
  225. 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
  226. 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
  227. 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
  228. 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
  229. };
  230. static const bfd_byte oor_brl[16] =
  231. {
  232. 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
  233. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;;*/
  234. 0x00, 0x00, 0x00, 0xc0
  235. };
  236. /* These functions do relaxation for IA-64 ELF. */
  237. /* Rename some of the generic section flags to better document how they
  238. are used here. */
  239. #define skip_relax_pass_0 sec_flg0
  240. #define skip_relax_pass_1 sec_flg1
  241. static void
  242. elf64_ia64_update_short_info (asection *sec, bfd_vma offset,
  243. struct elf64_ia64_link_hash_table *ia64_info)
  244. {
  245. /* Skip ABS and SHF_IA_64_SHORT sections. */
  246. if (sec == bfd_abs_section_ptr
  247. || (sec->flags & SEC_SMALL_DATA) != 0)
  248. return;
  249. if (!ia64_info->min_short_sec)
  250. {
  251. ia64_info->max_short_sec = sec;
  252. ia64_info->max_short_offset = offset;
  253. ia64_info->min_short_sec = sec;
  254. ia64_info->min_short_offset = offset;
  255. }
  256. else if (sec == ia64_info->max_short_sec
  257. && offset > ia64_info->max_short_offset)
  258. ia64_info->max_short_offset = offset;
  259. else if (sec == ia64_info->min_short_sec
  260. && offset < ia64_info->min_short_offset)
  261. ia64_info->min_short_offset = offset;
  262. else if (sec->output_section->vma
  263. > ia64_info->max_short_sec->vma)
  264. {
  265. ia64_info->max_short_sec = sec;
  266. ia64_info->max_short_offset = offset;
  267. }
  268. else if (sec->output_section->vma
  269. < ia64_info->min_short_sec->vma)
  270. {
  271. ia64_info->min_short_sec = sec;
  272. ia64_info->min_short_offset = offset;
  273. }
  274. }
  275. /* Use a two passes algorithm. In the first pass, branches are relaxed
  276. (which may increase the size of the section). In the second pass,
  277. the other relaxations are done.
  278. */
  279. static bool
  280. elf64_ia64_relax_section (bfd *abfd, asection *sec,
  281. struct bfd_link_info *link_info,
  282. bool *again)
  283. {
  284. struct one_fixup
  285. {
  286. struct one_fixup *next;
  287. asection *tsec;
  288. bfd_vma toff;
  289. bfd_vma trampoff;
  290. };
  291. Elf_Internal_Shdr *symtab_hdr;
  292. Elf_Internal_Rela *internal_relocs;
  293. Elf_Internal_Rela *irel, *irelend;
  294. bfd_byte *contents;
  295. Elf_Internal_Sym *isymbuf = NULL;
  296. struct elf64_ia64_link_hash_table *ia64_info;
  297. struct one_fixup *fixups = NULL;
  298. bool changed_contents = false;
  299. bool changed_relocs = false;
  300. bool skip_relax_pass_0 = true;
  301. bool skip_relax_pass_1 = true;
  302. bfd_vma gp = 0;
  303. /* Assume we're not going to change any sizes, and we'll only need
  304. one pass. */
  305. *again = false;
  306. if (bfd_link_relocatable (link_info))
  307. (*link_info->callbacks->einfo)
  308. (_("%P%F: --relax and -r may not be used together\n"));
  309. /* Don't even try to relax for non-ELF outputs. */
  310. if (!is_elf_hash_table (link_info->hash))
  311. return false;
  312. /* Nothing to do if there are no relocations or there is no need for
  313. the current pass. */
  314. if ((sec->flags & SEC_RELOC) == 0
  315. || sec->reloc_count == 0
  316. || (link_info->relax_pass == 0 && sec->skip_relax_pass_0)
  317. || (link_info->relax_pass == 1 && sec->skip_relax_pass_1))
  318. return true;
  319. ia64_info = elf64_ia64_hash_table (link_info);
  320. if (ia64_info == NULL)
  321. return false;
  322. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  323. /* Load the relocations for this section. */
  324. internal_relocs = (_bfd_elf_link_read_relocs
  325. (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
  326. link_info->keep_memory));
  327. if (internal_relocs == NULL)
  328. return false;
  329. irelend = internal_relocs + sec->reloc_count;
  330. /* Get the section contents. */
  331. if (elf_section_data (sec)->this_hdr.contents != NULL)
  332. contents = elf_section_data (sec)->this_hdr.contents;
  333. else
  334. {
  335. if (!bfd_malloc_and_get_section (abfd, sec, &contents))
  336. goto error_return;
  337. }
  338. for (irel = internal_relocs; irel < irelend; irel++)
  339. {
  340. unsigned long r_type = ELF64_R_TYPE (irel->r_info);
  341. bfd_vma symaddr, reladdr, trampoff, toff, roff;
  342. asection *tsec;
  343. struct one_fixup *f;
  344. bfd_size_type amt;
  345. bool is_branch;
  346. struct elf64_ia64_dyn_sym_info *dyn_i;
  347. switch (r_type)
  348. {
  349. case R_IA64_PCREL21B:
  350. case R_IA64_PCREL21BI:
  351. case R_IA64_PCREL21M:
  352. case R_IA64_PCREL21F:
  353. /* In pass 1, all br relaxations are done. We can skip it. */
  354. if (link_info->relax_pass == 1)
  355. continue;
  356. skip_relax_pass_0 = false;
  357. is_branch = true;
  358. break;
  359. case R_IA64_PCREL60B:
  360. /* We can't optimize brl to br in pass 0 since br relaxations
  361. will increase the code size. Defer it to pass 1. */
  362. if (link_info->relax_pass == 0)
  363. {
  364. skip_relax_pass_1 = false;
  365. continue;
  366. }
  367. is_branch = true;
  368. break;
  369. case R_IA64_GPREL22:
  370. /* Update max_short_sec/min_short_sec. */
  371. case R_IA64_LTOFF22X:
  372. case R_IA64_LDXMOV:
  373. /* We can't relax ldx/mov in pass 0 since br relaxations will
  374. increase the code size. Defer it to pass 1. */
  375. if (link_info->relax_pass == 0)
  376. {
  377. skip_relax_pass_1 = false;
  378. continue;
  379. }
  380. is_branch = false;
  381. break;
  382. default:
  383. continue;
  384. }
  385. /* Get the value of the symbol referred to by the reloc. */
  386. if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  387. {
  388. /* A local symbol. */
  389. Elf_Internal_Sym *isym;
  390. /* Read this BFD's local symbols. */
  391. if (isymbuf == NULL)
  392. {
  393. isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  394. if (isymbuf == NULL)
  395. isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
  396. symtab_hdr->sh_info, 0,
  397. NULL, NULL, NULL);
  398. if (isymbuf == 0)
  399. goto error_return;
  400. }
  401. isym = isymbuf + ELF64_R_SYM (irel->r_info);
  402. if (isym->st_shndx == SHN_UNDEF)
  403. continue; /* We can't do anything with undefined symbols. */
  404. else if (isym->st_shndx == SHN_ABS)
  405. tsec = bfd_abs_section_ptr;
  406. else if (isym->st_shndx == SHN_COMMON)
  407. tsec = bfd_com_section_ptr;
  408. else if (isym->st_shndx == SHN_IA_64_ANSI_COMMON)
  409. tsec = bfd_com_section_ptr;
  410. else
  411. tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  412. toff = isym->st_value;
  413. dyn_i = get_dyn_sym_info (ia64_info, NULL, abfd, irel, false);
  414. }
  415. else
  416. {
  417. unsigned long indx;
  418. struct elf_link_hash_entry *h;
  419. indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
  420. h = elf_sym_hashes (abfd)[indx];
  421. BFD_ASSERT (h != NULL);
  422. while (h->root.type == bfd_link_hash_indirect
  423. || h->root.type == bfd_link_hash_warning)
  424. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  425. dyn_i = get_dyn_sym_info (ia64_info, h, abfd, irel, false);
  426. /* For branches to dynamic symbols, we're interested instead
  427. in a branch to the PLT entry. */
  428. if (is_branch && dyn_i && dyn_i->want_plt2)
  429. {
  430. /* Internal branches shouldn't be sent to the PLT.
  431. Leave this for now and we'll give an error later. */
  432. if (r_type != R_IA64_PCREL21B)
  433. continue;
  434. tsec = ia64_info->root.splt;
  435. toff = dyn_i->plt2_offset;
  436. BFD_ASSERT (irel->r_addend == 0);
  437. }
  438. /* Can't do anything else with dynamic symbols. */
  439. else if (elf64_ia64_dynamic_symbol_p (h))
  440. continue;
  441. else
  442. {
  443. /* We can't do anything with undefined symbols. */
  444. if (h->root.type == bfd_link_hash_undefined
  445. || h->root.type == bfd_link_hash_undefweak)
  446. continue;
  447. tsec = h->root.u.def.section;
  448. toff = h->root.u.def.value;
  449. }
  450. }
  451. toff += irel->r_addend;
  452. symaddr = tsec->output_section->vma + tsec->output_offset + toff;
  453. roff = irel->r_offset;
  454. if (is_branch)
  455. {
  456. bfd_signed_vma offset;
  457. reladdr = (sec->output_section->vma
  458. + sec->output_offset
  459. + roff) & (bfd_vma) -4;
  460. /* The .plt section is aligned at 32byte and the .text section
  461. is aligned at 64byte. The .text section is right after the
  462. .plt section. After the first relaxation pass, linker may
  463. increase the gap between the .plt and .text sections up
  464. to 32byte. We assume linker will always insert 32byte
  465. between the .plt and .text sections after the first
  466. relaxation pass. */
  467. if (tsec == ia64_info->root.splt)
  468. offset = -0x1000000 + 32;
  469. else
  470. offset = -0x1000000;
  471. /* If the branch is in range, no need to do anything. */
  472. if ((bfd_signed_vma) (symaddr - reladdr) >= offset
  473. && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0)
  474. {
  475. /* If the 60-bit branch is in 21-bit range, optimize it. */
  476. if (r_type == R_IA64_PCREL60B)
  477. {
  478. ia64_elf_relax_brl (contents, roff);
  479. irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
  480. R_IA64_PCREL21B);
  481. /* If the original relocation offset points to slot
  482. 1, change it to slot 2. */
  483. if ((irel->r_offset & 3) == 1)
  484. irel->r_offset += 1;
  485. }
  486. continue;
  487. }
  488. else if (r_type == R_IA64_PCREL60B)
  489. continue;
  490. else if (ia64_elf_relax_br (contents, roff))
  491. {
  492. irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
  493. R_IA64_PCREL60B);
  494. /* Make the relocation offset point to slot 1. */
  495. irel->r_offset = (irel->r_offset & ~((bfd_vma) 0x3)) + 1;
  496. continue;
  497. }
  498. /* We can't put a trampoline in a .init/.fini section. Issue
  499. an error. */
  500. if (strcmp (sec->output_section->name, ".init") == 0
  501. || strcmp (sec->output_section->name, ".fini") == 0)
  502. {
  503. _bfd_error_handler
  504. /* xgettext:c-format */
  505. (_("%pB: can't relax br at %#" PRIx64 " in section `%pA';"
  506. " please use brl or indirect branch"),
  507. sec->owner, (uint64_t) roff, sec);
  508. bfd_set_error (bfd_error_bad_value);
  509. goto error_return;
  510. }
  511. /* If the branch and target are in the same section, you've
  512. got one honking big section and we can't help you unless
  513. you are branching backwards. You'll get an error message
  514. later. */
  515. if (tsec == sec && toff > roff)
  516. continue;
  517. /* Look for an existing fixup to this address. */
  518. for (f = fixups; f ; f = f->next)
  519. if (f->tsec == tsec && f->toff == toff)
  520. break;
  521. if (f == NULL)
  522. {
  523. /* Two alternatives: If it's a branch to a PLT entry, we can
  524. make a copy of the FULL_PLT entry. Otherwise, we'll have
  525. to use a `brl' insn to get where we're going. */
  526. size_t size;
  527. if (tsec == ia64_info->root.splt)
  528. size = sizeof (plt_full_entry);
  529. else
  530. size = sizeof (oor_brl);
  531. /* Resize the current section to make room for the new branch. */
  532. trampoff = (sec->size + 15) & (bfd_vma) -16;
  533. /* If trampoline is out of range, there is nothing we
  534. can do. */
  535. offset = trampoff - (roff & (bfd_vma) -4);
  536. if (offset < -0x1000000 || offset > 0x0FFFFF0)
  537. continue;
  538. amt = trampoff + size;
  539. contents = (bfd_byte *) bfd_realloc (contents, amt);
  540. if (contents == NULL)
  541. goto error_return;
  542. sec->size = amt;
  543. if (tsec == ia64_info->root.splt)
  544. {
  545. memcpy (contents + trampoff, plt_full_entry, size);
  546. /* Hijack the old relocation for use as the PLTOFF reloc. */
  547. irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
  548. R_IA64_PLTOFF22);
  549. irel->r_offset = trampoff;
  550. }
  551. else
  552. {
  553. memcpy (contents + trampoff, oor_brl, size);
  554. irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
  555. R_IA64_PCREL60B);
  556. irel->r_offset = trampoff + 2;
  557. }
  558. /* Record the fixup so we don't do it again this section. */
  559. f = (struct one_fixup *)
  560. bfd_malloc ((bfd_size_type) sizeof (*f));
  561. f->next = fixups;
  562. f->tsec = tsec;
  563. f->toff = toff;
  564. f->trampoff = trampoff;
  565. fixups = f;
  566. }
  567. else
  568. {
  569. /* If trampoline is out of range, there is nothing we
  570. can do. */
  571. offset = f->trampoff - (roff & (bfd_vma) -4);
  572. if (offset < -0x1000000 || offset > 0x0FFFFF0)
  573. continue;
  574. /* Nop out the reloc, since we're finalizing things here. */
  575. irel->r_info = ELF64_R_INFO (0, R_IA64_NONE);
  576. }
  577. /* Fix up the existing branch to hit the trampoline. */
  578. if (ia64_elf_install_value (contents + roff, offset, r_type)
  579. != bfd_reloc_ok)
  580. goto error_return;
  581. changed_contents = true;
  582. changed_relocs = true;
  583. }
  584. else
  585. {
  586. /* Fetch the gp. */
  587. if (gp == 0)
  588. {
  589. bfd *obfd = sec->output_section->owner;
  590. gp = _bfd_get_gp_value (obfd);
  591. if (gp == 0)
  592. {
  593. if (!elf64_ia64_choose_gp (obfd, link_info, false))
  594. goto error_return;
  595. gp = _bfd_get_gp_value (obfd);
  596. }
  597. }
  598. /* If the data is out of range, do nothing. */
  599. if ((bfd_signed_vma) (symaddr - gp) >= 0x200000
  600. ||(bfd_signed_vma) (symaddr - gp) < -0x200000)
  601. continue;
  602. if (r_type == R_IA64_GPREL22)
  603. elf64_ia64_update_short_info (tsec->output_section,
  604. tsec->output_offset + toff,
  605. ia64_info);
  606. else if (r_type == R_IA64_LTOFF22X)
  607. {
  608. /* Can't deal yet correctly with ABS symbols. */
  609. if (bfd_is_abs_section (tsec))
  610. continue;
  611. irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
  612. R_IA64_GPREL22);
  613. changed_relocs = true;
  614. elf64_ia64_update_short_info (tsec->output_section,
  615. tsec->output_offset + toff,
  616. ia64_info);
  617. }
  618. else
  619. {
  620. ia64_elf_relax_ldxmov (contents, roff);
  621. irel->r_info = ELF64_R_INFO (0, R_IA64_NONE);
  622. changed_contents = true;
  623. changed_relocs = true;
  624. }
  625. }
  626. }
  627. /* ??? If we created fixups, this may push the code segment large
  628. enough that the data segment moves, which will change the GP.
  629. Reset the GP so that we re-calculate next round. We need to
  630. do this at the _beginning_ of the next round; now will not do. */
  631. /* Clean up and go home. */
  632. while (fixups)
  633. {
  634. struct one_fixup *f = fixups;
  635. fixups = fixups->next;
  636. free (f);
  637. }
  638. if (isymbuf != NULL
  639. && symtab_hdr->contents != (unsigned char *) isymbuf)
  640. {
  641. if (! link_info->keep_memory)
  642. free (isymbuf);
  643. else
  644. {
  645. /* Cache the symbols for elf_link_input_bfd. */
  646. symtab_hdr->contents = (unsigned char *) isymbuf;
  647. }
  648. }
  649. if (contents != NULL
  650. && elf_section_data (sec)->this_hdr.contents != contents)
  651. {
  652. if (!changed_contents && !link_info->keep_memory)
  653. free (contents);
  654. else
  655. {
  656. /* Cache the section contents for elf_link_input_bfd. */
  657. elf_section_data (sec)->this_hdr.contents = contents;
  658. }
  659. }
  660. if (elf_section_data (sec)->relocs != internal_relocs)
  661. {
  662. if (!changed_relocs)
  663. free (internal_relocs);
  664. else
  665. elf_section_data (sec)->relocs = internal_relocs;
  666. }
  667. if (link_info->relax_pass == 0)
  668. {
  669. /* Pass 0 is only needed to relax br. */
  670. sec->skip_relax_pass_0 = skip_relax_pass_0;
  671. sec->skip_relax_pass_1 = skip_relax_pass_1;
  672. }
  673. *again = changed_contents || changed_relocs;
  674. return true;
  675. error_return:
  676. if ((unsigned char *) isymbuf != symtab_hdr->contents)
  677. free (isymbuf);
  678. if (elf_section_data (sec)->this_hdr.contents != contents)
  679. free (contents);
  680. if (elf_section_data (sec)->relocs != internal_relocs)
  681. free (internal_relocs);
  682. return false;
  683. }
  684. #undef skip_relax_pass_0
  685. #undef skip_relax_pass_1
  686. /* Return TRUE if NAME is an unwind table section name. */
  687. static inline bool
  688. is_unwind_section_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
  689. {
  690. return ((startswith (name, ELF_STRING_ia64_unwind)
  691. && ! startswith (name, ELF_STRING_ia64_unwind_info))
  692. || startswith (name, ELF_STRING_ia64_unwind_once));
  693. }
  694. /* Convert IA-64 specific section flags to bfd internal section flags. */
  695. /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
  696. flag. */
  697. static bool
  698. elf64_ia64_section_flags (const Elf_Internal_Shdr *hdr)
  699. {
  700. if (hdr->sh_flags & SHF_IA_64_SHORT)
  701. hdr->bfd_section->flags |= SEC_SMALL_DATA;
  702. return true;
  703. }
  704. /* Set the correct type for an IA-64 ELF section. We do this by the
  705. section name, which is a hack, but ought to work. */
  706. static bool
  707. elf64_ia64_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr,
  708. asection *sec)
  709. {
  710. const char *name;
  711. name = bfd_section_name (sec);
  712. if (is_unwind_section_name (abfd, name))
  713. {
  714. /* We don't have the sections numbered at this point, so sh_info
  715. is set later, in elf64_ia64_final_write_processing. */
  716. hdr->sh_type = SHT_IA_64_UNWIND;
  717. hdr->sh_flags |= SHF_LINK_ORDER;
  718. }
  719. else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
  720. hdr->sh_type = SHT_IA_64_EXT;
  721. if (sec->flags & SEC_SMALL_DATA)
  722. hdr->sh_flags |= SHF_IA_64_SHORT;
  723. return true;
  724. }
  725. /* Hook called by the linker routine which adds symbols from an object
  726. file. We use it to put .comm items in .sbss, and not .bss. */
  727. static bool
  728. elf64_ia64_add_symbol_hook (bfd *abfd,
  729. struct bfd_link_info *info,
  730. Elf_Internal_Sym *sym,
  731. const char **namep ATTRIBUTE_UNUSED,
  732. flagword *flagsp ATTRIBUTE_UNUSED,
  733. asection **secp,
  734. bfd_vma *valp)
  735. {
  736. if (sym->st_shndx == SHN_COMMON
  737. && !bfd_link_relocatable (info)
  738. && sym->st_size <= elf_gp_size (abfd))
  739. {
  740. /* Common symbols less than or equal to -G nn bytes are
  741. automatically put into .sbss. */
  742. asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
  743. if (scomm == NULL)
  744. {
  745. scomm = bfd_make_section_with_flags (abfd, ".scommon",
  746. (SEC_ALLOC
  747. | SEC_IS_COMMON
  748. | SEC_SMALL_DATA
  749. | SEC_LINKER_CREATED));
  750. if (scomm == NULL)
  751. return false;
  752. }
  753. *secp = scomm;
  754. *valp = sym->st_size;
  755. }
  756. return true;
  757. }
  758. /* According to the Tahoe assembler spec, all labels starting with a
  759. '.' are local. */
  760. static bool
  761. elf64_ia64_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
  762. const char *name)
  763. {
  764. return name[0] == '.';
  765. }
  766. /* Should we do dynamic things to this symbol? */
  767. static bool
  768. elf64_ia64_dynamic_symbol_p (struct elf_link_hash_entry *h)
  769. {
  770. return h != NULL && h->def_dynamic;
  771. }
  772. static struct bfd_hash_entry*
  773. elf64_ia64_new_elf_hash_entry (struct bfd_hash_entry *entry,
  774. struct bfd_hash_table *table,
  775. const char *string)
  776. {
  777. struct elf64_ia64_link_hash_entry *ret;
  778. ret = (struct elf64_ia64_link_hash_entry *) entry;
  779. /* Allocate the structure if it has not already been allocated by a
  780. subclass. */
  781. if (!ret)
  782. ret = bfd_hash_allocate (table, sizeof (*ret));
  783. if (!ret)
  784. return 0;
  785. /* Call the allocation method of the superclass. */
  786. ret = ((struct elf64_ia64_link_hash_entry *)
  787. _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
  788. table, string));
  789. ret->info = NULL;
  790. ret->count = 0;
  791. ret->sorted_count = 0;
  792. ret->size = 0;
  793. return (struct bfd_hash_entry *) ret;
  794. }
  795. static void
  796. elf64_ia64_hash_hide_symbol (struct bfd_link_info *info,
  797. struct elf_link_hash_entry *xh,
  798. bool force_local)
  799. {
  800. struct elf64_ia64_link_hash_entry *h;
  801. struct elf64_ia64_dyn_sym_info *dyn_i;
  802. unsigned int count;
  803. h = (struct elf64_ia64_link_hash_entry *)xh;
  804. _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
  805. for (count = h->count, dyn_i = h->info;
  806. count != 0;
  807. count--, dyn_i++)
  808. {
  809. dyn_i->want_plt2 = 0;
  810. dyn_i->want_plt = 0;
  811. }
  812. }
  813. /* Compute a hash of a local hash entry. */
  814. static hashval_t
  815. elf64_ia64_local_htab_hash (const void *ptr)
  816. {
  817. struct elf64_ia64_local_hash_entry *entry
  818. = (struct elf64_ia64_local_hash_entry *) ptr;
  819. return ELF_LOCAL_SYMBOL_HASH (entry->id, entry->r_sym);
  820. }
  821. /* Compare local hash entries. */
  822. static int
  823. elf64_ia64_local_htab_eq (const void *ptr1, const void *ptr2)
  824. {
  825. struct elf64_ia64_local_hash_entry *entry1
  826. = (struct elf64_ia64_local_hash_entry *) ptr1;
  827. struct elf64_ia64_local_hash_entry *entry2
  828. = (struct elf64_ia64_local_hash_entry *) ptr2;
  829. return entry1->id == entry2->id && entry1->r_sym == entry2->r_sym;
  830. }
  831. /* Free the global elf64_ia64_dyn_sym_info array. */
  832. static bool
  833. elf64_ia64_global_dyn_info_free (struct elf_link_hash_entry *xentry,
  834. void * unused ATTRIBUTE_UNUSED)
  835. {
  836. struct elf64_ia64_link_hash_entry *entry
  837. = (struct elf64_ia64_link_hash_entry *) xentry;
  838. if (entry->root.root.type == bfd_link_hash_warning)
  839. entry = (struct elf64_ia64_link_hash_entry *) entry->root.root.u.i.link;
  840. free (entry->info);
  841. entry->info = NULL;
  842. entry->count = 0;
  843. entry->sorted_count = 0;
  844. entry->size = 0;
  845. return true;
  846. }
  847. /* Free the local elf64_ia64_dyn_sym_info array. */
  848. static int
  849. elf64_ia64_local_dyn_info_free (void **slot,
  850. void * unused ATTRIBUTE_UNUSED)
  851. {
  852. struct elf64_ia64_local_hash_entry *entry
  853. = (struct elf64_ia64_local_hash_entry *) *slot;
  854. free (entry->info);
  855. entry->info = NULL;
  856. entry->count = 0;
  857. entry->sorted_count = 0;
  858. entry->size = 0;
  859. return true;
  860. }
  861. /* Destroy IA-64 linker hash table. */
  862. static void
  863. elf64_ia64_link_hash_table_free (bfd *obfd)
  864. {
  865. struct elf64_ia64_link_hash_table *ia64_info
  866. = (struct elf64_ia64_link_hash_table *) obfd->link.hash;
  867. if (ia64_info->loc_hash_table)
  868. {
  869. htab_traverse (ia64_info->loc_hash_table,
  870. elf64_ia64_local_dyn_info_free, NULL);
  871. htab_delete (ia64_info->loc_hash_table);
  872. }
  873. if (ia64_info->loc_hash_memory)
  874. objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory);
  875. elf_link_hash_traverse (&ia64_info->root,
  876. elf64_ia64_global_dyn_info_free, NULL);
  877. _bfd_elf_link_hash_table_free (obfd);
  878. }
  879. /* Create the derived linker hash table. The IA-64 ELF port uses this
  880. derived hash table to keep information specific to the IA-64 ElF
  881. linker (without using static variables). */
  882. static struct bfd_link_hash_table *
  883. elf64_ia64_hash_table_create (bfd *abfd)
  884. {
  885. struct elf64_ia64_link_hash_table *ret;
  886. ret = bfd_zmalloc ((bfd_size_type) sizeof (*ret));
  887. if (!ret)
  888. return NULL;
  889. if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
  890. elf64_ia64_new_elf_hash_entry,
  891. sizeof (struct elf64_ia64_link_hash_entry),
  892. IA64_ELF_DATA))
  893. {
  894. free (ret);
  895. return NULL;
  896. }
  897. ret->loc_hash_table = htab_try_create (1024, elf64_ia64_local_htab_hash,
  898. elf64_ia64_local_htab_eq, NULL);
  899. ret->loc_hash_memory = objalloc_create ();
  900. if (!ret->loc_hash_table || !ret->loc_hash_memory)
  901. {
  902. elf64_ia64_link_hash_table_free (abfd);
  903. return NULL;
  904. }
  905. ret->root.root.hash_table_free = elf64_ia64_link_hash_table_free;
  906. return &ret->root.root;
  907. }
  908. /* Traverse both local and global hash tables. */
  909. struct elf64_ia64_dyn_sym_traverse_data
  910. {
  911. bool (*func) (struct elf64_ia64_dyn_sym_info *, void *);
  912. void * data;
  913. };
  914. static bool
  915. elf64_ia64_global_dyn_sym_thunk (struct elf_link_hash_entry *xentry,
  916. void * xdata)
  917. {
  918. struct elf64_ia64_link_hash_entry *entry
  919. = (struct elf64_ia64_link_hash_entry *) xentry;
  920. struct elf64_ia64_dyn_sym_traverse_data *data
  921. = (struct elf64_ia64_dyn_sym_traverse_data *) xdata;
  922. struct elf64_ia64_dyn_sym_info *dyn_i;
  923. unsigned int count;
  924. if (entry->root.root.type == bfd_link_hash_warning)
  925. entry = (struct elf64_ia64_link_hash_entry *) entry->root.root.u.i.link;
  926. for (count = entry->count, dyn_i = entry->info;
  927. count != 0;
  928. count--, dyn_i++)
  929. if (! (*data->func) (dyn_i, data->data))
  930. return false;
  931. return true;
  932. }
  933. static int
  934. elf64_ia64_local_dyn_sym_thunk (void **slot, void * xdata)
  935. {
  936. struct elf64_ia64_local_hash_entry *entry
  937. = (struct elf64_ia64_local_hash_entry *) *slot;
  938. struct elf64_ia64_dyn_sym_traverse_data *data
  939. = (struct elf64_ia64_dyn_sym_traverse_data *) xdata;
  940. struct elf64_ia64_dyn_sym_info *dyn_i;
  941. unsigned int count;
  942. for (count = entry->count, dyn_i = entry->info;
  943. count != 0;
  944. count--, dyn_i++)
  945. if (! (*data->func) (dyn_i, data->data))
  946. return false;
  947. return true;
  948. }
  949. static void
  950. elf64_ia64_dyn_sym_traverse (struct elf64_ia64_link_hash_table *ia64_info,
  951. bool (*func) (struct elf64_ia64_dyn_sym_info *, void *),
  952. void * data)
  953. {
  954. struct elf64_ia64_dyn_sym_traverse_data xdata;
  955. xdata.func = func;
  956. xdata.data = data;
  957. elf_link_hash_traverse (&ia64_info->root,
  958. elf64_ia64_global_dyn_sym_thunk, &xdata);
  959. htab_traverse (ia64_info->loc_hash_table,
  960. elf64_ia64_local_dyn_sym_thunk, &xdata);
  961. }
  962. #define NOTE_NAME "IPF/VMS"
  963. static bool
  964. create_ia64_vms_notes (bfd *abfd, struct bfd_link_info *info,
  965. unsigned int time_hi, unsigned int time_lo)
  966. {
  967. #define NBR_NOTES 7
  968. Elf_Internal_Note notes[NBR_NOTES];
  969. char *module_name;
  970. int module_name_len;
  971. unsigned char cur_time[8];
  972. Elf64_External_VMS_ORIG_DYN_Note *orig_dyn;
  973. unsigned int orig_dyn_size;
  974. unsigned int note_size;
  975. int i;
  976. unsigned char *noteptr;
  977. unsigned char *note_contents;
  978. struct elf64_ia64_link_hash_table *ia64_info;
  979. ia64_info = elf64_ia64_hash_table (info);
  980. module_name = vms_get_module_name (bfd_get_filename (abfd), true);
  981. module_name_len = strlen (module_name) + 1;
  982. bfd_putl32 (time_lo, cur_time + 0);
  983. bfd_putl32 (time_hi, cur_time + 4);
  984. /* Note 0: IMGNAM. */
  985. notes[0].type = NT_VMS_IMGNAM;
  986. notes[0].descdata = module_name;
  987. notes[0].descsz = module_name_len;
  988. /* Note 1: GSTNAM. */
  989. notes[1].type = NT_VMS_GSTNAM;
  990. notes[1].descdata = module_name;
  991. notes[1].descsz = module_name_len;
  992. /* Note 2: IMGID. */
  993. #define IMG_ID "V1.0"
  994. notes[2].type = NT_VMS_IMGID;
  995. notes[2].descdata = IMG_ID;
  996. notes[2].descsz = sizeof (IMG_ID);
  997. /* Note 3: Linktime. */
  998. notes[3].type = NT_VMS_LINKTIME;
  999. notes[3].descdata = (char *)cur_time;
  1000. notes[3].descsz = sizeof (cur_time);
  1001. /* Note 4: Linker id. */
  1002. notes[4].type = NT_VMS_LINKID;
  1003. notes[4].descdata = "GNU ld " BFD_VERSION_STRING;
  1004. notes[4].descsz = strlen (notes[4].descdata) + 1;
  1005. /* Note 5: Original dyn. */
  1006. orig_dyn_size = (sizeof (*orig_dyn) + sizeof (IMG_ID) - 1 + 7) & ~7;
  1007. orig_dyn = bfd_zalloc (abfd, orig_dyn_size);
  1008. if (orig_dyn == NULL)
  1009. return false;
  1010. bfd_putl32 (1, orig_dyn->major_id);
  1011. bfd_putl32 (3, orig_dyn->minor_id);
  1012. memcpy (orig_dyn->manipulation_date, cur_time, sizeof (cur_time));
  1013. bfd_putl64 (VMS_LF_IMGSTA | VMS_LF_MAIN, orig_dyn->link_flags);
  1014. bfd_putl32 (EF_IA_64_ABI64, orig_dyn->elf_flags);
  1015. memcpy (orig_dyn->imgid, IMG_ID, sizeof (IMG_ID));
  1016. notes[5].type = NT_VMS_ORIG_DYN;
  1017. notes[5].descdata = (char *)orig_dyn;
  1018. notes[5].descsz = orig_dyn_size;
  1019. /* Note 3: Patchtime. */
  1020. notes[6].type = NT_VMS_PATCHTIME;
  1021. notes[6].descdata = (char *)cur_time;
  1022. notes[6].descsz = sizeof (cur_time);
  1023. /* Compute notes size. */
  1024. note_size = 0;
  1025. for (i = 0; i < NBR_NOTES; i++)
  1026. note_size += sizeof (Elf64_External_VMS_Note) - 1
  1027. + ((sizeof (NOTE_NAME) - 1 + 7) & ~7)
  1028. + ((notes[i].descsz + 7) & ~7);
  1029. /* Malloc a temporary buffer large enough for most notes */
  1030. note_contents = (unsigned char *) bfd_zalloc (abfd, note_size);
  1031. if (note_contents == NULL)
  1032. return false;
  1033. noteptr = note_contents;
  1034. /* Fill notes. */
  1035. for (i = 0; i < NBR_NOTES; i++)
  1036. {
  1037. Elf64_External_VMS_Note *enote = (Elf64_External_VMS_Note *) noteptr;
  1038. bfd_putl64 (sizeof (NOTE_NAME) - 1, enote->namesz);
  1039. bfd_putl64 (notes[i].descsz, enote->descsz);
  1040. bfd_putl64 (notes[i].type, enote->type);
  1041. noteptr = (unsigned char *)enote->name;
  1042. memcpy (noteptr, NOTE_NAME, sizeof (NOTE_NAME) - 1);
  1043. noteptr += (sizeof (NOTE_NAME) - 1 + 7) & ~7;
  1044. memcpy (noteptr, notes[i].descdata, notes[i].descsz);
  1045. noteptr += (notes[i].descsz + 7) & ~7;
  1046. }
  1047. ia64_info->note_sec->contents = note_contents;
  1048. ia64_info->note_sec->size = note_size;
  1049. free (module_name);
  1050. return true;
  1051. }
  1052. static bool
  1053. elf64_ia64_create_dynamic_sections (bfd *abfd,
  1054. struct bfd_link_info *info)
  1055. {
  1056. struct elf64_ia64_link_hash_table *ia64_info;
  1057. asection *s;
  1058. flagword flags;
  1059. const struct elf_backend_data *bed;
  1060. ia64_info = elf64_ia64_hash_table (info);
  1061. if (ia64_info == NULL)
  1062. return false;
  1063. if (elf_hash_table (info)->dynamic_sections_created)
  1064. return true;
  1065. abfd = elf_hash_table (info)->dynobj;
  1066. bed = get_elf_backend_data (abfd);
  1067. flags = bed->dynamic_sec_flags;
  1068. s = bfd_make_section_anyway_with_flags (abfd, ".dynamic",
  1069. flags | SEC_READONLY);
  1070. if (s == NULL
  1071. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  1072. return false;
  1073. s = bfd_make_section_anyway_with_flags (abfd, ".plt", flags | SEC_READONLY);
  1074. if (s == NULL
  1075. || !bfd_set_section_alignment (s, bed->plt_alignment))
  1076. return false;
  1077. ia64_info->root.splt = s;
  1078. if (!get_got (abfd, ia64_info))
  1079. return false;
  1080. if (!get_pltoff (abfd, ia64_info))
  1081. return false;
  1082. s = bfd_make_section_anyway_with_flags (abfd, ".vmsdynstr",
  1083. (SEC_ALLOC
  1084. | SEC_HAS_CONTENTS
  1085. | SEC_IN_MEMORY
  1086. | SEC_LINKER_CREATED));
  1087. if (s == NULL
  1088. || !bfd_set_section_alignment (s, 0))
  1089. return false;
  1090. /* Create a fixup section. */
  1091. s = bfd_make_section_anyway_with_flags (abfd, ".fixups",
  1092. (SEC_ALLOC
  1093. | SEC_HAS_CONTENTS
  1094. | SEC_IN_MEMORY
  1095. | SEC_LINKER_CREATED));
  1096. if (s == NULL
  1097. || !bfd_set_section_alignment (s, 3))
  1098. return false;
  1099. ia64_info->fixups_sec = s;
  1100. /* Create the transfer fixup section. */
  1101. s = bfd_make_section_anyway_with_flags (abfd, ".transfer",
  1102. (SEC_ALLOC
  1103. | SEC_HAS_CONTENTS
  1104. | SEC_IN_MEMORY
  1105. | SEC_LINKER_CREATED));
  1106. if (s == NULL
  1107. || !bfd_set_section_alignment (s, 3))
  1108. return false;
  1109. s->size = sizeof (struct elf64_vms_transfer);
  1110. ia64_info->transfer_sec = s;
  1111. /* Create note section. */
  1112. s = bfd_make_section_anyway_with_flags (abfd, ".vms.note",
  1113. (SEC_LINKER_CREATED
  1114. | SEC_HAS_CONTENTS
  1115. | SEC_IN_MEMORY
  1116. | SEC_READONLY));
  1117. if (s == NULL
  1118. || !bfd_set_section_alignment (s, 3))
  1119. return false;
  1120. ia64_info->note_sec = s;
  1121. elf_hash_table (info)->dynamic_sections_created = true;
  1122. return true;
  1123. }
  1124. /* Find and/or create a hash entry for local symbol. */
  1125. static struct elf64_ia64_local_hash_entry *
  1126. get_local_sym_hash (struct elf64_ia64_link_hash_table *ia64_info,
  1127. bfd *abfd, const Elf_Internal_Rela *rel,
  1128. bool create)
  1129. {
  1130. struct elf64_ia64_local_hash_entry e, *ret;
  1131. asection *sec = abfd->sections;
  1132. hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
  1133. ELF64_R_SYM (rel->r_info));
  1134. void **slot;
  1135. e.id = sec->id;
  1136. e.r_sym = ELF64_R_SYM (rel->r_info);
  1137. slot = htab_find_slot_with_hash (ia64_info->loc_hash_table, &e, h,
  1138. create ? INSERT : NO_INSERT);
  1139. if (!slot)
  1140. return NULL;
  1141. if (*slot)
  1142. return (struct elf64_ia64_local_hash_entry *) *slot;
  1143. ret = (struct elf64_ia64_local_hash_entry *)
  1144. objalloc_alloc ((struct objalloc *) ia64_info->loc_hash_memory,
  1145. sizeof (struct elf64_ia64_local_hash_entry));
  1146. if (ret)
  1147. {
  1148. memset (ret, 0, sizeof (*ret));
  1149. ret->id = sec->id;
  1150. ret->r_sym = ELF64_R_SYM (rel->r_info);
  1151. *slot = ret;
  1152. }
  1153. return ret;
  1154. }
  1155. /* Used to sort elf64_ia64_dyn_sym_info array. */
  1156. static int
  1157. addend_compare (const void *xp, const void *yp)
  1158. {
  1159. const struct elf64_ia64_dyn_sym_info *x
  1160. = (const struct elf64_ia64_dyn_sym_info *) xp;
  1161. const struct elf64_ia64_dyn_sym_info *y
  1162. = (const struct elf64_ia64_dyn_sym_info *) yp;
  1163. return x->addend < y->addend ? -1 : x->addend > y->addend ? 1 : 0;
  1164. }
  1165. /* Sort elf64_ia64_dyn_sym_info array and remove duplicates. */
  1166. static unsigned int
  1167. sort_dyn_sym_info (struct elf64_ia64_dyn_sym_info *info,
  1168. unsigned int count)
  1169. {
  1170. bfd_vma curr, prev, got_offset;
  1171. unsigned int i, kept, dupes, diff, dest, src, len;
  1172. qsort (info, count, sizeof (*info), addend_compare);
  1173. /* Find the first duplicate. */
  1174. prev = info [0].addend;
  1175. got_offset = info [0].got_offset;
  1176. for (i = 1; i < count; i++)
  1177. {
  1178. curr = info [i].addend;
  1179. if (curr == prev)
  1180. {
  1181. /* For duplicates, make sure that GOT_OFFSET is valid. */
  1182. if (got_offset == (bfd_vma) -1)
  1183. got_offset = info [i].got_offset;
  1184. break;
  1185. }
  1186. got_offset = info [i].got_offset;
  1187. prev = curr;
  1188. }
  1189. /* We may move a block of elements to here. */
  1190. dest = i++;
  1191. /* Remove duplicates. */
  1192. if (i < count)
  1193. {
  1194. while (i < count)
  1195. {
  1196. /* For duplicates, make sure that the kept one has a valid
  1197. got_offset. */
  1198. kept = dest - 1;
  1199. if (got_offset != (bfd_vma) -1)
  1200. info [kept].got_offset = got_offset;
  1201. curr = info [i].addend;
  1202. got_offset = info [i].got_offset;
  1203. /* Move a block of elements whose first one is different from
  1204. the previous. */
  1205. if (curr == prev)
  1206. {
  1207. for (src = i + 1; src < count; src++)
  1208. {
  1209. if (info [src].addend != curr)
  1210. break;
  1211. /* For duplicates, make sure that GOT_OFFSET is
  1212. valid. */
  1213. if (got_offset == (bfd_vma) -1)
  1214. got_offset = info [src].got_offset;
  1215. }
  1216. /* Make sure that the kept one has a valid got_offset. */
  1217. if (got_offset != (bfd_vma) -1)
  1218. info [kept].got_offset = got_offset;
  1219. }
  1220. else
  1221. src = i;
  1222. if (src >= count)
  1223. break;
  1224. /* Find the next duplicate. SRC will be kept. */
  1225. prev = info [src].addend;
  1226. got_offset = info [src].got_offset;
  1227. for (dupes = src + 1; dupes < count; dupes ++)
  1228. {
  1229. curr = info [dupes].addend;
  1230. if (curr == prev)
  1231. {
  1232. /* Make sure that got_offset is valid. */
  1233. if (got_offset == (bfd_vma) -1)
  1234. got_offset = info [dupes].got_offset;
  1235. /* For duplicates, make sure that the kept one has
  1236. a valid got_offset. */
  1237. if (got_offset != (bfd_vma) -1)
  1238. info [dupes - 1].got_offset = got_offset;
  1239. break;
  1240. }
  1241. got_offset = info [dupes].got_offset;
  1242. prev = curr;
  1243. }
  1244. /* How much to move. */
  1245. len = dupes - src;
  1246. i = dupes + 1;
  1247. if (len == 1 && dupes < count)
  1248. {
  1249. /* If we only move 1 element, we combine it with the next
  1250. one. There must be at least a duplicate. Find the
  1251. next different one. */
  1252. for (diff = dupes + 1, src++; diff < count; diff++, src++)
  1253. {
  1254. if (info [diff].addend != curr)
  1255. break;
  1256. /* Make sure that got_offset is valid. */
  1257. if (got_offset == (bfd_vma) -1)
  1258. got_offset = info [diff].got_offset;
  1259. }
  1260. /* Makre sure that the last duplicated one has an valid
  1261. offset. */
  1262. BFD_ASSERT (curr == prev);
  1263. if (got_offset != (bfd_vma) -1)
  1264. info [diff - 1].got_offset = got_offset;
  1265. if (diff < count)
  1266. {
  1267. /* Find the next duplicate. Track the current valid
  1268. offset. */
  1269. prev = info [diff].addend;
  1270. got_offset = info [diff].got_offset;
  1271. for (dupes = diff + 1; dupes < count; dupes ++)
  1272. {
  1273. curr = info [dupes].addend;
  1274. if (curr == prev)
  1275. {
  1276. /* For duplicates, make sure that GOT_OFFSET
  1277. is valid. */
  1278. if (got_offset == (bfd_vma) -1)
  1279. got_offset = info [dupes].got_offset;
  1280. break;
  1281. }
  1282. got_offset = info [dupes].got_offset;
  1283. prev = curr;
  1284. diff++;
  1285. }
  1286. len = diff - src + 1;
  1287. i = diff + 1;
  1288. }
  1289. }
  1290. memmove (&info [dest], &info [src], len * sizeof (*info));
  1291. dest += len;
  1292. }
  1293. count = dest;
  1294. }
  1295. else
  1296. {
  1297. /* When we get here, either there is no duplicate at all or
  1298. the only duplicate is the last element. */
  1299. if (dest < count)
  1300. {
  1301. /* If the last element is a duplicate, make sure that the
  1302. kept one has a valid got_offset. We also update count. */
  1303. if (got_offset != (bfd_vma) -1)
  1304. info [dest - 1].got_offset = got_offset;
  1305. count = dest;
  1306. }
  1307. }
  1308. return count;
  1309. }
  1310. /* Find and/or create a descriptor for dynamic symbol info. This will
  1311. vary based on global or local symbol, and the addend to the reloc.
  1312. We don't sort when inserting. Also, we sort and eliminate
  1313. duplicates if there is an unsorted section. Typically, this will
  1314. only happen once, because we do all insertions before lookups. We
  1315. then use bsearch to do a lookup. This also allows lookups to be
  1316. fast. So we have fast insertion (O(log N) due to duplicate check),
  1317. fast lookup (O(log N)) and one sort (O(N log N) expected time).
  1318. Previously, all lookups were O(N) because of the use of the linked
  1319. list and also all insertions were O(N) because of the check for
  1320. duplicates. There are some complications here because the array
  1321. size grows occasionally, which may add an O(N) factor, but this
  1322. should be rare. Also, we free the excess array allocation, which
  1323. requires a copy which is O(N), but this only happens once. */
  1324. static struct elf64_ia64_dyn_sym_info *
  1325. get_dyn_sym_info (struct elf64_ia64_link_hash_table *ia64_info,
  1326. struct elf_link_hash_entry *h, bfd *abfd,
  1327. const Elf_Internal_Rela *rel, bool create)
  1328. {
  1329. struct elf64_ia64_dyn_sym_info **info_p, *info, *dyn_i, key;
  1330. unsigned int *count_p, *sorted_count_p, *size_p;
  1331. unsigned int count, sorted_count, size;
  1332. bfd_vma addend = rel ? rel->r_addend : 0;
  1333. bfd_size_type amt;
  1334. if (h)
  1335. {
  1336. struct elf64_ia64_link_hash_entry *global_h;
  1337. global_h = (struct elf64_ia64_link_hash_entry *) h;
  1338. info_p = &global_h->info;
  1339. count_p = &global_h->count;
  1340. sorted_count_p = &global_h->sorted_count;
  1341. size_p = &global_h->size;
  1342. }
  1343. else
  1344. {
  1345. struct elf64_ia64_local_hash_entry *loc_h;
  1346. loc_h = get_local_sym_hash (ia64_info, abfd, rel, create);
  1347. if (!loc_h)
  1348. {
  1349. BFD_ASSERT (!create);
  1350. return NULL;
  1351. }
  1352. info_p = &loc_h->info;
  1353. count_p = &loc_h->count;
  1354. sorted_count_p = &loc_h->sorted_count;
  1355. size_p = &loc_h->size;
  1356. }
  1357. count = *count_p;
  1358. sorted_count = *sorted_count_p;
  1359. size = *size_p;
  1360. info = *info_p;
  1361. if (create)
  1362. {
  1363. /* When we create the array, we don't check for duplicates,
  1364. except in the previously sorted section if one exists, and
  1365. against the last inserted entry. This allows insertions to
  1366. be fast. */
  1367. if (info)
  1368. {
  1369. if (sorted_count)
  1370. {
  1371. /* Try bsearch first on the sorted section. */
  1372. key.addend = addend;
  1373. dyn_i = bsearch (&key, info, sorted_count,
  1374. sizeof (*info), addend_compare);
  1375. if (dyn_i)
  1376. {
  1377. return dyn_i;
  1378. }
  1379. }
  1380. /* Do a quick check for the last inserted entry. */
  1381. dyn_i = info + count - 1;
  1382. if (dyn_i->addend == addend)
  1383. {
  1384. return dyn_i;
  1385. }
  1386. }
  1387. if (size == 0)
  1388. {
  1389. /* It is the very first element. We create the array of size
  1390. 1. */
  1391. size = 1;
  1392. amt = size * sizeof (*info);
  1393. info = bfd_malloc (amt);
  1394. }
  1395. else if (size <= count)
  1396. {
  1397. /* We double the array size every time when we reach the
  1398. size limit. */
  1399. size += size;
  1400. amt = size * sizeof (*info);
  1401. info = bfd_realloc (info, amt);
  1402. }
  1403. else
  1404. goto has_space;
  1405. if (info == NULL)
  1406. return NULL;
  1407. *size_p = size;
  1408. *info_p = info;
  1409. has_space:
  1410. /* Append the new one to the array. */
  1411. dyn_i = info + count;
  1412. memset (dyn_i, 0, sizeof (*dyn_i));
  1413. dyn_i->got_offset = (bfd_vma) -1;
  1414. dyn_i->addend = addend;
  1415. /* We increment count only since the new ones are unsorted and
  1416. may have duplicate. */
  1417. (*count_p)++;
  1418. }
  1419. else
  1420. {
  1421. /* It is a lookup without insertion. Sort array if part of the
  1422. array isn't sorted. */
  1423. if (count != sorted_count)
  1424. {
  1425. count = sort_dyn_sym_info (info, count);
  1426. *count_p = count;
  1427. *sorted_count_p = count;
  1428. }
  1429. /* Free unused memory. */
  1430. if (size != count)
  1431. {
  1432. amt = count * sizeof (*info);
  1433. info = bfd_malloc (amt);
  1434. if (info != NULL)
  1435. {
  1436. memcpy (info, *info_p, amt);
  1437. free (*info_p);
  1438. *size_p = count;
  1439. *info_p = info;
  1440. }
  1441. }
  1442. key.addend = addend;
  1443. dyn_i = bsearch (&key, info, count,
  1444. sizeof (*info), addend_compare);
  1445. }
  1446. return dyn_i;
  1447. }
  1448. static asection *
  1449. get_got (bfd *abfd, struct elf64_ia64_link_hash_table *ia64_info)
  1450. {
  1451. asection *got;
  1452. bfd *dynobj;
  1453. got = ia64_info->root.sgot;
  1454. if (!got)
  1455. {
  1456. flagword flags;
  1457. dynobj = ia64_info->root.dynobj;
  1458. if (!dynobj)
  1459. ia64_info->root.dynobj = dynobj = abfd;
  1460. /* The .got section is always aligned at 8 bytes. */
  1461. flags = get_elf_backend_data (dynobj)->dynamic_sec_flags;
  1462. got = bfd_make_section_anyway_with_flags (dynobj, ".got",
  1463. flags | SEC_SMALL_DATA);
  1464. if (got == NULL
  1465. || !bfd_set_section_alignment (got, 3))
  1466. return NULL;
  1467. ia64_info->root.sgot = got;
  1468. }
  1469. return got;
  1470. }
  1471. /* Create function descriptor section (.opd). This section is called .opd
  1472. because it contains "official procedure descriptors". The "official"
  1473. refers to the fact that these descriptors are used when taking the address
  1474. of a procedure, thus ensuring a unique address for each procedure. */
  1475. static asection *
  1476. get_fptr (bfd *abfd, struct bfd_link_info *info,
  1477. struct elf64_ia64_link_hash_table *ia64_info)
  1478. {
  1479. asection *fptr;
  1480. bfd *dynobj;
  1481. fptr = ia64_info->fptr_sec;
  1482. if (!fptr)
  1483. {
  1484. dynobj = ia64_info->root.dynobj;
  1485. if (!dynobj)
  1486. ia64_info->root.dynobj = dynobj = abfd;
  1487. fptr = bfd_make_section_anyway_with_flags (dynobj, ".opd",
  1488. (SEC_ALLOC
  1489. | SEC_LOAD
  1490. | SEC_HAS_CONTENTS
  1491. | SEC_IN_MEMORY
  1492. | (bfd_link_pie (info) ? 0
  1493. : SEC_READONLY)
  1494. | SEC_LINKER_CREATED));
  1495. if (!fptr
  1496. || !bfd_set_section_alignment (fptr, 4))
  1497. {
  1498. BFD_ASSERT (0);
  1499. return NULL;
  1500. }
  1501. ia64_info->fptr_sec = fptr;
  1502. if (bfd_link_pie (info))
  1503. {
  1504. asection *fptr_rel;
  1505. fptr_rel = bfd_make_section_anyway_with_flags (dynobj, ".rela.opd",
  1506. (SEC_ALLOC | SEC_LOAD
  1507. | SEC_HAS_CONTENTS
  1508. | SEC_IN_MEMORY
  1509. | SEC_LINKER_CREATED
  1510. | SEC_READONLY));
  1511. if (fptr_rel == NULL
  1512. || !bfd_set_section_alignment (fptr_rel, 3))
  1513. {
  1514. BFD_ASSERT (0);
  1515. return NULL;
  1516. }
  1517. ia64_info->rel_fptr_sec = fptr_rel;
  1518. }
  1519. }
  1520. return fptr;
  1521. }
  1522. static asection *
  1523. get_pltoff (bfd *abfd, struct elf64_ia64_link_hash_table *ia64_info)
  1524. {
  1525. asection *pltoff;
  1526. bfd *dynobj;
  1527. pltoff = ia64_info->pltoff_sec;
  1528. if (!pltoff)
  1529. {
  1530. dynobj = ia64_info->root.dynobj;
  1531. if (!dynobj)
  1532. ia64_info->root.dynobj = dynobj = abfd;
  1533. pltoff = bfd_make_section_anyway_with_flags (dynobj,
  1534. ELF_STRING_ia64_pltoff,
  1535. (SEC_ALLOC
  1536. | SEC_LOAD
  1537. | SEC_HAS_CONTENTS
  1538. | SEC_IN_MEMORY
  1539. | SEC_SMALL_DATA
  1540. | SEC_LINKER_CREATED));
  1541. if (!pltoff
  1542. || !bfd_set_section_alignment (pltoff, 4))
  1543. {
  1544. BFD_ASSERT (0);
  1545. return NULL;
  1546. }
  1547. ia64_info->pltoff_sec = pltoff;
  1548. }
  1549. return pltoff;
  1550. }
  1551. static asection *
  1552. get_reloc_section (bfd *abfd,
  1553. struct elf64_ia64_link_hash_table *ia64_info,
  1554. asection *sec, bool create)
  1555. {
  1556. const char *srel_name;
  1557. asection *srel;
  1558. bfd *dynobj;
  1559. srel_name = (bfd_elf_string_from_elf_section
  1560. (abfd, elf_elfheader(abfd)->e_shstrndx,
  1561. _bfd_elf_single_rel_hdr (sec)->sh_name));
  1562. if (srel_name == NULL)
  1563. return NULL;
  1564. BFD_ASSERT ((startswith (srel_name, ".rela")
  1565. && strcmp (bfd_section_name (sec), srel_name+5) == 0)
  1566. || (startswith (srel_name, ".rel")
  1567. && strcmp (bfd_section_name (sec), srel_name+4) == 0));
  1568. dynobj = ia64_info->root.dynobj;
  1569. if (!dynobj)
  1570. ia64_info->root.dynobj = dynobj = abfd;
  1571. srel = bfd_get_linker_section (dynobj, srel_name);
  1572. if (srel == NULL && create)
  1573. {
  1574. srel = bfd_make_section_anyway_with_flags (dynobj, srel_name,
  1575. (SEC_ALLOC | SEC_LOAD
  1576. | SEC_HAS_CONTENTS
  1577. | SEC_IN_MEMORY
  1578. | SEC_LINKER_CREATED
  1579. | SEC_READONLY));
  1580. if (srel == NULL
  1581. || !bfd_set_section_alignment (srel, 3))
  1582. return NULL;
  1583. }
  1584. return srel;
  1585. }
  1586. static bool
  1587. count_dyn_reloc (bfd *abfd, struct elf64_ia64_dyn_sym_info *dyn_i,
  1588. asection *srel, int type)
  1589. {
  1590. struct elf64_ia64_dyn_reloc_entry *rent;
  1591. for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
  1592. if (rent->srel == srel && rent->type == type)
  1593. break;
  1594. if (!rent)
  1595. {
  1596. rent = ((struct elf64_ia64_dyn_reloc_entry *)
  1597. bfd_alloc (abfd, (bfd_size_type) sizeof (*rent)));
  1598. if (!rent)
  1599. return false;
  1600. rent->next = dyn_i->reloc_entries;
  1601. rent->srel = srel;
  1602. rent->type = type;
  1603. rent->count = 0;
  1604. dyn_i->reloc_entries = rent;
  1605. }
  1606. rent->count++;
  1607. return true;
  1608. }
  1609. static bool
  1610. elf64_ia64_check_relocs (bfd *abfd, struct bfd_link_info *info,
  1611. asection *sec,
  1612. const Elf_Internal_Rela *relocs)
  1613. {
  1614. struct elf64_ia64_link_hash_table *ia64_info;
  1615. const Elf_Internal_Rela *relend;
  1616. Elf_Internal_Shdr *symtab_hdr;
  1617. const Elf_Internal_Rela *rel;
  1618. asection *got, *fptr, *srel, *pltoff;
  1619. enum {
  1620. NEED_GOT = 1,
  1621. NEED_GOTX = 2,
  1622. NEED_FPTR = 4,
  1623. NEED_PLTOFF = 8,
  1624. NEED_MIN_PLT = 16,
  1625. NEED_FULL_PLT = 32,
  1626. NEED_DYNREL = 64,
  1627. NEED_LTOFF_FPTR = 128
  1628. };
  1629. int need_entry;
  1630. struct elf_link_hash_entry *h;
  1631. unsigned long r_symndx;
  1632. bool maybe_dynamic;
  1633. if (bfd_link_relocatable (info))
  1634. return true;
  1635. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  1636. ia64_info = elf64_ia64_hash_table (info);
  1637. if (ia64_info == NULL)
  1638. return false;
  1639. got = fptr = srel = pltoff = NULL;
  1640. relend = relocs + sec->reloc_count;
  1641. /* We scan relocations first to create dynamic relocation arrays. We
  1642. modified get_dyn_sym_info to allow fast insertion and support fast
  1643. lookup in the next loop. */
  1644. for (rel = relocs; rel < relend; ++rel)
  1645. {
  1646. r_symndx = ELF64_R_SYM (rel->r_info);
  1647. if (r_symndx >= symtab_hdr->sh_info)
  1648. {
  1649. long indx = r_symndx - symtab_hdr->sh_info;
  1650. h = elf_sym_hashes (abfd)[indx];
  1651. while (h->root.type == bfd_link_hash_indirect
  1652. || h->root.type == bfd_link_hash_warning)
  1653. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1654. }
  1655. else
  1656. h = NULL;
  1657. /* We can only get preliminary data on whether a symbol is
  1658. locally or externally defined, as not all of the input files
  1659. have yet been processed. Do something with what we know, as
  1660. this may help reduce memory usage and processing time later. */
  1661. maybe_dynamic = (h && ((!bfd_link_executable (info)
  1662. && (!SYMBOLIC_BIND (info, h)
  1663. || info->unresolved_syms_in_shared_libs == RM_IGNORE))
  1664. || !h->def_regular
  1665. || h->root.type == bfd_link_hash_defweak));
  1666. need_entry = 0;
  1667. switch (ELF64_R_TYPE (rel->r_info))
  1668. {
  1669. case R_IA64_TPREL64MSB:
  1670. case R_IA64_TPREL64LSB:
  1671. case R_IA64_LTOFF_TPREL22:
  1672. case R_IA64_DTPREL32MSB:
  1673. case R_IA64_DTPREL32LSB:
  1674. case R_IA64_DTPREL64MSB:
  1675. case R_IA64_DTPREL64LSB:
  1676. case R_IA64_LTOFF_DTPREL22:
  1677. case R_IA64_DTPMOD64MSB:
  1678. case R_IA64_DTPMOD64LSB:
  1679. case R_IA64_LTOFF_DTPMOD22:
  1680. abort ();
  1681. break;
  1682. case R_IA64_IPLTMSB:
  1683. case R_IA64_IPLTLSB:
  1684. break;
  1685. case R_IA64_LTOFF_FPTR22:
  1686. case R_IA64_LTOFF_FPTR64I:
  1687. case R_IA64_LTOFF_FPTR32MSB:
  1688. case R_IA64_LTOFF_FPTR32LSB:
  1689. case R_IA64_LTOFF_FPTR64MSB:
  1690. case R_IA64_LTOFF_FPTR64LSB:
  1691. need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
  1692. break;
  1693. case R_IA64_FPTR64I:
  1694. case R_IA64_FPTR32MSB:
  1695. case R_IA64_FPTR32LSB:
  1696. case R_IA64_FPTR64MSB:
  1697. case R_IA64_FPTR64LSB:
  1698. if (bfd_link_pic (info) || h)
  1699. need_entry = NEED_FPTR | NEED_DYNREL;
  1700. else
  1701. need_entry = NEED_FPTR;
  1702. break;
  1703. case R_IA64_LTOFF22:
  1704. case R_IA64_LTOFF64I:
  1705. need_entry = NEED_GOT;
  1706. break;
  1707. case R_IA64_LTOFF22X:
  1708. need_entry = NEED_GOTX;
  1709. break;
  1710. case R_IA64_PLTOFF22:
  1711. case R_IA64_PLTOFF64I:
  1712. case R_IA64_PLTOFF64MSB:
  1713. case R_IA64_PLTOFF64LSB:
  1714. need_entry = NEED_PLTOFF;
  1715. if (h)
  1716. {
  1717. if (maybe_dynamic)
  1718. need_entry |= NEED_MIN_PLT;
  1719. }
  1720. else
  1721. {
  1722. (*info->callbacks->warning)
  1723. (info, _("@pltoff reloc against local symbol"), 0,
  1724. abfd, 0, (bfd_vma) 0);
  1725. }
  1726. break;
  1727. case R_IA64_PCREL21B:
  1728. case R_IA64_PCREL60B:
  1729. /* Depending on where this symbol is defined, we may or may not
  1730. need a full plt entry. Only skip if we know we'll not need
  1731. the entry -- static or symbolic, and the symbol definition
  1732. has already been seen. */
  1733. if (maybe_dynamic && rel->r_addend == 0)
  1734. need_entry = NEED_FULL_PLT;
  1735. break;
  1736. case R_IA64_IMM14:
  1737. case R_IA64_IMM22:
  1738. case R_IA64_IMM64:
  1739. case R_IA64_DIR32MSB:
  1740. case R_IA64_DIR32LSB:
  1741. case R_IA64_DIR64MSB:
  1742. case R_IA64_DIR64LSB:
  1743. /* Shared objects will always need at least a REL relocation. */
  1744. if (bfd_link_pic (info) || maybe_dynamic)
  1745. need_entry = NEED_DYNREL;
  1746. break;
  1747. case R_IA64_PCREL22:
  1748. case R_IA64_PCREL64I:
  1749. case R_IA64_PCREL32MSB:
  1750. case R_IA64_PCREL32LSB:
  1751. case R_IA64_PCREL64MSB:
  1752. case R_IA64_PCREL64LSB:
  1753. if (maybe_dynamic)
  1754. need_entry = NEED_DYNREL;
  1755. break;
  1756. }
  1757. if (!need_entry)
  1758. continue;
  1759. if ((need_entry & NEED_FPTR) != 0
  1760. && rel->r_addend)
  1761. {
  1762. (*info->callbacks->warning)
  1763. (info, _("non-zero addend in @fptr reloc"), 0,
  1764. abfd, 0, (bfd_vma) 0);
  1765. }
  1766. if (get_dyn_sym_info (ia64_info, h, abfd, rel, true) == NULL)
  1767. return false;
  1768. }
  1769. /* Now, we only do lookup without insertion, which is very fast
  1770. with the modified get_dyn_sym_info. */
  1771. for (rel = relocs; rel < relend; ++rel)
  1772. {
  1773. struct elf64_ia64_dyn_sym_info *dyn_i;
  1774. int dynrel_type = R_IA64_NONE;
  1775. r_symndx = ELF64_R_SYM (rel->r_info);
  1776. if (r_symndx >= symtab_hdr->sh_info)
  1777. {
  1778. /* We're dealing with a global symbol -- find its hash entry
  1779. and mark it as being referenced. */
  1780. long indx = r_symndx - symtab_hdr->sh_info;
  1781. h = elf_sym_hashes (abfd)[indx];
  1782. while (h->root.type == bfd_link_hash_indirect
  1783. || h->root.type == bfd_link_hash_warning)
  1784. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1785. /* PR15323, ref flags aren't set for references in the same
  1786. object. */
  1787. h->ref_regular = 1;
  1788. }
  1789. else
  1790. h = NULL;
  1791. /* We can only get preliminary data on whether a symbol is
  1792. locally or externally defined, as not all of the input files
  1793. have yet been processed. Do something with what we know, as
  1794. this may help reduce memory usage and processing time later. */
  1795. maybe_dynamic = (h && ((!bfd_link_executable (info)
  1796. && (!SYMBOLIC_BIND (info, h)
  1797. || info->unresolved_syms_in_shared_libs == RM_IGNORE))
  1798. || !h->def_regular
  1799. || h->root.type == bfd_link_hash_defweak));
  1800. need_entry = 0;
  1801. switch (ELF64_R_TYPE (rel->r_info))
  1802. {
  1803. case R_IA64_TPREL64MSB:
  1804. case R_IA64_TPREL64LSB:
  1805. case R_IA64_LTOFF_TPREL22:
  1806. case R_IA64_DTPREL32MSB:
  1807. case R_IA64_DTPREL32LSB:
  1808. case R_IA64_DTPREL64MSB:
  1809. case R_IA64_DTPREL64LSB:
  1810. case R_IA64_LTOFF_DTPREL22:
  1811. case R_IA64_DTPMOD64MSB:
  1812. case R_IA64_DTPMOD64LSB:
  1813. case R_IA64_LTOFF_DTPMOD22:
  1814. abort ();
  1815. break;
  1816. case R_IA64_LTOFF_FPTR22:
  1817. case R_IA64_LTOFF_FPTR64I:
  1818. case R_IA64_LTOFF_FPTR32MSB:
  1819. case R_IA64_LTOFF_FPTR32LSB:
  1820. case R_IA64_LTOFF_FPTR64MSB:
  1821. case R_IA64_LTOFF_FPTR64LSB:
  1822. need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
  1823. break;
  1824. case R_IA64_FPTR64I:
  1825. case R_IA64_FPTR32MSB:
  1826. case R_IA64_FPTR32LSB:
  1827. case R_IA64_FPTR64MSB:
  1828. case R_IA64_FPTR64LSB:
  1829. if (bfd_link_pic (info) || h)
  1830. need_entry = NEED_FPTR | NEED_DYNREL;
  1831. else
  1832. need_entry = NEED_FPTR;
  1833. dynrel_type = R_IA64_FPTR64LSB;
  1834. break;
  1835. case R_IA64_LTOFF22:
  1836. case R_IA64_LTOFF64I:
  1837. need_entry = NEED_GOT;
  1838. break;
  1839. case R_IA64_LTOFF22X:
  1840. need_entry = NEED_GOTX;
  1841. break;
  1842. case R_IA64_PLTOFF22:
  1843. case R_IA64_PLTOFF64I:
  1844. case R_IA64_PLTOFF64MSB:
  1845. case R_IA64_PLTOFF64LSB:
  1846. need_entry = NEED_PLTOFF;
  1847. if (h)
  1848. {
  1849. if (maybe_dynamic)
  1850. need_entry |= NEED_MIN_PLT;
  1851. }
  1852. break;
  1853. case R_IA64_PCREL21B:
  1854. case R_IA64_PCREL60B:
  1855. /* Depending on where this symbol is defined, we may or may not
  1856. need a full plt entry. Only skip if we know we'll not need
  1857. the entry -- static or symbolic, and the symbol definition
  1858. has already been seen. */
  1859. if (maybe_dynamic && rel->r_addend == 0)
  1860. need_entry = NEED_FULL_PLT;
  1861. break;
  1862. case R_IA64_IMM14:
  1863. case R_IA64_IMM22:
  1864. case R_IA64_IMM64:
  1865. case R_IA64_DIR32MSB:
  1866. case R_IA64_DIR32LSB:
  1867. case R_IA64_DIR64MSB:
  1868. case R_IA64_DIR64LSB:
  1869. /* Shared objects will always need at least a REL relocation. */
  1870. if (bfd_link_pic (info) || maybe_dynamic)
  1871. need_entry = NEED_DYNREL;
  1872. dynrel_type = R_IA64_DIR64LSB;
  1873. break;
  1874. case R_IA64_IPLTMSB:
  1875. case R_IA64_IPLTLSB:
  1876. break;
  1877. case R_IA64_PCREL22:
  1878. case R_IA64_PCREL64I:
  1879. case R_IA64_PCREL32MSB:
  1880. case R_IA64_PCREL32LSB:
  1881. case R_IA64_PCREL64MSB:
  1882. case R_IA64_PCREL64LSB:
  1883. if (maybe_dynamic)
  1884. need_entry = NEED_DYNREL;
  1885. dynrel_type = R_IA64_PCREL64LSB;
  1886. break;
  1887. }
  1888. if (!need_entry)
  1889. continue;
  1890. dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, false);
  1891. /* Record whether or not this is a local symbol. */
  1892. dyn_i->h = h;
  1893. /* Create what's needed. */
  1894. if (need_entry & (NEED_GOT | NEED_GOTX))
  1895. {
  1896. if (!got)
  1897. {
  1898. got = get_got (abfd, ia64_info);
  1899. if (!got)
  1900. return false;
  1901. }
  1902. if (need_entry & NEED_GOT)
  1903. dyn_i->want_got = 1;
  1904. if (need_entry & NEED_GOTX)
  1905. dyn_i->want_gotx = 1;
  1906. }
  1907. if (need_entry & NEED_FPTR)
  1908. {
  1909. /* Create the .opd section. */
  1910. if (!fptr)
  1911. {
  1912. fptr = get_fptr (abfd, info, ia64_info);
  1913. if (!fptr)
  1914. return false;
  1915. }
  1916. dyn_i->want_fptr = 1;
  1917. }
  1918. if (need_entry & NEED_LTOFF_FPTR)
  1919. dyn_i->want_ltoff_fptr = 1;
  1920. if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT))
  1921. {
  1922. if (!ia64_info->root.dynobj)
  1923. ia64_info->root.dynobj = abfd;
  1924. h->needs_plt = 1;
  1925. dyn_i->want_plt = 1;
  1926. }
  1927. if (need_entry & NEED_FULL_PLT)
  1928. dyn_i->want_plt2 = 1;
  1929. if (need_entry & NEED_PLTOFF)
  1930. {
  1931. /* This is needed here, in case @pltoff is used in a non-shared
  1932. link. */
  1933. if (!pltoff)
  1934. {
  1935. pltoff = get_pltoff (abfd, ia64_info);
  1936. if (!pltoff)
  1937. return false;
  1938. }
  1939. dyn_i->want_pltoff = 1;
  1940. }
  1941. if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
  1942. {
  1943. if (!srel)
  1944. {
  1945. srel = get_reloc_section (abfd, ia64_info, sec, true);
  1946. if (!srel)
  1947. return false;
  1948. }
  1949. if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type))
  1950. return false;
  1951. }
  1952. }
  1953. return true;
  1954. }
  1955. /* For cleanliness, and potentially faster dynamic loading, allocate
  1956. external GOT entries first. */
  1957. static bool
  1958. allocate_global_data_got (struct elf64_ia64_dyn_sym_info *dyn_i,
  1959. void * data)
  1960. {
  1961. struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
  1962. if ((dyn_i->want_got || dyn_i->want_gotx)
  1963. && ! dyn_i->want_fptr
  1964. && elf64_ia64_dynamic_symbol_p (dyn_i->h))
  1965. {
  1966. /* GOT entry with FPTR is done by allocate_global_fptr_got. */
  1967. dyn_i->got_offset = x->ofs;
  1968. x->ofs += 8;
  1969. }
  1970. return true;
  1971. }
  1972. /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
  1973. static bool
  1974. allocate_global_fptr_got (struct elf64_ia64_dyn_sym_info *dyn_i,
  1975. void * data)
  1976. {
  1977. struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
  1978. if (dyn_i->want_got
  1979. && dyn_i->want_fptr
  1980. && elf64_ia64_dynamic_symbol_p (dyn_i->h))
  1981. {
  1982. dyn_i->got_offset = x->ofs;
  1983. x->ofs += 8;
  1984. }
  1985. return true;
  1986. }
  1987. /* Lastly, allocate all the GOT entries for local data. */
  1988. static bool
  1989. allocate_local_got (struct elf64_ia64_dyn_sym_info *dyn_i,
  1990. void * data)
  1991. {
  1992. struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *) data;
  1993. if ((dyn_i->want_got || dyn_i->want_gotx)
  1994. && !elf64_ia64_dynamic_symbol_p (dyn_i->h))
  1995. {
  1996. dyn_i->got_offset = x->ofs;
  1997. x->ofs += 8;
  1998. }
  1999. return true;
  2000. }
  2001. /* Allocate function descriptors. We can do these for every function
  2002. in a main executable that is not exported. */
  2003. static bool
  2004. allocate_fptr (struct elf64_ia64_dyn_sym_info *dyn_i, void * data)
  2005. {
  2006. struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *) data;
  2007. if (dyn_i->want_fptr)
  2008. {
  2009. struct elf_link_hash_entry *h = dyn_i->h;
  2010. if (h)
  2011. while (h->root.type == bfd_link_hash_indirect
  2012. || h->root.type == bfd_link_hash_warning)
  2013. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  2014. if (h == NULL || !h->def_dynamic)
  2015. {
  2016. /* A non dynamic symbol. */
  2017. dyn_i->fptr_offset = x->ofs;
  2018. x->ofs += 16;
  2019. }
  2020. else
  2021. dyn_i->want_fptr = 0;
  2022. }
  2023. return true;
  2024. }
  2025. /* Allocate all the minimal PLT entries. */
  2026. static bool
  2027. allocate_plt_entries (struct elf64_ia64_dyn_sym_info *dyn_i,
  2028. void * data ATTRIBUTE_UNUSED)
  2029. {
  2030. if (dyn_i->want_plt)
  2031. {
  2032. struct elf_link_hash_entry *h = dyn_i->h;
  2033. if (h)
  2034. while (h->root.type == bfd_link_hash_indirect
  2035. || h->root.type == bfd_link_hash_warning)
  2036. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  2037. /* ??? Versioned symbols seem to lose NEEDS_PLT. */
  2038. if (elf64_ia64_dynamic_symbol_p (h))
  2039. {
  2040. dyn_i->want_pltoff = 1;
  2041. }
  2042. else
  2043. {
  2044. dyn_i->want_plt = 0;
  2045. dyn_i->want_plt2 = 0;
  2046. }
  2047. }
  2048. return true;
  2049. }
  2050. /* Allocate all the full PLT entries. */
  2051. static bool
  2052. allocate_plt2_entries (struct elf64_ia64_dyn_sym_info *dyn_i,
  2053. void * data)
  2054. {
  2055. struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
  2056. if (dyn_i->want_plt2)
  2057. {
  2058. struct elf_link_hash_entry *h = dyn_i->h;
  2059. bfd_size_type ofs = x->ofs;
  2060. dyn_i->plt2_offset = ofs;
  2061. x->ofs = ofs + PLT_FULL_ENTRY_SIZE;
  2062. while (h->root.type == bfd_link_hash_indirect
  2063. || h->root.type == bfd_link_hash_warning)
  2064. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  2065. dyn_i->h->plt.offset = ofs;
  2066. }
  2067. return true;
  2068. }
  2069. /* Allocate all the PLTOFF entries requested by relocations and
  2070. plt entries. We can't share space with allocated FPTR entries,
  2071. because the latter are not necessarily addressable by the GP.
  2072. ??? Relaxation might be able to determine that they are. */
  2073. static bool
  2074. allocate_pltoff_entries (struct elf64_ia64_dyn_sym_info *dyn_i,
  2075. void * data)
  2076. {
  2077. struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
  2078. if (dyn_i->want_pltoff)
  2079. {
  2080. dyn_i->pltoff_offset = x->ofs;
  2081. x->ofs += 16;
  2082. }
  2083. return true;
  2084. }
  2085. /* Allocate dynamic relocations for those symbols that turned out
  2086. to be dynamic. */
  2087. static bool
  2088. allocate_dynrel_entries (struct elf64_ia64_dyn_sym_info *dyn_i,
  2089. void * data)
  2090. {
  2091. struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
  2092. struct elf64_ia64_link_hash_table *ia64_info;
  2093. struct elf64_ia64_dyn_reloc_entry *rent;
  2094. bool dynamic_symbol, shared, resolved_zero;
  2095. struct elf64_ia64_link_hash_entry *h_ia64;
  2096. ia64_info = elf64_ia64_hash_table (x->info);
  2097. if (ia64_info == NULL)
  2098. return false;
  2099. /* Note that this can't be used in relation to FPTR relocs below. */
  2100. dynamic_symbol = elf64_ia64_dynamic_symbol_p (dyn_i->h);
  2101. shared = bfd_link_pic (x->info);
  2102. resolved_zero = (dyn_i->h
  2103. && ELF_ST_VISIBILITY (dyn_i->h->other)
  2104. && dyn_i->h->root.type == bfd_link_hash_undefweak);
  2105. /* Take care of the GOT and PLT relocations. */
  2106. if ((!resolved_zero
  2107. && (dynamic_symbol || shared)
  2108. && (dyn_i->want_got || dyn_i->want_gotx))
  2109. || (dyn_i->want_ltoff_fptr
  2110. && dyn_i->h
  2111. && dyn_i->h->def_dynamic))
  2112. {
  2113. /* VMS: FIX64. */
  2114. if (dyn_i->h != NULL && dyn_i->h->def_dynamic)
  2115. {
  2116. h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h;
  2117. elf_ia64_vms_tdata (h_ia64->shl)->fixups_off +=
  2118. sizeof (Elf64_External_VMS_IMAGE_FIXUP);
  2119. ia64_info->fixups_sec->size +=
  2120. sizeof (Elf64_External_VMS_IMAGE_FIXUP);
  2121. }
  2122. }
  2123. if (ia64_info->rel_fptr_sec && dyn_i->want_fptr)
  2124. {
  2125. /* VMS: only image reloc. */
  2126. if (dyn_i->h == NULL || dyn_i->h->root.type != bfd_link_hash_undefweak)
  2127. ia64_info->rel_fptr_sec->size += sizeof (Elf64_External_Rela);
  2128. }
  2129. if (!resolved_zero && dyn_i->want_pltoff)
  2130. {
  2131. /* VMS: FIXFD. */
  2132. if (dyn_i->h != NULL && dyn_i->h->def_dynamic)
  2133. {
  2134. h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h;
  2135. elf_ia64_vms_tdata (h_ia64->shl)->fixups_off +=
  2136. sizeof (Elf64_External_VMS_IMAGE_FIXUP);
  2137. ia64_info->fixups_sec->size +=
  2138. sizeof (Elf64_External_VMS_IMAGE_FIXUP);
  2139. }
  2140. }
  2141. /* Take care of the normal data relocations. */
  2142. for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
  2143. {
  2144. switch (rent->type)
  2145. {
  2146. case R_IA64_FPTR32LSB:
  2147. case R_IA64_FPTR64LSB:
  2148. /* Allocate one iff !want_fptr and not PIE, which by this point
  2149. will be true only if we're actually allocating one statically
  2150. in the main executable. Position independent executables
  2151. need a relative reloc. */
  2152. if (dyn_i->want_fptr && !bfd_link_pie (x->info))
  2153. continue;
  2154. break;
  2155. case R_IA64_PCREL32LSB:
  2156. case R_IA64_PCREL64LSB:
  2157. if (!dynamic_symbol)
  2158. continue;
  2159. break;
  2160. case R_IA64_DIR32LSB:
  2161. case R_IA64_DIR64LSB:
  2162. if (!dynamic_symbol && !shared)
  2163. continue;
  2164. break;
  2165. case R_IA64_IPLTLSB:
  2166. if (!dynamic_symbol && !shared)
  2167. continue;
  2168. break;
  2169. case R_IA64_DTPREL32LSB:
  2170. case R_IA64_TPREL64LSB:
  2171. case R_IA64_DTPREL64LSB:
  2172. case R_IA64_DTPMOD64LSB:
  2173. break;
  2174. default:
  2175. abort ();
  2176. }
  2177. /* Add a fixup. */
  2178. if (!dynamic_symbol)
  2179. abort ();
  2180. h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h;
  2181. elf_ia64_vms_tdata (h_ia64->shl)->fixups_off +=
  2182. sizeof (Elf64_External_VMS_IMAGE_FIXUP);
  2183. ia64_info->fixups_sec->size +=
  2184. sizeof (Elf64_External_VMS_IMAGE_FIXUP);
  2185. }
  2186. return true;
  2187. }
  2188. static bool
  2189. elf64_ia64_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
  2190. struct elf_link_hash_entry *h)
  2191. {
  2192. /* ??? Undefined symbols with PLT entries should be re-defined
  2193. to be the PLT entry. */
  2194. /* If this is a weak symbol, and there is a real definition, the
  2195. processor independent code will have arranged for us to see the
  2196. real definition first, and we can just use the same value. */
  2197. if (h->is_weakalias)
  2198. {
  2199. struct elf_link_hash_entry *def = weakdef (h);
  2200. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  2201. h->root.u.def.section = def->root.u.def.section;
  2202. h->root.u.def.value = def->root.u.def.value;
  2203. return true;
  2204. }
  2205. /* If this is a reference to a symbol defined by a dynamic object which
  2206. is not a function, we might allocate the symbol in our .dynbss section
  2207. and allocate a COPY dynamic relocation.
  2208. But IA-64 code is canonically PIC, so as a rule we can avoid this sort
  2209. of hackery. */
  2210. return true;
  2211. }
  2212. static bool
  2213. elf64_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  2214. struct bfd_link_info *info)
  2215. {
  2216. struct elf64_ia64_allocate_data data;
  2217. struct elf64_ia64_link_hash_table *ia64_info;
  2218. asection *sec;
  2219. bfd *dynobj;
  2220. struct elf_link_hash_table *hash_table;
  2221. hash_table = elf_hash_table (info);
  2222. dynobj = hash_table->dynobj;
  2223. ia64_info = elf64_ia64_hash_table (info);
  2224. if (ia64_info == NULL)
  2225. return false;
  2226. BFD_ASSERT(dynobj != NULL);
  2227. data.info = info;
  2228. /* Allocate the GOT entries. */
  2229. if (ia64_info->root.sgot)
  2230. {
  2231. data.ofs = 0;
  2232. elf64_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data);
  2233. elf64_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data);
  2234. elf64_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data);
  2235. ia64_info->root.sgot->size = data.ofs;
  2236. }
  2237. /* Allocate the FPTR entries. */
  2238. if (ia64_info->fptr_sec)
  2239. {
  2240. data.ofs = 0;
  2241. elf64_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data);
  2242. ia64_info->fptr_sec->size = data.ofs;
  2243. }
  2244. /* Now that we've seen all of the input files, we can decide which
  2245. symbols need plt entries. Allocate the minimal PLT entries first.
  2246. We do this even though dynamic_sections_created may be FALSE, because
  2247. this has the side-effect of clearing want_plt and want_plt2. */
  2248. data.ofs = 0;
  2249. elf64_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data);
  2250. /* Align the pointer for the plt2 entries. */
  2251. data.ofs = (data.ofs + 31) & (bfd_vma) -32;
  2252. elf64_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data);
  2253. if (data.ofs != 0 || ia64_info->root.dynamic_sections_created)
  2254. {
  2255. /* FIXME: we always reserve the memory for dynamic linker even if
  2256. there are no PLT entries since dynamic linker may assume the
  2257. reserved memory always exists. */
  2258. BFD_ASSERT (ia64_info->root.dynamic_sections_created);
  2259. ia64_info->root.splt->size = data.ofs;
  2260. }
  2261. /* Allocate the PLTOFF entries. */
  2262. if (ia64_info->pltoff_sec)
  2263. {
  2264. data.ofs = 0;
  2265. elf64_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data);
  2266. ia64_info->pltoff_sec->size = data.ofs;
  2267. }
  2268. if (ia64_info->root.dynamic_sections_created)
  2269. {
  2270. /* Allocate space for the dynamic relocations that turned out to be
  2271. required. */
  2272. elf64_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data);
  2273. }
  2274. /* We have now determined the sizes of the various dynamic sections.
  2275. Allocate memory for them. */
  2276. for (sec = dynobj->sections; sec != NULL; sec = sec->next)
  2277. {
  2278. bool strip;
  2279. if (!(sec->flags & SEC_LINKER_CREATED))
  2280. continue;
  2281. /* If we don't need this section, strip it from the output file.
  2282. There were several sections primarily related to dynamic
  2283. linking that must be create before the linker maps input
  2284. sections to output sections. The linker does that before
  2285. bfd_elf_size_dynamic_sections is called, and it is that
  2286. function which decides whether anything needs to go into
  2287. these sections. */
  2288. strip = (sec->size == 0);
  2289. if (sec == ia64_info->root.sgot)
  2290. strip = false;
  2291. else if (sec == ia64_info->root.srelgot)
  2292. {
  2293. if (strip)
  2294. ia64_info->root.srelgot = NULL;
  2295. else
  2296. /* We use the reloc_count field as a counter if we need to
  2297. copy relocs into the output file. */
  2298. sec->reloc_count = 0;
  2299. }
  2300. else if (sec == ia64_info->fptr_sec)
  2301. {
  2302. if (strip)
  2303. ia64_info->fptr_sec = NULL;
  2304. }
  2305. else if (sec == ia64_info->rel_fptr_sec)
  2306. {
  2307. if (strip)
  2308. ia64_info->rel_fptr_sec = NULL;
  2309. else
  2310. /* We use the reloc_count field as a counter if we need to
  2311. copy relocs into the output file. */
  2312. sec->reloc_count = 0;
  2313. }
  2314. else if (sec == ia64_info->root.splt)
  2315. {
  2316. if (strip)
  2317. ia64_info->root.splt = NULL;
  2318. }
  2319. else if (sec == ia64_info->pltoff_sec)
  2320. {
  2321. if (strip)
  2322. ia64_info->pltoff_sec = NULL;
  2323. }
  2324. else if (sec == ia64_info->fixups_sec)
  2325. {
  2326. if (strip)
  2327. ia64_info->fixups_sec = NULL;
  2328. }
  2329. else if (sec == ia64_info->transfer_sec)
  2330. {
  2331. ;
  2332. }
  2333. else
  2334. {
  2335. const char *name;
  2336. /* It's OK to base decisions on the section name, because none
  2337. of the dynobj section names depend upon the input files. */
  2338. name = bfd_section_name (sec);
  2339. if (strcmp (name, ".got.plt") == 0)
  2340. strip = false;
  2341. else if (startswith (name, ".rel"))
  2342. {
  2343. if (!strip)
  2344. {
  2345. /* We use the reloc_count field as a counter if we need to
  2346. copy relocs into the output file. */
  2347. sec->reloc_count = 0;
  2348. }
  2349. }
  2350. else
  2351. continue;
  2352. }
  2353. if (strip)
  2354. sec->flags |= SEC_EXCLUDE;
  2355. else
  2356. {
  2357. /* Allocate memory for the section contents. */
  2358. sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
  2359. if (sec->contents == NULL && sec->size != 0)
  2360. return false;
  2361. }
  2362. }
  2363. if (elf_hash_table (info)->dynamic_sections_created)
  2364. {
  2365. bfd *abfd;
  2366. asection *dynsec;
  2367. asection *dynstrsec;
  2368. Elf_Internal_Dyn dyn;
  2369. const struct elf_backend_data *bed;
  2370. unsigned int shl_num = 0;
  2371. bfd_vma fixups_off = 0;
  2372. bfd_vma strdyn_off;
  2373. unsigned int time_hi, time_lo;
  2374. /* The .dynamic section must exist and be empty. */
  2375. dynsec = bfd_get_linker_section (hash_table->dynobj, ".dynamic");
  2376. BFD_ASSERT (dynsec != NULL);
  2377. BFD_ASSERT (dynsec->size == 0);
  2378. dynstrsec = bfd_get_linker_section (hash_table->dynobj, ".vmsdynstr");
  2379. BFD_ASSERT (dynstrsec != NULL);
  2380. BFD_ASSERT (dynstrsec->size == 0);
  2381. dynstrsec->size = 1; /* Initial blank. */
  2382. /* Ident + link time. */
  2383. vms_get_time (&time_hi, &time_lo);
  2384. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_IDENT, 0))
  2385. return false;
  2386. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_LINKTIME,
  2387. (((bfd_uint64_t)time_hi) << 32)
  2388. + time_lo))
  2389. return false;
  2390. /* Strtab. */
  2391. strdyn_off = dynsec->size;
  2392. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_STRTAB_OFFSET, 0))
  2393. return false;
  2394. if (!_bfd_elf_add_dynamic_entry (info, DT_STRSZ, 0))
  2395. return false;
  2396. /* PLTGOT */
  2397. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_PLTGOT_SEG, 0))
  2398. return false;
  2399. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_PLTGOT_OFFSET, 0))
  2400. return false;
  2401. /* Misc. */
  2402. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FPMODE, 0x9800000))
  2403. return false;
  2404. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_LNKFLAGS,
  2405. VMS_LF_IMGSTA | VMS_LF_MAIN))
  2406. return false;
  2407. /* Add entries for shared libraries. */
  2408. for (abfd = info->input_bfds; abfd; abfd = abfd->link.next)
  2409. {
  2410. char *soname;
  2411. size_t soname_len;
  2412. bfd_size_type strindex;
  2413. bfd_byte *newcontents;
  2414. bfd_vma fixups_shl_off;
  2415. if (!(abfd->flags & DYNAMIC))
  2416. continue;
  2417. BFD_ASSERT (abfd->xvec == output_bfd->xvec);
  2418. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_NEEDED_IDENT,
  2419. elf_ia64_vms_ident (abfd)))
  2420. return false;
  2421. soname = vms_get_module_name (bfd_get_filename (abfd), true);
  2422. if (soname == NULL)
  2423. return false;
  2424. strindex = dynstrsec->size;
  2425. soname_len = strlen (soname) + 1;
  2426. newcontents = (bfd_byte *) bfd_realloc (dynstrsec->contents,
  2427. strindex + soname_len);
  2428. if (newcontents == NULL)
  2429. return false;
  2430. memcpy (newcontents + strindex, soname, soname_len);
  2431. dynstrsec->size += soname_len;
  2432. dynstrsec->contents = newcontents;
  2433. if (!_bfd_elf_add_dynamic_entry (info, DT_NEEDED, strindex))
  2434. return false;
  2435. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FIXUP_NEEDED,
  2436. shl_num))
  2437. return false;
  2438. shl_num++;
  2439. /* The fixups_off was in fact containing the size of the fixup
  2440. section. Remap into the offset. */
  2441. fixups_shl_off = elf_ia64_vms_tdata (abfd)->fixups_off;
  2442. elf_ia64_vms_tdata (abfd)->fixups_off = fixups_off;
  2443. if (!_bfd_elf_add_dynamic_entry
  2444. (info, DT_IA_64_VMS_FIXUP_RELA_CNT,
  2445. fixups_shl_off / sizeof (Elf64_External_VMS_IMAGE_FIXUP)))
  2446. return false;
  2447. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FIXUP_RELA_OFF,
  2448. fixups_off))
  2449. return false;
  2450. fixups_off += fixups_shl_off;
  2451. }
  2452. /* Unwind. */
  2453. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWINDSZ, 0))
  2454. return false;
  2455. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_CODSEG, 0))
  2456. return false;
  2457. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_INFOSEG, 0))
  2458. return false;
  2459. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_OFFSET, 0))
  2460. return false;
  2461. if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_SEG, 0))
  2462. return false;
  2463. if (!_bfd_elf_add_dynamic_entry (info, DT_NULL, 0xdead))
  2464. return false;
  2465. /* Fix the strtab entries. */
  2466. bed = get_elf_backend_data (hash_table->dynobj);
  2467. if (dynstrsec->size > 1)
  2468. dynstrsec->contents[0] = 0;
  2469. else
  2470. dynstrsec->size = 0;
  2471. /* Note: one 'spare' (ie DT_NULL) entry is added by
  2472. bfd_elf_size_dynsym_hash_dynstr. */
  2473. dyn.d_tag = DT_IA_64_VMS_STRTAB_OFFSET;
  2474. dyn.d_un.d_val = dynsec->size /* + sizeof (Elf64_External_Dyn) */;
  2475. bed->s->swap_dyn_out (hash_table->dynobj, &dyn,
  2476. dynsec->contents + strdyn_off);
  2477. dyn.d_tag = DT_STRSZ;
  2478. dyn.d_un.d_val = dynstrsec->size;
  2479. bed->s->swap_dyn_out (hash_table->dynobj, &dyn,
  2480. dynsec->contents + strdyn_off + bed->s->sizeof_dyn);
  2481. elf_ia64_vms_tdata (output_bfd)->needed_count = shl_num;
  2482. /* Note section. */
  2483. if (!create_ia64_vms_notes (output_bfd, info, time_hi, time_lo))
  2484. return false;
  2485. }
  2486. /* ??? Perhaps force __gp local. */
  2487. return true;
  2488. }
  2489. static void
  2490. elf64_ia64_install_fixup (bfd *output_bfd,
  2491. struct elf64_ia64_link_hash_table *ia64_info,
  2492. struct elf_link_hash_entry *h,
  2493. unsigned int type, asection *sec, bfd_vma offset,
  2494. bfd_vma addend)
  2495. {
  2496. asection *relsec;
  2497. Elf64_External_VMS_IMAGE_FIXUP *fixup;
  2498. struct elf64_ia64_link_hash_entry *h_ia64;
  2499. bfd_vma fixoff;
  2500. Elf_Internal_Phdr *phdr;
  2501. if (h == NULL || !h->def_dynamic)
  2502. abort ();
  2503. h_ia64 = (struct elf64_ia64_link_hash_entry *) h;
  2504. fixoff = elf_ia64_vms_tdata (h_ia64->shl)->fixups_off;
  2505. elf_ia64_vms_tdata (h_ia64->shl)->fixups_off +=
  2506. sizeof (Elf64_External_VMS_IMAGE_FIXUP);
  2507. relsec = ia64_info->fixups_sec;
  2508. fixup = (Elf64_External_VMS_IMAGE_FIXUP *)(relsec->contents + fixoff);
  2509. offset += sec->output_section->vma + sec->output_offset;
  2510. /* FIXME: this is slow. We should cache the last one used, or create a
  2511. map. */
  2512. phdr = _bfd_elf_find_segment_containing_section
  2513. (output_bfd, sec->output_section);
  2514. BFD_ASSERT (phdr != NULL);
  2515. bfd_putl64 (offset - phdr->p_vaddr, fixup->fixup_offset);
  2516. bfd_putl32 (type, fixup->type);
  2517. bfd_putl32 (phdr - elf_tdata (output_bfd)->phdr, fixup->fixup_seg);
  2518. bfd_putl64 (addend, fixup->addend);
  2519. bfd_putl32 (h->root.u.def.value, fixup->symvec_index);
  2520. bfd_putl32 (2, fixup->data_type);
  2521. }
  2522. /* Store an entry for target address TARGET_ADDR in the linkage table
  2523. and return the gp-relative address of the linkage table entry. */
  2524. static bfd_vma
  2525. set_got_entry (bfd *abfd, struct bfd_link_info *info,
  2526. struct elf64_ia64_dyn_sym_info *dyn_i,
  2527. bfd_vma addend, bfd_vma value, unsigned int dyn_r_type)
  2528. {
  2529. struct elf64_ia64_link_hash_table *ia64_info;
  2530. asection *got_sec;
  2531. bool done;
  2532. bfd_vma got_offset;
  2533. ia64_info = elf64_ia64_hash_table (info);
  2534. if (ia64_info == NULL)
  2535. return 0;
  2536. got_sec = ia64_info->root.sgot;
  2537. switch (dyn_r_type)
  2538. {
  2539. case R_IA64_TPREL64LSB:
  2540. case R_IA64_DTPMOD64LSB:
  2541. case R_IA64_DTPREL32LSB:
  2542. case R_IA64_DTPREL64LSB:
  2543. abort ();
  2544. break;
  2545. default:
  2546. done = dyn_i->got_done;
  2547. dyn_i->got_done = true;
  2548. got_offset = dyn_i->got_offset;
  2549. break;
  2550. }
  2551. BFD_ASSERT ((got_offset & 7) == 0);
  2552. if (! done)
  2553. {
  2554. /* Store the target address in the linkage table entry. */
  2555. bfd_put_64 (abfd, value, got_sec->contents + got_offset);
  2556. /* Install a dynamic relocation if needed. */
  2557. if (((bfd_link_pic (info)
  2558. && (!dyn_i->h
  2559. || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
  2560. || dyn_i->h->root.type != bfd_link_hash_undefweak))
  2561. || elf64_ia64_dynamic_symbol_p (dyn_i->h))
  2562. && (!dyn_i->want_ltoff_fptr
  2563. || !bfd_link_pie (info)
  2564. || !dyn_i->h
  2565. || dyn_i->h->root.type != bfd_link_hash_undefweak))
  2566. {
  2567. if (!dyn_i->h || !dyn_i->h->def_dynamic)
  2568. {
  2569. dyn_r_type = R_IA64_REL64LSB;
  2570. addend = value;
  2571. }
  2572. /* VMS: install a FIX32 or FIX64. */
  2573. switch (dyn_r_type)
  2574. {
  2575. case R_IA64_DIR32LSB:
  2576. case R_IA64_FPTR32LSB:
  2577. dyn_r_type = R_IA64_VMS_FIX32;
  2578. break;
  2579. case R_IA64_DIR64LSB:
  2580. case R_IA64_FPTR64LSB:
  2581. dyn_r_type = R_IA64_VMS_FIX64;
  2582. break;
  2583. default:
  2584. BFD_ASSERT (false);
  2585. break;
  2586. }
  2587. elf64_ia64_install_fixup
  2588. (info->output_bfd, ia64_info, dyn_i->h,
  2589. dyn_r_type, got_sec, got_offset, addend);
  2590. }
  2591. }
  2592. /* Return the address of the linkage table entry. */
  2593. value = (got_sec->output_section->vma
  2594. + got_sec->output_offset
  2595. + got_offset);
  2596. return value;
  2597. }
  2598. /* Fill in a function descriptor consisting of the function's code
  2599. address and its global pointer. Return the descriptor's address. */
  2600. static bfd_vma
  2601. set_fptr_entry (bfd *abfd, struct bfd_link_info *info,
  2602. struct elf64_ia64_dyn_sym_info *dyn_i,
  2603. bfd_vma value)
  2604. {
  2605. struct elf64_ia64_link_hash_table *ia64_info;
  2606. asection *fptr_sec;
  2607. ia64_info = elf64_ia64_hash_table (info);
  2608. if (ia64_info == NULL)
  2609. return 0;
  2610. fptr_sec = ia64_info->fptr_sec;
  2611. if (!dyn_i->fptr_done)
  2612. {
  2613. dyn_i->fptr_done = 1;
  2614. /* Fill in the function descriptor. */
  2615. bfd_put_64 (abfd, value, fptr_sec->contents + dyn_i->fptr_offset);
  2616. bfd_put_64 (abfd, _bfd_get_gp_value (abfd),
  2617. fptr_sec->contents + dyn_i->fptr_offset + 8);
  2618. }
  2619. /* Return the descriptor's address. */
  2620. value = (fptr_sec->output_section->vma
  2621. + fptr_sec->output_offset
  2622. + dyn_i->fptr_offset);
  2623. return value;
  2624. }
  2625. /* Fill in a PLTOFF entry consisting of the function's code address
  2626. and its global pointer. Return the descriptor's address. */
  2627. static bfd_vma
  2628. set_pltoff_entry (bfd *abfd, struct bfd_link_info *info,
  2629. struct elf64_ia64_dyn_sym_info *dyn_i,
  2630. bfd_vma value, bool is_plt)
  2631. {
  2632. struct elf64_ia64_link_hash_table *ia64_info;
  2633. asection *pltoff_sec;
  2634. ia64_info = elf64_ia64_hash_table (info);
  2635. if (ia64_info == NULL)
  2636. return 0;
  2637. pltoff_sec = ia64_info->pltoff_sec;
  2638. /* Don't do anything if this symbol uses a real PLT entry. In
  2639. that case, we'll fill this in during finish_dynamic_symbol. */
  2640. if ((! dyn_i->want_plt || is_plt)
  2641. && !dyn_i->pltoff_done)
  2642. {
  2643. bfd_vma gp = _bfd_get_gp_value (abfd);
  2644. /* Fill in the function descriptor. */
  2645. bfd_put_64 (abfd, value, pltoff_sec->contents + dyn_i->pltoff_offset);
  2646. bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8);
  2647. /* Install dynamic relocations if needed. */
  2648. if (!is_plt
  2649. && bfd_link_pic (info)
  2650. && (!dyn_i->h
  2651. || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
  2652. || dyn_i->h->root.type != bfd_link_hash_undefweak))
  2653. {
  2654. /* VMS: */
  2655. abort ();
  2656. }
  2657. dyn_i->pltoff_done = 1;
  2658. }
  2659. /* Return the descriptor's address. */
  2660. value = (pltoff_sec->output_section->vma
  2661. + pltoff_sec->output_offset
  2662. + dyn_i->pltoff_offset);
  2663. return value;
  2664. }
  2665. /* Called through qsort to sort the .IA_64.unwind section during a
  2666. non-relocatable link. Set elf64_ia64_unwind_entry_compare_bfd
  2667. to the output bfd so we can do proper endianness frobbing. */
  2668. static bfd *elf64_ia64_unwind_entry_compare_bfd;
  2669. static int
  2670. elf64_ia64_unwind_entry_compare (const void * a, const void * b)
  2671. {
  2672. bfd_vma av, bv;
  2673. av = bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd, a);
  2674. bv = bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd, b);
  2675. return (av < bv ? -1 : av > bv ? 1 : 0);
  2676. }
  2677. /* Make sure we've got ourselves a nice fat __gp value. */
  2678. static bool
  2679. elf64_ia64_choose_gp (bfd *abfd, struct bfd_link_info *info, bool final)
  2680. {
  2681. bfd_vma min_vma = (bfd_vma) -1, max_vma = 0;
  2682. bfd_vma min_short_vma = min_vma, max_short_vma = 0;
  2683. struct elf_link_hash_entry *gp;
  2684. bfd_vma gp_val;
  2685. asection *os;
  2686. struct elf64_ia64_link_hash_table *ia64_info;
  2687. ia64_info = elf64_ia64_hash_table (info);
  2688. if (ia64_info == NULL)
  2689. return false;
  2690. /* Find the min and max vma of all sections marked short. Also collect
  2691. min and max vma of any type, for use in selecting a nice gp. */
  2692. for (os = abfd->sections; os ; os = os->next)
  2693. {
  2694. bfd_vma lo, hi;
  2695. if ((os->flags & SEC_ALLOC) == 0)
  2696. continue;
  2697. lo = os->vma;
  2698. /* When this function is called from elfNN_ia64_final_link
  2699. the correct value to use is os->size. When called from
  2700. elfNN_ia64_relax_section we are in the middle of section
  2701. sizing; some sections will already have os->size set, others
  2702. will have os->size zero and os->rawsize the previous size. */
  2703. hi = os->vma + (!final && os->rawsize ? os->rawsize : os->size);
  2704. if (hi < lo)
  2705. hi = (bfd_vma) -1;
  2706. if (min_vma > lo)
  2707. min_vma = lo;
  2708. if (max_vma < hi)
  2709. max_vma = hi;
  2710. if (os->flags & SEC_SMALL_DATA)
  2711. {
  2712. if (min_short_vma > lo)
  2713. min_short_vma = lo;
  2714. if (max_short_vma < hi)
  2715. max_short_vma = hi;
  2716. }
  2717. }
  2718. if (ia64_info->min_short_sec)
  2719. {
  2720. if (min_short_vma
  2721. > (ia64_info->min_short_sec->vma
  2722. + ia64_info->min_short_offset))
  2723. min_short_vma = (ia64_info->min_short_sec->vma
  2724. + ia64_info->min_short_offset);
  2725. if (max_short_vma
  2726. < (ia64_info->max_short_sec->vma
  2727. + ia64_info->max_short_offset))
  2728. max_short_vma = (ia64_info->max_short_sec->vma
  2729. + ia64_info->max_short_offset);
  2730. }
  2731. /* See if the user wants to force a value. */
  2732. gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false,
  2733. false, false);
  2734. if (gp
  2735. && (gp->root.type == bfd_link_hash_defined
  2736. || gp->root.type == bfd_link_hash_defweak))
  2737. {
  2738. asection *gp_sec = gp->root.u.def.section;
  2739. gp_val = (gp->root.u.def.value
  2740. + gp_sec->output_section->vma
  2741. + gp_sec->output_offset);
  2742. }
  2743. else
  2744. {
  2745. /* Pick a sensible value. */
  2746. if (ia64_info->min_short_sec)
  2747. {
  2748. bfd_vma short_range = max_short_vma - min_short_vma;
  2749. /* If min_short_sec is set, pick one in the middle bewteen
  2750. min_short_vma and max_short_vma. */
  2751. if (short_range >= 0x400000)
  2752. goto overflow;
  2753. gp_val = min_short_vma + short_range / 2;
  2754. }
  2755. else
  2756. {
  2757. asection *got_sec = ia64_info->root.sgot;
  2758. /* Start with just the address of the .got. */
  2759. if (got_sec)
  2760. gp_val = got_sec->output_section->vma;
  2761. else if (max_short_vma != 0)
  2762. gp_val = min_short_vma;
  2763. else if (max_vma - min_vma < 0x200000)
  2764. gp_val = min_vma;
  2765. else
  2766. gp_val = max_vma - 0x200000 + 8;
  2767. }
  2768. /* If it is possible to address the entire image, but we
  2769. don't with the choice above, adjust. */
  2770. if (max_vma - min_vma < 0x400000
  2771. && (max_vma - gp_val >= 0x200000
  2772. || gp_val - min_vma > 0x200000))
  2773. gp_val = min_vma + 0x200000;
  2774. else if (max_short_vma != 0)
  2775. {
  2776. /* If we don't cover all the short data, adjust. */
  2777. if (max_short_vma - gp_val >= 0x200000)
  2778. gp_val = min_short_vma + 0x200000;
  2779. /* If we're addressing stuff past the end, adjust back. */
  2780. if (gp_val > max_vma)
  2781. gp_val = max_vma - 0x200000 + 8;
  2782. }
  2783. }
  2784. /* Validate whether all SHF_IA_64_SHORT sections are within
  2785. range of the chosen GP. */
  2786. if (max_short_vma != 0)
  2787. {
  2788. if (max_short_vma - min_short_vma >= 0x400000)
  2789. {
  2790. overflow:
  2791. _bfd_error_handler
  2792. /* xgettext:c-format */
  2793. (_("%pB: short data segment overflowed (%#" PRIx64 " >= 0x400000)"),
  2794. abfd, (uint64_t) (max_short_vma - min_short_vma));
  2795. return false;
  2796. }
  2797. else if ((gp_val > min_short_vma
  2798. && gp_val - min_short_vma > 0x200000)
  2799. || (gp_val < max_short_vma
  2800. && max_short_vma - gp_val >= 0x200000))
  2801. {
  2802. _bfd_error_handler
  2803. (_("%pB: __gp does not cover short data segment"), abfd);
  2804. return false;
  2805. }
  2806. }
  2807. _bfd_set_gp_value (abfd, gp_val);
  2808. return true;
  2809. }
  2810. static bool
  2811. elf64_ia64_final_link (bfd *abfd, struct bfd_link_info *info)
  2812. {
  2813. struct elf64_ia64_link_hash_table *ia64_info;
  2814. asection *unwind_output_sec;
  2815. ia64_info = elf64_ia64_hash_table (info);
  2816. if (ia64_info == NULL)
  2817. return false;
  2818. /* Make sure we've got ourselves a nice fat __gp value. */
  2819. if (!bfd_link_relocatable (info))
  2820. {
  2821. bfd_vma gp_val;
  2822. struct elf_link_hash_entry *gp;
  2823. /* We assume after gp is set, section size will only decrease. We
  2824. need to adjust gp for it. */
  2825. _bfd_set_gp_value (abfd, 0);
  2826. if (! elf64_ia64_choose_gp (abfd, info, true))
  2827. return false;
  2828. gp_val = _bfd_get_gp_value (abfd);
  2829. gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false,
  2830. false, false);
  2831. if (gp)
  2832. {
  2833. gp->root.type = bfd_link_hash_defined;
  2834. gp->root.u.def.value = gp_val;
  2835. gp->root.u.def.section = bfd_abs_section_ptr;
  2836. }
  2837. }
  2838. /* If we're producing a final executable, we need to sort the contents
  2839. of the .IA_64.unwind section. Force this section to be relocated
  2840. into memory rather than written immediately to the output file. */
  2841. unwind_output_sec = NULL;
  2842. if (!bfd_link_relocatable (info))
  2843. {
  2844. asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind);
  2845. if (s)
  2846. {
  2847. unwind_output_sec = s->output_section;
  2848. unwind_output_sec->contents
  2849. = bfd_malloc (unwind_output_sec->size);
  2850. if (unwind_output_sec->contents == NULL)
  2851. return false;
  2852. }
  2853. }
  2854. /* Invoke the regular ELF backend linker to do all the work. */
  2855. if (!bfd_elf_final_link (abfd, info))
  2856. return false;
  2857. if (unwind_output_sec)
  2858. {
  2859. elf64_ia64_unwind_entry_compare_bfd = abfd;
  2860. qsort (unwind_output_sec->contents,
  2861. (size_t) (unwind_output_sec->size / 24),
  2862. 24,
  2863. elf64_ia64_unwind_entry_compare);
  2864. if (! bfd_set_section_contents (abfd, unwind_output_sec,
  2865. unwind_output_sec->contents, (bfd_vma) 0,
  2866. unwind_output_sec->size))
  2867. return false;
  2868. }
  2869. return true;
  2870. }
  2871. static int
  2872. elf64_ia64_relocate_section (bfd *output_bfd,
  2873. struct bfd_link_info *info,
  2874. bfd *input_bfd,
  2875. asection *input_section,
  2876. bfd_byte *contents,
  2877. Elf_Internal_Rela *relocs,
  2878. Elf_Internal_Sym *local_syms,
  2879. asection **local_sections)
  2880. {
  2881. struct elf64_ia64_link_hash_table *ia64_info;
  2882. Elf_Internal_Shdr *symtab_hdr;
  2883. Elf_Internal_Rela *rel;
  2884. Elf_Internal_Rela *relend;
  2885. bool ret_val = true; /* for non-fatal errors */
  2886. bfd_vma gp_val;
  2887. symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  2888. ia64_info = elf64_ia64_hash_table (info);
  2889. if (ia64_info == NULL)
  2890. return false;
  2891. /* Infect various flags from the input section to the output section. */
  2892. if (bfd_link_relocatable (info))
  2893. {
  2894. bfd_vma flags;
  2895. flags = elf_section_data(input_section)->this_hdr.sh_flags;
  2896. flags &= SHF_IA_64_NORECOV;
  2897. elf_section_data(input_section->output_section)
  2898. ->this_hdr.sh_flags |= flags;
  2899. }
  2900. gp_val = _bfd_get_gp_value (output_bfd);
  2901. rel = relocs;
  2902. relend = relocs + input_section->reloc_count;
  2903. for (; rel < relend; ++rel)
  2904. {
  2905. struct elf_link_hash_entry *h;
  2906. struct elf64_ia64_dyn_sym_info *dyn_i;
  2907. bfd_reloc_status_type r;
  2908. reloc_howto_type *howto;
  2909. unsigned long r_symndx;
  2910. Elf_Internal_Sym *sym;
  2911. unsigned int r_type;
  2912. bfd_vma value;
  2913. asection *sym_sec;
  2914. bfd_byte *hit_addr;
  2915. bool dynamic_symbol_p;
  2916. bool undef_weak_ref;
  2917. r_type = ELF64_R_TYPE (rel->r_info);
  2918. if (r_type > R_IA64_MAX_RELOC_CODE)
  2919. {
  2920. /* xgettext:c-format */
  2921. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  2922. input_bfd, (int) r_type);
  2923. bfd_set_error (bfd_error_bad_value);
  2924. ret_val = false;
  2925. continue;
  2926. }
  2927. howto = ia64_elf_lookup_howto (r_type);
  2928. if (howto == NULL)
  2929. {
  2930. ret_val = false;
  2931. continue;
  2932. }
  2933. r_symndx = ELF64_R_SYM (rel->r_info);
  2934. h = NULL;
  2935. sym = NULL;
  2936. sym_sec = NULL;
  2937. undef_weak_ref = false;
  2938. if (r_symndx < symtab_hdr->sh_info)
  2939. {
  2940. /* Reloc against local symbol. */
  2941. asection *msec;
  2942. sym = local_syms + r_symndx;
  2943. sym_sec = local_sections[r_symndx];
  2944. msec = sym_sec;
  2945. value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel);
  2946. if (!bfd_link_relocatable (info)
  2947. && (sym_sec->flags & SEC_MERGE) != 0
  2948. && ELF_ST_TYPE (sym->st_info) == STT_SECTION
  2949. && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE)
  2950. {
  2951. struct elf64_ia64_local_hash_entry *loc_h;
  2952. loc_h = get_local_sym_hash (ia64_info, input_bfd, rel, false);
  2953. if (loc_h && ! loc_h->sec_merge_done)
  2954. {
  2955. struct elf64_ia64_dyn_sym_info *dynent;
  2956. unsigned int count;
  2957. for (count = loc_h->count, dynent = loc_h->info;
  2958. count != 0;
  2959. count--, dynent++)
  2960. {
  2961. msec = sym_sec;
  2962. dynent->addend =
  2963. _bfd_merged_section_offset (output_bfd, &msec,
  2964. elf_section_data (msec)->
  2965. sec_info,
  2966. sym->st_value
  2967. + dynent->addend);
  2968. dynent->addend -= sym->st_value;
  2969. dynent->addend += msec->output_section->vma
  2970. + msec->output_offset
  2971. - sym_sec->output_section->vma
  2972. - sym_sec->output_offset;
  2973. }
  2974. /* We may have introduced duplicated entries. We need
  2975. to remove them properly. */
  2976. count = sort_dyn_sym_info (loc_h->info, loc_h->count);
  2977. if (count != loc_h->count)
  2978. {
  2979. loc_h->count = count;
  2980. loc_h->sorted_count = count;
  2981. }
  2982. loc_h->sec_merge_done = 1;
  2983. }
  2984. }
  2985. }
  2986. else
  2987. {
  2988. bool unresolved_reloc;
  2989. bool warned, ignored;
  2990. struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
  2991. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  2992. r_symndx, symtab_hdr, sym_hashes,
  2993. h, sym_sec, value,
  2994. unresolved_reloc, warned, ignored);
  2995. if (h->root.type == bfd_link_hash_undefweak)
  2996. undef_weak_ref = true;
  2997. else if (warned)
  2998. continue;
  2999. }
  3000. /* For relocs against symbols from removed linkonce sections,
  3001. or sections discarded by a linker script, we just want the
  3002. section contents zeroed. Avoid any special processing. */
  3003. if (sym_sec != NULL && discarded_section (sym_sec))
  3004. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  3005. rel, 1, relend, howto, 0, contents);
  3006. if (bfd_link_relocatable (info))
  3007. continue;
  3008. hit_addr = contents + rel->r_offset;
  3009. value += rel->r_addend;
  3010. dynamic_symbol_p = elf64_ia64_dynamic_symbol_p (h);
  3011. switch (r_type)
  3012. {
  3013. case R_IA64_NONE:
  3014. case R_IA64_LDXMOV:
  3015. continue;
  3016. case R_IA64_IMM14:
  3017. case R_IA64_IMM22:
  3018. case R_IA64_IMM64:
  3019. case R_IA64_DIR32MSB:
  3020. case R_IA64_DIR32LSB:
  3021. case R_IA64_DIR64MSB:
  3022. case R_IA64_DIR64LSB:
  3023. /* Install a dynamic relocation for this reloc. */
  3024. if ((dynamic_symbol_p || bfd_link_pic (info))
  3025. && r_symndx != 0
  3026. && (input_section->flags & SEC_ALLOC) != 0)
  3027. {
  3028. unsigned int dyn_r_type;
  3029. bfd_vma addend;
  3030. switch (r_type)
  3031. {
  3032. case R_IA64_IMM14:
  3033. case R_IA64_IMM22:
  3034. case R_IA64_IMM64:
  3035. /* ??? People shouldn't be doing non-pic code in
  3036. shared libraries nor dynamic executables. */
  3037. _bfd_error_handler
  3038. /* xgettext:c-format */
  3039. (_("%pB: non-pic code with imm relocation against"
  3040. " dynamic symbol `%s'"),
  3041. input_bfd,
  3042. h ? h->root.root.string
  3043. : bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
  3044. sym_sec));
  3045. ret_val = false;
  3046. continue;
  3047. default:
  3048. break;
  3049. }
  3050. /* If we don't need dynamic symbol lookup, find a
  3051. matching RELATIVE relocation. */
  3052. dyn_r_type = r_type;
  3053. if (dynamic_symbol_p)
  3054. {
  3055. addend = rel->r_addend;
  3056. value = 0;
  3057. }
  3058. else
  3059. {
  3060. addend = value;
  3061. }
  3062. /* VMS: install a FIX64. */
  3063. switch (dyn_r_type)
  3064. {
  3065. case R_IA64_DIR32LSB:
  3066. dyn_r_type = R_IA64_VMS_FIX32;
  3067. break;
  3068. case R_IA64_DIR64LSB:
  3069. dyn_r_type = R_IA64_VMS_FIX64;
  3070. break;
  3071. default:
  3072. BFD_ASSERT (false);
  3073. break;
  3074. }
  3075. elf64_ia64_install_fixup
  3076. (output_bfd, ia64_info, h,
  3077. dyn_r_type, input_section, rel->r_offset, addend);
  3078. r = bfd_reloc_ok;
  3079. break;
  3080. }
  3081. /* Fall through. */
  3082. case R_IA64_LTV32MSB:
  3083. case R_IA64_LTV32LSB:
  3084. case R_IA64_LTV64MSB:
  3085. case R_IA64_LTV64LSB:
  3086. r = ia64_elf_install_value (hit_addr, value, r_type);
  3087. break;
  3088. case R_IA64_GPREL22:
  3089. case R_IA64_GPREL64I:
  3090. case R_IA64_GPREL32MSB:
  3091. case R_IA64_GPREL32LSB:
  3092. case R_IA64_GPREL64MSB:
  3093. case R_IA64_GPREL64LSB:
  3094. if (dynamic_symbol_p)
  3095. {
  3096. _bfd_error_handler
  3097. /* xgettext:c-format */
  3098. (_("%pB: @gprel relocation against dynamic symbol %s"),
  3099. input_bfd,
  3100. h ? h->root.root.string
  3101. : bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
  3102. sym_sec));
  3103. ret_val = false;
  3104. continue;
  3105. }
  3106. value -= gp_val;
  3107. r = ia64_elf_install_value (hit_addr, value, r_type);
  3108. break;
  3109. case R_IA64_LTOFF22:
  3110. case R_IA64_LTOFF22X:
  3111. case R_IA64_LTOFF64I:
  3112. dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
  3113. value = set_got_entry (input_bfd, info, dyn_i,
  3114. rel->r_addend, value, R_IA64_DIR64LSB);
  3115. value -= gp_val;
  3116. r = ia64_elf_install_value (hit_addr, value, r_type);
  3117. break;
  3118. case R_IA64_PLTOFF22:
  3119. case R_IA64_PLTOFF64I:
  3120. case R_IA64_PLTOFF64MSB:
  3121. case R_IA64_PLTOFF64LSB:
  3122. dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
  3123. value = set_pltoff_entry (output_bfd, info, dyn_i, value, false);
  3124. value -= gp_val;
  3125. r = ia64_elf_install_value (hit_addr, value, r_type);
  3126. break;
  3127. case R_IA64_FPTR64I:
  3128. case R_IA64_FPTR32MSB:
  3129. case R_IA64_FPTR32LSB:
  3130. case R_IA64_FPTR64MSB:
  3131. case R_IA64_FPTR64LSB:
  3132. dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
  3133. if (dyn_i->want_fptr)
  3134. {
  3135. if (!undef_weak_ref)
  3136. value = set_fptr_entry (output_bfd, info, dyn_i, value);
  3137. }
  3138. if (!dyn_i->want_fptr || bfd_link_pie (info))
  3139. {
  3140. /* Otherwise, we expect the dynamic linker to create
  3141. the entry. */
  3142. if (dyn_i->want_fptr)
  3143. {
  3144. if (r_type == R_IA64_FPTR64I)
  3145. {
  3146. /* We can't represent this without a dynamic symbol.
  3147. Adjust the relocation to be against an output
  3148. section symbol, which are always present in the
  3149. dynamic symbol table. */
  3150. /* ??? People shouldn't be doing non-pic code in
  3151. shared libraries. Hork. */
  3152. _bfd_error_handler
  3153. (_("%pB: linking non-pic code in a position independent executable"),
  3154. input_bfd);
  3155. ret_val = false;
  3156. continue;
  3157. }
  3158. }
  3159. else
  3160. {
  3161. value = 0;
  3162. }
  3163. /* VMS: FIXFD. */
  3164. elf64_ia64_install_fixup
  3165. (output_bfd, ia64_info, h, R_IA64_VMS_FIXFD,
  3166. input_section, rel->r_offset, 0);
  3167. r = bfd_reloc_ok;
  3168. break;
  3169. }
  3170. r = ia64_elf_install_value (hit_addr, value, r_type);
  3171. break;
  3172. case R_IA64_LTOFF_FPTR22:
  3173. case R_IA64_LTOFF_FPTR64I:
  3174. case R_IA64_LTOFF_FPTR32MSB:
  3175. case R_IA64_LTOFF_FPTR32LSB:
  3176. case R_IA64_LTOFF_FPTR64MSB:
  3177. case R_IA64_LTOFF_FPTR64LSB:
  3178. dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
  3179. if (dyn_i->want_fptr)
  3180. {
  3181. BFD_ASSERT (h == NULL || !h->def_dynamic);
  3182. if (!undef_weak_ref)
  3183. value = set_fptr_entry (output_bfd, info, dyn_i, value);
  3184. }
  3185. else
  3186. value = 0;
  3187. value = set_got_entry (output_bfd, info, dyn_i,
  3188. rel->r_addend, value, R_IA64_FPTR64LSB);
  3189. value -= gp_val;
  3190. r = ia64_elf_install_value (hit_addr, value, r_type);
  3191. break;
  3192. case R_IA64_PCREL32MSB:
  3193. case R_IA64_PCREL32LSB:
  3194. case R_IA64_PCREL64MSB:
  3195. case R_IA64_PCREL64LSB:
  3196. /* Install a dynamic relocation for this reloc. */
  3197. if (dynamic_symbol_p && r_symndx != 0)
  3198. {
  3199. /* VMS: doesn't exist ??? */
  3200. abort ();
  3201. }
  3202. goto finish_pcrel;
  3203. case R_IA64_PCREL21B:
  3204. case R_IA64_PCREL60B:
  3205. /* We should have created a PLT entry for any dynamic symbol. */
  3206. dyn_i = NULL;
  3207. if (h)
  3208. dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
  3209. if (dyn_i && dyn_i->want_plt2)
  3210. {
  3211. /* Should have caught this earlier. */
  3212. BFD_ASSERT (rel->r_addend == 0);
  3213. value = (ia64_info->root.splt->output_section->vma
  3214. + ia64_info->root.splt->output_offset
  3215. + dyn_i->plt2_offset);
  3216. }
  3217. else
  3218. {
  3219. /* Since there's no PLT entry, Validate that this is
  3220. locally defined. */
  3221. BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL);
  3222. /* If the symbol is undef_weak, we shouldn't be trying
  3223. to call it. There's every chance that we'd wind up
  3224. with an out-of-range fixup here. Don't bother setting
  3225. any value at all. */
  3226. if (undef_weak_ref)
  3227. continue;
  3228. }
  3229. goto finish_pcrel;
  3230. case R_IA64_PCREL21BI:
  3231. case R_IA64_PCREL21F:
  3232. case R_IA64_PCREL21M:
  3233. case R_IA64_PCREL22:
  3234. case R_IA64_PCREL64I:
  3235. /* The PCREL21BI reloc is specifically not intended for use with
  3236. dynamic relocs. PCREL21F and PCREL21M are used for speculation
  3237. fixup code, and thus probably ought not be dynamic. The
  3238. PCREL22 and PCREL64I relocs aren't emitted as dynamic relocs. */
  3239. if (dynamic_symbol_p)
  3240. {
  3241. const char *msg;
  3242. if (r_type == R_IA64_PCREL21BI)
  3243. /* xgettext:c-format */
  3244. msg = _("%pB: @internal branch to dynamic symbol %s");
  3245. else if (r_type == R_IA64_PCREL21F || r_type == R_IA64_PCREL21M)
  3246. /* xgettext:c-format */
  3247. msg = _("%pB: speculation fixup to dynamic symbol %s");
  3248. else
  3249. /* xgettext:c-format */
  3250. msg = _("%pB: @pcrel relocation against dynamic symbol %s");
  3251. _bfd_error_handler (msg, input_bfd,
  3252. h ? h->root.root.string
  3253. : bfd_elf_sym_name (input_bfd,
  3254. symtab_hdr,
  3255. sym,
  3256. sym_sec));
  3257. ret_val = false;
  3258. continue;
  3259. }
  3260. goto finish_pcrel;
  3261. finish_pcrel:
  3262. /* Make pc-relative. */
  3263. value -= (input_section->output_section->vma
  3264. + input_section->output_offset
  3265. + rel->r_offset) & ~ (bfd_vma) 0x3;
  3266. r = ia64_elf_install_value (hit_addr, value, r_type);
  3267. break;
  3268. case R_IA64_SEGREL32MSB:
  3269. case R_IA64_SEGREL32LSB:
  3270. case R_IA64_SEGREL64MSB:
  3271. case R_IA64_SEGREL64LSB:
  3272. {
  3273. /* Find the segment that contains the output_section. */
  3274. Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section
  3275. (output_bfd, sym_sec->output_section);
  3276. if (p == NULL)
  3277. {
  3278. r = bfd_reloc_notsupported;
  3279. }
  3280. else
  3281. {
  3282. /* The VMA of the segment is the vaddr of the associated
  3283. program header. */
  3284. if (value > p->p_vaddr)
  3285. value -= p->p_vaddr;
  3286. else
  3287. value = 0;
  3288. r = ia64_elf_install_value (hit_addr, value, r_type);
  3289. }
  3290. break;
  3291. }
  3292. case R_IA64_SECREL32MSB:
  3293. case R_IA64_SECREL32LSB:
  3294. case R_IA64_SECREL64MSB:
  3295. case R_IA64_SECREL64LSB:
  3296. /* Make output-section relative to section where the symbol
  3297. is defined. PR 475 */
  3298. if (sym_sec)
  3299. value -= sym_sec->output_section->vma;
  3300. r = ia64_elf_install_value (hit_addr, value, r_type);
  3301. break;
  3302. case R_IA64_IPLTMSB:
  3303. case R_IA64_IPLTLSB:
  3304. /* Install a dynamic relocation for this reloc. */
  3305. if ((dynamic_symbol_p || bfd_link_pic (info))
  3306. && (input_section->flags & SEC_ALLOC) != 0)
  3307. {
  3308. /* VMS: FIXFD ?? */
  3309. abort ();
  3310. }
  3311. if (r_type == R_IA64_IPLTMSB)
  3312. r_type = R_IA64_DIR64MSB;
  3313. else
  3314. r_type = R_IA64_DIR64LSB;
  3315. ia64_elf_install_value (hit_addr, value, r_type);
  3316. r = ia64_elf_install_value (hit_addr + 8, gp_val, r_type);
  3317. break;
  3318. case R_IA64_TPREL14:
  3319. case R_IA64_TPREL22:
  3320. case R_IA64_TPREL64I:
  3321. r = bfd_reloc_notsupported;
  3322. break;
  3323. case R_IA64_DTPREL14:
  3324. case R_IA64_DTPREL22:
  3325. case R_IA64_DTPREL64I:
  3326. case R_IA64_DTPREL32LSB:
  3327. case R_IA64_DTPREL32MSB:
  3328. case R_IA64_DTPREL64LSB:
  3329. case R_IA64_DTPREL64MSB:
  3330. r = bfd_reloc_notsupported;
  3331. break;
  3332. case R_IA64_LTOFF_TPREL22:
  3333. case R_IA64_LTOFF_DTPMOD22:
  3334. case R_IA64_LTOFF_DTPREL22:
  3335. r = bfd_reloc_notsupported;
  3336. break;
  3337. default:
  3338. r = bfd_reloc_notsupported;
  3339. break;
  3340. }
  3341. switch (r)
  3342. {
  3343. case bfd_reloc_ok:
  3344. break;
  3345. case bfd_reloc_undefined:
  3346. /* This can happen for global table relative relocs if
  3347. __gp is undefined. This is a panic situation so we
  3348. don't try to continue. */
  3349. (*info->callbacks->undefined_symbol)
  3350. (info, "__gp", input_bfd, input_section, rel->r_offset, 1);
  3351. return false;
  3352. case bfd_reloc_notsupported:
  3353. {
  3354. const char *name;
  3355. if (h)
  3356. name = h->root.root.string;
  3357. else
  3358. name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
  3359. sym_sec);
  3360. (*info->callbacks->warning) (info, _("unsupported reloc"),
  3361. name, input_bfd,
  3362. input_section, rel->r_offset);
  3363. ret_val = false;
  3364. }
  3365. break;
  3366. case bfd_reloc_dangerous:
  3367. case bfd_reloc_outofrange:
  3368. case bfd_reloc_overflow:
  3369. default:
  3370. {
  3371. const char *name;
  3372. if (h)
  3373. name = h->root.root.string;
  3374. else
  3375. name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
  3376. sym_sec);
  3377. switch (r_type)
  3378. {
  3379. case R_IA64_TPREL14:
  3380. case R_IA64_TPREL22:
  3381. case R_IA64_TPREL64I:
  3382. case R_IA64_DTPREL14:
  3383. case R_IA64_DTPREL22:
  3384. case R_IA64_DTPREL64I:
  3385. case R_IA64_DTPREL32LSB:
  3386. case R_IA64_DTPREL32MSB:
  3387. case R_IA64_DTPREL64LSB:
  3388. case R_IA64_DTPREL64MSB:
  3389. case R_IA64_LTOFF_TPREL22:
  3390. case R_IA64_LTOFF_DTPMOD22:
  3391. case R_IA64_LTOFF_DTPREL22:
  3392. _bfd_error_handler
  3393. /* xgettext:c-format */
  3394. (_("%pB: missing TLS section for relocation %s against `%s'"
  3395. " at %#" PRIx64 " in section `%pA'."),
  3396. input_bfd, howto->name, name,
  3397. (uint64_t) rel->r_offset, input_section);
  3398. break;
  3399. case R_IA64_PCREL21B:
  3400. case R_IA64_PCREL21BI:
  3401. case R_IA64_PCREL21M:
  3402. case R_IA64_PCREL21F:
  3403. if (is_elf_hash_table (info->hash))
  3404. {
  3405. /* Relaxtion is always performed for ELF output.
  3406. Overflow failures for those relocations mean
  3407. that the section is too big to relax. */
  3408. _bfd_error_handler
  3409. /* xgettext:c-format */
  3410. (_("%pB: Can't relax br (%s) to `%s' "
  3411. "at %#" PRIx64 " in section `%pA' "
  3412. "with size %#" PRIx64 " (> 0x1000000)."),
  3413. input_bfd, howto->name, name, (uint64_t) rel->r_offset,
  3414. input_section, (uint64_t) input_section->size);
  3415. break;
  3416. }
  3417. /* Fall through. */
  3418. default:
  3419. (*info->callbacks->reloc_overflow) (info,
  3420. &h->root,
  3421. name,
  3422. howto->name,
  3423. (bfd_vma) 0,
  3424. input_bfd,
  3425. input_section,
  3426. rel->r_offset);
  3427. break;
  3428. }
  3429. ret_val = false;
  3430. }
  3431. break;
  3432. }
  3433. }
  3434. return ret_val;
  3435. }
  3436. static bool
  3437. elf64_ia64_finish_dynamic_symbol (bfd *output_bfd,
  3438. struct bfd_link_info *info,
  3439. struct elf_link_hash_entry *h,
  3440. Elf_Internal_Sym *sym)
  3441. {
  3442. struct elf64_ia64_link_hash_table *ia64_info;
  3443. struct elf64_ia64_dyn_sym_info *dyn_i;
  3444. ia64_info = elf64_ia64_hash_table (info);
  3445. if (ia64_info == NULL)
  3446. return false;
  3447. dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
  3448. /* Fill in the PLT data, if required. */
  3449. if (dyn_i && dyn_i->want_plt)
  3450. {
  3451. bfd_byte *loc;
  3452. asection *plt_sec;
  3453. bfd_vma plt_addr, pltoff_addr, gp_val;
  3454. gp_val = _bfd_get_gp_value (output_bfd);
  3455. plt_sec = ia64_info->root.splt;
  3456. plt_addr = 0; /* Not used as overriden by FIXUPs. */
  3457. pltoff_addr = set_pltoff_entry (output_bfd, info, dyn_i, plt_addr, true);
  3458. /* Initialize the FULL PLT entry, if needed. */
  3459. if (dyn_i->want_plt2)
  3460. {
  3461. loc = plt_sec->contents + dyn_i->plt2_offset;
  3462. memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE);
  3463. ia64_elf_install_value (loc, pltoff_addr - gp_val, R_IA64_IMM22);
  3464. /* Mark the symbol as undefined, rather than as defined in the
  3465. plt section. Leave the value alone. */
  3466. /* ??? We didn't redefine it in adjust_dynamic_symbol in the
  3467. first place. But perhaps elflink.c did some for us. */
  3468. if (!h->def_regular)
  3469. sym->st_shndx = SHN_UNDEF;
  3470. }
  3471. /* VMS: FIXFD. */
  3472. elf64_ia64_install_fixup
  3473. (output_bfd, ia64_info, h, R_IA64_VMS_FIXFD, ia64_info->pltoff_sec,
  3474. pltoff_addr - (ia64_info->pltoff_sec->output_section->vma
  3475. + ia64_info->pltoff_sec->output_offset), 0);
  3476. }
  3477. /* Mark some specially defined symbols as absolute. */
  3478. if (h == ia64_info->root.hdynamic
  3479. || h == ia64_info->root.hgot
  3480. || h == ia64_info->root.hplt)
  3481. sym->st_shndx = SHN_ABS;
  3482. return true;
  3483. }
  3484. static bool
  3485. elf64_ia64_finish_dynamic_sections (bfd *abfd,
  3486. struct bfd_link_info *info)
  3487. {
  3488. struct elf64_ia64_link_hash_table *ia64_info;
  3489. bfd *dynobj;
  3490. ia64_info = elf64_ia64_hash_table (info);
  3491. if (ia64_info == NULL)
  3492. return false;
  3493. dynobj = ia64_info->root.dynobj;
  3494. if (elf_hash_table (info)->dynamic_sections_created)
  3495. {
  3496. Elf64_External_Dyn *dyncon, *dynconend;
  3497. asection *sdyn;
  3498. asection *unwind_sec;
  3499. bfd_vma gp_val;
  3500. unsigned int gp_seg;
  3501. bfd_vma gp_off;
  3502. Elf_Internal_Phdr *phdr;
  3503. Elf_Internal_Phdr *base_phdr;
  3504. unsigned int unwind_seg = 0;
  3505. unsigned int code_seg = 0;
  3506. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  3507. BFD_ASSERT (sdyn != NULL);
  3508. dyncon = (Elf64_External_Dyn *) sdyn->contents;
  3509. dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
  3510. gp_val = _bfd_get_gp_value (abfd);
  3511. phdr = _bfd_elf_find_segment_containing_section
  3512. (info->output_bfd, ia64_info->pltoff_sec->output_section);
  3513. BFD_ASSERT (phdr != NULL);
  3514. base_phdr = elf_tdata (info->output_bfd)->phdr;
  3515. gp_seg = phdr - base_phdr;
  3516. gp_off = gp_val - phdr->p_vaddr;
  3517. unwind_sec = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind);
  3518. if (unwind_sec != NULL)
  3519. {
  3520. asection *code_sec;
  3521. phdr = _bfd_elf_find_segment_containing_section (abfd, unwind_sec);
  3522. BFD_ASSERT (phdr != NULL);
  3523. unwind_seg = phdr - base_phdr;
  3524. code_sec = bfd_get_section_by_name (abfd, "$CODE$");
  3525. phdr = _bfd_elf_find_segment_containing_section (abfd, code_sec);
  3526. BFD_ASSERT (phdr != NULL);
  3527. code_seg = phdr - base_phdr;
  3528. }
  3529. for (; dyncon < dynconend; dyncon++)
  3530. {
  3531. Elf_Internal_Dyn dyn;
  3532. bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
  3533. switch (dyn.d_tag)
  3534. {
  3535. case DT_IA_64_VMS_FIXUP_RELA_OFF:
  3536. dyn.d_un.d_val +=
  3537. (ia64_info->fixups_sec->output_section->vma
  3538. + ia64_info->fixups_sec->output_offset)
  3539. - (sdyn->output_section->vma + sdyn->output_offset);
  3540. break;
  3541. case DT_IA_64_VMS_PLTGOT_OFFSET:
  3542. dyn.d_un.d_val = gp_off;
  3543. break;
  3544. case DT_IA_64_VMS_PLTGOT_SEG:
  3545. dyn.d_un.d_val = gp_seg;
  3546. break;
  3547. case DT_IA_64_VMS_UNWINDSZ:
  3548. if (unwind_sec == NULL)
  3549. {
  3550. dyn.d_tag = DT_NULL;
  3551. dyn.d_un.d_val = 0xdead;
  3552. }
  3553. else
  3554. dyn.d_un.d_val = unwind_sec->size;
  3555. break;
  3556. case DT_IA_64_VMS_UNWIND_CODSEG:
  3557. dyn.d_un.d_val = code_seg;
  3558. break;
  3559. case DT_IA_64_VMS_UNWIND_INFOSEG:
  3560. case DT_IA_64_VMS_UNWIND_SEG:
  3561. dyn.d_un.d_val = unwind_seg;
  3562. break;
  3563. case DT_IA_64_VMS_UNWIND_OFFSET:
  3564. break;
  3565. default:
  3566. /* No need to rewrite the entry. */
  3567. continue;
  3568. }
  3569. bfd_elf64_swap_dyn_out (abfd, &dyn, dyncon);
  3570. }
  3571. }
  3572. /* Handle transfer addresses. */
  3573. {
  3574. asection *tfr_sec = ia64_info->transfer_sec;
  3575. struct elf64_vms_transfer *tfr;
  3576. struct elf_link_hash_entry *tfr3;
  3577. tfr = (struct elf64_vms_transfer *)tfr_sec->contents;
  3578. bfd_putl32 (6 * 8, tfr->size);
  3579. bfd_putl64 (tfr_sec->output_section->vma
  3580. + tfr_sec->output_offset
  3581. + 6 * 8, tfr->tfradr3);
  3582. tfr3 = elf_link_hash_lookup (elf_hash_table (info), "ELF$TFRADR", false,
  3583. false, false);
  3584. if (tfr3
  3585. && (tfr3->root.type == bfd_link_hash_defined
  3586. || tfr3->root.type == bfd_link_hash_defweak))
  3587. {
  3588. asection *tfr3_sec = tfr3->root.u.def.section;
  3589. bfd_vma tfr3_val;
  3590. tfr3_val = (tfr3->root.u.def.value
  3591. + tfr3_sec->output_section->vma
  3592. + tfr3_sec->output_offset);
  3593. bfd_putl64 (tfr3_val, tfr->tfr3_func);
  3594. bfd_putl64 (_bfd_get_gp_value (info->output_bfd), tfr->tfr3_gp);
  3595. }
  3596. /* FIXME: set linker flags,
  3597. handle lib$initialize. */
  3598. }
  3599. return true;
  3600. }
  3601. /* ELF file flag handling: */
  3602. /* Function to keep IA-64 specific file flags. */
  3603. static bool
  3604. elf64_ia64_set_private_flags (bfd *abfd, flagword flags)
  3605. {
  3606. BFD_ASSERT (!elf_flags_init (abfd)
  3607. || elf_elfheader (abfd)->e_flags == flags);
  3608. elf_elfheader (abfd)->e_flags = flags;
  3609. elf_flags_init (abfd) = true;
  3610. return true;
  3611. }
  3612. /* Merge backend specific data from an object file to the output
  3613. object file when linking. */
  3614. static bool
  3615. elf64_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
  3616. {
  3617. bfd *obfd = info->output_bfd;
  3618. flagword out_flags;
  3619. flagword in_flags;
  3620. bool ok = true;
  3621. /* FIXME: What should be checked when linking shared libraries? */
  3622. if ((ibfd->flags & DYNAMIC) != 0)
  3623. return true;
  3624. /* Don't even pretend to support mixed-format linking. */
  3625. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
  3626. || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
  3627. return false;
  3628. in_flags = elf_elfheader (ibfd)->e_flags;
  3629. out_flags = elf_elfheader (obfd)->e_flags;
  3630. if (! elf_flags_init (obfd))
  3631. {
  3632. elf_flags_init (obfd) = true;
  3633. elf_elfheader (obfd)->e_flags = in_flags;
  3634. if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
  3635. && bfd_get_arch_info (obfd)->the_default)
  3636. {
  3637. return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
  3638. bfd_get_mach (ibfd));
  3639. }
  3640. return true;
  3641. }
  3642. /* Check flag compatibility. */
  3643. if (in_flags == out_flags)
  3644. return true;
  3645. /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
  3646. if (!(in_flags & EF_IA_64_REDUCEDFP) && (out_flags & EF_IA_64_REDUCEDFP))
  3647. elf_elfheader (obfd)->e_flags &= ~EF_IA_64_REDUCEDFP;
  3648. if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL))
  3649. {
  3650. _bfd_error_handler
  3651. (_("%pB: linking trap-on-NULL-dereference with non-trapping files"),
  3652. ibfd);
  3653. bfd_set_error (bfd_error_bad_value);
  3654. ok = false;
  3655. }
  3656. if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE))
  3657. {
  3658. _bfd_error_handler
  3659. (_("%pB: linking big-endian files with little-endian files"),
  3660. ibfd);
  3661. bfd_set_error (bfd_error_bad_value);
  3662. ok = false;
  3663. }
  3664. if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64))
  3665. {
  3666. _bfd_error_handler
  3667. (_("%pB: linking 64-bit files with 32-bit files"),
  3668. ibfd);
  3669. bfd_set_error (bfd_error_bad_value);
  3670. ok = false;
  3671. }
  3672. if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP))
  3673. {
  3674. _bfd_error_handler
  3675. (_("%pB: linking constant-gp files with non-constant-gp files"),
  3676. ibfd);
  3677. bfd_set_error (bfd_error_bad_value);
  3678. ok = false;
  3679. }
  3680. if ((in_flags & EF_IA_64_NOFUNCDESC_CONS_GP)
  3681. != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
  3682. {
  3683. _bfd_error_handler
  3684. (_("%pB: linking auto-pic files with non-auto-pic files"),
  3685. ibfd);
  3686. bfd_set_error (bfd_error_bad_value);
  3687. ok = false;
  3688. }
  3689. return ok;
  3690. }
  3691. static bool
  3692. elf64_ia64_print_private_bfd_data (bfd *abfd, void * ptr)
  3693. {
  3694. FILE *file = (FILE *) ptr;
  3695. flagword flags = elf_elfheader (abfd)->e_flags;
  3696. BFD_ASSERT (abfd != NULL && ptr != NULL);
  3697. fprintf (file, "private flags = %s%s%s%s%s%s%s%s\n",
  3698. (flags & EF_IA_64_TRAPNIL) ? "TRAPNIL, " : "",
  3699. (flags & EF_IA_64_EXT) ? "EXT, " : "",
  3700. (flags & EF_IA_64_BE) ? "BE, " : "LE, ",
  3701. (flags & EF_IA_64_REDUCEDFP) ? "REDUCEDFP, " : "",
  3702. (flags & EF_IA_64_CONS_GP) ? "CONS_GP, " : "",
  3703. (flags & EF_IA_64_NOFUNCDESC_CONS_GP) ? "NOFUNCDESC_CONS_GP, " : "",
  3704. (flags & EF_IA_64_ABSOLUTE) ? "ABSOLUTE, " : "",
  3705. (flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32");
  3706. _bfd_elf_print_private_bfd_data (abfd, ptr);
  3707. return true;
  3708. }
  3709. static enum elf_reloc_type_class
  3710. elf64_ia64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  3711. const asection *rel_sec ATTRIBUTE_UNUSED,
  3712. const Elf_Internal_Rela *rela)
  3713. {
  3714. switch ((int) ELF64_R_TYPE (rela->r_info))
  3715. {
  3716. case R_IA64_REL32MSB:
  3717. case R_IA64_REL32LSB:
  3718. case R_IA64_REL64MSB:
  3719. case R_IA64_REL64LSB:
  3720. return reloc_class_relative;
  3721. case R_IA64_IPLTMSB:
  3722. case R_IA64_IPLTLSB:
  3723. return reloc_class_plt;
  3724. case R_IA64_COPY:
  3725. return reloc_class_copy;
  3726. default:
  3727. return reloc_class_normal;
  3728. }
  3729. }
  3730. static const struct bfd_elf_special_section elf64_ia64_special_sections[] =
  3731. {
  3732. { STRING_COMMA_LEN (".sbss"), -1, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
  3733. { STRING_COMMA_LEN (".sdata"), -1, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
  3734. { NULL, 0, 0, 0, 0 }
  3735. };
  3736. static bool
  3737. elf64_ia64_object_p (bfd *abfd)
  3738. {
  3739. asection *sec;
  3740. asection *group, *unwi, *unw;
  3741. flagword flags;
  3742. const char *name;
  3743. char *unwi_name, *unw_name;
  3744. size_t amt;
  3745. if (abfd->flags & DYNAMIC)
  3746. return true;
  3747. /* Flags for fake group section. */
  3748. flags = (SEC_LINKER_CREATED | SEC_GROUP | SEC_LINK_ONCE
  3749. | SEC_EXCLUDE);
  3750. /* We add a fake section group for each .gnu.linkonce.t.* section,
  3751. which isn't in a section group, and its unwind sections. */
  3752. for (sec = abfd->sections; sec != NULL; sec = sec->next)
  3753. {
  3754. if (elf_sec_group (sec) == NULL
  3755. && ((sec->flags & (SEC_LINK_ONCE | SEC_CODE | SEC_GROUP))
  3756. == (SEC_LINK_ONCE | SEC_CODE))
  3757. && startswith (sec->name, ".gnu.linkonce.t."))
  3758. {
  3759. name = sec->name + 16;
  3760. amt = strlen (name) + sizeof (".gnu.linkonce.ia64unwi.");
  3761. unwi_name = bfd_alloc (abfd, amt);
  3762. if (!unwi_name)
  3763. return false;
  3764. strcpy (stpcpy (unwi_name, ".gnu.linkonce.ia64unwi."), name);
  3765. unwi = bfd_get_section_by_name (abfd, unwi_name);
  3766. amt = strlen (name) + sizeof (".gnu.linkonce.ia64unw.");
  3767. unw_name = bfd_alloc (abfd, amt);
  3768. if (!unw_name)
  3769. return false;
  3770. strcpy (stpcpy (unw_name, ".gnu.linkonce.ia64unw."), name);
  3771. unw = bfd_get_section_by_name (abfd, unw_name);
  3772. /* We need to create a fake group section for it and its
  3773. unwind sections. */
  3774. group = bfd_make_section_anyway_with_flags (abfd, name,
  3775. flags);
  3776. if (group == NULL)
  3777. return false;
  3778. /* Move the fake group section to the beginning. */
  3779. bfd_section_list_remove (abfd, group);
  3780. bfd_section_list_prepend (abfd, group);
  3781. elf_next_in_group (group) = sec;
  3782. elf_group_name (sec) = name;
  3783. elf_next_in_group (sec) = sec;
  3784. elf_sec_group (sec) = group;
  3785. if (unwi)
  3786. {
  3787. elf_group_name (unwi) = name;
  3788. elf_next_in_group (unwi) = sec;
  3789. elf_next_in_group (sec) = unwi;
  3790. elf_sec_group (unwi) = group;
  3791. }
  3792. if (unw)
  3793. {
  3794. elf_group_name (unw) = name;
  3795. if (unwi)
  3796. {
  3797. elf_next_in_group (unw) = elf_next_in_group (unwi);
  3798. elf_next_in_group (unwi) = unw;
  3799. }
  3800. else
  3801. {
  3802. elf_next_in_group (unw) = sec;
  3803. elf_next_in_group (sec) = unw;
  3804. }
  3805. elf_sec_group (unw) = group;
  3806. }
  3807. /* Fake SHT_GROUP section header. */
  3808. elf_section_data (group)->this_hdr.bfd_section = group;
  3809. elf_section_data (group)->this_hdr.sh_type = SHT_GROUP;
  3810. }
  3811. }
  3812. return true;
  3813. }
  3814. /* Handle an IA-64 specific section when reading an object file. This
  3815. is called when bfd_section_from_shdr finds a section with an unknown
  3816. type. */
  3817. static bool
  3818. elf64_vms_section_from_shdr (bfd *abfd,
  3819. Elf_Internal_Shdr *hdr,
  3820. const char *name,
  3821. int shindex)
  3822. {
  3823. flagword secflags = 0;
  3824. switch (hdr->sh_type)
  3825. {
  3826. case SHT_IA_64_VMS_TRACE:
  3827. case SHT_IA_64_VMS_DEBUG:
  3828. case SHT_IA_64_VMS_DEBUG_STR:
  3829. secflags = SEC_DEBUGGING;
  3830. break;
  3831. case SHT_IA_64_UNWIND:
  3832. case SHT_IA_64_HP_OPT_ANOT:
  3833. break;
  3834. case SHT_IA_64_EXT:
  3835. if (strcmp (name, ELF_STRING_ia64_archext) != 0)
  3836. return false;
  3837. break;
  3838. default:
  3839. return false;
  3840. }
  3841. if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
  3842. return false;
  3843. if (secflags != 0)
  3844. {
  3845. asection *newsect = hdr->bfd_section;
  3846. if (!bfd_set_section_flags (newsect,
  3847. bfd_section_flags (newsect) | secflags))
  3848. return false;
  3849. }
  3850. return true;
  3851. }
  3852. static bool
  3853. elf64_vms_object_p (bfd *abfd)
  3854. {
  3855. Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
  3856. Elf_Internal_Phdr *i_phdr = elf_tdata (abfd)->phdr;
  3857. unsigned int i;
  3858. unsigned int num_text = 0;
  3859. unsigned int num_data = 0;
  3860. unsigned int num_rodata = 0;
  3861. char name[16];
  3862. if (!elf64_ia64_object_p (abfd))
  3863. return false;
  3864. /* Many VMS compilers do not generate sections for the corresponding
  3865. segment. This is boring as binutils tools won't be able to disassemble
  3866. the code. So we simply create all the missing sections. */
  3867. for (i = 0; i < i_ehdrp->e_phnum; i++, i_phdr++)
  3868. {
  3869. /* Is there a section for this segment? */
  3870. bfd_vma base_vma = i_phdr->p_vaddr;
  3871. bfd_vma limit_vma = base_vma + i_phdr->p_filesz;
  3872. if (i_phdr->p_type != PT_LOAD)
  3873. continue;
  3874. /* We need to cover from base_vms to limit_vma. */
  3875. again:
  3876. while (base_vma < limit_vma)
  3877. {
  3878. bfd_vma next_vma = limit_vma;
  3879. asection *nsec;
  3880. asection *sec;
  3881. flagword flags;
  3882. char *nname = NULL;
  3883. /* Find a section covering [base_vma;limit_vma) */
  3884. for (sec = abfd->sections; sec != NULL; sec = sec->next)
  3885. {
  3886. /* Skip uninteresting sections (either not in memory or
  3887. below base_vma. */
  3888. if ((sec->flags & (SEC_ALLOC | SEC_LOAD)) == 0
  3889. || sec->vma + sec->size <= base_vma)
  3890. continue;
  3891. if (sec->vma <= base_vma)
  3892. {
  3893. /* This section covers (maybe partially) the beginning
  3894. of the range. */
  3895. base_vma = sec->vma + sec->size;
  3896. goto again;
  3897. }
  3898. if (sec->vma < next_vma)
  3899. {
  3900. /* This section partially covers the end of the range.
  3901. Used to compute the size of the hole. */
  3902. next_vma = sec->vma;
  3903. }
  3904. }
  3905. /* No section covering [base_vma; next_vma). Create a fake one. */
  3906. flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
  3907. if (i_phdr->p_flags & PF_X)
  3908. {
  3909. flags |= SEC_CODE;
  3910. if (num_text++ == 0)
  3911. nname = ".text";
  3912. else
  3913. sprintf (name, ".text$%u", num_text);
  3914. }
  3915. else if ((i_phdr->p_flags & (PF_R | PF_W)) == PF_R)
  3916. {
  3917. flags |= SEC_READONLY;
  3918. sprintf (name, ".rodata$%u", num_rodata++);
  3919. }
  3920. else
  3921. {
  3922. flags |= SEC_DATA;
  3923. sprintf (name, ".data$%u", num_data++);
  3924. }
  3925. /* Allocate name. */
  3926. if (nname == NULL)
  3927. {
  3928. size_t name_len = strlen (name) + 1;
  3929. nname = bfd_alloc (abfd, name_len);
  3930. if (nname == NULL)
  3931. return false;
  3932. memcpy (nname, name, name_len);
  3933. }
  3934. /* Create and fill new section. */
  3935. nsec = bfd_make_section_anyway_with_flags (abfd, nname, flags);
  3936. if (nsec == NULL)
  3937. return false;
  3938. nsec->vma = base_vma;
  3939. nsec->size = next_vma - base_vma;
  3940. nsec->filepos = i_phdr->p_offset + (base_vma - i_phdr->p_vaddr);
  3941. base_vma = next_vma;
  3942. }
  3943. }
  3944. return true;
  3945. }
  3946. static bool
  3947. elf64_vms_init_file_header (bfd *abfd, struct bfd_link_info *info)
  3948. {
  3949. Elf_Internal_Ehdr *i_ehdrp;
  3950. if (!_bfd_elf_init_file_header (abfd, info))
  3951. return false;
  3952. i_ehdrp = elf_elfheader (abfd);
  3953. i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_OPENVMS;
  3954. i_ehdrp->e_ident[EI_ABIVERSION] = 2;
  3955. return true;
  3956. }
  3957. static bool
  3958. elf64_vms_section_processing (bfd *abfd ATTRIBUTE_UNUSED,
  3959. Elf_Internal_Shdr *hdr)
  3960. {
  3961. if (hdr->bfd_section != NULL)
  3962. {
  3963. const char *name = bfd_section_name (hdr->bfd_section);
  3964. if (strcmp (name, ".text") == 0)
  3965. hdr->sh_flags |= SHF_IA_64_VMS_SHARED;
  3966. else if ((strcmp (name, ".debug") == 0)
  3967. || (strcmp (name, ".debug_abbrev") == 0)
  3968. || (strcmp (name, ".debug_aranges") == 0)
  3969. || (strcmp (name, ".debug_frame") == 0)
  3970. || (strcmp (name, ".debug_info") == 0)
  3971. || (strcmp (name, ".debug_loc") == 0)
  3972. || (strcmp (name, ".debug_macinfo") == 0)
  3973. || (strcmp (name, ".debug_pubnames") == 0)
  3974. || (strcmp (name, ".debug_pubtypes") == 0))
  3975. hdr->sh_type = SHT_IA_64_VMS_DEBUG;
  3976. else if ((strcmp (name, ".debug_line") == 0)
  3977. || (strcmp (name, ".debug_ranges") == 0)
  3978. || (strcmp (name, ".trace_info") == 0)
  3979. || (strcmp (name, ".trace_abbrev") == 0)
  3980. || (strcmp (name, ".trace_aranges") == 0))
  3981. hdr->sh_type = SHT_IA_64_VMS_TRACE;
  3982. else if (strcmp (name, ".debug_str") == 0)
  3983. hdr->sh_type = SHT_IA_64_VMS_DEBUG_STR;
  3984. }
  3985. return true;
  3986. }
  3987. /* The final processing done just before writing out a VMS IA-64 ELF
  3988. object file. */
  3989. static bool
  3990. elf64_vms_final_write_processing (bfd *abfd)
  3991. {
  3992. Elf_Internal_Shdr *hdr;
  3993. asection *s;
  3994. int unwind_info_sect_idx = 0;
  3995. for (s = abfd->sections; s; s = s->next)
  3996. {
  3997. hdr = &elf_section_data (s)->this_hdr;
  3998. if (strcmp (bfd_section_name (hdr->bfd_section),
  3999. ".IA_64.unwind_info") == 0)
  4000. unwind_info_sect_idx = elf_section_data (s)->this_idx;
  4001. switch (hdr->sh_type)
  4002. {
  4003. case SHT_IA_64_UNWIND:
  4004. /* VMS requires sh_info to point to the unwind info section. */
  4005. hdr->sh_info = unwind_info_sect_idx;
  4006. break;
  4007. }
  4008. }
  4009. if (! elf_flags_init (abfd))
  4010. {
  4011. unsigned long flags = 0;
  4012. if (abfd->xvec->byteorder == BFD_ENDIAN_BIG)
  4013. flags |= EF_IA_64_BE;
  4014. if (bfd_get_mach (abfd) == bfd_mach_ia64_elf64)
  4015. flags |= EF_IA_64_ABI64;
  4016. elf_elfheader (abfd)->e_flags = flags;
  4017. elf_flags_init (abfd) = true;
  4018. }
  4019. return _bfd_elf_final_write_processing (abfd);
  4020. }
  4021. static bool
  4022. elf64_vms_write_shdrs_and_ehdr (bfd *abfd)
  4023. {
  4024. unsigned char needed_count[8];
  4025. if (!bfd_elf64_write_shdrs_and_ehdr (abfd))
  4026. return false;
  4027. bfd_putl64 (elf_ia64_vms_tdata (abfd)->needed_count, needed_count);
  4028. if (bfd_seek (abfd, sizeof (Elf64_External_Ehdr), SEEK_SET) != 0
  4029. || bfd_bwrite (needed_count, 8, abfd) != 8)
  4030. return false;
  4031. return true;
  4032. }
  4033. static bool
  4034. elf64_vms_close_and_cleanup (bfd *abfd)
  4035. {
  4036. if (bfd_get_format (abfd) == bfd_object)
  4037. {
  4038. long isize;
  4039. /* Pad to 8 byte boundary for IPF/VMS. */
  4040. isize = bfd_get_size (abfd);
  4041. if ((isize & 7) != 0)
  4042. {
  4043. int ishort = 8 - (isize & 7);
  4044. bfd_uint64_t pad = 0;
  4045. bfd_seek (abfd, isize, SEEK_SET);
  4046. bfd_bwrite (&pad, ishort, abfd);
  4047. }
  4048. }
  4049. return _bfd_elf_close_and_cleanup (abfd);
  4050. }
  4051. /* Add symbols from an ELF object file to the linker hash table. */
  4052. static bool
  4053. elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
  4054. {
  4055. Elf_Internal_Shdr *hdr;
  4056. bfd_size_type symcount;
  4057. bfd_size_type extsymcount;
  4058. bfd_size_type extsymoff;
  4059. struct elf_link_hash_entry **sym_hash;
  4060. bool dynamic;
  4061. Elf_Internal_Sym *isymbuf = NULL;
  4062. Elf_Internal_Sym *isym;
  4063. Elf_Internal_Sym *isymend;
  4064. const struct elf_backend_data *bed;
  4065. struct elf_link_hash_table *htab;
  4066. bfd_size_type amt;
  4067. htab = elf_hash_table (info);
  4068. bed = get_elf_backend_data (abfd);
  4069. if ((abfd->flags & DYNAMIC) == 0)
  4070. dynamic = false;
  4071. else
  4072. {
  4073. dynamic = true;
  4074. /* You can't use -r against a dynamic object. Also, there's no
  4075. hope of using a dynamic object which does not exactly match
  4076. the format of the output file. */
  4077. if (bfd_link_relocatable (info)
  4078. || !is_elf_hash_table (&htab->root)
  4079. || info->output_bfd->xvec != abfd->xvec)
  4080. {
  4081. if (bfd_link_relocatable (info))
  4082. bfd_set_error (bfd_error_invalid_operation);
  4083. else
  4084. bfd_set_error (bfd_error_wrong_format);
  4085. goto error_return;
  4086. }
  4087. }
  4088. if (! dynamic)
  4089. {
  4090. /* If we are creating a shared library, create all the dynamic
  4091. sections immediately. We need to attach them to something,
  4092. so we attach them to this BFD, provided it is the right
  4093. format. FIXME: If there are no input BFD's of the same
  4094. format as the output, we can't make a shared library. */
  4095. if (bfd_link_pic (info)
  4096. && is_elf_hash_table (&htab->root)
  4097. && info->output_bfd->xvec == abfd->xvec
  4098. && !htab->dynamic_sections_created)
  4099. {
  4100. if (! elf64_ia64_create_dynamic_sections (abfd, info))
  4101. goto error_return;
  4102. }
  4103. }
  4104. else if (!is_elf_hash_table (&htab->root))
  4105. goto error_return;
  4106. else
  4107. {
  4108. asection *s;
  4109. bfd_byte *dynbuf;
  4110. bfd_byte *extdyn;
  4111. /* ld --just-symbols and dynamic objects don't mix very well.
  4112. ld shouldn't allow it. */
  4113. if ((s = abfd->sections) != NULL
  4114. && s->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
  4115. abort ();
  4116. /* Be sure there are dynamic sections. */
  4117. if (! elf64_ia64_create_dynamic_sections (htab->dynobj, info))
  4118. goto error_return;
  4119. s = bfd_get_section_by_name (abfd, ".dynamic");
  4120. if (s == NULL)
  4121. {
  4122. /* VMS libraries do not have dynamic sections. Create one from
  4123. the segment. */
  4124. Elf_Internal_Phdr *phdr;
  4125. unsigned int i, phnum;
  4126. phdr = elf_tdata (abfd)->phdr;
  4127. if (phdr == NULL)
  4128. goto error_return;
  4129. phnum = elf_elfheader (abfd)->e_phnum;
  4130. for (i = 0; i < phnum; phdr++)
  4131. if (phdr->p_type == PT_DYNAMIC)
  4132. {
  4133. s = bfd_make_section (abfd, ".dynamic");
  4134. if (s == NULL)
  4135. goto error_return;
  4136. s->vma = phdr->p_vaddr;
  4137. s->lma = phdr->p_paddr;
  4138. s->size = phdr->p_filesz;
  4139. s->filepos = phdr->p_offset;
  4140. s->flags |= SEC_HAS_CONTENTS;
  4141. s->alignment_power = bfd_log2 (phdr->p_align);
  4142. break;
  4143. }
  4144. if (s == NULL)
  4145. goto error_return;
  4146. }
  4147. /* Extract IDENT. */
  4148. if (!bfd_malloc_and_get_section (abfd, s, &dynbuf))
  4149. {
  4150. error_free_dyn:
  4151. free (dynbuf);
  4152. goto error_return;
  4153. }
  4154. for (extdyn = dynbuf;
  4155. extdyn < dynbuf + s->size;
  4156. extdyn += bed->s->sizeof_dyn)
  4157. {
  4158. Elf_Internal_Dyn dyn;
  4159. bed->s->swap_dyn_in (abfd, extdyn, &dyn);
  4160. if (dyn.d_tag == DT_IA_64_VMS_IDENT)
  4161. {
  4162. bfd_uint64_t tagv = dyn.d_un.d_val;
  4163. elf_ia64_vms_ident (abfd) = tagv;
  4164. break;
  4165. }
  4166. }
  4167. if (extdyn >= dynbuf + s->size)
  4168. {
  4169. /* Ident not found. */
  4170. goto error_free_dyn;
  4171. }
  4172. free (dynbuf);
  4173. /* We do not want to include any of the sections in a dynamic
  4174. object in the output file. We hack by simply clobbering the
  4175. list of sections in the BFD. This could be handled more
  4176. cleanly by, say, a new section flag; the existing
  4177. SEC_NEVER_LOAD flag is not the one we want, because that one
  4178. still implies that the section takes up space in the output
  4179. file. */
  4180. bfd_section_list_clear (abfd);
  4181. /* FIXME: should we detect if this library is already included ?
  4182. This should be harmless and shouldn't happen in practice. */
  4183. }
  4184. hdr = &elf_tdata (abfd)->symtab_hdr;
  4185. symcount = hdr->sh_size / bed->s->sizeof_sym;
  4186. /* The sh_info field of the symtab header tells us where the
  4187. external symbols start. We don't care about the local symbols at
  4188. this point. */
  4189. extsymcount = symcount - hdr->sh_info;
  4190. extsymoff = hdr->sh_info;
  4191. sym_hash = NULL;
  4192. if (extsymcount != 0)
  4193. {
  4194. isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
  4195. NULL, NULL, NULL);
  4196. if (isymbuf == NULL)
  4197. goto error_return;
  4198. /* We store a pointer to the hash table entry for each external
  4199. symbol. */
  4200. amt = extsymcount * sizeof (struct elf_link_hash_entry *);
  4201. sym_hash = (struct elf_link_hash_entry **) bfd_alloc (abfd, amt);
  4202. if (sym_hash == NULL)
  4203. goto error_free_sym;
  4204. elf_sym_hashes (abfd) = sym_hash;
  4205. }
  4206. for (isym = isymbuf, isymend = isymbuf + extsymcount;
  4207. isym < isymend;
  4208. isym++, sym_hash++)
  4209. {
  4210. int bind;
  4211. bfd_vma value;
  4212. asection *sec, *new_sec;
  4213. flagword flags;
  4214. const char *name;
  4215. struct elf_link_hash_entry *h;
  4216. bool definition;
  4217. bool size_change_ok;
  4218. bool type_change_ok;
  4219. bool common;
  4220. unsigned int old_alignment;
  4221. bfd *old_bfd;
  4222. flags = BSF_NO_FLAGS;
  4223. sec = NULL;
  4224. value = isym->st_value;
  4225. *sym_hash = NULL;
  4226. common = bed->common_definition (isym);
  4227. bind = ELF_ST_BIND (isym->st_info);
  4228. switch (bind)
  4229. {
  4230. case STB_LOCAL:
  4231. /* This should be impossible, since ELF requires that all
  4232. global symbols follow all local symbols, and that sh_info
  4233. point to the first global symbol. Unfortunately, Irix 5
  4234. screws this up. */
  4235. continue;
  4236. case STB_GLOBAL:
  4237. if (isym->st_shndx != SHN_UNDEF && !common)
  4238. flags = BSF_GLOBAL;
  4239. break;
  4240. case STB_WEAK:
  4241. flags = BSF_WEAK;
  4242. break;
  4243. case STB_GNU_UNIQUE:
  4244. flags = BSF_GNU_UNIQUE;
  4245. break;
  4246. default:
  4247. /* Leave it up to the processor backend. */
  4248. break;
  4249. }
  4250. if (isym->st_shndx == SHN_UNDEF)
  4251. sec = bfd_und_section_ptr;
  4252. else if (isym->st_shndx == SHN_ABS)
  4253. sec = bfd_abs_section_ptr;
  4254. else if (isym->st_shndx == SHN_COMMON)
  4255. {
  4256. sec = bfd_com_section_ptr;
  4257. /* What ELF calls the size we call the value. What ELF
  4258. calls the value we call the alignment. */
  4259. value = isym->st_size;
  4260. }
  4261. else
  4262. {
  4263. sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  4264. if (sec == NULL)
  4265. sec = bfd_abs_section_ptr;
  4266. else if (sec->kept_section)
  4267. {
  4268. /* Symbols from discarded section are undefined. We keep
  4269. its visibility. */
  4270. sec = bfd_und_section_ptr;
  4271. isym->st_shndx = SHN_UNDEF;
  4272. }
  4273. else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
  4274. value -= sec->vma;
  4275. }
  4276. name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
  4277. isym->st_name);
  4278. if (name == NULL)
  4279. goto error_free_vers;
  4280. if (bed->elf_add_symbol_hook)
  4281. {
  4282. if (! (*bed->elf_add_symbol_hook) (abfd, info, isym, &name, &flags,
  4283. &sec, &value))
  4284. goto error_free_vers;
  4285. /* The hook function sets the name to NULL if this symbol
  4286. should be skipped for some reason. */
  4287. if (name == NULL)
  4288. continue;
  4289. }
  4290. /* Sanity check that all possibilities were handled. */
  4291. if (sec == NULL)
  4292. {
  4293. bfd_set_error (bfd_error_bad_value);
  4294. goto error_free_vers;
  4295. }
  4296. if (bfd_is_und_section (sec)
  4297. || bfd_is_com_section (sec))
  4298. definition = false;
  4299. else
  4300. definition = true;
  4301. size_change_ok = false;
  4302. type_change_ok = bed->type_change_ok;
  4303. old_alignment = 0;
  4304. old_bfd = NULL;
  4305. new_sec = sec;
  4306. if (! bfd_is_und_section (sec))
  4307. h = elf_link_hash_lookup (htab, name, true, false, false);
  4308. else
  4309. h = ((struct elf_link_hash_entry *) bfd_wrapped_link_hash_lookup
  4310. (abfd, info, name, true, false, false));
  4311. if (h == NULL)
  4312. goto error_free_sym;
  4313. *sym_hash = h;
  4314. if (is_elf_hash_table (&htab->root))
  4315. {
  4316. while (h->root.type == bfd_link_hash_indirect
  4317. || h->root.type == bfd_link_hash_warning)
  4318. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  4319. /* Remember the old alignment if this is a common symbol, so
  4320. that we don't reduce the alignment later on. We can't
  4321. check later, because _bfd_generic_link_add_one_symbol
  4322. will set a default for the alignment which we want to
  4323. override. We also remember the old bfd where the existing
  4324. definition comes from. */
  4325. switch (h->root.type)
  4326. {
  4327. default:
  4328. break;
  4329. case bfd_link_hash_defined:
  4330. if (abfd->selective_search)
  4331. continue;
  4332. /* Fall-through. */
  4333. case bfd_link_hash_defweak:
  4334. old_bfd = h->root.u.def.section->owner;
  4335. break;
  4336. case bfd_link_hash_common:
  4337. old_bfd = h->root.u.c.p->section->owner;
  4338. old_alignment = h->root.u.c.p->alignment_power;
  4339. break;
  4340. }
  4341. }
  4342. if (! (_bfd_generic_link_add_one_symbol
  4343. (info, abfd, name, flags, sec, value, NULL, false, bed->collect,
  4344. (struct bfd_link_hash_entry **) sym_hash)))
  4345. goto error_free_vers;
  4346. h = *sym_hash;
  4347. while (h->root.type == bfd_link_hash_indirect
  4348. || h->root.type == bfd_link_hash_warning)
  4349. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  4350. *sym_hash = h;
  4351. if (definition)
  4352. h->unique_global = (flags & BSF_GNU_UNIQUE) != 0;
  4353. /* Set the alignment of a common symbol. */
  4354. if ((common || bfd_is_com_section (sec))
  4355. && h->root.type == bfd_link_hash_common)
  4356. {
  4357. unsigned int align;
  4358. if (common)
  4359. align = bfd_log2 (isym->st_value);
  4360. else
  4361. {
  4362. /* The new symbol is a common symbol in a shared object.
  4363. We need to get the alignment from the section. */
  4364. align = new_sec->alignment_power;
  4365. }
  4366. if (align > old_alignment
  4367. /* Permit an alignment power of zero if an alignment of one
  4368. is specified and no other alignments have been specified. */
  4369. || (isym->st_value == 1 && old_alignment == 0))
  4370. h->root.u.c.p->alignment_power = align;
  4371. else
  4372. h->root.u.c.p->alignment_power = old_alignment;
  4373. }
  4374. if (is_elf_hash_table (&htab->root))
  4375. {
  4376. /* Check the alignment when a common symbol is involved. This
  4377. can change when a common symbol is overridden by a normal
  4378. definition or a common symbol is ignored due to the old
  4379. normal definition. We need to make sure the maximum
  4380. alignment is maintained. */
  4381. if ((old_alignment || common)
  4382. && h->root.type != bfd_link_hash_common)
  4383. {
  4384. unsigned int common_align;
  4385. unsigned int normal_align;
  4386. unsigned int symbol_align;
  4387. bfd *normal_bfd;
  4388. bfd *common_bfd;
  4389. symbol_align = ffs (h->root.u.def.value) - 1;
  4390. if (h->root.u.def.section->owner != NULL
  4391. && (h->root.u.def.section->owner->flags & DYNAMIC) == 0)
  4392. {
  4393. normal_align = h->root.u.def.section->alignment_power;
  4394. if (normal_align > symbol_align)
  4395. normal_align = symbol_align;
  4396. }
  4397. else
  4398. normal_align = symbol_align;
  4399. if (old_alignment)
  4400. {
  4401. common_align = old_alignment;
  4402. common_bfd = old_bfd;
  4403. normal_bfd = abfd;
  4404. }
  4405. else
  4406. {
  4407. common_align = bfd_log2 (isym->st_value);
  4408. common_bfd = abfd;
  4409. normal_bfd = old_bfd;
  4410. }
  4411. if (normal_align < common_align)
  4412. {
  4413. /* PR binutils/2735 */
  4414. if (normal_bfd == NULL)
  4415. _bfd_error_handler
  4416. /* xgettext:c-format */
  4417. (_("warning: alignment %u of common symbol `%s' in %pB"
  4418. " is greater than the alignment (%u) of its section %pA"),
  4419. 1 << common_align, name, common_bfd,
  4420. 1 << normal_align, h->root.u.def.section);
  4421. else
  4422. _bfd_error_handler
  4423. /* xgettext:c-format */
  4424. (_("warning: alignment %u of symbol `%s' in %pB"
  4425. " is smaller than %u in %pB"),
  4426. 1 << normal_align, name, normal_bfd,
  4427. 1 << common_align, common_bfd);
  4428. }
  4429. }
  4430. /* Remember the symbol size if it isn't undefined. */
  4431. if ((isym->st_size != 0 && isym->st_shndx != SHN_UNDEF)
  4432. && (definition || h->size == 0))
  4433. {
  4434. if (h->size != 0
  4435. && h->size != isym->st_size
  4436. && ! size_change_ok)
  4437. _bfd_error_handler
  4438. /* xgettext:c-format */
  4439. (_("warning: size of symbol `%s' changed"
  4440. " from %" PRIu64 " in %pB to %" PRIu64 " in %pB"),
  4441. name, (uint64_t) h->size, old_bfd,
  4442. (uint64_t) isym->st_size, abfd);
  4443. h->size = isym->st_size;
  4444. }
  4445. /* If this is a common symbol, then we always want H->SIZE
  4446. to be the size of the common symbol. The code just above
  4447. won't fix the size if a common symbol becomes larger. We
  4448. don't warn about a size change here, because that is
  4449. covered by --warn-common. Allow changed between different
  4450. function types. */
  4451. if (h->root.type == bfd_link_hash_common)
  4452. h->size = h->root.u.c.size;
  4453. if (ELF_ST_TYPE (isym->st_info) != STT_NOTYPE
  4454. && (definition || h->type == STT_NOTYPE))
  4455. {
  4456. unsigned int type = ELF_ST_TYPE (isym->st_info);
  4457. if (h->type != type)
  4458. {
  4459. if (h->type != STT_NOTYPE && ! type_change_ok)
  4460. _bfd_error_handler
  4461. /* xgettext:c-format */
  4462. (_("warning: type of symbol `%s' changed"
  4463. " from %d to %d in %pB"),
  4464. name, h->type, type, abfd);
  4465. h->type = type;
  4466. }
  4467. }
  4468. /* Set a flag in the hash table entry indicating the type of
  4469. reference or definition we just found. Keep a count of
  4470. the number of dynamic symbols we find. A dynamic symbol
  4471. is one which is referenced or defined by both a regular
  4472. object and a shared object. */
  4473. if (! dynamic)
  4474. {
  4475. if (! definition)
  4476. {
  4477. h->ref_regular = 1;
  4478. if (bind != STB_WEAK)
  4479. h->ref_regular_nonweak = 1;
  4480. }
  4481. else
  4482. {
  4483. BFD_ASSERT (!h->def_dynamic);
  4484. h->def_regular = 1;
  4485. }
  4486. }
  4487. else
  4488. {
  4489. BFD_ASSERT (definition);
  4490. h->def_dynamic = 1;
  4491. h->dynindx = -2;
  4492. ((struct elf64_ia64_link_hash_entry *)h)->shl = abfd;
  4493. }
  4494. }
  4495. }
  4496. free (isymbuf);
  4497. isymbuf = NULL;
  4498. /* If this object is the same format as the output object, and it is
  4499. not a shared library, then let the backend look through the
  4500. relocs.
  4501. This is required to build global offset table entries and to
  4502. arrange for dynamic relocs. It is not required for the
  4503. particular common case of linking non PIC code, even when linking
  4504. against shared libraries, but unfortunately there is no way of
  4505. knowing whether an object file has been compiled PIC or not.
  4506. Looking through the relocs is not particularly time consuming.
  4507. The problem is that we must either (1) keep the relocs in memory,
  4508. which causes the linker to require additional runtime memory or
  4509. (2) read the relocs twice from the input file, which wastes time.
  4510. This would be a good case for using mmap.
  4511. I have no idea how to handle linking PIC code into a file of a
  4512. different format. It probably can't be done. */
  4513. if (! dynamic
  4514. && is_elf_hash_table (&htab->root)
  4515. && bed->check_relocs != NULL
  4516. && (*bed->relocs_compatible) (abfd->xvec, info->output_bfd->xvec))
  4517. {
  4518. asection *o;
  4519. for (o = abfd->sections; o != NULL; o = o->next)
  4520. {
  4521. Elf_Internal_Rela *internal_relocs;
  4522. bool ok;
  4523. if ((o->flags & SEC_RELOC) == 0
  4524. || o->reloc_count == 0
  4525. || ((info->strip == strip_all || info->strip == strip_debugger)
  4526. && (o->flags & SEC_DEBUGGING) != 0)
  4527. || bfd_is_abs_section (o->output_section))
  4528. continue;
  4529. internal_relocs = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL,
  4530. info->keep_memory);
  4531. if (internal_relocs == NULL)
  4532. goto error_return;
  4533. ok = (*bed->check_relocs) (abfd, info, o, internal_relocs);
  4534. if (elf_section_data (o)->relocs != internal_relocs)
  4535. free (internal_relocs);
  4536. if (! ok)
  4537. goto error_return;
  4538. }
  4539. }
  4540. return true;
  4541. error_free_vers:
  4542. error_free_sym:
  4543. free (isymbuf);
  4544. error_return:
  4545. return false;
  4546. }
  4547. static bool
  4548. elf64_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
  4549. {
  4550. int pass;
  4551. struct bfd_link_hash_entry **pundef;
  4552. struct bfd_link_hash_entry **next_pundef;
  4553. /* We only accept VMS libraries. */
  4554. if (info->output_bfd->xvec != abfd->xvec)
  4555. {
  4556. bfd_set_error (bfd_error_wrong_format);
  4557. return false;
  4558. }
  4559. /* The archive_pass field in the archive itself is used to
  4560. initialize PASS, since we may search the same archive multiple
  4561. times. */
  4562. pass = ++abfd->archive_pass;
  4563. /* Look through the list of undefined symbols. */
  4564. for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef)
  4565. {
  4566. struct bfd_link_hash_entry *h;
  4567. symindex symidx;
  4568. bfd *element;
  4569. bfd *orig_element;
  4570. h = *pundef;
  4571. next_pundef = &(*pundef)->u.undef.next;
  4572. /* When a symbol is defined, it is not necessarily removed from
  4573. the list. */
  4574. if (h->type != bfd_link_hash_undefined
  4575. && h->type != bfd_link_hash_common)
  4576. {
  4577. /* Remove this entry from the list, for general cleanliness
  4578. and because we are going to look through the list again
  4579. if we search any more libraries. We can't remove the
  4580. entry if it is the tail, because that would lose any
  4581. entries we add to the list later on. */
  4582. if (*pundef != info->hash->undefs_tail)
  4583. {
  4584. *pundef = *next_pundef;
  4585. next_pundef = pundef;
  4586. }
  4587. continue;
  4588. }
  4589. /* Look for this symbol in the archive hash table. */
  4590. symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string);
  4591. if (symidx == BFD_NO_MORE_SYMBOLS)
  4592. {
  4593. /* Nothing in this slot. */
  4594. continue;
  4595. }
  4596. element = bfd_get_elt_at_index (abfd, symidx);
  4597. if (element == NULL)
  4598. return false;
  4599. if (element->archive_pass == -1 || element->archive_pass == pass)
  4600. {
  4601. /* Next symbol if this archive is wrong or already handled. */
  4602. continue;
  4603. }
  4604. orig_element = element;
  4605. if (bfd_is_thin_archive (abfd))
  4606. {
  4607. element = _bfd_vms_lib_get_imagelib_file (element);
  4608. if (element == NULL || !bfd_check_format (element, bfd_object))
  4609. {
  4610. orig_element->archive_pass = -1;
  4611. return false;
  4612. }
  4613. }
  4614. else if (! bfd_check_format (element, bfd_object))
  4615. {
  4616. element->archive_pass = -1;
  4617. return false;
  4618. }
  4619. /* Unlike the generic linker, we know that this element provides
  4620. a definition for an undefined symbol and we know that we want
  4621. to include it. We don't need to check anything. */
  4622. if (! (*info->callbacks->add_archive_element) (info, element,
  4623. h->root.string, &element))
  4624. continue;
  4625. if (! elf64_vms_link_add_object_symbols (element, info))
  4626. return false;
  4627. orig_element->archive_pass = pass;
  4628. }
  4629. return true;
  4630. }
  4631. static bool
  4632. elf64_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
  4633. {
  4634. switch (bfd_get_format (abfd))
  4635. {
  4636. case bfd_object:
  4637. return elf64_vms_link_add_object_symbols (abfd, info);
  4638. break;
  4639. case bfd_archive:
  4640. return elf64_vms_link_add_archive_symbols (abfd, info);
  4641. break;
  4642. default:
  4643. bfd_set_error (bfd_error_wrong_format);
  4644. return false;
  4645. }
  4646. }
  4647. static bool
  4648. elf64_ia64_vms_mkobject (bfd *abfd)
  4649. {
  4650. return bfd_elf_allocate_object
  4651. (abfd, sizeof (struct elf64_ia64_vms_obj_tdata), IA64_ELF_DATA);
  4652. }
  4653. /* Size-dependent data and functions. */
  4654. static const struct elf_size_info elf64_ia64_vms_size_info = {
  4655. sizeof (Elf64_External_VMS_Ehdr),
  4656. sizeof (Elf64_External_Phdr),
  4657. sizeof (Elf64_External_Shdr),
  4658. sizeof (Elf64_External_Rel),
  4659. sizeof (Elf64_External_Rela),
  4660. sizeof (Elf64_External_Sym),
  4661. sizeof (Elf64_External_Dyn),
  4662. sizeof (Elf_External_Note),
  4663. 4,
  4664. 1,
  4665. 64, 3, /* ARCH_SIZE, LOG_FILE_ALIGN */
  4666. ELFCLASS64, EV_CURRENT,
  4667. bfd_elf64_write_out_phdrs,
  4668. elf64_vms_write_shdrs_and_ehdr,
  4669. bfd_elf64_checksum_contents,
  4670. bfd_elf64_write_relocs,
  4671. bfd_elf64_swap_symbol_in,
  4672. bfd_elf64_swap_symbol_out,
  4673. bfd_elf64_slurp_reloc_table,
  4674. bfd_elf64_slurp_symbol_table,
  4675. bfd_elf64_swap_dyn_in,
  4676. bfd_elf64_swap_dyn_out,
  4677. bfd_elf64_swap_reloc_in,
  4678. bfd_elf64_swap_reloc_out,
  4679. bfd_elf64_swap_reloca_in,
  4680. bfd_elf64_swap_reloca_out
  4681. };
  4682. #define ELF_ARCH bfd_arch_ia64
  4683. #define ELF_MACHINE_CODE EM_IA_64
  4684. #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
  4685. #define ELF_COMMONPAGESIZE 0x200 /* 16KB */
  4686. #define elf_backend_section_from_shdr \
  4687. elf64_ia64_section_from_shdr
  4688. #define elf_backend_section_flags \
  4689. elf64_ia64_section_flags
  4690. #define elf_backend_fake_sections \
  4691. elf64_ia64_fake_sections
  4692. #define elf_backend_final_write_processing \
  4693. elf64_ia64_final_write_processing
  4694. #define elf_backend_add_symbol_hook \
  4695. elf64_ia64_add_symbol_hook
  4696. #define elf_info_to_howto \
  4697. elf64_ia64_info_to_howto
  4698. #define bfd_elf64_bfd_reloc_type_lookup \
  4699. ia64_elf_reloc_type_lookup
  4700. #define bfd_elf64_bfd_reloc_name_lookup \
  4701. ia64_elf_reloc_name_lookup
  4702. #define bfd_elf64_bfd_is_local_label_name \
  4703. elf64_ia64_is_local_label_name
  4704. #define bfd_elf64_bfd_relax_section \
  4705. elf64_ia64_relax_section
  4706. #define elf_backend_object_p \
  4707. elf64_ia64_object_p
  4708. /* Stuff for the BFD linker: */
  4709. #define bfd_elf64_bfd_link_hash_table_create \
  4710. elf64_ia64_hash_table_create
  4711. #define elf_backend_create_dynamic_sections \
  4712. elf64_ia64_create_dynamic_sections
  4713. #define elf_backend_check_relocs \
  4714. elf64_ia64_check_relocs
  4715. #define elf_backend_adjust_dynamic_symbol \
  4716. elf64_ia64_adjust_dynamic_symbol
  4717. #define elf_backend_size_dynamic_sections \
  4718. elf64_ia64_size_dynamic_sections
  4719. #define elf_backend_omit_section_dynsym \
  4720. _bfd_elf_omit_section_dynsym_all
  4721. #define elf_backend_relocate_section \
  4722. elf64_ia64_relocate_section
  4723. #define elf_backend_finish_dynamic_symbol \
  4724. elf64_ia64_finish_dynamic_symbol
  4725. #define elf_backend_finish_dynamic_sections \
  4726. elf64_ia64_finish_dynamic_sections
  4727. #define bfd_elf64_bfd_final_link \
  4728. elf64_ia64_final_link
  4729. #define bfd_elf64_bfd_merge_private_bfd_data \
  4730. elf64_ia64_merge_private_bfd_data
  4731. #define bfd_elf64_bfd_set_private_flags \
  4732. elf64_ia64_set_private_flags
  4733. #define bfd_elf64_bfd_print_private_bfd_data \
  4734. elf64_ia64_print_private_bfd_data
  4735. #define elf_backend_plt_readonly 1
  4736. #define elf_backend_want_plt_sym 0
  4737. #define elf_backend_plt_alignment 5
  4738. #define elf_backend_got_header_size 0
  4739. #define elf_backend_want_got_plt 1
  4740. #define elf_backend_may_use_rel_p 1
  4741. #define elf_backend_may_use_rela_p 1
  4742. #define elf_backend_default_use_rela_p 1
  4743. #define elf_backend_want_dynbss 0
  4744. #define elf_backend_hide_symbol elf64_ia64_hash_hide_symbol
  4745. #define elf_backend_fixup_symbol _bfd_elf_link_hash_fixup_symbol
  4746. #define elf_backend_reloc_type_class elf64_ia64_reloc_type_class
  4747. #define elf_backend_rela_normal 1
  4748. #define elf_backend_special_sections elf64_ia64_special_sections
  4749. #define elf_backend_default_execstack 0
  4750. /* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with
  4751. SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields.
  4752. We don't want to flood users with so many error messages. We turn
  4753. off the warning for now. It will be turned on later when the Intel
  4754. compiler is fixed. */
  4755. #define elf_backend_link_order_error_handler NULL
  4756. /* VMS-specific vectors. */
  4757. #undef TARGET_LITTLE_SYM
  4758. #define TARGET_LITTLE_SYM ia64_elf64_vms_vec
  4759. #undef TARGET_LITTLE_NAME
  4760. #define TARGET_LITTLE_NAME "elf64-ia64-vms"
  4761. #undef TARGET_BIG_SYM
  4762. #undef TARGET_BIG_NAME
  4763. /* These are VMS specific functions. */
  4764. #undef elf_backend_object_p
  4765. #define elf_backend_object_p elf64_vms_object_p
  4766. #undef elf_backend_section_from_shdr
  4767. #define elf_backend_section_from_shdr elf64_vms_section_from_shdr
  4768. #undef elf_backend_init_file_header
  4769. #define elf_backend_init_file_header elf64_vms_init_file_header
  4770. #undef elf_backend_section_processing
  4771. #define elf_backend_section_processing elf64_vms_section_processing
  4772. #undef elf_backend_final_write_processing
  4773. #define elf_backend_final_write_processing elf64_vms_final_write_processing
  4774. #undef bfd_elf64_close_and_cleanup
  4775. #define bfd_elf64_close_and_cleanup elf64_vms_close_and_cleanup
  4776. #undef elf_backend_section_from_bfd_section
  4777. #undef elf_backend_symbol_processing
  4778. #undef elf_backend_want_p_paddr_set_to_zero
  4779. #undef ELF_OSABI
  4780. #define ELF_OSABI ELFOSABI_OPENVMS
  4781. #undef ELF_MAXPAGESIZE
  4782. #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
  4783. #undef elf64_bed
  4784. #define elf64_bed elf64_ia64_vms_bed
  4785. #define elf_backend_size_info elf64_ia64_vms_size_info
  4786. /* Use VMS-style archives (in particular, don't use the standard coff
  4787. archive format). */
  4788. #define bfd_elf64_archive_functions
  4789. #undef bfd_elf64_archive_p
  4790. #define bfd_elf64_archive_p _bfd_vms_lib_ia64_archive_p
  4791. #undef bfd_elf64_write_archive_contents
  4792. #define bfd_elf64_write_archive_contents _bfd_vms_lib_write_archive_contents
  4793. #undef bfd_elf64_mkarchive
  4794. #define bfd_elf64_mkarchive _bfd_vms_lib_ia64_mkarchive
  4795. #define bfd_elf64_archive_slurp_armap \
  4796. _bfd_vms_lib_slurp_armap
  4797. #define bfd_elf64_archive_slurp_extended_name_table \
  4798. _bfd_vms_lib_slurp_extended_name_table
  4799. #define bfd_elf64_archive_construct_extended_name_table \
  4800. _bfd_vms_lib_construct_extended_name_table
  4801. #define bfd_elf64_archive_truncate_arname \
  4802. _bfd_vms_lib_truncate_arname
  4803. #define bfd_elf64_archive_write_armap \
  4804. _bfd_vms_lib_write_armap
  4805. #define bfd_elf64_archive_read_ar_hdr \
  4806. _bfd_vms_lib_read_ar_hdr
  4807. #define bfd_elf64_archive_write_ar_hdr \
  4808. _bfd_vms_lib_write_ar_hdr
  4809. #define bfd_elf64_archive_openr_next_archived_file \
  4810. _bfd_vms_lib_openr_next_archived_file
  4811. #define bfd_elf64_archive_get_elt_at_index \
  4812. _bfd_vms_lib_get_elt_at_index
  4813. #define bfd_elf64_archive_generic_stat_arch_elt \
  4814. _bfd_vms_lib_generic_stat_arch_elt
  4815. #define bfd_elf64_archive_update_armap_timestamp \
  4816. _bfd_vms_lib_update_armap_timestamp
  4817. /* VMS link methods. */
  4818. #undef bfd_elf64_bfd_link_add_symbols
  4819. #define bfd_elf64_bfd_link_add_symbols elf64_vms_bfd_link_add_symbols
  4820. #undef elf_backend_want_got_sym
  4821. #define elf_backend_want_got_sym 0
  4822. #undef bfd_elf64_mkobject
  4823. #define bfd_elf64_mkobject elf64_ia64_vms_mkobject
  4824. /* Redefine to align segments on block size. */
  4825. #undef ELF_MAXPAGESIZE
  4826. #define ELF_MAXPAGESIZE 0x200 /* 512B */
  4827. #undef elf_backend_want_got_plt
  4828. #define elf_backend_want_got_plt 0
  4829. #include "elf64-target.h"