obj-elf.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701
  1. /* ELF object file format
  2. Copyright (C) 1992-2015 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 3,
  7. or (at your option) any later version.
  8. GAS is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  11. the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #define OBJ_HEADER "obj-elf.h"
  17. #include "as.h"
  18. #include "safe-ctype.h"
  19. #include "subsegs.h"
  20. #include "obstack.h"
  21. #include "struc-symbol.h"
  22. #include "dwarf2dbg.h"
  23. #ifndef ECOFF_DEBUGGING
  24. #define ECOFF_DEBUGGING 0
  25. #else
  26. #define NEED_ECOFF_DEBUG
  27. #endif
  28. #ifdef NEED_ECOFF_DEBUG
  29. #include "ecoff.h"
  30. #endif
  31. #ifdef TC_ALPHA
  32. #include "elf/alpha.h"
  33. #endif
  34. #ifdef TC_MIPS
  35. #include "elf/mips.h"
  36. #endif
  37. #ifdef TC_PPC
  38. #include "elf/ppc.h"
  39. #endif
  40. #ifdef TC_I370
  41. #include "elf/i370.h"
  42. #endif
  43. #ifdef TC_I386
  44. #include "elf/x86-64.h"
  45. #endif
  46. #ifdef TC_MEP
  47. #include "elf/mep.h"
  48. #endif
  49. #ifdef TC_NIOS2
  50. #include "elf/nios2.h"
  51. #endif
  52. static void obj_elf_line (int);
  53. static void obj_elf_size (int);
  54. static void obj_elf_type (int);
  55. static void obj_elf_ident (int);
  56. static void obj_elf_weak (int);
  57. static void obj_elf_local (int);
  58. static void obj_elf_visibility (int);
  59. static void obj_elf_symver (int);
  60. static void obj_elf_subsection (int);
  61. static void obj_elf_popsection (int);
  62. static void obj_elf_gnu_attribute (int);
  63. static void obj_elf_tls_common (int);
  64. static void obj_elf_lcomm (int);
  65. static void obj_elf_struct (int);
  66. static const pseudo_typeS elf_pseudo_table[] =
  67. {
  68. {"comm", obj_elf_common, 0},
  69. {"common", obj_elf_common, 1},
  70. {"ident", obj_elf_ident, 0},
  71. {"lcomm", obj_elf_lcomm, 0},
  72. {"local", obj_elf_local, 0},
  73. {"previous", obj_elf_previous, 0},
  74. {"section", obj_elf_section, 0},
  75. {"section.s", obj_elf_section, 0},
  76. {"sect", obj_elf_section, 0},
  77. {"sect.s", obj_elf_section, 0},
  78. {"pushsection", obj_elf_section, 1},
  79. {"popsection", obj_elf_popsection, 0},
  80. {"size", obj_elf_size, 0},
  81. {"type", obj_elf_type, 0},
  82. {"version", obj_elf_version, 0},
  83. {"weak", obj_elf_weak, 0},
  84. /* These define symbol visibility. */
  85. {"internal", obj_elf_visibility, STV_INTERNAL},
  86. {"hidden", obj_elf_visibility, STV_HIDDEN},
  87. {"protected", obj_elf_visibility, STV_PROTECTED},
  88. /* These are used for stabs-in-elf configurations. */
  89. {"line", obj_elf_line, 0},
  90. /* This is a GNU extension to handle symbol versions. */
  91. {"symver", obj_elf_symver, 0},
  92. /* A GNU extension to change subsection only. */
  93. {"subsection", obj_elf_subsection, 0},
  94. /* These are GNU extensions to aid in garbage collecting C++ vtables. */
  95. {"vtable_inherit", (void (*) (int)) &obj_elf_vtable_inherit, 0},
  96. {"vtable_entry", (void (*) (int)) &obj_elf_vtable_entry, 0},
  97. /* A GNU extension for object attributes. */
  98. {"gnu_attribute", obj_elf_gnu_attribute, 0},
  99. /* These are used for dwarf. */
  100. {"2byte", cons, 2},
  101. {"4byte", cons, 4},
  102. {"8byte", cons, 8},
  103. /* These are used for dwarf2. */
  104. { "file", (void (*) (int)) dwarf2_directive_file, 0 },
  105. { "loc", dwarf2_directive_loc, 0 },
  106. { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
  107. /* We need to trap the section changing calls to handle .previous. */
  108. {"data", obj_elf_data, 0},
  109. {"offset", obj_elf_struct, 0},
  110. {"struct", obj_elf_struct, 0},
  111. {"text", obj_elf_text, 0},
  112. {"tls_common", obj_elf_tls_common, 0},
  113. /* End sentinel. */
  114. {NULL, NULL, 0},
  115. };
  116. static const pseudo_typeS ecoff_debug_pseudo_table[] =
  117. {
  118. #ifdef NEED_ECOFF_DEBUG
  119. /* COFF style debugging information for ECOFF. .ln is not used; .loc
  120. is used instead. */
  121. { "def", ecoff_directive_def, 0 },
  122. { "dim", ecoff_directive_dim, 0 },
  123. { "endef", ecoff_directive_endef, 0 },
  124. { "file", ecoff_directive_file, 0 },
  125. { "scl", ecoff_directive_scl, 0 },
  126. { "tag", ecoff_directive_tag, 0 },
  127. { "val", ecoff_directive_val, 0 },
  128. /* COFF debugging requires pseudo-ops .size and .type, but ELF
  129. already has meanings for those. We use .esize and .etype
  130. instead. These are only generated by gcc anyhow. */
  131. { "esize", ecoff_directive_size, 0 },
  132. { "etype", ecoff_directive_type, 0 },
  133. /* ECOFF specific debugging information. */
  134. { "begin", ecoff_directive_begin, 0 },
  135. { "bend", ecoff_directive_bend, 0 },
  136. { "end", ecoff_directive_end, 0 },
  137. { "ent", ecoff_directive_ent, 0 },
  138. { "fmask", ecoff_directive_fmask, 0 },
  139. { "frame", ecoff_directive_frame, 0 },
  140. { "loc", ecoff_directive_loc, 0 },
  141. { "mask", ecoff_directive_mask, 0 },
  142. /* Other ECOFF directives. */
  143. { "extern", ecoff_directive_extern, 0 },
  144. /* These are used on Irix. I don't know how to implement them. */
  145. { "alias", s_ignore, 0 },
  146. { "bgnb", s_ignore, 0 },
  147. { "endb", s_ignore, 0 },
  148. { "lab", s_ignore, 0 },
  149. { "noalias", s_ignore, 0 },
  150. { "verstamp", s_ignore, 0 },
  151. { "vreg", s_ignore, 0 },
  152. #endif
  153. {NULL, NULL, 0} /* end sentinel */
  154. };
  155. #undef NO_RELOC
  156. #include "aout/aout64.h"
  157. /* This is called when the assembler starts. */
  158. asection *elf_com_section_ptr;
  159. void
  160. elf_begin (void)
  161. {
  162. asection *s;
  163. /* Add symbols for the known sections to the symbol table. */
  164. s = bfd_get_section_by_name (stdoutput, TEXT_SECTION_NAME);
  165. symbol_table_insert (section_symbol (s));
  166. s = bfd_get_section_by_name (stdoutput, DATA_SECTION_NAME);
  167. symbol_table_insert (section_symbol (s));
  168. s = bfd_get_section_by_name (stdoutput, BSS_SECTION_NAME);
  169. symbol_table_insert (section_symbol (s));
  170. elf_com_section_ptr = bfd_com_section_ptr;
  171. }
  172. void
  173. elf_pop_insert (void)
  174. {
  175. pop_insert (elf_pseudo_table);
  176. if (ECOFF_DEBUGGING)
  177. pop_insert (ecoff_debug_pseudo_table);
  178. }
  179. static bfd_vma
  180. elf_s_get_size (symbolS *sym)
  181. {
  182. return S_GET_SIZE (sym);
  183. }
  184. static void
  185. elf_s_set_size (symbolS *sym, bfd_vma sz)
  186. {
  187. S_SET_SIZE (sym, sz);
  188. }
  189. static bfd_vma
  190. elf_s_get_align (symbolS *sym)
  191. {
  192. return S_GET_ALIGN (sym);
  193. }
  194. static void
  195. elf_s_set_align (symbolS *sym, bfd_vma align)
  196. {
  197. S_SET_ALIGN (sym, align);
  198. }
  199. int
  200. elf_s_get_other (symbolS *sym)
  201. {
  202. return elf_symbol (symbol_get_bfdsym (sym))->internal_elf_sym.st_other;
  203. }
  204. static void
  205. elf_s_set_other (symbolS *sym, int other)
  206. {
  207. S_SET_OTHER (sym, other);
  208. }
  209. static int
  210. elf_sec_sym_ok_for_reloc (asection *sec)
  211. {
  212. return obj_sec_sym_ok_for_reloc (sec);
  213. }
  214. void
  215. elf_file_symbol (const char *s, int appfile)
  216. {
  217. if (!appfile
  218. || symbol_rootP == NULL
  219. || symbol_rootP->bsym == NULL
  220. || (symbol_rootP->bsym->flags & BSF_FILE) == 0)
  221. {
  222. symbolS *sym;
  223. size_t name_length;
  224. sym = symbol_new (s, absolute_section, 0, NULL);
  225. symbol_set_frag (sym, &zero_address_frag);
  226. name_length = strlen (s);
  227. if (name_length > strlen (S_GET_NAME (sym)))
  228. {
  229. obstack_grow (&notes, s, name_length + 1);
  230. S_SET_NAME (sym, (const char *) obstack_finish (&notes));
  231. }
  232. else
  233. strcpy ((char *) S_GET_NAME (sym), s);
  234. symbol_get_bfdsym (sym)->flags |= BSF_FILE;
  235. if (symbol_rootP != sym)
  236. {
  237. symbol_remove (sym, &symbol_rootP, &symbol_lastP);
  238. symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP);
  239. #ifdef DEBUG
  240. verify_symbol_chain (symbol_rootP, symbol_lastP);
  241. #endif
  242. }
  243. }
  244. #ifdef NEED_ECOFF_DEBUG
  245. ecoff_new_file (s, appfile);
  246. #endif
  247. }
  248. /* Called from read.c:s_comm after we've parsed .comm symbol, size.
  249. Parse a possible alignment value. */
  250. symbolS *
  251. elf_common_parse (int ignore ATTRIBUTE_UNUSED, symbolS *symbolP, addressT size)
  252. {
  253. addressT align = 0;
  254. int is_local = symbol_get_obj (symbolP)->local;
  255. if (*input_line_pointer == ',')
  256. {
  257. char *save = input_line_pointer;
  258. input_line_pointer++;
  259. SKIP_WHITESPACE ();
  260. if (*input_line_pointer == '"')
  261. {
  262. /* For sparc. Accept .common symbol, length, "bss" */
  263. input_line_pointer++;
  264. /* Some use the dot, some don't. */
  265. if (*input_line_pointer == '.')
  266. input_line_pointer++;
  267. /* Some say data, some say bss. */
  268. if (strncmp (input_line_pointer, "bss\"", 4) == 0)
  269. input_line_pointer += 4;
  270. else if (strncmp (input_line_pointer, "data\"", 5) == 0)
  271. input_line_pointer += 5;
  272. else
  273. {
  274. char *p = input_line_pointer;
  275. char c;
  276. while (*--p != '"')
  277. ;
  278. while (!is_end_of_line[(unsigned char) *input_line_pointer])
  279. if (*input_line_pointer++ == '"')
  280. break;
  281. c = *input_line_pointer;
  282. *input_line_pointer = '\0';
  283. as_bad (_("bad .common segment %s"), p);
  284. *input_line_pointer = c;
  285. ignore_rest_of_line ();
  286. return NULL;
  287. }
  288. /* ??? Don't ask me why these are always global. */
  289. is_local = 0;
  290. }
  291. else
  292. {
  293. input_line_pointer = save;
  294. align = parse_align (is_local);
  295. if (align == (addressT) -1)
  296. return NULL;
  297. }
  298. }
  299. if (is_local)
  300. {
  301. bss_alloc (symbolP, size, align);
  302. S_CLEAR_EXTERNAL (symbolP);
  303. }
  304. else
  305. {
  306. S_SET_VALUE (symbolP, size);
  307. S_SET_ALIGN (symbolP, align);
  308. S_SET_EXTERNAL (symbolP);
  309. S_SET_SEGMENT (symbolP, elf_com_section_ptr);
  310. }
  311. symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
  312. return symbolP;
  313. }
  314. void
  315. obj_elf_common (int is_common)
  316. {
  317. if (flag_mri && is_common)
  318. s_mri_common (0);
  319. else
  320. s_comm_internal (0, elf_common_parse);
  321. }
  322. static void
  323. obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED)
  324. {
  325. symbolS *symbolP = s_comm_internal (0, elf_common_parse);
  326. if (symbolP)
  327. symbol_get_bfdsym (symbolP)->flags |= BSF_THREAD_LOCAL;
  328. }
  329. static void
  330. obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED)
  331. {
  332. symbolS *symbolP = s_comm_internal (0, s_lcomm_internal);
  333. if (symbolP)
  334. symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
  335. }
  336. static symbolS *
  337. get_sym_from_input_line_and_check (void)
  338. {
  339. char *name;
  340. char c;
  341. symbolS *sym;
  342. c = get_symbol_name (& name);
  343. sym = symbol_find_or_make (name);
  344. *input_line_pointer = c;
  345. SKIP_WHITESPACE_AFTER_NAME ();
  346. /* There is no symbol name if input_line_pointer has not moved. */
  347. if (name == input_line_pointer)
  348. as_bad (_("Missing symbol name in directive"));
  349. return sym;
  350. }
  351. static void
  352. obj_elf_local (int ignore ATTRIBUTE_UNUSED)
  353. {
  354. int c;
  355. symbolS *symbolP;
  356. do
  357. {
  358. symbolP = get_sym_from_input_line_and_check ();
  359. c = *input_line_pointer;
  360. S_CLEAR_EXTERNAL (symbolP);
  361. symbol_get_obj (symbolP)->local = 1;
  362. if (c == ',')
  363. {
  364. input_line_pointer++;
  365. SKIP_WHITESPACE ();
  366. if (*input_line_pointer == '\n')
  367. c = '\n';
  368. }
  369. }
  370. while (c == ',');
  371. demand_empty_rest_of_line ();
  372. }
  373. static void
  374. obj_elf_weak (int ignore ATTRIBUTE_UNUSED)
  375. {
  376. int c;
  377. symbolS *symbolP;
  378. do
  379. {
  380. symbolP = get_sym_from_input_line_and_check ();
  381. c = *input_line_pointer;
  382. S_SET_WEAK (symbolP);
  383. if (c == ',')
  384. {
  385. input_line_pointer++;
  386. SKIP_WHITESPACE ();
  387. if (*input_line_pointer == '\n')
  388. c = '\n';
  389. }
  390. }
  391. while (c == ',');
  392. demand_empty_rest_of_line ();
  393. }
  394. static void
  395. obj_elf_visibility (int visibility)
  396. {
  397. int c;
  398. symbolS *symbolP;
  399. asymbol *bfdsym;
  400. elf_symbol_type *elfsym;
  401. do
  402. {
  403. symbolP = get_sym_from_input_line_and_check ();
  404. bfdsym = symbol_get_bfdsym (symbolP);
  405. elfsym = elf_symbol_from (bfd_asymbol_bfd (bfdsym), bfdsym);
  406. gas_assert (elfsym);
  407. elfsym->internal_elf_sym.st_other &= ~3;
  408. elfsym->internal_elf_sym.st_other |= visibility;
  409. c = *input_line_pointer;
  410. if (c == ',')
  411. {
  412. input_line_pointer ++;
  413. SKIP_WHITESPACE ();
  414. if (*input_line_pointer == '\n')
  415. c = '\n';
  416. }
  417. }
  418. while (c == ',');
  419. demand_empty_rest_of_line ();
  420. }
  421. static segT previous_section;
  422. static int previous_subsection;
  423. struct section_stack
  424. {
  425. struct section_stack *next;
  426. segT seg, prev_seg;
  427. int subseg, prev_subseg;
  428. };
  429. static struct section_stack *section_stack;
  430. static bfd_boolean
  431. get_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf)
  432. {
  433. const char *gname = (const char *) inf;
  434. const char *group_name = elf_group_name (sec);
  435. return (group_name == gname
  436. || (group_name != NULL
  437. && gname != NULL
  438. && strcmp (group_name, gname) == 0));
  439. }
  440. /* Handle the .section pseudo-op. This code supports two different
  441. syntaxes.
  442. The first is found on Solaris, and looks like
  443. .section ".sec1",#alloc,#execinstr,#write
  444. Here the names after '#' are the SHF_* flags to turn on for the
  445. section. I'm not sure how it determines the SHT_* type (BFD
  446. doesn't really give us control over the type, anyhow).
  447. The second format is found on UnixWare, and probably most SVR4
  448. machines, and looks like
  449. .section .sec1,"a",@progbits
  450. The quoted string may contain any combination of a, w, x, and
  451. represents the SHF_* flags to turn on for the section. The string
  452. beginning with '@' can be progbits or nobits. There should be
  453. other possibilities, but I don't know what they are. In any case,
  454. BFD doesn't really let us set the section type. */
  455. void
  456. obj_elf_change_section (const char *name,
  457. int type,
  458. bfd_vma attr,
  459. int entsize,
  460. const char *group_name,
  461. int linkonce,
  462. int push)
  463. {
  464. asection *old_sec;
  465. segT sec;
  466. flagword flags;
  467. const struct elf_backend_data *bed;
  468. const struct bfd_elf_special_section *ssect;
  469. #ifdef md_flush_pending_output
  470. md_flush_pending_output ();
  471. #endif
  472. /* Switch to the section, creating it if necessary. */
  473. if (push)
  474. {
  475. struct section_stack *elt;
  476. elt = (struct section_stack *) xmalloc (sizeof (struct section_stack));
  477. elt->next = section_stack;
  478. elt->seg = now_seg;
  479. elt->prev_seg = previous_section;
  480. elt->subseg = now_subseg;
  481. elt->prev_subseg = previous_subsection;
  482. section_stack = elt;
  483. }
  484. previous_section = now_seg;
  485. previous_subsection = now_subseg;
  486. old_sec = bfd_get_section_by_name_if (stdoutput, name, get_section,
  487. (void *) group_name);
  488. if (old_sec)
  489. {
  490. sec = old_sec;
  491. subseg_set (sec, 0);
  492. }
  493. else
  494. sec = subseg_force_new (name, 0);
  495. bed = get_elf_backend_data (stdoutput);
  496. ssect = (*bed->get_sec_type_attr) (stdoutput, sec);
  497. if (ssect != NULL)
  498. {
  499. bfd_boolean override = FALSE;
  500. if (type == SHT_NULL)
  501. type = ssect->type;
  502. else if (type != ssect->type)
  503. {
  504. if (old_sec == NULL
  505. /* Some older versions of gcc will emit
  506. .section .init_array,"aw",@progbits
  507. for __attribute__ ((section (".init_array"))).
  508. "@progbits" is incorrect. Also for x86-64 large bss
  509. sections, some older versions of gcc will emit
  510. .section .lbss,"aw",@progbits
  511. "@progbits" is incorrect. */
  512. #ifdef TC_I386
  513. && (bed->s->arch_size != 64
  514. || !(ssect->attr & SHF_X86_64_LARGE))
  515. #endif
  516. && ssect->type != SHT_INIT_ARRAY
  517. && ssect->type != SHT_FINI_ARRAY
  518. && ssect->type != SHT_PREINIT_ARRAY)
  519. {
  520. /* We allow to specify any type for a .note section. */
  521. if (ssect->type != SHT_NOTE)
  522. as_warn (_("setting incorrect section type for %s"),
  523. name);
  524. }
  525. else
  526. {
  527. as_warn (_("ignoring incorrect section type for %s"),
  528. name);
  529. type = ssect->type;
  530. }
  531. }
  532. if (old_sec == NULL && (attr & ~ssect->attr) != 0)
  533. {
  534. /* As a GNU extension, we permit a .note section to be
  535. allocatable. If the linker sees an allocatable .note
  536. section, it will create a PT_NOTE segment in the output
  537. file. We also allow "x" for .note.GNU-stack. */
  538. if (ssect->type == SHT_NOTE
  539. && (attr == SHF_ALLOC || attr == SHF_EXECINSTR))
  540. ;
  541. /* Allow different SHF_MERGE and SHF_STRINGS if we have
  542. something like .rodata.str. */
  543. else if (ssect->suffix_length == -2
  544. && name[ssect->prefix_length] == '.'
  545. && (attr
  546. & ~ssect->attr
  547. & ~SHF_MERGE
  548. & ~SHF_STRINGS) == 0)
  549. ;
  550. /* .interp, .strtab and .symtab can have SHF_ALLOC. */
  551. else if (attr == SHF_ALLOC
  552. && (strcmp (name, ".interp") == 0
  553. || strcmp (name, ".strtab") == 0
  554. || strcmp (name, ".symtab") == 0))
  555. override = TRUE;
  556. /* .note.GNU-stack can have SHF_EXECINSTR. */
  557. else if (attr == SHF_EXECINSTR
  558. && strcmp (name, ".note.GNU-stack") == 0)
  559. override = TRUE;
  560. #ifdef TC_ALPHA
  561. /* A section on Alpha may have SHF_ALPHA_GPREL. */
  562. else if ((attr & ~ssect->attr) == SHF_ALPHA_GPREL)
  563. override = TRUE;
  564. #endif
  565. #ifdef TC_RX
  566. else if (attr == (SHF_EXECINSTR | SHF_WRITE | SHF_ALLOC)
  567. && (ssect->type == SHT_INIT_ARRAY
  568. || ssect->type == SHT_FINI_ARRAY
  569. || ssect->type == SHT_PREINIT_ARRAY))
  570. /* RX init/fini arrays can and should have the "awx" attributes set. */
  571. ;
  572. #endif
  573. else
  574. {
  575. if (group_name == NULL)
  576. as_warn (_("setting incorrect section attributes for %s"),
  577. name);
  578. override = TRUE;
  579. }
  580. }
  581. if (!override && old_sec == NULL)
  582. attr |= ssect->attr;
  583. }
  584. /* Convert ELF type and flags to BFD flags. */
  585. flags = (SEC_RELOC
  586. | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
  587. | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0)
  588. | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0)
  589. | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0)
  590. | ((attr & SHF_MERGE) ? SEC_MERGE : 0)
  591. | ((attr & SHF_STRINGS) ? SEC_STRINGS : 0)
  592. | ((attr & SHF_EXCLUDE) ? SEC_EXCLUDE: 0)
  593. | ((attr & SHF_TLS) ? SEC_THREAD_LOCAL : 0));
  594. #ifdef md_elf_section_flags
  595. flags = md_elf_section_flags (flags, attr, type);
  596. #endif
  597. if (linkonce)
  598. flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
  599. if (old_sec == NULL)
  600. {
  601. symbolS *secsym;
  602. if (type == SHT_NULL)
  603. type = bfd_elf_get_default_section_type (flags);
  604. elf_section_type (sec) = type;
  605. elf_section_flags (sec) = attr;
  606. /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
  607. if (type == SHT_NOBITS)
  608. seg_info (sec)->bss = 1;
  609. bfd_set_section_flags (stdoutput, sec, flags);
  610. if (flags & SEC_MERGE)
  611. sec->entsize = entsize;
  612. elf_group_name (sec) = group_name;
  613. /* Add a symbol for this section to the symbol table. */
  614. secsym = symbol_find (name);
  615. if (secsym != NULL)
  616. symbol_set_bfdsym (secsym, sec->symbol);
  617. else
  618. symbol_table_insert (section_symbol (sec));
  619. }
  620. else
  621. {
  622. if (type != SHT_NULL
  623. && (unsigned) type != elf_section_type (old_sec))
  624. as_warn (_("ignoring changed section type for %s"), name);
  625. if (attr != 0)
  626. {
  627. /* If section attributes are specified the second time we see a
  628. particular section, then check that they are the same as we
  629. saw the first time. */
  630. if (((old_sec->flags ^ flags)
  631. & (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
  632. | SEC_EXCLUDE | SEC_SORT_ENTRIES | SEC_MERGE | SEC_STRINGS
  633. | SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
  634. | SEC_THREAD_LOCAL)))
  635. as_warn (_("ignoring changed section attributes for %s"), name);
  636. if ((flags & SEC_MERGE) && old_sec->entsize != (unsigned) entsize)
  637. as_warn (_("ignoring changed section entity size for %s"), name);
  638. }
  639. }
  640. #ifdef md_elf_section_change_hook
  641. md_elf_section_change_hook ();
  642. #endif
  643. }
  644. static bfd_vma
  645. obj_elf_parse_section_letters (char *str, size_t len, bfd_boolean *is_clone)
  646. {
  647. bfd_vma attr = 0;
  648. *is_clone = FALSE;
  649. while (len > 0)
  650. {
  651. switch (*str)
  652. {
  653. case 'a':
  654. attr |= SHF_ALLOC;
  655. break;
  656. case 'e':
  657. attr |= SHF_EXCLUDE;
  658. break;
  659. case 'w':
  660. attr |= SHF_WRITE;
  661. break;
  662. case 'x':
  663. attr |= SHF_EXECINSTR;
  664. break;
  665. case 'M':
  666. attr |= SHF_MERGE;
  667. break;
  668. case 'S':
  669. attr |= SHF_STRINGS;
  670. break;
  671. case 'G':
  672. attr |= SHF_GROUP;
  673. break;
  674. case 'T':
  675. attr |= SHF_TLS;
  676. break;
  677. case '?':
  678. *is_clone = TRUE;
  679. break;
  680. /* Compatibility. */
  681. case 'm':
  682. if (*(str - 1) == 'a')
  683. {
  684. attr |= SHF_MERGE;
  685. if (len > 1 && str[1] == 's')
  686. {
  687. attr |= SHF_STRINGS;
  688. str++, len--;
  689. }
  690. break;
  691. }
  692. default:
  693. {
  694. char *bad_msg = _("unrecognized .section attribute: want a,e,w,x,M,S,G,T");
  695. #ifdef md_elf_section_letter
  696. bfd_vma md_attr = md_elf_section_letter (*str, &bad_msg);
  697. if (md_attr != (bfd_vma) -1)
  698. attr |= md_attr;
  699. else
  700. #endif
  701. as_fatal ("%s", bad_msg);
  702. }
  703. break;
  704. }
  705. str++, len--;
  706. }
  707. return attr;
  708. }
  709. static int
  710. obj_elf_section_type (char *str, size_t len, bfd_boolean warn)
  711. {
  712. if (len == 8 && strncmp (str, "progbits", 8) == 0)
  713. return SHT_PROGBITS;
  714. if (len == 6 && strncmp (str, "nobits", 6) == 0)
  715. return SHT_NOBITS;
  716. if (len == 4 && strncmp (str, "note", 4) == 0)
  717. return SHT_NOTE;
  718. if (len == 10 && strncmp (str, "init_array", 10) == 0)
  719. return SHT_INIT_ARRAY;
  720. if (len == 10 && strncmp (str, "fini_array", 10) == 0)
  721. return SHT_FINI_ARRAY;
  722. if (len == 13 && strncmp (str, "preinit_array", 13) == 0)
  723. return SHT_PREINIT_ARRAY;
  724. #ifdef md_elf_section_type
  725. {
  726. int md_type = md_elf_section_type (str, len);
  727. if (md_type >= 0)
  728. return md_type;
  729. }
  730. #endif
  731. if (warn)
  732. as_warn (_("unrecognized section type"));
  733. return 0;
  734. }
  735. static bfd_vma
  736. obj_elf_section_word (char *str, size_t len, int *type)
  737. {
  738. int ret;
  739. if (len == 5 && strncmp (str, "write", 5) == 0)
  740. return SHF_WRITE;
  741. if (len == 5 && strncmp (str, "alloc", 5) == 0)
  742. return SHF_ALLOC;
  743. if (len == 9 && strncmp (str, "execinstr", 9) == 0)
  744. return SHF_EXECINSTR;
  745. if (len == 7 && strncmp (str, "exclude", 7) == 0)
  746. return SHF_EXCLUDE;
  747. if (len == 3 && strncmp (str, "tls", 3) == 0)
  748. return SHF_TLS;
  749. #ifdef md_elf_section_word
  750. {
  751. bfd_vma md_attr = md_elf_section_word (str, len);
  752. if (md_attr > 0)
  753. return md_attr;
  754. }
  755. #endif
  756. ret = obj_elf_section_type (str, len, FALSE);
  757. if (ret != 0)
  758. *type = ret;
  759. else
  760. as_warn (_("unrecognized section attribute"));
  761. return 0;
  762. }
  763. /* Get name of section. */
  764. char *
  765. obj_elf_section_name (void)
  766. {
  767. char *name;
  768. SKIP_WHITESPACE ();
  769. if (*input_line_pointer == '"')
  770. {
  771. int dummy;
  772. name = demand_copy_C_string (&dummy);
  773. if (name == NULL)
  774. {
  775. ignore_rest_of_line ();
  776. return NULL;
  777. }
  778. }
  779. else
  780. {
  781. char *end = input_line_pointer;
  782. while (0 == strchr ("\n\t,; ", *end))
  783. end++;
  784. if (end == input_line_pointer)
  785. {
  786. as_bad (_("missing name"));
  787. ignore_rest_of_line ();
  788. return NULL;
  789. }
  790. name = (char *) xmalloc (end - input_line_pointer + 1);
  791. memcpy (name, input_line_pointer, end - input_line_pointer);
  792. name[end - input_line_pointer] = '\0';
  793. while (flag_sectname_subst)
  794. {
  795. char *subst = strchr (name, '%');
  796. if (subst && subst[1] == 'S')
  797. {
  798. int oldlen = strlen (name);
  799. int substlen = strlen (now_seg->name);
  800. int newlen = oldlen - 2 + substlen;
  801. char *newname = (char *) xmalloc (newlen + 1);
  802. int headlen = subst - name;
  803. memcpy (newname, name, headlen);
  804. strcpy (newname + headlen, now_seg->name);
  805. strcat (newname + headlen, subst + 2);
  806. xfree (name);
  807. name = newname;
  808. }
  809. else
  810. break;
  811. }
  812. #ifdef tc_canonicalize_section_name
  813. name = tc_canonicalize_section_name (name);
  814. #endif
  815. input_line_pointer = end;
  816. }
  817. SKIP_WHITESPACE ();
  818. return name;
  819. }
  820. void
  821. obj_elf_section (int push)
  822. {
  823. char *name, *group_name, *beg;
  824. int type, dummy;
  825. bfd_vma attr;
  826. int entsize;
  827. int linkonce;
  828. subsegT new_subsection = -1;
  829. #ifndef TC_I370
  830. if (flag_mri)
  831. {
  832. char mri_type;
  833. #ifdef md_flush_pending_output
  834. md_flush_pending_output ();
  835. #endif
  836. previous_section = now_seg;
  837. previous_subsection = now_subseg;
  838. s_mri_sect (&mri_type);
  839. #ifdef md_elf_section_change_hook
  840. md_elf_section_change_hook ();
  841. #endif
  842. return;
  843. }
  844. #endif /* ! defined (TC_I370) */
  845. name = obj_elf_section_name ();
  846. if (name == NULL)
  847. return;
  848. type = SHT_NULL;
  849. attr = 0;
  850. group_name = NULL;
  851. entsize = 0;
  852. linkonce = 0;
  853. if (*input_line_pointer == ',')
  854. {
  855. /* Skip the comma. */
  856. ++input_line_pointer;
  857. SKIP_WHITESPACE ();
  858. if (push && ISDIGIT (*input_line_pointer))
  859. {
  860. /* .pushsection has an optional subsection. */
  861. new_subsection = (subsegT) get_absolute_expression ();
  862. SKIP_WHITESPACE ();
  863. /* Stop if we don't see a comma. */
  864. if (*input_line_pointer != ',')
  865. goto done;
  866. /* Skip the comma. */
  867. ++input_line_pointer;
  868. SKIP_WHITESPACE ();
  869. }
  870. if (*input_line_pointer == '"')
  871. {
  872. bfd_boolean is_clone;
  873. beg = demand_copy_C_string (&dummy);
  874. if (beg == NULL)
  875. {
  876. ignore_rest_of_line ();
  877. return;
  878. }
  879. attr |= obj_elf_parse_section_letters (beg, strlen (beg), &is_clone);
  880. SKIP_WHITESPACE ();
  881. if (*input_line_pointer == ',')
  882. {
  883. char c;
  884. char *save = input_line_pointer;
  885. ++input_line_pointer;
  886. SKIP_WHITESPACE ();
  887. c = *input_line_pointer;
  888. if (c == '"')
  889. {
  890. beg = demand_copy_C_string (&dummy);
  891. if (beg == NULL)
  892. {
  893. ignore_rest_of_line ();
  894. return;
  895. }
  896. type = obj_elf_section_type (beg, strlen (beg), TRUE);
  897. }
  898. else if (c == '@' || c == '%')
  899. {
  900. ++input_line_pointer;
  901. c = get_symbol_name (& beg);
  902. (void) restore_line_pointer (c);
  903. type = obj_elf_section_type (beg, input_line_pointer - beg, TRUE);
  904. }
  905. else
  906. input_line_pointer = save;
  907. }
  908. SKIP_WHITESPACE ();
  909. if ((attr & SHF_MERGE) != 0 && *input_line_pointer == ',')
  910. {
  911. ++input_line_pointer;
  912. SKIP_WHITESPACE ();
  913. entsize = get_absolute_expression ();
  914. SKIP_WHITESPACE ();
  915. if (entsize < 0)
  916. {
  917. as_warn (_("invalid merge entity size"));
  918. attr &= ~SHF_MERGE;
  919. entsize = 0;
  920. }
  921. }
  922. else if ((attr & SHF_MERGE) != 0)
  923. {
  924. as_warn (_("entity size for SHF_MERGE not specified"));
  925. attr &= ~SHF_MERGE;
  926. }
  927. if ((attr & SHF_GROUP) != 0 && is_clone)
  928. {
  929. as_warn (_("? section flag ignored with G present"));
  930. is_clone = FALSE;
  931. }
  932. if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',')
  933. {
  934. ++input_line_pointer;
  935. group_name = obj_elf_section_name ();
  936. if (group_name == NULL)
  937. attr &= ~SHF_GROUP;
  938. else if (*input_line_pointer == ',')
  939. {
  940. ++input_line_pointer;
  941. SKIP_WHITESPACE ();
  942. if (strncmp (input_line_pointer, "comdat", 6) == 0)
  943. {
  944. input_line_pointer += 6;
  945. linkonce = 1;
  946. }
  947. }
  948. else if (strncmp (name, ".gnu.linkonce", 13) == 0)
  949. linkonce = 1;
  950. }
  951. else if ((attr & SHF_GROUP) != 0)
  952. {
  953. as_warn (_("group name for SHF_GROUP not specified"));
  954. attr &= ~SHF_GROUP;
  955. }
  956. if (is_clone)
  957. {
  958. const char *now_group = elf_group_name (now_seg);
  959. if (now_group != NULL)
  960. {
  961. group_name = xstrdup (now_group);
  962. linkonce = (now_seg->flags & SEC_LINK_ONCE) != 0;
  963. }
  964. }
  965. }
  966. else
  967. {
  968. do
  969. {
  970. char c;
  971. SKIP_WHITESPACE ();
  972. if (*input_line_pointer != '#')
  973. {
  974. as_bad (_("character following name is not '#'"));
  975. ignore_rest_of_line ();
  976. return;
  977. }
  978. ++input_line_pointer;
  979. c = get_symbol_name (& beg);
  980. (void) restore_line_pointer (c);
  981. attr |= obj_elf_section_word (beg, input_line_pointer - beg, & type);
  982. SKIP_WHITESPACE ();
  983. }
  984. while (*input_line_pointer++ == ',');
  985. --input_line_pointer;
  986. }
  987. }
  988. done:
  989. demand_empty_rest_of_line ();
  990. obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push);
  991. if (push && new_subsection != -1)
  992. subseg_set (now_seg, new_subsection);
  993. }
  994. /* Change to the .data section. */
  995. void
  996. obj_elf_data (int i)
  997. {
  998. #ifdef md_flush_pending_output
  999. md_flush_pending_output ();
  1000. #endif
  1001. previous_section = now_seg;
  1002. previous_subsection = now_subseg;
  1003. s_data (i);
  1004. #ifdef md_elf_section_change_hook
  1005. md_elf_section_change_hook ();
  1006. #endif
  1007. }
  1008. /* Change to the .text section. */
  1009. void
  1010. obj_elf_text (int i)
  1011. {
  1012. #ifdef md_flush_pending_output
  1013. md_flush_pending_output ();
  1014. #endif
  1015. previous_section = now_seg;
  1016. previous_subsection = now_subseg;
  1017. s_text (i);
  1018. #ifdef md_elf_section_change_hook
  1019. md_elf_section_change_hook ();
  1020. #endif
  1021. }
  1022. /* Change to the *ABS* section. */
  1023. void
  1024. obj_elf_struct (int i)
  1025. {
  1026. #ifdef md_flush_pending_output
  1027. md_flush_pending_output ();
  1028. #endif
  1029. previous_section = now_seg;
  1030. previous_subsection = now_subseg;
  1031. s_struct (i);
  1032. #ifdef md_elf_section_change_hook
  1033. md_elf_section_change_hook ();
  1034. #endif
  1035. }
  1036. static void
  1037. obj_elf_subsection (int ignore ATTRIBUTE_UNUSED)
  1038. {
  1039. int temp;
  1040. #ifdef md_flush_pending_output
  1041. md_flush_pending_output ();
  1042. #endif
  1043. previous_section = now_seg;
  1044. previous_subsection = now_subseg;
  1045. temp = get_absolute_expression ();
  1046. subseg_set (now_seg, (subsegT) temp);
  1047. demand_empty_rest_of_line ();
  1048. #ifdef md_elf_section_change_hook
  1049. md_elf_section_change_hook ();
  1050. #endif
  1051. }
  1052. /* This can be called from the processor backends if they change
  1053. sections. */
  1054. void
  1055. obj_elf_section_change_hook (void)
  1056. {
  1057. previous_section = now_seg;
  1058. previous_subsection = now_subseg;
  1059. }
  1060. void
  1061. obj_elf_previous (int ignore ATTRIBUTE_UNUSED)
  1062. {
  1063. segT new_section;
  1064. int new_subsection;
  1065. if (previous_section == 0)
  1066. {
  1067. as_warn (_(".previous without corresponding .section; ignored"));
  1068. return;
  1069. }
  1070. #ifdef md_flush_pending_output
  1071. md_flush_pending_output ();
  1072. #endif
  1073. new_section = previous_section;
  1074. new_subsection = previous_subsection;
  1075. previous_section = now_seg;
  1076. previous_subsection = now_subseg;
  1077. subseg_set (new_section, new_subsection);
  1078. #ifdef md_elf_section_change_hook
  1079. md_elf_section_change_hook ();
  1080. #endif
  1081. }
  1082. static void
  1083. obj_elf_popsection (int xxx ATTRIBUTE_UNUSED)
  1084. {
  1085. struct section_stack *top = section_stack;
  1086. if (top == NULL)
  1087. {
  1088. as_warn (_(".popsection without corresponding .pushsection; ignored"));
  1089. return;
  1090. }
  1091. #ifdef md_flush_pending_output
  1092. md_flush_pending_output ();
  1093. #endif
  1094. section_stack = top->next;
  1095. previous_section = top->prev_seg;
  1096. previous_subsection = top->prev_subseg;
  1097. subseg_set (top->seg, top->subseg);
  1098. free (top);
  1099. #ifdef md_elf_section_change_hook
  1100. md_elf_section_change_hook ();
  1101. #endif
  1102. }
  1103. static void
  1104. obj_elf_line (int ignore ATTRIBUTE_UNUSED)
  1105. {
  1106. /* Assume delimiter is part of expression. BSD4.2 as fails with
  1107. delightful bug, so we are not being incompatible here. */
  1108. new_logical_line (NULL, get_absolute_expression ());
  1109. demand_empty_rest_of_line ();
  1110. }
  1111. /* This handles the .symver pseudo-op, which is used to specify a
  1112. symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
  1113. SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
  1114. pseudo-op causes the assembler to emit a symbol named SYMVERNAME
  1115. with the same value as the symbol NAME. */
  1116. static void
  1117. obj_elf_symver (int ignore ATTRIBUTE_UNUSED)
  1118. {
  1119. char *name;
  1120. char c;
  1121. char old_lexat;
  1122. symbolS *sym;
  1123. sym = get_sym_from_input_line_and_check ();
  1124. if (*input_line_pointer != ',')
  1125. {
  1126. as_bad (_("expected comma after name in .symver"));
  1127. ignore_rest_of_line ();
  1128. return;
  1129. }
  1130. ++input_line_pointer;
  1131. SKIP_WHITESPACE ();
  1132. /* Temporarily include '@' in symbol names. */
  1133. old_lexat = lex_type[(unsigned char) '@'];
  1134. lex_type[(unsigned char) '@'] |= LEX_NAME;
  1135. c = get_symbol_name (& name);
  1136. lex_type[(unsigned char) '@'] = old_lexat;
  1137. if (symbol_get_obj (sym)->versioned_name == NULL)
  1138. {
  1139. symbol_get_obj (sym)->versioned_name = xstrdup (name);
  1140. (void) restore_line_pointer (c);
  1141. if (strchr (symbol_get_obj (sym)->versioned_name,
  1142. ELF_VER_CHR) == NULL)
  1143. {
  1144. as_bad (_("missing version name in `%s' for symbol `%s'"),
  1145. symbol_get_obj (sym)->versioned_name,
  1146. S_GET_NAME (sym));
  1147. ignore_rest_of_line ();
  1148. return;
  1149. }
  1150. }
  1151. else
  1152. {
  1153. if (strcmp (symbol_get_obj (sym)->versioned_name, name))
  1154. {
  1155. as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
  1156. name, symbol_get_obj (sym)->versioned_name,
  1157. S_GET_NAME (sym));
  1158. ignore_rest_of_line ();
  1159. return;
  1160. }
  1161. (void) restore_line_pointer (c);
  1162. }
  1163. demand_empty_rest_of_line ();
  1164. }
  1165. /* This handles the .vtable_inherit pseudo-op, which is used to indicate
  1166. to the linker the hierarchy in which a particular table resides. The
  1167. syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
  1168. struct fix *
  1169. obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED)
  1170. {
  1171. char *cname, *pname;
  1172. symbolS *csym, *psym;
  1173. char c, bad = 0;
  1174. if (*input_line_pointer == '#')
  1175. ++input_line_pointer;
  1176. c = get_symbol_name (& cname);
  1177. csym = symbol_find (cname);
  1178. /* GCFIXME: should check that we don't have two .vtable_inherits for
  1179. the same child symbol. Also, we can currently only do this if the
  1180. child symbol is already exists and is placed in a fragment. */
  1181. if (csym == NULL || symbol_get_frag (csym) == NULL)
  1182. {
  1183. as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
  1184. cname);
  1185. bad = 1;
  1186. }
  1187. *input_line_pointer = c;
  1188. SKIP_WHITESPACE_AFTER_NAME ();
  1189. if (*input_line_pointer != ',')
  1190. {
  1191. as_bad (_("expected comma after name in .vtable_inherit"));
  1192. ignore_rest_of_line ();
  1193. return NULL;
  1194. }
  1195. ++input_line_pointer;
  1196. SKIP_WHITESPACE ();
  1197. if (*input_line_pointer == '#')
  1198. ++input_line_pointer;
  1199. if (input_line_pointer[0] == '0'
  1200. && (input_line_pointer[1] == '\0'
  1201. || ISSPACE (input_line_pointer[1])))
  1202. {
  1203. psym = section_symbol (absolute_section);
  1204. ++input_line_pointer;
  1205. }
  1206. else
  1207. {
  1208. c = get_symbol_name (& pname);
  1209. psym = symbol_find_or_make (pname);
  1210. restore_line_pointer (c);
  1211. }
  1212. demand_empty_rest_of_line ();
  1213. if (bad)
  1214. return NULL;
  1215. gas_assert (symbol_get_value_expression (csym)->X_op == O_constant);
  1216. return fix_new (symbol_get_frag (csym),
  1217. symbol_get_value_expression (csym)->X_add_number,
  1218. 0, psym, 0, 0, BFD_RELOC_VTABLE_INHERIT);
  1219. }
  1220. /* This handles the .vtable_entry pseudo-op, which is used to indicate
  1221. to the linker that a vtable slot was used. The syntax is
  1222. ".vtable_entry tablename, offset". */
  1223. struct fix *
  1224. obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED)
  1225. {
  1226. symbolS *sym;
  1227. offsetT offset;
  1228. if (*input_line_pointer == '#')
  1229. ++input_line_pointer;
  1230. sym = get_sym_from_input_line_and_check ();
  1231. if (*input_line_pointer != ',')
  1232. {
  1233. as_bad (_("expected comma after name in .vtable_entry"));
  1234. ignore_rest_of_line ();
  1235. return NULL;
  1236. }
  1237. ++input_line_pointer;
  1238. if (*input_line_pointer == '#')
  1239. ++input_line_pointer;
  1240. offset = get_absolute_expression ();
  1241. demand_empty_rest_of_line ();
  1242. return fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0,
  1243. BFD_RELOC_VTABLE_ENTRY);
  1244. }
  1245. #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
  1246. static inline int
  1247. skip_past_char (char ** str, char c)
  1248. {
  1249. if (**str == c)
  1250. {
  1251. (*str)++;
  1252. return 0;
  1253. }
  1254. else
  1255. return -1;
  1256. }
  1257. #define skip_past_comma(str) skip_past_char (str, ',')
  1258. /* A list of attributes that have been explicitly set by the assembly code.
  1259. VENDOR is the vendor id, BASE is the tag shifted right by the number
  1260. of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
  1261. struct recorded_attribute_info {
  1262. struct recorded_attribute_info *next;
  1263. int vendor;
  1264. unsigned int base;
  1265. unsigned long mask;
  1266. };
  1267. static struct recorded_attribute_info *recorded_attributes;
  1268. /* Record that we have seen an explicit specification of attribute TAG
  1269. for vendor VENDOR. */
  1270. static void
  1271. record_attribute (int vendor, unsigned int tag)
  1272. {
  1273. unsigned int base;
  1274. unsigned long mask;
  1275. struct recorded_attribute_info *rai;
  1276. base = tag / (8 * sizeof (rai->mask));
  1277. mask = 1UL << (tag % (8 * sizeof (rai->mask)));
  1278. for (rai = recorded_attributes; rai; rai = rai->next)
  1279. if (rai->vendor == vendor && rai->base == base)
  1280. {
  1281. rai->mask |= mask;
  1282. return;
  1283. }
  1284. rai = XNEW (struct recorded_attribute_info);
  1285. rai->next = recorded_attributes;
  1286. rai->vendor = vendor;
  1287. rai->base = base;
  1288. rai->mask = mask;
  1289. recorded_attributes = rai;
  1290. }
  1291. /* Return true if we have seen an explicit specification of attribute TAG
  1292. for vendor VENDOR. */
  1293. bfd_boolean
  1294. obj_elf_seen_attribute (int vendor, unsigned int tag)
  1295. {
  1296. unsigned int base;
  1297. unsigned long mask;
  1298. struct recorded_attribute_info *rai;
  1299. base = tag / (8 * sizeof (rai->mask));
  1300. mask = 1UL << (tag % (8 * sizeof (rai->mask)));
  1301. for (rai = recorded_attributes; rai; rai = rai->next)
  1302. if (rai->vendor == vendor && rai->base == base)
  1303. return (rai->mask & mask) != 0;
  1304. return FALSE;
  1305. }
  1306. /* Parse an attribute directive for VENDOR.
  1307. Returns the attribute number read, or zero on error. */
  1308. int
  1309. obj_elf_vendor_attribute (int vendor)
  1310. {
  1311. expressionS exp;
  1312. int type;
  1313. int tag;
  1314. unsigned int i = 0;
  1315. char *s = NULL;
  1316. /* Read the first number or name. */
  1317. skip_whitespace (input_line_pointer);
  1318. s = input_line_pointer;
  1319. if (ISDIGIT (*input_line_pointer))
  1320. {
  1321. expression (& exp);
  1322. if (exp.X_op != O_constant)
  1323. goto bad;
  1324. tag = exp.X_add_number;
  1325. }
  1326. else
  1327. {
  1328. char *name;
  1329. /* A name may contain '_', but no other punctuation. */
  1330. for (; ISALNUM (*input_line_pointer) || *input_line_pointer == '_';
  1331. ++input_line_pointer)
  1332. i++;
  1333. if (i == 0)
  1334. goto bad;
  1335. name = (char *) alloca (i + 1);
  1336. memcpy (name, s, i);
  1337. name[i] = '\0';
  1338. #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
  1339. #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
  1340. #endif
  1341. tag = CONVERT_SYMBOLIC_ATTRIBUTE (name);
  1342. if (tag == -1)
  1343. {
  1344. as_bad (_("Attribute name not recognised: %s"), name);
  1345. ignore_rest_of_line ();
  1346. return 0;
  1347. }
  1348. }
  1349. type = _bfd_elf_obj_attrs_arg_type (stdoutput, vendor, tag);
  1350. if (skip_past_comma (&input_line_pointer) == -1)
  1351. goto bad;
  1352. if (type & 1)
  1353. {
  1354. expression (& exp);
  1355. if (exp.X_op != O_constant)
  1356. {
  1357. as_bad (_("expected numeric constant"));
  1358. ignore_rest_of_line ();
  1359. return 0;
  1360. }
  1361. i = exp.X_add_number;
  1362. }
  1363. if ((type & 3) == 3
  1364. && skip_past_comma (&input_line_pointer) == -1)
  1365. {
  1366. as_bad (_("expected comma"));
  1367. ignore_rest_of_line ();
  1368. return 0;
  1369. }
  1370. if (type & 2)
  1371. {
  1372. int len;
  1373. skip_whitespace (input_line_pointer);
  1374. if (*input_line_pointer != '"')
  1375. goto bad_string;
  1376. s = demand_copy_C_string (&len);
  1377. }
  1378. record_attribute (vendor, tag);
  1379. switch (type & 3)
  1380. {
  1381. case 3:
  1382. bfd_elf_add_obj_attr_int_string (stdoutput, vendor, tag, i, s);
  1383. break;
  1384. case 2:
  1385. bfd_elf_add_obj_attr_string (stdoutput, vendor, tag, s);
  1386. break;
  1387. case 1:
  1388. bfd_elf_add_obj_attr_int (stdoutput, vendor, tag, i);
  1389. break;
  1390. default:
  1391. abort ();
  1392. }
  1393. demand_empty_rest_of_line ();
  1394. return tag;
  1395. bad_string:
  1396. as_bad (_("bad string constant"));
  1397. ignore_rest_of_line ();
  1398. return 0;
  1399. bad:
  1400. as_bad (_("expected <tag> , <value>"));
  1401. ignore_rest_of_line ();
  1402. return 0;
  1403. }
  1404. /* Parse a .gnu_attribute directive. */
  1405. static void
  1406. obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
  1407. {
  1408. obj_elf_vendor_attribute (OBJ_ATTR_GNU);
  1409. }
  1410. void
  1411. elf_obj_read_begin_hook (void)
  1412. {
  1413. #ifdef NEED_ECOFF_DEBUG
  1414. if (ECOFF_DEBUGGING)
  1415. ecoff_read_begin_hook ();
  1416. #endif
  1417. }
  1418. void
  1419. elf_obj_symbol_new_hook (symbolS *symbolP)
  1420. {
  1421. struct elf_obj_sy *sy_obj;
  1422. sy_obj = symbol_get_obj (symbolP);
  1423. sy_obj->size = NULL;
  1424. sy_obj->versioned_name = NULL;
  1425. #ifdef NEED_ECOFF_DEBUG
  1426. if (ECOFF_DEBUGGING)
  1427. ecoff_symbol_new_hook (symbolP);
  1428. #endif
  1429. }
  1430. /* When setting one symbol equal to another, by default we probably
  1431. want them to have the same "size", whatever it means in the current
  1432. context. */
  1433. void
  1434. elf_copy_symbol_attributes (symbolS *dest, symbolS *src)
  1435. {
  1436. struct elf_obj_sy *srcelf = symbol_get_obj (src);
  1437. struct elf_obj_sy *destelf = symbol_get_obj (dest);
  1438. if (srcelf->size)
  1439. {
  1440. if (destelf->size == NULL)
  1441. destelf->size = (expressionS *) xmalloc (sizeof (expressionS));
  1442. *destelf->size = *srcelf->size;
  1443. }
  1444. else
  1445. {
  1446. if (destelf->size != NULL)
  1447. free (destelf->size);
  1448. destelf->size = NULL;
  1449. }
  1450. S_SET_SIZE (dest, S_GET_SIZE (src));
  1451. /* Don't copy visibility. */
  1452. S_SET_OTHER (dest, (ELF_ST_VISIBILITY (S_GET_OTHER (dest))
  1453. | (S_GET_OTHER (src) & ~ELF_ST_VISIBILITY (-1))));
  1454. }
  1455. void
  1456. obj_elf_version (int ignore ATTRIBUTE_UNUSED)
  1457. {
  1458. char *name;
  1459. unsigned int c;
  1460. char *p;
  1461. asection *seg = now_seg;
  1462. subsegT subseg = now_subseg;
  1463. Elf_Internal_Note i_note;
  1464. Elf_External_Note e_note;
  1465. asection *note_secp = NULL;
  1466. SKIP_WHITESPACE ();
  1467. if (*input_line_pointer == '\"')
  1468. {
  1469. unsigned int len;
  1470. ++input_line_pointer; /* -> 1st char of string. */
  1471. name = input_line_pointer;
  1472. while (is_a_char (c = next_char_of_string ()))
  1473. ;
  1474. c = *input_line_pointer;
  1475. *input_line_pointer = '\0';
  1476. *(input_line_pointer - 1) = '\0';
  1477. *input_line_pointer = c;
  1478. /* Create the .note section. */
  1479. note_secp = subseg_new (".note", 0);
  1480. bfd_set_section_flags (stdoutput,
  1481. note_secp,
  1482. SEC_HAS_CONTENTS | SEC_READONLY);
  1483. /* Process the version string. */
  1484. len = strlen (name) + 1;
  1485. /* PR 3456: Although the name field is padded out to an 4-byte
  1486. boundary, the namesz field should not be adjusted. */
  1487. i_note.namesz = len;
  1488. i_note.descsz = 0; /* No description. */
  1489. i_note.type = NT_VERSION;
  1490. p = frag_more (sizeof (e_note.namesz));
  1491. md_number_to_chars (p, i_note.namesz, sizeof (e_note.namesz));
  1492. p = frag_more (sizeof (e_note.descsz));
  1493. md_number_to_chars (p, i_note.descsz, sizeof (e_note.descsz));
  1494. p = frag_more (sizeof (e_note.type));
  1495. md_number_to_chars (p, i_note.type, sizeof (e_note.type));
  1496. p = frag_more (len);
  1497. memcpy (p, name, len);
  1498. frag_align (2, 0, 0);
  1499. subseg_set (seg, subseg);
  1500. }
  1501. else
  1502. as_bad (_("expected quoted string"));
  1503. demand_empty_rest_of_line ();
  1504. }
  1505. static void
  1506. obj_elf_size (int ignore ATTRIBUTE_UNUSED)
  1507. {
  1508. char *name;
  1509. char c = get_symbol_name (&name);
  1510. char *p;
  1511. expressionS exp;
  1512. symbolS *sym;
  1513. p = input_line_pointer;
  1514. *p = c;
  1515. SKIP_WHITESPACE_AFTER_NAME ();
  1516. if (*input_line_pointer != ',')
  1517. {
  1518. *p = 0;
  1519. as_bad (_("expected comma after name `%s' in .size directive"), name);
  1520. *p = c;
  1521. ignore_rest_of_line ();
  1522. return;
  1523. }
  1524. input_line_pointer++;
  1525. expression (&exp);
  1526. if (exp.X_op == O_absent)
  1527. {
  1528. as_bad (_("missing expression in .size directive"));
  1529. exp.X_op = O_constant;
  1530. exp.X_add_number = 0;
  1531. }
  1532. *p = 0;
  1533. sym = symbol_find_or_make (name);
  1534. *p = c;
  1535. if (exp.X_op == O_constant)
  1536. {
  1537. S_SET_SIZE (sym, exp.X_add_number);
  1538. if (symbol_get_obj (sym)->size)
  1539. {
  1540. xfree (symbol_get_obj (sym)->size);
  1541. symbol_get_obj (sym)->size = NULL;
  1542. }
  1543. }
  1544. else
  1545. {
  1546. symbol_get_obj (sym)->size =
  1547. (expressionS *) xmalloc (sizeof (expressionS));
  1548. *symbol_get_obj (sym)->size = exp;
  1549. }
  1550. demand_empty_rest_of_line ();
  1551. }
  1552. /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
  1553. There are six syntaxes:
  1554. The first (used on Solaris) is
  1555. .type SYM,#function
  1556. The second (used on UnixWare) is
  1557. .type SYM,@function
  1558. The third (reportedly to be used on Irix 6.0) is
  1559. .type SYM STT_FUNC
  1560. The fourth (used on NetBSD/Arm and Linux/ARM) is
  1561. .type SYM,%function
  1562. The fifth (used on SVR4/860) is
  1563. .type SYM,"function"
  1564. The sixth (emitted by recent SunPRO under Solaris) is
  1565. .type SYM,[0-9]
  1566. where the integer is the STT_* value.
  1567. */
  1568. static char *
  1569. obj_elf_type_name (char *cp)
  1570. {
  1571. char *p;
  1572. p = input_line_pointer;
  1573. if (*input_line_pointer >= '0'
  1574. && *input_line_pointer <= '9')
  1575. {
  1576. while (*input_line_pointer >= '0'
  1577. && *input_line_pointer <= '9')
  1578. ++input_line_pointer;
  1579. *cp = *input_line_pointer;
  1580. *input_line_pointer = '\0';
  1581. }
  1582. else
  1583. *cp = get_symbol_name (&p);
  1584. return p;
  1585. }
  1586. static void
  1587. obj_elf_type (int ignore ATTRIBUTE_UNUSED)
  1588. {
  1589. char c;
  1590. int type;
  1591. const char *type_name;
  1592. symbolS *sym;
  1593. elf_symbol_type *elfsym;
  1594. sym = get_sym_from_input_line_and_check ();
  1595. c = *input_line_pointer;
  1596. elfsym = (elf_symbol_type *) symbol_get_bfdsym (sym);
  1597. if (*input_line_pointer == ',')
  1598. ++input_line_pointer;
  1599. SKIP_WHITESPACE ();
  1600. if ( *input_line_pointer == '#'
  1601. || *input_line_pointer == '@'
  1602. || *input_line_pointer == '"'
  1603. || *input_line_pointer == '%')
  1604. ++input_line_pointer;
  1605. type_name = obj_elf_type_name (& c);
  1606. type = 0;
  1607. if (strcmp (type_name, "function") == 0
  1608. || strcmp (type_name, "2") == 0
  1609. || strcmp (type_name, "STT_FUNC") == 0)
  1610. type = BSF_FUNCTION;
  1611. else if (strcmp (type_name, "object") == 0
  1612. || strcmp (type_name, "1") == 0
  1613. || strcmp (type_name, "STT_OBJECT") == 0)
  1614. type = BSF_OBJECT;
  1615. else if (strcmp (type_name, "tls_object") == 0
  1616. || strcmp (type_name, "6") == 0
  1617. || strcmp (type_name, "STT_TLS") == 0)
  1618. type = BSF_OBJECT | BSF_THREAD_LOCAL;
  1619. else if (strcmp (type_name, "notype") == 0
  1620. || strcmp (type_name, "0") == 0
  1621. || strcmp (type_name, "STT_NOTYPE") == 0)
  1622. ;
  1623. else if (strcmp (type_name, "common") == 0
  1624. || strcmp (type_name, "5") == 0
  1625. || strcmp (type_name, "STT_COMMON") == 0)
  1626. {
  1627. type = BSF_OBJECT;
  1628. if (! S_IS_COMMON (sym))
  1629. {
  1630. if (S_IS_VOLATILE (sym))
  1631. {
  1632. sym = symbol_clone (sym, 1);
  1633. S_SET_SEGMENT (sym, bfd_com_section_ptr);
  1634. S_SET_VALUE (sym, 0);
  1635. S_SET_EXTERNAL (sym);
  1636. symbol_set_frag (sym, &zero_address_frag);
  1637. S_CLEAR_VOLATILE (sym);
  1638. }
  1639. else if (S_IS_DEFINED (sym) || symbol_equated_p (sym))
  1640. as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym));
  1641. else
  1642. {
  1643. /* FIXME: Is it safe to just change the section ? */
  1644. S_SET_SEGMENT (sym, bfd_com_section_ptr);
  1645. S_SET_VALUE (sym, 0);
  1646. S_SET_EXTERNAL (sym);
  1647. }
  1648. }
  1649. }
  1650. else if (strcmp (type_name, "gnu_indirect_function") == 0
  1651. || strcmp (type_name, "10") == 0
  1652. || strcmp (type_name, "STT_GNU_IFUNC") == 0)
  1653. {
  1654. const struct elf_backend_data *bed;
  1655. bed = get_elf_backend_data (stdoutput);
  1656. if (!(bed->elf_osabi == ELFOSABI_GNU
  1657. || bed->elf_osabi == ELFOSABI_FREEBSD
  1658. /* GNU is still using the default value 0. */
  1659. || bed->elf_osabi == ELFOSABI_NONE))
  1660. as_bad (_("symbol type \"%s\" is supported only by GNU and FreeBSD targets"),
  1661. type_name);
  1662. type = BSF_FUNCTION | BSF_GNU_INDIRECT_FUNCTION;
  1663. }
  1664. else if (strcmp (type_name, "gnu_unique_object") == 0)
  1665. {
  1666. struct elf_backend_data *bed;
  1667. bed = (struct elf_backend_data *) get_elf_backend_data (stdoutput);
  1668. if (!(bed->elf_osabi == ELFOSABI_GNU
  1669. /* GNU is still using the default value 0. */
  1670. || bed->elf_osabi == ELFOSABI_NONE))
  1671. as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
  1672. type_name);
  1673. type = BSF_OBJECT | BSF_GNU_UNIQUE;
  1674. /* PR 10549: Always set OSABI field to GNU for objects containing unique symbols. */
  1675. bed->elf_osabi = ELFOSABI_GNU;
  1676. }
  1677. #ifdef md_elf_symbol_type
  1678. else if ((type = md_elf_symbol_type (type_name, sym, elfsym)) != -1)
  1679. ;
  1680. #endif
  1681. else
  1682. as_bad (_("unrecognized symbol type \"%s\""), type_name);
  1683. *input_line_pointer = c;
  1684. if (*input_line_pointer == '"')
  1685. ++input_line_pointer;
  1686. elfsym->symbol.flags |= type;
  1687. demand_empty_rest_of_line ();
  1688. }
  1689. static void
  1690. obj_elf_ident (int ignore ATTRIBUTE_UNUSED)
  1691. {
  1692. static segT comment_section;
  1693. segT old_section = now_seg;
  1694. int old_subsection = now_subseg;
  1695. #ifdef md_flush_pending_output
  1696. md_flush_pending_output ();
  1697. #endif
  1698. if (!comment_section)
  1699. {
  1700. char *p;
  1701. comment_section = subseg_new (".comment", 0);
  1702. bfd_set_section_flags (stdoutput, comment_section,
  1703. SEC_READONLY | SEC_HAS_CONTENTS
  1704. | SEC_MERGE | SEC_STRINGS);
  1705. comment_section->entsize = 1;
  1706. #ifdef md_elf_section_change_hook
  1707. md_elf_section_change_hook ();
  1708. #endif
  1709. p = frag_more (1);
  1710. *p = 0;
  1711. }
  1712. else
  1713. subseg_set (comment_section, 0);
  1714. stringer (8 + 1);
  1715. subseg_set (old_section, old_subsection);
  1716. }
  1717. #ifdef INIT_STAB_SECTION
  1718. /* The first entry in a .stabs section is special. */
  1719. void
  1720. obj_elf_init_stab_section (segT seg)
  1721. {
  1722. char *file;
  1723. char *p;
  1724. char *stabstr_name;
  1725. unsigned int stroff;
  1726. /* Force the section to align to a longword boundary. Without this,
  1727. UnixWare ar crashes. */
  1728. bfd_set_section_alignment (stdoutput, seg, 2);
  1729. /* Make space for this first symbol. */
  1730. p = frag_more (12);
  1731. /* Zero it out. */
  1732. memset (p, 0, 12);
  1733. as_where (&file, NULL);
  1734. stabstr_name = (char *) xmalloc (strlen (segment_name (seg)) + 4);
  1735. strcpy (stabstr_name, segment_name (seg));
  1736. strcat (stabstr_name, "str");
  1737. stroff = get_stab_string_offset (file, stabstr_name);
  1738. know (stroff == 1 || (stroff == 0 && file[0] == '\0'));
  1739. md_number_to_chars (p, stroff, 4);
  1740. seg_info (seg)->stabu.p = p;
  1741. }
  1742. #endif
  1743. /* Fill in the counts in the first entry in a .stabs section. */
  1744. static void
  1745. adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED)
  1746. {
  1747. char *name;
  1748. asection *strsec;
  1749. char *p;
  1750. int strsz, nsyms;
  1751. if (strncmp (".stab", sec->name, 5))
  1752. return;
  1753. if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
  1754. return;
  1755. name = (char *) alloca (strlen (sec->name) + 4);
  1756. strcpy (name, sec->name);
  1757. strcat (name, "str");
  1758. strsec = bfd_get_section_by_name (abfd, name);
  1759. if (strsec)
  1760. strsz = bfd_section_size (abfd, strsec);
  1761. else
  1762. strsz = 0;
  1763. nsyms = bfd_section_size (abfd, sec) / 12 - 1;
  1764. p = seg_info (sec)->stabu.p;
  1765. gas_assert (p != 0);
  1766. bfd_h_put_16 (abfd, nsyms, p + 6);
  1767. bfd_h_put_32 (abfd, strsz, p + 8);
  1768. }
  1769. #ifdef NEED_ECOFF_DEBUG
  1770. /* This function is called by the ECOFF code. It is supposed to
  1771. record the external symbol information so that the backend can
  1772. write it out correctly. The ELF backend doesn't actually handle
  1773. this at the moment, so we do it ourselves. We save the information
  1774. in the symbol. */
  1775. #ifdef OBJ_MAYBE_ELF
  1776. static
  1777. #endif
  1778. void
  1779. elf_ecoff_set_ext (symbolS *sym, struct ecoff_extr *ext)
  1780. {
  1781. symbol_get_bfdsym (sym)->udata.p = ext;
  1782. }
  1783. /* This function is called by bfd_ecoff_debug_externals. It is
  1784. supposed to *EXT to the external symbol information, and return
  1785. whether the symbol should be used at all. */
  1786. static bfd_boolean
  1787. elf_get_extr (asymbol *sym, EXTR *ext)
  1788. {
  1789. if (sym->udata.p == NULL)
  1790. return FALSE;
  1791. *ext = *(EXTR *) sym->udata.p;
  1792. return TRUE;
  1793. }
  1794. /* This function is called by bfd_ecoff_debug_externals. It has
  1795. nothing to do for ELF. */
  1796. static void
  1797. elf_set_index (asymbol *sym ATTRIBUTE_UNUSED,
  1798. bfd_size_type indx ATTRIBUTE_UNUSED)
  1799. {
  1800. }
  1801. #endif /* NEED_ECOFF_DEBUG */
  1802. void
  1803. elf_frob_symbol (symbolS *symp, int *puntp)
  1804. {
  1805. struct elf_obj_sy *sy_obj;
  1806. expressionS *size;
  1807. #ifdef NEED_ECOFF_DEBUG
  1808. if (ECOFF_DEBUGGING)
  1809. ecoff_frob_symbol (symp);
  1810. #endif
  1811. sy_obj = symbol_get_obj (symp);
  1812. size = sy_obj->size;
  1813. if (size != NULL)
  1814. {
  1815. if (resolve_expression (size)
  1816. && size->X_op == O_constant)
  1817. S_SET_SIZE (symp, size->X_add_number);
  1818. else
  1819. {
  1820. if (flag_size_check == size_check_error)
  1821. as_bad (_(".size expression for %s "
  1822. "does not evaluate to a constant"), S_GET_NAME (symp));
  1823. else
  1824. as_warn (_(".size expression for %s "
  1825. "does not evaluate to a constant"), S_GET_NAME (symp));
  1826. }
  1827. free (sy_obj->size);
  1828. sy_obj->size = NULL;
  1829. }
  1830. if (sy_obj->versioned_name != NULL)
  1831. {
  1832. char *p;
  1833. p = strchr (sy_obj->versioned_name, ELF_VER_CHR);
  1834. if (p == NULL)
  1835. /* We will have already reported an error about a missing version. */
  1836. *puntp = TRUE;
  1837. /* This symbol was given a new name with the .symver directive.
  1838. If this is an external reference, just rename the symbol to
  1839. include the version string. This will make the relocs be
  1840. against the correct versioned symbol.
  1841. If this is a definition, add an alias. FIXME: Using an alias
  1842. will permit the debugging information to refer to the right
  1843. symbol. However, it's not clear whether it is the best
  1844. approach. */
  1845. else if (! S_IS_DEFINED (symp))
  1846. {
  1847. /* Verify that the name isn't using the @@ syntax--this is
  1848. reserved for definitions of the default version to link
  1849. against. */
  1850. if (p[1] == ELF_VER_CHR)
  1851. {
  1852. as_bad (_("invalid attempt to declare external version name"
  1853. " as default in symbol `%s'"),
  1854. sy_obj->versioned_name);
  1855. *puntp = TRUE;
  1856. }
  1857. S_SET_NAME (symp, sy_obj->versioned_name);
  1858. }
  1859. else
  1860. {
  1861. if (p[1] == ELF_VER_CHR && p[2] == ELF_VER_CHR)
  1862. {
  1863. size_t l;
  1864. /* The @@@ syntax is a special case. It renames the
  1865. symbol name to versioned_name with one `@' removed. */
  1866. l = strlen (&p[3]) + 1;
  1867. memmove (&p[2], &p[3], l);
  1868. S_SET_NAME (symp, sy_obj->versioned_name);
  1869. }
  1870. else
  1871. {
  1872. symbolS *symp2;
  1873. /* FIXME: Creating a new symbol here is risky. We're
  1874. in the final loop over the symbol table. We can
  1875. get away with it only because the symbol goes to
  1876. the end of the list, where the loop will still see
  1877. it. It would probably be better to do this in
  1878. obj_frob_file_before_adjust. */
  1879. symp2 = symbol_find_or_make (sy_obj->versioned_name);
  1880. /* Now we act as though we saw symp2 = sym. */
  1881. S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp));
  1882. /* Subtracting out the frag address here is a hack
  1883. because we are in the middle of the final loop. */
  1884. S_SET_VALUE (symp2,
  1885. (S_GET_VALUE (symp)
  1886. - symbol_get_frag (symp)->fr_address));
  1887. symbol_set_frag (symp2, symbol_get_frag (symp));
  1888. /* This will copy over the size information. */
  1889. copy_symbol_attributes (symp2, symp);
  1890. S_SET_OTHER (symp2, S_GET_OTHER (symp));
  1891. if (S_IS_WEAK (symp))
  1892. S_SET_WEAK (symp2);
  1893. if (S_IS_EXTERNAL (symp))
  1894. S_SET_EXTERNAL (symp2);
  1895. }
  1896. }
  1897. }
  1898. /* Double check weak symbols. */
  1899. if (S_IS_WEAK (symp))
  1900. {
  1901. if (S_IS_COMMON (symp))
  1902. as_bad (_("symbol `%s' can not be both weak and common"),
  1903. S_GET_NAME (symp));
  1904. }
  1905. #ifdef TC_MIPS
  1906. /* The Irix 5 and 6 assemblers set the type of any common symbol and
  1907. any undefined non-function symbol to STT_OBJECT. We try to be
  1908. compatible, since newer Irix 5 and 6 linkers care. However, we
  1909. only set undefined symbols to be STT_OBJECT if we are on Irix,
  1910. because that is the only time gcc will generate the necessary
  1911. .global directives to mark functions. */
  1912. if (S_IS_COMMON (symp))
  1913. symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
  1914. if (strstr (TARGET_OS, "irix") != NULL
  1915. && ! S_IS_DEFINED (symp)
  1916. && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0)
  1917. symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
  1918. #endif
  1919. }
  1920. struct group_list
  1921. {
  1922. asection **head; /* Section lists. */
  1923. unsigned int *elt_count; /* Number of sections in each list. */
  1924. unsigned int num_group; /* Number of lists. */
  1925. struct hash_control *indexes; /* Maps group name to index in head array. */
  1926. };
  1927. /* Called via bfd_map_over_sections. If SEC is a member of a group,
  1928. add it to a list of sections belonging to the group. INF is a
  1929. pointer to a struct group_list, which is where we store the head of
  1930. each list. */
  1931. static void
  1932. build_group_lists (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf)
  1933. {
  1934. struct group_list *list = (struct group_list *) inf;
  1935. const char *group_name = elf_group_name (sec);
  1936. unsigned int i;
  1937. unsigned int *elem_idx;
  1938. unsigned int *idx_ptr;
  1939. if (group_name == NULL)
  1940. return;
  1941. /* If this group already has a list, add the section to the head of
  1942. the list. */
  1943. elem_idx = (unsigned int *) hash_find (list->indexes, group_name);
  1944. if (elem_idx != NULL)
  1945. {
  1946. elf_next_in_group (sec) = list->head[*elem_idx];
  1947. list->head[*elem_idx] = sec;
  1948. list->elt_count[*elem_idx] += 1;
  1949. return;
  1950. }
  1951. /* New group. Make the arrays bigger in chunks to minimize calls to
  1952. realloc. */
  1953. i = list->num_group;
  1954. if ((i & 127) == 0)
  1955. {
  1956. unsigned int newsize = i + 128;
  1957. list->head = (asection **) xrealloc (list->head,
  1958. newsize * sizeof (*list->head));
  1959. list->elt_count = (unsigned int *)
  1960. xrealloc (list->elt_count, newsize * sizeof (*list->elt_count));
  1961. }
  1962. list->head[i] = sec;
  1963. list->elt_count[i] = 1;
  1964. list->num_group += 1;
  1965. /* Add index to hash. */
  1966. idx_ptr = (unsigned int *) xmalloc (sizeof (unsigned int));
  1967. *idx_ptr = i;
  1968. hash_insert (list->indexes, group_name, idx_ptr);
  1969. }
  1970. static void free_section_idx (const char *key ATTRIBUTE_UNUSED, void *val)
  1971. {
  1972. free ((unsigned int *) val);
  1973. }
  1974. void
  1975. elf_adjust_symtab (void)
  1976. {
  1977. struct group_list list;
  1978. unsigned int i;
  1979. /* Go find section groups. */
  1980. list.num_group = 0;
  1981. list.head = NULL;
  1982. list.elt_count = NULL;
  1983. list.indexes = hash_new ();
  1984. bfd_map_over_sections (stdoutput, build_group_lists, &list);
  1985. /* Make the SHT_GROUP sections that describe each section group. We
  1986. can't set up the section contents here yet, because elf section
  1987. indices have yet to be calculated. elf.c:set_group_contents does
  1988. the rest of the work. */
  1989. for (i = 0; i < list.num_group; i++)
  1990. {
  1991. const char *group_name = elf_group_name (list.head[i]);
  1992. const char *sec_name;
  1993. asection *s;
  1994. flagword flags;
  1995. struct symbol *sy;
  1996. bfd_size_type size;
  1997. flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_GROUP;
  1998. for (s = list.head[i]; s != NULL; s = elf_next_in_group (s))
  1999. if ((s->flags ^ flags) & SEC_LINK_ONCE)
  2000. {
  2001. flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
  2002. if (s != list.head[i])
  2003. {
  2004. as_warn (_("assuming all members of group `%s' are COMDAT"),
  2005. group_name);
  2006. break;
  2007. }
  2008. }
  2009. sec_name = ".group";
  2010. s = subseg_force_new (sec_name, 0);
  2011. if (s == NULL
  2012. || !bfd_set_section_flags (stdoutput, s, flags)
  2013. || !bfd_set_section_alignment (stdoutput, s, 2))
  2014. {
  2015. as_fatal (_("can't create group: %s"),
  2016. bfd_errmsg (bfd_get_error ()));
  2017. }
  2018. elf_section_type (s) = SHT_GROUP;
  2019. /* Pass a pointer to the first section in this group. */
  2020. elf_next_in_group (s) = list.head[i];
  2021. /* Make sure that the signature symbol for the group has the
  2022. name of the group. */
  2023. sy = symbol_find_exact (group_name);
  2024. if (!sy
  2025. || (sy != symbol_lastP
  2026. && (sy->sy_next == NULL
  2027. || sy->sy_next->sy_previous != sy)))
  2028. {
  2029. /* Create the symbol now. */
  2030. sy = symbol_new (group_name, now_seg, (valueT) 0, frag_now);
  2031. #ifdef TE_SOLARIS
  2032. /* Before Solaris 11 build 154, Sun ld rejects local group
  2033. signature symbols, so make them weak hidden instead. */
  2034. symbol_get_bfdsym (sy)->flags |= BSF_WEAK;
  2035. S_SET_OTHER (sy, STV_HIDDEN);
  2036. #else
  2037. symbol_get_obj (sy)->local = 1;
  2038. #endif
  2039. symbol_table_insert (sy);
  2040. }
  2041. elf_group_id (s) = symbol_get_bfdsym (sy);
  2042. size = 4 * (list.elt_count[i] + 1);
  2043. bfd_set_section_size (stdoutput, s, size);
  2044. s->contents = (unsigned char *) frag_more (size);
  2045. frag_now->fr_fix = frag_now_fix_octets ();
  2046. frag_wane (frag_now);
  2047. }
  2048. /* Cleanup hash. */
  2049. hash_traverse (list.indexes, free_section_idx);
  2050. hash_die (list.indexes);
  2051. }
  2052. void
  2053. elf_frob_file (void)
  2054. {
  2055. bfd_map_over_sections (stdoutput, adjust_stab_sections, NULL);
  2056. #ifdef elf_tc_final_processing
  2057. elf_tc_final_processing ();
  2058. #endif
  2059. }
  2060. /* It removes any unneeded versioned symbols from the symbol table. */
  2061. void
  2062. elf_frob_file_before_adjust (void)
  2063. {
  2064. if (symbol_rootP)
  2065. {
  2066. symbolS *symp;
  2067. for (symp = symbol_rootP; symp; symp = symbol_next (symp))
  2068. if (!S_IS_DEFINED (symp))
  2069. {
  2070. if (symbol_get_obj (symp)->versioned_name)
  2071. {
  2072. char *p;
  2073. /* The @@@ syntax is a special case. If the symbol is
  2074. not defined, 2 `@'s will be removed from the
  2075. versioned_name. */
  2076. p = strchr (symbol_get_obj (symp)->versioned_name,
  2077. ELF_VER_CHR);
  2078. if (p != NULL && p[1] == ELF_VER_CHR && p[2] == ELF_VER_CHR)
  2079. {
  2080. size_t l = strlen (&p[3]) + 1;
  2081. memmove (&p[1], &p[3], l);
  2082. }
  2083. if (symbol_used_p (symp) == 0
  2084. && symbol_used_in_reloc_p (symp) == 0)
  2085. symbol_remove (symp, &symbol_rootP, &symbol_lastP);
  2086. }
  2087. /* If there was .weak foo, but foo was neither defined nor
  2088. used anywhere, remove it. */
  2089. else if (S_IS_WEAK (symp)
  2090. && symbol_used_p (symp) == 0
  2091. && symbol_used_in_reloc_p (symp) == 0)
  2092. symbol_remove (symp, &symbol_rootP, &symbol_lastP);
  2093. }
  2094. }
  2095. }
  2096. /* It is required that we let write_relocs have the opportunity to
  2097. optimize away fixups before output has begun, since it is possible
  2098. to eliminate all fixups for a section and thus we never should
  2099. have generated the relocation section. */
  2100. void
  2101. elf_frob_file_after_relocs (void)
  2102. {
  2103. #ifdef NEED_ECOFF_DEBUG
  2104. if (ECOFF_DEBUGGING)
  2105. /* Generate the ECOFF debugging information. */
  2106. {
  2107. const struct ecoff_debug_swap *debug_swap;
  2108. struct ecoff_debug_info debug;
  2109. char *buf;
  2110. asection *sec;
  2111. debug_swap
  2112. = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap;
  2113. know (debug_swap != NULL);
  2114. ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap);
  2115. /* Set up the pointers in debug. */
  2116. #define SET(ptr, offset, type) \
  2117. debug.ptr = (type) (buf + debug.symbolic_header.offset)
  2118. SET (line, cbLineOffset, unsigned char *);
  2119. SET (external_dnr, cbDnOffset, void *);
  2120. SET (external_pdr, cbPdOffset, void *);
  2121. SET (external_sym, cbSymOffset, void *);
  2122. SET (external_opt, cbOptOffset, void *);
  2123. SET (external_aux, cbAuxOffset, union aux_ext *);
  2124. SET (ss, cbSsOffset, char *);
  2125. SET (external_fdr, cbFdOffset, void *);
  2126. SET (external_rfd, cbRfdOffset, void *);
  2127. /* ssext and external_ext are set up just below. */
  2128. #undef SET
  2129. /* Set up the external symbols. */
  2130. debug.ssext = debug.ssext_end = NULL;
  2131. debug.external_ext = debug.external_ext_end = NULL;
  2132. if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, TRUE,
  2133. elf_get_extr, elf_set_index))
  2134. as_fatal (_("failed to set up debugging information: %s"),
  2135. bfd_errmsg (bfd_get_error ()));
  2136. sec = bfd_get_section_by_name (stdoutput, ".mdebug");
  2137. gas_assert (sec != NULL);
  2138. know (!stdoutput->output_has_begun);
  2139. /* We set the size of the section, call bfd_set_section_contents
  2140. to force the ELF backend to allocate a file position, and then
  2141. write out the data. FIXME: Is this really the best way to do
  2142. this? */
  2143. bfd_set_section_size
  2144. (stdoutput, sec, bfd_ecoff_debug_size (stdoutput, &debug, debug_swap));
  2145. /* Pass BUF to bfd_set_section_contents because this will
  2146. eventually become a call to fwrite, and ISO C prohibits
  2147. passing a NULL pointer to a stdio function even if the
  2148. pointer will not be used. */
  2149. if (! bfd_set_section_contents (stdoutput, sec, buf, 0, 0))
  2150. as_fatal (_("can't start writing .mdebug section: %s"),
  2151. bfd_errmsg (bfd_get_error ()));
  2152. know (stdoutput->output_has_begun);
  2153. know (sec->filepos != 0);
  2154. if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap,
  2155. sec->filepos))
  2156. as_fatal (_("could not write .mdebug section: %s"),
  2157. bfd_errmsg (bfd_get_error ()));
  2158. }
  2159. #endif /* NEED_ECOFF_DEBUG */
  2160. }
  2161. #ifdef SCO_ELF
  2162. /* Heavily plagiarized from obj_elf_version. The idea is to emit the
  2163. SCO specific identifier in the .notes section to satisfy the SCO
  2164. linker.
  2165. This looks more complicated than it really is. As opposed to the
  2166. "obvious" solution, this should handle the cross dev cases
  2167. correctly. (i.e, hosting on a 64 bit big endian processor, but
  2168. generating SCO Elf code) Efficiency isn't a concern, as there
  2169. should be exactly one of these sections per object module.
  2170. SCO OpenServer 5 identifies it's ELF modules with a standard ELF
  2171. .note section.
  2172. int_32 namesz = 4 ; Name size
  2173. int_32 descsz = 12 ; Descriptive information
  2174. int_32 type = 1 ;
  2175. char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
  2176. int_32 version = (major ver # << 16) | version of tools ;
  2177. int_32 source = (tool_id << 16 ) | 1 ;
  2178. int_32 info = 0 ; These are set by the SCO tools, but we
  2179. don't know enough about the source
  2180. environment to set them. SCO ld currently
  2181. ignores them, and recommends we set them
  2182. to zero. */
  2183. #define SCO_MAJOR_VERSION 0x1
  2184. #define SCO_MINOR_VERSION 0x1
  2185. void
  2186. sco_id (void)
  2187. {
  2188. char *name;
  2189. unsigned int c;
  2190. char ch;
  2191. char *p;
  2192. asection *seg = now_seg;
  2193. subsegT subseg = now_subseg;
  2194. Elf_Internal_Note i_note;
  2195. Elf_External_Note e_note;
  2196. asection *note_secp = NULL;
  2197. int i, len;
  2198. /* create the .note section */
  2199. note_secp = subseg_new (".note", 0);
  2200. bfd_set_section_flags (stdoutput,
  2201. note_secp,
  2202. SEC_HAS_CONTENTS | SEC_READONLY);
  2203. /* process the version string */
  2204. i_note.namesz = 4;
  2205. i_note.descsz = 12; /* 12 descriptive bytes */
  2206. i_note.type = NT_VERSION; /* Contains a version string */
  2207. p = frag_more (sizeof (i_note.namesz));
  2208. md_number_to_chars (p, i_note.namesz, 4);
  2209. p = frag_more (sizeof (i_note.descsz));
  2210. md_number_to_chars (p, i_note.descsz, 4);
  2211. p = frag_more (sizeof (i_note.type));
  2212. md_number_to_chars (p, i_note.type, 4);
  2213. p = frag_more (4);
  2214. strcpy (p, "SCO");
  2215. /* Note: this is the version number of the ELF we're representing */
  2216. p = frag_more (4);
  2217. md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4);
  2218. /* Here, we pick a magic number for ourselves (yes, I "registered"
  2219. it with SCO. The bottom bit shows that we are compat with the
  2220. SCO ABI. */
  2221. p = frag_more (4);
  2222. md_number_to_chars (p, 0x4c520000 | 0x0001, 4);
  2223. /* If we knew (or cared) what the source language options were, we'd
  2224. fill them in here. SCO has given us permission to ignore these
  2225. and just set them to zero. */
  2226. p = frag_more (4);
  2227. md_number_to_chars (p, 0x0000, 4);
  2228. frag_align (2, 0, 0);
  2229. /* We probably can't restore the current segment, for there likely
  2230. isn't one yet... */
  2231. if (seg && subseg)
  2232. subseg_set (seg, subseg);
  2233. }
  2234. #endif /* SCO_ELF */
  2235. static void
  2236. elf_generate_asm_lineno (void)
  2237. {
  2238. #ifdef NEED_ECOFF_DEBUG
  2239. if (ECOFF_DEBUGGING)
  2240. ecoff_generate_asm_lineno ();
  2241. #endif
  2242. }
  2243. static void
  2244. elf_process_stab (segT sec ATTRIBUTE_UNUSED,
  2245. int what ATTRIBUTE_UNUSED,
  2246. const char *string ATTRIBUTE_UNUSED,
  2247. int type ATTRIBUTE_UNUSED,
  2248. int other ATTRIBUTE_UNUSED,
  2249. int desc ATTRIBUTE_UNUSED)
  2250. {
  2251. #ifdef NEED_ECOFF_DEBUG
  2252. if (ECOFF_DEBUGGING)
  2253. ecoff_stab (sec, what, string, type, other, desc);
  2254. #endif
  2255. }
  2256. static int
  2257. elf_separate_stab_sections (void)
  2258. {
  2259. #ifdef NEED_ECOFF_DEBUG
  2260. return (!ECOFF_DEBUGGING);
  2261. #else
  2262. return 1;
  2263. #endif
  2264. }
  2265. static void
  2266. elf_init_stab_section (segT seg)
  2267. {
  2268. #ifdef NEED_ECOFF_DEBUG
  2269. if (!ECOFF_DEBUGGING)
  2270. #endif
  2271. obj_elf_init_stab_section (seg);
  2272. }
  2273. const struct format_ops elf_format_ops =
  2274. {
  2275. bfd_target_elf_flavour,
  2276. 0, /* dfl_leading_underscore */
  2277. 1, /* emit_section_symbols */
  2278. elf_begin,
  2279. elf_file_symbol,
  2280. elf_frob_symbol,
  2281. elf_frob_file,
  2282. elf_frob_file_before_adjust,
  2283. 0, /* obj_frob_file_before_fix */
  2284. elf_frob_file_after_relocs,
  2285. elf_s_get_size, elf_s_set_size,
  2286. elf_s_get_align, elf_s_set_align,
  2287. elf_s_get_other,
  2288. elf_s_set_other,
  2289. 0, /* s_get_desc */
  2290. 0, /* s_set_desc */
  2291. 0, /* s_get_type */
  2292. 0, /* s_set_type */
  2293. elf_copy_symbol_attributes,
  2294. elf_generate_asm_lineno,
  2295. elf_process_stab,
  2296. elf_separate_stab_sections,
  2297. elf_init_stab_section,
  2298. elf_sec_sym_ok_for_reloc,
  2299. elf_pop_insert,
  2300. #ifdef NEED_ECOFF_DEBUG
  2301. elf_ecoff_set_ext,
  2302. #else
  2303. 0, /* ecoff_set_ext */
  2304. #endif
  2305. elf_obj_read_begin_hook,
  2306. elf_obj_symbol_new_hook,
  2307. 0,
  2308. elf_adjust_symtab
  2309. };