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 | |
Eugene Zelenko | 8157a88 | 2015-10-23 16:56:07 +0000 | [diff] [blame] | 13 | // C Includes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include <stdint.h> |
Eugene Zelenko | 8157a88 | 2015-10-23 16:56:07 +0000 | [diff] [blame] | 15 | |
| 16 | // C++ Includes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/ObjectFile.h" |
Pavel Labath | 5f19b90 | 2017-11-13 16:16:33 +0000 | [diff] [blame] | 20 | #include "lldb/Utility/ArchSpec.h" |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 21 | #include "lldb/Utility/FileSpec.h" |
| 22 | #include "lldb/Utility/UUID.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | #include "lldb/lldb-private.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 25 | #include "ELFHeader.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | struct ELFNote { |
| 28 | elf::elf_word n_namesz; |
| 29 | elf::elf_word n_descsz; |
| 30 | elf::elf_word n_type; |
Ed Maste | c113ff8 | 2013-12-02 17:49:13 +0000 | [diff] [blame] | 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | std::string n_name; |
Ed Maste | c113ff8 | 2013-12-02 17:49:13 +0000 | [diff] [blame] | 33 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | ELFNote() : n_namesz(0), n_descsz(0), n_type(0) {} |
Ed Maste | c113ff8 | 2013-12-02 17:49:13 +0000 | [diff] [blame] | 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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 Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset); |
Greg Clayton | b704b69 | 2015-10-28 18:04:38 +0000 | [diff] [blame] | 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | size_t GetByteSize() const { |
| 51 | return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4); |
| 52 | } |
Ed Maste | c113ff8 | 2013-12-02 17:49:13 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 55 | //------------------------------------------------------------------------------ |
| 56 | /// @class ObjectFileELF |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 57 | /// Generic ELF object file reader. |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 58 | /// |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 59 | /// This class provides a generic ELF (32/64 bit) reader plugin implementing |
| 60 | /// the ObjectFile protocol. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | class ObjectFileELF : public lldb_private::ObjectFile { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | ~ObjectFileELF() override; |
Eugene Zelenko | 8157a88 | 2015-10-23 16:56:07 +0000 | [diff] [blame] | 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | //------------------------------------------------------------------ |
| 66 | // Static Functions |
| 67 | //------------------------------------------------------------------ |
| 68 | static void Initialize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | static void Terminate(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | static lldb_private::ConstString GetPluginNameStatic(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | static const char *GetPluginDescriptionStatic(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | 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 Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | 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 Sartain | 9f0013d | 2013-05-17 00:20:21 +0000 | [diff] [blame] | 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, |
| 93 | lldb::addr_t length); |
Michael Sartain | 9f0013d | 2013-05-17 00:20:21 +0000 | [diff] [blame] | 94 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | //------------------------------------------------------------------ |
| 96 | // PluginInterface protocol |
| 97 | //------------------------------------------------------------------ |
| 98 | lldb_private::ConstString GetPluginName() override; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | uint32_t GetPluginVersion() override; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 101 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | //------------------------------------------------------------------ |
| 103 | // ObjectFile Protocol. |
| 104 | //------------------------------------------------------------------ |
| 105 | bool ParseHeader() override; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, |
| 108 | bool value_is_offset) override; |
Steve Pucci | 9e02dac | 2014-02-06 19:02:19 +0000 | [diff] [blame] | 109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | lldb::ByteOrder GetByteOrder() const override; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | bool IsExecutable() const override; |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 113 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | uint32_t GetAddressByteSize() const override; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 115 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | lldb::AddressClass GetAddressClass(lldb::addr_t file_addr) override; |
Todd Fiala | fbd703a | 2014-09-15 22:33:39 +0000 | [diff] [blame] | 117 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | lldb_private::Symtab *GetSymtab() override; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 119 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 120 | bool IsStripped() override; |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 121 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 122 | void CreateSections(lldb_private::SectionList &unified_section_list) override; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | void Dump(lldb_private::Stream *s) override; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 125 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | bool GetArchitecture(lldb_private::ArchSpec &arch) override; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 127 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 128 | bool GetUUID(lldb_private::UUID *uuid) override; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 129 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | lldb_private::FileSpecList GetDebugSymbolFilePaths() override; |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | uint32_t GetDependentModules(lldb_private::FileSpecList &files) override; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 133 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 134 | lldb_private::Address |
| 135 | GetImageInfoAddress(lldb_private::Target *target) override; |
Stephen Wilson | 2ab0a58 | 2011-01-15 00:08:44 +0000 | [diff] [blame] | 136 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | lldb_private::Address GetEntryPointAddress() override; |
Ashok Thirumurthi | 4822d92 | 2013-07-11 20:39:00 +0000 | [diff] [blame] | 138 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | ObjectFile::Type CalculateType() override; |
Ashok Thirumurthi | 4822d92 | 2013-07-11 20:39:00 +0000 | [diff] [blame] | 140 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | ObjectFile::Strata CalculateStrata() override; |
Ashok Thirumurthi | 4822d92 | 2013-07-11 20:39:00 +0000 | [diff] [blame] | 142 | |
Pavel Labath | e2867bc | 2017-12-15 14:23:58 +0000 | [diff] [blame] | 143 | 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 §ion_data) override; |
| 149 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | // 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 Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 159 | llvm::StringRef |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override; |
Pavel Labath | c6ae7ea | 2015-03-04 10:25:22 +0000 | [diff] [blame] | 161 | |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 162 | void RelocateSection(lldb_private::Section *section) override; |
| 163 | |
Pavel Labath | 16064d3 | 2018-03-20 11:56:24 +0000 | [diff] [blame] | 164 | protected: |
| 165 | |
| 166 | std::vector<LoadableData> |
| 167 | GetLoadableData(lldb_private::Target &target) override; |
| 168 | |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 169 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 170 | 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 Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 173 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | ObjectFileELF(const lldb::ModuleSP &module_sp, |
| 175 | lldb::DataBufferSP &header_data_sp, |
| 176 | const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 177 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | typedef std::vector<elf::ELFProgramHeader> ProgramHeaderColl; |
| 179 | typedef ProgramHeaderColl::iterator ProgramHeaderCollIter; |
| 180 | typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 181 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 182 | struct ELFSectionHeaderInfo : public elf::ELFSectionHeader { |
| 183 | lldb_private::ConstString section_name; |
| 184 | }; |
Eugene Zelenko | 8157a88 | 2015-10-23 16:56:07 +0000 | [diff] [blame] | 185 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | typedef std::vector<ELFSectionHeaderInfo> SectionHeaderColl; |
| 187 | typedef SectionHeaderColl::iterator SectionHeaderCollIter; |
| 188 | typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | typedef std::vector<elf::ELFDynamic> DynamicSymbolColl; |
| 191 | typedef DynamicSymbolColl::iterator DynamicSymbolCollIter; |
| 192 | typedef DynamicSymbolColl::const_iterator DynamicSymbolCollConstIter; |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 193 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 194 | typedef std::map<lldb::addr_t, lldb::AddressClass> |
| 195 | FileAddressToAddressClassMap; |
Tamas Berghammer | 83544cf | 2015-04-07 10:43:50 +0000 | [diff] [blame] | 196 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 197 | /// 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 Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 200 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | /// ELF file header. |
| 202 | elf::ELFHeader m_header; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 203 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | /// ELF build ID. |
| 205 | lldb_private::UUID m_uuid; |
Michael Sartain | c836ae7 | 2013-05-23 20:57:03 +0000 | [diff] [blame] | 206 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 207 | /// ELF .gnu_debuglink file and crc data if available. |
| 208 | std::string m_gnu_debuglink_file; |
| 209 | uint32_t m_gnu_debuglink_crc; |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 210 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 211 | /// Collection of program headers. |
| 212 | ProgramHeaderColl m_program_headers; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 213 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | /// Collection of section headers. |
| 215 | SectionHeaderColl m_section_headers; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 216 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 217 | /// Collection of symbols from the dynamic table. |
| 218 | DynamicSymbolColl m_dynamic_symbols; |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | /// 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 Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 223 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 224 | /// Cached value of the entry point for this module. |
| 225 | lldb_private::Address m_entry_point_address; |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 226 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 227 | /// The architecture detected from parsing elf file contents. |
| 228 | lldb_private::ArchSpec m_arch_spec; |
Todd Fiala | b91de78 | 2014-06-27 16:52:49 +0000 | [diff] [blame] | 229 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 230 | /// The address class for each symbol in the elf file |
| 231 | FileAddressToAddressClassMap m_address_class_map; |
Tamas Berghammer | 83544cf | 2015-04-07 10:43:50 +0000 | [diff] [blame] | 232 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 233 | /// Returns a 1 based index of the given section header. |
| 234 | size_t SectionIndex(const SectionHeaderCollIter &I); |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 235 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 236 | /// Returns a 1 based index of the given section header. |
| 237 | size_t SectionIndex(const SectionHeaderCollConstIter &I) const; |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 238 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 239 | // Parses the ELF program headers. |
| 240 | static size_t GetProgramHeaderInfo(ProgramHeaderColl &program_headers, |
Pavel Labath | df1a0d1 | 2017-06-20 08:11:47 +0000 | [diff] [blame] | 241 | lldb_private::DataExtractor &object_data, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 242 | const elf::ELFHeader &header); |
Todd Fiala | 4339f3a | 2014-03-25 19:29:09 +0000 | [diff] [blame] | 243 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 244 | // 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 Fiala | 4339f3a | 2014-03-25 19:29:09 +0000 | [diff] [blame] | 248 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 249 | /// 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 253 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 254 | /// 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 258 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 259 | static void ParseARMAttributes(lldb_private::DataExtractor &data, |
| 260 | uint64_t length, |
| 261 | lldb_private::ArchSpec &arch_spec); |
Saleem Abdulrasool | d2d1504 | 2016-04-23 16:00:15 +0000 | [diff] [blame] | 262 | |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 263 | /// Parses the elf section headers and returns the uuid, debug link name, |
| 264 | /// crc, archspec. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 265 | static size_t GetSectionHeaderInfo(SectionHeaderColl §ion_headers, |
Pavel Labath | df1a0d1 | 2017-06-20 08:11:47 +0000 | [diff] [blame] | 266 | lldb_private::DataExtractor &object_data, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 267 | 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 Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 272 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 273 | /// 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 278 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 279 | /// 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 Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 283 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 284 | /// 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 Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 289 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 290 | /// 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 Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 297 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 298 | /// 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 Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 305 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 306 | void ParseUnwindSymbols(lldb_private::Symtab *symbol_table, |
| 307 | lldb_private::DWARFCallFrameInfo *eh_frame); |
Tamas Berghammer | 6b63b14 | 2016-02-18 11:12:18 +0000 | [diff] [blame] | 308 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 309 | /// Relocates debug sections |
| 310 | unsigned RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr, |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 311 | lldb::user_id_t rel_id, |
| 312 | lldb_private::Symtab *thetab); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 313 | |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 314 | 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 MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 323 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 324 | /// Loads the section name string table into m_shstr_data. Returns the |
| 325 | /// number of bytes constituting the table. |
| 326 | size_t GetSectionHeaderStringTable(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 327 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 328 | /// 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 MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 333 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 334 | // Returns the ID of the first section that has the given type. |
| 335 | lldb::user_id_t GetSectionIndexByType(unsigned type); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 336 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 337 | /// Returns the section header with the given id or NULL. |
| 338 | const ELFSectionHeaderInfo *GetSectionHeaderByIndex(lldb::user_id_t id); |
Stephen Wilson | 499b40e | 2011-03-30 16:07:05 +0000 | [diff] [blame] | 339 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 340 | /// @name ELF header dump routines |
| 341 | //@{ |
| 342 | static void DumpELFHeader(lldb_private::Stream *s, |
| 343 | const elf::ELFHeader &header); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 344 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 345 | static void DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s, |
| 346 | unsigned char ei_data); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 347 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 348 | static void DumpELFHeader_e_type(lldb_private::Stream *s, |
| 349 | elf::elf_half e_type); |
| 350 | //@} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 352 | /// @name ELF program header dump routines |
| 353 | //@{ |
| 354 | void DumpELFProgramHeaders(lldb_private::Stream *s); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 355 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 356 | static void DumpELFProgramHeader(lldb_private::Stream *s, |
| 357 | const elf::ELFProgramHeader &ph); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 359 | static void DumpELFProgramHeader_p_type(lldb_private::Stream *s, |
| 360 | elf::elf_word p_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 361 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 362 | static void DumpELFProgramHeader_p_flags(lldb_private::Stream *s, |
| 363 | elf::elf_word p_flags); |
| 364 | //@} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 366 | /// @name ELF section header dump routines |
| 367 | //@{ |
| 368 | void DumpELFSectionHeaders(lldb_private::Stream *s); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 369 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 370 | static void DumpELFSectionHeader(lldb_private::Stream *s, |
| 371 | const ELFSectionHeaderInfo &sh); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 372 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 373 | static void DumpELFSectionHeader_sh_type(lldb_private::Stream *s, |
| 374 | elf::elf_word sh_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 375 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 376 | static void DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, |
| 377 | elf::elf_xword sh_flags); |
| 378 | //@} |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 379 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 380 | /// ELF dependent module dump routine. |
| 381 | void DumpDependentModules(lldb_private::Stream *s); |
Stephen Wilson | f325ba9 | 2010-07-13 23:07:23 +0000 | [diff] [blame] | 382 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 383 | const elf::ELFDynamic *FindDynamicSymbol(unsigned tag); |
Todd Fiala | b91de78 | 2014-06-27 16:52:49 +0000 | [diff] [blame] | 384 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 385 | unsigned PLTRelocationType(); |
Ravitheja Addepally | 15f89c4 | 2016-01-19 12:55:21 +0000 | [diff] [blame] | 386 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 387 | static lldb_private::Status |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 388 | RefineModuleDetailsFromNote(lldb_private::DataExtractor &data, |
| 389 | lldb_private::ArchSpec &arch_spec, |
| 390 | lldb_private::UUID &uuid); |
Pavel Labath | 16064d3 | 2018-03-20 11:56:24 +0000 | [diff] [blame] | 391 | |
| 392 | bool AnySegmentHasPhysicalAddress(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | }; |
| 394 | |
Eugene Zelenko | 8157a88 | 2015-10-23 16:56:07 +0000 | [diff] [blame] | 395 | #endif // liblldb_ObjectFileELF_h_ |