symtab.cc 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795
  1. // symtab.cc -- the gold symbol table
  2. // Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. #include "gold.h"
  18. #include <cstring>
  19. #include <stdint.h>
  20. #include <algorithm>
  21. #include <set>
  22. #include <string>
  23. #include <utility>
  24. #include "demangle.h"
  25. #include "gc.h"
  26. #include "object.h"
  27. #include "dwarf_reader.h"
  28. #include "dynobj.h"
  29. #include "output.h"
  30. #include "target.h"
  31. #include "workqueue.h"
  32. #include "symtab.h"
  33. #include "script.h"
  34. #include "plugin.h"
  35. #include "incremental.h"
  36. namespace gold
  37. {
  38. // Class Symbol.
  39. // Initialize fields in Symbol. This initializes everything except u_
  40. // and source_.
  41. void
  42. Symbol::init_fields(const char* name, const char* version,
  43. elfcpp::STT type, elfcpp::STB binding,
  44. elfcpp::STV visibility, unsigned char nonvis)
  45. {
  46. this->name_ = name;
  47. this->version_ = version;
  48. this->symtab_index_ = 0;
  49. this->dynsym_index_ = 0;
  50. this->got_offsets_.init();
  51. this->plt_offset_ = -1U;
  52. this->type_ = type;
  53. this->binding_ = binding;
  54. this->visibility_ = visibility;
  55. this->nonvis_ = nonvis;
  56. this->is_def_ = false;
  57. this->is_forwarder_ = false;
  58. this->has_alias_ = false;
  59. this->needs_dynsym_entry_ = false;
  60. this->in_reg_ = false;
  61. this->in_dyn_ = false;
  62. this->has_warning_ = false;
  63. this->is_copied_from_dynobj_ = false;
  64. this->is_forced_local_ = false;
  65. this->is_ordinary_shndx_ = false;
  66. this->in_real_elf_ = false;
  67. this->is_defined_in_discarded_section_ = false;
  68. this->undef_binding_set_ = false;
  69. this->undef_binding_weak_ = false;
  70. this->is_predefined_ = false;
  71. }
  72. // Return the demangled version of the symbol's name, but only
  73. // if the --demangle flag was set.
  74. static std::string
  75. demangle(const char* name)
  76. {
  77. if (!parameters->options().do_demangle())
  78. return name;
  79. // cplus_demangle allocates memory for the result it returns,
  80. // and returns NULL if the name is already demangled.
  81. char* demangled_name = cplus_demangle(name, DMGL_ANSI | DMGL_PARAMS);
  82. if (demangled_name == NULL)
  83. return name;
  84. std::string retval(demangled_name);
  85. free(demangled_name);
  86. return retval;
  87. }
  88. std::string
  89. Symbol::demangled_name() const
  90. {
  91. return demangle(this->name());
  92. }
  93. // Initialize the fields in the base class Symbol for SYM in OBJECT.
  94. template<int size, bool big_endian>
  95. void
  96. Symbol::init_base_object(const char* name, const char* version, Object* object,
  97. const elfcpp::Sym<size, big_endian>& sym,
  98. unsigned int st_shndx, bool is_ordinary)
  99. {
  100. this->init_fields(name, version, sym.get_st_type(), sym.get_st_bind(),
  101. sym.get_st_visibility(), sym.get_st_nonvis());
  102. this->u_.from_object.object = object;
  103. this->u_.from_object.shndx = st_shndx;
  104. this->is_ordinary_shndx_ = is_ordinary;
  105. this->source_ = FROM_OBJECT;
  106. this->in_reg_ = !object->is_dynamic();
  107. this->in_dyn_ = object->is_dynamic();
  108. this->in_real_elf_ = object->pluginobj() == NULL;
  109. }
  110. // Initialize the fields in the base class Symbol for a symbol defined
  111. // in an Output_data.
  112. void
  113. Symbol::init_base_output_data(const char* name, const char* version,
  114. Output_data* od, elfcpp::STT type,
  115. elfcpp::STB binding, elfcpp::STV visibility,
  116. unsigned char nonvis, bool offset_is_from_end,
  117. bool is_predefined)
  118. {
  119. this->init_fields(name, version, type, binding, visibility, nonvis);
  120. this->u_.in_output_data.output_data = od;
  121. this->u_.in_output_data.offset_is_from_end = offset_is_from_end;
  122. this->source_ = IN_OUTPUT_DATA;
  123. this->in_reg_ = true;
  124. this->in_real_elf_ = true;
  125. this->is_predefined_ = is_predefined;
  126. }
  127. // Initialize the fields in the base class Symbol for a symbol defined
  128. // in an Output_segment.
  129. void
  130. Symbol::init_base_output_segment(const char* name, const char* version,
  131. Output_segment* os, elfcpp::STT type,
  132. elfcpp::STB binding, elfcpp::STV visibility,
  133. unsigned char nonvis,
  134. Segment_offset_base offset_base,
  135. bool is_predefined)
  136. {
  137. this->init_fields(name, version, type, binding, visibility, nonvis);
  138. this->u_.in_output_segment.output_segment = os;
  139. this->u_.in_output_segment.offset_base = offset_base;
  140. this->source_ = IN_OUTPUT_SEGMENT;
  141. this->in_reg_ = true;
  142. this->in_real_elf_ = true;
  143. this->is_predefined_ = is_predefined;
  144. }
  145. // Initialize the fields in the base class Symbol for a symbol defined
  146. // as a constant.
  147. void
  148. Symbol::init_base_constant(const char* name, const char* version,
  149. elfcpp::STT type, elfcpp::STB binding,
  150. elfcpp::STV visibility, unsigned char nonvis,
  151. bool is_predefined)
  152. {
  153. this->init_fields(name, version, type, binding, visibility, nonvis);
  154. this->source_ = IS_CONSTANT;
  155. this->in_reg_ = true;
  156. this->in_real_elf_ = true;
  157. this->is_predefined_ = is_predefined;
  158. }
  159. // Initialize the fields in the base class Symbol for an undefined
  160. // symbol.
  161. void
  162. Symbol::init_base_undefined(const char* name, const char* version,
  163. elfcpp::STT type, elfcpp::STB binding,
  164. elfcpp::STV visibility, unsigned char nonvis)
  165. {
  166. this->init_fields(name, version, type, binding, visibility, nonvis);
  167. this->dynsym_index_ = -1U;
  168. this->source_ = IS_UNDEFINED;
  169. this->in_reg_ = true;
  170. this->in_real_elf_ = true;
  171. }
  172. // Allocate a common symbol in the base.
  173. void
  174. Symbol::allocate_base_common(Output_data* od)
  175. {
  176. gold_assert(this->is_common());
  177. this->source_ = IN_OUTPUT_DATA;
  178. this->u_.in_output_data.output_data = od;
  179. this->u_.in_output_data.offset_is_from_end = false;
  180. }
  181. // Initialize the fields in Sized_symbol for SYM in OBJECT.
  182. template<int size>
  183. template<bool big_endian>
  184. void
  185. Sized_symbol<size>::init_object(const char* name, const char* version,
  186. Object* object,
  187. const elfcpp::Sym<size, big_endian>& sym,
  188. unsigned int st_shndx, bool is_ordinary)
  189. {
  190. this->init_base_object(name, version, object, sym, st_shndx, is_ordinary);
  191. this->value_ = sym.get_st_value();
  192. this->symsize_ = sym.get_st_size();
  193. }
  194. // Initialize the fields in Sized_symbol for a symbol defined in an
  195. // Output_data.
  196. template<int size>
  197. void
  198. Sized_symbol<size>::init_output_data(const char* name, const char* version,
  199. Output_data* od, Value_type value,
  200. Size_type symsize, elfcpp::STT type,
  201. elfcpp::STB binding,
  202. elfcpp::STV visibility,
  203. unsigned char nonvis,
  204. bool offset_is_from_end,
  205. bool is_predefined)
  206. {
  207. this->init_base_output_data(name, version, od, type, binding, visibility,
  208. nonvis, offset_is_from_end, is_predefined);
  209. this->value_ = value;
  210. this->symsize_ = symsize;
  211. }
  212. // Initialize the fields in Sized_symbol for a symbol defined in an
  213. // Output_segment.
  214. template<int size>
  215. void
  216. Sized_symbol<size>::init_output_segment(const char* name, const char* version,
  217. Output_segment* os, Value_type value,
  218. Size_type symsize, elfcpp::STT type,
  219. elfcpp::STB binding,
  220. elfcpp::STV visibility,
  221. unsigned char nonvis,
  222. Segment_offset_base offset_base,
  223. bool is_predefined)
  224. {
  225. this->init_base_output_segment(name, version, os, type, binding, visibility,
  226. nonvis, offset_base, is_predefined);
  227. this->value_ = value;
  228. this->symsize_ = symsize;
  229. }
  230. // Initialize the fields in Sized_symbol for a symbol defined as a
  231. // constant.
  232. template<int size>
  233. void
  234. Sized_symbol<size>::init_constant(const char* name, const char* version,
  235. Value_type value, Size_type symsize,
  236. elfcpp::STT type, elfcpp::STB binding,
  237. elfcpp::STV visibility, unsigned char nonvis,
  238. bool is_predefined)
  239. {
  240. this->init_base_constant(name, version, type, binding, visibility, nonvis,
  241. is_predefined);
  242. this->value_ = value;
  243. this->symsize_ = symsize;
  244. }
  245. // Initialize the fields in Sized_symbol for an undefined symbol.
  246. template<int size>
  247. void
  248. Sized_symbol<size>::init_undefined(const char* name, const char* version,
  249. elfcpp::STT type, elfcpp::STB binding,
  250. elfcpp::STV visibility, unsigned char nonvis)
  251. {
  252. this->init_base_undefined(name, version, type, binding, visibility, nonvis);
  253. this->value_ = 0;
  254. this->symsize_ = 0;
  255. }
  256. // Return an allocated string holding the symbol's name as
  257. // name@version. This is used for relocatable links.
  258. std::string
  259. Symbol::versioned_name() const
  260. {
  261. gold_assert(this->version_ != NULL);
  262. std::string ret = this->name_;
  263. ret.push_back('@');
  264. if (this->is_def_)
  265. ret.push_back('@');
  266. ret += this->version_;
  267. return ret;
  268. }
  269. // Return true if SHNDX represents a common symbol.
  270. bool
  271. Symbol::is_common_shndx(unsigned int shndx)
  272. {
  273. return (shndx == elfcpp::SHN_COMMON
  274. || shndx == parameters->target().small_common_shndx()
  275. || shndx == parameters->target().large_common_shndx());
  276. }
  277. // Allocate a common symbol.
  278. template<int size>
  279. void
  280. Sized_symbol<size>::allocate_common(Output_data* od, Value_type value)
  281. {
  282. this->allocate_base_common(od);
  283. this->value_ = value;
  284. }
  285. // The ""'s around str ensure str is a string literal, so sizeof works.
  286. #define strprefix(var, str) (strncmp(var, str, sizeof("" str "") - 1) == 0)
  287. // Return true if this symbol should be added to the dynamic symbol
  288. // table.
  289. bool
  290. Symbol::should_add_dynsym_entry(Symbol_table* symtab) const
  291. {
  292. // If the symbol is only present on plugin files, the plugin decided we
  293. // don't need it.
  294. if (!this->in_real_elf())
  295. return false;
  296. // If the symbol is used by a dynamic relocation, we need to add it.
  297. if (this->needs_dynsym_entry())
  298. return true;
  299. // If this symbol's section is not added, the symbol need not be added.
  300. // The section may have been GCed. Note that export_dynamic is being
  301. // overridden here. This should not be done for shared objects.
  302. if (parameters->options().gc_sections()
  303. && !parameters->options().shared()
  304. && this->source() == Symbol::FROM_OBJECT
  305. && !this->object()->is_dynamic())
  306. {
  307. Relobj* relobj = static_cast<Relobj*>(this->object());
  308. bool is_ordinary;
  309. unsigned int shndx = this->shndx(&is_ordinary);
  310. if (is_ordinary && shndx != elfcpp::SHN_UNDEF
  311. && !relobj->is_section_included(shndx)
  312. && !symtab->is_section_folded(relobj, shndx))
  313. return false;
  314. }
  315. // If the symbol was forced dynamic in a --dynamic-list file
  316. // or an --export-dynamic-symbol option, add it.
  317. if (!this->is_from_dynobj()
  318. && (parameters->options().in_dynamic_list(this->name())
  319. || parameters->options().is_export_dynamic_symbol(this->name())))
  320. {
  321. if (!this->is_forced_local())
  322. return true;
  323. gold_warning(_("Cannot export local symbol '%s'"),
  324. this->demangled_name().c_str());
  325. return false;
  326. }
  327. // If the symbol was forced local in a version script, do not add it.
  328. if (this->is_forced_local())
  329. return false;
  330. // If dynamic-list-data was specified, add any STT_OBJECT.
  331. if (parameters->options().dynamic_list_data()
  332. && !this->is_from_dynobj()
  333. && this->type() == elfcpp::STT_OBJECT)
  334. return true;
  335. // If --dynamic-list-cpp-new was specified, add any new/delete symbol.
  336. // If --dynamic-list-cpp-typeinfo was specified, add any typeinfo symbols.
  337. if ((parameters->options().dynamic_list_cpp_new()
  338. || parameters->options().dynamic_list_cpp_typeinfo())
  339. && !this->is_from_dynobj())
  340. {
  341. // TODO(csilvers): We could probably figure out if we're an operator
  342. // new/delete or typeinfo without the need to demangle.
  343. char* demangled_name = cplus_demangle(this->name(),
  344. DMGL_ANSI | DMGL_PARAMS);
  345. if (demangled_name == NULL)
  346. {
  347. // Not a C++ symbol, so it can't satisfy these flags
  348. }
  349. else if (parameters->options().dynamic_list_cpp_new()
  350. && (strprefix(demangled_name, "operator new")
  351. || strprefix(demangled_name, "operator delete")))
  352. {
  353. free(demangled_name);
  354. return true;
  355. }
  356. else if (parameters->options().dynamic_list_cpp_typeinfo()
  357. && (strprefix(demangled_name, "typeinfo name for")
  358. || strprefix(demangled_name, "typeinfo for")))
  359. {
  360. free(demangled_name);
  361. return true;
  362. }
  363. else
  364. free(demangled_name);
  365. }
  366. // If exporting all symbols or building a shared library,
  367. // or the symbol should be globally unique (GNU_UNIQUE),
  368. // and the symbol is defined in a regular object and is
  369. // externally visible, we need to add it.
  370. if ((parameters->options().export_dynamic()
  371. || parameters->options().shared()
  372. || (parameters->options().gnu_unique()
  373. && this->binding() == elfcpp::STB_GNU_UNIQUE))
  374. && !this->is_from_dynobj()
  375. && !this->is_undefined()
  376. && this->is_externally_visible())
  377. return true;
  378. return false;
  379. }
  380. // Return true if the final value of this symbol is known at link
  381. // time.
  382. bool
  383. Symbol::final_value_is_known() const
  384. {
  385. // If we are not generating an executable, then no final values are
  386. // known, since they will change at runtime, with the exception of
  387. // TLS symbols in a position-independent executable.
  388. if ((parameters->options().output_is_position_independent()
  389. || parameters->options().relocatable())
  390. && !(this->type() == elfcpp::STT_TLS
  391. && parameters->options().pie()))
  392. return false;
  393. // If the symbol is not from an object file, and is not undefined,
  394. // then it is defined, and known.
  395. if (this->source_ != FROM_OBJECT)
  396. {
  397. if (this->source_ != IS_UNDEFINED)
  398. return true;
  399. }
  400. else
  401. {
  402. // If the symbol is from a dynamic object, then the final value
  403. // is not known.
  404. if (this->object()->is_dynamic())
  405. return false;
  406. // If the symbol is not undefined (it is defined or common),
  407. // then the final value is known.
  408. if (!this->is_undefined())
  409. return true;
  410. }
  411. // If the symbol is undefined, then whether the final value is known
  412. // depends on whether we are doing a static link. If we are doing a
  413. // dynamic link, then the final value could be filled in at runtime.
  414. // This could reasonably be the case for a weak undefined symbol.
  415. return parameters->doing_static_link();
  416. }
  417. // Return the output section where this symbol is defined.
  418. Output_section*
  419. Symbol::output_section() const
  420. {
  421. switch (this->source_)
  422. {
  423. case FROM_OBJECT:
  424. {
  425. unsigned int shndx = this->u_.from_object.shndx;
  426. if (shndx != elfcpp::SHN_UNDEF && this->is_ordinary_shndx_)
  427. {
  428. gold_assert(!this->u_.from_object.object->is_dynamic());
  429. gold_assert(this->u_.from_object.object->pluginobj() == NULL);
  430. Relobj* relobj = static_cast<Relobj*>(this->u_.from_object.object);
  431. return relobj->output_section(shndx);
  432. }
  433. return NULL;
  434. }
  435. case IN_OUTPUT_DATA:
  436. return this->u_.in_output_data.output_data->output_section();
  437. case IN_OUTPUT_SEGMENT:
  438. case IS_CONSTANT:
  439. case IS_UNDEFINED:
  440. return NULL;
  441. default:
  442. gold_unreachable();
  443. }
  444. }
  445. // Set the symbol's output section. This is used for symbols defined
  446. // in scripts. This should only be called after the symbol table has
  447. // been finalized.
  448. void
  449. Symbol::set_output_section(Output_section* os)
  450. {
  451. switch (this->source_)
  452. {
  453. case FROM_OBJECT:
  454. case IN_OUTPUT_DATA:
  455. gold_assert(this->output_section() == os);
  456. break;
  457. case IS_CONSTANT:
  458. this->source_ = IN_OUTPUT_DATA;
  459. this->u_.in_output_data.output_data = os;
  460. this->u_.in_output_data.offset_is_from_end = false;
  461. break;
  462. case IN_OUTPUT_SEGMENT:
  463. case IS_UNDEFINED:
  464. default:
  465. gold_unreachable();
  466. }
  467. }
  468. // Set the symbol's output segment. This is used for pre-defined
  469. // symbols whose segments aren't known until after layout is done
  470. // (e.g., __ehdr_start).
  471. void
  472. Symbol::set_output_segment(Output_segment* os, Segment_offset_base base)
  473. {
  474. gold_assert(this->is_predefined_);
  475. this->source_ = IN_OUTPUT_SEGMENT;
  476. this->u_.in_output_segment.output_segment = os;
  477. this->u_.in_output_segment.offset_base = base;
  478. }
  479. // Set the symbol to undefined. This is used for pre-defined
  480. // symbols whose segments aren't known until after layout is done
  481. // (e.g., __ehdr_start).
  482. void
  483. Symbol::set_undefined()
  484. {
  485. this->source_ = IS_UNDEFINED;
  486. this->is_predefined_ = false;
  487. }
  488. // Class Symbol_table.
  489. Symbol_table::Symbol_table(unsigned int count,
  490. const Version_script_info& version_script)
  491. : saw_undefined_(0), offset_(0), table_(count), namepool_(),
  492. forwarders_(), commons_(), tls_commons_(), small_commons_(),
  493. large_commons_(), forced_locals_(), warnings_(),
  494. version_script_(version_script), gc_(NULL), icf_(NULL)
  495. {
  496. namepool_.reserve(count);
  497. }
  498. Symbol_table::~Symbol_table()
  499. {
  500. }
  501. // The symbol table key equality function. This is called with
  502. // Stringpool keys.
  503. inline bool
  504. Symbol_table::Symbol_table_eq::operator()(const Symbol_table_key& k1,
  505. const Symbol_table_key& k2) const
  506. {
  507. return k1.first == k2.first && k1.second == k2.second;
  508. }
  509. bool
  510. Symbol_table::is_section_folded(Relobj* obj, unsigned int shndx) const
  511. {
  512. return (parameters->options().icf_enabled()
  513. && this->icf_->is_section_folded(obj, shndx));
  514. }
  515. // For symbols that have been listed with a -u or --export-dynamic-symbol
  516. // option, add them to the work list to avoid gc'ing them.
  517. void
  518. Symbol_table::gc_mark_undef_symbols(Layout* layout)
  519. {
  520. for (options::String_set::const_iterator p =
  521. parameters->options().undefined_begin();
  522. p != parameters->options().undefined_end();
  523. ++p)
  524. {
  525. const char* name = p->c_str();
  526. Symbol* sym = this->lookup(name);
  527. gold_assert(sym != NULL);
  528. if (sym->source() == Symbol::FROM_OBJECT
  529. && !sym->object()->is_dynamic())
  530. {
  531. this->gc_mark_symbol(sym);
  532. }
  533. }
  534. for (options::String_set::const_iterator p =
  535. parameters->options().export_dynamic_symbol_begin();
  536. p != parameters->options().export_dynamic_symbol_end();
  537. ++p)
  538. {
  539. const char* name = p->c_str();
  540. Symbol* sym = this->lookup(name);
  541. // It's not an error if a symbol named by --export-dynamic-symbol
  542. // is undefined.
  543. if (sym != NULL
  544. && sym->source() == Symbol::FROM_OBJECT
  545. && !sym->object()->is_dynamic())
  546. {
  547. this->gc_mark_symbol(sym);
  548. }
  549. }
  550. for (Script_options::referenced_const_iterator p =
  551. layout->script_options()->referenced_begin();
  552. p != layout->script_options()->referenced_end();
  553. ++p)
  554. {
  555. Symbol* sym = this->lookup(p->c_str());
  556. gold_assert(sym != NULL);
  557. if (sym->source() == Symbol::FROM_OBJECT
  558. && !sym->object()->is_dynamic())
  559. {
  560. this->gc_mark_symbol(sym);
  561. }
  562. }
  563. }
  564. void
  565. Symbol_table::gc_mark_symbol(Symbol* sym)
  566. {
  567. // Add the object and section to the work list.
  568. bool is_ordinary;
  569. unsigned int shndx = sym->shndx(&is_ordinary);
  570. if (is_ordinary && shndx != elfcpp::SHN_UNDEF && !sym->object()->is_dynamic())
  571. {
  572. gold_assert(this->gc_!= NULL);
  573. Relobj* relobj = static_cast<Relobj*>(sym->object());
  574. this->gc_->worklist().push_back(Section_id(relobj, shndx));
  575. }
  576. parameters->target().gc_mark_symbol(this, sym);
  577. }
  578. // When doing garbage collection, keep symbols that have been seen in
  579. // dynamic objects.
  580. inline void
  581. Symbol_table::gc_mark_dyn_syms(Symbol* sym)
  582. {
  583. if (sym->in_dyn() && sym->source() == Symbol::FROM_OBJECT
  584. && !sym->object()->is_dynamic())
  585. this->gc_mark_symbol(sym);
  586. }
  587. // Make TO a symbol which forwards to FROM.
  588. void
  589. Symbol_table::make_forwarder(Symbol* from, Symbol* to)
  590. {
  591. gold_assert(from != to);
  592. gold_assert(!from->is_forwarder() && !to->is_forwarder());
  593. this->forwarders_[from] = to;
  594. from->set_forwarder();
  595. }
  596. // Resolve the forwards from FROM, returning the real symbol.
  597. Symbol*
  598. Symbol_table::resolve_forwards(const Symbol* from) const
  599. {
  600. gold_assert(from->is_forwarder());
  601. Unordered_map<const Symbol*, Symbol*>::const_iterator p =
  602. this->forwarders_.find(from);
  603. gold_assert(p != this->forwarders_.end());
  604. return p->second;
  605. }
  606. // Look up a symbol by name.
  607. Symbol*
  608. Symbol_table::lookup(const char* name, const char* version) const
  609. {
  610. Stringpool::Key name_key;
  611. name = this->namepool_.find(name, &name_key);
  612. if (name == NULL)
  613. return NULL;
  614. Stringpool::Key version_key = 0;
  615. if (version != NULL)
  616. {
  617. version = this->namepool_.find(version, &version_key);
  618. if (version == NULL)
  619. return NULL;
  620. }
  621. Symbol_table_key key(name_key, version_key);
  622. Symbol_table::Symbol_table_type::const_iterator p = this->table_.find(key);
  623. if (p == this->table_.end())
  624. return NULL;
  625. return p->second;
  626. }
  627. // Resolve a Symbol with another Symbol. This is only used in the
  628. // unusual case where there are references to both an unversioned
  629. // symbol and a symbol with a version, and we then discover that that
  630. // version is the default version. Because this is unusual, we do
  631. // this the slow way, by converting back to an ELF symbol.
  632. template<int size, bool big_endian>
  633. void
  634. Symbol_table::resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from)
  635. {
  636. unsigned char buf[elfcpp::Elf_sizes<size>::sym_size];
  637. elfcpp::Sym_write<size, big_endian> esym(buf);
  638. // We don't bother to set the st_name or the st_shndx field.
  639. esym.put_st_value(from->value());
  640. esym.put_st_size(from->symsize());
  641. esym.put_st_info(from->binding(), from->type());
  642. esym.put_st_other(from->visibility(), from->nonvis());
  643. bool is_ordinary;
  644. unsigned int shndx = from->shndx(&is_ordinary);
  645. this->resolve(to, esym.sym(), shndx, is_ordinary, shndx, from->object(),
  646. from->version(), true);
  647. if (from->in_reg())
  648. to->set_in_reg();
  649. if (from->in_dyn())
  650. to->set_in_dyn();
  651. if (parameters->options().gc_sections())
  652. this->gc_mark_dyn_syms(to);
  653. }
  654. // Record that a symbol is forced to be local by a version script or
  655. // by visibility.
  656. void
  657. Symbol_table::force_local(Symbol* sym)
  658. {
  659. if (!sym->is_defined() && !sym->is_common())
  660. return;
  661. if (sym->is_forced_local())
  662. {
  663. // We already got this one.
  664. return;
  665. }
  666. sym->set_is_forced_local();
  667. this->forced_locals_.push_back(sym);
  668. }
  669. // Adjust NAME for wrapping, and update *NAME_KEY if necessary. This
  670. // is only called for undefined symbols, when at least one --wrap
  671. // option was used.
  672. const char*
  673. Symbol_table::wrap_symbol(const char* name, Stringpool::Key* name_key)
  674. {
  675. // For some targets, we need to ignore a specific character when
  676. // wrapping, and add it back later.
  677. char prefix = '\0';
  678. if (name[0] == parameters->target().wrap_char())
  679. {
  680. prefix = name[0];
  681. ++name;
  682. }
  683. if (parameters->options().is_wrap(name))
  684. {
  685. // Turn NAME into __wrap_NAME.
  686. std::string s;
  687. if (prefix != '\0')
  688. s += prefix;
  689. s += "__wrap_";
  690. s += name;
  691. // This will give us both the old and new name in NAMEPOOL_, but
  692. // that is OK. Only the versions we need will wind up in the
  693. // real string table in the output file.
  694. return this->namepool_.add(s.c_str(), true, name_key);
  695. }
  696. const char* const real_prefix = "__real_";
  697. const size_t real_prefix_length = strlen(real_prefix);
  698. if (strncmp(name, real_prefix, real_prefix_length) == 0
  699. && parameters->options().is_wrap(name + real_prefix_length))
  700. {
  701. // Turn __real_NAME into NAME.
  702. std::string s;
  703. if (prefix != '\0')
  704. s += prefix;
  705. s += name + real_prefix_length;
  706. return this->namepool_.add(s.c_str(), true, name_key);
  707. }
  708. return name;
  709. }
  710. // This is called when we see a symbol NAME/VERSION, and the symbol
  711. // already exists in the symbol table, and VERSION is marked as being
  712. // the default version. SYM is the NAME/VERSION symbol we just added.
  713. // DEFAULT_IS_NEW is true if this is the first time we have seen the
  714. // symbol NAME/NULL. PDEF points to the entry for NAME/NULL.
  715. template<int size, bool big_endian>
  716. void
  717. Symbol_table::define_default_version(Sized_symbol<size>* sym,
  718. bool default_is_new,
  719. Symbol_table_type::iterator pdef)
  720. {
  721. if (default_is_new)
  722. {
  723. // This is the first time we have seen NAME/NULL. Make
  724. // NAME/NULL point to NAME/VERSION, and mark SYM as the default
  725. // version.
  726. pdef->second = sym;
  727. sym->set_is_default();
  728. }
  729. else if (pdef->second == sym)
  730. {
  731. // NAME/NULL already points to NAME/VERSION. Don't mark the
  732. // symbol as the default if it is not already the default.
  733. }
  734. else
  735. {
  736. // This is the unfortunate case where we already have entries
  737. // for both NAME/VERSION and NAME/NULL. We now see a symbol
  738. // NAME/VERSION where VERSION is the default version. We have
  739. // already resolved this new symbol with the existing
  740. // NAME/VERSION symbol.
  741. // It's possible that NAME/NULL and NAME/VERSION are both
  742. // defined in regular objects. This can only happen if one
  743. // object file defines foo and another defines foo@@ver. This
  744. // is somewhat obscure, but we call it a multiple definition
  745. // error.
  746. // It's possible that NAME/NULL actually has a version, in which
  747. // case it won't be the same as VERSION. This happens with
  748. // ver_test_7.so in the testsuite for the symbol t2_2. We see
  749. // t2_2@@VER2, so we define both t2_2/VER2 and t2_2/NULL. We
  750. // then see an unadorned t2_2 in an object file and give it
  751. // version VER1 from the version script. This looks like a
  752. // default definition for VER1, so it looks like we should merge
  753. // t2_2/NULL with t2_2/VER1. That doesn't make sense, but it's
  754. // not obvious that this is an error, either. So we just punt.
  755. // If one of the symbols has non-default visibility, and the
  756. // other is defined in a shared object, then they are different
  757. // symbols.
  758. // Otherwise, we just resolve the symbols as though they were
  759. // the same.
  760. if (pdef->second->version() != NULL)
  761. gold_assert(pdef->second->version() != sym->version());
  762. else if (sym->visibility() != elfcpp::STV_DEFAULT
  763. && pdef->second->is_from_dynobj())
  764. ;
  765. else if (pdef->second->visibility() != elfcpp::STV_DEFAULT
  766. && sym->is_from_dynobj())
  767. ;
  768. else
  769. {
  770. const Sized_symbol<size>* symdef;
  771. symdef = this->get_sized_symbol<size>(pdef->second);
  772. Symbol_table::resolve<size, big_endian>(sym, symdef);
  773. this->make_forwarder(pdef->second, sym);
  774. pdef->second = sym;
  775. sym->set_is_default();
  776. }
  777. }
  778. }
  779. // Add one symbol from OBJECT to the symbol table. NAME is symbol
  780. // name and VERSION is the version; both are canonicalized. DEF is
  781. // whether this is the default version. ST_SHNDX is the symbol's
  782. // section index; IS_ORDINARY is whether this is a normal section
  783. // rather than a special code.
  784. // If IS_DEFAULT_VERSION is true, then this is the definition of a
  785. // default version of a symbol. That means that any lookup of
  786. // NAME/NULL and any lookup of NAME/VERSION should always return the
  787. // same symbol. This is obvious for references, but in particular we
  788. // want to do this for definitions: overriding NAME/NULL should also
  789. // override NAME/VERSION. If we don't do that, it would be very hard
  790. // to override functions in a shared library which uses versioning.
  791. // We implement this by simply making both entries in the hash table
  792. // point to the same Symbol structure. That is easy enough if this is
  793. // the first time we see NAME/NULL or NAME/VERSION, but it is possible
  794. // that we have seen both already, in which case they will both have
  795. // independent entries in the symbol table. We can't simply change
  796. // the symbol table entry, because we have pointers to the entries
  797. // attached to the object files. So we mark the entry attached to the
  798. // object file as a forwarder, and record it in the forwarders_ map.
  799. // Note that entries in the hash table will never be marked as
  800. // forwarders.
  801. //
  802. // ORIG_ST_SHNDX and ST_SHNDX are almost always the same.
  803. // ORIG_ST_SHNDX is the section index in the input file, or SHN_UNDEF
  804. // for a special section code. ST_SHNDX may be modified if the symbol
  805. // is defined in a section being discarded.
  806. template<int size, bool big_endian>
  807. Sized_symbol<size>*
  808. Symbol_table::add_from_object(Object* object,
  809. const char* name,
  810. Stringpool::Key name_key,
  811. const char* version,
  812. Stringpool::Key version_key,
  813. bool is_default_version,
  814. const elfcpp::Sym<size, big_endian>& sym,
  815. unsigned int st_shndx,
  816. bool is_ordinary,
  817. unsigned int orig_st_shndx)
  818. {
  819. // Print a message if this symbol is being traced.
  820. if (parameters->options().is_trace_symbol(name))
  821. {
  822. if (orig_st_shndx == elfcpp::SHN_UNDEF)
  823. gold_info(_("%s: reference to %s"), object->name().c_str(), name);
  824. else
  825. gold_info(_("%s: definition of %s"), object->name().c_str(), name);
  826. }
  827. // For an undefined symbol, we may need to adjust the name using
  828. // --wrap.
  829. if (orig_st_shndx == elfcpp::SHN_UNDEF
  830. && parameters->options().any_wrap())
  831. {
  832. const char* wrap_name = this->wrap_symbol(name, &name_key);
  833. if (wrap_name != name)
  834. {
  835. // If we see a reference to malloc with version GLIBC_2.0,
  836. // and we turn it into a reference to __wrap_malloc, then we
  837. // discard the version number. Otherwise the user would be
  838. // required to specify the correct version for
  839. // __wrap_malloc.
  840. version = NULL;
  841. version_key = 0;
  842. name = wrap_name;
  843. }
  844. }
  845. Symbol* const snull = NULL;
  846. std::pair<typename Symbol_table_type::iterator, bool> ins =
  847. this->table_.insert(std::make_pair(std::make_pair(name_key, version_key),
  848. snull));
  849. std::pair<typename Symbol_table_type::iterator, bool> insdefault =
  850. std::make_pair(this->table_.end(), false);
  851. if (is_default_version)
  852. {
  853. const Stringpool::Key vnull_key = 0;
  854. insdefault = this->table_.insert(std::make_pair(std::make_pair(name_key,
  855. vnull_key),
  856. snull));
  857. }
  858. // ins.first: an iterator, which is a pointer to a pair.
  859. // ins.first->first: the key (a pair of name and version).
  860. // ins.first->second: the value (Symbol*).
  861. // ins.second: true if new entry was inserted, false if not.
  862. Sized_symbol<size>* ret;
  863. bool was_undefined;
  864. bool was_common;
  865. if (!ins.second)
  866. {
  867. // We already have an entry for NAME/VERSION.
  868. ret = this->get_sized_symbol<size>(ins.first->second);
  869. gold_assert(ret != NULL);
  870. was_undefined = ret->is_undefined();
  871. // Commons from plugins are just placeholders.
  872. was_common = ret->is_common() && ret->object()->pluginobj() == NULL;
  873. this->resolve(ret, sym, st_shndx, is_ordinary, orig_st_shndx, object,
  874. version, is_default_version);
  875. if (parameters->options().gc_sections())
  876. this->gc_mark_dyn_syms(ret);
  877. if (is_default_version)
  878. this->define_default_version<size, big_endian>(ret, insdefault.second,
  879. insdefault.first);
  880. else
  881. {
  882. bool dummy;
  883. if (version != NULL
  884. && ret->source() == Symbol::FROM_OBJECT
  885. && ret->object() == object
  886. && is_ordinary
  887. && ret->shndx(&dummy) == st_shndx
  888. && ret->is_default())
  889. {
  890. // We have seen NAME/VERSION already, and marked it as the
  891. // default version, but now we see a definition for
  892. // NAME/VERSION that is not the default version. This can
  893. // happen when the assembler generates two symbols for
  894. // a symbol as a result of a ".symver foo,foo@VER"
  895. // directive. We see the first unversioned symbol and
  896. // we may mark it as the default version (from a
  897. // version script); then we see the second versioned
  898. // symbol and we need to override the first.
  899. // In any other case, the two symbols should have generated
  900. // a multiple definition error.
  901. // (See PR gold/18703.)
  902. ret->set_is_not_default();
  903. const Stringpool::Key vnull_key = 0;
  904. this->table_.erase(std::make_pair(name_key, vnull_key));
  905. }
  906. }
  907. }
  908. else
  909. {
  910. // This is the first time we have seen NAME/VERSION.
  911. gold_assert(ins.first->second == NULL);
  912. if (is_default_version && !insdefault.second)
  913. {
  914. // We already have an entry for NAME/NULL. If we override
  915. // it, then change it to NAME/VERSION.
  916. ret = this->get_sized_symbol<size>(insdefault.first->second);
  917. was_undefined = ret->is_undefined();
  918. // Commons from plugins are just placeholders.
  919. was_common = ret->is_common() && ret->object()->pluginobj() == NULL;
  920. this->resolve(ret, sym, st_shndx, is_ordinary, orig_st_shndx, object,
  921. version, is_default_version);
  922. if (parameters->options().gc_sections())
  923. this->gc_mark_dyn_syms(ret);
  924. ins.first->second = ret;
  925. }
  926. else
  927. {
  928. was_undefined = false;
  929. was_common = false;
  930. Sized_target<size, big_endian>* target =
  931. parameters->sized_target<size, big_endian>();
  932. if (!target->has_make_symbol())
  933. ret = new Sized_symbol<size>();
  934. else
  935. {
  936. ret = target->make_symbol();
  937. if (ret == NULL)
  938. {
  939. // This means that we don't want a symbol table
  940. // entry after all.
  941. if (!is_default_version)
  942. this->table_.erase(ins.first);
  943. else
  944. {
  945. this->table_.erase(insdefault.first);
  946. // Inserting INSDEFAULT invalidated INS.
  947. this->table_.erase(std::make_pair(name_key,
  948. version_key));
  949. }
  950. return NULL;
  951. }
  952. }
  953. ret->init_object(name, version, object, sym, st_shndx, is_ordinary);
  954. ins.first->second = ret;
  955. if (is_default_version)
  956. {
  957. // This is the first time we have seen NAME/NULL. Point
  958. // it at the new entry for NAME/VERSION.
  959. gold_assert(insdefault.second);
  960. insdefault.first->second = ret;
  961. }
  962. }
  963. if (is_default_version)
  964. ret->set_is_default();
  965. }
  966. // Record every time we see a new undefined symbol, to speed up
  967. // archive groups.
  968. if (!was_undefined && ret->is_undefined())
  969. {
  970. ++this->saw_undefined_;
  971. if (parameters->options().has_plugins())
  972. parameters->options().plugins()->new_undefined_symbol(ret);
  973. }
  974. // Keep track of common symbols, to speed up common symbol
  975. // allocation. Don't record commons from plugin objects;
  976. // we need to wait until we see the real symbol in the
  977. // replacement file.
  978. if (!was_common && ret->is_common() && ret->object()->pluginobj() == NULL)
  979. {
  980. if (ret->type() == elfcpp::STT_TLS)
  981. this->tls_commons_.push_back(ret);
  982. else if (!is_ordinary
  983. && st_shndx == parameters->target().small_common_shndx())
  984. this->small_commons_.push_back(ret);
  985. else if (!is_ordinary
  986. && st_shndx == parameters->target().large_common_shndx())
  987. this->large_commons_.push_back(ret);
  988. else
  989. this->commons_.push_back(ret);
  990. }
  991. // If we're not doing a relocatable link, then any symbol with
  992. // hidden or internal visibility is local.
  993. if ((ret->visibility() == elfcpp::STV_HIDDEN
  994. || ret->visibility() == elfcpp::STV_INTERNAL)
  995. && (ret->binding() == elfcpp::STB_GLOBAL
  996. || ret->binding() == elfcpp::STB_GNU_UNIQUE
  997. || ret->binding() == elfcpp::STB_WEAK)
  998. && !parameters->options().relocatable())
  999. this->force_local(ret);
  1000. return ret;
  1001. }
  1002. // Add all the symbols in a relocatable object to the hash table.
  1003. template<int size, bool big_endian>
  1004. void
  1005. Symbol_table::add_from_relobj(
  1006. Sized_relobj_file<size, big_endian>* relobj,
  1007. const unsigned char* syms,
  1008. size_t count,
  1009. size_t symndx_offset,
  1010. const char* sym_names,
  1011. size_t sym_name_size,
  1012. typename Sized_relobj_file<size, big_endian>::Symbols* sympointers,
  1013. size_t* defined)
  1014. {
  1015. *defined = 0;
  1016. gold_assert(size == parameters->target().get_size());
  1017. const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
  1018. const bool just_symbols = relobj->just_symbols();
  1019. const unsigned char* p = syms;
  1020. for (size_t i = 0; i < count; ++i, p += sym_size)
  1021. {
  1022. (*sympointers)[i] = NULL;
  1023. elfcpp::Sym<size, big_endian> sym(p);
  1024. unsigned int st_name = sym.get_st_name();
  1025. if (st_name >= sym_name_size)
  1026. {
  1027. relobj->error(_("bad global symbol name offset %u at %zu"),
  1028. st_name, i);
  1029. continue;
  1030. }
  1031. const char* name = sym_names + st_name;
  1032. if (strcmp (name, "__gnu_lto_slim") == 0)
  1033. gold_info(_("%s: plugin needed to handle lto object"),
  1034. relobj->name().c_str());
  1035. bool is_ordinary;
  1036. unsigned int st_shndx = relobj->adjust_sym_shndx(i + symndx_offset,
  1037. sym.get_st_shndx(),
  1038. &is_ordinary);
  1039. unsigned int orig_st_shndx = st_shndx;
  1040. if (!is_ordinary)
  1041. orig_st_shndx = elfcpp::SHN_UNDEF;
  1042. if (st_shndx != elfcpp::SHN_UNDEF)
  1043. ++*defined;
  1044. // A symbol defined in a section which we are not including must
  1045. // be treated as an undefined symbol.
  1046. bool is_defined_in_discarded_section = false;
  1047. if (st_shndx != elfcpp::SHN_UNDEF
  1048. && is_ordinary
  1049. && !relobj->is_section_included(st_shndx)
  1050. && !this->is_section_folded(relobj, st_shndx))
  1051. {
  1052. st_shndx = elfcpp::SHN_UNDEF;
  1053. is_defined_in_discarded_section = true;
  1054. }
  1055. // In an object file, an '@' in the name separates the symbol
  1056. // name from the version name. If there are two '@' characters,
  1057. // this is the default version.
  1058. const char* ver = strchr(name, '@');
  1059. Stringpool::Key ver_key = 0;
  1060. int namelen = 0;
  1061. // IS_DEFAULT_VERSION: is the version default?
  1062. // IS_FORCED_LOCAL: is the symbol forced local?
  1063. bool is_default_version = false;
  1064. bool is_forced_local = false;
  1065. // FIXME: For incremental links, we don't store version information,
  1066. // so we need to ignore version symbols for now.
  1067. if (parameters->incremental_update() && ver != NULL)
  1068. {
  1069. namelen = ver - name;
  1070. ver = NULL;
  1071. }
  1072. if (ver != NULL)
  1073. {
  1074. // The symbol name is of the form foo@VERSION or foo@@VERSION
  1075. namelen = ver - name;
  1076. ++ver;
  1077. if (*ver == '@')
  1078. {
  1079. is_default_version = true;
  1080. ++ver;
  1081. }
  1082. ver = this->namepool_.add(ver, true, &ver_key);
  1083. }
  1084. // We don't want to assign a version to an undefined symbol,
  1085. // even if it is listed in the version script. FIXME: What
  1086. // about a common symbol?
  1087. else
  1088. {
  1089. namelen = strlen(name);
  1090. if (!this->version_script_.empty()
  1091. && st_shndx != elfcpp::SHN_UNDEF)
  1092. {
  1093. // The symbol name did not have a version, but the
  1094. // version script may assign a version anyway.
  1095. std::string version;
  1096. bool is_global;
  1097. if (this->version_script_.get_symbol_version(name, &version,
  1098. &is_global))
  1099. {
  1100. if (!is_global)
  1101. is_forced_local = true;
  1102. else if (!version.empty())
  1103. {
  1104. ver = this->namepool_.add_with_length(version.c_str(),
  1105. version.length(),
  1106. true,
  1107. &ver_key);
  1108. is_default_version = true;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. elfcpp::Sym<size, big_endian>* psym = &sym;
  1114. unsigned char symbuf[sym_size];
  1115. elfcpp::Sym<size, big_endian> sym2(symbuf);
  1116. if (just_symbols)
  1117. {
  1118. memcpy(symbuf, p, sym_size);
  1119. elfcpp::Sym_write<size, big_endian> sw(symbuf);
  1120. if (orig_st_shndx != elfcpp::SHN_UNDEF
  1121. && is_ordinary
  1122. && relobj->e_type() == elfcpp::ET_REL)
  1123. {
  1124. // Symbol values in relocatable object files are section
  1125. // relative. This is normally what we want, but since here
  1126. // we are converting the symbol to absolute we need to add
  1127. // the section address. The section address in an object
  1128. // file is normally zero, but people can use a linker
  1129. // script to change it.
  1130. sw.put_st_value(sym.get_st_value()
  1131. + relobj->section_address(orig_st_shndx));
  1132. }
  1133. st_shndx = elfcpp::SHN_ABS;
  1134. is_ordinary = false;
  1135. psym = &sym2;
  1136. }
  1137. // Fix up visibility if object has no-export set.
  1138. if (relobj->no_export()
  1139. && (orig_st_shndx != elfcpp::SHN_UNDEF || !is_ordinary))
  1140. {
  1141. // We may have copied symbol already above.
  1142. if (psym != &sym2)
  1143. {
  1144. memcpy(symbuf, p, sym_size);
  1145. psym = &sym2;
  1146. }
  1147. elfcpp::STV visibility = sym2.get_st_visibility();
  1148. if (visibility == elfcpp::STV_DEFAULT
  1149. || visibility == elfcpp::STV_PROTECTED)
  1150. {
  1151. elfcpp::Sym_write<size, big_endian> sw(symbuf);
  1152. unsigned char nonvis = sym2.get_st_nonvis();
  1153. sw.put_st_other(elfcpp::STV_HIDDEN, nonvis);
  1154. }
  1155. }
  1156. Stringpool::Key name_key;
  1157. name = this->namepool_.add_with_length(name, namelen, true,
  1158. &name_key);
  1159. Sized_symbol<size>* res;
  1160. res = this->add_from_object(relobj, name, name_key, ver, ver_key,
  1161. is_default_version, *psym, st_shndx,
  1162. is_ordinary, orig_st_shndx);
  1163. if (is_forced_local)
  1164. this->force_local(res);
  1165. // Do not treat this symbol as garbage if this symbol will be
  1166. // exported to the dynamic symbol table. This is true when
  1167. // building a shared library or using --export-dynamic and
  1168. // the symbol is externally visible.
  1169. if (parameters->options().gc_sections()
  1170. && res->is_externally_visible()
  1171. && !res->is_from_dynobj()
  1172. && (parameters->options().shared()
  1173. || parameters->options().export_dynamic()
  1174. || parameters->options().in_dynamic_list(res->name())))
  1175. this->gc_mark_symbol(res);
  1176. if (is_defined_in_discarded_section)
  1177. res->set_is_defined_in_discarded_section();
  1178. (*sympointers)[i] = res;
  1179. }
  1180. }
  1181. // Add a symbol from a plugin-claimed file.
  1182. template<int size, bool big_endian>
  1183. Symbol*
  1184. Symbol_table::add_from_pluginobj(
  1185. Sized_pluginobj<size, big_endian>* obj,
  1186. const char* name,
  1187. const char* ver,
  1188. elfcpp::Sym<size, big_endian>* sym)
  1189. {
  1190. unsigned int st_shndx = sym->get_st_shndx();
  1191. bool is_ordinary = st_shndx < elfcpp::SHN_LORESERVE;
  1192. Stringpool::Key ver_key = 0;
  1193. bool is_default_version = false;
  1194. bool is_forced_local = false;
  1195. if (ver != NULL)
  1196. {
  1197. ver = this->namepool_.add(ver, true, &ver_key);
  1198. }
  1199. // We don't want to assign a version to an undefined symbol,
  1200. // even if it is listed in the version script. FIXME: What
  1201. // about a common symbol?
  1202. else
  1203. {
  1204. if (!this->version_script_.empty()
  1205. && st_shndx != elfcpp::SHN_UNDEF)
  1206. {
  1207. // The symbol name did not have a version, but the
  1208. // version script may assign a version anyway.
  1209. std::string version;
  1210. bool is_global;
  1211. if (this->version_script_.get_symbol_version(name, &version,
  1212. &is_global))
  1213. {
  1214. if (!is_global)
  1215. is_forced_local = true;
  1216. else if (!version.empty())
  1217. {
  1218. ver = this->namepool_.add_with_length(version.c_str(),
  1219. version.length(),
  1220. true,
  1221. &ver_key);
  1222. is_default_version = true;
  1223. }
  1224. }
  1225. }
  1226. }
  1227. Stringpool::Key name_key;
  1228. name = this->namepool_.add(name, true, &name_key);
  1229. Sized_symbol<size>* res;
  1230. res = this->add_from_object(obj, name, name_key, ver, ver_key,
  1231. is_default_version, *sym, st_shndx,
  1232. is_ordinary, st_shndx);
  1233. if (is_forced_local)
  1234. this->force_local(res);
  1235. return res;
  1236. }
  1237. // Add all the symbols in a dynamic object to the hash table.
  1238. template<int size, bool big_endian>
  1239. void
  1240. Symbol_table::add_from_dynobj(
  1241. Sized_dynobj<size, big_endian>* dynobj,
  1242. const unsigned char* syms,
  1243. size_t count,
  1244. const char* sym_names,
  1245. size_t sym_name_size,
  1246. const unsigned char* versym,
  1247. size_t versym_size,
  1248. const std::vector<const char*>* version_map,
  1249. typename Sized_relobj_file<size, big_endian>::Symbols* sympointers,
  1250. size_t* defined)
  1251. {
  1252. *defined = 0;
  1253. gold_assert(size == parameters->target().get_size());
  1254. if (dynobj->just_symbols())
  1255. {
  1256. gold_error(_("--just-symbols does not make sense with a shared object"));
  1257. return;
  1258. }
  1259. // FIXME: For incremental links, we don't store version information,
  1260. // so we need to ignore version symbols for now.
  1261. if (parameters->incremental_update())
  1262. versym = NULL;
  1263. if (versym != NULL && versym_size / 2 < count)
  1264. {
  1265. dynobj->error(_("too few symbol versions"));
  1266. return;
  1267. }
  1268. const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
  1269. // We keep a list of all STT_OBJECT symbols, so that we can resolve
  1270. // weak aliases. This is necessary because if the dynamic object
  1271. // provides the same variable under two names, one of which is a
  1272. // weak definition, and the regular object refers to the weak
  1273. // definition, we have to put both the weak definition and the
  1274. // strong definition into the dynamic symbol table. Given a weak
  1275. // definition, the only way that we can find the corresponding
  1276. // strong definition, if any, is to search the symbol table.
  1277. std::vector<Sized_symbol<size>*> object_symbols;
  1278. const unsigned char* p = syms;
  1279. const unsigned char* vs = versym;
  1280. for (size_t i = 0; i < count; ++i, p += sym_size, vs += 2)
  1281. {
  1282. elfcpp::Sym<size, big_endian> sym(p);
  1283. if (sympointers != NULL)
  1284. (*sympointers)[i] = NULL;
  1285. // Ignore symbols with local binding or that have
  1286. // internal or hidden visibility.
  1287. if (sym.get_st_bind() == elfcpp::STB_LOCAL
  1288. || sym.get_st_visibility() == elfcpp::STV_INTERNAL
  1289. || sym.get_st_visibility() == elfcpp::STV_HIDDEN)
  1290. continue;
  1291. // A protected symbol in a shared library must be treated as a
  1292. // normal symbol when viewed from outside the shared library.
  1293. // Implement this by overriding the visibility here.
  1294. // Likewise, an IFUNC symbol in a shared library must be treated
  1295. // as a normal FUNC symbol.
  1296. elfcpp::Sym<size, big_endian>* psym = &sym;
  1297. unsigned char symbuf[sym_size];
  1298. elfcpp::Sym<size, big_endian> sym2(symbuf);
  1299. if (sym.get_st_visibility() == elfcpp::STV_PROTECTED
  1300. || sym.get_st_type() == elfcpp::STT_GNU_IFUNC)
  1301. {
  1302. memcpy(symbuf, p, sym_size);
  1303. elfcpp::Sym_write<size, big_endian> sw(symbuf);
  1304. if (sym.get_st_visibility() == elfcpp::STV_PROTECTED)
  1305. sw.put_st_other(elfcpp::STV_DEFAULT, sym.get_st_nonvis());
  1306. if (sym.get_st_type() == elfcpp::STT_GNU_IFUNC)
  1307. sw.put_st_info(sym.get_st_bind(), elfcpp::STT_FUNC);
  1308. psym = &sym2;
  1309. }
  1310. unsigned int st_name = psym->get_st_name();
  1311. if (st_name >= sym_name_size)
  1312. {
  1313. dynobj->error(_("bad symbol name offset %u at %zu"),
  1314. st_name, i);
  1315. continue;
  1316. }
  1317. const char* name = sym_names + st_name;
  1318. bool is_ordinary;
  1319. unsigned int st_shndx = dynobj->adjust_sym_shndx(i, psym->get_st_shndx(),
  1320. &is_ordinary);
  1321. if (st_shndx != elfcpp::SHN_UNDEF)
  1322. ++*defined;
  1323. Sized_symbol<size>* res;
  1324. if (versym == NULL)
  1325. {
  1326. Stringpool::Key name_key;
  1327. name = this->namepool_.add(name, true, &name_key);
  1328. res = this->add_from_object(dynobj, name, name_key, NULL, 0,
  1329. false, *psym, st_shndx, is_ordinary,
  1330. st_shndx);
  1331. }
  1332. else
  1333. {
  1334. // Read the version information.
  1335. unsigned int v = elfcpp::Swap<16, big_endian>::readval(vs);
  1336. bool hidden = (v & elfcpp::VERSYM_HIDDEN) != 0;
  1337. v &= elfcpp::VERSYM_VERSION;
  1338. // The Sun documentation says that V can be VER_NDX_LOCAL,
  1339. // or VER_NDX_GLOBAL, or a version index. The meaning of
  1340. // VER_NDX_LOCAL is defined as "Symbol has local scope."
  1341. // The old GNU linker will happily generate VER_NDX_LOCAL
  1342. // for an undefined symbol. I don't know what the Sun
  1343. // linker will generate.
  1344. if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
  1345. && st_shndx != elfcpp::SHN_UNDEF)
  1346. {
  1347. // This symbol should not be visible outside the object.
  1348. continue;
  1349. }
  1350. // At this point we are definitely going to add this symbol.
  1351. Stringpool::Key name_key;
  1352. name = this->namepool_.add(name, true, &name_key);
  1353. if (v == static_cast<unsigned int>(elfcpp::VER_NDX_LOCAL)
  1354. || v == static_cast<unsigned int>(elfcpp::VER_NDX_GLOBAL))
  1355. {
  1356. // This symbol does not have a version.
  1357. res = this->add_from_object(dynobj, name, name_key, NULL, 0,
  1358. false, *psym, st_shndx, is_ordinary,
  1359. st_shndx);
  1360. }
  1361. else
  1362. {
  1363. if (v >= version_map->size())
  1364. {
  1365. dynobj->error(_("versym for symbol %zu out of range: %u"),
  1366. i, v);
  1367. continue;
  1368. }
  1369. const char* version = (*version_map)[v];
  1370. if (version == NULL)
  1371. {
  1372. dynobj->error(_("versym for symbol %zu has no name: %u"),
  1373. i, v);
  1374. continue;
  1375. }
  1376. Stringpool::Key version_key;
  1377. version = this->namepool_.add(version, true, &version_key);
  1378. // If this is an absolute symbol, and the version name
  1379. // and symbol name are the same, then this is the
  1380. // version definition symbol. These symbols exist to
  1381. // support using -u to pull in particular versions. We
  1382. // do not want to record a version for them.
  1383. if (st_shndx == elfcpp::SHN_ABS
  1384. && !is_ordinary
  1385. && name_key == version_key)
  1386. res = this->add_from_object(dynobj, name, name_key, NULL, 0,
  1387. false, *psym, st_shndx, is_ordinary,
  1388. st_shndx);
  1389. else
  1390. {
  1391. const bool is_default_version =
  1392. !hidden && st_shndx != elfcpp::SHN_UNDEF;
  1393. res = this->add_from_object(dynobj, name, name_key, version,
  1394. version_key, is_default_version,
  1395. *psym, st_shndx,
  1396. is_ordinary, st_shndx);
  1397. }
  1398. }
  1399. }
  1400. // Note that it is possible that RES was overridden by an
  1401. // earlier object, in which case it can't be aliased here.
  1402. if (st_shndx != elfcpp::SHN_UNDEF
  1403. && is_ordinary
  1404. && psym->get_st_type() == elfcpp::STT_OBJECT
  1405. && res->source() == Symbol::FROM_OBJECT
  1406. && res->object() == dynobj)
  1407. object_symbols.push_back(res);
  1408. if (sympointers != NULL)
  1409. (*sympointers)[i] = res;
  1410. }
  1411. this->record_weak_aliases(&object_symbols);
  1412. }
  1413. // Add a symbol from a incremental object file.
  1414. template<int size, bool big_endian>
  1415. Sized_symbol<size>*
  1416. Symbol_table::add_from_incrobj(
  1417. Object* obj,
  1418. const char* name,
  1419. const char* ver,
  1420. elfcpp::Sym<size, big_endian>* sym)
  1421. {
  1422. unsigned int st_shndx = sym->get_st_shndx();
  1423. bool is_ordinary = st_shndx < elfcpp::SHN_LORESERVE;
  1424. Stringpool::Key ver_key = 0;
  1425. bool is_default_version = false;
  1426. bool is_forced_local = false;
  1427. Stringpool::Key name_key;
  1428. name = this->namepool_.add(name, true, &name_key);
  1429. Sized_symbol<size>* res;
  1430. res = this->add_from_object(obj, name, name_key, ver, ver_key,
  1431. is_default_version, *sym, st_shndx,
  1432. is_ordinary, st_shndx);
  1433. if (is_forced_local)
  1434. this->force_local(res);
  1435. return res;
  1436. }
  1437. // This is used to sort weak aliases. We sort them first by section
  1438. // index, then by offset, then by weak ahead of strong.
  1439. template<int size>
  1440. class Weak_alias_sorter
  1441. {
  1442. public:
  1443. bool operator()(const Sized_symbol<size>*, const Sized_symbol<size>*) const;
  1444. };
  1445. template<int size>
  1446. bool
  1447. Weak_alias_sorter<size>::operator()(const Sized_symbol<size>* s1,
  1448. const Sized_symbol<size>* s2) const
  1449. {
  1450. bool is_ordinary;
  1451. unsigned int s1_shndx = s1->shndx(&is_ordinary);
  1452. gold_assert(is_ordinary);
  1453. unsigned int s2_shndx = s2->shndx(&is_ordinary);
  1454. gold_assert(is_ordinary);
  1455. if (s1_shndx != s2_shndx)
  1456. return s1_shndx < s2_shndx;
  1457. if (s1->value() != s2->value())
  1458. return s1->value() < s2->value();
  1459. if (s1->binding() != s2->binding())
  1460. {
  1461. if (s1->binding() == elfcpp::STB_WEAK)
  1462. return true;
  1463. if (s2->binding() == elfcpp::STB_WEAK)
  1464. return false;
  1465. }
  1466. return std::string(s1->name()) < std::string(s2->name());
  1467. }
  1468. // SYMBOLS is a list of object symbols from a dynamic object. Look
  1469. // for any weak aliases, and record them so that if we add the weak
  1470. // alias to the dynamic symbol table, we also add the corresponding
  1471. // strong symbol.
  1472. template<int size>
  1473. void
  1474. Symbol_table::record_weak_aliases(std::vector<Sized_symbol<size>*>* symbols)
  1475. {
  1476. // Sort the vector by section index, then by offset, then by weak
  1477. // ahead of strong.
  1478. std::sort(symbols->begin(), symbols->end(), Weak_alias_sorter<size>());
  1479. // Walk through the vector. For each weak definition, record
  1480. // aliases.
  1481. for (typename std::vector<Sized_symbol<size>*>::const_iterator p =
  1482. symbols->begin();
  1483. p != symbols->end();
  1484. ++p)
  1485. {
  1486. if ((*p)->binding() != elfcpp::STB_WEAK)
  1487. continue;
  1488. // Build a circular list of weak aliases. Each symbol points to
  1489. // the next one in the circular list.
  1490. Sized_symbol<size>* from_sym = *p;
  1491. typename std::vector<Sized_symbol<size>*>::const_iterator q;
  1492. for (q = p + 1; q != symbols->end(); ++q)
  1493. {
  1494. bool dummy;
  1495. if ((*q)->shndx(&dummy) != from_sym->shndx(&dummy)
  1496. || (*q)->value() != from_sym->value())
  1497. break;
  1498. this->weak_aliases_[from_sym] = *q;
  1499. from_sym->set_has_alias();
  1500. from_sym = *q;
  1501. }
  1502. if (from_sym != *p)
  1503. {
  1504. this->weak_aliases_[from_sym] = *p;
  1505. from_sym->set_has_alias();
  1506. }
  1507. p = q - 1;
  1508. }
  1509. }
  1510. // Create and return a specially defined symbol. If ONLY_IF_REF is
  1511. // true, then only create the symbol if there is a reference to it.
  1512. // If this does not return NULL, it sets *POLDSYM to the existing
  1513. // symbol if there is one. This sets *RESOLVE_OLDSYM if we should
  1514. // resolve the newly created symbol to the old one. This
  1515. // canonicalizes *PNAME and *PVERSION.
  1516. template<int size, bool big_endian>
  1517. Sized_symbol<size>*
  1518. Symbol_table::define_special_symbol(const char** pname, const char** pversion,
  1519. bool only_if_ref,
  1520. Sized_symbol<size>** poldsym,
  1521. bool* resolve_oldsym)
  1522. {
  1523. *resolve_oldsym = false;
  1524. *poldsym = NULL;
  1525. // If the caller didn't give us a version, see if we get one from
  1526. // the version script.
  1527. std::string v;
  1528. bool is_default_version = false;
  1529. if (*pversion == NULL)
  1530. {
  1531. bool is_global;
  1532. if (this->version_script_.get_symbol_version(*pname, &v, &is_global))
  1533. {
  1534. if (is_global && !v.empty())
  1535. {
  1536. *pversion = v.c_str();
  1537. // If we get the version from a version script, then we
  1538. // are also the default version.
  1539. is_default_version = true;
  1540. }
  1541. }
  1542. }
  1543. Symbol* oldsym;
  1544. Sized_symbol<size>* sym;
  1545. bool add_to_table = false;
  1546. typename Symbol_table_type::iterator add_loc = this->table_.end();
  1547. bool add_def_to_table = false;
  1548. typename Symbol_table_type::iterator add_def_loc = this->table_.end();
  1549. if (only_if_ref)
  1550. {
  1551. oldsym = this->lookup(*pname, *pversion);
  1552. if (oldsym == NULL && is_default_version)
  1553. oldsym = this->lookup(*pname, NULL);
  1554. if (oldsym == NULL || !oldsym->is_undefined())
  1555. return NULL;
  1556. *pname = oldsym->name();
  1557. if (is_default_version)
  1558. *pversion = this->namepool_.add(*pversion, true, NULL);
  1559. else
  1560. *pversion = oldsym->version();
  1561. }
  1562. else
  1563. {
  1564. // Canonicalize NAME and VERSION.
  1565. Stringpool::Key name_key;
  1566. *pname = this->namepool_.add(*pname, true, &name_key);
  1567. Stringpool::Key version_key = 0;
  1568. if (*pversion != NULL)
  1569. *pversion = this->namepool_.add(*pversion, true, &version_key);
  1570. Symbol* const snull = NULL;
  1571. std::pair<typename Symbol_table_type::iterator, bool> ins =
  1572. this->table_.insert(std::make_pair(std::make_pair(name_key,
  1573. version_key),
  1574. snull));
  1575. std::pair<typename Symbol_table_type::iterator, bool> insdefault =
  1576. std::make_pair(this->table_.end(), false);
  1577. if (is_default_version)
  1578. {
  1579. const Stringpool::Key vnull = 0;
  1580. insdefault =
  1581. this->table_.insert(std::make_pair(std::make_pair(name_key,
  1582. vnull),
  1583. snull));
  1584. }
  1585. if (!ins.second)
  1586. {
  1587. // We already have a symbol table entry for NAME/VERSION.
  1588. oldsym = ins.first->second;
  1589. gold_assert(oldsym != NULL);
  1590. if (is_default_version)
  1591. {
  1592. Sized_symbol<size>* soldsym =
  1593. this->get_sized_symbol<size>(oldsym);
  1594. this->define_default_version<size, big_endian>(soldsym,
  1595. insdefault.second,
  1596. insdefault.first);
  1597. }
  1598. }
  1599. else
  1600. {
  1601. // We haven't seen this symbol before.
  1602. gold_assert(ins.first->second == NULL);
  1603. add_to_table = true;
  1604. add_loc = ins.first;
  1605. if (is_default_version && !insdefault.second)
  1606. {
  1607. // We are adding NAME/VERSION, and it is the default
  1608. // version. We already have an entry for NAME/NULL.
  1609. oldsym = insdefault.first->second;
  1610. *resolve_oldsym = true;
  1611. }
  1612. else
  1613. {
  1614. oldsym = NULL;
  1615. if (is_default_version)
  1616. {
  1617. add_def_to_table = true;
  1618. add_def_loc = insdefault.first;
  1619. }
  1620. }
  1621. }
  1622. }
  1623. const Target& target = parameters->target();
  1624. if (!target.has_make_symbol())
  1625. sym = new Sized_symbol<size>();
  1626. else
  1627. {
  1628. Sized_target<size, big_endian>* sized_target =
  1629. parameters->sized_target<size, big_endian>();
  1630. sym = sized_target->make_symbol();
  1631. if (sym == NULL)
  1632. return NULL;
  1633. }
  1634. if (add_to_table)
  1635. add_loc->second = sym;
  1636. else
  1637. gold_assert(oldsym != NULL);
  1638. if (add_def_to_table)
  1639. add_def_loc->second = sym;
  1640. *poldsym = this->get_sized_symbol<size>(oldsym);
  1641. return sym;
  1642. }
  1643. // Define a symbol based on an Output_data.
  1644. Symbol*
  1645. Symbol_table::define_in_output_data(const char* name,
  1646. const char* version,
  1647. Defined defined,
  1648. Output_data* od,
  1649. uint64_t value,
  1650. uint64_t symsize,
  1651. elfcpp::STT type,
  1652. elfcpp::STB binding,
  1653. elfcpp::STV visibility,
  1654. unsigned char nonvis,
  1655. bool offset_is_from_end,
  1656. bool only_if_ref)
  1657. {
  1658. if (parameters->target().get_size() == 32)
  1659. {
  1660. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
  1661. return this->do_define_in_output_data<32>(name, version, defined, od,
  1662. value, symsize, type, binding,
  1663. visibility, nonvis,
  1664. offset_is_from_end,
  1665. only_if_ref);
  1666. #else
  1667. gold_unreachable();
  1668. #endif
  1669. }
  1670. else if (parameters->target().get_size() == 64)
  1671. {
  1672. #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
  1673. return this->do_define_in_output_data<64>(name, version, defined, od,
  1674. value, symsize, type, binding,
  1675. visibility, nonvis,
  1676. offset_is_from_end,
  1677. only_if_ref);
  1678. #else
  1679. gold_unreachable();
  1680. #endif
  1681. }
  1682. else
  1683. gold_unreachable();
  1684. }
  1685. // Define a symbol in an Output_data, sized version.
  1686. template<int size>
  1687. Sized_symbol<size>*
  1688. Symbol_table::do_define_in_output_data(
  1689. const char* name,
  1690. const char* version,
  1691. Defined defined,
  1692. Output_data* od,
  1693. typename elfcpp::Elf_types<size>::Elf_Addr value,
  1694. typename elfcpp::Elf_types<size>::Elf_WXword symsize,
  1695. elfcpp::STT type,
  1696. elfcpp::STB binding,
  1697. elfcpp::STV visibility,
  1698. unsigned char nonvis,
  1699. bool offset_is_from_end,
  1700. bool only_if_ref)
  1701. {
  1702. Sized_symbol<size>* sym;
  1703. Sized_symbol<size>* oldsym;
  1704. bool resolve_oldsym;
  1705. if (parameters->target().is_big_endian())
  1706. {
  1707. #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
  1708. sym = this->define_special_symbol<size, true>(&name, &version,
  1709. only_if_ref, &oldsym,
  1710. &resolve_oldsym);
  1711. #else
  1712. gold_unreachable();
  1713. #endif
  1714. }
  1715. else
  1716. {
  1717. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
  1718. sym = this->define_special_symbol<size, false>(&name, &version,
  1719. only_if_ref, &oldsym,
  1720. &resolve_oldsym);
  1721. #else
  1722. gold_unreachable();
  1723. #endif
  1724. }
  1725. if (sym == NULL)
  1726. return NULL;
  1727. sym->init_output_data(name, version, od, value, symsize, type, binding,
  1728. visibility, nonvis, offset_is_from_end,
  1729. defined == PREDEFINED);
  1730. if (oldsym == NULL)
  1731. {
  1732. if (binding == elfcpp::STB_LOCAL
  1733. || this->version_script_.symbol_is_local(name))
  1734. this->force_local(sym);
  1735. else if (version != NULL)
  1736. sym->set_is_default();
  1737. return sym;
  1738. }
  1739. if (Symbol_table::should_override_with_special(oldsym, type, defined))
  1740. this->override_with_special(oldsym, sym);
  1741. if (resolve_oldsym)
  1742. return sym;
  1743. else
  1744. {
  1745. if (binding == elfcpp::STB_LOCAL
  1746. || this->version_script_.symbol_is_local(name))
  1747. this->force_local(oldsym);
  1748. delete sym;
  1749. return oldsym;
  1750. }
  1751. }
  1752. // Define a symbol based on an Output_segment.
  1753. Symbol*
  1754. Symbol_table::define_in_output_segment(const char* name,
  1755. const char* version,
  1756. Defined defined,
  1757. Output_segment* os,
  1758. uint64_t value,
  1759. uint64_t symsize,
  1760. elfcpp::STT type,
  1761. elfcpp::STB binding,
  1762. elfcpp::STV visibility,
  1763. unsigned char nonvis,
  1764. Symbol::Segment_offset_base offset_base,
  1765. bool only_if_ref)
  1766. {
  1767. if (parameters->target().get_size() == 32)
  1768. {
  1769. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
  1770. return this->do_define_in_output_segment<32>(name, version, defined, os,
  1771. value, symsize, type,
  1772. binding, visibility, nonvis,
  1773. offset_base, only_if_ref);
  1774. #else
  1775. gold_unreachable();
  1776. #endif
  1777. }
  1778. else if (parameters->target().get_size() == 64)
  1779. {
  1780. #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
  1781. return this->do_define_in_output_segment<64>(name, version, defined, os,
  1782. value, symsize, type,
  1783. binding, visibility, nonvis,
  1784. offset_base, only_if_ref);
  1785. #else
  1786. gold_unreachable();
  1787. #endif
  1788. }
  1789. else
  1790. gold_unreachable();
  1791. }
  1792. // Define a symbol in an Output_segment, sized version.
  1793. template<int size>
  1794. Sized_symbol<size>*
  1795. Symbol_table::do_define_in_output_segment(
  1796. const char* name,
  1797. const char* version,
  1798. Defined defined,
  1799. Output_segment* os,
  1800. typename elfcpp::Elf_types<size>::Elf_Addr value,
  1801. typename elfcpp::Elf_types<size>::Elf_WXword symsize,
  1802. elfcpp::STT type,
  1803. elfcpp::STB binding,
  1804. elfcpp::STV visibility,
  1805. unsigned char nonvis,
  1806. Symbol::Segment_offset_base offset_base,
  1807. bool only_if_ref)
  1808. {
  1809. Sized_symbol<size>* sym;
  1810. Sized_symbol<size>* oldsym;
  1811. bool resolve_oldsym;
  1812. if (parameters->target().is_big_endian())
  1813. {
  1814. #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
  1815. sym = this->define_special_symbol<size, true>(&name, &version,
  1816. only_if_ref, &oldsym,
  1817. &resolve_oldsym);
  1818. #else
  1819. gold_unreachable();
  1820. #endif
  1821. }
  1822. else
  1823. {
  1824. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
  1825. sym = this->define_special_symbol<size, false>(&name, &version,
  1826. only_if_ref, &oldsym,
  1827. &resolve_oldsym);
  1828. #else
  1829. gold_unreachable();
  1830. #endif
  1831. }
  1832. if (sym == NULL)
  1833. return NULL;
  1834. sym->init_output_segment(name, version, os, value, symsize, type, binding,
  1835. visibility, nonvis, offset_base,
  1836. defined == PREDEFINED);
  1837. if (oldsym == NULL)
  1838. {
  1839. if (binding == elfcpp::STB_LOCAL
  1840. || this->version_script_.symbol_is_local(name))
  1841. this->force_local(sym);
  1842. else if (version != NULL)
  1843. sym->set_is_default();
  1844. return sym;
  1845. }
  1846. if (Symbol_table::should_override_with_special(oldsym, type, defined))
  1847. this->override_with_special(oldsym, sym);
  1848. if (resolve_oldsym)
  1849. return sym;
  1850. else
  1851. {
  1852. if (binding == elfcpp::STB_LOCAL
  1853. || this->version_script_.symbol_is_local(name))
  1854. this->force_local(oldsym);
  1855. delete sym;
  1856. return oldsym;
  1857. }
  1858. }
  1859. // Define a special symbol with a constant value. It is a multiple
  1860. // definition error if this symbol is already defined.
  1861. Symbol*
  1862. Symbol_table::define_as_constant(const char* name,
  1863. const char* version,
  1864. Defined defined,
  1865. uint64_t value,
  1866. uint64_t symsize,
  1867. elfcpp::STT type,
  1868. elfcpp::STB binding,
  1869. elfcpp::STV visibility,
  1870. unsigned char nonvis,
  1871. bool only_if_ref,
  1872. bool force_override)
  1873. {
  1874. if (parameters->target().get_size() == 32)
  1875. {
  1876. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
  1877. return this->do_define_as_constant<32>(name, version, defined, value,
  1878. symsize, type, binding,
  1879. visibility, nonvis, only_if_ref,
  1880. force_override);
  1881. #else
  1882. gold_unreachable();
  1883. #endif
  1884. }
  1885. else if (parameters->target().get_size() == 64)
  1886. {
  1887. #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
  1888. return this->do_define_as_constant<64>(name, version, defined, value,
  1889. symsize, type, binding,
  1890. visibility, nonvis, only_if_ref,
  1891. force_override);
  1892. #else
  1893. gold_unreachable();
  1894. #endif
  1895. }
  1896. else
  1897. gold_unreachable();
  1898. }
  1899. // Define a symbol as a constant, sized version.
  1900. template<int size>
  1901. Sized_symbol<size>*
  1902. Symbol_table::do_define_as_constant(
  1903. const char* name,
  1904. const char* version,
  1905. Defined defined,
  1906. typename elfcpp::Elf_types<size>::Elf_Addr value,
  1907. typename elfcpp::Elf_types<size>::Elf_WXword symsize,
  1908. elfcpp::STT type,
  1909. elfcpp::STB binding,
  1910. elfcpp::STV visibility,
  1911. unsigned char nonvis,
  1912. bool only_if_ref,
  1913. bool force_override)
  1914. {
  1915. Sized_symbol<size>* sym;
  1916. Sized_symbol<size>* oldsym;
  1917. bool resolve_oldsym;
  1918. if (parameters->target().is_big_endian())
  1919. {
  1920. #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
  1921. sym = this->define_special_symbol<size, true>(&name, &version,
  1922. only_if_ref, &oldsym,
  1923. &resolve_oldsym);
  1924. #else
  1925. gold_unreachable();
  1926. #endif
  1927. }
  1928. else
  1929. {
  1930. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
  1931. sym = this->define_special_symbol<size, false>(&name, &version,
  1932. only_if_ref, &oldsym,
  1933. &resolve_oldsym);
  1934. #else
  1935. gold_unreachable();
  1936. #endif
  1937. }
  1938. if (sym == NULL)
  1939. return NULL;
  1940. sym->init_constant(name, version, value, symsize, type, binding, visibility,
  1941. nonvis, defined == PREDEFINED);
  1942. if (oldsym == NULL)
  1943. {
  1944. // Version symbols are absolute symbols with name == version.
  1945. // We don't want to force them to be local.
  1946. if ((version == NULL
  1947. || name != version
  1948. || value != 0)
  1949. && (binding == elfcpp::STB_LOCAL
  1950. || this->version_script_.symbol_is_local(name)))
  1951. this->force_local(sym);
  1952. else if (version != NULL
  1953. && (name != version || value != 0))
  1954. sym->set_is_default();
  1955. return sym;
  1956. }
  1957. if (force_override
  1958. || Symbol_table::should_override_with_special(oldsym, type, defined))
  1959. this->override_with_special(oldsym, sym);
  1960. if (resolve_oldsym)
  1961. return sym;
  1962. else
  1963. {
  1964. if (binding == elfcpp::STB_LOCAL
  1965. || this->version_script_.symbol_is_local(name))
  1966. this->force_local(oldsym);
  1967. delete sym;
  1968. return oldsym;
  1969. }
  1970. }
  1971. // Define a set of symbols in output sections.
  1972. void
  1973. Symbol_table::define_symbols(const Layout* layout, int count,
  1974. const Define_symbol_in_section* p,
  1975. bool only_if_ref)
  1976. {
  1977. for (int i = 0; i < count; ++i, ++p)
  1978. {
  1979. Output_section* os = layout->find_output_section(p->output_section);
  1980. if (os != NULL)
  1981. this->define_in_output_data(p->name, NULL, PREDEFINED, os, p->value,
  1982. p->size, p->type, p->binding,
  1983. p->visibility, p->nonvis,
  1984. p->offset_is_from_end,
  1985. only_if_ref || p->only_if_ref);
  1986. else
  1987. this->define_as_constant(p->name, NULL, PREDEFINED, 0, p->size,
  1988. p->type, p->binding, p->visibility, p->nonvis,
  1989. only_if_ref || p->only_if_ref,
  1990. false);
  1991. }
  1992. }
  1993. // Define a set of symbols in output segments.
  1994. void
  1995. Symbol_table::define_symbols(const Layout* layout, int count,
  1996. const Define_symbol_in_segment* p,
  1997. bool only_if_ref)
  1998. {
  1999. for (int i = 0; i < count; ++i, ++p)
  2000. {
  2001. Output_segment* os = layout->find_output_segment(p->segment_type,
  2002. p->segment_flags_set,
  2003. p->segment_flags_clear);
  2004. if (os != NULL)
  2005. this->define_in_output_segment(p->name, NULL, PREDEFINED, os, p->value,
  2006. p->size, p->type, p->binding,
  2007. p->visibility, p->nonvis,
  2008. p->offset_base,
  2009. only_if_ref || p->only_if_ref);
  2010. else
  2011. this->define_as_constant(p->name, NULL, PREDEFINED, 0, p->size,
  2012. p->type, p->binding, p->visibility, p->nonvis,
  2013. only_if_ref || p->only_if_ref,
  2014. false);
  2015. }
  2016. }
  2017. // Define CSYM using a COPY reloc. POSD is the Output_data where the
  2018. // symbol should be defined--typically a .dyn.bss section. VALUE is
  2019. // the offset within POSD.
  2020. template<int size>
  2021. void
  2022. Symbol_table::define_with_copy_reloc(
  2023. Sized_symbol<size>* csym,
  2024. Output_data* posd,
  2025. typename elfcpp::Elf_types<size>::Elf_Addr value)
  2026. {
  2027. gold_assert(csym->is_from_dynobj());
  2028. gold_assert(!csym->is_copied_from_dynobj());
  2029. Object* object = csym->object();
  2030. gold_assert(object->is_dynamic());
  2031. Dynobj* dynobj = static_cast<Dynobj*>(object);
  2032. // Our copied variable has to override any variable in a shared
  2033. // library.
  2034. elfcpp::STB binding = csym->binding();
  2035. if (binding == elfcpp::STB_WEAK)
  2036. binding = elfcpp::STB_GLOBAL;
  2037. this->define_in_output_data(csym->name(), csym->version(), COPY,
  2038. posd, value, csym->symsize(),
  2039. csym->type(), binding,
  2040. csym->visibility(), csym->nonvis(),
  2041. false, false);
  2042. csym->set_is_copied_from_dynobj();
  2043. csym->set_needs_dynsym_entry();
  2044. this->copied_symbol_dynobjs_[csym] = dynobj;
  2045. // We have now defined all aliases, but we have not entered them all
  2046. // in the copied_symbol_dynobjs_ map.
  2047. if (csym->has_alias())
  2048. {
  2049. Symbol* sym = csym;
  2050. while (true)
  2051. {
  2052. sym = this->weak_aliases_[sym];
  2053. if (sym == csym)
  2054. break;
  2055. gold_assert(sym->output_data() == posd);
  2056. sym->set_is_copied_from_dynobj();
  2057. this->copied_symbol_dynobjs_[sym] = dynobj;
  2058. }
  2059. }
  2060. }
  2061. // SYM is defined using a COPY reloc. Return the dynamic object where
  2062. // the original definition was found.
  2063. Dynobj*
  2064. Symbol_table::get_copy_source(const Symbol* sym) const
  2065. {
  2066. gold_assert(sym->is_copied_from_dynobj());
  2067. Copied_symbol_dynobjs::const_iterator p =
  2068. this->copied_symbol_dynobjs_.find(sym);
  2069. gold_assert(p != this->copied_symbol_dynobjs_.end());
  2070. return p->second;
  2071. }
  2072. // Add any undefined symbols named on the command line.
  2073. void
  2074. Symbol_table::add_undefined_symbols_from_command_line(Layout* layout)
  2075. {
  2076. if (parameters->options().any_undefined()
  2077. || layout->script_options()->any_unreferenced())
  2078. {
  2079. if (parameters->target().get_size() == 32)
  2080. {
  2081. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
  2082. this->do_add_undefined_symbols_from_command_line<32>(layout);
  2083. #else
  2084. gold_unreachable();
  2085. #endif
  2086. }
  2087. else if (parameters->target().get_size() == 64)
  2088. {
  2089. #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
  2090. this->do_add_undefined_symbols_from_command_line<64>(layout);
  2091. #else
  2092. gold_unreachable();
  2093. #endif
  2094. }
  2095. else
  2096. gold_unreachable();
  2097. }
  2098. }
  2099. template<int size>
  2100. void
  2101. Symbol_table::do_add_undefined_symbols_from_command_line(Layout* layout)
  2102. {
  2103. for (options::String_set::const_iterator p =
  2104. parameters->options().undefined_begin();
  2105. p != parameters->options().undefined_end();
  2106. ++p)
  2107. this->add_undefined_symbol_from_command_line<size>(p->c_str());
  2108. for (options::String_set::const_iterator p =
  2109. parameters->options().export_dynamic_symbol_begin();
  2110. p != parameters->options().export_dynamic_symbol_end();
  2111. ++p)
  2112. this->add_undefined_symbol_from_command_line<size>(p->c_str());
  2113. for (Script_options::referenced_const_iterator p =
  2114. layout->script_options()->referenced_begin();
  2115. p != layout->script_options()->referenced_end();
  2116. ++p)
  2117. this->add_undefined_symbol_from_command_line<size>(p->c_str());
  2118. }
  2119. template<int size>
  2120. void
  2121. Symbol_table::add_undefined_symbol_from_command_line(const char* name)
  2122. {
  2123. if (this->lookup(name) != NULL)
  2124. return;
  2125. const char* version = NULL;
  2126. Sized_symbol<size>* sym;
  2127. Sized_symbol<size>* oldsym;
  2128. bool resolve_oldsym;
  2129. if (parameters->target().is_big_endian())
  2130. {
  2131. #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
  2132. sym = this->define_special_symbol<size, true>(&name, &version,
  2133. false, &oldsym,
  2134. &resolve_oldsym);
  2135. #else
  2136. gold_unreachable();
  2137. #endif
  2138. }
  2139. else
  2140. {
  2141. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
  2142. sym = this->define_special_symbol<size, false>(&name, &version,
  2143. false, &oldsym,
  2144. &resolve_oldsym);
  2145. #else
  2146. gold_unreachable();
  2147. #endif
  2148. }
  2149. gold_assert(oldsym == NULL);
  2150. sym->init_undefined(name, version, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
  2151. elfcpp::STV_DEFAULT, 0);
  2152. ++this->saw_undefined_;
  2153. }
  2154. // Set the dynamic symbol indexes. INDEX is the index of the first
  2155. // global dynamic symbol. Pointers to the symbols are stored into the
  2156. // vector SYMS. The names are added to DYNPOOL. This returns an
  2157. // updated dynamic symbol index.
  2158. unsigned int
  2159. Symbol_table::set_dynsym_indexes(unsigned int index,
  2160. std::vector<Symbol*>* syms,
  2161. Stringpool* dynpool,
  2162. Versions* versions)
  2163. {
  2164. std::vector<Symbol*> as_needed_sym;
  2165. // Allow a target to set dynsym indexes.
  2166. if (parameters->target().has_custom_set_dynsym_indexes())
  2167. {
  2168. std::vector<Symbol*> dyn_symbols;
  2169. for (Symbol_table_type::iterator p = this->table_.begin();
  2170. p != this->table_.end();
  2171. ++p)
  2172. {
  2173. Symbol* sym = p->second;
  2174. if (!sym->should_add_dynsym_entry(this))
  2175. sym->set_dynsym_index(-1U);
  2176. else
  2177. dyn_symbols.push_back(sym);
  2178. }
  2179. return parameters->target().set_dynsym_indexes(&dyn_symbols, index, syms,
  2180. dynpool, versions, this);
  2181. }
  2182. for (Symbol_table_type::iterator p = this->table_.begin();
  2183. p != this->table_.end();
  2184. ++p)
  2185. {
  2186. Symbol* sym = p->second;
  2187. // Note that SYM may already have a dynamic symbol index, since
  2188. // some symbols appear more than once in the symbol table, with
  2189. // and without a version.
  2190. if (!sym->should_add_dynsym_entry(this))
  2191. sym->set_dynsym_index(-1U);
  2192. else if (!sym->has_dynsym_index())
  2193. {
  2194. sym->set_dynsym_index(index);
  2195. ++index;
  2196. syms->push_back(sym);
  2197. dynpool->add(sym->name(), false, NULL);
  2198. // If the symbol is defined in a dynamic object and is
  2199. // referenced strongly in a regular object, then mark the
  2200. // dynamic object as needed. This is used to implement
  2201. // --as-needed.
  2202. if (sym->is_from_dynobj()
  2203. && sym->in_reg()
  2204. && !sym->is_undef_binding_weak())
  2205. sym->object()->set_is_needed();
  2206. // Record any version information, except those from
  2207. // as-needed libraries not seen to be needed. Note that the
  2208. // is_needed state for such libraries can change in this loop.
  2209. if (sym->version() != NULL)
  2210. {
  2211. if (!sym->is_from_dynobj()
  2212. || !sym->object()->as_needed()
  2213. || sym->object()->is_needed())
  2214. versions->record_version(this, dynpool, sym);
  2215. else
  2216. as_needed_sym.push_back(sym);
  2217. }
  2218. }
  2219. }
  2220. // Process version information for symbols from as-needed libraries.
  2221. for (std::vector<Symbol*>::iterator p = as_needed_sym.begin();
  2222. p != as_needed_sym.end();
  2223. ++p)
  2224. {
  2225. Symbol* sym = *p;
  2226. if (sym->object()->is_needed())
  2227. versions->record_version(this, dynpool, sym);
  2228. else
  2229. sym->clear_version();
  2230. }
  2231. // Finish up the versions. In some cases this may add new dynamic
  2232. // symbols.
  2233. index = versions->finalize(this, index, syms);
  2234. return index;
  2235. }
  2236. // Set the final values for all the symbols. The index of the first
  2237. // global symbol in the output file is *PLOCAL_SYMCOUNT. Record the
  2238. // file offset OFF. Add their names to POOL. Return the new file
  2239. // offset. Update *PLOCAL_SYMCOUNT if necessary.
  2240. off_t
  2241. Symbol_table::finalize(off_t off, off_t dynoff, size_t dyn_global_index,
  2242. size_t dyncount, Stringpool* pool,
  2243. unsigned int* plocal_symcount)
  2244. {
  2245. off_t ret;
  2246. gold_assert(*plocal_symcount != 0);
  2247. this->first_global_index_ = *plocal_symcount;
  2248. this->dynamic_offset_ = dynoff;
  2249. this->first_dynamic_global_index_ = dyn_global_index;
  2250. this->dynamic_count_ = dyncount;
  2251. if (parameters->target().get_size() == 32)
  2252. {
  2253. #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_32_LITTLE)
  2254. ret = this->sized_finalize<32>(off, pool, plocal_symcount);
  2255. #else
  2256. gold_unreachable();
  2257. #endif
  2258. }
  2259. else if (parameters->target().get_size() == 64)
  2260. {
  2261. #if defined(HAVE_TARGET_64_BIG) || defined(HAVE_TARGET_64_LITTLE)
  2262. ret = this->sized_finalize<64>(off, pool, plocal_symcount);
  2263. #else
  2264. gold_unreachable();
  2265. #endif
  2266. }
  2267. else
  2268. gold_unreachable();
  2269. // Now that we have the final symbol table, we can reliably note
  2270. // which symbols should get warnings.
  2271. this->warnings_.note_warnings(this);
  2272. return ret;
  2273. }
  2274. // SYM is going into the symbol table at *PINDEX. Add the name to
  2275. // POOL, update *PINDEX and *POFF.
  2276. template<int size>
  2277. void
  2278. Symbol_table::add_to_final_symtab(Symbol* sym, Stringpool* pool,
  2279. unsigned int* pindex, off_t* poff)
  2280. {
  2281. sym->set_symtab_index(*pindex);
  2282. if (sym->version() == NULL || !parameters->options().relocatable())
  2283. pool->add(sym->name(), false, NULL);
  2284. else
  2285. pool->add(sym->versioned_name(), true, NULL);
  2286. ++*pindex;
  2287. *poff += elfcpp::Elf_sizes<size>::sym_size;
  2288. }
  2289. // Set the final value for all the symbols. This is called after
  2290. // Layout::finalize, so all the output sections have their final
  2291. // address.
  2292. template<int size>
  2293. off_t
  2294. Symbol_table::sized_finalize(off_t off, Stringpool* pool,
  2295. unsigned int* plocal_symcount)
  2296. {
  2297. off = align_address(off, size >> 3);
  2298. this->offset_ = off;
  2299. unsigned int index = *plocal_symcount;
  2300. const unsigned int orig_index = index;
  2301. // First do all the symbols which have been forced to be local, as
  2302. // they must appear before all global symbols.
  2303. for (Forced_locals::iterator p = this->forced_locals_.begin();
  2304. p != this->forced_locals_.end();
  2305. ++p)
  2306. {
  2307. Symbol* sym = *p;
  2308. gold_assert(sym->is_forced_local());
  2309. if (this->sized_finalize_symbol<size>(sym))
  2310. {
  2311. this->add_to_final_symtab<size>(sym, pool, &index, &off);
  2312. ++*plocal_symcount;
  2313. }
  2314. }
  2315. // Now do all the remaining symbols.
  2316. for (Symbol_table_type::iterator p = this->table_.begin();
  2317. p != this->table_.end();
  2318. ++p)
  2319. {
  2320. Symbol* sym = p->second;
  2321. if (this->sized_finalize_symbol<size>(sym))
  2322. this->add_to_final_symtab<size>(sym, pool, &index, &off);
  2323. }
  2324. this->output_count_ = index - orig_index;
  2325. return off;
  2326. }
  2327. // Compute the final value of SYM and store status in location PSTATUS.
  2328. // During relaxation, this may be called multiple times for a symbol to
  2329. // compute its would-be final value in each relaxation pass.
  2330. template<int size>
  2331. typename Sized_symbol<size>::Value_type
  2332. Symbol_table::compute_final_value(
  2333. const Sized_symbol<size>* sym,
  2334. Compute_final_value_status* pstatus) const
  2335. {
  2336. typedef typename Sized_symbol<size>::Value_type Value_type;
  2337. Value_type value;
  2338. switch (sym->source())
  2339. {
  2340. case Symbol::FROM_OBJECT:
  2341. {
  2342. bool is_ordinary;
  2343. unsigned int shndx = sym->shndx(&is_ordinary);
  2344. if (!is_ordinary
  2345. && shndx != elfcpp::SHN_ABS
  2346. && !Symbol::is_common_shndx(shndx))
  2347. {
  2348. *pstatus = CFVS_UNSUPPORTED_SYMBOL_SECTION;
  2349. return 0;
  2350. }
  2351. Object* symobj = sym->object();
  2352. if (symobj->is_dynamic())
  2353. {
  2354. value = 0;
  2355. shndx = elfcpp::SHN_UNDEF;
  2356. }
  2357. else if (symobj->pluginobj() != NULL)
  2358. {
  2359. value = 0;
  2360. shndx = elfcpp::SHN_UNDEF;
  2361. }
  2362. else if (shndx == elfcpp::SHN_UNDEF)
  2363. value = 0;
  2364. else if (!is_ordinary
  2365. && (shndx == elfcpp::SHN_ABS
  2366. || Symbol::is_common_shndx(shndx)))
  2367. value = sym->value();
  2368. else
  2369. {
  2370. Relobj* relobj = static_cast<Relobj*>(symobj);
  2371. Output_section* os = relobj->output_section(shndx);
  2372. if (this->is_section_folded(relobj, shndx))
  2373. {
  2374. gold_assert(os == NULL);
  2375. // Get the os of the section it is folded onto.
  2376. Section_id folded = this->icf_->get_folded_section(relobj,
  2377. shndx);
  2378. gold_assert(folded.first != NULL);
  2379. Relobj* folded_obj = reinterpret_cast<Relobj*>(folded.first);
  2380. unsigned folded_shndx = folded.second;
  2381. os = folded_obj->output_section(folded_shndx);
  2382. gold_assert(os != NULL);
  2383. // Replace (relobj, shndx) with canonical ICF input section.
  2384. shndx = folded_shndx;
  2385. relobj = folded_obj;
  2386. }
  2387. uint64_t secoff64 = relobj->output_section_offset(shndx);
  2388. if (os == NULL)
  2389. {
  2390. bool static_or_reloc = (parameters->doing_static_link() ||
  2391. parameters->options().relocatable());
  2392. gold_assert(static_or_reloc || sym->dynsym_index() == -1U);
  2393. *pstatus = CFVS_NO_OUTPUT_SECTION;
  2394. return 0;
  2395. }
  2396. if (secoff64 == -1ULL)
  2397. {
  2398. // The section needs special handling (e.g., a merge section).
  2399. value = os->output_address(relobj, shndx, sym->value());
  2400. }
  2401. else
  2402. {
  2403. Value_type secoff =
  2404. convert_types<Value_type, uint64_t>(secoff64);
  2405. if (sym->type() == elfcpp::STT_TLS)
  2406. value = sym->value() + os->tls_offset() + secoff;
  2407. else
  2408. value = sym->value() + os->address() + secoff;
  2409. }
  2410. }
  2411. }
  2412. break;
  2413. case Symbol::IN_OUTPUT_DATA:
  2414. {
  2415. Output_data* od = sym->output_data();
  2416. value = sym->value();
  2417. if (sym->type() != elfcpp::STT_TLS)
  2418. value += od->address();
  2419. else
  2420. {
  2421. Output_section* os = od->output_section();
  2422. gold_assert(os != NULL);
  2423. value += os->tls_offset() + (od->address() - os->address());
  2424. }
  2425. if (sym->offset_is_from_end())
  2426. value += od->data_size();
  2427. }
  2428. break;
  2429. case Symbol::IN_OUTPUT_SEGMENT:
  2430. {
  2431. Output_segment* os = sym->output_segment();
  2432. value = sym->value();
  2433. if (sym->type() != elfcpp::STT_TLS)
  2434. value += os->vaddr();
  2435. switch (sym->offset_base())
  2436. {
  2437. case Symbol::SEGMENT_START:
  2438. break;
  2439. case Symbol::SEGMENT_END:
  2440. value += os->memsz();
  2441. break;
  2442. case Symbol::SEGMENT_BSS:
  2443. value += os->filesz();
  2444. break;
  2445. default:
  2446. gold_unreachable();
  2447. }
  2448. }
  2449. break;
  2450. case Symbol::IS_CONSTANT:
  2451. value = sym->value();
  2452. break;
  2453. case Symbol::IS_UNDEFINED:
  2454. value = 0;
  2455. break;
  2456. default:
  2457. gold_unreachable();
  2458. }
  2459. *pstatus = CFVS_OK;
  2460. return value;
  2461. }
  2462. // Finalize the symbol SYM. This returns true if the symbol should be
  2463. // added to the symbol table, false otherwise.
  2464. template<int size>
  2465. bool
  2466. Symbol_table::sized_finalize_symbol(Symbol* unsized_sym)
  2467. {
  2468. typedef typename Sized_symbol<size>::Value_type Value_type;
  2469. Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(unsized_sym);
  2470. // The default version of a symbol may appear twice in the symbol
  2471. // table. We only need to finalize it once.
  2472. if (sym->has_symtab_index())
  2473. return false;
  2474. if (!sym->in_reg())
  2475. {
  2476. gold_assert(!sym->has_symtab_index());
  2477. sym->set_symtab_index(-1U);
  2478. gold_assert(sym->dynsym_index() == -1U);
  2479. return false;
  2480. }
  2481. // If the symbol is only present on plugin files, the plugin decided we
  2482. // don't need it.
  2483. if (!sym->in_real_elf())
  2484. {
  2485. gold_assert(!sym->has_symtab_index());
  2486. sym->set_symtab_index(-1U);
  2487. return false;
  2488. }
  2489. // Compute final symbol value.
  2490. Compute_final_value_status status;
  2491. Value_type value = this->compute_final_value(sym, &status);
  2492. switch (status)
  2493. {
  2494. case CFVS_OK:
  2495. break;
  2496. case CFVS_UNSUPPORTED_SYMBOL_SECTION:
  2497. {
  2498. bool is_ordinary;
  2499. unsigned int shndx = sym->shndx(&is_ordinary);
  2500. gold_error(_("%s: unsupported symbol section 0x%x"),
  2501. sym->demangled_name().c_str(), shndx);
  2502. }
  2503. break;
  2504. case CFVS_NO_OUTPUT_SECTION:
  2505. sym->set_symtab_index(-1U);
  2506. return false;
  2507. default:
  2508. gold_unreachable();
  2509. }
  2510. sym->set_value(value);
  2511. if (parameters->options().strip_all()
  2512. || !parameters->options().should_retain_symbol(sym->name()))
  2513. {
  2514. sym->set_symtab_index(-1U);
  2515. return false;
  2516. }
  2517. return true;
  2518. }
  2519. // Write out the global symbols.
  2520. void
  2521. Symbol_table::write_globals(const Stringpool* sympool,
  2522. const Stringpool* dynpool,
  2523. Output_symtab_xindex* symtab_xindex,
  2524. Output_symtab_xindex* dynsym_xindex,
  2525. Output_file* of) const
  2526. {
  2527. switch (parameters->size_and_endianness())
  2528. {
  2529. #ifdef HAVE_TARGET_32_LITTLE
  2530. case Parameters::TARGET_32_LITTLE:
  2531. this->sized_write_globals<32, false>(sympool, dynpool, symtab_xindex,
  2532. dynsym_xindex, of);
  2533. break;
  2534. #endif
  2535. #ifdef HAVE_TARGET_32_BIG
  2536. case Parameters::TARGET_32_BIG:
  2537. this->sized_write_globals<32, true>(sympool, dynpool, symtab_xindex,
  2538. dynsym_xindex, of);
  2539. break;
  2540. #endif
  2541. #ifdef HAVE_TARGET_64_LITTLE
  2542. case Parameters::TARGET_64_LITTLE:
  2543. this->sized_write_globals<64, false>(sympool, dynpool, symtab_xindex,
  2544. dynsym_xindex, of);
  2545. break;
  2546. #endif
  2547. #ifdef HAVE_TARGET_64_BIG
  2548. case Parameters::TARGET_64_BIG:
  2549. this->sized_write_globals<64, true>(sympool, dynpool, symtab_xindex,
  2550. dynsym_xindex, of);
  2551. break;
  2552. #endif
  2553. default:
  2554. gold_unreachable();
  2555. }
  2556. }
  2557. // Write out the global symbols.
  2558. template<int size, bool big_endian>
  2559. void
  2560. Symbol_table::sized_write_globals(const Stringpool* sympool,
  2561. const Stringpool* dynpool,
  2562. Output_symtab_xindex* symtab_xindex,
  2563. Output_symtab_xindex* dynsym_xindex,
  2564. Output_file* of) const
  2565. {
  2566. const Target& target = parameters->target();
  2567. const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
  2568. const unsigned int output_count = this->output_count_;
  2569. const section_size_type oview_size = output_count * sym_size;
  2570. const unsigned int first_global_index = this->first_global_index_;
  2571. unsigned char* psyms;
  2572. if (this->offset_ == 0 || output_count == 0)
  2573. psyms = NULL;
  2574. else
  2575. psyms = of->get_output_view(this->offset_, oview_size);
  2576. const unsigned int dynamic_count = this->dynamic_count_;
  2577. const section_size_type dynamic_size = dynamic_count * sym_size;
  2578. const unsigned int first_dynamic_global_index =
  2579. this->first_dynamic_global_index_;
  2580. unsigned char* dynamic_view;
  2581. if (this->dynamic_offset_ == 0 || dynamic_count == 0)
  2582. dynamic_view = NULL;
  2583. else
  2584. dynamic_view = of->get_output_view(this->dynamic_offset_, dynamic_size);
  2585. for (Symbol_table_type::const_iterator p = this->table_.begin();
  2586. p != this->table_.end();
  2587. ++p)
  2588. {
  2589. Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(p->second);
  2590. // Possibly warn about unresolved symbols in shared libraries.
  2591. this->warn_about_undefined_dynobj_symbol(sym);
  2592. unsigned int sym_index = sym->symtab_index();
  2593. unsigned int dynsym_index;
  2594. if (dynamic_view == NULL)
  2595. dynsym_index = -1U;
  2596. else
  2597. dynsym_index = sym->dynsym_index();
  2598. if (sym_index == -1U && dynsym_index == -1U)
  2599. {
  2600. // This symbol is not included in the output file.
  2601. continue;
  2602. }
  2603. unsigned int shndx;
  2604. typename elfcpp::Elf_types<size>::Elf_Addr sym_value = sym->value();
  2605. typename elfcpp::Elf_types<size>::Elf_Addr dynsym_value = sym_value;
  2606. elfcpp::STB binding = sym->binding();
  2607. // If --weak-unresolved-symbols is set, change binding of unresolved
  2608. // global symbols to STB_WEAK.
  2609. if (parameters->options().weak_unresolved_symbols()
  2610. && binding == elfcpp::STB_GLOBAL
  2611. && sym->is_undefined())
  2612. binding = elfcpp::STB_WEAK;
  2613. // If --no-gnu-unique is set, change STB_GNU_UNIQUE to STB_GLOBAL.
  2614. if (binding == elfcpp::STB_GNU_UNIQUE
  2615. && !parameters->options().gnu_unique())
  2616. binding = elfcpp::STB_GLOBAL;
  2617. switch (sym->source())
  2618. {
  2619. case Symbol::FROM_OBJECT:
  2620. {
  2621. bool is_ordinary;
  2622. unsigned int in_shndx = sym->shndx(&is_ordinary);
  2623. if (!is_ordinary
  2624. && in_shndx != elfcpp::SHN_ABS
  2625. && !Symbol::is_common_shndx(in_shndx))
  2626. {
  2627. gold_error(_("%s: unsupported symbol section 0x%x"),
  2628. sym->demangled_name().c_str(), in_shndx);
  2629. shndx = in_shndx;
  2630. }
  2631. else
  2632. {
  2633. Object* symobj = sym->object();
  2634. if (symobj->is_dynamic())
  2635. {
  2636. if (sym->needs_dynsym_value())
  2637. dynsym_value = target.dynsym_value(sym);
  2638. shndx = elfcpp::SHN_UNDEF;
  2639. if (sym->is_undef_binding_weak())
  2640. binding = elfcpp::STB_WEAK;
  2641. else
  2642. binding = elfcpp::STB_GLOBAL;
  2643. }
  2644. else if (symobj->pluginobj() != NULL)
  2645. shndx = elfcpp::SHN_UNDEF;
  2646. else if (in_shndx == elfcpp::SHN_UNDEF
  2647. || (!is_ordinary
  2648. && (in_shndx == elfcpp::SHN_ABS
  2649. || Symbol::is_common_shndx(in_shndx))))
  2650. shndx = in_shndx;
  2651. else
  2652. {
  2653. Relobj* relobj = static_cast<Relobj*>(symobj);
  2654. Output_section* os = relobj->output_section(in_shndx);
  2655. if (this->is_section_folded(relobj, in_shndx))
  2656. {
  2657. // This global symbol must be written out even though
  2658. // it is folded.
  2659. // Get the os of the section it is folded onto.
  2660. Section_id folded =
  2661. this->icf_->get_folded_section(relobj, in_shndx);
  2662. gold_assert(folded.first !=NULL);
  2663. Relobj* folded_obj =
  2664. reinterpret_cast<Relobj*>(folded.first);
  2665. os = folded_obj->output_section(folded.second);
  2666. gold_assert(os != NULL);
  2667. }
  2668. gold_assert(os != NULL);
  2669. shndx = os->out_shndx();
  2670. if (shndx >= elfcpp::SHN_LORESERVE)
  2671. {
  2672. if (sym_index != -1U)
  2673. symtab_xindex->add(sym_index, shndx);
  2674. if (dynsym_index != -1U)
  2675. dynsym_xindex->add(dynsym_index, shndx);
  2676. shndx = elfcpp::SHN_XINDEX;
  2677. }
  2678. // In object files symbol values are section
  2679. // relative.
  2680. if (parameters->options().relocatable())
  2681. sym_value -= os->address();
  2682. }
  2683. }
  2684. }
  2685. break;
  2686. case Symbol::IN_OUTPUT_DATA:
  2687. {
  2688. Output_data* od = sym->output_data();
  2689. shndx = od->out_shndx();
  2690. if (shndx >= elfcpp::SHN_LORESERVE)
  2691. {
  2692. if (sym_index != -1U)
  2693. symtab_xindex->add(sym_index, shndx);
  2694. if (dynsym_index != -1U)
  2695. dynsym_xindex->add(dynsym_index, shndx);
  2696. shndx = elfcpp::SHN_XINDEX;
  2697. }
  2698. // In object files symbol values are section
  2699. // relative.
  2700. if (parameters->options().relocatable())
  2701. sym_value -= od->address();
  2702. }
  2703. break;
  2704. case Symbol::IN_OUTPUT_SEGMENT:
  2705. shndx = elfcpp::SHN_ABS;
  2706. break;
  2707. case Symbol::IS_CONSTANT:
  2708. shndx = elfcpp::SHN_ABS;
  2709. break;
  2710. case Symbol::IS_UNDEFINED:
  2711. shndx = elfcpp::SHN_UNDEF;
  2712. break;
  2713. default:
  2714. gold_unreachable();
  2715. }
  2716. if (sym_index != -1U)
  2717. {
  2718. sym_index -= first_global_index;
  2719. gold_assert(sym_index < output_count);
  2720. unsigned char* ps = psyms + (sym_index * sym_size);
  2721. this->sized_write_symbol<size, big_endian>(sym, sym_value, shndx,
  2722. binding, sympool, ps);
  2723. }
  2724. if (dynsym_index != -1U)
  2725. {
  2726. dynsym_index -= first_dynamic_global_index;
  2727. gold_assert(dynsym_index < dynamic_count);
  2728. unsigned char* pd = dynamic_view + (dynsym_index * sym_size);
  2729. this->sized_write_symbol<size, big_endian>(sym, dynsym_value, shndx,
  2730. binding, dynpool, pd);
  2731. // Allow a target to adjust dynamic symbol value.
  2732. parameters->target().adjust_dyn_symbol(sym, pd);
  2733. }
  2734. }
  2735. of->write_output_view(this->offset_, oview_size, psyms);
  2736. if (dynamic_view != NULL)
  2737. of->write_output_view(this->dynamic_offset_, dynamic_size, dynamic_view);
  2738. }
  2739. // Write out the symbol SYM, in section SHNDX, to P. POOL is the
  2740. // strtab holding the name.
  2741. template<int size, bool big_endian>
  2742. void
  2743. Symbol_table::sized_write_symbol(
  2744. Sized_symbol<size>* sym,
  2745. typename elfcpp::Elf_types<size>::Elf_Addr value,
  2746. unsigned int shndx,
  2747. elfcpp::STB binding,
  2748. const Stringpool* pool,
  2749. unsigned char* p) const
  2750. {
  2751. elfcpp::Sym_write<size, big_endian> osym(p);
  2752. if (sym->version() == NULL || !parameters->options().relocatable())
  2753. osym.put_st_name(pool->get_offset(sym->name()));
  2754. else
  2755. osym.put_st_name(pool->get_offset(sym->versioned_name()));
  2756. osym.put_st_value(value);
  2757. // Use a symbol size of zero for undefined symbols from shared libraries.
  2758. if (shndx == elfcpp::SHN_UNDEF && sym->is_from_dynobj())
  2759. osym.put_st_size(0);
  2760. else
  2761. osym.put_st_size(sym->symsize());
  2762. elfcpp::STT type = sym->type();
  2763. gold_assert(type != elfcpp::STT_GNU_IFUNC || !sym->is_from_dynobj());
  2764. // A version script may have overridden the default binding.
  2765. if (sym->is_forced_local())
  2766. osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL, type));
  2767. else
  2768. osym.put_st_info(elfcpp::elf_st_info(binding, type));
  2769. osym.put_st_other(elfcpp::elf_st_other(sym->visibility(), sym->nonvis()));
  2770. osym.put_st_shndx(shndx);
  2771. }
  2772. // Check for unresolved symbols in shared libraries. This is
  2773. // controlled by the --allow-shlib-undefined option.
  2774. // We only warn about libraries for which we have seen all the
  2775. // DT_NEEDED entries. We don't try to track down DT_NEEDED entries
  2776. // which were not seen in this link. If we didn't see a DT_NEEDED
  2777. // entry, we aren't going to be able to reliably report whether the
  2778. // symbol is undefined.
  2779. // We also don't warn about libraries found in a system library
  2780. // directory (e.g., /lib or /usr/lib); we assume that those libraries
  2781. // are OK. This heuristic avoids problems on GNU/Linux, in which -ldl
  2782. // can have undefined references satisfied by ld-linux.so.
  2783. inline void
  2784. Symbol_table::warn_about_undefined_dynobj_symbol(Symbol* sym) const
  2785. {
  2786. bool dummy;
  2787. if (sym->source() == Symbol::FROM_OBJECT
  2788. && sym->object()->is_dynamic()
  2789. && sym->shndx(&dummy) == elfcpp::SHN_UNDEF
  2790. && sym->binding() != elfcpp::STB_WEAK
  2791. && !parameters->options().allow_shlib_undefined()
  2792. && !parameters->target().is_defined_by_abi(sym)
  2793. && !sym->object()->is_in_system_directory())
  2794. {
  2795. // A very ugly cast.
  2796. Dynobj* dynobj = static_cast<Dynobj*>(sym->object());
  2797. if (!dynobj->has_unknown_needed_entries())
  2798. gold_undefined_symbol(sym);
  2799. }
  2800. }
  2801. // Write out a section symbol. Return the update offset.
  2802. void
  2803. Symbol_table::write_section_symbol(const Output_section* os,
  2804. Output_symtab_xindex* symtab_xindex,
  2805. Output_file* of,
  2806. off_t offset) const
  2807. {
  2808. switch (parameters->size_and_endianness())
  2809. {
  2810. #ifdef HAVE_TARGET_32_LITTLE
  2811. case Parameters::TARGET_32_LITTLE:
  2812. this->sized_write_section_symbol<32, false>(os, symtab_xindex, of,
  2813. offset);
  2814. break;
  2815. #endif
  2816. #ifdef HAVE_TARGET_32_BIG
  2817. case Parameters::TARGET_32_BIG:
  2818. this->sized_write_section_symbol<32, true>(os, symtab_xindex, of,
  2819. offset);
  2820. break;
  2821. #endif
  2822. #ifdef HAVE_TARGET_64_LITTLE
  2823. case Parameters::TARGET_64_LITTLE:
  2824. this->sized_write_section_symbol<64, false>(os, symtab_xindex, of,
  2825. offset);
  2826. break;
  2827. #endif
  2828. #ifdef HAVE_TARGET_64_BIG
  2829. case Parameters::TARGET_64_BIG:
  2830. this->sized_write_section_symbol<64, true>(os, symtab_xindex, of,
  2831. offset);
  2832. break;
  2833. #endif
  2834. default:
  2835. gold_unreachable();
  2836. }
  2837. }
  2838. // Write out a section symbol, specialized for size and endianness.
  2839. template<int size, bool big_endian>
  2840. void
  2841. Symbol_table::sized_write_section_symbol(const Output_section* os,
  2842. Output_symtab_xindex* symtab_xindex,
  2843. Output_file* of,
  2844. off_t offset) const
  2845. {
  2846. const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
  2847. unsigned char* pov = of->get_output_view(offset, sym_size);
  2848. elfcpp::Sym_write<size, big_endian> osym(pov);
  2849. osym.put_st_name(0);
  2850. if (parameters->options().relocatable())
  2851. osym.put_st_value(0);
  2852. else
  2853. osym.put_st_value(os->address());
  2854. osym.put_st_size(0);
  2855. osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL,
  2856. elfcpp::STT_SECTION));
  2857. osym.put_st_other(elfcpp::elf_st_other(elfcpp::STV_DEFAULT, 0));
  2858. unsigned int shndx = os->out_shndx();
  2859. if (shndx >= elfcpp::SHN_LORESERVE)
  2860. {
  2861. symtab_xindex->add(os->symtab_index(), shndx);
  2862. shndx = elfcpp::SHN_XINDEX;
  2863. }
  2864. osym.put_st_shndx(shndx);
  2865. of->write_output_view(offset, sym_size, pov);
  2866. }
  2867. // Print statistical information to stderr. This is used for --stats.
  2868. void
  2869. Symbol_table::print_stats() const
  2870. {
  2871. #if defined(HAVE_TR1_UNORDERED_MAP) || defined(HAVE_EXT_HASH_MAP)
  2872. fprintf(stderr, _("%s: symbol table entries: %zu; buckets: %zu\n"),
  2873. program_name, this->table_.size(), this->table_.bucket_count());
  2874. #else
  2875. fprintf(stderr, _("%s: symbol table entries: %zu\n"),
  2876. program_name, this->table_.size());
  2877. #endif
  2878. this->namepool_.print_stats("symbol table stringpool");
  2879. }
  2880. // We check for ODR violations by looking for symbols with the same
  2881. // name for which the debugging information reports that they were
  2882. // defined in disjoint source locations. When comparing the source
  2883. // location, we consider instances with the same base filename to be
  2884. // the same. This is because different object files/shared libraries
  2885. // can include the same header file using different paths, and
  2886. // different optimization settings can make the line number appear to
  2887. // be a couple lines off, and we don't want to report an ODR violation
  2888. // in those cases.
  2889. // This struct is used to compare line information, as returned by
  2890. // Dwarf_line_info::one_addr2line. It implements a < comparison
  2891. // operator used with std::sort.
  2892. struct Odr_violation_compare
  2893. {
  2894. bool
  2895. operator()(const std::string& s1, const std::string& s2) const
  2896. {
  2897. // Inputs should be of the form "dirname/filename:linenum" where
  2898. // "dirname/" is optional. We want to compare just the filename:linenum.
  2899. // Find the last '/' in each string.
  2900. std::string::size_type s1begin = s1.rfind('/');
  2901. std::string::size_type s2begin = s2.rfind('/');
  2902. // If there was no '/' in a string, start at the beginning.
  2903. if (s1begin == std::string::npos)
  2904. s1begin = 0;
  2905. if (s2begin == std::string::npos)
  2906. s2begin = 0;
  2907. return s1.compare(s1begin, std::string::npos,
  2908. s2, s2begin, std::string::npos) < 0;
  2909. }
  2910. };
  2911. // Returns all of the lines attached to LOC, not just the one the
  2912. // instruction actually came from.
  2913. std::vector<std::string>
  2914. Symbol_table::linenos_from_loc(const Task* task,
  2915. const Symbol_location& loc)
  2916. {
  2917. // We need to lock the object in order to read it. This
  2918. // means that we have to run in a singleton Task. If we
  2919. // want to run this in a general Task for better
  2920. // performance, we will need one Task for object, plus
  2921. // appropriate locking to ensure that we don't conflict with
  2922. // other uses of the object. Also note, one_addr2line is not
  2923. // currently thread-safe.
  2924. Task_lock_obj<Object> tl(task, loc.object);
  2925. std::vector<std::string> result;
  2926. Symbol_location code_loc = loc;
  2927. parameters->target().function_location(&code_loc);
  2928. // 16 is the size of the object-cache that one_addr2line should use.
  2929. std::string canonical_result = Dwarf_line_info::one_addr2line(
  2930. code_loc.object, code_loc.shndx, code_loc.offset, 16, &result);
  2931. if (!canonical_result.empty())
  2932. result.push_back(canonical_result);
  2933. return result;
  2934. }
  2935. // OutputIterator that records if it was ever assigned to. This
  2936. // allows it to be used with std::set_intersection() to check for
  2937. // intersection rather than computing the intersection.
  2938. struct Check_intersection
  2939. {
  2940. Check_intersection()
  2941. : value_(false)
  2942. {}
  2943. bool had_intersection() const
  2944. { return this->value_; }
  2945. Check_intersection& operator++()
  2946. { return *this; }
  2947. Check_intersection& operator*()
  2948. { return *this; }
  2949. template<typename T>
  2950. Check_intersection& operator=(const T&)
  2951. {
  2952. this->value_ = true;
  2953. return *this;
  2954. }
  2955. private:
  2956. bool value_;
  2957. };
  2958. // Check candidate_odr_violations_ to find symbols with the same name
  2959. // but apparently different definitions (different source-file/line-no
  2960. // for each line assigned to the first instruction).
  2961. void
  2962. Symbol_table::detect_odr_violations(const Task* task,
  2963. const char* output_file_name) const
  2964. {
  2965. for (Odr_map::const_iterator it = candidate_odr_violations_.begin();
  2966. it != candidate_odr_violations_.end();
  2967. ++it)
  2968. {
  2969. const char* const symbol_name = it->first;
  2970. std::string first_object_name;
  2971. std::vector<std::string> first_object_linenos;
  2972. Unordered_set<Symbol_location, Symbol_location_hash>::const_iterator
  2973. locs = it->second.begin();
  2974. const Unordered_set<Symbol_location, Symbol_location_hash>::const_iterator
  2975. locs_end = it->second.end();
  2976. for (; locs != locs_end && first_object_linenos.empty(); ++locs)
  2977. {
  2978. // Save the line numbers from the first definition to
  2979. // compare to the other definitions. Ideally, we'd compare
  2980. // every definition to every other, but we don't want to
  2981. // take O(N^2) time to do this. This shortcut may cause
  2982. // false negatives that appear or disappear depending on the
  2983. // link order, but it won't cause false positives.
  2984. first_object_name = locs->object->name();
  2985. first_object_linenos = this->linenos_from_loc(task, *locs);
  2986. }
  2987. if (first_object_linenos.empty())
  2988. continue;
  2989. // Sort by Odr_violation_compare to make std::set_intersection work.
  2990. std::string first_object_canonical_result = first_object_linenos.back();
  2991. std::sort(first_object_linenos.begin(), first_object_linenos.end(),
  2992. Odr_violation_compare());
  2993. for (; locs != locs_end; ++locs)
  2994. {
  2995. std::vector<std::string> linenos =
  2996. this->linenos_from_loc(task, *locs);
  2997. // linenos will be empty if we couldn't parse the debug info.
  2998. if (linenos.empty())
  2999. continue;
  3000. // Sort by Odr_violation_compare to make std::set_intersection work.
  3001. gold_assert(!linenos.empty());
  3002. std::string second_object_canonical_result = linenos.back();
  3003. std::sort(linenos.begin(), linenos.end(), Odr_violation_compare());
  3004. Check_intersection intersection_result =
  3005. std::set_intersection(first_object_linenos.begin(),
  3006. first_object_linenos.end(),
  3007. linenos.begin(),
  3008. linenos.end(),
  3009. Check_intersection(),
  3010. Odr_violation_compare());
  3011. if (!intersection_result.had_intersection())
  3012. {
  3013. gold_warning(_("while linking %s: symbol '%s' defined in "
  3014. "multiple places (possible ODR violation):"),
  3015. output_file_name, demangle(symbol_name).c_str());
  3016. // This only prints one location from each definition,
  3017. // which may not be the location we expect to intersect
  3018. // with another definition. We could print the whole
  3019. // set of locations, but that seems too verbose.
  3020. fprintf(stderr, _(" %s from %s\n"),
  3021. first_object_canonical_result.c_str(),
  3022. first_object_name.c_str());
  3023. fprintf(stderr, _(" %s from %s\n"),
  3024. second_object_canonical_result.c_str(),
  3025. locs->object->name().c_str());
  3026. // Only print one broken pair, to avoid needing to
  3027. // compare against a list of the disjoint definition
  3028. // locations we've found so far. (If we kept comparing
  3029. // against just the first one, we'd get a lot of
  3030. // redundant complaints about the second definition
  3031. // location.)
  3032. break;
  3033. }
  3034. }
  3035. }
  3036. // We only call one_addr2line() in this function, so we can clear its cache.
  3037. Dwarf_line_info::clear_addr2line_cache();
  3038. }
  3039. // Warnings functions.
  3040. // Add a new warning.
  3041. void
  3042. Warnings::add_warning(Symbol_table* symtab, const char* name, Object* obj,
  3043. const std::string& warning)
  3044. {
  3045. name = symtab->canonicalize_name(name);
  3046. this->warnings_[name].set(obj, warning);
  3047. }
  3048. // Look through the warnings and mark the symbols for which we should
  3049. // warn. This is called during Layout::finalize when we know the
  3050. // sources for all the symbols.
  3051. void
  3052. Warnings::note_warnings(Symbol_table* symtab)
  3053. {
  3054. for (Warning_table::iterator p = this->warnings_.begin();
  3055. p != this->warnings_.end();
  3056. ++p)
  3057. {
  3058. Symbol* sym = symtab->lookup(p->first, NULL);
  3059. if (sym != NULL
  3060. && sym->source() == Symbol::FROM_OBJECT
  3061. && sym->object() == p->second.object)
  3062. sym->set_has_warning();
  3063. }
  3064. }
  3065. // Issue a warning. This is called when we see a relocation against a
  3066. // symbol for which has a warning.
  3067. template<int size, bool big_endian>
  3068. void
  3069. Warnings::issue_warning(const Symbol* sym,
  3070. const Relocate_info<size, big_endian>* relinfo,
  3071. size_t relnum, off_t reloffset) const
  3072. {
  3073. gold_assert(sym->has_warning());
  3074. // We don't want to issue a warning for a relocation against the
  3075. // symbol in the same object file in which the symbol is defined.
  3076. if (sym->object() == relinfo->object)
  3077. return;
  3078. Warning_table::const_iterator p = this->warnings_.find(sym->name());
  3079. gold_assert(p != this->warnings_.end());
  3080. gold_warning_at_location(relinfo, relnum, reloffset,
  3081. "%s", p->second.text.c_str());
  3082. }
  3083. // Instantiate the templates we need. We could use the configure
  3084. // script to restrict this to only the ones needed for implemented
  3085. // targets.
  3086. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
  3087. template
  3088. void
  3089. Sized_symbol<32>::allocate_common(Output_data*, Value_type);
  3090. #endif
  3091. #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
  3092. template
  3093. void
  3094. Sized_symbol<64>::allocate_common(Output_data*, Value_type);
  3095. #endif
  3096. #ifdef HAVE_TARGET_32_LITTLE
  3097. template
  3098. void
  3099. Symbol_table::add_from_relobj<32, false>(
  3100. Sized_relobj_file<32, false>* relobj,
  3101. const unsigned char* syms,
  3102. size_t count,
  3103. size_t symndx_offset,
  3104. const char* sym_names,
  3105. size_t sym_name_size,
  3106. Sized_relobj_file<32, false>::Symbols* sympointers,
  3107. size_t* defined);
  3108. #endif
  3109. #ifdef HAVE_TARGET_32_BIG
  3110. template
  3111. void
  3112. Symbol_table::add_from_relobj<32, true>(
  3113. Sized_relobj_file<32, true>* relobj,
  3114. const unsigned char* syms,
  3115. size_t count,
  3116. size_t symndx_offset,
  3117. const char* sym_names,
  3118. size_t sym_name_size,
  3119. Sized_relobj_file<32, true>::Symbols* sympointers,
  3120. size_t* defined);
  3121. #endif
  3122. #ifdef HAVE_TARGET_64_LITTLE
  3123. template
  3124. void
  3125. Symbol_table::add_from_relobj<64, false>(
  3126. Sized_relobj_file<64, false>* relobj,
  3127. const unsigned char* syms,
  3128. size_t count,
  3129. size_t symndx_offset,
  3130. const char* sym_names,
  3131. size_t sym_name_size,
  3132. Sized_relobj_file<64, false>::Symbols* sympointers,
  3133. size_t* defined);
  3134. #endif
  3135. #ifdef HAVE_TARGET_64_BIG
  3136. template
  3137. void
  3138. Symbol_table::add_from_relobj<64, true>(
  3139. Sized_relobj_file<64, true>* relobj,
  3140. const unsigned char* syms,
  3141. size_t count,
  3142. size_t symndx_offset,
  3143. const char* sym_names,
  3144. size_t sym_name_size,
  3145. Sized_relobj_file<64, true>::Symbols* sympointers,
  3146. size_t* defined);
  3147. #endif
  3148. #ifdef HAVE_TARGET_32_LITTLE
  3149. template
  3150. Symbol*
  3151. Symbol_table::add_from_pluginobj<32, false>(
  3152. Sized_pluginobj<32, false>* obj,
  3153. const char* name,
  3154. const char* ver,
  3155. elfcpp::Sym<32, false>* sym);
  3156. #endif
  3157. #ifdef HAVE_TARGET_32_BIG
  3158. template
  3159. Symbol*
  3160. Symbol_table::add_from_pluginobj<32, true>(
  3161. Sized_pluginobj<32, true>* obj,
  3162. const char* name,
  3163. const char* ver,
  3164. elfcpp::Sym<32, true>* sym);
  3165. #endif
  3166. #ifdef HAVE_TARGET_64_LITTLE
  3167. template
  3168. Symbol*
  3169. Symbol_table::add_from_pluginobj<64, false>(
  3170. Sized_pluginobj<64, false>* obj,
  3171. const char* name,
  3172. const char* ver,
  3173. elfcpp::Sym<64, false>* sym);
  3174. #endif
  3175. #ifdef HAVE_TARGET_64_BIG
  3176. template
  3177. Symbol*
  3178. Symbol_table::add_from_pluginobj<64, true>(
  3179. Sized_pluginobj<64, true>* obj,
  3180. const char* name,
  3181. const char* ver,
  3182. elfcpp::Sym<64, true>* sym);
  3183. #endif
  3184. #ifdef HAVE_TARGET_32_LITTLE
  3185. template
  3186. void
  3187. Symbol_table::add_from_dynobj<32, false>(
  3188. Sized_dynobj<32, false>* dynobj,
  3189. const unsigned char* syms,
  3190. size_t count,
  3191. const char* sym_names,
  3192. size_t sym_name_size,
  3193. const unsigned char* versym,
  3194. size_t versym_size,
  3195. const std::vector<const char*>* version_map,
  3196. Sized_relobj_file<32, false>::Symbols* sympointers,
  3197. size_t* defined);
  3198. #endif
  3199. #ifdef HAVE_TARGET_32_BIG
  3200. template
  3201. void
  3202. Symbol_table::add_from_dynobj<32, true>(
  3203. Sized_dynobj<32, true>* dynobj,
  3204. const unsigned char* syms,
  3205. size_t count,
  3206. const char* sym_names,
  3207. size_t sym_name_size,
  3208. const unsigned char* versym,
  3209. size_t versym_size,
  3210. const std::vector<const char*>* version_map,
  3211. Sized_relobj_file<32, true>::Symbols* sympointers,
  3212. size_t* defined);
  3213. #endif
  3214. #ifdef HAVE_TARGET_64_LITTLE
  3215. template
  3216. void
  3217. Symbol_table::add_from_dynobj<64, false>(
  3218. Sized_dynobj<64, false>* dynobj,
  3219. const unsigned char* syms,
  3220. size_t count,
  3221. const char* sym_names,
  3222. size_t sym_name_size,
  3223. const unsigned char* versym,
  3224. size_t versym_size,
  3225. const std::vector<const char*>* version_map,
  3226. Sized_relobj_file<64, false>::Symbols* sympointers,
  3227. size_t* defined);
  3228. #endif
  3229. #ifdef HAVE_TARGET_64_BIG
  3230. template
  3231. void
  3232. Symbol_table::add_from_dynobj<64, true>(
  3233. Sized_dynobj<64, true>* dynobj,
  3234. const unsigned char* syms,
  3235. size_t count,
  3236. const char* sym_names,
  3237. size_t sym_name_size,
  3238. const unsigned char* versym,
  3239. size_t versym_size,
  3240. const std::vector<const char*>* version_map,
  3241. Sized_relobj_file<64, true>::Symbols* sympointers,
  3242. size_t* defined);
  3243. #endif
  3244. #ifdef HAVE_TARGET_32_LITTLE
  3245. template
  3246. Sized_symbol<32>*
  3247. Symbol_table::add_from_incrobj(
  3248. Object* obj,
  3249. const char* name,
  3250. const char* ver,
  3251. elfcpp::Sym<32, false>* sym);
  3252. #endif
  3253. #ifdef HAVE_TARGET_32_BIG
  3254. template
  3255. Sized_symbol<32>*
  3256. Symbol_table::add_from_incrobj(
  3257. Object* obj,
  3258. const char* name,
  3259. const char* ver,
  3260. elfcpp::Sym<32, true>* sym);
  3261. #endif
  3262. #ifdef HAVE_TARGET_64_LITTLE
  3263. template
  3264. Sized_symbol<64>*
  3265. Symbol_table::add_from_incrobj(
  3266. Object* obj,
  3267. const char* name,
  3268. const char* ver,
  3269. elfcpp::Sym<64, false>* sym);
  3270. #endif
  3271. #ifdef HAVE_TARGET_64_BIG
  3272. template
  3273. Sized_symbol<64>*
  3274. Symbol_table::add_from_incrobj(
  3275. Object* obj,
  3276. const char* name,
  3277. const char* ver,
  3278. elfcpp::Sym<64, true>* sym);
  3279. #endif
  3280. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
  3281. template
  3282. void
  3283. Symbol_table::define_with_copy_reloc<32>(
  3284. Sized_symbol<32>* sym,
  3285. Output_data* posd,
  3286. elfcpp::Elf_types<32>::Elf_Addr value);
  3287. #endif
  3288. #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
  3289. template
  3290. void
  3291. Symbol_table::define_with_copy_reloc<64>(
  3292. Sized_symbol<64>* sym,
  3293. Output_data* posd,
  3294. elfcpp::Elf_types<64>::Elf_Addr value);
  3295. #endif
  3296. #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
  3297. template
  3298. void
  3299. Sized_symbol<32>::init_output_data(const char* name, const char* version,
  3300. Output_data* od, Value_type value,
  3301. Size_type symsize, elfcpp::STT type,
  3302. elfcpp::STB binding,
  3303. elfcpp::STV visibility,
  3304. unsigned char nonvis,
  3305. bool offset_is_from_end,
  3306. bool is_predefined);
  3307. #endif
  3308. #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
  3309. template
  3310. void
  3311. Sized_symbol<64>::init_output_data(const char* name, const char* version,
  3312. Output_data* od, Value_type value,
  3313. Size_type symsize, elfcpp::STT type,
  3314. elfcpp::STB binding,
  3315. elfcpp::STV visibility,
  3316. unsigned char nonvis,
  3317. bool offset_is_from_end,
  3318. bool is_predefined);
  3319. #endif
  3320. #ifdef HAVE_TARGET_32_LITTLE
  3321. template
  3322. void
  3323. Warnings::issue_warning<32, false>(const Symbol* sym,
  3324. const Relocate_info<32, false>* relinfo,
  3325. size_t relnum, off_t reloffset) const;
  3326. #endif
  3327. #ifdef HAVE_TARGET_32_BIG
  3328. template
  3329. void
  3330. Warnings::issue_warning<32, true>(const Symbol* sym,
  3331. const Relocate_info<32, true>* relinfo,
  3332. size_t relnum, off_t reloffset) const;
  3333. #endif
  3334. #ifdef HAVE_TARGET_64_LITTLE
  3335. template
  3336. void
  3337. Warnings::issue_warning<64, false>(const Symbol* sym,
  3338. const Relocate_info<64, false>* relinfo,
  3339. size_t relnum, off_t reloffset) const;
  3340. #endif
  3341. #ifdef HAVE_TARGET_64_BIG
  3342. template
  3343. void
  3344. Warnings::issue_warning<64, true>(const Symbol* sym,
  3345. const Relocate_info<64, true>* relinfo,
  3346. size_t relnum, off_t reloffset) const;
  3347. #endif
  3348. } // End namespace gold.