dwp.cc 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452
  1. // dwp.cc -- DWARF packaging utility
  2. // Copyright (C) 2012-2015 Free Software Foundation, Inc.
  3. // Written by Cary Coutant <ccoutant@google.com>.
  4. // This file is part of dwp, the DWARF packaging utility.
  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 "dwp.h"
  18. #include <cstdarg>
  19. #include <cstddef>
  20. #include <cstdio>
  21. #include <cstdlib>
  22. #include <cstring>
  23. #include <cerrno>
  24. #include <vector>
  25. #include <algorithm>
  26. #include "getopt.h"
  27. #include "libiberty.h"
  28. #include "../bfd/bfdver.h"
  29. #include "elfcpp.h"
  30. #include "elfcpp_file.h"
  31. #include "dwarf.h"
  32. #include "dirsearch.h"
  33. #include "fileread.h"
  34. #include "object.h"
  35. #include "compressed_output.h"
  36. #include "stringpool.h"
  37. #include "dwarf_reader.h"
  38. static void
  39. usage(FILE* fd, int) ATTRIBUTE_NORETURN;
  40. static void
  41. print_version() ATTRIBUTE_NORETURN;
  42. namespace gold {
  43. class Dwp_output_file;
  44. template <int size, bool big_endian>
  45. class Sized_relobj_dwo;
  46. // List of .dwo files to process.
  47. struct Dwo_file_entry
  48. {
  49. Dwo_file_entry(uint64_t id, std::string name)
  50. : dwo_id(id), dwo_name(name)
  51. { }
  52. uint64_t dwo_id;
  53. std::string dwo_name;
  54. };
  55. typedef std::vector<Dwo_file_entry> File_list;
  56. // Type to hold the offset and length of an input section
  57. // within an output section.
  58. struct Section_bounds
  59. {
  60. section_offset_type offset;
  61. section_size_type size;
  62. Section_bounds()
  63. : offset(0), size(0)
  64. { }
  65. Section_bounds(section_offset_type o, section_size_type s)
  66. : offset(o), size(s)
  67. { }
  68. };
  69. // A set of sections for a compilation unit or type unit.
  70. struct Unit_set
  71. {
  72. uint64_t signature;
  73. Section_bounds sections[elfcpp::DW_SECT_MAX + 1];
  74. Unit_set()
  75. : signature(0), sections()
  76. { }
  77. };
  78. // An input file.
  79. // This class may represent a .dwo file, a .dwp file
  80. // produced by an earlier run, or an executable file whose
  81. // debug section identifies a set of .dwo files to read.
  82. class Dwo_file
  83. {
  84. public:
  85. Dwo_file(const char* name)
  86. : name_(name), obj_(NULL), input_file_(NULL), is_compressed_(),
  87. sect_offsets_(), str_offset_map_()
  88. { }
  89. ~Dwo_file();
  90. // Read the input executable file and extract the list of .dwo files
  91. // that it references.
  92. void
  93. read_executable(File_list* files);
  94. // Read the input file and send its contents to OUTPUT_FILE.
  95. void
  96. read(Dwp_output_file* output_file);
  97. // Verify a .dwp file given a list of .dwo files referenced by the
  98. // corresponding executable file. Returns true if no problems
  99. // were found.
  100. bool
  101. verify(const File_list& files);
  102. private:
  103. // Types for mapping input string offsets to output string offsets.
  104. typedef std::pair<section_offset_type, section_offset_type>
  105. Str_offset_map_entry;
  106. typedef std::vector<Str_offset_map_entry> Str_offset_map;
  107. // A less-than comparison routine for Str_offset_map.
  108. struct Offset_compare
  109. {
  110. bool
  111. operator()(const Str_offset_map_entry& i1,
  112. const Str_offset_map_entry& i2) const
  113. { return i1.first < i2.first; }
  114. };
  115. // Create a Sized_relobj_dwo of the given size and endianness,
  116. // and record the target info. P is a pointer to the ELF header
  117. // in memory.
  118. Relobj*
  119. make_object(Dwp_output_file* output_file);
  120. template <int size, bool big_endian>
  121. Relobj*
  122. sized_make_object(const unsigned char* p, Input_file* input_file,
  123. Dwp_output_file* output_file);
  124. // Return the number of sections in the input object file.
  125. unsigned int
  126. shnum() const
  127. { return this->obj_->shnum(); }
  128. // Return section type.
  129. unsigned int
  130. section_type(unsigned int shndx)
  131. { return this->obj_->section_type(shndx); }
  132. // Get the name of a section.
  133. std::string
  134. section_name(unsigned int shndx)
  135. { return this->obj_->section_name(shndx); }
  136. // Return a view of the contents of a section, decompressed if necessary.
  137. // Set *PLEN to the size. Set *IS_NEW to true if the contents need to be
  138. // deleted by the caller.
  139. const unsigned char*
  140. section_contents(unsigned int shndx, section_size_type* plen, bool* is_new)
  141. { return this->obj_->decompressed_section_contents(shndx, plen, is_new); }
  142. // Read the .debug_cu_index or .debug_tu_index section of a .dwp file,
  143. // and process the CU or TU sets.
  144. void
  145. read_unit_index(unsigned int, unsigned int *, Dwp_output_file*,
  146. bool is_tu_index);
  147. template <bool big_endian>
  148. void
  149. sized_read_unit_index(unsigned int, unsigned int *, Dwp_output_file*,
  150. bool is_tu_index);
  151. // Verify the .debug_cu_index section of a .dwp file, comparing it
  152. // against the list of .dwo files referenced by the corresponding
  153. // executable file.
  154. bool
  155. verify_dwo_list(unsigned int, const File_list& files);
  156. template <bool big_endian>
  157. bool
  158. sized_verify_dwo_list(unsigned int, const File_list& files);
  159. // Merge the input string table section into the output file.
  160. void
  161. add_strings(Dwp_output_file*, unsigned int);
  162. // Copy a section from the input file to the output file.
  163. Section_bounds
  164. copy_section(Dwp_output_file* output_file, unsigned int shndx,
  165. elfcpp::DW_SECT section_id);
  166. // Remap the string offsets in the .debug_str_offsets.dwo section.
  167. const unsigned char*
  168. remap_str_offsets(const unsigned char* contents, section_size_type len);
  169. template <bool big_endian>
  170. const unsigned char*
  171. sized_remap_str_offsets(const unsigned char* contents, section_size_type len);
  172. // Remap a single string offsets from an offset in the input string table
  173. // to an offset in the output string table.
  174. unsigned int
  175. remap_str_offset(section_offset_type val);
  176. // Add a set of .debug_info.dwo or .debug_types.dwo and related sections
  177. // to OUTPUT_FILE.
  178. void
  179. add_unit_set(Dwp_output_file* output_file, unsigned int *debug_shndx,
  180. bool is_debug_types);
  181. // The filename.
  182. const char* name_;
  183. // The ELF file, represented as a gold Relobj instance.
  184. Relobj* obj_;
  185. // The Input_file object.
  186. Input_file* input_file_;
  187. // Flags indicating which sections are compressed.
  188. std::vector<bool> is_compressed_;
  189. // Map input section index onto output section offset and size.
  190. std::vector<Section_bounds> sect_offsets_;
  191. // Map input string offsets to output string offsets.
  192. Str_offset_map str_offset_map_;
  193. };
  194. // An ELF input file.
  195. // We derive from Sized_relobj so that we can use interfaces
  196. // in libgold to access the file.
  197. template <int size, bool big_endian>
  198. class Sized_relobj_dwo : public Sized_relobj<size, big_endian>
  199. {
  200. public:
  201. typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
  202. typedef typename Sized_relobj<size, big_endian>::Symbols Symbols;
  203. Sized_relobj_dwo(const char* name, Input_file* input_file,
  204. const elfcpp::Ehdr<size, big_endian>& ehdr)
  205. : Sized_relobj<size, big_endian>(name, input_file),
  206. elf_file_(this, ehdr)
  207. { }
  208. ~Sized_relobj_dwo()
  209. { }
  210. // Setup the section information.
  211. void
  212. setup();
  213. protected:
  214. // Return section type.
  215. unsigned int
  216. do_section_type(unsigned int shndx)
  217. { return this->elf_file_.section_type(shndx); }
  218. // Get the name of a section.
  219. std::string
  220. do_section_name(unsigned int shndx) const
  221. { return this->elf_file_.section_name(shndx); }
  222. // Get the size of a section.
  223. uint64_t
  224. do_section_size(unsigned int shndx)
  225. { return this->elf_file_.section_size(shndx); }
  226. // Return a view of the contents of a section.
  227. const unsigned char*
  228. do_section_contents(unsigned int, section_size_type*, bool);
  229. // The following virtual functions are abstract in the base classes,
  230. // but are not used here.
  231. // Read the symbols.
  232. void
  233. do_read_symbols(Read_symbols_data*)
  234. { gold_unreachable(); }
  235. // Lay out the input sections.
  236. void
  237. do_layout(Symbol_table*, Layout*, Read_symbols_data*)
  238. { gold_unreachable(); }
  239. // Layout sections whose layout was deferred while waiting for
  240. // input files from a plugin.
  241. void
  242. do_layout_deferred_sections(Layout*)
  243. { gold_unreachable(); }
  244. // Add the symbols to the symbol table.
  245. void
  246. do_add_symbols(Symbol_table*, Read_symbols_data*, Layout*)
  247. { gold_unreachable(); }
  248. Archive::Should_include
  249. do_should_include_member(Symbol_table*, Layout*, Read_symbols_data*,
  250. std::string*)
  251. { gold_unreachable(); }
  252. // Iterate over global symbols, calling a visitor class V for each.
  253. void
  254. do_for_all_global_symbols(Read_symbols_data*,
  255. Library_base::Symbol_visitor_base*)
  256. { gold_unreachable(); }
  257. // Return section flags.
  258. uint64_t
  259. do_section_flags(unsigned int)
  260. { gold_unreachable(); }
  261. // Return section entsize.
  262. uint64_t
  263. do_section_entsize(unsigned int)
  264. { gold_unreachable(); }
  265. // Return section address.
  266. uint64_t
  267. do_section_address(unsigned int)
  268. { gold_unreachable(); }
  269. // Return the section link field.
  270. unsigned int
  271. do_section_link(unsigned int)
  272. { gold_unreachable(); }
  273. // Return the section link field.
  274. unsigned int
  275. do_section_info(unsigned int)
  276. { gold_unreachable(); }
  277. // Return the section alignment.
  278. uint64_t
  279. do_section_addralign(unsigned int)
  280. { gold_unreachable(); }
  281. // Return the Xindex structure to use.
  282. Xindex*
  283. do_initialize_xindex()
  284. { gold_unreachable(); }
  285. // Get symbol counts.
  286. void
  287. do_get_global_symbol_counts(const Symbol_table*, size_t*, size_t*) const
  288. { gold_unreachable(); }
  289. // Get global symbols.
  290. const Symbols*
  291. do_get_global_symbols() const
  292. { return NULL; }
  293. // Return the value of a local symbol.
  294. uint64_t
  295. do_local_symbol_value(unsigned int, uint64_t) const
  296. { gold_unreachable(); }
  297. unsigned int
  298. do_local_plt_offset(unsigned int) const
  299. { gold_unreachable(); }
  300. // Return whether local symbol SYMNDX is a TLS symbol.
  301. bool
  302. do_local_is_tls(unsigned int) const
  303. { gold_unreachable(); }
  304. // Return the number of local symbols.
  305. unsigned int
  306. do_local_symbol_count() const
  307. { gold_unreachable(); }
  308. // Return the number of local symbols in the output symbol table.
  309. unsigned int
  310. do_output_local_symbol_count() const
  311. { gold_unreachable(); }
  312. // Return the file offset for local symbols in the output symbol table.
  313. off_t
  314. do_local_symbol_offset() const
  315. { gold_unreachable(); }
  316. // Read the relocs.
  317. void
  318. do_read_relocs(Read_relocs_data*)
  319. { gold_unreachable(); }
  320. // Process the relocs to find list of referenced sections. Used only
  321. // during garbage collection.
  322. void
  323. do_gc_process_relocs(Symbol_table*, Layout*, Read_relocs_data*)
  324. { gold_unreachable(); }
  325. // Scan the relocs and adjust the symbol table.
  326. void
  327. do_scan_relocs(Symbol_table*, Layout*, Read_relocs_data*)
  328. { gold_unreachable(); }
  329. // Count the local symbols.
  330. void
  331. do_count_local_symbols(Stringpool_template<char>*,
  332. Stringpool_template<char>*)
  333. { gold_unreachable(); }
  334. // Finalize the local symbols.
  335. unsigned int
  336. do_finalize_local_symbols(unsigned int, off_t, Symbol_table*)
  337. { gold_unreachable(); }
  338. // Set the offset where local dynamic symbol information will be stored.
  339. unsigned int
  340. do_set_local_dynsym_indexes(unsigned int)
  341. { gold_unreachable(); }
  342. // Set the offset where local dynamic symbol information will be stored.
  343. unsigned int
  344. do_set_local_dynsym_offset(off_t)
  345. { gold_unreachable(); }
  346. // Relocate the input sections and write out the local symbols.
  347. void
  348. do_relocate(const Symbol_table*, const Layout*, Output_file*)
  349. { gold_unreachable(); }
  350. private:
  351. // General access to the ELF file.
  352. elfcpp::Elf_file<size, big_endian, Object> elf_file_;
  353. };
  354. // The output file.
  355. // This class is responsible for collecting the debug index information
  356. // and writing the .dwp file in ELF format.
  357. class Dwp_output_file
  358. {
  359. public:
  360. Dwp_output_file(const char* name)
  361. : name_(name), machine_(0), size_(0), big_endian_(false), osabi_(0),
  362. abiversion_(0), fd_(NULL), next_file_offset_(0), shnum_(1), sections_(),
  363. section_id_map_(), shoff_(0), shstrndx_(0), have_strings_(false),
  364. stringpool_(), shstrtab_(), cu_index_(), tu_index_(), last_type_sig_(0),
  365. last_tu_slot_(0)
  366. {
  367. this->section_id_map_.resize(elfcpp::DW_SECT_MAX + 1);
  368. this->stringpool_.set_no_zero_null();
  369. }
  370. // Record the target info from an input file.
  371. void
  372. record_target_info(const char* name, int machine, int size, bool big_endian,
  373. int osabi, int abiversion);
  374. // Add a string to the debug strings section.
  375. section_offset_type
  376. add_string(const char* str, size_t len);
  377. // Add a section to the output file, and return the new section offset.
  378. section_offset_type
  379. add_contribution(elfcpp::DW_SECT section_id, const unsigned char* contents,
  380. section_size_type len, int align);
  381. // Add a set of .debug_info and related sections to the output file.
  382. void
  383. add_cu_set(Unit_set* cu_set);
  384. // Lookup a type signature and return TRUE if we have already seen it.
  385. bool
  386. lookup_tu(uint64_t type_sig);
  387. // Add a set of .debug_types and related sections to the output file.
  388. void
  389. add_tu_set(Unit_set* tu_set);
  390. // Finalize the file, write the string tables and index sections,
  391. // and close the file.
  392. void
  393. finalize();
  394. private:
  395. // Contributions to output sections.
  396. struct Contribution
  397. {
  398. section_offset_type output_offset;
  399. section_size_type size;
  400. const unsigned char* contents;
  401. };
  402. // Sections in the output file.
  403. struct Section
  404. {
  405. const char* name;
  406. off_t offset;
  407. section_size_type size;
  408. int align;
  409. std::vector<Contribution> contributions;
  410. Section(const char* n, int a)
  411. : name(n), offset(0), size(0), align(a), contributions()
  412. { }
  413. };
  414. // The index sections defined by the DWARF Package File Format spec.
  415. class Dwp_index
  416. {
  417. public:
  418. // Vector for the section table.
  419. typedef std::vector<const Unit_set*> Section_table;
  420. Dwp_index()
  421. : capacity_(0), used_(0), hash_table_(NULL), section_table_(),
  422. section_mask_(0)
  423. { }
  424. ~Dwp_index()
  425. { }
  426. // Find a slot in the hash table for SIGNATURE. Return TRUE
  427. // if the entry already exists.
  428. bool
  429. find_or_add(uint64_t signature, unsigned int* slotp);
  430. // Enter a CU or TU set at the given SLOT in the hash table.
  431. void
  432. enter_set(unsigned int slot, const Unit_set* set);
  433. // Return the contents of the given SLOT in the hash table of signatures.
  434. uint64_t
  435. hash_table(unsigned int slot) const
  436. { return this->hash_table_[slot]; }
  437. // Return the contents of the given SLOT in the parallel table of
  438. // shndx pool indexes.
  439. uint32_t
  440. index_table(unsigned int slot) const
  441. { return this->index_table_[slot]; }
  442. // Return the total number of slots in the hash table.
  443. unsigned int
  444. hash_table_total_slots() const
  445. { return this->capacity_; }
  446. // Return the number of used slots in the hash table.
  447. unsigned int
  448. hash_table_used_slots() const
  449. { return this->used_; }
  450. // Return an iterator into the shndx pool.
  451. Section_table::const_iterator
  452. section_table() const
  453. { return this->section_table_.begin(); }
  454. Section_table::const_iterator
  455. section_table_end() const
  456. { return this->section_table_.end(); }
  457. // Return the number of rows in the section table.
  458. unsigned int
  459. section_table_rows() const
  460. { return this->section_table_.size(); }
  461. // Return the mask indicating which columns will be used
  462. // in the section table.
  463. int
  464. section_table_cols() const
  465. { return this->section_mask_; }
  466. private:
  467. // Initialize the hash table.
  468. void
  469. initialize();
  470. // Grow the hash table when we reach 2/3 capacity.
  471. void
  472. grow();
  473. // The number of slots in the table, a power of 2 such that
  474. // capacity > 3 * size / 2.
  475. unsigned int capacity_;
  476. // The current number of used slots in the hash table.
  477. unsigned int used_;
  478. // The storage for the hash table of signatures.
  479. uint64_t* hash_table_;
  480. // The storage for the parallel table of shndx pool indexes.
  481. uint32_t* index_table_;
  482. // The table of section offsets and sizes.
  483. Section_table section_table_;
  484. // Bit mask to indicate which debug sections are present in the file.
  485. int section_mask_;
  486. }; // End class Dwp_output_file::Dwp_index.
  487. // Add a new output section and return the section index.
  488. unsigned int
  489. add_output_section(const char* section_name, int align);
  490. // Write a new section to the output file.
  491. void
  492. write_new_section(const char* section_name, const unsigned char* contents,
  493. section_size_type len, int align);
  494. // Write the ELF header.
  495. void
  496. write_ehdr();
  497. template<unsigned int size, bool big_endian>
  498. void
  499. sized_write_ehdr();
  500. // Write a section header.
  501. void
  502. write_shdr(const char* name, unsigned int type, unsigned int flags,
  503. uint64_t addr, off_t offset, section_size_type sect_size,
  504. unsigned int link, unsigned int info,
  505. unsigned int align, unsigned int ent_size);
  506. template<unsigned int size, bool big_endian>
  507. void
  508. sized_write_shdr(const char* name, unsigned int type, unsigned int flags,
  509. uint64_t addr, off_t offset, section_size_type sect_size,
  510. unsigned int link, unsigned int info,
  511. unsigned int align, unsigned int ent_size);
  512. // Write the contributions to an output section.
  513. void
  514. write_contributions(const Section& sect);
  515. // Write a CU or TU index section.
  516. template<bool big_endian>
  517. void
  518. write_index(const char* sect_name, const Dwp_index& index);
  519. // The output filename.
  520. const char* name_;
  521. // ELF header parameters.
  522. int machine_;
  523. int size_;
  524. int big_endian_;
  525. int osabi_;
  526. int abiversion_;
  527. // The output file descriptor.
  528. FILE* fd_;
  529. // Next available file offset.
  530. off_t next_file_offset_;
  531. // The number of sections.
  532. unsigned int shnum_;
  533. // Section table. The first entry is shndx 1.
  534. std::vector<Section> sections_;
  535. // Section id map. This maps a DW_SECT enum to an shndx.
  536. std::vector<unsigned int> section_id_map_;
  537. // File offset of the section header table.
  538. off_t shoff_;
  539. // Section index of the section string table.
  540. unsigned int shstrndx_;
  541. // TRUE if we have added any strings to the string pool.
  542. bool have_strings_;
  543. // String pool for the output .debug_str.dwo section.
  544. Stringpool stringpool_;
  545. // String pool for the .shstrtab section.
  546. Stringpool shstrtab_;
  547. // The compilation unit index.
  548. Dwp_index cu_index_;
  549. // The type unit index.
  550. Dwp_index tu_index_;
  551. // Cache of the last type signature looked up.
  552. uint64_t last_type_sig_;
  553. // Cache of the slot index for the last type signature.
  554. unsigned int last_tu_slot_;
  555. };
  556. // A specialization of Dwarf_info_reader, for reading dwo_names from
  557. // DWARF CUs.
  558. class Dwo_name_info_reader : public Dwarf_info_reader
  559. {
  560. public:
  561. Dwo_name_info_reader(Relobj* object, unsigned int shndx)
  562. : Dwarf_info_reader(false, object, NULL, 0, shndx, 0, 0),
  563. files_(NULL)
  564. { }
  565. ~Dwo_name_info_reader()
  566. { }
  567. // Get the dwo_names from the DWARF compilation unit DIEs.
  568. void
  569. get_dwo_names(File_list* files)
  570. {
  571. this->files_ = files;
  572. this->parse();
  573. }
  574. protected:
  575. // Visit a compilation unit.
  576. virtual void
  577. visit_compilation_unit(off_t cu_offset, off_t cu_length, Dwarf_die*);
  578. private:
  579. // The list of files to populate.
  580. File_list* files_;
  581. };
  582. // A specialization of Dwarf_info_reader, for reading DWARF CUs and TUs
  583. // and adding them to the output file.
  584. class Unit_reader : public Dwarf_info_reader
  585. {
  586. public:
  587. Unit_reader(bool is_type_unit, Relobj* object, unsigned int shndx)
  588. : Dwarf_info_reader(is_type_unit, object, NULL, 0, shndx, 0, 0),
  589. output_file_(NULL), sections_(NULL)
  590. { }
  591. ~Unit_reader()
  592. { }
  593. // Read the CUs or TUs and add them to the output file.
  594. void
  595. add_units(Dwp_output_file*, unsigned int debug_abbrev, Section_bounds*);
  596. protected:
  597. // Visit a compilation unit.
  598. virtual void
  599. visit_compilation_unit(off_t cu_offset, off_t cu_length, Dwarf_die*);
  600. // Visit a type unit.
  601. virtual void
  602. visit_type_unit(off_t tu_offset, off_t tu_length, off_t type_offset,
  603. uint64_t signature, Dwarf_die*);
  604. private:
  605. Dwp_output_file* output_file_;
  606. Section_bounds* sections_;
  607. };
  608. // Return the name of a DWARF .dwo section.
  609. static const char*
  610. get_dwarf_section_name(elfcpp::DW_SECT section_id)
  611. {
  612. static const char* dwarf_section_names[] = {
  613. NULL, // unused
  614. ".debug_info.dwo", // DW_SECT_INFO = 1
  615. ".debug_types.dwo", // DW_SECT_TYPES = 2
  616. ".debug_abbrev.dwo", // DW_SECT_ABBREV = 3
  617. ".debug_line.dwo", // DW_SECT_LINE = 4
  618. ".debug_loc.dwo", // DW_SECT_LOC = 5
  619. ".debug_str_offsets.dwo", // DW_SECT_STR_OFFSETS = 6
  620. ".debug_macinfo.dwo", // DW_SECT_MACINFO = 7
  621. ".debug_macro.dwo", // DW_SECT_MACRO = 8
  622. };
  623. gold_assert(section_id > 0 && section_id <= elfcpp::DW_SECT_MAX);
  624. return dwarf_section_names[section_id];
  625. }
  626. // Class Sized_relobj_dwo.
  627. // Setup the section information.
  628. template <int size, bool big_endian>
  629. void
  630. Sized_relobj_dwo<size, big_endian>::setup()
  631. {
  632. const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
  633. const off_t shoff = this->elf_file_.shoff();
  634. const unsigned int shnum = this->elf_file_.shnum();
  635. this->set_shnum(shnum);
  636. this->section_offsets().resize(shnum);
  637. // Read the section headers.
  638. const unsigned char* const pshdrs = this->get_view(shoff, shnum * shdr_size,
  639. true, false);
  640. // Read the section names.
  641. const unsigned char* pshdrnames =
  642. pshdrs + this->elf_file_.shstrndx() * shdr_size;
  643. typename elfcpp::Shdr<size, big_endian> shdrnames(pshdrnames);
  644. if (shdrnames.get_sh_type() != elfcpp::SHT_STRTAB)
  645. this->error(_("section name section has wrong type: %u"),
  646. static_cast<unsigned int>(shdrnames.get_sh_type()));
  647. section_size_type section_names_size =
  648. convert_to_section_size_type(shdrnames.get_sh_size());
  649. const unsigned char* namesu = this->get_view(shdrnames.get_sh_offset(),
  650. section_names_size, false,
  651. false);
  652. const char* names = reinterpret_cast<const char*>(namesu);
  653. Compressed_section_map* compressed_sections =
  654. build_compressed_section_map<size, big_endian>(
  655. pshdrs, this->shnum(), names, section_names_size, this, true);
  656. if (compressed_sections != NULL && !compressed_sections->empty())
  657. this->set_compressed_sections(compressed_sections);
  658. }
  659. // Return a view of the contents of a section.
  660. template <int size, bool big_endian>
  661. const unsigned char*
  662. Sized_relobj_dwo<size, big_endian>::do_section_contents(
  663. unsigned int shndx,
  664. section_size_type* plen,
  665. bool cache)
  666. {
  667. Object::Location loc(this->elf_file_.section_contents(shndx));
  668. *plen = convert_to_section_size_type(loc.data_size);
  669. if (*plen == 0)
  670. {
  671. static const unsigned char empty[1] = { '\0' };
  672. return empty;
  673. }
  674. return this->get_view(loc.file_offset, *plen, true, cache);
  675. }
  676. // Class Dwo_file.
  677. Dwo_file::~Dwo_file()
  678. {
  679. if (this->obj_ != NULL)
  680. delete this->obj_;
  681. if (this->input_file_ != NULL)
  682. delete this->input_file_;
  683. }
  684. // Read the input executable file and extract the list of .dwo files
  685. // that it references.
  686. void
  687. Dwo_file::read_executable(File_list* files)
  688. {
  689. this->obj_ = this->make_object(NULL);
  690. unsigned int shnum = this->shnum();
  691. this->is_compressed_.resize(shnum);
  692. this->sect_offsets_.resize(shnum);
  693. unsigned int debug_info = 0;
  694. unsigned int debug_abbrev = 0;
  695. // Scan the section table and collect the debug sections we need.
  696. // (Section index 0 is a dummy section; skip it.)
  697. for (unsigned int i = 1; i < shnum; i++)
  698. {
  699. if (this->section_type(i) != elfcpp::SHT_PROGBITS)
  700. continue;
  701. std::string sect_name = this->section_name(i);
  702. const char* suffix = sect_name.c_str();
  703. if (is_prefix_of(".debug_", suffix))
  704. suffix += 7;
  705. else if (is_prefix_of(".zdebug_", suffix))
  706. {
  707. this->is_compressed_[i] = true;
  708. suffix += 8;
  709. }
  710. else
  711. continue;
  712. if (strcmp(suffix, "info") == 0)
  713. debug_info = i;
  714. else if (strcmp(suffix, "abbrev") == 0)
  715. debug_abbrev = i;
  716. }
  717. if (debug_info > 0)
  718. {
  719. Dwo_name_info_reader dwarf_reader(this->obj_, debug_info);
  720. dwarf_reader.set_abbrev_shndx(debug_abbrev);
  721. dwarf_reader.get_dwo_names(files);
  722. }
  723. }
  724. // Read the input file and send its contents to OUTPUT_FILE.
  725. void
  726. Dwo_file::read(Dwp_output_file* output_file)
  727. {
  728. this->obj_ = this->make_object(output_file);
  729. unsigned int shnum = this->shnum();
  730. this->is_compressed_.resize(shnum);
  731. this->sect_offsets_.resize(shnum);
  732. typedef std::vector<unsigned int> Types_list;
  733. Types_list debug_types;
  734. unsigned int debug_shndx[elfcpp::DW_SECT_MAX + 1];
  735. for (unsigned int i = 0; i <= elfcpp::DW_SECT_MAX; i++)
  736. debug_shndx[i] = 0;
  737. unsigned int debug_str = 0;
  738. unsigned int debug_cu_index = 0;
  739. unsigned int debug_tu_index = 0;
  740. // Scan the section table and collect debug sections.
  741. // (Section index 0 is a dummy section; skip it.)
  742. for (unsigned int i = 1; i < shnum; i++)
  743. {
  744. if (this->section_type(i) != elfcpp::SHT_PROGBITS)
  745. continue;
  746. std::string sect_name = this->section_name(i);
  747. const char* suffix = sect_name.c_str();
  748. if (is_prefix_of(".debug_", suffix))
  749. suffix += 7;
  750. else if (is_prefix_of(".zdebug_", suffix))
  751. {
  752. this->is_compressed_[i] = true;
  753. suffix += 8;
  754. }
  755. else
  756. continue;
  757. if (strcmp(suffix, "info.dwo") == 0)
  758. debug_shndx[elfcpp::DW_SECT_INFO] = i;
  759. else if (strcmp(suffix, "types.dwo") == 0)
  760. debug_types.push_back(i);
  761. else if (strcmp(suffix, "abbrev.dwo") == 0)
  762. debug_shndx[elfcpp::DW_SECT_ABBREV] = i;
  763. else if (strcmp(suffix, "line.dwo") == 0)
  764. debug_shndx[elfcpp::DW_SECT_LINE] = i;
  765. else if (strcmp(suffix, "loc.dwo") == 0)
  766. debug_shndx[elfcpp::DW_SECT_LOC] = i;
  767. else if (strcmp(suffix, "str.dwo") == 0)
  768. debug_str = i;
  769. else if (strcmp(suffix, "str_offsets.dwo") == 0)
  770. debug_shndx[elfcpp::DW_SECT_STR_OFFSETS] = i;
  771. else if (strcmp(suffix, "macinfo.dwo") == 0)
  772. debug_shndx[elfcpp::DW_SECT_MACINFO] = i;
  773. else if (strcmp(suffix, "macro.dwo") == 0)
  774. debug_shndx[elfcpp::DW_SECT_MACRO] = i;
  775. else if (strcmp(suffix, "cu_index") == 0)
  776. debug_cu_index = i;
  777. else if (strcmp(suffix, "tu_index") == 0)
  778. debug_tu_index = i;
  779. }
  780. // Merge the input string table into the output string table.
  781. this->add_strings(output_file, debug_str);
  782. // If we found any .dwp index sections, read those and add the section
  783. // sets to the output file.
  784. if (debug_cu_index > 0 || debug_tu_index > 0)
  785. {
  786. if (debug_cu_index > 0)
  787. this->read_unit_index(debug_cu_index, debug_shndx, output_file, false);
  788. if (debug_tu_index > 0)
  789. {
  790. if (debug_types.size() > 1)
  791. gold_fatal(_("%s: .dwp file must have no more than one "
  792. ".debug_types.dwo section"), this->name_);
  793. if (debug_types.size() == 1)
  794. debug_shndx[elfcpp::DW_SECT_TYPES] = debug_types[0];
  795. else
  796. debug_shndx[elfcpp::DW_SECT_TYPES] = 0;
  797. this->read_unit_index(debug_tu_index, debug_shndx, output_file, true);
  798. }
  799. return;
  800. }
  801. // If we found no index sections, this is a .dwo file.
  802. if (debug_shndx[elfcpp::DW_SECT_INFO] > 0)
  803. this->add_unit_set(output_file, debug_shndx, false);
  804. debug_shndx[elfcpp::DW_SECT_INFO] = 0;
  805. for (Types_list::const_iterator tp = debug_types.begin();
  806. tp != debug_types.end();
  807. ++tp)
  808. {
  809. debug_shndx[elfcpp::DW_SECT_TYPES] = *tp;
  810. this->add_unit_set(output_file, debug_shndx, true);
  811. }
  812. }
  813. // Verify a .dwp file given a list of .dwo files referenced by the
  814. // corresponding executable file. Returns true if no problems
  815. // were found.
  816. bool
  817. Dwo_file::verify(const File_list& files)
  818. {
  819. this->obj_ = this->make_object(NULL);
  820. unsigned int shnum = this->shnum();
  821. this->is_compressed_.resize(shnum);
  822. this->sect_offsets_.resize(shnum);
  823. unsigned int debug_cu_index = 0;
  824. // Scan the section table and collect debug sections.
  825. // (Section index 0 is a dummy section; skip it.)
  826. for (unsigned int i = 1; i < shnum; i++)
  827. {
  828. if (this->section_type(i) != elfcpp::SHT_PROGBITS)
  829. continue;
  830. std::string sect_name = this->section_name(i);
  831. const char* suffix = sect_name.c_str();
  832. if (is_prefix_of(".debug_", suffix))
  833. suffix += 7;
  834. else if (is_prefix_of(".zdebug_", suffix))
  835. {
  836. this->is_compressed_[i] = true;
  837. suffix += 8;
  838. }
  839. else
  840. continue;
  841. if (strcmp(suffix, "cu_index") == 0)
  842. debug_cu_index = i;
  843. }
  844. if (debug_cu_index == 0)
  845. gold_fatal(_("%s: no .debug_cu_index section found"), this->name_);
  846. return this->verify_dwo_list(debug_cu_index, files);
  847. }
  848. // Create a Sized_relobj_dwo of the given size and endianness,
  849. // and record the target info.
  850. Relobj*
  851. Dwo_file::make_object(Dwp_output_file* output_file)
  852. {
  853. // Open the input file.
  854. Input_file* input_file = new Input_file(this->name_);
  855. this->input_file_ = input_file;
  856. Dirsearch dirpath;
  857. int index;
  858. if (!input_file->open(dirpath, NULL, &index))
  859. gold_fatal(_("%s: can't open"), this->name_);
  860. // Check that it's an ELF file.
  861. off_t filesize = input_file->file().filesize();
  862. int hdrsize = elfcpp::Elf_recognizer::max_header_size;
  863. if (filesize < hdrsize)
  864. hdrsize = filesize;
  865. const unsigned char* elf_header =
  866. input_file->file().get_view(0, 0, hdrsize, true, false);
  867. if (!elfcpp::Elf_recognizer::is_elf_file(elf_header, hdrsize))
  868. gold_fatal(_("%s: not an ELF object file"), this->name_);
  869. // Get the size, endianness, machine, etc. info from the header,
  870. // make an appropriately-sized Relobj, and pass the target info
  871. // to the output object.
  872. int size;
  873. bool big_endian;
  874. std::string error;
  875. if (!elfcpp::Elf_recognizer::is_valid_header(elf_header, hdrsize, &size,
  876. &big_endian, &error))
  877. gold_fatal(_("%s: %s"), this->name_, error.c_str());
  878. if (size == 32)
  879. {
  880. if (big_endian)
  881. #ifdef HAVE_TARGET_32_BIG
  882. return this->sized_make_object<32, true>(elf_header, input_file,
  883. output_file);
  884. #else
  885. gold_unreachable();
  886. #endif
  887. else
  888. #ifdef HAVE_TARGET_32_LITTLE
  889. return this->sized_make_object<32, false>(elf_header, input_file,
  890. output_file);
  891. #else
  892. gold_unreachable();
  893. #endif
  894. }
  895. else if (size == 64)
  896. {
  897. if (big_endian)
  898. #ifdef HAVE_TARGET_64_BIG
  899. return this->sized_make_object<64, true>(elf_header, input_file,
  900. output_file);
  901. #else
  902. gold_unreachable();
  903. #endif
  904. else
  905. #ifdef HAVE_TARGET_64_LITTLE
  906. return this->sized_make_object<64, false>(elf_header, input_file,
  907. output_file);
  908. #else
  909. gold_unreachable();
  910. #endif
  911. }
  912. else
  913. gold_unreachable();
  914. }
  915. // Function template to create a Sized_relobj_dwo and record the target info.
  916. // P is a pointer to the ELF header in memory.
  917. template <int size, bool big_endian>
  918. Relobj*
  919. Dwo_file::sized_make_object(const unsigned char* p, Input_file* input_file,
  920. Dwp_output_file* output_file)
  921. {
  922. elfcpp::Ehdr<size, big_endian> ehdr(p);
  923. Sized_relobj_dwo<size, big_endian>* obj =
  924. new Sized_relobj_dwo<size, big_endian>(this->name_, input_file, ehdr);
  925. obj->setup();
  926. if (output_file != NULL)
  927. output_file->record_target_info(
  928. this->name_, ehdr.get_e_machine(), size, big_endian,
  929. ehdr.get_e_ident()[elfcpp::EI_OSABI],
  930. ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
  931. return obj;
  932. }
  933. // Read the .debug_cu_index or .debug_tu_index section of a .dwp file,
  934. // and process the CU or TU sets.
  935. void
  936. Dwo_file::read_unit_index(unsigned int shndx, unsigned int *debug_shndx,
  937. Dwp_output_file* output_file, bool is_tu_index)
  938. {
  939. if (this->obj_->is_big_endian())
  940. this->sized_read_unit_index<true>(shndx, debug_shndx, output_file,
  941. is_tu_index);
  942. else
  943. this->sized_read_unit_index<false>(shndx, debug_shndx, output_file,
  944. is_tu_index);
  945. }
  946. template <bool big_endian>
  947. void
  948. Dwo_file::sized_read_unit_index(unsigned int shndx,
  949. unsigned int *debug_shndx,
  950. Dwp_output_file* output_file,
  951. bool is_tu_index)
  952. {
  953. elfcpp::DW_SECT info_sect = (is_tu_index
  954. ? elfcpp::DW_SECT_TYPES
  955. : elfcpp::DW_SECT_INFO);
  956. unsigned int info_shndx = debug_shndx[info_sect];
  957. gold_assert(shndx > 0);
  958. section_size_type index_len;
  959. bool index_is_new;
  960. const unsigned char* contents =
  961. this->section_contents(shndx, &index_len, &index_is_new);
  962. unsigned int version =
  963. elfcpp::Swap_unaligned<32, big_endian>::readval(contents);
  964. // We don't support version 1 anymore because it was experimental
  965. // and because in normal use, dwp is not expected to read .dwp files
  966. // produced by an earlier version of the tool.
  967. if (version != 2)
  968. gold_fatal(_("%s: section %s has unsupported version number %d"),
  969. this->name_, this->section_name(shndx).c_str(), version);
  970. unsigned int ncols =
  971. elfcpp::Swap_unaligned<32, big_endian>::readval(contents
  972. + sizeof(uint32_t));
  973. unsigned int nused =
  974. elfcpp::Swap_unaligned<32, big_endian>::readval(contents
  975. + 2 * sizeof(uint32_t));
  976. if (ncols == 0 || nused == 0)
  977. return;
  978. gold_assert(info_shndx > 0);
  979. unsigned int nslots =
  980. elfcpp::Swap_unaligned<32, big_endian>::readval(contents
  981. + 3 * sizeof(uint32_t));
  982. const unsigned char* phash = contents + 4 * sizeof(uint32_t);
  983. const unsigned char* pindex = phash + nslots * sizeof(uint64_t);
  984. const unsigned char* pcolhdrs = pindex + nslots * sizeof(uint32_t);
  985. const unsigned char* poffsets = pcolhdrs + ncols * sizeof(uint32_t);
  986. const unsigned char* psizes = poffsets + nused * ncols * sizeof(uint32_t);
  987. const unsigned char* pend = psizes + nused * ncols * sizeof(uint32_t);
  988. if (pend > contents + index_len)
  989. gold_fatal(_("%s: section %s is corrupt"), this->name_,
  990. this->section_name(shndx).c_str());
  991. // Copy the related sections and track the section offsets and sizes.
  992. Section_bounds sections[elfcpp::DW_SECT_MAX + 1];
  993. for (int i = elfcpp::DW_SECT_ABBREV; i <= elfcpp::DW_SECT_MAX; ++i)
  994. {
  995. if (debug_shndx[i] > 0)
  996. sections[i] = this->copy_section(output_file, debug_shndx[i],
  997. static_cast<elfcpp::DW_SECT>(i));
  998. }
  999. // Get the contents of the .debug_info.dwo or .debug_types.dwo section.
  1000. section_size_type info_len;
  1001. bool info_is_new;
  1002. const unsigned char* info_contents =
  1003. this->section_contents(info_shndx, &info_len, &info_is_new);
  1004. // Loop over the slots of the hash table.
  1005. for (unsigned int i = 0; i < nslots; ++i)
  1006. {
  1007. uint64_t signature =
  1008. elfcpp::Swap_unaligned<64, big_endian>::readval(phash);
  1009. unsigned int index =
  1010. elfcpp::Swap_unaligned<32, big_endian>::readval(pindex);
  1011. if (index != 0 && (!is_tu_index || !output_file->lookup_tu(signature)))
  1012. {
  1013. Unit_set* unit_set = new Unit_set();
  1014. unit_set->signature = signature;
  1015. const unsigned char* pch = pcolhdrs;
  1016. const unsigned char* porow =
  1017. poffsets + (index - 1) * ncols * sizeof(uint32_t);
  1018. const unsigned char* psrow =
  1019. psizes + (index - 1) * ncols * sizeof(uint32_t);
  1020. // Adjust the offset of each contribution within the input section
  1021. // by the offset of the input section within the output section.
  1022. for (unsigned int j = 0; j <= ncols; j++)
  1023. {
  1024. unsigned int dw_sect =
  1025. elfcpp::Swap_unaligned<64, big_endian>::readval(pch);
  1026. unsigned int offset =
  1027. elfcpp::Swap_unaligned<64, big_endian>::readval(porow);
  1028. unsigned int size =
  1029. elfcpp::Swap_unaligned<64, big_endian>::readval(psrow);
  1030. unit_set->sections[dw_sect].offset = (sections[dw_sect].offset
  1031. + offset);
  1032. unit_set->sections[dw_sect].size = size;
  1033. pch += sizeof(uint32_t);
  1034. porow += sizeof(uint32_t);
  1035. psrow += sizeof(uint32_t);
  1036. }
  1037. const unsigned char* unit_start =
  1038. info_contents + unit_set->sections[info_sect].offset;
  1039. section_size_type unit_length = unit_set->sections[info_sect].size;
  1040. // Dwp_output_file::add_contribution writes the .debug_info.dwo
  1041. // section directly to the output file, so we only need to
  1042. // duplicate contributions for .debug_types.dwo section.
  1043. if (is_tu_index)
  1044. {
  1045. unsigned char *copy = new unsigned char[unit_length];
  1046. memcpy(copy, unit_start, unit_length);
  1047. unit_start = copy;
  1048. }
  1049. section_offset_type off =
  1050. output_file->add_contribution(info_sect, unit_start,
  1051. unit_length, 1);
  1052. unit_set->sections[info_sect].offset = off;
  1053. if (is_tu_index)
  1054. output_file->add_tu_set(unit_set);
  1055. else
  1056. output_file->add_cu_set(unit_set);
  1057. }
  1058. phash += sizeof(uint64_t);
  1059. pindex += sizeof(uint32_t);
  1060. }
  1061. if (index_is_new)
  1062. delete[] contents;
  1063. if (info_is_new)
  1064. delete[] info_contents;
  1065. }
  1066. // Verify the .debug_cu_index section of a .dwp file, comparing it
  1067. // against the list of .dwo files referenced by the corresponding
  1068. // executable file.
  1069. bool
  1070. Dwo_file::verify_dwo_list(unsigned int shndx, const File_list& files)
  1071. {
  1072. if (this->obj_->is_big_endian())
  1073. return this->sized_verify_dwo_list<true>(shndx, files);
  1074. else
  1075. return this->sized_verify_dwo_list<false>(shndx, files);
  1076. }
  1077. template <bool big_endian>
  1078. bool
  1079. Dwo_file::sized_verify_dwo_list(unsigned int shndx, const File_list& files)
  1080. {
  1081. gold_assert(shndx > 0);
  1082. section_size_type index_len;
  1083. bool index_is_new;
  1084. const unsigned char* contents =
  1085. this->section_contents(shndx, &index_len, &index_is_new);
  1086. unsigned int version =
  1087. elfcpp::Swap_unaligned<32, big_endian>::readval(contents);
  1088. // We don't support version 1 anymore because it was experimental
  1089. // and because in normal use, dwp is not expected to read .dwp files
  1090. // produced by an earlier version of the tool.
  1091. if (version != 2)
  1092. gold_fatal(_("%s: section %s has unsupported version number %d"),
  1093. this->name_, this->section_name(shndx).c_str(), version);
  1094. unsigned int ncols =
  1095. elfcpp::Swap_unaligned<32, big_endian>::readval(contents
  1096. + sizeof(uint32_t));
  1097. unsigned int nused =
  1098. elfcpp::Swap_unaligned<32, big_endian>::readval(contents
  1099. + 2 * sizeof(uint32_t));
  1100. if (ncols == 0 || nused == 0)
  1101. return true;
  1102. unsigned int nslots =
  1103. elfcpp::Swap_unaligned<32, big_endian>::readval(contents
  1104. + 3 * sizeof(uint32_t));
  1105. const unsigned char* phash = contents + 4 * sizeof(uint32_t);
  1106. const unsigned char* pindex = phash + nslots * sizeof(uint64_t);
  1107. const unsigned char* pcolhdrs = pindex + nslots * sizeof(uint32_t);
  1108. const unsigned char* poffsets = pcolhdrs + ncols * sizeof(uint32_t);
  1109. const unsigned char* psizes = poffsets + nused * ncols * sizeof(uint32_t);
  1110. const unsigned char* pend = psizes + nused * ncols * sizeof(uint32_t);
  1111. if (pend > contents + index_len)
  1112. gold_fatal(_("%s: section %s is corrupt"), this->name_,
  1113. this->section_name(shndx).c_str());
  1114. int nmissing = 0;
  1115. for (File_list::const_iterator f = files.begin(); f != files.end(); ++f)
  1116. {
  1117. uint64_t dwo_id = f->dwo_id;
  1118. unsigned int slot = static_cast<unsigned int>(dwo_id) & (nslots - 1);
  1119. const unsigned char* ph = phash + slot * sizeof(uint64_t);
  1120. const unsigned char* pi = pindex + slot * sizeof(uint32_t);
  1121. uint64_t probe = elfcpp::Swap_unaligned<64, big_endian>::readval(ph);
  1122. uint32_t row_index = elfcpp::Swap_unaligned<32, big_endian>::readval(pi);
  1123. if (row_index != 0 && probe != dwo_id)
  1124. {
  1125. unsigned int h2 = ((static_cast<unsigned int>(dwo_id >> 32)
  1126. & (nslots - 1)) | 1);
  1127. do
  1128. {
  1129. slot = (slot + h2) & (nslots - 1);
  1130. ph = phash + slot * sizeof(uint64_t);
  1131. pi = pindex + slot * sizeof(uint32_t);
  1132. probe = elfcpp::Swap_unaligned<64, big_endian>::readval(ph);
  1133. row_index = elfcpp::Swap_unaligned<32, big_endian>::readval(pi);
  1134. } while (row_index != 0 && probe != dwo_id);
  1135. }
  1136. if (row_index == 0)
  1137. {
  1138. printf(_("missing .dwo file: %016llx %s\n"),
  1139. static_cast<long long>(dwo_id), f->dwo_name.c_str());
  1140. ++nmissing;
  1141. }
  1142. }
  1143. gold_info(_("Found %d missing .dwo files"), nmissing);
  1144. if (index_is_new)
  1145. delete[] contents;
  1146. return nmissing == 0;
  1147. }
  1148. // Merge the input string table section into the output file.
  1149. void
  1150. Dwo_file::add_strings(Dwp_output_file* output_file, unsigned int debug_str)
  1151. {
  1152. section_size_type len;
  1153. bool is_new;
  1154. const unsigned char* pdata = this->section_contents(debug_str, &len, &is_new);
  1155. const char* p = reinterpret_cast<const char*>(pdata);
  1156. const char* pend = p + len;
  1157. // Check that the last string is null terminated.
  1158. if (pend[-1] != '\0')
  1159. gold_fatal(_("%s: last entry in string section '%s' "
  1160. "is not null terminated"),
  1161. this->name_,
  1162. this->section_name(debug_str).c_str());
  1163. // Count the number of strings in the section, and size the map.
  1164. size_t count = 0;
  1165. for (const char* pt = p; pt < pend; pt += strlen(pt) + 1)
  1166. ++count;
  1167. this->str_offset_map_.reserve(count + 1);
  1168. // Add the strings to the output string table, and record the new offsets
  1169. // in the map.
  1170. section_offset_type i = 0;
  1171. section_offset_type new_offset;
  1172. while (p < pend)
  1173. {
  1174. size_t len = strlen(p);
  1175. new_offset = output_file->add_string(p, len);
  1176. this->str_offset_map_.push_back(std::make_pair(i, new_offset));
  1177. p += len + 1;
  1178. i += len + 1;
  1179. }
  1180. new_offset = 0;
  1181. this->str_offset_map_.push_back(std::make_pair(i, new_offset));
  1182. if (is_new)
  1183. delete[] pdata;
  1184. }
  1185. // Copy a section from the input file to the output file.
  1186. // Return the offset and length of this input section's contribution
  1187. // in the output section. If copying .debug_str_offsets.dwo, remap
  1188. // the string offsets for the output string table.
  1189. Section_bounds
  1190. Dwo_file::copy_section(Dwp_output_file* output_file, unsigned int shndx,
  1191. elfcpp::DW_SECT section_id)
  1192. {
  1193. // Some sections may be referenced from more than one set.
  1194. // Don't copy a section more than once.
  1195. if (this->sect_offsets_[shndx].size > 0)
  1196. return this->sect_offsets_[shndx];
  1197. // Get the section contents. Upon return, if IS_NEW is true, the memory
  1198. // has been allocated via new; if false, the memory is part of the mapped
  1199. // input file, and we will need to duplicate it so that it will persist
  1200. // after we close the input file.
  1201. section_size_type len;
  1202. bool is_new;
  1203. const unsigned char* contents = this->section_contents(shndx, &len, &is_new);
  1204. if (section_id == elfcpp::DW_SECT_STR_OFFSETS)
  1205. {
  1206. const unsigned char* remapped = this->remap_str_offsets(contents, len);
  1207. if (is_new)
  1208. delete[] contents;
  1209. contents = remapped;
  1210. }
  1211. else if (!is_new)
  1212. {
  1213. unsigned char* copy = new unsigned char[len];
  1214. memcpy(copy, contents, len);
  1215. contents = copy;
  1216. }
  1217. // Add the contents of the input section to the output section.
  1218. // The output file takes ownership of the memory pointed to by CONTENTS.
  1219. section_offset_type off = output_file->add_contribution(section_id, contents,
  1220. len, 1);
  1221. // Store the output section bounds.
  1222. Section_bounds bounds(off, len);
  1223. this->sect_offsets_[shndx] = bounds;
  1224. return bounds;
  1225. }
  1226. // Remap the
  1227. const unsigned char*
  1228. Dwo_file::remap_str_offsets(const unsigned char* contents,
  1229. section_size_type len)
  1230. {
  1231. if ((len & 3) != 0)
  1232. gold_fatal(_("%s: .debug_str_offsets.dwo section size not a multiple of 4"),
  1233. this->name_);
  1234. if (this->obj_->is_big_endian())
  1235. return this->sized_remap_str_offsets<true>(contents, len);
  1236. else
  1237. return this->sized_remap_str_offsets<false>(contents, len);
  1238. }
  1239. template <bool big_endian>
  1240. const unsigned char*
  1241. Dwo_file::sized_remap_str_offsets(const unsigned char* contents,
  1242. section_size_type len)
  1243. {
  1244. unsigned char* remapped = new unsigned char[len];
  1245. const unsigned char* p = contents;
  1246. unsigned char* q = remapped;
  1247. while (len > 0)
  1248. {
  1249. unsigned int val = elfcpp::Swap_unaligned<32, big_endian>::readval(p);
  1250. val = this->remap_str_offset(val);
  1251. elfcpp::Swap_unaligned<32, big_endian>::writeval(q, val);
  1252. len -= 4;
  1253. p += 4;
  1254. q += 4;
  1255. }
  1256. return remapped;
  1257. }
  1258. unsigned int
  1259. Dwo_file::remap_str_offset(section_offset_type val)
  1260. {
  1261. Str_offset_map_entry entry;
  1262. entry.first = val;
  1263. Str_offset_map::const_iterator p =
  1264. std::lower_bound(this->str_offset_map_.begin(),
  1265. this->str_offset_map_.end(),
  1266. entry, Offset_compare());
  1267. if (p == this->str_offset_map_.end() || p->first > val)
  1268. {
  1269. if (p == this->str_offset_map_.begin())
  1270. return 0;
  1271. --p;
  1272. gold_assert(p->first <= val);
  1273. }
  1274. return p->second + (val - p->first);
  1275. }
  1276. // Add a set of .debug_info.dwo or .debug_types.dwo and related sections
  1277. // to OUTPUT_FILE.
  1278. void
  1279. Dwo_file::add_unit_set(Dwp_output_file* output_file, unsigned int *debug_shndx,
  1280. bool is_debug_types)
  1281. {
  1282. unsigned int shndx = (is_debug_types
  1283. ? debug_shndx[elfcpp::DW_SECT_TYPES]
  1284. : debug_shndx[elfcpp::DW_SECT_INFO]);
  1285. gold_assert(shndx != 0);
  1286. if (debug_shndx[elfcpp::DW_SECT_ABBREV] == 0)
  1287. gold_fatal(_("%s: no .debug_abbrev.dwo section found"), this->name_);
  1288. // Copy the related sections and track the section offsets and sizes.
  1289. Section_bounds sections[elfcpp::DW_SECT_MAX + 1];
  1290. for (int i = elfcpp::DW_SECT_ABBREV; i <= elfcpp::DW_SECT_MAX; ++i)
  1291. {
  1292. if (debug_shndx[i] > 0)
  1293. sections[i] = this->copy_section(output_file, debug_shndx[i],
  1294. static_cast<elfcpp::DW_SECT>(i));
  1295. }
  1296. // Parse the .debug_info or .debug_types section and add each compilation
  1297. // or type unit to the output file, along with the contributions to the
  1298. // related sections.
  1299. Unit_reader reader(is_debug_types, this->obj_, shndx);
  1300. reader.add_units(output_file, debug_shndx[elfcpp::DW_SECT_ABBREV], sections);
  1301. }
  1302. // Class Dwp_output_file.
  1303. // Record the target info from an input file. On first call, we
  1304. // set the ELF header values for the output file. On subsequent
  1305. // calls, we just verify that the values match.
  1306. void
  1307. Dwp_output_file::record_target_info(const char*, int machine,
  1308. int size, bool big_endian,
  1309. int osabi, int abiversion)
  1310. {
  1311. // TODO: Check the values on subsequent calls.
  1312. if (this->size_ > 0)
  1313. return;
  1314. this->machine_ = machine;
  1315. this->size_ = size;
  1316. this->big_endian_ = big_endian;
  1317. this->osabi_ = osabi;
  1318. this->abiversion_ = abiversion;
  1319. if (size == 32)
  1320. this->next_file_offset_ = elfcpp::Elf_sizes<32>::ehdr_size;
  1321. else if (size == 64)
  1322. this->next_file_offset_ = elfcpp::Elf_sizes<64>::ehdr_size;
  1323. else
  1324. gold_unreachable();
  1325. this->fd_ = ::fopen(this->name_, "wb");
  1326. if (this->fd_ == NULL)
  1327. gold_fatal(_("%s: %s"), this->name_, strerror(errno));
  1328. // Write zeroes for the ELF header initially. We'll write
  1329. // the actual header during finalize().
  1330. static const char buf[elfcpp::Elf_sizes<64>::ehdr_size] = { 0 };
  1331. if (::fwrite(buf, 1, this->next_file_offset_, this->fd_)
  1332. < (size_t) this->next_file_offset_)
  1333. gold_fatal(_("%s: %s"), this->name_, strerror(errno));
  1334. }
  1335. // Add a string to the debug strings section.
  1336. section_offset_type
  1337. Dwp_output_file::add_string(const char* str, size_t len)
  1338. {
  1339. Stringpool::Key key;
  1340. this->stringpool_.add_with_length(str, len, true, &key);
  1341. this->have_strings_ = true;
  1342. // We aren't supposed to call get_offset() until after
  1343. // calling set_string_offsets(), but the offsets will
  1344. // not change unless optimizing the string pool.
  1345. return this->stringpool_.get_offset_from_key(key);
  1346. }
  1347. // Align the file offset to the given boundary.
  1348. static inline off_t
  1349. align_offset(off_t off, int align)
  1350. {
  1351. return (off + align - 1) & ~(align - 1);
  1352. }
  1353. // Add a new output section and return the section index.
  1354. unsigned int
  1355. Dwp_output_file::add_output_section(const char* section_name, int align)
  1356. {
  1357. Section sect(section_name, align);
  1358. this->sections_.push_back(sect);
  1359. return this->shnum_++;
  1360. }
  1361. // Add a contribution to a section in the output file, and return the offset
  1362. // of the contribution within the output section. The .debug_info.dwo section
  1363. // is expected to be the largest one, so we will write the contents of this
  1364. // section directly to the output file as we receive contributions, allowing
  1365. // us to free that memory as soon as possible. We will save the remaining
  1366. // contributions until we finalize the layout of the output file.
  1367. section_offset_type
  1368. Dwp_output_file::add_contribution(elfcpp::DW_SECT section_id,
  1369. const unsigned char* contents,
  1370. section_size_type len,
  1371. int align)
  1372. {
  1373. const char* section_name = get_dwarf_section_name(section_id);
  1374. gold_assert(static_cast<size_t>(section_id) < this->section_id_map_.size());
  1375. unsigned int shndx = this->section_id_map_[section_id];
  1376. // Create the section if necessary.
  1377. if (shndx == 0)
  1378. {
  1379. section_name = this->shstrtab_.add_with_length(section_name,
  1380. strlen(section_name),
  1381. false, NULL);
  1382. shndx = this->add_output_section(section_name, align);
  1383. this->section_id_map_[section_id] = shndx;
  1384. }
  1385. Section& section = this->sections_[shndx - 1];
  1386. section_offset_type section_offset;
  1387. if (section_id == elfcpp::DW_SECT_INFO)
  1388. {
  1389. // Write the .debug_info.dwo section directly.
  1390. // We do not need to free the memory in this case.
  1391. off_t file_offset = this->next_file_offset_;
  1392. gold_assert(this->size_ > 0 && file_offset > 0);
  1393. file_offset = align_offset(file_offset, align);
  1394. if (section.offset == 0)
  1395. section.offset = file_offset;
  1396. if (align > section.align)
  1397. {
  1398. // Since we've already committed to the layout for this
  1399. // section, an unexpected large alignment boundary may
  1400. // be impossible to honor.
  1401. if (align_offset(section.offset, align) != section.offset)
  1402. gold_fatal(_("%s: alignment (%d) for section '%s' "
  1403. "cannot be honored"),
  1404. this->name_, align, section_name);
  1405. section.align = align;
  1406. }
  1407. section_offset = file_offset - section.offset;
  1408. section.size = file_offset + len - section.offset;
  1409. ::fseek(this->fd_, file_offset, SEEK_SET);
  1410. if (::fwrite(contents, 1, len, this->fd_) < len)
  1411. gold_fatal(_("%s: error writing section '%s'"), this->name_,
  1412. section_name);
  1413. this->next_file_offset_ = file_offset + len;
  1414. }
  1415. else
  1416. {
  1417. // Collect the contributions and keep track of the total size.
  1418. if (align > section.align)
  1419. section.align = align;
  1420. section_offset = align_offset(section.size, align);
  1421. section.size = section_offset + len;
  1422. Contribution contrib = { section_offset, len, contents };
  1423. section.contributions.push_back(contrib);
  1424. }
  1425. return section_offset;
  1426. }
  1427. // Add a set of .debug_info and related sections to the output file.
  1428. void
  1429. Dwp_output_file::add_cu_set(Unit_set* cu_set)
  1430. {
  1431. uint64_t dwo_id = cu_set->signature;
  1432. unsigned int slot;
  1433. if (!this->cu_index_.find_or_add(dwo_id, &slot))
  1434. this->cu_index_.enter_set(slot, cu_set);
  1435. else
  1436. gold_warning(_("%s: duplicate entry for CU (dwo_id 0x%llx)"),
  1437. this->name_, (unsigned long long)dwo_id);
  1438. }
  1439. // Lookup a type signature and return TRUE if we have already seen it.
  1440. bool
  1441. Dwp_output_file::lookup_tu(uint64_t type_sig)
  1442. {
  1443. this->last_type_sig_ = type_sig;
  1444. return this->tu_index_.find_or_add(type_sig, &this->last_tu_slot_);
  1445. }
  1446. // Add a set of .debug_types and related sections to the output file.
  1447. void
  1448. Dwp_output_file::add_tu_set(Unit_set* tu_set)
  1449. {
  1450. uint64_t type_sig = tu_set->signature;
  1451. unsigned int slot;
  1452. if (type_sig == this->last_type_sig_)
  1453. slot = this->last_tu_slot_;
  1454. else
  1455. this->tu_index_.find_or_add(type_sig, &slot);
  1456. this->tu_index_.enter_set(slot, tu_set);
  1457. }
  1458. // Find a slot in the hash table for SIGNATURE. Return TRUE
  1459. // if the entry already exists.
  1460. bool
  1461. Dwp_output_file::Dwp_index::find_or_add(uint64_t signature,
  1462. unsigned int* slotp)
  1463. {
  1464. if (this->capacity_ == 0)
  1465. this->initialize();
  1466. unsigned int slot =
  1467. static_cast<unsigned int>(signature) & (this->capacity_ - 1);
  1468. unsigned int secondary_hash;
  1469. uint64_t probe = this->hash_table_[slot];
  1470. uint32_t row_index = this->index_table_[slot];
  1471. if (row_index != 0 && probe != signature)
  1472. {
  1473. secondary_hash = (static_cast<unsigned int>(signature >> 32)
  1474. & (this->capacity_ - 1)) | 1;
  1475. do
  1476. {
  1477. slot = (slot + secondary_hash) & (this->capacity_ - 1);
  1478. probe = this->hash_table_[slot];
  1479. row_index = this->index_table_[slot];
  1480. } while (row_index != 0 && probe != signature);
  1481. }
  1482. *slotp = slot;
  1483. return (row_index != 0);
  1484. }
  1485. // Enter a CU or TU set at the given SLOT in the hash table.
  1486. void
  1487. Dwp_output_file::Dwp_index::enter_set(unsigned int slot,
  1488. const Unit_set* set)
  1489. {
  1490. gold_assert(slot < this->capacity_);
  1491. // Add a row to the offsets and sizes tables.
  1492. this->section_table_.push_back(set);
  1493. uint32_t row_index = this->section_table_rows();
  1494. // Mark the sections used in this set.
  1495. for (unsigned int i = 1; i <= elfcpp::DW_SECT_MAX; i++)
  1496. if (set->sections[i].size > 0)
  1497. this->section_mask_ |= 1 << i;
  1498. // Enter the signature and pool index into the hash table.
  1499. gold_assert(this->hash_table_[slot] == 0);
  1500. this->hash_table_[slot] = set->signature;
  1501. this->index_table_[slot] = row_index;
  1502. ++this->used_;
  1503. // Grow the hash table when we exceed 2/3 capacity.
  1504. if (this->used_ * 3 > this->capacity_ * 2)
  1505. this->grow();
  1506. }
  1507. // Initialize the hash table.
  1508. void
  1509. Dwp_output_file::Dwp_index::initialize()
  1510. {
  1511. this->capacity_ = 16;
  1512. this->hash_table_ = new uint64_t[this->capacity_];
  1513. memset(this->hash_table_, 0, this->capacity_ * sizeof(uint64_t));
  1514. this->index_table_ = new uint32_t[this->capacity_];
  1515. memset(this->index_table_, 0, this->capacity_ * sizeof(uint32_t));
  1516. }
  1517. // Grow the hash table when we reach 2/3 capacity.
  1518. void
  1519. Dwp_output_file::Dwp_index::grow()
  1520. {
  1521. unsigned int old_capacity = this->capacity_;
  1522. uint64_t* old_hash_table = this->hash_table_;
  1523. uint32_t* old_index_table = this->index_table_;
  1524. unsigned int old_used = this->used_;
  1525. this->capacity_ = old_capacity * 2;
  1526. this->hash_table_ = new uint64_t[this->capacity_];
  1527. memset(this->hash_table_, 0, this->capacity_ * sizeof(uint64_t));
  1528. this->index_table_ = new uint32_t[this->capacity_];
  1529. memset(this->index_table_, 0, this->capacity_ * sizeof(uint32_t));
  1530. this->used_ = 0;
  1531. for (unsigned int i = 0; i < old_capacity; ++i)
  1532. {
  1533. uint64_t signature = old_hash_table[i];
  1534. uint32_t row_index = old_index_table[i];
  1535. if (row_index != 0)
  1536. {
  1537. unsigned int slot;
  1538. bool found = this->find_or_add(signature, &slot);
  1539. gold_assert(!found);
  1540. this->hash_table_[slot] = signature;
  1541. this->index_table_[slot] = row_index;
  1542. ++this->used_;
  1543. }
  1544. }
  1545. gold_assert(this->used_ == old_used);
  1546. delete[] old_hash_table;
  1547. delete[] old_index_table;
  1548. }
  1549. // Finalize the file, write the string tables and index sections,
  1550. // and close the file.
  1551. void
  1552. Dwp_output_file::finalize()
  1553. {
  1554. unsigned char* buf;
  1555. // Write the accumulated output sections.
  1556. for (unsigned int i = 0; i < this->sections_.size(); i++)
  1557. {
  1558. Section& sect = this->sections_[i];
  1559. // If the offset has already been assigned, the section has been written.
  1560. if (sect.offset > 0 || sect.size == 0)
  1561. continue;
  1562. off_t file_offset = this->next_file_offset_;
  1563. file_offset = align_offset(file_offset, sect.align);
  1564. sect.offset = file_offset;
  1565. this->write_contributions(sect);
  1566. this->next_file_offset_ = file_offset + sect.size;
  1567. }
  1568. // Write the debug string table.
  1569. if (this->have_strings_)
  1570. {
  1571. this->stringpool_.set_string_offsets();
  1572. section_size_type len = this->stringpool_.get_strtab_size();
  1573. buf = new unsigned char[len];
  1574. this->stringpool_.write_to_buffer(buf, len);
  1575. this->write_new_section(".debug_str.dwo", buf, len, 1);
  1576. delete[] buf;
  1577. }
  1578. // Write the CU and TU indexes.
  1579. if (this->big_endian_)
  1580. {
  1581. this->write_index<true>(".debug_cu_index", this->cu_index_);
  1582. this->write_index<true>(".debug_tu_index", this->tu_index_);
  1583. }
  1584. else
  1585. {
  1586. this->write_index<false>(".debug_cu_index", this->cu_index_);
  1587. this->write_index<false>(".debug_tu_index", this->tu_index_);
  1588. }
  1589. off_t file_offset = this->next_file_offset_;
  1590. // Write the section string table.
  1591. this->shstrndx_ = this->shnum_++;
  1592. const char* shstrtab_name =
  1593. this->shstrtab_.add_with_length(".shstrtab", sizeof(".shstrtab") - 1,
  1594. false, NULL);
  1595. this->shstrtab_.set_string_offsets();
  1596. section_size_type shstrtab_len = this->shstrtab_.get_strtab_size();
  1597. buf = new unsigned char[shstrtab_len];
  1598. this->shstrtab_.write_to_buffer(buf, shstrtab_len);
  1599. off_t shstrtab_off = file_offset;
  1600. ::fseek(this->fd_, file_offset, 0);
  1601. if (::fwrite(buf, 1, shstrtab_len, this->fd_) < shstrtab_len)
  1602. gold_fatal(_("%s: error writing section '.shstrtab'"), this->name_);
  1603. delete[] buf;
  1604. file_offset += shstrtab_len;
  1605. // Write the section header table. The first entry is a NULL entry.
  1606. // This is followed by the debug sections, and finally we write the
  1607. // .shstrtab section header.
  1608. file_offset = align_offset(file_offset, this->size_ == 32 ? 4 : 8);
  1609. this->shoff_ = file_offset;
  1610. ::fseek(this->fd_, file_offset, 0);
  1611. section_size_type sh0_size = 0;
  1612. unsigned int sh0_link = 0;
  1613. if (this->shnum_ >= elfcpp::SHN_LORESERVE)
  1614. sh0_size = this->shnum_;
  1615. if (this->shstrndx_ >= elfcpp::SHN_LORESERVE)
  1616. sh0_link = this->shstrndx_;
  1617. this->write_shdr(NULL, 0, 0, 0, 0, sh0_size, sh0_link, 0, 0, 0);
  1618. for (unsigned int i = 0; i < this->sections_.size(); ++i)
  1619. {
  1620. Section& sect = this->sections_[i];
  1621. this->write_shdr(sect.name, elfcpp::SHT_PROGBITS, 0, 0, sect.offset,
  1622. sect.size, 0, 0, sect.align, 0);
  1623. }
  1624. this->write_shdr(shstrtab_name, elfcpp::SHT_STRTAB, 0, 0,
  1625. shstrtab_off, shstrtab_len, 0, 0, 1, 0);
  1626. // Write the ELF header.
  1627. this->write_ehdr();
  1628. // Close the file.
  1629. if (this->fd_ != NULL)
  1630. {
  1631. if (::fclose(this->fd_) != 0)
  1632. gold_fatal(_("%s: %s"), this->name_, strerror(errno));
  1633. }
  1634. this->fd_ = NULL;
  1635. }
  1636. // Write the contributions to an output section.
  1637. void
  1638. Dwp_output_file::write_contributions(const Section& sect)
  1639. {
  1640. for (unsigned int i = 0; i < sect.contributions.size(); ++i)
  1641. {
  1642. const Contribution& c = sect.contributions[i];
  1643. ::fseek(this->fd_, sect.offset + c.output_offset, SEEK_SET);
  1644. if (::fwrite(c.contents, 1, c.size, this->fd_) < c.size)
  1645. gold_fatal(_("%s: error writing section '%s'"), this->name_, sect.name);
  1646. delete[] c.contents;
  1647. }
  1648. }
  1649. // Write a new section to the output file.
  1650. void
  1651. Dwp_output_file::write_new_section(const char* section_name,
  1652. const unsigned char* contents,
  1653. section_size_type len, int align)
  1654. {
  1655. section_name = this->shstrtab_.add_with_length(section_name,
  1656. strlen(section_name),
  1657. false, NULL);
  1658. unsigned int shndx = this->add_output_section(section_name, align);
  1659. Section& section = this->sections_[shndx - 1];
  1660. off_t file_offset = this->next_file_offset_;
  1661. file_offset = align_offset(file_offset, align);
  1662. section.offset = file_offset;
  1663. section.size = len;
  1664. ::fseek(this->fd_, file_offset, SEEK_SET);
  1665. if (::fwrite(contents, 1, len, this->fd_) < len)
  1666. gold_fatal(_("%s: error writing section '%s'"), this->name_, section_name);
  1667. this->next_file_offset_ = file_offset + len;
  1668. }
  1669. // Write a CU or TU index section.
  1670. template<bool big_endian>
  1671. void
  1672. Dwp_output_file::write_index(const char* sect_name, const Dwp_index& index)
  1673. {
  1674. const unsigned int nslots = index.hash_table_total_slots();
  1675. const unsigned int nused = index.hash_table_used_slots();
  1676. const unsigned int nrows = index.section_table_rows();
  1677. int column_mask = index.section_table_cols();
  1678. unsigned int ncols = 0;
  1679. for (unsigned int c = 1; c <= elfcpp::DW_SECT_MAX; ++c)
  1680. if (column_mask & (1 << c))
  1681. ncols++;
  1682. const unsigned int ntable = (nrows * 2 + 1) * ncols;
  1683. const section_size_type index_size = (4 * sizeof(uint32_t)
  1684. + nslots * sizeof(uint64_t)
  1685. + nslots * sizeof(uint32_t)
  1686. + ntable * sizeof(uint32_t));
  1687. // Allocate a buffer for the section contents.
  1688. unsigned char* buf = new unsigned char[index_size];
  1689. unsigned char* p = buf;
  1690. // Write the section header: version number, padding,
  1691. // number of used slots and total number of slots.
  1692. elfcpp::Swap_unaligned<32, big_endian>::writeval(p, 2);
  1693. p += sizeof(uint32_t);
  1694. elfcpp::Swap_unaligned<32, big_endian>::writeval(p, ncols);
  1695. p += sizeof(uint32_t);
  1696. elfcpp::Swap_unaligned<32, big_endian>::writeval(p, nused);
  1697. p += sizeof(uint32_t);
  1698. elfcpp::Swap_unaligned<32, big_endian>::writeval(p, nslots);
  1699. p += sizeof(uint32_t);
  1700. // Write the hash table.
  1701. for (unsigned int i = 0; i < nslots; ++i)
  1702. {
  1703. elfcpp::Swap_unaligned<64, big_endian>::writeval(p, index.hash_table(i));
  1704. p += sizeof(uint64_t);
  1705. }
  1706. // Write the parallel index table.
  1707. for (unsigned int i = 0; i < nslots; ++i)
  1708. {
  1709. elfcpp::Swap_unaligned<32, big_endian>::writeval(p, index.index_table(i));
  1710. p += sizeof(uint32_t);
  1711. }
  1712. // Write the first row of the table of section offsets.
  1713. for (unsigned int c = 1; c <= elfcpp::DW_SECT_MAX; ++c)
  1714. {
  1715. if (column_mask & (1 << c))
  1716. {
  1717. elfcpp::Swap_unaligned<32, big_endian>::writeval(p, c);
  1718. p += sizeof(uint32_t);
  1719. }
  1720. }
  1721. // Write the table of section offsets.
  1722. Dwp_index::Section_table::const_iterator tbl = index.section_table();
  1723. for (unsigned int r = 0; r < nrows; ++r)
  1724. {
  1725. gold_assert(tbl != index.section_table_end());
  1726. const Section_bounds* sects = (*tbl)->sections;
  1727. for (unsigned int c = 1; c <= elfcpp::DW_SECT_MAX; ++c)
  1728. {
  1729. if (column_mask & (1 << c))
  1730. {
  1731. section_offset_type offset = sects[c].offset;
  1732. elfcpp::Swap_unaligned<32, big_endian>::writeval(p, offset);
  1733. p += sizeof(uint32_t);
  1734. }
  1735. else
  1736. gold_assert(sects[c].size == 0);
  1737. }
  1738. ++tbl;
  1739. }
  1740. // Write the table of section sizes.
  1741. tbl = index.section_table();
  1742. for (unsigned int r = 0; r < nrows; ++r)
  1743. {
  1744. gold_assert(tbl != index.section_table_end());
  1745. const Section_bounds* sects = (*tbl)->sections;
  1746. for (unsigned int c = 1; c <= elfcpp::DW_SECT_MAX; ++c)
  1747. {
  1748. if (column_mask & (1 << c))
  1749. {
  1750. section_size_type size = sects[c].size;
  1751. elfcpp::Swap_unaligned<32, big_endian>::writeval(p, size);
  1752. p += sizeof(uint32_t);
  1753. }
  1754. else
  1755. gold_assert(sects[c].size == 0);
  1756. }
  1757. ++tbl;
  1758. }
  1759. gold_assert(p == buf + index_size);
  1760. this->write_new_section(sect_name, buf, index_size, sizeof(uint64_t));
  1761. delete[] buf;
  1762. }
  1763. // Write the ELF header.
  1764. void
  1765. Dwp_output_file::write_ehdr()
  1766. {
  1767. if (this->size_ == 32)
  1768. {
  1769. if (this->big_endian_)
  1770. return this->sized_write_ehdr<32, true>();
  1771. else
  1772. return this->sized_write_ehdr<32, false>();
  1773. }
  1774. else if (this->size_ == 64)
  1775. {
  1776. if (this->big_endian_)
  1777. return this->sized_write_ehdr<64, true>();
  1778. else
  1779. return this->sized_write_ehdr<64, false>();
  1780. }
  1781. else
  1782. gold_unreachable();
  1783. }
  1784. template<unsigned int size, bool big_endian>
  1785. void
  1786. Dwp_output_file::sized_write_ehdr()
  1787. {
  1788. const unsigned int ehdr_size = elfcpp::Elf_sizes<size>::ehdr_size;
  1789. unsigned char buf[ehdr_size];
  1790. elfcpp::Ehdr_write<size, big_endian> ehdr(buf);
  1791. unsigned char e_ident[elfcpp::EI_NIDENT];
  1792. memset(e_ident, 0, elfcpp::EI_NIDENT);
  1793. e_ident[elfcpp::EI_MAG0] = elfcpp::ELFMAG0;
  1794. e_ident[elfcpp::EI_MAG1] = elfcpp::ELFMAG1;
  1795. e_ident[elfcpp::EI_MAG2] = elfcpp::ELFMAG2;
  1796. e_ident[elfcpp::EI_MAG3] = elfcpp::ELFMAG3;
  1797. if (size == 32)
  1798. e_ident[elfcpp::EI_CLASS] = elfcpp::ELFCLASS32;
  1799. else if (size == 64)
  1800. e_ident[elfcpp::EI_CLASS] = elfcpp::ELFCLASS64;
  1801. else
  1802. gold_unreachable();
  1803. e_ident[elfcpp::EI_DATA] = (big_endian
  1804. ? elfcpp::ELFDATA2MSB
  1805. : elfcpp::ELFDATA2LSB);
  1806. e_ident[elfcpp::EI_VERSION] = elfcpp::EV_CURRENT;
  1807. ehdr.put_e_ident(e_ident);
  1808. ehdr.put_e_type(elfcpp::ET_REL);
  1809. ehdr.put_e_machine(this->machine_);
  1810. ehdr.put_e_version(elfcpp::EV_CURRENT);
  1811. ehdr.put_e_entry(0);
  1812. ehdr.put_e_phoff(0);
  1813. ehdr.put_e_shoff(this->shoff_);
  1814. ehdr.put_e_flags(0);
  1815. ehdr.put_e_ehsize(elfcpp::Elf_sizes<size>::ehdr_size);
  1816. ehdr.put_e_phentsize(0);
  1817. ehdr.put_e_phnum(0);
  1818. ehdr.put_e_shentsize(elfcpp::Elf_sizes<size>::shdr_size);
  1819. ehdr.put_e_shnum(this->shnum_ < elfcpp::SHN_LORESERVE ? this->shnum_ : 0);
  1820. ehdr.put_e_shstrndx(this->shstrndx_ < elfcpp::SHN_LORESERVE
  1821. ? this->shstrndx_
  1822. : static_cast<unsigned int>(elfcpp::SHN_XINDEX));
  1823. ::fseek(this->fd_, 0, 0);
  1824. if (::fwrite(buf, 1, ehdr_size, this->fd_) < ehdr_size)
  1825. gold_fatal(_("%s: error writing ELF header"), this->name_);
  1826. }
  1827. // Write a section header.
  1828. void
  1829. Dwp_output_file::write_shdr(const char* name, unsigned int type,
  1830. unsigned int flags, uint64_t addr, off_t offset,
  1831. section_size_type sect_size, unsigned int link,
  1832. unsigned int info, unsigned int align,
  1833. unsigned int ent_size)
  1834. {
  1835. if (this->size_ == 32)
  1836. {
  1837. if (this->big_endian_)
  1838. return this->sized_write_shdr<32, true>(name, type, flags, addr,
  1839. offset, sect_size, link, info,
  1840. align, ent_size);
  1841. else
  1842. return this->sized_write_shdr<32, false>(name, type, flags, addr,
  1843. offset, sect_size, link, info,
  1844. align, ent_size);
  1845. }
  1846. else if (this->size_ == 64)
  1847. {
  1848. if (this->big_endian_)
  1849. return this->sized_write_shdr<64, true>(name, type, flags, addr,
  1850. offset, sect_size, link, info,
  1851. align, ent_size);
  1852. else
  1853. return this->sized_write_shdr<64, false>(name, type, flags, addr,
  1854. offset, sect_size, link, info,
  1855. align, ent_size);
  1856. }
  1857. else
  1858. gold_unreachable();
  1859. }
  1860. template<unsigned int size, bool big_endian>
  1861. void
  1862. Dwp_output_file::sized_write_shdr(const char* name, unsigned int type,
  1863. unsigned int flags, uint64_t addr,
  1864. off_t offset, section_size_type sect_size,
  1865. unsigned int link, unsigned int info,
  1866. unsigned int align, unsigned int ent_size)
  1867. {
  1868. const unsigned int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
  1869. unsigned char buf[shdr_size];
  1870. elfcpp::Shdr_write<size, big_endian> shdr(buf);
  1871. shdr.put_sh_name(name == NULL ? 0 : this->shstrtab_.get_offset(name));
  1872. shdr.put_sh_type(type);
  1873. shdr.put_sh_flags(flags);
  1874. shdr.put_sh_addr(addr);
  1875. shdr.put_sh_offset(offset);
  1876. shdr.put_sh_size(sect_size);
  1877. shdr.put_sh_link(link);
  1878. shdr.put_sh_info(info);
  1879. shdr.put_sh_addralign(align);
  1880. shdr.put_sh_entsize(ent_size);
  1881. if (::fwrite(buf, 1, shdr_size, this->fd_) < shdr_size)
  1882. gold_fatal(_("%s: error writing section header table"), this->name_);
  1883. }
  1884. // Class Dwo_name_info_reader.
  1885. // Visit a compilation unit.
  1886. void
  1887. Dwo_name_info_reader::visit_compilation_unit(off_t, off_t, Dwarf_die* die)
  1888. {
  1889. const char* dwo_name = die->string_attribute(elfcpp::DW_AT_GNU_dwo_name);
  1890. if (dwo_name != NULL)
  1891. {
  1892. uint64_t dwo_id = die->uint_attribute(elfcpp::DW_AT_GNU_dwo_id);
  1893. this->files_->push_back(Dwo_file_entry(dwo_id, dwo_name));
  1894. }
  1895. }
  1896. // Class Unit_reader.
  1897. // Read the CUs or TUs and add them to the output file.
  1898. void
  1899. Unit_reader::add_units(Dwp_output_file* output_file,
  1900. unsigned int debug_abbrev,
  1901. Section_bounds* sections)
  1902. {
  1903. this->output_file_ = output_file;
  1904. this->sections_ = sections;
  1905. this->set_abbrev_shndx(debug_abbrev);
  1906. this->parse();
  1907. }
  1908. // Visit a compilation unit.
  1909. void
  1910. Unit_reader::visit_compilation_unit(off_t, off_t cu_length, Dwarf_die* die)
  1911. {
  1912. if (cu_length == 0)
  1913. return;
  1914. Unit_set* unit_set = new Unit_set();
  1915. unit_set->signature = die->uint_attribute(elfcpp::DW_AT_GNU_dwo_id);
  1916. for (unsigned int i = elfcpp::DW_SECT_ABBREV; i <= elfcpp::DW_SECT_MAX; ++i)
  1917. unit_set->sections[i] = this->sections_[i];
  1918. // Dwp_output_file::add_contribution writes the .debug_info.dwo section
  1919. // directly to the output file, so we do not need to duplicate the
  1920. // section contents, and add_contribution does not need to free the memory.
  1921. section_offset_type off =
  1922. this->output_file_->add_contribution(elfcpp::DW_SECT_INFO,
  1923. this->buffer_at_offset(0),
  1924. cu_length, 1);
  1925. Section_bounds bounds(off, cu_length);
  1926. unit_set->sections[elfcpp::DW_SECT_INFO] = bounds;
  1927. this->output_file_->add_cu_set(unit_set);
  1928. }
  1929. // Visit a type unit.
  1930. void
  1931. Unit_reader::visit_type_unit(off_t, off_t tu_length, off_t,
  1932. uint64_t signature, Dwarf_die*)
  1933. {
  1934. if (tu_length == 0)
  1935. return;
  1936. if (this->output_file_->lookup_tu(signature))
  1937. return;
  1938. Unit_set* unit_set = new Unit_set();
  1939. unit_set->signature = signature;
  1940. for (unsigned int i = elfcpp::DW_SECT_ABBREV; i <= elfcpp::DW_SECT_MAX; ++i)
  1941. unit_set->sections[i] = this->sections_[i];
  1942. unsigned char* contents = new unsigned char[tu_length];
  1943. memcpy(contents, this->buffer_at_offset(0), tu_length);
  1944. section_offset_type off =
  1945. this->output_file_->add_contribution(elfcpp::DW_SECT_TYPES, contents,
  1946. tu_length, 1);
  1947. Section_bounds bounds(off, tu_length);
  1948. unit_set->sections[elfcpp::DW_SECT_TYPES] = bounds;
  1949. this->output_file_->add_tu_set(unit_set);
  1950. }
  1951. }; // End namespace gold
  1952. using namespace gold;
  1953. // Options.
  1954. enum Dwp_options {
  1955. VERIFY_ONLY = 0x101,
  1956. };
  1957. struct option dwp_options[] =
  1958. {
  1959. { "exec", required_argument, NULL, 'e' },
  1960. { "help", no_argument, NULL, 'h' },
  1961. { "output", required_argument, NULL, 'o' },
  1962. { "verbose", no_argument, NULL, 'v' },
  1963. { "verify-only", no_argument, NULL, VERIFY_ONLY },
  1964. { "version", no_argument, NULL, 'V' },
  1965. { NULL, 0, NULL, 0 }
  1966. };
  1967. // Print usage message and exit.
  1968. static void
  1969. usage(FILE* fd, int exit_status)
  1970. {
  1971. fprintf(fd, _("Usage: %s [options] [file...]\n"), program_name);
  1972. fprintf(fd, _(" -h, --help Print this help message\n"));
  1973. fprintf(fd, _(" -e EXE, --exec EXE Get list of dwo files from EXE"
  1974. " (defaults output to EXE.dwp)\n"));
  1975. fprintf(fd, _(" -o FILE, --output FILE Set output dwp file name\n"));
  1976. fprintf(fd, _(" -v, --verbose Verbose output\n"));
  1977. fprintf(fd, _(" --verify-only Verify output file against"
  1978. " exec file\n"));
  1979. fprintf(fd, _(" -V, --version Print version number\n"));
  1980. // REPORT_BUGS_TO is defined in bfd/bfdver.h.
  1981. const char* report = REPORT_BUGS_TO;
  1982. if (*report != '\0')
  1983. fprintf(fd, _("\nReport bugs to %s\n"), report);
  1984. exit(exit_status);
  1985. }
  1986. // Report version information.
  1987. static void
  1988. print_version()
  1989. {
  1990. // This output is intended to follow the GNU standards.
  1991. printf("GNU dwp %s\n", BFD_VERSION_STRING);
  1992. printf(_("Copyright (C) 2015 Free Software Foundation, Inc.\n"));
  1993. printf(_("\
  1994. This program is free software; you may redistribute it under the terms of\n\
  1995. the GNU General Public License version 3 or (at your option) any later version.\n\
  1996. This program has absolutely no warranty.\n"));
  1997. exit(EXIT_SUCCESS);
  1998. }
  1999. // Main program.
  2000. int
  2001. main(int argc, char** argv)
  2002. {
  2003. #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
  2004. setlocale(LC_MESSAGES, "");
  2005. #endif
  2006. #if defined (HAVE_SETLOCALE)
  2007. setlocale(LC_CTYPE, "");
  2008. #endif
  2009. bindtextdomain(PACKAGE, LOCALEDIR);
  2010. textdomain(PACKAGE);
  2011. program_name = argv[0];
  2012. // Initialize the global parameters, to let random code get to the
  2013. // errors object.
  2014. Errors errors(program_name);
  2015. set_parameters_errors(&errors);
  2016. // Initialize gold's global options. We don't use these in
  2017. // this program, but they need to be initialized so that
  2018. // functions we call from libgold work properly.
  2019. General_options options;
  2020. set_parameters_options(&options);
  2021. // In libiberty; expands @filename to the args in "filename".
  2022. expandargv(&argc, &argv);
  2023. // Collect file names and options.
  2024. File_list files;
  2025. std::string output_filename;
  2026. const char* exe_filename = NULL;
  2027. bool verbose = false;
  2028. bool verify_only = false;
  2029. int c;
  2030. while ((c = getopt_long(argc, argv, "e:ho:vV", dwp_options, NULL)) != -1)
  2031. {
  2032. switch (c)
  2033. {
  2034. case 'h':
  2035. usage(stdout, EXIT_SUCCESS);
  2036. case 'e':
  2037. exe_filename = optarg;
  2038. break;
  2039. case 'o':
  2040. output_filename.assign(optarg);
  2041. break;
  2042. case 'v':
  2043. verbose = true;
  2044. break;
  2045. case VERIFY_ONLY:
  2046. verify_only = true;
  2047. break;
  2048. case 'V':
  2049. print_version();
  2050. case '?':
  2051. default:
  2052. usage(stderr, EXIT_FAILURE);
  2053. }
  2054. }
  2055. if (output_filename.empty())
  2056. {
  2057. if (exe_filename == NULL)
  2058. gold_fatal(_("no output file specified"));
  2059. output_filename.assign(exe_filename);
  2060. output_filename.append(".dwp");
  2061. }
  2062. // Get list of .dwo files from the executable.
  2063. if (exe_filename != NULL)
  2064. {
  2065. Dwo_file exe_file(exe_filename);
  2066. exe_file.read_executable(&files);
  2067. }
  2068. // Add any additional files listed on command line.
  2069. for (int i = optind; i < argc; ++i)
  2070. files.push_back(Dwo_file_entry(0, argv[i]));
  2071. if (exe_filename == NULL && files.empty())
  2072. gold_fatal(_("no input files and no executable specified"));
  2073. if (verify_only)
  2074. {
  2075. // Get list of DWO files in the DWP file and compare with
  2076. // references found in the EXE file.
  2077. Dwo_file dwp_file(output_filename.c_str());
  2078. bool ok = dwp_file.verify(files);
  2079. return ok ? EXIT_SUCCESS : EXIT_FAILURE;
  2080. }
  2081. // Process each file, adding its contents to the output file.
  2082. Dwp_output_file output_file(output_filename.c_str());
  2083. for (File_list::const_iterator f = files.begin(); f != files.end(); ++f)
  2084. {
  2085. if (verbose)
  2086. fprintf(stderr, "%s\n", f->dwo_name.c_str());
  2087. Dwo_file dwo_file(f->dwo_name.c_str());
  2088. dwo_file.read(&output_file);
  2089. }
  2090. output_file.finalize();
  2091. return EXIT_SUCCESS;
  2092. }