elf32-m68k.c 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669
  1. /* Motorola 68k series support for 32-bit ELF
  2. Copyright (C) 1993-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "bfdlink.h"
  19. #include "libbfd.h"
  20. #include "elf-bfd.h"
  21. #include "elf/m68k.h"
  22. #include "opcode/m68k.h"
  23. #include "cpu-m68k.h"
  24. #include "elf32-m68k.h"
  25. static bool
  26. elf_m68k_discard_copies (struct elf_link_hash_entry *, void *);
  27. static reloc_howto_type howto_table[] =
  28. {
  29. HOWTO(R_68K_NONE, 0, 3, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", false, 0, 0x00000000,false),
  30. HOWTO(R_68K_32, 0, 2,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", false, 0, 0xffffffff,false),
  31. HOWTO(R_68K_16, 0, 1,16, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", false, 0, 0x0000ffff,false),
  32. HOWTO(R_68K_8, 0, 0, 8, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", false, 0, 0x000000ff,false),
  33. HOWTO(R_68K_PC32, 0, 2,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", false, 0, 0xffffffff,true),
  34. HOWTO(R_68K_PC16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", false, 0, 0x0000ffff,true),
  35. HOWTO(R_68K_PC8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", false, 0, 0x000000ff,true),
  36. HOWTO(R_68K_GOT32, 0, 2,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", false, 0, 0xffffffff,true),
  37. HOWTO(R_68K_GOT16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", false, 0, 0x0000ffff,true),
  38. HOWTO(R_68K_GOT8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", false, 0, 0x000000ff,true),
  39. HOWTO(R_68K_GOT32O, 0, 2,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", false, 0, 0xffffffff,false),
  40. HOWTO(R_68K_GOT16O, 0, 1,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", false, 0, 0x0000ffff,false),
  41. HOWTO(R_68K_GOT8O, 0, 0, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", false, 0, 0x000000ff,false),
  42. HOWTO(R_68K_PLT32, 0, 2,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", false, 0, 0xffffffff,true),
  43. HOWTO(R_68K_PLT16, 0, 1,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", false, 0, 0x0000ffff,true),
  44. HOWTO(R_68K_PLT8, 0, 0, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", false, 0, 0x000000ff,true),
  45. HOWTO(R_68K_PLT32O, 0, 2,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", false, 0, 0xffffffff,false),
  46. HOWTO(R_68K_PLT16O, 0, 1,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", false, 0, 0x0000ffff,false),
  47. HOWTO(R_68K_PLT8O, 0, 0, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", false, 0, 0x000000ff,false),
  48. HOWTO(R_68K_COPY, 0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", false, 0, 0xffffffff,false),
  49. HOWTO(R_68K_GLOB_DAT, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", false, 0, 0xffffffff,false),
  50. HOWTO(R_68K_JMP_SLOT, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", false, 0, 0xffffffff,false),
  51. HOWTO(R_68K_RELATIVE, 0, 2,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", false, 0, 0xffffffff,false),
  52. /* GNU extension to record C++ vtable hierarchy. */
  53. HOWTO (R_68K_GNU_VTINHERIT, /* type */
  54. 0, /* rightshift */
  55. 2, /* size (0 = byte, 1 = short, 2 = long) */
  56. 0, /* bitsize */
  57. false, /* pc_relative */
  58. 0, /* bitpos */
  59. complain_overflow_dont, /* complain_on_overflow */
  60. NULL, /* special_function */
  61. "R_68K_GNU_VTINHERIT", /* name */
  62. false, /* partial_inplace */
  63. 0, /* src_mask */
  64. 0, /* dst_mask */
  65. false),
  66. /* GNU extension to record C++ vtable member usage. */
  67. HOWTO (R_68K_GNU_VTENTRY, /* type */
  68. 0, /* rightshift */
  69. 2, /* size (0 = byte, 1 = short, 2 = long) */
  70. 0, /* bitsize */
  71. false, /* pc_relative */
  72. 0, /* bitpos */
  73. complain_overflow_dont, /* complain_on_overflow */
  74. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  75. "R_68K_GNU_VTENTRY", /* name */
  76. false, /* partial_inplace */
  77. 0, /* src_mask */
  78. 0, /* dst_mask */
  79. false),
  80. /* TLS general dynamic variable reference. */
  81. HOWTO (R_68K_TLS_GD32, /* type */
  82. 0, /* rightshift */
  83. 2, /* size (0 = byte, 1 = short, 2 = long) */
  84. 32, /* bitsize */
  85. false, /* pc_relative */
  86. 0, /* bitpos */
  87. complain_overflow_bitfield, /* complain_on_overflow */
  88. bfd_elf_generic_reloc, /* special_function */
  89. "R_68K_TLS_GD32", /* name */
  90. false, /* partial_inplace */
  91. 0, /* src_mask */
  92. 0xffffffff, /* dst_mask */
  93. false), /* pcrel_offset */
  94. HOWTO (R_68K_TLS_GD16, /* type */
  95. 0, /* rightshift */
  96. 1, /* size (0 = byte, 1 = short, 2 = long) */
  97. 16, /* bitsize */
  98. false, /* pc_relative */
  99. 0, /* bitpos */
  100. complain_overflow_signed, /* complain_on_overflow */
  101. bfd_elf_generic_reloc, /* special_function */
  102. "R_68K_TLS_GD16", /* name */
  103. false, /* partial_inplace */
  104. 0, /* src_mask */
  105. 0x0000ffff, /* dst_mask */
  106. false), /* pcrel_offset */
  107. HOWTO (R_68K_TLS_GD8, /* type */
  108. 0, /* rightshift */
  109. 0, /* size (0 = byte, 1 = short, 2 = long) */
  110. 8, /* bitsize */
  111. false, /* pc_relative */
  112. 0, /* bitpos */
  113. complain_overflow_signed, /* complain_on_overflow */
  114. bfd_elf_generic_reloc, /* special_function */
  115. "R_68K_TLS_GD8", /* name */
  116. false, /* partial_inplace */
  117. 0, /* src_mask */
  118. 0x000000ff, /* dst_mask */
  119. false), /* pcrel_offset */
  120. /* TLS local dynamic variable reference. */
  121. HOWTO (R_68K_TLS_LDM32, /* type */
  122. 0, /* rightshift */
  123. 2, /* size (0 = byte, 1 = short, 2 = long) */
  124. 32, /* bitsize */
  125. false, /* pc_relative */
  126. 0, /* bitpos */
  127. complain_overflow_bitfield, /* complain_on_overflow */
  128. bfd_elf_generic_reloc, /* special_function */
  129. "R_68K_TLS_LDM32", /* name */
  130. false, /* partial_inplace */
  131. 0, /* src_mask */
  132. 0xffffffff, /* dst_mask */
  133. false), /* pcrel_offset */
  134. HOWTO (R_68K_TLS_LDM16, /* type */
  135. 0, /* rightshift */
  136. 1, /* size (0 = byte, 1 = short, 2 = long) */
  137. 16, /* bitsize */
  138. false, /* pc_relative */
  139. 0, /* bitpos */
  140. complain_overflow_signed, /* complain_on_overflow */
  141. bfd_elf_generic_reloc, /* special_function */
  142. "R_68K_TLS_LDM16", /* name */
  143. false, /* partial_inplace */
  144. 0, /* src_mask */
  145. 0x0000ffff, /* dst_mask */
  146. false), /* pcrel_offset */
  147. HOWTO (R_68K_TLS_LDM8, /* type */
  148. 0, /* rightshift */
  149. 0, /* size (0 = byte, 1 = short, 2 = long) */
  150. 8, /* bitsize */
  151. false, /* pc_relative */
  152. 0, /* bitpos */
  153. complain_overflow_signed, /* complain_on_overflow */
  154. bfd_elf_generic_reloc, /* special_function */
  155. "R_68K_TLS_LDM8", /* name */
  156. false, /* partial_inplace */
  157. 0, /* src_mask */
  158. 0x000000ff, /* dst_mask */
  159. false), /* pcrel_offset */
  160. HOWTO (R_68K_TLS_LDO32, /* type */
  161. 0, /* rightshift */
  162. 2, /* size (0 = byte, 1 = short, 2 = long) */
  163. 32, /* bitsize */
  164. false, /* pc_relative */
  165. 0, /* bitpos */
  166. complain_overflow_bitfield, /* complain_on_overflow */
  167. bfd_elf_generic_reloc, /* special_function */
  168. "R_68K_TLS_LDO32", /* name */
  169. false, /* partial_inplace */
  170. 0, /* src_mask */
  171. 0xffffffff, /* dst_mask */
  172. false), /* pcrel_offset */
  173. HOWTO (R_68K_TLS_LDO16, /* type */
  174. 0, /* rightshift */
  175. 1, /* size (0 = byte, 1 = short, 2 = long) */
  176. 16, /* bitsize */
  177. false, /* pc_relative */
  178. 0, /* bitpos */
  179. complain_overflow_signed, /* complain_on_overflow */
  180. bfd_elf_generic_reloc, /* special_function */
  181. "R_68K_TLS_LDO16", /* name */
  182. false, /* partial_inplace */
  183. 0, /* src_mask */
  184. 0x0000ffff, /* dst_mask */
  185. false), /* pcrel_offset */
  186. HOWTO (R_68K_TLS_LDO8, /* type */
  187. 0, /* rightshift */
  188. 0, /* size (0 = byte, 1 = short, 2 = long) */
  189. 8, /* bitsize */
  190. false, /* pc_relative */
  191. 0, /* bitpos */
  192. complain_overflow_signed, /* complain_on_overflow */
  193. bfd_elf_generic_reloc, /* special_function */
  194. "R_68K_TLS_LDO8", /* name */
  195. false, /* partial_inplace */
  196. 0, /* src_mask */
  197. 0x000000ff, /* dst_mask */
  198. false), /* pcrel_offset */
  199. /* TLS initial execution variable reference. */
  200. HOWTO (R_68K_TLS_IE32, /* type */
  201. 0, /* rightshift */
  202. 2, /* size (0 = byte, 1 = short, 2 = long) */
  203. 32, /* bitsize */
  204. false, /* pc_relative */
  205. 0, /* bitpos */
  206. complain_overflow_bitfield, /* complain_on_overflow */
  207. bfd_elf_generic_reloc, /* special_function */
  208. "R_68K_TLS_IE32", /* name */
  209. false, /* partial_inplace */
  210. 0, /* src_mask */
  211. 0xffffffff, /* dst_mask */
  212. false), /* pcrel_offset */
  213. HOWTO (R_68K_TLS_IE16, /* type */
  214. 0, /* rightshift */
  215. 1, /* size (0 = byte, 1 = short, 2 = long) */
  216. 16, /* bitsize */
  217. false, /* pc_relative */
  218. 0, /* bitpos */
  219. complain_overflow_signed, /* complain_on_overflow */
  220. bfd_elf_generic_reloc, /* special_function */
  221. "R_68K_TLS_IE16", /* name */
  222. false, /* partial_inplace */
  223. 0, /* src_mask */
  224. 0x0000ffff, /* dst_mask */
  225. false), /* pcrel_offset */
  226. HOWTO (R_68K_TLS_IE8, /* type */
  227. 0, /* rightshift */
  228. 0, /* size (0 = byte, 1 = short, 2 = long) */
  229. 8, /* bitsize */
  230. false, /* pc_relative */
  231. 0, /* bitpos */
  232. complain_overflow_signed, /* complain_on_overflow */
  233. bfd_elf_generic_reloc, /* special_function */
  234. "R_68K_TLS_IE8", /* name */
  235. false, /* partial_inplace */
  236. 0, /* src_mask */
  237. 0x000000ff, /* dst_mask */
  238. false), /* pcrel_offset */
  239. /* TLS local execution variable reference. */
  240. HOWTO (R_68K_TLS_LE32, /* type */
  241. 0, /* rightshift */
  242. 2, /* size (0 = byte, 1 = short, 2 = long) */
  243. 32, /* bitsize */
  244. false, /* pc_relative */
  245. 0, /* bitpos */
  246. complain_overflow_bitfield, /* complain_on_overflow */
  247. bfd_elf_generic_reloc, /* special_function */
  248. "R_68K_TLS_LE32", /* name */
  249. false, /* partial_inplace */
  250. 0, /* src_mask */
  251. 0xffffffff, /* dst_mask */
  252. false), /* pcrel_offset */
  253. HOWTO (R_68K_TLS_LE16, /* type */
  254. 0, /* rightshift */
  255. 1, /* size (0 = byte, 1 = short, 2 = long) */
  256. 16, /* bitsize */
  257. false, /* pc_relative */
  258. 0, /* bitpos */
  259. complain_overflow_signed, /* complain_on_overflow */
  260. bfd_elf_generic_reloc, /* special_function */
  261. "R_68K_TLS_LE16", /* name */
  262. false, /* partial_inplace */
  263. 0, /* src_mask */
  264. 0x0000ffff, /* dst_mask */
  265. false), /* pcrel_offset */
  266. HOWTO (R_68K_TLS_LE8, /* type */
  267. 0, /* rightshift */
  268. 0, /* size (0 = byte, 1 = short, 2 = long) */
  269. 8, /* bitsize */
  270. false, /* pc_relative */
  271. 0, /* bitpos */
  272. complain_overflow_signed, /* complain_on_overflow */
  273. bfd_elf_generic_reloc, /* special_function */
  274. "R_68K_TLS_LE8", /* name */
  275. false, /* partial_inplace */
  276. 0, /* src_mask */
  277. 0x000000ff, /* dst_mask */
  278. false), /* pcrel_offset */
  279. /* TLS GD/LD dynamic relocations. */
  280. HOWTO (R_68K_TLS_DTPMOD32, /* type */
  281. 0, /* rightshift */
  282. 2, /* size (0 = byte, 1 = short, 2 = long) */
  283. 32, /* bitsize */
  284. false, /* pc_relative */
  285. 0, /* bitpos */
  286. complain_overflow_dont, /* complain_on_overflow */
  287. bfd_elf_generic_reloc, /* special_function */
  288. "R_68K_TLS_DTPMOD32", /* name */
  289. false, /* partial_inplace */
  290. 0, /* src_mask */
  291. 0xffffffff, /* dst_mask */
  292. false), /* pcrel_offset */
  293. HOWTO (R_68K_TLS_DTPREL32, /* type */
  294. 0, /* rightshift */
  295. 2, /* size (0 = byte, 1 = short, 2 = long) */
  296. 32, /* bitsize */
  297. false, /* pc_relative */
  298. 0, /* bitpos */
  299. complain_overflow_dont, /* complain_on_overflow */
  300. bfd_elf_generic_reloc, /* special_function */
  301. "R_68K_TLS_DTPREL32", /* name */
  302. false, /* partial_inplace */
  303. 0, /* src_mask */
  304. 0xffffffff, /* dst_mask */
  305. false), /* pcrel_offset */
  306. HOWTO (R_68K_TLS_TPREL32, /* type */
  307. 0, /* rightshift */
  308. 2, /* size (0 = byte, 1 = short, 2 = long) */
  309. 32, /* bitsize */
  310. false, /* pc_relative */
  311. 0, /* bitpos */
  312. complain_overflow_dont, /* complain_on_overflow */
  313. bfd_elf_generic_reloc, /* special_function */
  314. "R_68K_TLS_TPREL32", /* name */
  315. false, /* partial_inplace */
  316. 0, /* src_mask */
  317. 0xffffffff, /* dst_mask */
  318. false), /* pcrel_offset */
  319. };
  320. static bool
  321. rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
  322. {
  323. unsigned int indx = ELF32_R_TYPE (dst->r_info);
  324. if (indx >= (unsigned int) R_68K_max)
  325. {
  326. /* xgettext:c-format */
  327. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  328. abfd, indx);
  329. bfd_set_error (bfd_error_bad_value);
  330. return false;
  331. }
  332. cache_ptr->howto = &howto_table[indx];
  333. return true;
  334. }
  335. #define elf_info_to_howto rtype_to_howto
  336. static const struct
  337. {
  338. bfd_reloc_code_real_type bfd_val;
  339. int elf_val;
  340. }
  341. reloc_map[] =
  342. {
  343. { BFD_RELOC_NONE, R_68K_NONE },
  344. { BFD_RELOC_32, R_68K_32 },
  345. { BFD_RELOC_16, R_68K_16 },
  346. { BFD_RELOC_8, R_68K_8 },
  347. { BFD_RELOC_32_PCREL, R_68K_PC32 },
  348. { BFD_RELOC_16_PCREL, R_68K_PC16 },
  349. { BFD_RELOC_8_PCREL, R_68K_PC8 },
  350. { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
  351. { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
  352. { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
  353. { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
  354. { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
  355. { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
  356. { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
  357. { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
  358. { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
  359. { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
  360. { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
  361. { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
  362. { BFD_RELOC_NONE, R_68K_COPY },
  363. { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
  364. { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
  365. { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
  366. { BFD_RELOC_CTOR, R_68K_32 },
  367. { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
  368. { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
  369. { BFD_RELOC_68K_TLS_GD32, R_68K_TLS_GD32 },
  370. { BFD_RELOC_68K_TLS_GD16, R_68K_TLS_GD16 },
  371. { BFD_RELOC_68K_TLS_GD8, R_68K_TLS_GD8 },
  372. { BFD_RELOC_68K_TLS_LDM32, R_68K_TLS_LDM32 },
  373. { BFD_RELOC_68K_TLS_LDM16, R_68K_TLS_LDM16 },
  374. { BFD_RELOC_68K_TLS_LDM8, R_68K_TLS_LDM8 },
  375. { BFD_RELOC_68K_TLS_LDO32, R_68K_TLS_LDO32 },
  376. { BFD_RELOC_68K_TLS_LDO16, R_68K_TLS_LDO16 },
  377. { BFD_RELOC_68K_TLS_LDO8, R_68K_TLS_LDO8 },
  378. { BFD_RELOC_68K_TLS_IE32, R_68K_TLS_IE32 },
  379. { BFD_RELOC_68K_TLS_IE16, R_68K_TLS_IE16 },
  380. { BFD_RELOC_68K_TLS_IE8, R_68K_TLS_IE8 },
  381. { BFD_RELOC_68K_TLS_LE32, R_68K_TLS_LE32 },
  382. { BFD_RELOC_68K_TLS_LE16, R_68K_TLS_LE16 },
  383. { BFD_RELOC_68K_TLS_LE8, R_68K_TLS_LE8 },
  384. };
  385. static reloc_howto_type *
  386. reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  387. bfd_reloc_code_real_type code)
  388. {
  389. unsigned int i;
  390. for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
  391. {
  392. if (reloc_map[i].bfd_val == code)
  393. return &howto_table[reloc_map[i].elf_val];
  394. }
  395. return 0;
  396. }
  397. static reloc_howto_type *
  398. reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
  399. {
  400. unsigned int i;
  401. for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
  402. if (howto_table[i].name != NULL
  403. && strcasecmp (howto_table[i].name, r_name) == 0)
  404. return &howto_table[i];
  405. return NULL;
  406. }
  407. #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
  408. #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
  409. #define ELF_ARCH bfd_arch_m68k
  410. #define ELF_TARGET_ID M68K_ELF_DATA
  411. /* Functions for the m68k ELF linker. */
  412. /* The name of the dynamic interpreter. This is put in the .interp
  413. section. */
  414. #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
  415. /* Describes one of the various PLT styles. */
  416. struct elf_m68k_plt_info
  417. {
  418. /* The size of each PLT entry. */
  419. bfd_vma size;
  420. /* The template for the first PLT entry. */
  421. const bfd_byte *plt0_entry;
  422. /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
  423. The comments by each member indicate the value that the relocation
  424. is against. */
  425. struct {
  426. unsigned int got4; /* .got + 4 */
  427. unsigned int got8; /* .got + 8 */
  428. } plt0_relocs;
  429. /* The template for a symbol's PLT entry. */
  430. const bfd_byte *symbol_entry;
  431. /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
  432. The comments by each member indicate the value that the relocation
  433. is against. */
  434. struct {
  435. unsigned int got; /* the symbol's .got.plt entry */
  436. unsigned int plt; /* .plt */
  437. } symbol_relocs;
  438. /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
  439. The stub starts with "move.l #relocoffset,%d0". */
  440. bfd_vma symbol_resolve_entry;
  441. };
  442. /* The size in bytes of an entry in the procedure linkage table. */
  443. #define PLT_ENTRY_SIZE 20
  444. /* The first entry in a procedure linkage table looks like this. See
  445. the SVR4 ABI m68k supplement to see how this works. */
  446. static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
  447. {
  448. 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
  449. 0, 0, 0, 2, /* + (.got + 4) - . */
  450. 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
  451. 0, 0, 0, 2, /* + (.got + 8) - . */
  452. 0, 0, 0, 0 /* pad out to 20 bytes. */
  453. };
  454. /* Subsequent entries in a procedure linkage table look like this. */
  455. static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
  456. {
  457. 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
  458. 0, 0, 0, 2, /* + (.got.plt entry) - . */
  459. 0x2f, 0x3c, /* move.l #offset,-(%sp) */
  460. 0, 0, 0, 0, /* + reloc index */
  461. 0x60, 0xff, /* bra.l .plt */
  462. 0, 0, 0, 0 /* + .plt - . */
  463. };
  464. static const struct elf_m68k_plt_info elf_m68k_plt_info =
  465. {
  466. PLT_ENTRY_SIZE,
  467. elf_m68k_plt0_entry, { 4, 12 },
  468. elf_m68k_plt_entry, { 4, 16 }, 8
  469. };
  470. #define ISAB_PLT_ENTRY_SIZE 24
  471. static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
  472. {
  473. 0x20, 0x3c, /* move.l #offset,%d0 */
  474. 0, 0, 0, 0, /* + (.got + 4) - . */
  475. 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
  476. 0x20, 0x3c, /* move.l #offset,%d0 */
  477. 0, 0, 0, 0, /* + (.got + 8) - . */
  478. 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
  479. 0x4e, 0xd0, /* jmp (%a0) */
  480. 0x4e, 0x71 /* nop */
  481. };
  482. /* Subsequent entries in a procedure linkage table look like this. */
  483. static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
  484. {
  485. 0x20, 0x3c, /* move.l #offset,%d0 */
  486. 0, 0, 0, 0, /* + (.got.plt entry) - . */
  487. 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
  488. 0x4e, 0xd0, /* jmp (%a0) */
  489. 0x2f, 0x3c, /* move.l #offset,-(%sp) */
  490. 0, 0, 0, 0, /* + reloc index */
  491. 0x60, 0xff, /* bra.l .plt */
  492. 0, 0, 0, 0 /* + .plt - . */
  493. };
  494. static const struct elf_m68k_plt_info elf_isab_plt_info =
  495. {
  496. ISAB_PLT_ENTRY_SIZE,
  497. elf_isab_plt0_entry, { 2, 12 },
  498. elf_isab_plt_entry, { 2, 20 }, 12
  499. };
  500. #define ISAC_PLT_ENTRY_SIZE 24
  501. static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] =
  502. {
  503. 0x20, 0x3c, /* move.l #offset,%d0 */
  504. 0, 0, 0, 0, /* replaced with .got + 4 - . */
  505. 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
  506. 0x20, 0x3c, /* move.l #offset,%d0 */
  507. 0, 0, 0, 0, /* replaced with .got + 8 - . */
  508. 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
  509. 0x4e, 0xd0, /* jmp (%a0) */
  510. 0x4e, 0x71 /* nop */
  511. };
  512. /* Subsequent entries in a procedure linkage table look like this. */
  513. static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] =
  514. {
  515. 0x20, 0x3c, /* move.l #offset,%d0 */
  516. 0, 0, 0, 0, /* replaced with (.got entry) - . */
  517. 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
  518. 0x4e, 0xd0, /* jmp (%a0) */
  519. 0x2f, 0x3c, /* move.l #offset,-(%sp) */
  520. 0, 0, 0, 0, /* replaced with offset into relocation table */
  521. 0x61, 0xff, /* bsr.l .plt */
  522. 0, 0, 0, 0 /* replaced with .plt - . */
  523. };
  524. static const struct elf_m68k_plt_info elf_isac_plt_info =
  525. {
  526. ISAC_PLT_ENTRY_SIZE,
  527. elf_isac_plt0_entry, { 2, 12},
  528. elf_isac_plt_entry, { 2, 20 }, 12
  529. };
  530. #define CPU32_PLT_ENTRY_SIZE 24
  531. /* Procedure linkage table entries for the cpu32 */
  532. static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
  533. {
  534. 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
  535. 0, 0, 0, 2, /* + (.got + 4) - . */
  536. 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
  537. 0, 0, 0, 2, /* + (.got + 8) - . */
  538. 0x4e, 0xd1, /* jmp %a1@ */
  539. 0, 0, 0, 0, /* pad out to 24 bytes. */
  540. 0, 0
  541. };
  542. static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
  543. {
  544. 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
  545. 0, 0, 0, 2, /* + (.got.plt entry) - . */
  546. 0x4e, 0xd1, /* jmp %a1@ */
  547. 0x2f, 0x3c, /* move.l #offset,-(%sp) */
  548. 0, 0, 0, 0, /* + reloc index */
  549. 0x60, 0xff, /* bra.l .plt */
  550. 0, 0, 0, 0, /* + .plt - . */
  551. 0, 0
  552. };
  553. static const struct elf_m68k_plt_info elf_cpu32_plt_info =
  554. {
  555. CPU32_PLT_ENTRY_SIZE,
  556. elf_cpu32_plt0_entry, { 4, 12 },
  557. elf_cpu32_plt_entry, { 4, 18 }, 10
  558. };
  559. /* The m68k linker needs to keep track of the number of relocs that it
  560. decides to copy in check_relocs for each symbol. This is so that it
  561. can discard PC relative relocs if it doesn't need them when linking
  562. with -Bsymbolic. We store the information in a field extending the
  563. regular ELF linker hash table. */
  564. /* This structure keeps track of the number of PC relative relocs we have
  565. copied for a given symbol. */
  566. struct elf_m68k_pcrel_relocs_copied
  567. {
  568. /* Next section. */
  569. struct elf_m68k_pcrel_relocs_copied *next;
  570. /* A section in dynobj. */
  571. asection *section;
  572. /* Number of relocs copied in this section. */
  573. bfd_size_type count;
  574. };
  575. /* Forward declaration. */
  576. struct elf_m68k_got_entry;
  577. /* m68k ELF linker hash entry. */
  578. struct elf_m68k_link_hash_entry
  579. {
  580. struct elf_link_hash_entry root;
  581. /* Number of PC relative relocs copied for this symbol. */
  582. struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
  583. /* Key to got_entries. */
  584. unsigned long got_entry_key;
  585. /* List of GOT entries for this symbol. This list is build during
  586. offset finalization and is used within elf_m68k_finish_dynamic_symbol
  587. to traverse all GOT entries for a particular symbol.
  588. ??? We could've used root.got.glist field instead, but having
  589. a separate field is cleaner. */
  590. struct elf_m68k_got_entry *glist;
  591. };
  592. #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
  593. /* Key part of GOT entry in hashtable. */
  594. struct elf_m68k_got_entry_key
  595. {
  596. /* BFD in which this symbol was defined. NULL for global symbols. */
  597. const bfd *bfd;
  598. /* Symbol index. Either local symbol index or h->got_entry_key. */
  599. unsigned long symndx;
  600. /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
  601. R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
  602. From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
  603. matters. That is, we distinguish between, say, R_68K_GOT16O
  604. and R_68K_GOT32O when allocating offsets, but they are considered to be
  605. the same when searching got->entries. */
  606. enum elf_m68k_reloc_type type;
  607. };
  608. /* Size of the GOT offset suitable for relocation. */
  609. enum elf_m68k_got_offset_size { R_8, R_16, R_32, R_LAST };
  610. /* Entry of the GOT. */
  611. struct elf_m68k_got_entry
  612. {
  613. /* GOT entries are put into a got->entries hashtable. This is the key. */
  614. struct elf_m68k_got_entry_key key_;
  615. /* GOT entry data. We need s1 before offset finalization and s2 after. */
  616. union
  617. {
  618. struct
  619. {
  620. /* Number of times this entry is referenced. */
  621. bfd_vma refcount;
  622. } s1;
  623. struct
  624. {
  625. /* Offset from the start of .got section. To calculate offset relative
  626. to GOT pointer one should subtract got->offset from this value. */
  627. bfd_vma offset;
  628. /* Pointer to the next GOT entry for this global symbol.
  629. Symbols have at most one entry in one GOT, but might
  630. have entries in more than one GOT.
  631. Root of this list is h->glist.
  632. NULL for local symbols. */
  633. struct elf_m68k_got_entry *next;
  634. } s2;
  635. } u;
  636. };
  637. /* Return representative type for relocation R_TYPE.
  638. This is used to avoid enumerating many relocations in comparisons,
  639. switches etc. */
  640. static enum elf_m68k_reloc_type
  641. elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type)
  642. {
  643. switch (r_type)
  644. {
  645. /* In most cases R_68K_GOTx relocations require the very same
  646. handling as R_68K_GOT32O relocation. In cases when we need
  647. to distinguish between the two, we use explicitly compare against
  648. r_type. */
  649. case R_68K_GOT32:
  650. case R_68K_GOT16:
  651. case R_68K_GOT8:
  652. case R_68K_GOT32O:
  653. case R_68K_GOT16O:
  654. case R_68K_GOT8O:
  655. return R_68K_GOT32O;
  656. case R_68K_TLS_GD32:
  657. case R_68K_TLS_GD16:
  658. case R_68K_TLS_GD8:
  659. return R_68K_TLS_GD32;
  660. case R_68K_TLS_LDM32:
  661. case R_68K_TLS_LDM16:
  662. case R_68K_TLS_LDM8:
  663. return R_68K_TLS_LDM32;
  664. case R_68K_TLS_IE32:
  665. case R_68K_TLS_IE16:
  666. case R_68K_TLS_IE8:
  667. return R_68K_TLS_IE32;
  668. default:
  669. BFD_ASSERT (false);
  670. return 0;
  671. }
  672. }
  673. /* Return size of the GOT entry offset for relocation R_TYPE. */
  674. static enum elf_m68k_got_offset_size
  675. elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type)
  676. {
  677. switch (r_type)
  678. {
  679. case R_68K_GOT32: case R_68K_GOT16: case R_68K_GOT8:
  680. case R_68K_GOT32O: case R_68K_TLS_GD32: case R_68K_TLS_LDM32:
  681. case R_68K_TLS_IE32:
  682. return R_32;
  683. case R_68K_GOT16O: case R_68K_TLS_GD16: case R_68K_TLS_LDM16:
  684. case R_68K_TLS_IE16:
  685. return R_16;
  686. case R_68K_GOT8O: case R_68K_TLS_GD8: case R_68K_TLS_LDM8:
  687. case R_68K_TLS_IE8:
  688. return R_8;
  689. default:
  690. BFD_ASSERT (false);
  691. return 0;
  692. }
  693. }
  694. /* Return number of GOT entries we need to allocate in GOT for
  695. relocation R_TYPE. */
  696. static bfd_vma
  697. elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type)
  698. {
  699. switch (elf_m68k_reloc_got_type (r_type))
  700. {
  701. case R_68K_GOT32O:
  702. case R_68K_TLS_IE32:
  703. return 1;
  704. case R_68K_TLS_GD32:
  705. case R_68K_TLS_LDM32:
  706. return 2;
  707. default:
  708. BFD_ASSERT (false);
  709. return 0;
  710. }
  711. }
  712. /* Return TRUE if relocation R_TYPE is a TLS one. */
  713. static bool
  714. elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type)
  715. {
  716. switch (r_type)
  717. {
  718. case R_68K_TLS_GD32: case R_68K_TLS_GD16: case R_68K_TLS_GD8:
  719. case R_68K_TLS_LDM32: case R_68K_TLS_LDM16: case R_68K_TLS_LDM8:
  720. case R_68K_TLS_LDO32: case R_68K_TLS_LDO16: case R_68K_TLS_LDO8:
  721. case R_68K_TLS_IE32: case R_68K_TLS_IE16: case R_68K_TLS_IE8:
  722. case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8:
  723. case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPREL32: case R_68K_TLS_TPREL32:
  724. return true;
  725. default:
  726. return false;
  727. }
  728. }
  729. /* Data structure representing a single GOT. */
  730. struct elf_m68k_got
  731. {
  732. /* Hashtable of 'struct elf_m68k_got_entry's.
  733. Starting size of this table is the maximum number of
  734. R_68K_GOT8O entries. */
  735. htab_t entries;
  736. /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require
  737. several GOT slots.
  738. n_slots[R_8] is the count of R_8 slots in this GOT.
  739. n_slots[R_16] is the cumulative count of R_8 and R_16 slots
  740. in this GOT.
  741. n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
  742. in this GOT. This is the total number of slots. */
  743. bfd_vma n_slots[R_LAST];
  744. /* Number of local (entry->key_.h == NULL) slots in this GOT.
  745. This is only used to properly calculate size of .rela.got section;
  746. see elf_m68k_partition_multi_got. */
  747. bfd_vma local_n_slots;
  748. /* Offset of this GOT relative to beginning of .got section. */
  749. bfd_vma offset;
  750. };
  751. /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
  752. struct elf_m68k_bfd2got_entry
  753. {
  754. /* BFD. */
  755. const bfd *bfd;
  756. /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
  757. GOT structure. After partitioning several BFD's might [and often do]
  758. share a single GOT. */
  759. struct elf_m68k_got *got;
  760. };
  761. /* The main data structure holding all the pieces. */
  762. struct elf_m68k_multi_got
  763. {
  764. /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
  765. here, then it doesn't need a GOT (this includes the case of a BFD
  766. having an empty GOT).
  767. ??? This hashtable can be replaced by an array indexed by bfd->id. */
  768. htab_t bfd2got;
  769. /* Next symndx to assign a global symbol.
  770. h->got_entry_key is initialized from this counter. */
  771. unsigned long global_symndx;
  772. };
  773. /* m68k ELF linker hash table. */
  774. struct elf_m68k_link_hash_table
  775. {
  776. struct elf_link_hash_table root;
  777. /* The PLT format used by this link, or NULL if the format has not
  778. yet been chosen. */
  779. const struct elf_m68k_plt_info *plt_info;
  780. /* True, if GP is loaded within each function which uses it.
  781. Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
  782. bool local_gp_p;
  783. /* Switch controlling use of negative offsets to double the size of GOTs. */
  784. bool use_neg_got_offsets_p;
  785. /* Switch controlling generation of multiple GOTs. */
  786. bool allow_multigot_p;
  787. /* Multi-GOT data structure. */
  788. struct elf_m68k_multi_got multi_got_;
  789. };
  790. /* Get the m68k ELF linker hash table from a link_info structure. */
  791. #define elf_m68k_hash_table(p) \
  792. ((is_elf_hash_table ((p)->hash) \
  793. && elf_hash_table_id (elf_hash_table (p)) == M68K_ELF_DATA) \
  794. ? (struct elf_m68k_link_hash_table *) (p)->hash : NULL)
  795. /* Shortcut to multi-GOT data. */
  796. #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
  797. /* Create an entry in an m68k ELF linker hash table. */
  798. static struct bfd_hash_entry *
  799. elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry,
  800. struct bfd_hash_table *table,
  801. const char *string)
  802. {
  803. struct bfd_hash_entry *ret = entry;
  804. /* Allocate the structure if it has not already been allocated by a
  805. subclass. */
  806. if (ret == NULL)
  807. ret = bfd_hash_allocate (table,
  808. sizeof (struct elf_m68k_link_hash_entry));
  809. if (ret == NULL)
  810. return ret;
  811. /* Call the allocation method of the superclass. */
  812. ret = _bfd_elf_link_hash_newfunc (ret, table, string);
  813. if (ret != NULL)
  814. {
  815. elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
  816. elf_m68k_hash_entry (ret)->got_entry_key = 0;
  817. elf_m68k_hash_entry (ret)->glist = NULL;
  818. }
  819. return ret;
  820. }
  821. /* Destroy an m68k ELF linker hash table. */
  822. static void
  823. elf_m68k_link_hash_table_free (bfd *obfd)
  824. {
  825. struct elf_m68k_link_hash_table *htab;
  826. htab = (struct elf_m68k_link_hash_table *) obfd->link.hash;
  827. if (htab->multi_got_.bfd2got != NULL)
  828. {
  829. htab_delete (htab->multi_got_.bfd2got);
  830. htab->multi_got_.bfd2got = NULL;
  831. }
  832. _bfd_elf_link_hash_table_free (obfd);
  833. }
  834. /* Create an m68k ELF linker hash table. */
  835. static struct bfd_link_hash_table *
  836. elf_m68k_link_hash_table_create (bfd *abfd)
  837. {
  838. struct elf_m68k_link_hash_table *ret;
  839. size_t amt = sizeof (struct elf_m68k_link_hash_table);
  840. ret = (struct elf_m68k_link_hash_table *) bfd_zmalloc (amt);
  841. if (ret == (struct elf_m68k_link_hash_table *) NULL)
  842. return NULL;
  843. if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
  844. elf_m68k_link_hash_newfunc,
  845. sizeof (struct elf_m68k_link_hash_entry),
  846. M68K_ELF_DATA))
  847. {
  848. free (ret);
  849. return NULL;
  850. }
  851. ret->root.root.hash_table_free = elf_m68k_link_hash_table_free;
  852. ret->multi_got_.global_symndx = 1;
  853. return &ret->root.root;
  854. }
  855. /* Set the right machine number. */
  856. static bool
  857. elf32_m68k_object_p (bfd *abfd)
  858. {
  859. unsigned int mach = 0;
  860. unsigned features = 0;
  861. flagword eflags = elf_elfheader (abfd)->e_flags;
  862. if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
  863. features |= m68000;
  864. else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
  865. features |= cpu32;
  866. else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
  867. features |= fido_a;
  868. else
  869. {
  870. switch (eflags & EF_M68K_CF_ISA_MASK)
  871. {
  872. case EF_M68K_CF_ISA_A_NODIV:
  873. features |= mcfisa_a;
  874. break;
  875. case EF_M68K_CF_ISA_A:
  876. features |= mcfisa_a|mcfhwdiv;
  877. break;
  878. case EF_M68K_CF_ISA_A_PLUS:
  879. features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
  880. break;
  881. case EF_M68K_CF_ISA_B_NOUSP:
  882. features |= mcfisa_a|mcfisa_b|mcfhwdiv;
  883. break;
  884. case EF_M68K_CF_ISA_B:
  885. features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
  886. break;
  887. case EF_M68K_CF_ISA_C:
  888. features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp;
  889. break;
  890. case EF_M68K_CF_ISA_C_NODIV:
  891. features |= mcfisa_a|mcfisa_c|mcfusp;
  892. break;
  893. }
  894. switch (eflags & EF_M68K_CF_MAC_MASK)
  895. {
  896. case EF_M68K_CF_MAC:
  897. features |= mcfmac;
  898. break;
  899. case EF_M68K_CF_EMAC:
  900. features |= mcfemac;
  901. break;
  902. }
  903. if (eflags & EF_M68K_CF_FLOAT)
  904. features |= cfloat;
  905. }
  906. mach = bfd_m68k_features_to_mach (features);
  907. bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
  908. return true;
  909. }
  910. /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag
  911. field based on the machine number. */
  912. static bool
  913. elf_m68k_final_write_processing (bfd *abfd)
  914. {
  915. int mach = bfd_get_mach (abfd);
  916. unsigned long e_flags = elf_elfheader (abfd)->e_flags;
  917. if (!e_flags)
  918. {
  919. unsigned int arch_mask;
  920. arch_mask = bfd_m68k_mach_to_features (mach);
  921. if (arch_mask & m68000)
  922. e_flags = EF_M68K_M68000;
  923. else if (arch_mask & cpu32)
  924. e_flags = EF_M68K_CPU32;
  925. else if (arch_mask & fido_a)
  926. e_flags = EF_M68K_FIDO;
  927. else
  928. {
  929. switch (arch_mask
  930. & (mcfisa_a | mcfisa_aa | mcfisa_b | mcfisa_c | mcfhwdiv | mcfusp))
  931. {
  932. case mcfisa_a:
  933. e_flags |= EF_M68K_CF_ISA_A_NODIV;
  934. break;
  935. case mcfisa_a | mcfhwdiv:
  936. e_flags |= EF_M68K_CF_ISA_A;
  937. break;
  938. case mcfisa_a | mcfisa_aa | mcfhwdiv | mcfusp:
  939. e_flags |= EF_M68K_CF_ISA_A_PLUS;
  940. break;
  941. case mcfisa_a | mcfisa_b | mcfhwdiv:
  942. e_flags |= EF_M68K_CF_ISA_B_NOUSP;
  943. break;
  944. case mcfisa_a | mcfisa_b | mcfhwdiv | mcfusp:
  945. e_flags |= EF_M68K_CF_ISA_B;
  946. break;
  947. case mcfisa_a | mcfisa_c | mcfhwdiv | mcfusp:
  948. e_flags |= EF_M68K_CF_ISA_C;
  949. break;
  950. case mcfisa_a | mcfisa_c | mcfusp:
  951. e_flags |= EF_M68K_CF_ISA_C_NODIV;
  952. break;
  953. }
  954. if (arch_mask & mcfmac)
  955. e_flags |= EF_M68K_CF_MAC;
  956. else if (arch_mask & mcfemac)
  957. e_flags |= EF_M68K_CF_EMAC;
  958. if (arch_mask & cfloat)
  959. e_flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E;
  960. }
  961. elf_elfheader (abfd)->e_flags = e_flags;
  962. }
  963. return _bfd_elf_final_write_processing (abfd);
  964. }
  965. /* Keep m68k-specific flags in the ELF header. */
  966. static bool
  967. elf32_m68k_set_private_flags (bfd *abfd, flagword flags)
  968. {
  969. elf_elfheader (abfd)->e_flags = flags;
  970. elf_flags_init (abfd) = true;
  971. return true;
  972. }
  973. /* Merge object attributes from IBFD into OBFD. Warn if
  974. there are conflicting attributes. */
  975. static bool
  976. m68k_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
  977. {
  978. bfd *obfd = info->output_bfd;
  979. obj_attribute *in_attr, *in_attrs;
  980. obj_attribute *out_attr, *out_attrs;
  981. bool ret = true;
  982. in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
  983. out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
  984. in_attr = &in_attrs[Tag_GNU_M68K_ABI_FP];
  985. out_attr = &out_attrs[Tag_GNU_M68K_ABI_FP];
  986. if (in_attr->i != out_attr->i)
  987. {
  988. int in_fp = in_attr->i & 3;
  989. int out_fp = out_attr->i & 3;
  990. static bfd *last_fp;
  991. if (in_fp == 0)
  992. ;
  993. else if (out_fp == 0)
  994. {
  995. out_attr->type = ATTR_TYPE_FLAG_INT_VAL;
  996. out_attr->i ^= in_fp;
  997. last_fp = ibfd;
  998. }
  999. else if (out_fp == 1 && in_fp == 2)
  1000. {
  1001. _bfd_error_handler
  1002. /* xgettext:c-format */
  1003. (_("%pB uses hard float, %pB uses soft float"),
  1004. last_fp, ibfd);
  1005. ret = false;
  1006. }
  1007. else if (out_fp == 2 && in_fp == 1)
  1008. {
  1009. _bfd_error_handler
  1010. /* xgettext:c-format */
  1011. (_("%pB uses hard float, %pB uses soft float"),
  1012. ibfd, last_fp);
  1013. ret = false;
  1014. }
  1015. }
  1016. if (!ret)
  1017. {
  1018. out_attr->type = ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_ERROR;
  1019. bfd_set_error (bfd_error_bad_value);
  1020. return false;
  1021. }
  1022. /* Merge Tag_compatibility attributes and any common GNU ones. */
  1023. return _bfd_elf_merge_object_attributes (ibfd, info);
  1024. }
  1025. /* Merge backend specific data from an object file to the output
  1026. object file when linking. */
  1027. static bool
  1028. elf32_m68k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
  1029. {
  1030. bfd *obfd = info->output_bfd;
  1031. flagword out_flags;
  1032. flagword in_flags;
  1033. flagword out_isa;
  1034. flagword in_isa;
  1035. const bfd_arch_info_type *arch_info;
  1036. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
  1037. || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
  1038. /* PR 24523: For non-ELF files do not try to merge any private
  1039. data, but also do not prevent the link from succeeding. */
  1040. return true;
  1041. /* Get the merged machine. This checks for incompatibility between
  1042. Coldfire & non-Coldfire flags, incompability between different
  1043. Coldfire ISAs, and incompability between different MAC types. */
  1044. arch_info = bfd_arch_get_compatible (ibfd, obfd, false);
  1045. if (!arch_info)
  1046. return false;
  1047. bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
  1048. if (!m68k_elf_merge_obj_attributes (ibfd, info))
  1049. return false;
  1050. in_flags = elf_elfheader (ibfd)->e_flags;
  1051. if (!elf_flags_init (obfd))
  1052. {
  1053. elf_flags_init (obfd) = true;
  1054. out_flags = in_flags;
  1055. }
  1056. else
  1057. {
  1058. out_flags = elf_elfheader (obfd)->e_flags;
  1059. unsigned int variant_mask;
  1060. if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
  1061. variant_mask = 0;
  1062. else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
  1063. variant_mask = 0;
  1064. else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
  1065. variant_mask = 0;
  1066. else
  1067. variant_mask = EF_M68K_CF_ISA_MASK;
  1068. in_isa = (in_flags & variant_mask);
  1069. out_isa = (out_flags & variant_mask);
  1070. if (in_isa > out_isa)
  1071. out_flags ^= in_isa ^ out_isa;
  1072. if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
  1073. && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
  1074. || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
  1075. && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
  1076. out_flags = EF_M68K_FIDO;
  1077. else
  1078. out_flags |= in_flags ^ in_isa;
  1079. }
  1080. elf_elfheader (obfd)->e_flags = out_flags;
  1081. return true;
  1082. }
  1083. /* Display the flags field. */
  1084. static bool
  1085. elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr)
  1086. {
  1087. FILE *file = (FILE *) ptr;
  1088. flagword eflags = elf_elfheader (abfd)->e_flags;
  1089. BFD_ASSERT (abfd != NULL && ptr != NULL);
  1090. /* Print normal ELF private data. */
  1091. _bfd_elf_print_private_bfd_data (abfd, ptr);
  1092. /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
  1093. /* xgettext:c-format */
  1094. fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
  1095. if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
  1096. fprintf (file, " [m68000]");
  1097. else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
  1098. fprintf (file, " [cpu32]");
  1099. else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
  1100. fprintf (file, " [fido]");
  1101. else
  1102. {
  1103. if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
  1104. fprintf (file, " [cfv4e]");
  1105. if (eflags & EF_M68K_CF_ISA_MASK)
  1106. {
  1107. char const *isa = _("unknown");
  1108. char const *mac = _("unknown");
  1109. char const *additional = "";
  1110. switch (eflags & EF_M68K_CF_ISA_MASK)
  1111. {
  1112. case EF_M68K_CF_ISA_A_NODIV:
  1113. isa = "A";
  1114. additional = " [nodiv]";
  1115. break;
  1116. case EF_M68K_CF_ISA_A:
  1117. isa = "A";
  1118. break;
  1119. case EF_M68K_CF_ISA_A_PLUS:
  1120. isa = "A+";
  1121. break;
  1122. case EF_M68K_CF_ISA_B_NOUSP:
  1123. isa = "B";
  1124. additional = " [nousp]";
  1125. break;
  1126. case EF_M68K_CF_ISA_B:
  1127. isa = "B";
  1128. break;
  1129. case EF_M68K_CF_ISA_C:
  1130. isa = "C";
  1131. break;
  1132. case EF_M68K_CF_ISA_C_NODIV:
  1133. isa = "C";
  1134. additional = " [nodiv]";
  1135. break;
  1136. }
  1137. fprintf (file, " [isa %s]%s", isa, additional);
  1138. if (eflags & EF_M68K_CF_FLOAT)
  1139. fprintf (file, " [float]");
  1140. switch (eflags & EF_M68K_CF_MAC_MASK)
  1141. {
  1142. case 0:
  1143. mac = NULL;
  1144. break;
  1145. case EF_M68K_CF_MAC:
  1146. mac = "mac";
  1147. break;
  1148. case EF_M68K_CF_EMAC:
  1149. mac = "emac";
  1150. break;
  1151. case EF_M68K_CF_EMAC_B:
  1152. mac = "emac_b";
  1153. break;
  1154. }
  1155. if (mac)
  1156. fprintf (file, " [%s]", mac);
  1157. }
  1158. }
  1159. fputc ('\n', file);
  1160. return true;
  1161. }
  1162. /* Multi-GOT support implementation design:
  1163. Multi-GOT starts in check_relocs hook. There we scan all
  1164. relocations of a BFD and build a local GOT (struct elf_m68k_got)
  1165. for it. If a single BFD appears to require too many GOT slots with
  1166. R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
  1167. to user.
  1168. After check_relocs has been invoked for each input BFD, we have
  1169. constructed a GOT for each input BFD.
  1170. To minimize total number of GOTs required for a particular output BFD
  1171. (as some environments support only 1 GOT per output object) we try
  1172. to merge some of the GOTs to share an offset space. Ideally [and in most
  1173. cases] we end up with a single GOT. In cases when there are too many
  1174. restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
  1175. several GOTs, assuming the environment can handle them.
  1176. Partitioning is done in elf_m68k_partition_multi_got. We start with
  1177. an empty GOT and traverse bfd2got hashtable putting got_entries from
  1178. local GOTs to the new 'big' one. We do that by constructing an
  1179. intermediate GOT holding all the entries the local GOT has and the big
  1180. GOT lacks. Then we check if there is room in the big GOT to accomodate
  1181. all the entries from diff. On success we add those entries to the big
  1182. GOT; on failure we start the new 'big' GOT and retry the adding of
  1183. entries from the local GOT. Note that this retry will always succeed as
  1184. each local GOT doesn't overflow the limits. After partitioning we
  1185. end up with each bfd assigned one of the big GOTs. GOT entries in the
  1186. big GOTs are initialized with GOT offsets. Note that big GOTs are
  1187. positioned consequently in program space and represent a single huge GOT
  1188. to the outside world.
  1189. After that we get to elf_m68k_relocate_section. There we
  1190. adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
  1191. relocations to refer to appropriate [assigned to current input_bfd]
  1192. big GOT.
  1193. Notes:
  1194. GOT entry type: We have several types of GOT entries.
  1195. * R_8 type is used in entries for symbols that have at least one
  1196. R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40
  1197. such entries in one GOT.
  1198. * R_16 type is used in entries for symbols that have at least one
  1199. R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
  1200. We can have at most 0x4000 such entries in one GOT.
  1201. * R_32 type is used in all other cases. We can have as many
  1202. such entries in one GOT as we'd like.
  1203. When counting relocations we have to include the count of the smaller
  1204. ranged relocations in the counts of the larger ranged ones in order
  1205. to correctly detect overflow.
  1206. Sorting the GOT: In each GOT starting offsets are assigned to
  1207. R_8 entries, which are followed by R_16 entries, and
  1208. R_32 entries go at the end. See finalize_got_offsets for details.
  1209. Negative GOT offsets: To double usable offset range of GOTs we use
  1210. negative offsets. As we assign entries with GOT offsets relative to
  1211. start of .got section, the offset values are positive. They become
  1212. negative only in relocate_section where got->offset value is
  1213. subtracted from them.
  1214. 3 special GOT entries: There are 3 special GOT entries used internally
  1215. by loader. These entries happen to be placed to .got.plt section,
  1216. so we don't do anything about them in multi-GOT support.
  1217. Memory management: All data except for hashtables
  1218. multi_got->bfd2got and got->entries are allocated on
  1219. elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
  1220. to most functions), so we don't need to care to free them. At the
  1221. moment of allocation hashtables are being linked into main data
  1222. structure (multi_got), all pieces of which are reachable from
  1223. elf_m68k_multi_got (info). We deallocate them in
  1224. elf_m68k_link_hash_table_free. */
  1225. /* Initialize GOT. */
  1226. static void
  1227. elf_m68k_init_got (struct elf_m68k_got *got)
  1228. {
  1229. got->entries = NULL;
  1230. got->n_slots[R_8] = 0;
  1231. got->n_slots[R_16] = 0;
  1232. got->n_slots[R_32] = 0;
  1233. got->local_n_slots = 0;
  1234. got->offset = (bfd_vma) -1;
  1235. }
  1236. /* Destruct GOT. */
  1237. static void
  1238. elf_m68k_clear_got (struct elf_m68k_got *got)
  1239. {
  1240. if (got->entries != NULL)
  1241. {
  1242. htab_delete (got->entries);
  1243. got->entries = NULL;
  1244. }
  1245. }
  1246. /* Create and empty GOT structure. INFO is the context where memory
  1247. should be allocated. */
  1248. static struct elf_m68k_got *
  1249. elf_m68k_create_empty_got (struct bfd_link_info *info)
  1250. {
  1251. struct elf_m68k_got *got;
  1252. got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got));
  1253. if (got == NULL)
  1254. return NULL;
  1255. elf_m68k_init_got (got);
  1256. return got;
  1257. }
  1258. /* Initialize KEY. */
  1259. static void
  1260. elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key,
  1261. struct elf_link_hash_entry *h,
  1262. const bfd *abfd, unsigned long symndx,
  1263. enum elf_m68k_reloc_type reloc_type)
  1264. {
  1265. if (elf_m68k_reloc_got_type (reloc_type) == R_68K_TLS_LDM32)
  1266. /* All TLS_LDM relocations share a single GOT entry. */
  1267. {
  1268. key->bfd = NULL;
  1269. key->symndx = 0;
  1270. }
  1271. else if (h != NULL)
  1272. /* Global symbols are identified with their got_entry_key. */
  1273. {
  1274. key->bfd = NULL;
  1275. key->symndx = elf_m68k_hash_entry (h)->got_entry_key;
  1276. BFD_ASSERT (key->symndx != 0);
  1277. }
  1278. else
  1279. /* Local symbols are identified by BFD they appear in and symndx. */
  1280. {
  1281. key->bfd = abfd;
  1282. key->symndx = symndx;
  1283. }
  1284. key->type = reloc_type;
  1285. }
  1286. /* Calculate hash of got_entry.
  1287. ??? Is it good? */
  1288. static hashval_t
  1289. elf_m68k_got_entry_hash (const void *_entry)
  1290. {
  1291. const struct elf_m68k_got_entry_key *key;
  1292. key = &((const struct elf_m68k_got_entry *) _entry)->key_;
  1293. return (key->symndx
  1294. + (key->bfd != NULL ? (int) key->bfd->id : -1)
  1295. + elf_m68k_reloc_got_type (key->type));
  1296. }
  1297. /* Check if two got entries are equal. */
  1298. static int
  1299. elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2)
  1300. {
  1301. const struct elf_m68k_got_entry_key *key1;
  1302. const struct elf_m68k_got_entry_key *key2;
  1303. key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_;
  1304. key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_;
  1305. return (key1->bfd == key2->bfd
  1306. && key1->symndx == key2->symndx
  1307. && (elf_m68k_reloc_got_type (key1->type)
  1308. == elf_m68k_reloc_got_type (key2->type)));
  1309. }
  1310. /* When using negative offsets, we allocate one extra R_8, one extra R_16
  1311. and one extra R_32 slots to simplify handling of 2-slot entries during
  1312. offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */
  1313. /* Maximal number of R_8 slots in a single GOT. */
  1314. #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \
  1315. (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
  1316. ? (0x40 - 1) \
  1317. : 0x20)
  1318. /* Maximal number of R_8 and R_16 slots in a single GOT. */
  1319. #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \
  1320. (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
  1321. ? (0x4000 - 2) \
  1322. : 0x2000)
  1323. /* SEARCH - simply search the hashtable, don't insert new entries or fail when
  1324. the entry cannot be found.
  1325. FIND_OR_CREATE - search for an existing entry, but create new if there's
  1326. no such.
  1327. MUST_FIND - search for an existing entry and assert that it exist.
  1328. MUST_CREATE - assert that there's no such entry and create new one. */
  1329. enum elf_m68k_get_entry_howto
  1330. {
  1331. SEARCH,
  1332. FIND_OR_CREATE,
  1333. MUST_FIND,
  1334. MUST_CREATE
  1335. };
  1336. /* Get or create (depending on HOWTO) entry with KEY in GOT.
  1337. INFO is context in which memory should be allocated (can be NULL if
  1338. HOWTO is SEARCH or MUST_FIND). */
  1339. static struct elf_m68k_got_entry *
  1340. elf_m68k_get_got_entry (struct elf_m68k_got *got,
  1341. const struct elf_m68k_got_entry_key *key,
  1342. enum elf_m68k_get_entry_howto howto,
  1343. struct bfd_link_info *info)
  1344. {
  1345. struct elf_m68k_got_entry entry_;
  1346. struct elf_m68k_got_entry *entry;
  1347. void **ptr;
  1348. BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
  1349. if (got->entries == NULL)
  1350. /* This is the first entry in ABFD. Initialize hashtable. */
  1351. {
  1352. if (howto == SEARCH)
  1353. return NULL;
  1354. got->entries = htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
  1355. (info),
  1356. elf_m68k_got_entry_hash,
  1357. elf_m68k_got_entry_eq, NULL);
  1358. if (got->entries == NULL)
  1359. {
  1360. bfd_set_error (bfd_error_no_memory);
  1361. return NULL;
  1362. }
  1363. }
  1364. entry_.key_ = *key;
  1365. ptr = htab_find_slot (got->entries, &entry_,
  1366. (howto == SEARCH || howto == MUST_FIND ? NO_INSERT
  1367. : INSERT));
  1368. if (ptr == NULL)
  1369. {
  1370. if (howto == SEARCH)
  1371. /* Entry not found. */
  1372. return NULL;
  1373. if (howto == MUST_FIND)
  1374. abort ();
  1375. /* We're out of memory. */
  1376. bfd_set_error (bfd_error_no_memory);
  1377. return NULL;
  1378. }
  1379. if (*ptr == NULL)
  1380. /* We didn't find the entry and we're asked to create a new one. */
  1381. {
  1382. if (howto == MUST_FIND)
  1383. abort ();
  1384. BFD_ASSERT (howto != SEARCH);
  1385. entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry));
  1386. if (entry == NULL)
  1387. return NULL;
  1388. /* Initialize new entry. */
  1389. entry->key_ = *key;
  1390. entry->u.s1.refcount = 0;
  1391. /* Mark the entry as not initialized. */
  1392. entry->key_.type = R_68K_max;
  1393. *ptr = entry;
  1394. }
  1395. else
  1396. /* We found the entry. */
  1397. {
  1398. BFD_ASSERT (howto != MUST_CREATE);
  1399. entry = *ptr;
  1400. }
  1401. return entry;
  1402. }
  1403. /* Update GOT counters when merging entry of WAS type with entry of NEW type.
  1404. Return the value to which ENTRY's type should be set. */
  1405. static enum elf_m68k_reloc_type
  1406. elf_m68k_update_got_entry_type (struct elf_m68k_got *got,
  1407. enum elf_m68k_reloc_type was,
  1408. enum elf_m68k_reloc_type new_reloc)
  1409. {
  1410. enum elf_m68k_got_offset_size was_size;
  1411. enum elf_m68k_got_offset_size new_size;
  1412. bfd_vma n_slots;
  1413. if (was == R_68K_max)
  1414. /* The type of the entry is not initialized yet. */
  1415. {
  1416. /* Update all got->n_slots counters, including n_slots[R_32]. */
  1417. was_size = R_LAST;
  1418. was = new_reloc;
  1419. }
  1420. else
  1421. {
  1422. /* !!! We, probably, should emit an error rather then fail on assert
  1423. in such a case. */
  1424. BFD_ASSERT (elf_m68k_reloc_got_type (was)
  1425. == elf_m68k_reloc_got_type (new_reloc));
  1426. was_size = elf_m68k_reloc_got_offset_size (was);
  1427. }
  1428. new_size = elf_m68k_reloc_got_offset_size (new_reloc);
  1429. n_slots = elf_m68k_reloc_got_n_slots (new_reloc);
  1430. while (was_size > new_size)
  1431. {
  1432. --was_size;
  1433. got->n_slots[was_size] += n_slots;
  1434. }
  1435. if (new_reloc > was)
  1436. /* Relocations are ordered from bigger got offset size to lesser,
  1437. so choose the relocation type with lesser offset size. */
  1438. was = new_reloc;
  1439. return was;
  1440. }
  1441. /* Add new or update existing entry to GOT.
  1442. H, ABFD, TYPE and SYMNDX is data for the entry.
  1443. INFO is a context where memory should be allocated. */
  1444. static struct elf_m68k_got_entry *
  1445. elf_m68k_add_entry_to_got (struct elf_m68k_got *got,
  1446. struct elf_link_hash_entry *h,
  1447. const bfd *abfd,
  1448. enum elf_m68k_reloc_type reloc_type,
  1449. unsigned long symndx,
  1450. struct bfd_link_info *info)
  1451. {
  1452. struct elf_m68k_got_entry_key key_;
  1453. struct elf_m68k_got_entry *entry;
  1454. if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0)
  1455. elf_m68k_hash_entry (h)->got_entry_key
  1456. = elf_m68k_multi_got (info)->global_symndx++;
  1457. elf_m68k_init_got_entry_key (&key_, h, abfd, symndx, reloc_type);
  1458. entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info);
  1459. if (entry == NULL)
  1460. return NULL;
  1461. /* Determine entry's type and update got->n_slots counters. */
  1462. entry->key_.type = elf_m68k_update_got_entry_type (got,
  1463. entry->key_.type,
  1464. reloc_type);
  1465. /* Update refcount. */
  1466. ++entry->u.s1.refcount;
  1467. if (entry->u.s1.refcount == 1)
  1468. /* We see this entry for the first time. */
  1469. {
  1470. if (entry->key_.bfd != NULL)
  1471. got->local_n_slots += elf_m68k_reloc_got_n_slots (entry->key_.type);
  1472. }
  1473. BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
  1474. if ((got->n_slots[R_8]
  1475. > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
  1476. || (got->n_slots[R_16]
  1477. > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
  1478. /* This BFD has too many relocation. */
  1479. {
  1480. if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
  1481. /* xgettext:c-format */
  1482. _bfd_error_handler (_("%pB: GOT overflow: "
  1483. "number of relocations with 8-bit "
  1484. "offset > %d"),
  1485. abfd,
  1486. ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info));
  1487. else
  1488. /* xgettext:c-format */
  1489. _bfd_error_handler (_("%pB: GOT overflow: "
  1490. "number of relocations with 8- or 16-bit "
  1491. "offset > %d"),
  1492. abfd,
  1493. ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info));
  1494. return NULL;
  1495. }
  1496. return entry;
  1497. }
  1498. /* Compute the hash value of the bfd in a bfd2got hash entry. */
  1499. static hashval_t
  1500. elf_m68k_bfd2got_entry_hash (const void *entry)
  1501. {
  1502. const struct elf_m68k_bfd2got_entry *e;
  1503. e = (const struct elf_m68k_bfd2got_entry *) entry;
  1504. return e->bfd->id;
  1505. }
  1506. /* Check whether two hash entries have the same bfd. */
  1507. static int
  1508. elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2)
  1509. {
  1510. const struct elf_m68k_bfd2got_entry *e1;
  1511. const struct elf_m68k_bfd2got_entry *e2;
  1512. e1 = (const struct elf_m68k_bfd2got_entry *) entry1;
  1513. e2 = (const struct elf_m68k_bfd2got_entry *) entry2;
  1514. return e1->bfd == e2->bfd;
  1515. }
  1516. /* Destruct a bfd2got entry. */
  1517. static void
  1518. elf_m68k_bfd2got_entry_del (void *_entry)
  1519. {
  1520. struct elf_m68k_bfd2got_entry *entry;
  1521. entry = (struct elf_m68k_bfd2got_entry *) _entry;
  1522. BFD_ASSERT (entry->got != NULL);
  1523. elf_m68k_clear_got (entry->got);
  1524. }
  1525. /* Find existing or create new (depending on HOWTO) bfd2got entry in
  1526. MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
  1527. memory should be allocated. */
  1528. static struct elf_m68k_bfd2got_entry *
  1529. elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got,
  1530. const bfd *abfd,
  1531. enum elf_m68k_get_entry_howto howto,
  1532. struct bfd_link_info *info)
  1533. {
  1534. struct elf_m68k_bfd2got_entry entry_;
  1535. void **ptr;
  1536. struct elf_m68k_bfd2got_entry *entry;
  1537. BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
  1538. if (multi_got->bfd2got == NULL)
  1539. /* This is the first GOT. Initialize bfd2got. */
  1540. {
  1541. if (howto == SEARCH)
  1542. return NULL;
  1543. multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash,
  1544. elf_m68k_bfd2got_entry_eq,
  1545. elf_m68k_bfd2got_entry_del);
  1546. if (multi_got->bfd2got == NULL)
  1547. {
  1548. bfd_set_error (bfd_error_no_memory);
  1549. return NULL;
  1550. }
  1551. }
  1552. entry_.bfd = abfd;
  1553. ptr = htab_find_slot (multi_got->bfd2got, &entry_,
  1554. (howto == SEARCH || howto == MUST_FIND ? NO_INSERT
  1555. : INSERT));
  1556. if (ptr == NULL)
  1557. {
  1558. if (howto == SEARCH)
  1559. /* Entry not found. */
  1560. return NULL;
  1561. if (howto == MUST_FIND)
  1562. abort ();
  1563. /* We're out of memory. */
  1564. bfd_set_error (bfd_error_no_memory);
  1565. return NULL;
  1566. }
  1567. if (*ptr == NULL)
  1568. /* Entry was not found. Create new one. */
  1569. {
  1570. if (howto == MUST_FIND)
  1571. abort ();
  1572. BFD_ASSERT (howto != SEARCH);
  1573. entry = ((struct elf_m68k_bfd2got_entry *)
  1574. bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)));
  1575. if (entry == NULL)
  1576. return NULL;
  1577. entry->bfd = abfd;
  1578. entry->got = elf_m68k_create_empty_got (info);
  1579. if (entry->got == NULL)
  1580. return NULL;
  1581. *ptr = entry;
  1582. }
  1583. else
  1584. {
  1585. BFD_ASSERT (howto != MUST_CREATE);
  1586. /* Return existing entry. */
  1587. entry = *ptr;
  1588. }
  1589. return entry;
  1590. }
  1591. struct elf_m68k_can_merge_gots_arg
  1592. {
  1593. /* A current_got that we constructing a DIFF against. */
  1594. struct elf_m68k_got *big;
  1595. /* GOT holding entries not present or that should be changed in
  1596. BIG. */
  1597. struct elf_m68k_got *diff;
  1598. /* Context where to allocate memory. */
  1599. struct bfd_link_info *info;
  1600. /* Error flag. */
  1601. bool error_p;
  1602. };
  1603. /* Process a single entry from the small GOT to see if it should be added
  1604. or updated in the big GOT. */
  1605. static int
  1606. elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg)
  1607. {
  1608. const struct elf_m68k_got_entry *entry1;
  1609. struct elf_m68k_can_merge_gots_arg *arg;
  1610. const struct elf_m68k_got_entry *entry2;
  1611. enum elf_m68k_reloc_type type;
  1612. entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr;
  1613. arg = (struct elf_m68k_can_merge_gots_arg *) _arg;
  1614. entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL);
  1615. if (entry2 != NULL)
  1616. /* We found an existing entry. Check if we should update it. */
  1617. {
  1618. type = elf_m68k_update_got_entry_type (arg->diff,
  1619. entry2->key_.type,
  1620. entry1->key_.type);
  1621. if (type == entry2->key_.type)
  1622. /* ENTRY1 doesn't update data in ENTRY2. Skip it.
  1623. To skip creation of difference entry we use the type,
  1624. which we won't see in GOT entries for sure. */
  1625. type = R_68K_max;
  1626. }
  1627. else
  1628. /* We didn't find the entry. Add entry1 to DIFF. */
  1629. {
  1630. BFD_ASSERT (entry1->key_.type != R_68K_max);
  1631. type = elf_m68k_update_got_entry_type (arg->diff,
  1632. R_68K_max, entry1->key_.type);
  1633. if (entry1->key_.bfd != NULL)
  1634. arg->diff->local_n_slots += elf_m68k_reloc_got_n_slots (type);
  1635. }
  1636. if (type != R_68K_max)
  1637. /* Create an entry in DIFF. */
  1638. {
  1639. struct elf_m68k_got_entry *entry;
  1640. entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE,
  1641. arg->info);
  1642. if (entry == NULL)
  1643. {
  1644. arg->error_p = true;
  1645. return 0;
  1646. }
  1647. entry->key_.type = type;
  1648. }
  1649. return 1;
  1650. }
  1651. /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
  1652. Construct DIFF GOT holding the entries which should be added or updated
  1653. in BIG GOT to accumulate information from SMALL.
  1654. INFO is the context where memory should be allocated. */
  1655. static bool
  1656. elf_m68k_can_merge_gots (struct elf_m68k_got *big,
  1657. const struct elf_m68k_got *small,
  1658. struct bfd_link_info *info,
  1659. struct elf_m68k_got *diff)
  1660. {
  1661. struct elf_m68k_can_merge_gots_arg arg_;
  1662. BFD_ASSERT (small->offset == (bfd_vma) -1);
  1663. arg_.big = big;
  1664. arg_.diff = diff;
  1665. arg_.info = info;
  1666. arg_.error_p = false;
  1667. htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_);
  1668. if (arg_.error_p)
  1669. {
  1670. diff->offset = 0;
  1671. return false;
  1672. }
  1673. /* Check for overflow. */
  1674. if ((big->n_slots[R_8] + arg_.diff->n_slots[R_8]
  1675. > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
  1676. || (big->n_slots[R_16] + arg_.diff->n_slots[R_16]
  1677. > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
  1678. return false;
  1679. return true;
  1680. }
  1681. struct elf_m68k_merge_gots_arg
  1682. {
  1683. /* The BIG got. */
  1684. struct elf_m68k_got *big;
  1685. /* Context where memory should be allocated. */
  1686. struct bfd_link_info *info;
  1687. /* Error flag. */
  1688. bool error_p;
  1689. };
  1690. /* Process a single entry from DIFF got. Add or update corresponding
  1691. entry in the BIG got. */
  1692. static int
  1693. elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg)
  1694. {
  1695. const struct elf_m68k_got_entry *from;
  1696. struct elf_m68k_merge_gots_arg *arg;
  1697. struct elf_m68k_got_entry *to;
  1698. from = (const struct elf_m68k_got_entry *) *entry_ptr;
  1699. arg = (struct elf_m68k_merge_gots_arg *) _arg;
  1700. to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE,
  1701. arg->info);
  1702. if (to == NULL)
  1703. {
  1704. arg->error_p = true;
  1705. return 0;
  1706. }
  1707. BFD_ASSERT (to->u.s1.refcount == 0);
  1708. /* All we need to merge is TYPE. */
  1709. to->key_.type = from->key_.type;
  1710. return 1;
  1711. }
  1712. /* Merge data from DIFF to BIG. INFO is context where memory should be
  1713. allocated. */
  1714. static bool
  1715. elf_m68k_merge_gots (struct elf_m68k_got *big,
  1716. struct elf_m68k_got *diff,
  1717. struct bfd_link_info *info)
  1718. {
  1719. if (diff->entries != NULL)
  1720. /* DIFF is not empty. Merge it into BIG GOT. */
  1721. {
  1722. struct elf_m68k_merge_gots_arg arg_;
  1723. /* Merge entries. */
  1724. arg_.big = big;
  1725. arg_.info = info;
  1726. arg_.error_p = false;
  1727. htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_);
  1728. if (arg_.error_p)
  1729. return false;
  1730. /* Merge counters. */
  1731. big->n_slots[R_8] += diff->n_slots[R_8];
  1732. big->n_slots[R_16] += diff->n_slots[R_16];
  1733. big->n_slots[R_32] += diff->n_slots[R_32];
  1734. big->local_n_slots += diff->local_n_slots;
  1735. }
  1736. else
  1737. /* DIFF is empty. */
  1738. {
  1739. BFD_ASSERT (diff->n_slots[R_8] == 0);
  1740. BFD_ASSERT (diff->n_slots[R_16] == 0);
  1741. BFD_ASSERT (diff->n_slots[R_32] == 0);
  1742. BFD_ASSERT (diff->local_n_slots == 0);
  1743. }
  1744. BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p
  1745. || ((big->n_slots[R_8]
  1746. <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
  1747. && (big->n_slots[R_16]
  1748. <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))));
  1749. return true;
  1750. }
  1751. struct elf_m68k_finalize_got_offsets_arg
  1752. {
  1753. /* Ranges of the offsets for GOT entries.
  1754. R_x entries receive offsets between offset1[R_x] and offset2[R_x].
  1755. R_x is R_8, R_16 and R_32. */
  1756. bfd_vma *offset1;
  1757. bfd_vma *offset2;
  1758. /* Mapping from global symndx to global symbols.
  1759. This is used to build lists of got entries for global symbols. */
  1760. struct elf_m68k_link_hash_entry **symndx2h;
  1761. bfd_vma n_ldm_entries;
  1762. };
  1763. /* Assign ENTRY an offset. Build list of GOT entries for global symbols
  1764. along the way. */
  1765. static int
  1766. elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg)
  1767. {
  1768. struct elf_m68k_got_entry *entry;
  1769. struct elf_m68k_finalize_got_offsets_arg *arg;
  1770. enum elf_m68k_got_offset_size got_offset_size;
  1771. bfd_vma entry_size;
  1772. entry = (struct elf_m68k_got_entry *) *entry_ptr;
  1773. arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg;
  1774. /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
  1775. BFD_ASSERT (entry->u.s1.refcount == 0);
  1776. /* Get GOT offset size for the entry . */
  1777. got_offset_size = elf_m68k_reloc_got_offset_size (entry->key_.type);
  1778. /* Calculate entry size in bytes. */
  1779. entry_size = 4 * elf_m68k_reloc_got_n_slots (entry->key_.type);
  1780. /* Check if we should switch to negative range of the offsets. */
  1781. if (arg->offset1[got_offset_size] + entry_size
  1782. > arg->offset2[got_offset_size])
  1783. {
  1784. /* Verify that this is the only switch to negative range for
  1785. got_offset_size. If this assertion fails, then we've miscalculated
  1786. range for got_offset_size entries in
  1787. elf_m68k_finalize_got_offsets. */
  1788. BFD_ASSERT (arg->offset2[got_offset_size]
  1789. != arg->offset2[-(int) got_offset_size - 1]);
  1790. /* Switch. */
  1791. arg->offset1[got_offset_size] = arg->offset1[-(int) got_offset_size - 1];
  1792. arg->offset2[got_offset_size] = arg->offset2[-(int) got_offset_size - 1];
  1793. /* Verify that now we have enough room for the entry. */
  1794. BFD_ASSERT (arg->offset1[got_offset_size] + entry_size
  1795. <= arg->offset2[got_offset_size]);
  1796. }
  1797. /* Assign offset to entry. */
  1798. entry->u.s2.offset = arg->offset1[got_offset_size];
  1799. arg->offset1[got_offset_size] += entry_size;
  1800. if (entry->key_.bfd == NULL)
  1801. /* Hook up this entry into the list of got_entries of H. */
  1802. {
  1803. struct elf_m68k_link_hash_entry *h;
  1804. h = arg->symndx2h[entry->key_.symndx];
  1805. if (h != NULL)
  1806. {
  1807. entry->u.s2.next = h->glist;
  1808. h->glist = entry;
  1809. }
  1810. else
  1811. /* This should be the entry for TLS_LDM relocation then. */
  1812. {
  1813. BFD_ASSERT ((elf_m68k_reloc_got_type (entry->key_.type)
  1814. == R_68K_TLS_LDM32)
  1815. && entry->key_.symndx == 0);
  1816. ++arg->n_ldm_entries;
  1817. }
  1818. }
  1819. else
  1820. /* This entry is for local symbol. */
  1821. entry->u.s2.next = NULL;
  1822. return 1;
  1823. }
  1824. /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
  1825. should use negative offsets.
  1826. Build list of GOT entries for global symbols along the way.
  1827. SYMNDX2H is mapping from global symbol indices to actual
  1828. global symbols.
  1829. Return offset at which next GOT should start. */
  1830. static void
  1831. elf_m68k_finalize_got_offsets (struct elf_m68k_got *got,
  1832. bool use_neg_got_offsets_p,
  1833. struct elf_m68k_link_hash_entry **symndx2h,
  1834. bfd_vma *final_offset, bfd_vma *n_ldm_entries)
  1835. {
  1836. struct elf_m68k_finalize_got_offsets_arg arg_;
  1837. bfd_vma offset1_[2 * R_LAST];
  1838. bfd_vma offset2_[2 * R_LAST];
  1839. int i;
  1840. bfd_vma start_offset;
  1841. BFD_ASSERT (got->offset != (bfd_vma) -1);
  1842. /* We set entry offsets relative to the .got section (and not the
  1843. start of a particular GOT), so that we can use them in
  1844. finish_dynamic_symbol without needing to know the GOT which they come
  1845. from. */
  1846. /* Put offset1 in the middle of offset1_, same for offset2. */
  1847. arg_.offset1 = offset1_ + R_LAST;
  1848. arg_.offset2 = offset2_ + R_LAST;
  1849. start_offset = got->offset;
  1850. if (use_neg_got_offsets_p)
  1851. /* Setup both negative and positive ranges for R_8, R_16 and R_32. */
  1852. i = -(int) R_32 - 1;
  1853. else
  1854. /* Setup positives ranges for R_8, R_16 and R_32. */
  1855. i = (int) R_8;
  1856. for (; i <= (int) R_32; ++i)
  1857. {
  1858. int j;
  1859. size_t n;
  1860. /* Set beginning of the range of offsets I. */
  1861. arg_.offset1[i] = start_offset;
  1862. /* Calculate number of slots that require I offsets. */
  1863. j = (i >= 0) ? i : -i - 1;
  1864. n = (j >= 1) ? got->n_slots[j - 1] : 0;
  1865. n = got->n_slots[j] - n;
  1866. if (use_neg_got_offsets_p && n != 0)
  1867. {
  1868. if (i < 0)
  1869. /* We first fill the positive side of the range, so we might
  1870. end up with one empty slot at that side when we can't fit
  1871. whole 2-slot entry. Account for that at negative side of
  1872. the interval with one additional entry. */
  1873. n = n / 2 + 1;
  1874. else
  1875. /* When the number of slots is odd, make positive side of the
  1876. range one entry bigger. */
  1877. n = (n + 1) / 2;
  1878. }
  1879. /* N is the number of slots that require I offsets.
  1880. Calculate length of the range for I offsets. */
  1881. n = 4 * n;
  1882. /* Set end of the range. */
  1883. arg_.offset2[i] = start_offset + n;
  1884. start_offset = arg_.offset2[i];
  1885. }
  1886. if (!use_neg_got_offsets_p)
  1887. /* Make sure that if we try to switch to negative offsets in
  1888. elf_m68k_finalize_got_offsets_1, the assert therein will catch
  1889. the bug. */
  1890. for (i = R_8; i <= R_32; ++i)
  1891. arg_.offset2[-i - 1] = arg_.offset2[i];
  1892. /* Setup got->offset. offset1[R_8] is either in the middle or at the
  1893. beginning of GOT depending on use_neg_got_offsets_p. */
  1894. got->offset = arg_.offset1[R_8];
  1895. arg_.symndx2h = symndx2h;
  1896. arg_.n_ldm_entries = 0;
  1897. /* Assign offsets. */
  1898. htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_);
  1899. /* Check offset ranges we have actually assigned. */
  1900. for (i = (int) R_8; i <= (int) R_32; ++i)
  1901. BFD_ASSERT (arg_.offset2[i] - arg_.offset1[i] <= 4);
  1902. *final_offset = start_offset;
  1903. *n_ldm_entries = arg_.n_ldm_entries;
  1904. }
  1905. struct elf_m68k_partition_multi_got_arg
  1906. {
  1907. /* The GOT we are adding entries to. Aka big got. */
  1908. struct elf_m68k_got *current_got;
  1909. /* Offset to assign the next CURRENT_GOT. */
  1910. bfd_vma offset;
  1911. /* Context where memory should be allocated. */
  1912. struct bfd_link_info *info;
  1913. /* Total number of slots in the .got section.
  1914. This is used to calculate size of the .got and .rela.got sections. */
  1915. bfd_vma n_slots;
  1916. /* Difference in numbers of allocated slots in the .got section
  1917. and necessary relocations in the .rela.got section.
  1918. This is used to calculate size of the .rela.got section. */
  1919. bfd_vma slots_relas_diff;
  1920. /* Error flag. */
  1921. bool error_p;
  1922. /* Mapping from global symndx to global symbols.
  1923. This is used to build lists of got entries for global symbols. */
  1924. struct elf_m68k_link_hash_entry **symndx2h;
  1925. };
  1926. static void
  1927. elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg)
  1928. {
  1929. bfd_vma n_ldm_entries;
  1930. elf_m68k_finalize_got_offsets (arg->current_got,
  1931. (elf_m68k_hash_table (arg->info)
  1932. ->use_neg_got_offsets_p),
  1933. arg->symndx2h,
  1934. &arg->offset, &n_ldm_entries);
  1935. arg->n_slots += arg->current_got->n_slots[R_32];
  1936. if (!bfd_link_pic (arg->info))
  1937. /* If we are generating a shared object, we need to
  1938. output a R_68K_RELATIVE reloc so that the dynamic
  1939. linker can adjust this GOT entry. Overwise we
  1940. don't need space in .rela.got for local symbols. */
  1941. arg->slots_relas_diff += arg->current_got->local_n_slots;
  1942. /* @LDM relocations require a 2-slot GOT entry, but only
  1943. one relocation. Account for that. */
  1944. arg->slots_relas_diff += n_ldm_entries;
  1945. BFD_ASSERT (arg->slots_relas_diff <= arg->n_slots);
  1946. }
  1947. /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
  1948. or start a new CURRENT_GOT. */
  1949. static int
  1950. elf_m68k_partition_multi_got_1 (void **_entry, void *_arg)
  1951. {
  1952. struct elf_m68k_bfd2got_entry *entry;
  1953. struct elf_m68k_partition_multi_got_arg *arg;
  1954. struct elf_m68k_got *got;
  1955. struct elf_m68k_got diff_;
  1956. struct elf_m68k_got *diff;
  1957. entry = (struct elf_m68k_bfd2got_entry *) *_entry;
  1958. arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
  1959. got = entry->got;
  1960. BFD_ASSERT (got != NULL);
  1961. BFD_ASSERT (got->offset == (bfd_vma) -1);
  1962. diff = NULL;
  1963. if (arg->current_got != NULL)
  1964. /* Construct diff. */
  1965. {
  1966. diff = &diff_;
  1967. elf_m68k_init_got (diff);
  1968. if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff))
  1969. {
  1970. if (diff->offset == 0)
  1971. /* Offset set to 0 in the diff_ indicates an error. */
  1972. {
  1973. arg->error_p = true;
  1974. goto final_return;
  1975. }
  1976. if (elf_m68k_hash_table (arg->info)->allow_multigot_p)
  1977. {
  1978. elf_m68k_clear_got (diff);
  1979. /* Schedule to finish up current_got and start new one. */
  1980. diff = NULL;
  1981. }
  1982. /* else
  1983. Merge GOTs no matter what. If big GOT overflows,
  1984. we'll fail in relocate_section due to truncated relocations.
  1985. ??? May be fail earlier? E.g., in can_merge_gots. */
  1986. }
  1987. }
  1988. else
  1989. /* Diff of got against empty current_got is got itself. */
  1990. {
  1991. /* Create empty current_got to put subsequent GOTs to. */
  1992. arg->current_got = elf_m68k_create_empty_got (arg->info);
  1993. if (arg->current_got == NULL)
  1994. {
  1995. arg->error_p = true;
  1996. goto final_return;
  1997. }
  1998. arg->current_got->offset = arg->offset;
  1999. diff = got;
  2000. }
  2001. if (diff != NULL)
  2002. {
  2003. if (!elf_m68k_merge_gots (arg->current_got, diff, arg->info))
  2004. {
  2005. arg->error_p = true;
  2006. goto final_return;
  2007. }
  2008. /* Now we can free GOT. */
  2009. elf_m68k_clear_got (got);
  2010. entry->got = arg->current_got;
  2011. }
  2012. else
  2013. {
  2014. /* Finish up current_got. */
  2015. elf_m68k_partition_multi_got_2 (arg);
  2016. /* Schedule to start a new current_got. */
  2017. arg->current_got = NULL;
  2018. /* Retry. */
  2019. if (!elf_m68k_partition_multi_got_1 (_entry, _arg))
  2020. {
  2021. BFD_ASSERT (arg->error_p);
  2022. goto final_return;
  2023. }
  2024. }
  2025. final_return:
  2026. if (diff != NULL)
  2027. elf_m68k_clear_got (diff);
  2028. return !arg->error_p;
  2029. }
  2030. /* Helper function to build symndx2h mapping. */
  2031. static bool
  2032. elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h,
  2033. void *_arg)
  2034. {
  2035. struct elf_m68k_link_hash_entry *h;
  2036. h = elf_m68k_hash_entry (_h);
  2037. if (h->got_entry_key != 0)
  2038. /* H has at least one entry in the GOT. */
  2039. {
  2040. struct elf_m68k_partition_multi_got_arg *arg;
  2041. arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
  2042. BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL);
  2043. arg->symndx2h[h->got_entry_key] = h;
  2044. }
  2045. return true;
  2046. }
  2047. /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
  2048. lists of GOT entries for global symbols.
  2049. Calculate sizes of .got and .rela.got sections. */
  2050. static bool
  2051. elf_m68k_partition_multi_got (struct bfd_link_info *info)
  2052. {
  2053. struct elf_m68k_multi_got *multi_got;
  2054. struct elf_m68k_partition_multi_got_arg arg_;
  2055. multi_got = elf_m68k_multi_got (info);
  2056. arg_.current_got = NULL;
  2057. arg_.offset = 0;
  2058. arg_.info = info;
  2059. arg_.n_slots = 0;
  2060. arg_.slots_relas_diff = 0;
  2061. arg_.error_p = false;
  2062. if (multi_got->bfd2got != NULL)
  2063. {
  2064. /* Initialize symndx2h mapping. */
  2065. {
  2066. arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx
  2067. * sizeof (*arg_.symndx2h));
  2068. if (arg_.symndx2h == NULL)
  2069. return false;
  2070. elf_link_hash_traverse (elf_hash_table (info),
  2071. elf_m68k_init_symndx2h_1, &arg_);
  2072. }
  2073. /* Partition. */
  2074. htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1,
  2075. &arg_);
  2076. if (arg_.error_p)
  2077. {
  2078. free (arg_.symndx2h);
  2079. arg_.symndx2h = NULL;
  2080. return false;
  2081. }
  2082. /* Finish up last current_got. */
  2083. elf_m68k_partition_multi_got_2 (&arg_);
  2084. free (arg_.symndx2h);
  2085. }
  2086. if (elf_hash_table (info)->dynobj != NULL)
  2087. /* Set sizes of .got and .rela.got sections. */
  2088. {
  2089. asection *s;
  2090. s = elf_hash_table (info)->sgot;
  2091. if (s != NULL)
  2092. s->size = arg_.offset;
  2093. else
  2094. BFD_ASSERT (arg_.offset == 0);
  2095. BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots);
  2096. arg_.n_slots -= arg_.slots_relas_diff;
  2097. s = elf_hash_table (info)->srelgot;
  2098. if (s != NULL)
  2099. s->size = arg_.n_slots * sizeof (Elf32_External_Rela);
  2100. else
  2101. BFD_ASSERT (arg_.n_slots == 0);
  2102. }
  2103. else
  2104. BFD_ASSERT (multi_got->bfd2got == NULL);
  2105. return true;
  2106. }
  2107. /* Copy any information related to dynamic linking from a pre-existing
  2108. symbol to a newly created symbol. Also called to copy flags and
  2109. other back-end info to a weakdef, in which case the symbol is not
  2110. newly created and plt/got refcounts and dynamic indices should not
  2111. be copied. */
  2112. static void
  2113. elf_m68k_copy_indirect_symbol (struct bfd_link_info *info,
  2114. struct elf_link_hash_entry *_dir,
  2115. struct elf_link_hash_entry *_ind)
  2116. {
  2117. struct elf_m68k_link_hash_entry *dir;
  2118. struct elf_m68k_link_hash_entry *ind;
  2119. _bfd_elf_link_hash_copy_indirect (info, _dir, _ind);
  2120. if (_ind->root.type != bfd_link_hash_indirect)
  2121. return;
  2122. dir = elf_m68k_hash_entry (_dir);
  2123. ind = elf_m68k_hash_entry (_ind);
  2124. /* Any absolute non-dynamic relocations against an indirect or weak
  2125. definition will be against the target symbol. */
  2126. _dir->non_got_ref |= _ind->non_got_ref;
  2127. /* We might have a direct symbol already having entries in the GOTs.
  2128. Update its key only in case indirect symbol has GOT entries and
  2129. assert that both indirect and direct symbols don't have GOT entries
  2130. at the same time. */
  2131. if (ind->got_entry_key != 0)
  2132. {
  2133. BFD_ASSERT (dir->got_entry_key == 0);
  2134. /* Assert that GOTs aren't partioned yet. */
  2135. BFD_ASSERT (ind->glist == NULL);
  2136. dir->got_entry_key = ind->got_entry_key;
  2137. ind->got_entry_key = 0;
  2138. }
  2139. }
  2140. /* Look through the relocs for a section during the first phase, and
  2141. allocate space in the global offset table or procedure linkage
  2142. table. */
  2143. static bool
  2144. elf_m68k_check_relocs (bfd *abfd,
  2145. struct bfd_link_info *info,
  2146. asection *sec,
  2147. const Elf_Internal_Rela *relocs)
  2148. {
  2149. bfd *dynobj;
  2150. Elf_Internal_Shdr *symtab_hdr;
  2151. struct elf_link_hash_entry **sym_hashes;
  2152. const Elf_Internal_Rela *rel;
  2153. const Elf_Internal_Rela *rel_end;
  2154. asection *sreloc;
  2155. struct elf_m68k_got *got;
  2156. if (bfd_link_relocatable (info))
  2157. return true;
  2158. dynobj = elf_hash_table (info)->dynobj;
  2159. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  2160. sym_hashes = elf_sym_hashes (abfd);
  2161. sreloc = NULL;
  2162. got = NULL;
  2163. rel_end = relocs + sec->reloc_count;
  2164. for (rel = relocs; rel < rel_end; rel++)
  2165. {
  2166. unsigned long r_symndx;
  2167. struct elf_link_hash_entry *h;
  2168. r_symndx = ELF32_R_SYM (rel->r_info);
  2169. if (r_symndx < symtab_hdr->sh_info)
  2170. h = NULL;
  2171. else
  2172. {
  2173. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  2174. while (h->root.type == bfd_link_hash_indirect
  2175. || h->root.type == bfd_link_hash_warning)
  2176. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  2177. }
  2178. switch (ELF32_R_TYPE (rel->r_info))
  2179. {
  2180. case R_68K_GOT8:
  2181. case R_68K_GOT16:
  2182. case R_68K_GOT32:
  2183. if (h != NULL
  2184. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  2185. break;
  2186. /* Fall through. */
  2187. /* Relative GOT relocations. */
  2188. case R_68K_GOT8O:
  2189. case R_68K_GOT16O:
  2190. case R_68K_GOT32O:
  2191. /* Fall through. */
  2192. /* TLS relocations. */
  2193. case R_68K_TLS_GD8:
  2194. case R_68K_TLS_GD16:
  2195. case R_68K_TLS_GD32:
  2196. case R_68K_TLS_LDM8:
  2197. case R_68K_TLS_LDM16:
  2198. case R_68K_TLS_LDM32:
  2199. case R_68K_TLS_IE8:
  2200. case R_68K_TLS_IE16:
  2201. case R_68K_TLS_IE32:
  2202. case R_68K_TLS_TPREL32:
  2203. case R_68K_TLS_DTPREL32:
  2204. if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32
  2205. && bfd_link_pic (info))
  2206. /* Do the special chorus for libraries with static TLS. */
  2207. info->flags |= DF_STATIC_TLS;
  2208. /* This symbol requires a global offset table entry. */
  2209. if (dynobj == NULL)
  2210. {
  2211. /* Create the .got section. */
  2212. elf_hash_table (info)->dynobj = dynobj = abfd;
  2213. if (!_bfd_elf_create_got_section (dynobj, info))
  2214. return false;
  2215. }
  2216. if (got == NULL)
  2217. {
  2218. struct elf_m68k_bfd2got_entry *bfd2got_entry;
  2219. bfd2got_entry
  2220. = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
  2221. abfd, FIND_OR_CREATE, info);
  2222. if (bfd2got_entry == NULL)
  2223. return false;
  2224. got = bfd2got_entry->got;
  2225. BFD_ASSERT (got != NULL);
  2226. }
  2227. {
  2228. struct elf_m68k_got_entry *got_entry;
  2229. /* Add entry to got. */
  2230. got_entry = elf_m68k_add_entry_to_got (got, h, abfd,
  2231. ELF32_R_TYPE (rel->r_info),
  2232. r_symndx, info);
  2233. if (got_entry == NULL)
  2234. return false;
  2235. if (got_entry->u.s1.refcount == 1)
  2236. {
  2237. /* Make sure this symbol is output as a dynamic symbol. */
  2238. if (h != NULL
  2239. && h->dynindx == -1
  2240. && !h->forced_local)
  2241. {
  2242. if (!bfd_elf_link_record_dynamic_symbol (info, h))
  2243. return false;
  2244. }
  2245. }
  2246. }
  2247. break;
  2248. case R_68K_PLT8:
  2249. case R_68K_PLT16:
  2250. case R_68K_PLT32:
  2251. /* This symbol requires a procedure linkage table entry. We
  2252. actually build the entry in adjust_dynamic_symbol,
  2253. because this might be a case of linking PIC code which is
  2254. never referenced by a dynamic object, in which case we
  2255. don't need to generate a procedure linkage table entry
  2256. after all. */
  2257. /* If this is a local symbol, we resolve it directly without
  2258. creating a procedure linkage table entry. */
  2259. if (h == NULL)
  2260. continue;
  2261. h->needs_plt = 1;
  2262. h->plt.refcount++;
  2263. break;
  2264. case R_68K_PLT8O:
  2265. case R_68K_PLT16O:
  2266. case R_68K_PLT32O:
  2267. /* This symbol requires a procedure linkage table entry. */
  2268. if (h == NULL)
  2269. {
  2270. /* It does not make sense to have this relocation for a
  2271. local symbol. FIXME: does it? How to handle it if
  2272. it does make sense? */
  2273. bfd_set_error (bfd_error_bad_value);
  2274. return false;
  2275. }
  2276. /* Make sure this symbol is output as a dynamic symbol. */
  2277. if (h->dynindx == -1
  2278. && !h->forced_local)
  2279. {
  2280. if (!bfd_elf_link_record_dynamic_symbol (info, h))
  2281. return false;
  2282. }
  2283. h->needs_plt = 1;
  2284. h->plt.refcount++;
  2285. break;
  2286. case R_68K_PC8:
  2287. case R_68K_PC16:
  2288. case R_68K_PC32:
  2289. /* If we are creating a shared library and this is not a local
  2290. symbol, we need to copy the reloc into the shared library.
  2291. However when linking with -Bsymbolic and this is a global
  2292. symbol which is defined in an object we are including in the
  2293. link (i.e., DEF_REGULAR is set), then we can resolve the
  2294. reloc directly. At this point we have not seen all the input
  2295. files, so it is possible that DEF_REGULAR is not set now but
  2296. will be set later (it is never cleared). We account for that
  2297. possibility below by storing information in the
  2298. pcrel_relocs_copied field of the hash table entry. */
  2299. if (!(bfd_link_pic (info)
  2300. && (sec->flags & SEC_ALLOC) != 0
  2301. && h != NULL
  2302. && (!SYMBOLIC_BIND (info, h)
  2303. || h->root.type == bfd_link_hash_defweak
  2304. || !h->def_regular)))
  2305. {
  2306. if (h != NULL)
  2307. {
  2308. /* Make sure a plt entry is created for this symbol if
  2309. it turns out to be a function defined by a dynamic
  2310. object. */
  2311. h->plt.refcount++;
  2312. }
  2313. break;
  2314. }
  2315. /* Fall through. */
  2316. case R_68K_8:
  2317. case R_68K_16:
  2318. case R_68K_32:
  2319. /* We don't need to handle relocs into sections not going into
  2320. the "real" output. */
  2321. if ((sec->flags & SEC_ALLOC) == 0)
  2322. break;
  2323. if (h != NULL)
  2324. {
  2325. /* Make sure a plt entry is created for this symbol if it
  2326. turns out to be a function defined by a dynamic object. */
  2327. h->plt.refcount++;
  2328. if (bfd_link_executable (info))
  2329. /* This symbol needs a non-GOT reference. */
  2330. h->non_got_ref = 1;
  2331. }
  2332. /* If we are creating a shared library, we need to copy the
  2333. reloc into the shared library. */
  2334. if (bfd_link_pic (info)
  2335. && (h == NULL
  2336. || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)))
  2337. {
  2338. /* When creating a shared object, we must copy these
  2339. reloc types into the output file. We create a reloc
  2340. section in dynobj and make room for this reloc. */
  2341. if (sreloc == NULL)
  2342. {
  2343. sreloc = _bfd_elf_make_dynamic_reloc_section
  2344. (sec, dynobj, 2, abfd, /*rela?*/ true);
  2345. if (sreloc == NULL)
  2346. return false;
  2347. }
  2348. if (sec->flags & SEC_READONLY
  2349. /* Don't set DF_TEXTREL yet for PC relative
  2350. relocations, they might be discarded later. */
  2351. && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
  2352. || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
  2353. || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
  2354. info->flags |= DF_TEXTREL;
  2355. sreloc->size += sizeof (Elf32_External_Rela);
  2356. /* We count the number of PC relative relocations we have
  2357. entered for this symbol, so that we can discard them
  2358. again if, in the -Bsymbolic case, the symbol is later
  2359. defined by a regular object, or, in the normal shared
  2360. case, the symbol is forced to be local. Note that this
  2361. function is only called if we are using an m68kelf linker
  2362. hash table, which means that h is really a pointer to an
  2363. elf_m68k_link_hash_entry. */
  2364. if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
  2365. || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
  2366. || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
  2367. {
  2368. struct elf_m68k_pcrel_relocs_copied *p;
  2369. struct elf_m68k_pcrel_relocs_copied **head;
  2370. if (h != NULL)
  2371. {
  2372. struct elf_m68k_link_hash_entry *eh
  2373. = elf_m68k_hash_entry (h);
  2374. head = &eh->pcrel_relocs_copied;
  2375. }
  2376. else
  2377. {
  2378. asection *s;
  2379. void *vpp;
  2380. Elf_Internal_Sym *isym;
  2381. isym = bfd_sym_from_r_symndx (&elf_m68k_hash_table (info)->root.sym_cache,
  2382. abfd, r_symndx);
  2383. if (isym == NULL)
  2384. return false;
  2385. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  2386. if (s == NULL)
  2387. s = sec;
  2388. vpp = &elf_section_data (s)->local_dynrel;
  2389. head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
  2390. }
  2391. for (p = *head; p != NULL; p = p->next)
  2392. if (p->section == sreloc)
  2393. break;
  2394. if (p == NULL)
  2395. {
  2396. p = ((struct elf_m68k_pcrel_relocs_copied *)
  2397. bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
  2398. if (p == NULL)
  2399. return false;
  2400. p->next = *head;
  2401. *head = p;
  2402. p->section = sreloc;
  2403. p->count = 0;
  2404. }
  2405. ++p->count;
  2406. }
  2407. }
  2408. break;
  2409. /* This relocation describes the C++ object vtable hierarchy.
  2410. Reconstruct it for later use during GC. */
  2411. case R_68K_GNU_VTINHERIT:
  2412. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  2413. return false;
  2414. break;
  2415. /* This relocation describes which C++ vtable entries are actually
  2416. used. Record for later use during GC. */
  2417. case R_68K_GNU_VTENTRY:
  2418. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  2419. return false;
  2420. break;
  2421. default:
  2422. break;
  2423. }
  2424. }
  2425. return true;
  2426. }
  2427. /* Return the section that should be marked against GC for a given
  2428. relocation. */
  2429. static asection *
  2430. elf_m68k_gc_mark_hook (asection *sec,
  2431. struct bfd_link_info *info,
  2432. Elf_Internal_Rela *rel,
  2433. struct elf_link_hash_entry *h,
  2434. Elf_Internal_Sym *sym)
  2435. {
  2436. if (h != NULL)
  2437. switch (ELF32_R_TYPE (rel->r_info))
  2438. {
  2439. case R_68K_GNU_VTINHERIT:
  2440. case R_68K_GNU_VTENTRY:
  2441. return NULL;
  2442. }
  2443. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  2444. }
  2445. /* Return the type of PLT associated with OUTPUT_BFD. */
  2446. static const struct elf_m68k_plt_info *
  2447. elf_m68k_get_plt_info (bfd *output_bfd)
  2448. {
  2449. unsigned int features;
  2450. features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
  2451. if (features & cpu32)
  2452. return &elf_cpu32_plt_info;
  2453. if (features & mcfisa_b)
  2454. return &elf_isab_plt_info;
  2455. if (features & mcfisa_c)
  2456. return &elf_isac_plt_info;
  2457. return &elf_m68k_plt_info;
  2458. }
  2459. /* This function is called after all the input files have been read,
  2460. and the input sections have been assigned to output sections.
  2461. It's a convenient place to determine the PLT style. */
  2462. static bool
  2463. elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
  2464. {
  2465. /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
  2466. sections. */
  2467. if (!elf_m68k_partition_multi_got (info))
  2468. return false;
  2469. elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
  2470. return true;
  2471. }
  2472. /* Adjust a symbol defined by a dynamic object and referenced by a
  2473. regular object. The current definition is in some section of the
  2474. dynamic object, but we're not including those sections. We have to
  2475. change the definition to something the rest of the link can
  2476. understand. */
  2477. static bool
  2478. elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info,
  2479. struct elf_link_hash_entry *h)
  2480. {
  2481. struct elf_m68k_link_hash_table *htab;
  2482. bfd *dynobj;
  2483. asection *s;
  2484. htab = elf_m68k_hash_table (info);
  2485. dynobj = htab->root.dynobj;
  2486. /* Make sure we know what is going on here. */
  2487. BFD_ASSERT (dynobj != NULL
  2488. && (h->needs_plt
  2489. || h->is_weakalias
  2490. || (h->def_dynamic
  2491. && h->ref_regular
  2492. && !h->def_regular)));
  2493. /* If this is a function, put it in the procedure linkage table. We
  2494. will fill in the contents of the procedure linkage table later,
  2495. when we know the address of the .got section. */
  2496. if (h->type == STT_FUNC
  2497. || h->needs_plt)
  2498. {
  2499. if ((h->plt.refcount <= 0
  2500. || SYMBOL_CALLS_LOCAL (info, h)
  2501. || ((ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  2502. || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  2503. && h->root.type == bfd_link_hash_undefweak))
  2504. /* We must always create the plt entry if it was referenced
  2505. by a PLTxxO relocation. In this case we already recorded
  2506. it as a dynamic symbol. */
  2507. && h->dynindx == -1)
  2508. {
  2509. /* This case can occur if we saw a PLTxx reloc in an input
  2510. file, but the symbol was never referred to by a dynamic
  2511. object, or if all references were garbage collected. In
  2512. such a case, we don't actually need to build a procedure
  2513. linkage table, and we can just do a PCxx reloc instead. */
  2514. h->plt.offset = (bfd_vma) -1;
  2515. h->needs_plt = 0;
  2516. return true;
  2517. }
  2518. /* Make sure this symbol is output as a dynamic symbol. */
  2519. if (h->dynindx == -1
  2520. && !h->forced_local)
  2521. {
  2522. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2523. return false;
  2524. }
  2525. s = htab->root.splt;
  2526. BFD_ASSERT (s != NULL);
  2527. /* If this is the first .plt entry, make room for the special
  2528. first entry. */
  2529. if (s->size == 0)
  2530. s->size = htab->plt_info->size;
  2531. /* If this symbol is not defined in a regular file, and we are
  2532. not generating a shared library, then set the symbol to this
  2533. location in the .plt. This is required to make function
  2534. pointers compare as equal between the normal executable and
  2535. the shared library. */
  2536. if (!bfd_link_pic (info)
  2537. && !h->def_regular)
  2538. {
  2539. h->root.u.def.section = s;
  2540. h->root.u.def.value = s->size;
  2541. }
  2542. h->plt.offset = s->size;
  2543. /* Make room for this entry. */
  2544. s->size += htab->plt_info->size;
  2545. /* We also need to make an entry in the .got.plt section, which
  2546. will be placed in the .got section by the linker script. */
  2547. s = htab->root.sgotplt;
  2548. BFD_ASSERT (s != NULL);
  2549. s->size += 4;
  2550. /* We also need to make an entry in the .rela.plt section. */
  2551. s = htab->root.srelplt;
  2552. BFD_ASSERT (s != NULL);
  2553. s->size += sizeof (Elf32_External_Rela);
  2554. return true;
  2555. }
  2556. /* Reinitialize the plt offset now that it is not used as a reference
  2557. count any more. */
  2558. h->plt.offset = (bfd_vma) -1;
  2559. /* If this is a weak symbol, and there is a real definition, the
  2560. processor independent code will have arranged for us to see the
  2561. real definition first, and we can just use the same value. */
  2562. if (h->is_weakalias)
  2563. {
  2564. struct elf_link_hash_entry *def = weakdef (h);
  2565. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  2566. h->root.u.def.section = def->root.u.def.section;
  2567. h->root.u.def.value = def->root.u.def.value;
  2568. return true;
  2569. }
  2570. /* This is a reference to a symbol defined by a dynamic object which
  2571. is not a function. */
  2572. /* If we are creating a shared library, we must presume that the
  2573. only references to the symbol are via the global offset table.
  2574. For such cases we need not do anything here; the relocations will
  2575. be handled correctly by relocate_section. */
  2576. if (bfd_link_pic (info))
  2577. return true;
  2578. /* If there are no references to this symbol that do not use the
  2579. GOT, we don't need to generate a copy reloc. */
  2580. if (!h->non_got_ref)
  2581. return true;
  2582. /* We must allocate the symbol in our .dynbss section, which will
  2583. become part of the .bss section of the executable. There will be
  2584. an entry for this symbol in the .dynsym section. The dynamic
  2585. object will contain position independent code, so all references
  2586. from the dynamic object to this symbol will go through the global
  2587. offset table. The dynamic linker will use the .dynsym entry to
  2588. determine the address it must put in the global offset table, so
  2589. both the dynamic object and the regular object will refer to the
  2590. same memory location for the variable. */
  2591. s = bfd_get_linker_section (dynobj, ".dynbss");
  2592. BFD_ASSERT (s != NULL);
  2593. /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
  2594. copy the initial value out of the dynamic object and into the
  2595. runtime process image. We need to remember the offset into the
  2596. .rela.bss section we are going to use. */
  2597. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  2598. {
  2599. asection *srel;
  2600. srel = bfd_get_linker_section (dynobj, ".rela.bss");
  2601. BFD_ASSERT (srel != NULL);
  2602. srel->size += sizeof (Elf32_External_Rela);
  2603. h->needs_copy = 1;
  2604. }
  2605. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  2606. }
  2607. /* Set the sizes of the dynamic sections. */
  2608. static bool
  2609. elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  2610. struct bfd_link_info *info)
  2611. {
  2612. bfd *dynobj;
  2613. asection *s;
  2614. bool relocs;
  2615. dynobj = elf_hash_table (info)->dynobj;
  2616. BFD_ASSERT (dynobj != NULL);
  2617. if (elf_hash_table (info)->dynamic_sections_created)
  2618. {
  2619. /* Set the contents of the .interp section to the interpreter. */
  2620. if (bfd_link_executable (info) && !info->nointerp)
  2621. {
  2622. s = bfd_get_linker_section (dynobj, ".interp");
  2623. BFD_ASSERT (s != NULL);
  2624. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  2625. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  2626. }
  2627. }
  2628. else
  2629. {
  2630. /* We may have created entries in the .rela.got section.
  2631. However, if we are not creating the dynamic sections, we will
  2632. not actually use these entries. Reset the size of .rela.got,
  2633. which will cause it to get stripped from the output file
  2634. below. */
  2635. s = elf_hash_table (info)->srelgot;
  2636. if (s != NULL)
  2637. s->size = 0;
  2638. }
  2639. /* If this is a -Bsymbolic shared link, then we need to discard all
  2640. PC relative relocs against symbols defined in a regular object.
  2641. For the normal shared case we discard the PC relative relocs
  2642. against symbols that have become local due to visibility changes.
  2643. We allocated space for them in the check_relocs routine, but we
  2644. will not fill them in in the relocate_section routine. */
  2645. if (bfd_link_pic (info))
  2646. elf_link_hash_traverse (elf_hash_table (info),
  2647. elf_m68k_discard_copies,
  2648. info);
  2649. /* The check_relocs and adjust_dynamic_symbol entry points have
  2650. determined the sizes of the various dynamic sections. Allocate
  2651. memory for them. */
  2652. relocs = false;
  2653. for (s = dynobj->sections; s != NULL; s = s->next)
  2654. {
  2655. const char *name;
  2656. if ((s->flags & SEC_LINKER_CREATED) == 0)
  2657. continue;
  2658. /* It's OK to base decisions on the section name, because none
  2659. of the dynobj section names depend upon the input files. */
  2660. name = bfd_section_name (s);
  2661. if (strcmp (name, ".plt") == 0)
  2662. {
  2663. /* Remember whether there is a PLT. */
  2664. ;
  2665. }
  2666. else if (startswith (name, ".rela"))
  2667. {
  2668. if (s->size != 0)
  2669. {
  2670. relocs = true;
  2671. /* We use the reloc_count field as a counter if we need
  2672. to copy relocs into the output file. */
  2673. s->reloc_count = 0;
  2674. }
  2675. }
  2676. else if (! startswith (name, ".got")
  2677. && strcmp (name, ".dynbss") != 0)
  2678. {
  2679. /* It's not one of our sections, so don't allocate space. */
  2680. continue;
  2681. }
  2682. if (s->size == 0)
  2683. {
  2684. /* If we don't need this section, strip it from the
  2685. output file. This is mostly to handle .rela.bss and
  2686. .rela.plt. We must create both sections in
  2687. create_dynamic_sections, because they must be created
  2688. before the linker maps input sections to output
  2689. sections. The linker does that before
  2690. adjust_dynamic_symbol is called, and it is that
  2691. function which decides whether anything needs to go
  2692. into these sections. */
  2693. s->flags |= SEC_EXCLUDE;
  2694. continue;
  2695. }
  2696. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  2697. continue;
  2698. /* Allocate memory for the section contents. */
  2699. /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
  2700. Unused entries should be reclaimed before the section's contents
  2701. are written out, but at the moment this does not happen. Thus in
  2702. order to prevent writing out garbage, we initialise the section's
  2703. contents to zero. */
  2704. s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
  2705. if (s->contents == NULL)
  2706. return false;
  2707. }
  2708. return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
  2709. }
  2710. /* This function is called via elf_link_hash_traverse if we are
  2711. creating a shared object. In the -Bsymbolic case it discards the
  2712. space allocated to copy PC relative relocs against symbols which
  2713. are defined in regular objects. For the normal shared case, it
  2714. discards space for pc-relative relocs that have become local due to
  2715. symbol visibility changes. We allocated space for them in the
  2716. check_relocs routine, but we won't fill them in in the
  2717. relocate_section routine.
  2718. We also check whether any of the remaining relocations apply
  2719. against a readonly section, and set the DF_TEXTREL flag in this
  2720. case. */
  2721. static bool
  2722. elf_m68k_discard_copies (struct elf_link_hash_entry *h,
  2723. void * inf)
  2724. {
  2725. struct bfd_link_info *info = (struct bfd_link_info *) inf;
  2726. struct elf_m68k_pcrel_relocs_copied *s;
  2727. if (!SYMBOL_CALLS_LOCAL (info, h))
  2728. {
  2729. if ((info->flags & DF_TEXTREL) == 0)
  2730. {
  2731. /* Look for relocations against read-only sections. */
  2732. for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
  2733. s != NULL;
  2734. s = s->next)
  2735. if ((s->section->flags & SEC_READONLY) != 0)
  2736. {
  2737. info->flags |= DF_TEXTREL;
  2738. break;
  2739. }
  2740. }
  2741. /* Make sure undefined weak symbols are output as a dynamic symbol
  2742. in PIEs. */
  2743. if (h->non_got_ref
  2744. && h->root.type == bfd_link_hash_undefweak
  2745. && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  2746. && h->dynindx == -1
  2747. && !h->forced_local)
  2748. {
  2749. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2750. return false;
  2751. }
  2752. return true;
  2753. }
  2754. for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
  2755. s != NULL;
  2756. s = s->next)
  2757. s->section->size -= s->count * sizeof (Elf32_External_Rela);
  2758. return true;
  2759. }
  2760. /* Install relocation RELA. */
  2761. static void
  2762. elf_m68k_install_rela (bfd *output_bfd,
  2763. asection *srela,
  2764. Elf_Internal_Rela *rela)
  2765. {
  2766. bfd_byte *loc;
  2767. loc = srela->contents;
  2768. loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
  2769. bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
  2770. }
  2771. /* Find the base offsets for thread-local storage in this object,
  2772. for GD/LD and IE/LE respectively. */
  2773. #define DTP_OFFSET 0x8000
  2774. #define TP_OFFSET 0x7000
  2775. static bfd_vma
  2776. dtpoff_base (struct bfd_link_info *info)
  2777. {
  2778. /* If tls_sec is NULL, we should have signalled an error already. */
  2779. if (elf_hash_table (info)->tls_sec == NULL)
  2780. return 0;
  2781. return elf_hash_table (info)->tls_sec->vma + DTP_OFFSET;
  2782. }
  2783. static bfd_vma
  2784. tpoff_base (struct bfd_link_info *info)
  2785. {
  2786. /* If tls_sec is NULL, we should have signalled an error already. */
  2787. if (elf_hash_table (info)->tls_sec == NULL)
  2788. return 0;
  2789. return elf_hash_table (info)->tls_sec->vma + TP_OFFSET;
  2790. }
  2791. /* Output necessary relocation to handle a symbol during static link.
  2792. This function is called from elf_m68k_relocate_section. */
  2793. static void
  2794. elf_m68k_init_got_entry_static (struct bfd_link_info *info,
  2795. bfd *output_bfd,
  2796. enum elf_m68k_reloc_type r_type,
  2797. asection *sgot,
  2798. bfd_vma got_entry_offset,
  2799. bfd_vma relocation)
  2800. {
  2801. switch (elf_m68k_reloc_got_type (r_type))
  2802. {
  2803. case R_68K_GOT32O:
  2804. bfd_put_32 (output_bfd, relocation, sgot->contents + got_entry_offset);
  2805. break;
  2806. case R_68K_TLS_GD32:
  2807. /* We know the offset within the module,
  2808. put it into the second GOT slot. */
  2809. bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
  2810. sgot->contents + got_entry_offset + 4);
  2811. /* FALLTHRU */
  2812. case R_68K_TLS_LDM32:
  2813. /* Mark it as belonging to module 1, the executable. */
  2814. bfd_put_32 (output_bfd, 1, sgot->contents + got_entry_offset);
  2815. break;
  2816. case R_68K_TLS_IE32:
  2817. bfd_put_32 (output_bfd, relocation - tpoff_base (info),
  2818. sgot->contents + got_entry_offset);
  2819. break;
  2820. default:
  2821. BFD_ASSERT (false);
  2822. }
  2823. }
  2824. /* Output necessary relocation to handle a local symbol
  2825. during dynamic link.
  2826. This function is called either from elf_m68k_relocate_section
  2827. or from elf_m68k_finish_dynamic_symbol. */
  2828. static void
  2829. elf_m68k_init_got_entry_local_shared (struct bfd_link_info *info,
  2830. bfd *output_bfd,
  2831. enum elf_m68k_reloc_type r_type,
  2832. asection *sgot,
  2833. bfd_vma got_entry_offset,
  2834. bfd_vma relocation,
  2835. asection *srela)
  2836. {
  2837. Elf_Internal_Rela outrel;
  2838. switch (elf_m68k_reloc_got_type (r_type))
  2839. {
  2840. case R_68K_GOT32O:
  2841. /* Emit RELATIVE relocation to initialize GOT slot
  2842. at run-time. */
  2843. outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
  2844. outrel.r_addend = relocation;
  2845. break;
  2846. case R_68K_TLS_GD32:
  2847. /* We know the offset within the module,
  2848. put it into the second GOT slot. */
  2849. bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
  2850. sgot->contents + got_entry_offset + 4);
  2851. /* FALLTHRU */
  2852. case R_68K_TLS_LDM32:
  2853. /* We don't know the module number,
  2854. create a relocation for it. */
  2855. outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32);
  2856. outrel.r_addend = 0;
  2857. break;
  2858. case R_68K_TLS_IE32:
  2859. /* Emit TPREL relocation to initialize GOT slot
  2860. at run-time. */
  2861. outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32);
  2862. outrel.r_addend = relocation - elf_hash_table (info)->tls_sec->vma;
  2863. break;
  2864. default:
  2865. BFD_ASSERT (false);
  2866. }
  2867. /* Offset of the GOT entry. */
  2868. outrel.r_offset = (sgot->output_section->vma
  2869. + sgot->output_offset
  2870. + got_entry_offset);
  2871. /* Install one of the above relocations. */
  2872. elf_m68k_install_rela (output_bfd, srela, &outrel);
  2873. bfd_put_32 (output_bfd, outrel.r_addend, sgot->contents + got_entry_offset);
  2874. }
  2875. /* Relocate an M68K ELF section. */
  2876. static int
  2877. elf_m68k_relocate_section (bfd *output_bfd,
  2878. struct bfd_link_info *info,
  2879. bfd *input_bfd,
  2880. asection *input_section,
  2881. bfd_byte *contents,
  2882. Elf_Internal_Rela *relocs,
  2883. Elf_Internal_Sym *local_syms,
  2884. asection **local_sections)
  2885. {
  2886. Elf_Internal_Shdr *symtab_hdr;
  2887. struct elf_link_hash_entry **sym_hashes;
  2888. asection *sgot;
  2889. asection *splt;
  2890. asection *sreloc;
  2891. asection *srela;
  2892. struct elf_m68k_got *got;
  2893. Elf_Internal_Rela *rel;
  2894. Elf_Internal_Rela *relend;
  2895. symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  2896. sym_hashes = elf_sym_hashes (input_bfd);
  2897. sgot = NULL;
  2898. splt = NULL;
  2899. sreloc = NULL;
  2900. srela = NULL;
  2901. got = NULL;
  2902. rel = relocs;
  2903. relend = relocs + input_section->reloc_count;
  2904. for (; rel < relend; rel++)
  2905. {
  2906. int r_type;
  2907. reloc_howto_type *howto;
  2908. unsigned long r_symndx;
  2909. struct elf_link_hash_entry *h;
  2910. Elf_Internal_Sym *sym;
  2911. asection *sec;
  2912. bfd_vma relocation;
  2913. bool unresolved_reloc;
  2914. bfd_reloc_status_type r;
  2915. bool resolved_to_zero;
  2916. r_type = ELF32_R_TYPE (rel->r_info);
  2917. if (r_type < 0 || r_type >= (int) R_68K_max)
  2918. {
  2919. bfd_set_error (bfd_error_bad_value);
  2920. return false;
  2921. }
  2922. howto = howto_table + r_type;
  2923. r_symndx = ELF32_R_SYM (rel->r_info);
  2924. h = NULL;
  2925. sym = NULL;
  2926. sec = NULL;
  2927. unresolved_reloc = false;
  2928. if (r_symndx < symtab_hdr->sh_info)
  2929. {
  2930. sym = local_syms + r_symndx;
  2931. sec = local_sections[r_symndx];
  2932. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  2933. }
  2934. else
  2935. {
  2936. bool warned, ignored;
  2937. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  2938. r_symndx, symtab_hdr, sym_hashes,
  2939. h, sec, relocation,
  2940. unresolved_reloc, warned, ignored);
  2941. }
  2942. if (sec != NULL && discarded_section (sec))
  2943. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  2944. rel, 1, relend, howto, 0, contents);
  2945. if (bfd_link_relocatable (info))
  2946. continue;
  2947. resolved_to_zero = (h != NULL
  2948. && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
  2949. switch (r_type)
  2950. {
  2951. case R_68K_GOT8:
  2952. case R_68K_GOT16:
  2953. case R_68K_GOT32:
  2954. /* Relocation is to the address of the entry for this symbol
  2955. in the global offset table. */
  2956. if (h != NULL
  2957. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  2958. {
  2959. if (elf_m68k_hash_table (info)->local_gp_p)
  2960. {
  2961. bfd_vma sgot_output_offset;
  2962. bfd_vma got_offset;
  2963. sgot = elf_hash_table (info)->sgot;
  2964. if (sgot != NULL)
  2965. sgot_output_offset = sgot->output_offset;
  2966. else
  2967. /* In this case we have a reference to
  2968. _GLOBAL_OFFSET_TABLE_, but the GOT itself is
  2969. empty.
  2970. ??? Issue a warning? */
  2971. sgot_output_offset = 0;
  2972. if (got == NULL)
  2973. {
  2974. struct elf_m68k_bfd2got_entry *bfd2got_entry;
  2975. bfd2got_entry
  2976. = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
  2977. input_bfd, SEARCH, NULL);
  2978. if (bfd2got_entry != NULL)
  2979. {
  2980. got = bfd2got_entry->got;
  2981. BFD_ASSERT (got != NULL);
  2982. got_offset = got->offset;
  2983. }
  2984. else
  2985. /* In this case we have a reference to
  2986. _GLOBAL_OFFSET_TABLE_, but no other references
  2987. accessing any GOT entries.
  2988. ??? Issue a warning? */
  2989. got_offset = 0;
  2990. }
  2991. else
  2992. got_offset = got->offset;
  2993. /* Adjust GOT pointer to point to the GOT
  2994. assigned to input_bfd. */
  2995. rel->r_addend += sgot_output_offset + got_offset;
  2996. }
  2997. else
  2998. BFD_ASSERT (got == NULL || got->offset == 0);
  2999. break;
  3000. }
  3001. /* Fall through. */
  3002. case R_68K_GOT8O:
  3003. case R_68K_GOT16O:
  3004. case R_68K_GOT32O:
  3005. case R_68K_TLS_LDM32:
  3006. case R_68K_TLS_LDM16:
  3007. case R_68K_TLS_LDM8:
  3008. case R_68K_TLS_GD8:
  3009. case R_68K_TLS_GD16:
  3010. case R_68K_TLS_GD32:
  3011. case R_68K_TLS_IE8:
  3012. case R_68K_TLS_IE16:
  3013. case R_68K_TLS_IE32:
  3014. /* Relocation is the offset of the entry for this symbol in
  3015. the global offset table. */
  3016. {
  3017. struct elf_m68k_got_entry_key key_;
  3018. bfd_vma *off_ptr;
  3019. bfd_vma off;
  3020. sgot = elf_hash_table (info)->sgot;
  3021. BFD_ASSERT (sgot != NULL);
  3022. if (got == NULL)
  3023. got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
  3024. input_bfd, MUST_FIND,
  3025. NULL)->got;
  3026. /* Get GOT offset for this symbol. */
  3027. elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx,
  3028. r_type);
  3029. off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND,
  3030. NULL)->u.s2.offset;
  3031. off = *off_ptr;
  3032. /* The offset must always be a multiple of 4. We use
  3033. the least significant bit to record whether we have
  3034. already generated the necessary reloc. */
  3035. if ((off & 1) != 0)
  3036. off &= ~1;
  3037. else
  3038. {
  3039. if (h != NULL
  3040. /* @TLSLDM relocations are bounded to the module, in
  3041. which the symbol is defined -- not to the symbol
  3042. itself. */
  3043. && elf_m68k_reloc_got_type (r_type) != R_68K_TLS_LDM32)
  3044. {
  3045. bool dyn;
  3046. dyn = elf_hash_table (info)->dynamic_sections_created;
  3047. if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  3048. bfd_link_pic (info),
  3049. h)
  3050. || (bfd_link_pic (info)
  3051. && SYMBOL_REFERENCES_LOCAL (info, h))
  3052. || ((ELF_ST_VISIBILITY (h->other)
  3053. || resolved_to_zero)
  3054. && h->root.type == bfd_link_hash_undefweak))
  3055. {
  3056. /* This is actually a static link, or it is a
  3057. -Bsymbolic link and the symbol is defined
  3058. locally, or the symbol was forced to be local
  3059. because of a version file. We must initialize
  3060. this entry in the global offset table. Since
  3061. the offset must always be a multiple of 4, we
  3062. use the least significant bit to record whether
  3063. we have initialized it already.
  3064. When doing a dynamic link, we create a .rela.got
  3065. relocation entry to initialize the value. This
  3066. is done in the finish_dynamic_symbol routine. */
  3067. elf_m68k_init_got_entry_static (info,
  3068. output_bfd,
  3069. r_type,
  3070. sgot,
  3071. off,
  3072. relocation);
  3073. *off_ptr |= 1;
  3074. }
  3075. else
  3076. unresolved_reloc = false;
  3077. }
  3078. else if (bfd_link_pic (info)) /* && h == NULL */
  3079. /* Process local symbol during dynamic link. */
  3080. {
  3081. srela = elf_hash_table (info)->srelgot;
  3082. BFD_ASSERT (srela != NULL);
  3083. elf_m68k_init_got_entry_local_shared (info,
  3084. output_bfd,
  3085. r_type,
  3086. sgot,
  3087. off,
  3088. relocation,
  3089. srela);
  3090. *off_ptr |= 1;
  3091. }
  3092. else /* h == NULL && !bfd_link_pic (info) */
  3093. {
  3094. elf_m68k_init_got_entry_static (info,
  3095. output_bfd,
  3096. r_type,
  3097. sgot,
  3098. off,
  3099. relocation);
  3100. *off_ptr |= 1;
  3101. }
  3102. }
  3103. /* We don't use elf_m68k_reloc_got_type in the condition below
  3104. because this is the only place where difference between
  3105. R_68K_GOTx and R_68K_GOTxO relocations matters. */
  3106. if (r_type == R_68K_GOT32O
  3107. || r_type == R_68K_GOT16O
  3108. || r_type == R_68K_GOT8O
  3109. || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_GD32
  3110. || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_LDM32
  3111. || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_IE32)
  3112. {
  3113. /* GOT pointer is adjusted to point to the start/middle
  3114. of local GOT. Adjust the offset accordingly. */
  3115. BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p
  3116. || off >= got->offset);
  3117. if (elf_m68k_hash_table (info)->local_gp_p)
  3118. relocation = off - got->offset;
  3119. else
  3120. {
  3121. BFD_ASSERT (got->offset == 0);
  3122. relocation = sgot->output_offset + off;
  3123. }
  3124. /* This relocation does not use the addend. */
  3125. rel->r_addend = 0;
  3126. }
  3127. else
  3128. relocation = (sgot->output_section->vma + sgot->output_offset
  3129. + off);
  3130. }
  3131. break;
  3132. case R_68K_TLS_LDO32:
  3133. case R_68K_TLS_LDO16:
  3134. case R_68K_TLS_LDO8:
  3135. relocation -= dtpoff_base (info);
  3136. break;
  3137. case R_68K_TLS_LE32:
  3138. case R_68K_TLS_LE16:
  3139. case R_68K_TLS_LE8:
  3140. if (bfd_link_dll (info))
  3141. {
  3142. _bfd_error_handler
  3143. /* xgettext:c-format */
  3144. (_("%pB(%pA+%#" PRIx64 "): "
  3145. "%s relocation not permitted in shared object"),
  3146. input_bfd, input_section, (uint64_t) rel->r_offset,
  3147. howto->name);
  3148. return false;
  3149. }
  3150. else
  3151. relocation -= tpoff_base (info);
  3152. break;
  3153. case R_68K_PLT8:
  3154. case R_68K_PLT16:
  3155. case R_68K_PLT32:
  3156. /* Relocation is to the entry for this symbol in the
  3157. procedure linkage table. */
  3158. /* Resolve a PLTxx reloc against a local symbol directly,
  3159. without using the procedure linkage table. */
  3160. if (h == NULL)
  3161. break;
  3162. if (h->plt.offset == (bfd_vma) -1
  3163. || !elf_hash_table (info)->dynamic_sections_created)
  3164. {
  3165. /* We didn't make a PLT entry for this symbol. This
  3166. happens when statically linking PIC code, or when
  3167. using -Bsymbolic. */
  3168. break;
  3169. }
  3170. splt = elf_hash_table (info)->splt;
  3171. BFD_ASSERT (splt != NULL);
  3172. relocation = (splt->output_section->vma
  3173. + splt->output_offset
  3174. + h->plt.offset);
  3175. unresolved_reloc = false;
  3176. break;
  3177. case R_68K_PLT8O:
  3178. case R_68K_PLT16O:
  3179. case R_68K_PLT32O:
  3180. /* Relocation is the offset of the entry for this symbol in
  3181. the procedure linkage table. */
  3182. BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
  3183. splt = elf_hash_table (info)->splt;
  3184. BFD_ASSERT (splt != NULL);
  3185. relocation = h->plt.offset;
  3186. unresolved_reloc = false;
  3187. /* This relocation does not use the addend. */
  3188. rel->r_addend = 0;
  3189. break;
  3190. case R_68K_8:
  3191. case R_68K_16:
  3192. case R_68K_32:
  3193. case R_68K_PC8:
  3194. case R_68K_PC16:
  3195. case R_68K_PC32:
  3196. if (bfd_link_pic (info)
  3197. && r_symndx != STN_UNDEF
  3198. && (input_section->flags & SEC_ALLOC) != 0
  3199. && (h == NULL
  3200. || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  3201. && !resolved_to_zero)
  3202. || h->root.type != bfd_link_hash_undefweak)
  3203. && ((r_type != R_68K_PC8
  3204. && r_type != R_68K_PC16
  3205. && r_type != R_68K_PC32)
  3206. || !SYMBOL_CALLS_LOCAL (info, h)))
  3207. {
  3208. Elf_Internal_Rela outrel;
  3209. bfd_byte *loc;
  3210. bool skip, relocate;
  3211. /* When generating a shared object, these relocations
  3212. are copied into the output file to be resolved at run
  3213. time. */
  3214. skip = false;
  3215. relocate = false;
  3216. outrel.r_offset =
  3217. _bfd_elf_section_offset (output_bfd, info, input_section,
  3218. rel->r_offset);
  3219. if (outrel.r_offset == (bfd_vma) -1)
  3220. skip = true;
  3221. else if (outrel.r_offset == (bfd_vma) -2)
  3222. skip = true, relocate = true;
  3223. outrel.r_offset += (input_section->output_section->vma
  3224. + input_section->output_offset);
  3225. if (skip)
  3226. memset (&outrel, 0, sizeof outrel);
  3227. else if (h != NULL
  3228. && h->dynindx != -1
  3229. && (r_type == R_68K_PC8
  3230. || r_type == R_68K_PC16
  3231. || r_type == R_68K_PC32
  3232. || !bfd_link_pic (info)
  3233. || !SYMBOLIC_BIND (info, h)
  3234. || !h->def_regular))
  3235. {
  3236. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  3237. outrel.r_addend = rel->r_addend;
  3238. }
  3239. else
  3240. {
  3241. /* This symbol is local, or marked to become local. */
  3242. outrel.r_addend = relocation + rel->r_addend;
  3243. if (r_type == R_68K_32)
  3244. {
  3245. relocate = true;
  3246. outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
  3247. }
  3248. else
  3249. {
  3250. long indx;
  3251. if (bfd_is_abs_section (sec))
  3252. indx = 0;
  3253. else if (sec == NULL || sec->owner == NULL)
  3254. {
  3255. bfd_set_error (bfd_error_bad_value);
  3256. return false;
  3257. }
  3258. else
  3259. {
  3260. asection *osec;
  3261. /* We are turning this relocation into one
  3262. against a section symbol. It would be
  3263. proper to subtract the symbol's value,
  3264. osec->vma, from the emitted reloc addend,
  3265. but ld.so expects buggy relocs. */
  3266. osec = sec->output_section;
  3267. indx = elf_section_data (osec)->dynindx;
  3268. if (indx == 0)
  3269. {
  3270. struct elf_link_hash_table *htab;
  3271. htab = elf_hash_table (info);
  3272. osec = htab->text_index_section;
  3273. indx = elf_section_data (osec)->dynindx;
  3274. }
  3275. BFD_ASSERT (indx != 0);
  3276. }
  3277. outrel.r_info = ELF32_R_INFO (indx, r_type);
  3278. }
  3279. }
  3280. sreloc = elf_section_data (input_section)->sreloc;
  3281. if (sreloc == NULL)
  3282. abort ();
  3283. loc = sreloc->contents;
  3284. loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
  3285. bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
  3286. /* This reloc will be computed at runtime, so there's no
  3287. need to do anything now, except for R_68K_32
  3288. relocations that have been turned into
  3289. R_68K_RELATIVE. */
  3290. if (!relocate)
  3291. continue;
  3292. }
  3293. break;
  3294. case R_68K_GNU_VTINHERIT:
  3295. case R_68K_GNU_VTENTRY:
  3296. /* These are no-ops in the end. */
  3297. continue;
  3298. default:
  3299. break;
  3300. }
  3301. /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
  3302. because such sections are not SEC_ALLOC and thus ld.so will
  3303. not process them. */
  3304. if (unresolved_reloc
  3305. && !((input_section->flags & SEC_DEBUGGING) != 0
  3306. && h->def_dynamic)
  3307. && _bfd_elf_section_offset (output_bfd, info, input_section,
  3308. rel->r_offset) != (bfd_vma) -1)
  3309. {
  3310. _bfd_error_handler
  3311. /* xgettext:c-format */
  3312. (_("%pB(%pA+%#" PRIx64 "): "
  3313. "unresolvable %s relocation against symbol `%s'"),
  3314. input_bfd,
  3315. input_section,
  3316. (uint64_t) rel->r_offset,
  3317. howto->name,
  3318. h->root.root.string);
  3319. return false;
  3320. }
  3321. if (r_symndx != STN_UNDEF
  3322. && r_type != R_68K_NONE
  3323. && (h == NULL
  3324. || h->root.type == bfd_link_hash_defined
  3325. || h->root.type == bfd_link_hash_defweak))
  3326. {
  3327. char sym_type;
  3328. sym_type = (sym != NULL) ? ELF32_ST_TYPE (sym->st_info) : h->type;
  3329. if (elf_m68k_reloc_tls_p (r_type) != (sym_type == STT_TLS))
  3330. {
  3331. const char *name;
  3332. if (h != NULL)
  3333. name = h->root.root.string;
  3334. else
  3335. {
  3336. name = (bfd_elf_string_from_elf_section
  3337. (input_bfd, symtab_hdr->sh_link, sym->st_name));
  3338. if (name == NULL || *name == '\0')
  3339. name = bfd_section_name (sec);
  3340. }
  3341. _bfd_error_handler
  3342. ((sym_type == STT_TLS
  3343. /* xgettext:c-format */
  3344. ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s")
  3345. /* xgettext:c-format */
  3346. : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")),
  3347. input_bfd,
  3348. input_section,
  3349. (uint64_t) rel->r_offset,
  3350. howto->name,
  3351. name);
  3352. }
  3353. }
  3354. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  3355. contents, rel->r_offset,
  3356. relocation, rel->r_addend);
  3357. if (r != bfd_reloc_ok)
  3358. {
  3359. const char *name;
  3360. if (h != NULL)
  3361. name = h->root.root.string;
  3362. else
  3363. {
  3364. name = bfd_elf_string_from_elf_section (input_bfd,
  3365. symtab_hdr->sh_link,
  3366. sym->st_name);
  3367. if (name == NULL)
  3368. return false;
  3369. if (*name == '\0')
  3370. name = bfd_section_name (sec);
  3371. }
  3372. if (r == bfd_reloc_overflow)
  3373. (*info->callbacks->reloc_overflow)
  3374. (info, (h ? &h->root : NULL), name, howto->name,
  3375. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  3376. else
  3377. {
  3378. _bfd_error_handler
  3379. /* xgettext:c-format */
  3380. (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
  3381. input_bfd, input_section,
  3382. (uint64_t) rel->r_offset, name, (int) r);
  3383. return false;
  3384. }
  3385. }
  3386. }
  3387. return true;
  3388. }
  3389. /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
  3390. into section SEC. */
  3391. static void
  3392. elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
  3393. {
  3394. /* Make VALUE PC-relative. */
  3395. value -= sec->output_section->vma + offset;
  3396. /* Apply any in-place addend. */
  3397. value += bfd_get_32 (sec->owner, sec->contents + offset);
  3398. bfd_put_32 (sec->owner, value, sec->contents + offset);
  3399. }
  3400. /* Finish up dynamic symbol handling. We set the contents of various
  3401. dynamic sections here. */
  3402. static bool
  3403. elf_m68k_finish_dynamic_symbol (bfd *output_bfd,
  3404. struct bfd_link_info *info,
  3405. struct elf_link_hash_entry *h,
  3406. Elf_Internal_Sym *sym)
  3407. {
  3408. bfd *dynobj;
  3409. dynobj = elf_hash_table (info)->dynobj;
  3410. if (h->plt.offset != (bfd_vma) -1)
  3411. {
  3412. const struct elf_m68k_plt_info *plt_info;
  3413. asection *splt;
  3414. asection *sgot;
  3415. asection *srela;
  3416. bfd_vma plt_index;
  3417. bfd_vma got_offset;
  3418. Elf_Internal_Rela rela;
  3419. bfd_byte *loc;
  3420. /* This symbol has an entry in the procedure linkage table. Set
  3421. it up. */
  3422. BFD_ASSERT (h->dynindx != -1);
  3423. plt_info = elf_m68k_hash_table (info)->plt_info;
  3424. splt = elf_hash_table (info)->splt;
  3425. sgot = elf_hash_table (info)->sgotplt;
  3426. srela = elf_hash_table (info)->srelplt;
  3427. BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
  3428. /* Get the index in the procedure linkage table which
  3429. corresponds to this symbol. This is the index of this symbol
  3430. in all the symbols for which we are making plt entries. The
  3431. first entry in the procedure linkage table is reserved. */
  3432. plt_index = (h->plt.offset / plt_info->size) - 1;
  3433. /* Get the offset into the .got table of the entry that
  3434. corresponds to this function. Each .got entry is 4 bytes.
  3435. The first three are reserved. */
  3436. got_offset = (plt_index + 3) * 4;
  3437. memcpy (splt->contents + h->plt.offset,
  3438. plt_info->symbol_entry,
  3439. plt_info->size);
  3440. elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
  3441. (sgot->output_section->vma
  3442. + sgot->output_offset
  3443. + got_offset));
  3444. bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
  3445. splt->contents
  3446. + h->plt.offset
  3447. + plt_info->symbol_resolve_entry + 2);
  3448. elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
  3449. splt->output_section->vma);
  3450. /* Fill in the entry in the global offset table. */
  3451. bfd_put_32 (output_bfd,
  3452. (splt->output_section->vma
  3453. + splt->output_offset
  3454. + h->plt.offset
  3455. + plt_info->symbol_resolve_entry),
  3456. sgot->contents + got_offset);
  3457. /* Fill in the entry in the .rela.plt section. */
  3458. rela.r_offset = (sgot->output_section->vma
  3459. + sgot->output_offset
  3460. + got_offset);
  3461. rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
  3462. rela.r_addend = 0;
  3463. loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
  3464. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  3465. if (!h->def_regular)
  3466. {
  3467. /* Mark the symbol as undefined, rather than as defined in
  3468. the .plt section. Leave the value alone. */
  3469. sym->st_shndx = SHN_UNDEF;
  3470. }
  3471. }
  3472. if (elf_m68k_hash_entry (h)->glist != NULL)
  3473. {
  3474. asection *sgot;
  3475. asection *srela;
  3476. struct elf_m68k_got_entry *got_entry;
  3477. /* This symbol has an entry in the global offset table. Set it
  3478. up. */
  3479. sgot = elf_hash_table (info)->sgot;
  3480. srela = elf_hash_table (info)->srelgot;
  3481. BFD_ASSERT (sgot != NULL && srela != NULL);
  3482. got_entry = elf_m68k_hash_entry (h)->glist;
  3483. while (got_entry != NULL)
  3484. {
  3485. enum elf_m68k_reloc_type r_type;
  3486. bfd_vma got_entry_offset;
  3487. r_type = got_entry->key_.type;
  3488. got_entry_offset = got_entry->u.s2.offset &~ (bfd_vma) 1;
  3489. /* If this is a -Bsymbolic link, and the symbol is defined
  3490. locally, we just want to emit a RELATIVE reloc. Likewise if
  3491. the symbol was forced to be local because of a version file.
  3492. The entry in the global offset table already have been
  3493. initialized in the relocate_section function. */
  3494. if (bfd_link_pic (info)
  3495. && SYMBOL_REFERENCES_LOCAL (info, h))
  3496. {
  3497. bfd_vma relocation;
  3498. relocation = bfd_get_signed_32 (output_bfd,
  3499. (sgot->contents
  3500. + got_entry_offset));
  3501. /* Undo TP bias. */
  3502. switch (elf_m68k_reloc_got_type (r_type))
  3503. {
  3504. case R_68K_GOT32O:
  3505. case R_68K_TLS_LDM32:
  3506. break;
  3507. case R_68K_TLS_GD32:
  3508. /* The value for this relocation is actually put in
  3509. the second GOT slot. */
  3510. relocation = bfd_get_signed_32 (output_bfd,
  3511. (sgot->contents
  3512. + got_entry_offset + 4));
  3513. relocation += dtpoff_base (info);
  3514. break;
  3515. case R_68K_TLS_IE32:
  3516. relocation += tpoff_base (info);
  3517. break;
  3518. default:
  3519. BFD_ASSERT (false);
  3520. }
  3521. elf_m68k_init_got_entry_local_shared (info,
  3522. output_bfd,
  3523. r_type,
  3524. sgot,
  3525. got_entry_offset,
  3526. relocation,
  3527. srela);
  3528. }
  3529. else
  3530. {
  3531. Elf_Internal_Rela rela;
  3532. /* Put zeros to GOT slots that will be initialized
  3533. at run-time. */
  3534. {
  3535. bfd_vma n_slots;
  3536. n_slots = elf_m68k_reloc_got_n_slots (got_entry->key_.type);
  3537. while (n_slots--)
  3538. bfd_put_32 (output_bfd, (bfd_vma) 0,
  3539. (sgot->contents + got_entry_offset
  3540. + 4 * n_slots));
  3541. }
  3542. rela.r_addend = 0;
  3543. rela.r_offset = (sgot->output_section->vma
  3544. + sgot->output_offset
  3545. + got_entry_offset);
  3546. switch (elf_m68k_reloc_got_type (r_type))
  3547. {
  3548. case R_68K_GOT32O:
  3549. rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
  3550. elf_m68k_install_rela (output_bfd, srela, &rela);
  3551. break;
  3552. case R_68K_TLS_GD32:
  3553. rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPMOD32);
  3554. elf_m68k_install_rela (output_bfd, srela, &rela);
  3555. rela.r_offset += 4;
  3556. rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPREL32);
  3557. elf_m68k_install_rela (output_bfd, srela, &rela);
  3558. break;
  3559. case R_68K_TLS_IE32:
  3560. rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_TPREL32);
  3561. elf_m68k_install_rela (output_bfd, srela, &rela);
  3562. break;
  3563. default:
  3564. BFD_ASSERT (false);
  3565. break;
  3566. }
  3567. }
  3568. got_entry = got_entry->u.s2.next;
  3569. }
  3570. }
  3571. if (h->needs_copy)
  3572. {
  3573. asection *s;
  3574. Elf_Internal_Rela rela;
  3575. bfd_byte *loc;
  3576. /* This symbol needs a copy reloc. Set it up. */
  3577. BFD_ASSERT (h->dynindx != -1
  3578. && (h->root.type == bfd_link_hash_defined
  3579. || h->root.type == bfd_link_hash_defweak));
  3580. s = bfd_get_linker_section (dynobj, ".rela.bss");
  3581. BFD_ASSERT (s != NULL);
  3582. rela.r_offset = (h->root.u.def.value
  3583. + h->root.u.def.section->output_section->vma
  3584. + h->root.u.def.section->output_offset);
  3585. rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
  3586. rela.r_addend = 0;
  3587. loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
  3588. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  3589. }
  3590. return true;
  3591. }
  3592. /* Finish up the dynamic sections. */
  3593. static bool
  3594. elf_m68k_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
  3595. {
  3596. bfd *dynobj;
  3597. asection *sgot;
  3598. asection *sdyn;
  3599. dynobj = elf_hash_table (info)->dynobj;
  3600. sgot = elf_hash_table (info)->sgotplt;
  3601. BFD_ASSERT (sgot != NULL);
  3602. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  3603. if (elf_hash_table (info)->dynamic_sections_created)
  3604. {
  3605. asection *splt;
  3606. Elf32_External_Dyn *dyncon, *dynconend;
  3607. splt = elf_hash_table (info)->splt;
  3608. BFD_ASSERT (splt != NULL && sdyn != NULL);
  3609. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  3610. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  3611. for (; dyncon < dynconend; dyncon++)
  3612. {
  3613. Elf_Internal_Dyn dyn;
  3614. asection *s;
  3615. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  3616. switch (dyn.d_tag)
  3617. {
  3618. default:
  3619. break;
  3620. case DT_PLTGOT:
  3621. s = elf_hash_table (info)->sgotplt;
  3622. goto get_vma;
  3623. case DT_JMPREL:
  3624. s = elf_hash_table (info)->srelplt;
  3625. get_vma:
  3626. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  3627. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  3628. break;
  3629. case DT_PLTRELSZ:
  3630. s = elf_hash_table (info)->srelplt;
  3631. dyn.d_un.d_val = s->size;
  3632. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  3633. break;
  3634. }
  3635. }
  3636. /* Fill in the first entry in the procedure linkage table. */
  3637. if (splt->size > 0)
  3638. {
  3639. const struct elf_m68k_plt_info *plt_info;
  3640. plt_info = elf_m68k_hash_table (info)->plt_info;
  3641. memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
  3642. elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
  3643. (sgot->output_section->vma
  3644. + sgot->output_offset
  3645. + 4));
  3646. elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
  3647. (sgot->output_section->vma
  3648. + sgot->output_offset
  3649. + 8));
  3650. elf_section_data (splt->output_section)->this_hdr.sh_entsize
  3651. = plt_info->size;
  3652. }
  3653. }
  3654. /* Fill in the first three entries in the global offset table. */
  3655. if (sgot->size > 0)
  3656. {
  3657. if (sdyn == NULL)
  3658. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
  3659. else
  3660. bfd_put_32 (output_bfd,
  3661. sdyn->output_section->vma + sdyn->output_offset,
  3662. sgot->contents);
  3663. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
  3664. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
  3665. }
  3666. elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
  3667. return true;
  3668. }
  3669. /* Given a .data section and a .emreloc in-memory section, store
  3670. relocation information into the .emreloc section which can be
  3671. used at runtime to relocate the section. This is called by the
  3672. linker when the --embedded-relocs switch is used. This is called
  3673. after the add_symbols entry point has been called for all the
  3674. objects, and before the final_link entry point is called. */
  3675. bool
  3676. bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
  3677. asection *datasec, asection *relsec,
  3678. char **errmsg)
  3679. {
  3680. Elf_Internal_Shdr *symtab_hdr;
  3681. Elf_Internal_Sym *isymbuf = NULL;
  3682. Elf_Internal_Rela *internal_relocs = NULL;
  3683. Elf_Internal_Rela *irel, *irelend;
  3684. bfd_byte *p;
  3685. bfd_size_type amt;
  3686. BFD_ASSERT (! bfd_link_relocatable (info));
  3687. *errmsg = NULL;
  3688. if (datasec->reloc_count == 0)
  3689. return true;
  3690. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  3691. /* Get a copy of the native relocations. */
  3692. internal_relocs = (_bfd_elf_link_read_relocs
  3693. (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL,
  3694. info->keep_memory));
  3695. if (internal_relocs == NULL)
  3696. goto error_return;
  3697. amt = (bfd_size_type) datasec->reloc_count * 12;
  3698. relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
  3699. if (relsec->contents == NULL)
  3700. goto error_return;
  3701. p = relsec->contents;
  3702. irelend = internal_relocs + datasec->reloc_count;
  3703. for (irel = internal_relocs; irel < irelend; irel++, p += 12)
  3704. {
  3705. asection *targetsec;
  3706. /* We are going to write a four byte longword into the runtime
  3707. reloc section. The longword will be the address in the data
  3708. section which must be relocated. It is followed by the name
  3709. of the target section NUL-padded or truncated to 8
  3710. characters. */
  3711. /* We can only relocate absolute longword relocs at run time. */
  3712. if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
  3713. {
  3714. *errmsg = _("unsupported relocation type");
  3715. bfd_set_error (bfd_error_bad_value);
  3716. goto error_return;
  3717. }
  3718. /* Get the target section referred to by the reloc. */
  3719. if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  3720. {
  3721. /* A local symbol. */
  3722. Elf_Internal_Sym *isym;
  3723. /* Read this BFD's local symbols if we haven't done so already. */
  3724. if (isymbuf == NULL)
  3725. {
  3726. isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  3727. if (isymbuf == NULL)
  3728. isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
  3729. symtab_hdr->sh_info, 0,
  3730. NULL, NULL, NULL);
  3731. if (isymbuf == NULL)
  3732. goto error_return;
  3733. }
  3734. isym = isymbuf + ELF32_R_SYM (irel->r_info);
  3735. targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  3736. }
  3737. else
  3738. {
  3739. unsigned long indx;
  3740. struct elf_link_hash_entry *h;
  3741. /* An external symbol. */
  3742. indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
  3743. h = elf_sym_hashes (abfd)[indx];
  3744. BFD_ASSERT (h != NULL);
  3745. if (h->root.type == bfd_link_hash_defined
  3746. || h->root.type == bfd_link_hash_defweak)
  3747. targetsec = h->root.u.def.section;
  3748. else
  3749. targetsec = NULL;
  3750. }
  3751. bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
  3752. memset (p + 4, 0, 8);
  3753. if (targetsec != NULL)
  3754. strncpy ((char *) p + 4, targetsec->output_section->name, 8);
  3755. }
  3756. if (symtab_hdr->contents != (unsigned char *) isymbuf)
  3757. free (isymbuf);
  3758. if (elf_section_data (datasec)->relocs != internal_relocs)
  3759. free (internal_relocs);
  3760. return true;
  3761. error_return:
  3762. if (symtab_hdr->contents != (unsigned char *) isymbuf)
  3763. free (isymbuf);
  3764. if (elf_section_data (datasec)->relocs != internal_relocs)
  3765. free (internal_relocs);
  3766. return false;
  3767. }
  3768. /* Set target options. */
  3769. void
  3770. bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling)
  3771. {
  3772. struct elf_m68k_link_hash_table *htab;
  3773. bool use_neg_got_offsets_p;
  3774. bool allow_multigot_p;
  3775. bool local_gp_p;
  3776. switch (got_handling)
  3777. {
  3778. case 0:
  3779. /* --got=single. */
  3780. local_gp_p = false;
  3781. use_neg_got_offsets_p = false;
  3782. allow_multigot_p = false;
  3783. break;
  3784. case 1:
  3785. /* --got=negative. */
  3786. local_gp_p = true;
  3787. use_neg_got_offsets_p = true;
  3788. allow_multigot_p = false;
  3789. break;
  3790. case 2:
  3791. /* --got=multigot. */
  3792. local_gp_p = true;
  3793. use_neg_got_offsets_p = true;
  3794. allow_multigot_p = true;
  3795. break;
  3796. default:
  3797. BFD_ASSERT (false);
  3798. return;
  3799. }
  3800. htab = elf_m68k_hash_table (info);
  3801. if (htab != NULL)
  3802. {
  3803. htab->local_gp_p = local_gp_p;
  3804. htab->use_neg_got_offsets_p = use_neg_got_offsets_p;
  3805. htab->allow_multigot_p = allow_multigot_p;
  3806. }
  3807. }
  3808. static enum elf_reloc_type_class
  3809. elf32_m68k_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  3810. const asection *rel_sec ATTRIBUTE_UNUSED,
  3811. const Elf_Internal_Rela *rela)
  3812. {
  3813. switch ((int) ELF32_R_TYPE (rela->r_info))
  3814. {
  3815. case R_68K_RELATIVE:
  3816. return reloc_class_relative;
  3817. case R_68K_JMP_SLOT:
  3818. return reloc_class_plt;
  3819. case R_68K_COPY:
  3820. return reloc_class_copy;
  3821. default:
  3822. return reloc_class_normal;
  3823. }
  3824. }
  3825. /* Return address for Ith PLT stub in section PLT, for relocation REL
  3826. or (bfd_vma) -1 if it should not be included. */
  3827. static bfd_vma
  3828. elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
  3829. const arelent *rel ATTRIBUTE_UNUSED)
  3830. {
  3831. return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
  3832. }
  3833. /* Support for core dump NOTE sections. */
  3834. static bool
  3835. elf_m68k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
  3836. {
  3837. int offset;
  3838. size_t size;
  3839. switch (note->descsz)
  3840. {
  3841. default:
  3842. return false;
  3843. case 154: /* Linux/m68k */
  3844. /* pr_cursig */
  3845. elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
  3846. /* pr_pid */
  3847. elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 22);
  3848. /* pr_reg */
  3849. offset = 70;
  3850. size = 80;
  3851. break;
  3852. }
  3853. /* Make a ".reg/999" section. */
  3854. return _bfd_elfcore_make_pseudosection (abfd, ".reg",
  3855. size, note->descpos + offset);
  3856. }
  3857. static bool
  3858. elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
  3859. {
  3860. switch (note->descsz)
  3861. {
  3862. default:
  3863. return false;
  3864. case 124: /* Linux/m68k elf_prpsinfo. */
  3865. elf_tdata (abfd)->core->pid
  3866. = bfd_get_32 (abfd, note->descdata + 12);
  3867. elf_tdata (abfd)->core->program
  3868. = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
  3869. elf_tdata (abfd)->core->command
  3870. = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
  3871. }
  3872. /* Note that for some reason, a spurious space is tacked
  3873. onto the end of the args in some (at least one anyway)
  3874. implementations, so strip it off if it exists. */
  3875. {
  3876. char *command = elf_tdata (abfd)->core->command;
  3877. int n = strlen (command);
  3878. if (n > 0 && command[n - 1] == ' ')
  3879. command[n - 1] = '\0';
  3880. }
  3881. return true;
  3882. }
  3883. #define TARGET_BIG_SYM m68k_elf32_vec
  3884. #define TARGET_BIG_NAME "elf32-m68k"
  3885. #define ELF_MACHINE_CODE EM_68K
  3886. #define ELF_MAXPAGESIZE 0x2000
  3887. #define elf_backend_create_dynamic_sections \
  3888. _bfd_elf_create_dynamic_sections
  3889. #define bfd_elf32_bfd_link_hash_table_create \
  3890. elf_m68k_link_hash_table_create
  3891. #define bfd_elf32_bfd_final_link bfd_elf_final_link
  3892. #define elf_backend_check_relocs elf_m68k_check_relocs
  3893. #define elf_backend_always_size_sections \
  3894. elf_m68k_always_size_sections
  3895. #define elf_backend_adjust_dynamic_symbol \
  3896. elf_m68k_adjust_dynamic_symbol
  3897. #define elf_backend_size_dynamic_sections \
  3898. elf_m68k_size_dynamic_sections
  3899. #define elf_backend_final_write_processing elf_m68k_final_write_processing
  3900. #define elf_backend_init_index_section _bfd_elf_init_1_index_section
  3901. #define elf_backend_relocate_section elf_m68k_relocate_section
  3902. #define elf_backend_finish_dynamic_symbol \
  3903. elf_m68k_finish_dynamic_symbol
  3904. #define elf_backend_finish_dynamic_sections \
  3905. elf_m68k_finish_dynamic_sections
  3906. #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
  3907. #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
  3908. #define bfd_elf32_bfd_merge_private_bfd_data \
  3909. elf32_m68k_merge_private_bfd_data
  3910. #define bfd_elf32_bfd_set_private_flags \
  3911. elf32_m68k_set_private_flags
  3912. #define bfd_elf32_bfd_print_private_bfd_data \
  3913. elf32_m68k_print_private_bfd_data
  3914. #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
  3915. #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
  3916. #define elf_backend_object_p elf32_m68k_object_p
  3917. #define elf_backend_grok_prstatus elf_m68k_grok_prstatus
  3918. #define elf_backend_grok_psinfo elf_m68k_grok_psinfo
  3919. #define elf_backend_can_gc_sections 1
  3920. #define elf_backend_can_refcount 1
  3921. #define elf_backend_want_got_plt 1
  3922. #define elf_backend_plt_readonly 1
  3923. #define elf_backend_want_plt_sym 0
  3924. #define elf_backend_got_header_size 12
  3925. #define elf_backend_rela_normal 1
  3926. #define elf_backend_dtrel_excludes_plt 1
  3927. #define elf_backend_linux_prpsinfo32_ugid16 true
  3928. #include "elf32-target.h"