blob: e84c8038b19e976467dfe9c677eb14bb3a39f43a [file] [log] [blame]
Stephen Wilsonf325ba92010-07-13 23:07:23 +00001//===-- ObjectFileELF.h --------------------------------------- -*- C++ -*-===//
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_ObjectFileELF_h_
11#define liblldb_ObjectFileELF_h_
12
Eugene Zelenko8157a882015-10-23 16:56:07 +000013// C Includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include <stdint.h>
Eugene Zelenko8157a882015-10-23 16:56:07 +000015
16// C++ Includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include <vector>
18
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Symbol/ObjectFile.h"
Pavel Labath5f19b902017-11-13 16:16:33 +000020#include "lldb/Utility/ArchSpec.h"
Zachary Turner5713a052017-03-22 18:40:07 +000021#include "lldb/Utility/FileSpec.h"
22#include "lldb/Utility/UUID.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000023#include "lldb/lldb-private.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024
Stephen Wilsonf325ba92010-07-13 23:07:23 +000025#include "ELFHeader.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Kate Stoneb9c1b512016-09-06 20:57:50 +000027struct ELFNote {
28 elf::elf_word n_namesz;
29 elf::elf_word n_descsz;
30 elf::elf_word n_type;
Ed Mastec113ff82013-12-02 17:49:13 +000031
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 std::string n_name;
Ed Mastec113ff82013-12-02 17:49:13 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034 ELFNote() : n_namesz(0), n_descsz(0), n_type(0) {}
Ed Mastec113ff82013-12-02 17:49:13 +000035
Kate Stoneb9c1b512016-09-06 20:57:50 +000036 /// Parse an ELFNote entry from the given DataExtractor starting at position
37 /// \p offset.
38 ///
39 /// @param[in] data
40 /// The DataExtractor to read from.
41 ///
42 /// @param[in,out] offset
43 /// Pointer to an offset in the data. On return the offset will be
44 /// advanced by the number of bytes read.
45 ///
46 /// @return
47 /// True if the ELFRel entry was successfully read and false otherwise.
48 bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
Greg Claytonb704b692015-10-28 18:04:38 +000049
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 size_t GetByteSize() const {
51 return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4);
52 }
Ed Mastec113ff82013-12-02 17:49:13 +000053};
54
Stephen Wilsonf325ba92010-07-13 23:07:23 +000055//------------------------------------------------------------------------------
56/// @class ObjectFileELF
Adrian Prantld8f460e2018-05-02 16:55:16 +000057/// Generic ELF object file reader.
Stephen Wilsonf325ba92010-07-13 23:07:23 +000058///
Adrian Prantld8f460e2018-05-02 16:55:16 +000059/// This class provides a generic ELF (32/64 bit) reader plugin implementing
60/// the ObjectFile protocol.
Kate Stoneb9c1b512016-09-06 20:57:50 +000061class ObjectFileELF : public lldb_private::ObjectFile {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 ~ObjectFileELF() override;
Eugene Zelenko8157a882015-10-23 16:56:07 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 //------------------------------------------------------------------
66 // Static Functions
67 //------------------------------------------------------------------
68 static void Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 static void Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 static lldb_private::ConstString GetPluginNameStatic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 static const char *GetPluginDescriptionStatic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 static lldb_private::ObjectFile *
77 CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
78 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
79 lldb::offset_t file_offset, lldb::offset_t length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 static lldb_private::ObjectFile *CreateMemoryInstance(
82 const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
83 const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
Greg Claytonc9660542012-02-05 02:38:54 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
86 lldb::DataBufferSP &data_sp,
87 lldb::offset_t data_offset,
88 lldb::offset_t file_offset,
89 lldb::offset_t length,
90 lldb_private::ModuleSpecList &specs);
Michael Sartain9f0013d2013-05-17 00:20:21 +000091
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset,
93 lldb::addr_t length);
Michael Sartain9f0013d2013-05-17 00:20:21 +000094
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 //------------------------------------------------------------------
96 // PluginInterface protocol
97 //------------------------------------------------------------------
98 lldb_private::ConstString GetPluginName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 uint32_t GetPluginVersion() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 //------------------------------------------------------------------
103 // ObjectFile Protocol.
104 //------------------------------------------------------------------
105 bool ParseHeader() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107 bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
108 bool value_is_offset) override;
Steve Pucci9e02dac2014-02-06 19:02:19 +0000109
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110 lldb::ByteOrder GetByteOrder() const override;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000111
Kate Stoneb9c1b512016-09-06 20:57:50 +0000112 bool IsExecutable() const override;
Jim Ingham5aee1622010-08-09 23:31:02 +0000113
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114 uint32_t GetAddressByteSize() const override;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000115
Kate Stoneb9c1b512016-09-06 20:57:50 +0000116 lldb::AddressClass GetAddressClass(lldb::addr_t file_addr) override;
Todd Fialafbd703a2014-09-15 22:33:39 +0000117
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118 lldb_private::Symtab *GetSymtab() override;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000119
Kate Stoneb9c1b512016-09-06 20:57:50 +0000120 bool IsStripped() override;
Greg Clayton3046e662013-07-10 01:23:25 +0000121
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122 void CreateSections(lldb_private::SectionList &unified_section_list) override;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000123
Kate Stoneb9c1b512016-09-06 20:57:50 +0000124 void Dump(lldb_private::Stream *s) override;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000125
Kate Stoneb9c1b512016-09-06 20:57:50 +0000126 bool GetArchitecture(lldb_private::ArchSpec &arch) override;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000127
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128 bool GetUUID(lldb_private::UUID *uuid) override;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130 lldb_private::FileSpecList GetDebugSymbolFilePaths() override;
Michael Sartaina7499c92013-07-01 19:45:50 +0000131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000133
Kate Stoneb9c1b512016-09-06 20:57:50 +0000134 lldb_private::Address
135 GetImageInfoAddress(lldb_private::Target *target) override;
Stephen Wilson2ab0a582011-01-15 00:08:44 +0000136
Kate Stoneb9c1b512016-09-06 20:57:50 +0000137 lldb_private::Address GetEntryPointAddress() override;
Ashok Thirumurthi4822d922013-07-11 20:39:00 +0000138
Kate Stoneb9c1b512016-09-06 20:57:50 +0000139 ObjectFile::Type CalculateType() override;
Ashok Thirumurthi4822d922013-07-11 20:39:00 +0000140
Kate Stoneb9c1b512016-09-06 20:57:50 +0000141 ObjectFile::Strata CalculateStrata() override;
Ashok Thirumurthi4822d922013-07-11 20:39:00 +0000142
Pavel Labathe2867bc2017-12-15 14:23:58 +0000143 size_t ReadSectionData(lldb_private::Section *section,
144 lldb::offset_t section_offset, void *dst,
145 size_t dst_len) override;
146
147 size_t ReadSectionData(lldb_private::Section *section,
148 lldb_private::DataExtractor &section_data) override;
149
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150 // Returns number of program headers found in the ELF file.
151 size_t GetProgramHeaderCount();
152
153 // Returns the program header with the given index.
154 const elf::ELFProgramHeader *GetProgramHeaderByIndex(lldb::user_id_t id);
155
156 // Returns segment data for the given index.
157 lldb_private::DataExtractor GetSegmentDataByIndex(lldb::user_id_t id);
158
Pavel Labath4d35d6b2017-05-02 10:17:30 +0000159 llvm::StringRef
Kate Stoneb9c1b512016-09-06 20:57:50 +0000160 StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override;
Pavel Labathc6ae7ea2015-03-04 10:25:22 +0000161
Ed Masted13f6912017-10-02 14:35:07 +0000162 void RelocateSection(lldb_private::Section *section) override;
163
Pavel Labath16064d32018-03-20 11:56:24 +0000164protected:
165
166 std::vector<LoadableData>
167 GetLoadableData(lldb_private::Target &target) override;
168
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000169private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000170 ObjectFileELF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
171 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
172 lldb::offset_t offset, lldb::offset_t length);
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000173
Kate Stoneb9c1b512016-09-06 20:57:50 +0000174 ObjectFileELF(const lldb::ModuleSP &module_sp,
175 lldb::DataBufferSP &header_data_sp,
176 const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
Andrew MacPherson17220c12014-03-05 10:12:43 +0000177
Kate Stoneb9c1b512016-09-06 20:57:50 +0000178 typedef std::vector<elf::ELFProgramHeader> ProgramHeaderColl;
179 typedef ProgramHeaderColl::iterator ProgramHeaderCollIter;
180 typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181
Kate Stoneb9c1b512016-09-06 20:57:50 +0000182 struct ELFSectionHeaderInfo : public elf::ELFSectionHeader {
183 lldb_private::ConstString section_name;
184 };
Eugene Zelenko8157a882015-10-23 16:56:07 +0000185
Kate Stoneb9c1b512016-09-06 20:57:50 +0000186 typedef std::vector<ELFSectionHeaderInfo> SectionHeaderColl;
187 typedef SectionHeaderColl::iterator SectionHeaderCollIter;
188 typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189
Kate Stoneb9c1b512016-09-06 20:57:50 +0000190 typedef std::vector<elf::ELFDynamic> DynamicSymbolColl;
191 typedef DynamicSymbolColl::iterator DynamicSymbolCollIter;
192 typedef DynamicSymbolColl::const_iterator DynamicSymbolCollConstIter;
Stephen Wilson499b40e2011-03-30 16:07:05 +0000193
Kate Stoneb9c1b512016-09-06 20:57:50 +0000194 typedef std::map<lldb::addr_t, lldb::AddressClass>
195 FileAddressToAddressClassMap;
Tamas Berghammer83544cf2015-04-07 10:43:50 +0000196
Kate Stoneb9c1b512016-09-06 20:57:50 +0000197 /// Version of this reader common to all plugins based on this class.
198 static const uint32_t m_plugin_version = 1;
199 static const uint32_t g_core_uuid_magic;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000200
Kate Stoneb9c1b512016-09-06 20:57:50 +0000201 /// ELF file header.
202 elf::ELFHeader m_header;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000203
Kate Stoneb9c1b512016-09-06 20:57:50 +0000204 /// ELF build ID.
205 lldb_private::UUID m_uuid;
Michael Sartainc836ae72013-05-23 20:57:03 +0000206
Kate Stoneb9c1b512016-09-06 20:57:50 +0000207 /// ELF .gnu_debuglink file and crc data if available.
208 std::string m_gnu_debuglink_file;
209 uint32_t m_gnu_debuglink_crc;
Michael Sartaina7499c92013-07-01 19:45:50 +0000210
Kate Stoneb9c1b512016-09-06 20:57:50 +0000211 /// Collection of program headers.
212 ProgramHeaderColl m_program_headers;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000213
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214 /// Collection of section headers.
215 SectionHeaderColl m_section_headers;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000216
Kate Stoneb9c1b512016-09-06 20:57:50 +0000217 /// Collection of symbols from the dynamic table.
218 DynamicSymbolColl m_dynamic_symbols;
Stephen Wilson499b40e2011-03-30 16:07:05 +0000219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220 /// List of file specifications corresponding to the modules (shared
221 /// libraries) on which this object file depends.
222 mutable std::unique_ptr<lldb_private::FileSpecList> m_filespec_ap;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000223
Kate Stoneb9c1b512016-09-06 20:57:50 +0000224 /// Cached value of the entry point for this module.
225 lldb_private::Address m_entry_point_address;
Stephen Wilson499b40e2011-03-30 16:07:05 +0000226
Kate Stoneb9c1b512016-09-06 20:57:50 +0000227 /// The architecture detected from parsing elf file contents.
228 lldb_private::ArchSpec m_arch_spec;
Todd Fialab91de782014-06-27 16:52:49 +0000229
Kate Stoneb9c1b512016-09-06 20:57:50 +0000230 /// The address class for each symbol in the elf file
231 FileAddressToAddressClassMap m_address_class_map;
Tamas Berghammer83544cf2015-04-07 10:43:50 +0000232
Kate Stoneb9c1b512016-09-06 20:57:50 +0000233 /// Returns a 1 based index of the given section header.
234 size_t SectionIndex(const SectionHeaderCollIter &I);
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000235
Kate Stoneb9c1b512016-09-06 20:57:50 +0000236 /// Returns a 1 based index of the given section header.
237 size_t SectionIndex(const SectionHeaderCollConstIter &I) const;
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000238
Kate Stoneb9c1b512016-09-06 20:57:50 +0000239 // Parses the ELF program headers.
240 static size_t GetProgramHeaderInfo(ProgramHeaderColl &program_headers,
Pavel Labathdf1a0d12017-06-20 08:11:47 +0000241 lldb_private::DataExtractor &object_data,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000242 const elf::ELFHeader &header);
Todd Fiala4339f3a2014-03-25 19:29:09 +0000243
Kate Stoneb9c1b512016-09-06 20:57:50 +0000244 // Finds PT_NOTE segments and calculates their crc sum.
245 static uint32_t
246 CalculateELFNotesSegmentsCRC32(const ProgramHeaderColl &program_headers,
247 lldb_private::DataExtractor &data);
Todd Fiala4339f3a2014-03-25 19:29:09 +0000248
Kate Stoneb9c1b512016-09-06 20:57:50 +0000249 /// Parses all section headers present in this object file and populates
250 /// m_program_headers. This method will compute the header list only once.
251 /// Returns the number of headers parsed.
252 size_t ParseProgramHeaders();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253
Kate Stoneb9c1b512016-09-06 20:57:50 +0000254 /// Parses all section headers present in this object file and populates
255 /// m_section_headers. This method will compute the header list only once.
256 /// Returns the number of headers parsed.
257 size_t ParseSectionHeaders();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258
Kate Stoneb9c1b512016-09-06 20:57:50 +0000259 static void ParseARMAttributes(lldb_private::DataExtractor &data,
260 uint64_t length,
261 lldb_private::ArchSpec &arch_spec);
Saleem Abdulrasoold2d15042016-04-23 16:00:15 +0000262
Adrian Prantld8f460e2018-05-02 16:55:16 +0000263 /// Parses the elf section headers and returns the uuid, debug link name,
264 /// crc, archspec.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000265 static size_t GetSectionHeaderInfo(SectionHeaderColl &section_headers,
Pavel Labathdf1a0d12017-06-20 08:11:47 +0000266 lldb_private::DataExtractor &object_data,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 const elf::ELFHeader &header,
268 lldb_private::UUID &uuid,
269 std::string &gnu_debuglink_file,
270 uint32_t &gnu_debuglink_crc,
271 lldb_private::ArchSpec &arch_spec);
Michael Sartaina7499c92013-07-01 19:45:50 +0000272
Kate Stoneb9c1b512016-09-06 20:57:50 +0000273 /// Scans the dynamic section and locates all dependent modules (shared
274 /// libraries) populating m_filespec_ap. This method will compute the
275 /// dependent module list only once. Returns the number of dependent
276 /// modules parsed.
277 size_t ParseDependentModules();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278
Kate Stoneb9c1b512016-09-06 20:57:50 +0000279 /// Parses the dynamic symbol table and populates m_dynamic_symbols. The
280 /// vector retains the order as found in the object file. Returns the
281 /// number of dynamic symbols parsed.
282 size_t ParseDynamicSymbols();
Stephen Wilson499b40e2011-03-30 16:07:05 +0000283
Kate Stoneb9c1b512016-09-06 20:57:50 +0000284 /// Populates m_symtab_ap will all non-dynamic linker symbols. This method
285 /// will parse the symbols only once. Returns the number of symbols parsed.
286 unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table,
287 lldb::user_id_t start_id,
288 lldb_private::Section *symtab);
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000289
Kate Stoneb9c1b512016-09-06 20:57:50 +0000290 /// Helper routine for ParseSymbolTable().
291 unsigned ParseSymbols(lldb_private::Symtab *symbol_table,
292 lldb::user_id_t start_id,
293 lldb_private::SectionList *section_list,
294 const size_t num_symbols,
295 const lldb_private::DataExtractor &symtab_data,
296 const lldb_private::DataExtractor &strtab_data);
Michael Sartaina7499c92013-07-01 19:45:50 +0000297
Kate Stoneb9c1b512016-09-06 20:57:50 +0000298 /// Scans the relocation entries and adds a set of artificial symbols to the
299 /// given symbol table for each PLT slot. Returns the number of symbols
300 /// added.
301 unsigned ParseTrampolineSymbols(lldb_private::Symtab *symbol_table,
302 lldb::user_id_t start_id,
303 const ELFSectionHeaderInfo *rela_hdr,
304 lldb::user_id_t section_id);
Stephen Wilson499b40e2011-03-30 16:07:05 +0000305
Kate Stoneb9c1b512016-09-06 20:57:50 +0000306 void ParseUnwindSymbols(lldb_private::Symtab *symbol_table,
307 lldb_private::DWARFCallFrameInfo *eh_frame);
Tamas Berghammer6b63b142016-02-18 11:12:18 +0000308
Kate Stoneb9c1b512016-09-06 20:57:50 +0000309 /// Relocates debug sections
310 unsigned RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr,
Ed Masted13f6912017-10-02 14:35:07 +0000311 lldb::user_id_t rel_id,
312 lldb_private::Symtab *thetab);
Andrew MacPherson17220c12014-03-05 10:12:43 +0000313
Ed Masted13f6912017-10-02 14:35:07 +0000314 unsigned ApplyRelocations(lldb_private::Symtab *symtab,
315 const elf::ELFHeader *hdr,
316 const elf::ELFSectionHeader *rel_hdr,
317 const elf::ELFSectionHeader *symtab_hdr,
318 const elf::ELFSectionHeader *debug_hdr,
319 lldb_private::DataExtractor &rel_data,
320 lldb_private::DataExtractor &symtab_data,
321 lldb_private::DataExtractor &debug_data,
322 lldb_private::Section *rel_section);
Andrew MacPherson17220c12014-03-05 10:12:43 +0000323
Kate Stoneb9c1b512016-09-06 20:57:50 +0000324 /// Loads the section name string table into m_shstr_data. Returns the
325 /// number of bytes constituting the table.
326 size_t GetSectionHeaderStringTable();
Andrew MacPherson17220c12014-03-05 10:12:43 +0000327
Kate Stoneb9c1b512016-09-06 20:57:50 +0000328 /// Utility method for looking up a section given its name. Returns the
329 /// index of the corresponding section or zero if no section with the given
330 /// name can be found (note that section indices are always 1 based, and so
331 /// section index 0 is never valid).
332 lldb::user_id_t GetSectionIndexByName(const char *name);
Andrew MacPherson17220c12014-03-05 10:12:43 +0000333
Kate Stoneb9c1b512016-09-06 20:57:50 +0000334 // Returns the ID of the first section that has the given type.
335 lldb::user_id_t GetSectionIndexByType(unsigned type);
Andrew MacPherson17220c12014-03-05 10:12:43 +0000336
Kate Stoneb9c1b512016-09-06 20:57:50 +0000337 /// Returns the section header with the given id or NULL.
338 const ELFSectionHeaderInfo *GetSectionHeaderByIndex(lldb::user_id_t id);
Stephen Wilson499b40e2011-03-30 16:07:05 +0000339
Kate Stoneb9c1b512016-09-06 20:57:50 +0000340 /// @name ELF header dump routines
341 //@{
342 static void DumpELFHeader(lldb_private::Stream *s,
343 const elf::ELFHeader &header);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 static void DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s,
346 unsigned char ei_data);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347
Kate Stoneb9c1b512016-09-06 20:57:50 +0000348 static void DumpELFHeader_e_type(lldb_private::Stream *s,
349 elf::elf_half e_type);
350 //@}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351
Kate Stoneb9c1b512016-09-06 20:57:50 +0000352 /// @name ELF program header dump routines
353 //@{
354 void DumpELFProgramHeaders(lldb_private::Stream *s);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355
Kate Stoneb9c1b512016-09-06 20:57:50 +0000356 static void DumpELFProgramHeader(lldb_private::Stream *s,
357 const elf::ELFProgramHeader &ph);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359 static void DumpELFProgramHeader_p_type(lldb_private::Stream *s,
360 elf::elf_word p_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361
Kate Stoneb9c1b512016-09-06 20:57:50 +0000362 static void DumpELFProgramHeader_p_flags(lldb_private::Stream *s,
363 elf::elf_word p_flags);
364 //@}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365
Kate Stoneb9c1b512016-09-06 20:57:50 +0000366 /// @name ELF section header dump routines
367 //@{
368 void DumpELFSectionHeaders(lldb_private::Stream *s);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000369
Kate Stoneb9c1b512016-09-06 20:57:50 +0000370 static void DumpELFSectionHeader(lldb_private::Stream *s,
371 const ELFSectionHeaderInfo &sh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373 static void DumpELFSectionHeader_sh_type(lldb_private::Stream *s,
374 elf::elf_word sh_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375
Kate Stoneb9c1b512016-09-06 20:57:50 +0000376 static void DumpELFSectionHeader_sh_flags(lldb_private::Stream *s,
377 elf::elf_xword sh_flags);
378 //@}
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000379
Kate Stoneb9c1b512016-09-06 20:57:50 +0000380 /// ELF dependent module dump routine.
381 void DumpDependentModules(lldb_private::Stream *s);
Stephen Wilsonf325ba92010-07-13 23:07:23 +0000382
Kate Stoneb9c1b512016-09-06 20:57:50 +0000383 const elf::ELFDynamic *FindDynamicSymbol(unsigned tag);
Todd Fialab91de782014-06-27 16:52:49 +0000384
Kate Stoneb9c1b512016-09-06 20:57:50 +0000385 unsigned PLTRelocationType();
Ravitheja Addepally15f89c42016-01-19 12:55:21 +0000386
Zachary Turner97206d52017-05-12 04:51:55 +0000387 static lldb_private::Status
Kate Stoneb9c1b512016-09-06 20:57:50 +0000388 RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
389 lldb_private::ArchSpec &arch_spec,
390 lldb_private::UUID &uuid);
Pavel Labath16064d32018-03-20 11:56:24 +0000391
392 bool AnySegmentHasPhysicalAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393};
394
Eugene Zelenko8157a882015-10-23 16:56:07 +0000395#endif // liblldb_ObjectFileELF_h_