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