Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 1 | //===-- ObjectFileELF.h --------------------------------------- -*- C++ -*-===// |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2 | // |
| 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 | |
| 13 | #include <stdint.h> |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "lldb/lldb-private.h" |
Greg Clayton | 53239f0 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 17 | #include "lldb/Host/FileSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/ObjectFile.h" |
Michael Sartain | c836ae7 | 2013-05-23 20:57:03 +0000 | [diff] [blame] | 19 | #include "lldb/Core/UUID.h" |
Todd Fiala | b91de78 | 2014-06-27 16:52:49 +0000 | [diff] [blame] | 20 | #include "lldb/Core/ArchSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 22 | #include "ELFHeader.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
Ed Maste | c113ff8 | 2013-12-02 17:49:13 +0000 | [diff] [blame] | 24 | struct ELFNote |
| 25 | { |
| 26 | elf::elf_word n_namesz; |
| 27 | elf::elf_word n_descsz; |
| 28 | elf::elf_word n_type; |
| 29 | |
| 30 | std::string n_name; |
| 31 | |
| 32 | ELFNote() : n_namesz(0), n_descsz(0), n_type(0) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | /// 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 |
| 49 | Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); |
| 50 | }; |
| 51 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 52 | //------------------------------------------------------------------------------ |
| 53 | /// @class ObjectFileELF |
| 54 | /// @brief Generic ELF object file reader. |
| 55 | /// |
| 56 | /// This class provides a generic ELF (32/64 bit) reader plugin implementing the |
| 57 | /// ObjectFile protocol. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | class ObjectFileELF : |
| 59 | public lldb_private::ObjectFile |
| 60 | { |
| 61 | public: |
| 62 | //------------------------------------------------------------------ |
| 63 | // Static Functions |
| 64 | //------------------------------------------------------------------ |
| 65 | static void |
| 66 | Initialize(); |
| 67 | |
| 68 | static void |
| 69 | Terminate(); |
| 70 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 71 | static lldb_private::ConstString |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | GetPluginNameStatic(); |
| 73 | |
| 74 | static const char * |
| 75 | GetPluginDescriptionStatic(); |
| 76 | |
| 77 | static lldb_private::ObjectFile * |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 78 | CreateInstance(const lldb::ModuleSP &module_sp, |
Greg Clayton | 5ce9c56 | 2013-02-06 17:22:03 +0000 | [diff] [blame] | 79 | lldb::DataBufferSP& data_sp, |
| 80 | lldb::offset_t data_offset, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | const lldb_private::FileSpec* file, |
Greg Clayton | 5ce9c56 | 2013-02-06 17:22:03 +0000 | [diff] [blame] | 82 | lldb::offset_t file_offset, |
| 83 | lldb::offset_t length); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 85 | static lldb_private::ObjectFile * |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 86 | CreateMemoryInstance (const lldb::ModuleSP &module_sp, |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 87 | lldb::DataBufferSP& data_sp, |
| 88 | const lldb::ProcessSP &process_sp, |
| 89 | lldb::addr_t header_addr); |
| 90 | |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 91 | static size_t |
| 92 | GetModuleSpecifications (const lldb_private::FileSpec& file, |
| 93 | lldb::DataBufferSP& data_sp, |
| 94 | lldb::offset_t data_offset, |
| 95 | lldb::offset_t file_offset, |
| 96 | lldb::offset_t length, |
| 97 | lldb_private::ModuleSpecList &specs); |
Michael Sartain | 9f0013d | 2013-05-17 00:20:21 +0000 | [diff] [blame] | 98 | |
| 99 | static bool |
| 100 | MagicBytesMatch (lldb::DataBufferSP& data_sp, |
| 101 | lldb::addr_t offset, |
| 102 | lldb::addr_t length); |
| 103 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | //------------------------------------------------------------------ |
| 105 | // PluginInterface protocol |
| 106 | //------------------------------------------------------------------ |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 107 | virtual lldb_private::ConstString |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | GetPluginName(); |
| 109 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | virtual uint32_t |
| 111 | GetPluginVersion(); |
| 112 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 113 | //------------------------------------------------------------------ |
| 114 | // ObjectFile Protocol. |
| 115 | //------------------------------------------------------------------ |
| 116 | virtual |
| 117 | ~ObjectFileELF(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 119 | virtual bool |
| 120 | ParseHeader(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | |
Steve Pucci | 9e02dac | 2014-02-06 19:02:19 +0000 | [diff] [blame] | 122 | virtual bool |
Greg Clayton | 751caf6 | 2014-02-07 22:54:47 +0000 | [diff] [blame] | 123 | SetLoadAddress (lldb_private::Target &target, |
| 124 | lldb::addr_t value, |
| 125 | bool value_is_offset); |
Steve Pucci | 9e02dac | 2014-02-06 19:02:19 +0000 | [diff] [blame] | 126 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 127 | virtual lldb::ByteOrder |
| 128 | GetByteOrder() const; |
| 129 | |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 130 | virtual bool |
| 131 | IsExecutable () const; |
| 132 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 133 | virtual uint32_t |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 134 | GetAddressByteSize() const; |
| 135 | |
Todd Fiala | fbd703a | 2014-09-15 22:33:39 +0000 | [diff] [blame] | 136 | virtual lldb::AddressClass |
| 137 | GetAddressClass (lldb::addr_t file_addr); |
| 138 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 139 | virtual lldb_private::Symtab * |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 140 | GetSymtab(); |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 141 | |
Ashok Thirumurthi | 35729bb | 2013-09-24 15:34:13 +0000 | [diff] [blame] | 142 | virtual lldb_private::Symbol * |
| 143 | ResolveSymbolForAddress(const lldb_private::Address& so_addr, bool verify_unique); |
| 144 | |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 145 | virtual bool |
| 146 | IsStripped (); |
| 147 | |
| 148 | virtual void |
| 149 | CreateSections (lldb_private::SectionList &unified_section_list); |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 150 | |
| 151 | virtual void |
| 152 | Dump(lldb_private::Stream *s); |
| 153 | |
| 154 | virtual bool |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 155 | GetArchitecture (lldb_private::ArchSpec &arch); |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 156 | |
| 157 | virtual bool |
| 158 | GetUUID(lldb_private::UUID* uuid); |
| 159 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 160 | virtual lldb_private::FileSpecList |
| 161 | GetDebugSymbolFilePaths(); |
| 162 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 163 | virtual uint32_t |
| 164 | GetDependentModules(lldb_private::FileSpecList& files); |
| 165 | |
Stephen Wilson | 2ab0a58 | 2011-01-15 00:08:44 +0000 | [diff] [blame] | 166 | virtual lldb_private::Address |
Ed Maste | 5480365 | 2013-10-11 17:39:07 +0000 | [diff] [blame] | 167 | GetImageInfoAddress(lldb_private::Target *target); |
Jim Ingham | 672e6f5 | 2011-03-07 23:44:08 +0000 | [diff] [blame] | 168 | |
| 169 | virtual lldb_private::Address |
| 170 | GetEntryPointAddress (); |
Greg Clayton | 9e00b6a65 | 2011-07-09 00:41:34 +0000 | [diff] [blame] | 171 | |
| 172 | virtual ObjectFile::Type |
| 173 | CalculateType(); |
| 174 | |
| 175 | virtual ObjectFile::Strata |
| 176 | CalculateStrata(); |
Stephen Wilson | 2ab0a58 | 2011-01-15 00:08:44 +0000 | [diff] [blame] | 177 | |
Ashok Thirumurthi | 4822d92 | 2013-07-11 20:39:00 +0000 | [diff] [blame] | 178 | // Returns number of program headers found in the ELF file. |
| 179 | size_t |
| 180 | GetProgramHeaderCount(); |
| 181 | |
| 182 | // Returns the program header with the given index. |
| 183 | const elf::ELFProgramHeader * |
| 184 | GetProgramHeaderByIndex(lldb::user_id_t id); |
| 185 | |
| 186 | // Returns segment data for the given index. |
| 187 | lldb_private::DataExtractor |
| 188 | GetSegmentDataByIndex(lldb::user_id_t id); |
| 189 | |
Pavel Labath | c6ae7ea | 2015-03-04 10:25:22 +0000 | [diff] [blame] | 190 | std::string |
| 191 | StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override; |
| 192 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 193 | private: |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 194 | ObjectFileELF(const lldb::ModuleSP &module_sp, |
Greg Clayton | 5ce9c56 | 2013-02-06 17:22:03 +0000 | [diff] [blame] | 195 | lldb::DataBufferSP& data_sp, |
| 196 | lldb::offset_t data_offset, |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 197 | const lldb_private::FileSpec* file, |
Greg Clayton | 5ce9c56 | 2013-02-06 17:22:03 +0000 | [diff] [blame] | 198 | lldb::offset_t offset, |
| 199 | lldb::offset_t length); |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 200 | |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 201 | ObjectFileELF (const lldb::ModuleSP &module_sp, |
| 202 | lldb::DataBufferSP& data_sp, |
| 203 | const lldb::ProcessSP &process_sp, |
| 204 | lldb::addr_t header_addr); |
| 205 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 206 | typedef std::vector<elf::ELFProgramHeader> ProgramHeaderColl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | typedef ProgramHeaderColl::iterator ProgramHeaderCollIter; |
| 208 | typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter; |
| 209 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 210 | struct ELFSectionHeaderInfo : public elf::ELFSectionHeader |
| 211 | { |
| 212 | lldb_private::ConstString section_name; |
| 213 | }; |
| 214 | typedef std::vector<ELFSectionHeaderInfo> SectionHeaderColl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 215 | typedef SectionHeaderColl::iterator SectionHeaderCollIter; |
| 216 | typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter; |
| 217 | |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 218 | typedef std::vector<elf::ELFDynamic> DynamicSymbolColl; |
| 219 | typedef DynamicSymbolColl::iterator DynamicSymbolCollIter; |
| 220 | typedef DynamicSymbolColl::const_iterator DynamicSymbolCollConstIter; |
| 221 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 222 | /// Version of this reader common to all plugins based on this class. |
| 223 | static const uint32_t m_plugin_version = 1; |
Todd Fiala | 4339f3a | 2014-03-25 19:29:09 +0000 | [diff] [blame] | 224 | static const uint32_t g_core_uuid_magic; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 225 | |
| 226 | /// ELF file header. |
| 227 | elf::ELFHeader m_header; |
| 228 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 229 | /// ELF build ID. |
Michael Sartain | c836ae7 | 2013-05-23 20:57:03 +0000 | [diff] [blame] | 230 | lldb_private::UUID m_uuid; |
| 231 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 232 | /// ELF .gnu_debuglink file and crc data if available. |
| 233 | std::string m_gnu_debuglink_file; |
| 234 | uint32_t m_gnu_debuglink_crc; |
| 235 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 236 | /// Collection of program headers. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 237 | ProgramHeaderColl m_program_headers; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 238 | |
| 239 | /// Collection of section headers. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 240 | SectionHeaderColl m_section_headers; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 241 | |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 242 | /// Collection of symbols from the dynamic table. |
| 243 | DynamicSymbolColl m_dynamic_symbols; |
| 244 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 245 | /// List of file specifications corresponding to the modules (shared |
| 246 | /// libraries) on which this object file depends. |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 247 | mutable std::unique_ptr<lldb_private::FileSpecList> m_filespec_ap; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 248 | |
Jim Ingham | 672e6f5 | 2011-03-07 23:44:08 +0000 | [diff] [blame] | 249 | /// Cached value of the entry point for this module. |
| 250 | lldb_private::Address m_entry_point_address; |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 251 | |
Todd Fiala | b91de78 | 2014-06-27 16:52:49 +0000 | [diff] [blame] | 252 | /// The architecture detected from parsing elf file contents. |
| 253 | lldb_private::ArchSpec m_arch_spec; |
| 254 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 255 | /// Returns a 1 based index of the given section header. |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 256 | size_t |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 257 | SectionIndex(const SectionHeaderCollIter &I); |
| 258 | |
| 259 | /// Returns a 1 based index of the given section header. |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 260 | size_t |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 261 | SectionIndex(const SectionHeaderCollConstIter &I) const; |
| 262 | |
Todd Fiala | 4339f3a | 2014-03-25 19:29:09 +0000 | [diff] [blame] | 263 | // Parses the ELF program headers. |
| 264 | static size_t |
| 265 | GetProgramHeaderInfo(ProgramHeaderColl &program_headers, |
| 266 | lldb_private::DataExtractor &data, |
| 267 | const elf::ELFHeader &header); |
| 268 | |
| 269 | // Finds PT_NOTE segments and calculates their crc sum. |
| 270 | static uint32_t |
| 271 | CalculateELFNotesSegmentsCRC32(const ProgramHeaderColl& program_headers, |
| 272 | lldb_private::DataExtractor &data); |
| 273 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 274 | /// Parses all section headers present in this object file and populates |
| 275 | /// m_program_headers. This method will compute the header list only once. |
| 276 | /// Returns the number of headers parsed. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 277 | size_t |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 278 | ParseProgramHeaders(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 279 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 280 | /// Parses all section headers present in this object file and populates |
| 281 | /// m_section_headers. This method will compute the header list only once. |
| 282 | /// Returns the number of headers parsed. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | size_t |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 284 | ParseSectionHeaders(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | |
Todd Fiala | b91de78 | 2014-06-27 16:52:49 +0000 | [diff] [blame] | 286 | /// Parses the elf section headers and returns the uuid, debug link name, crc, archspec. |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 287 | static size_t |
| 288 | GetSectionHeaderInfo(SectionHeaderColl §ion_headers, |
| 289 | lldb_private::DataExtractor &data, |
| 290 | const elf::ELFHeader &header, |
| 291 | lldb_private::UUID &uuid, |
| 292 | std::string &gnu_debuglink_file, |
Todd Fiala | b91de78 | 2014-06-27 16:52:49 +0000 | [diff] [blame] | 293 | uint32_t &gnu_debuglink_crc, |
| 294 | lldb_private::ArchSpec &arch_spec); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 295 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 296 | /// Scans the dynamic section and locates all dependent modules (shared |
Greg Clayton | 710dd5a | 2011-01-08 20:28:42 +0000 | [diff] [blame] | 297 | /// libraries) populating m_filespec_ap. This method will compute the |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 298 | /// dependent module list only once. Returns the number of dependent |
| 299 | /// modules parsed. |
| 300 | size_t |
| 301 | ParseDependentModules(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 302 | |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 303 | /// Parses the dynamic symbol table and populates m_dynamic_symbols. The |
| 304 | /// vector retains the order as found in the object file. Returns the |
| 305 | /// number of dynamic symbols parsed. |
| 306 | size_t |
| 307 | ParseDynamicSymbols(); |
| 308 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 309 | /// Populates m_symtab_ap will all non-dynamic linker symbols. This method |
| 310 | /// will parse the symbols only once. Returns the number of symbols parsed. |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 311 | unsigned |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 312 | ParseSymbolTable(lldb_private::Symtab *symbol_table, |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 313 | lldb::user_id_t start_id, |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 314 | lldb_private::Section *symtab); |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 315 | |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 316 | /// Helper routine for ParseSymbolTable(). |
| 317 | unsigned |
| 318 | ParseSymbols(lldb_private::Symtab *symbol_table, |
| 319 | lldb::user_id_t start_id, |
| 320 | lldb_private::SectionList *section_list, |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 321 | const size_t num_symbols, |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 322 | const lldb_private::DataExtractor &symtab_data, |
| 323 | const lldb_private::DataExtractor &strtab_data); |
| 324 | |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 325 | /// Scans the relocation entries and adds a set of artificial symbols to the |
| 326 | /// given symbol table for each PLT slot. Returns the number of symbols |
| 327 | /// added. |
| 328 | unsigned |
| 329 | ParseTrampolineSymbols(lldb_private::Symtab *symbol_table, |
| 330 | lldb::user_id_t start_id, |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 331 | const ELFSectionHeaderInfo *rela_hdr, |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 332 | lldb::user_id_t section_id); |
| 333 | |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 334 | /// Relocates debug sections |
| 335 | unsigned |
| 336 | RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr, lldb::user_id_t rel_id); |
| 337 | |
| 338 | unsigned |
| 339 | RelocateSection(lldb_private::Symtab* symtab, const elf::ELFHeader *hdr, const elf::ELFSectionHeader *rel_hdr, |
| 340 | const elf::ELFSectionHeader *symtab_hdr, const elf::ELFSectionHeader *debug_hdr, |
| 341 | lldb_private::DataExtractor &rel_data, lldb_private::DataExtractor &symtab_data, |
| 342 | lldb_private::DataExtractor &debug_data, lldb_private::Section* rel_section); |
| 343 | |
| 344 | /// Loads the section name string table into m_shstr_data. Returns the |
| 345 | /// number of bytes constituting the table. |
| 346 | size_t |
| 347 | GetSectionHeaderStringTable(); |
| 348 | |
| 349 | /// Utility method for looking up a section given its name. Returns the |
| 350 | /// index of the corresponding section or zero if no section with the given |
| 351 | /// name can be found (note that section indices are always 1 based, and so |
| 352 | /// section index 0 is never valid). |
| 353 | lldb::user_id_t |
| 354 | GetSectionIndexByName(const char *name); |
| 355 | |
| 356 | // Returns the ID of the first section that has the given type. |
| 357 | lldb::user_id_t |
| 358 | GetSectionIndexByType(unsigned type); |
| 359 | |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 360 | /// Returns the section header with the given id or NULL. |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 361 | const ELFSectionHeaderInfo * |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 362 | GetSectionHeaderByIndex(lldb::user_id_t id); |
| 363 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 364 | /// @name ELF header dump routines |
| 365 | //@{ |
| 366 | static void |
| 367 | DumpELFHeader(lldb_private::Stream *s, const elf::ELFHeader& header); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 368 | |
| 369 | static void |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 370 | DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s, |
| 371 | unsigned char ei_data); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 372 | |
| 373 | static void |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 374 | DumpELFHeader_e_type(lldb_private::Stream *s, elf::elf_half e_type); |
| 375 | //@} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 377 | /// @name ELF program header dump routines |
| 378 | //@{ |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 379 | void |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 380 | DumpELFProgramHeaders(lldb_private::Stream *s); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 381 | |
| 382 | static void |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 383 | DumpELFProgramHeader(lldb_private::Stream *s, |
| 384 | const elf::ELFProgramHeader &ph); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 385 | |
| 386 | static void |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 387 | DumpELFProgramHeader_p_type(lldb_private::Stream *s, elf::elf_word p_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 388 | |
| 389 | static void |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 390 | DumpELFProgramHeader_p_flags(lldb_private::Stream *s, |
| 391 | elf::elf_word p_flags); |
| 392 | //@} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 394 | /// @name ELF section header dump routines |
| 395 | //@{ |
| 396 | void |
| 397 | DumpELFSectionHeaders(lldb_private::Stream *s); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 399 | static void |
| 400 | DumpELFSectionHeader(lldb_private::Stream *s, |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 401 | const ELFSectionHeaderInfo& sh); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 402 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 403 | static void |
| 404 | DumpELFSectionHeader_sh_type(lldb_private::Stream *s, |
| 405 | elf::elf_word sh_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 406 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 407 | static void |
| 408 | DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 409 | elf::elf_xword sh_flags); |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 410 | //@} |
| 411 | |
| 412 | /// ELF dependent module dump routine. |
| 413 | void |
| 414 | DumpDependentModules(lldb_private::Stream *s); |
| 415 | |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 416 | const elf::ELFDynamic * |
| 417 | FindDynamicSymbol(unsigned tag); |
| 418 | |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 419 | unsigned |
| 420 | PLTRelocationType(); |
Todd Fiala | b91de78 | 2014-06-27 16:52:49 +0000 | [diff] [blame] | 421 | |
| 422 | static lldb_private::Error |
| 423 | RefineModuleDetailsFromNote (lldb_private::DataExtractor &data, lldb_private::ArchSpec &arch_spec, lldb_private::UUID &uuid); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | }; |
| 425 | |
| 426 | #endif // #ifndef liblldb_ObjectFileELF_h_ |