From 3fd9b8422328a60664a5c631ec9519b58017fcbc Mon Sep 17 00:00:00 2001 From: Danil Malyshev Date: Tue, 10 Apr 2012 01:54:44 +0000 Subject: Add a constructor for DataRefImpl and remove excess initialization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154371 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 14 +------------- include/llvm/Object/ObjectFile.h | 19 +++++++------------ 2 files changed, 8 insertions(+), 25 deletions(-) (limited to 'include/llvm/Object') diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index d33f317..cb013b9 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -290,9 +290,7 @@ class DynRefImpl { const OwningType *OwningObject; public: - DynRefImpl() : OwningObject(NULL) { - std::memset(&DynPimpl, 0, sizeof(DynPimpl)); - } + DynRefImpl() : OwningObject(NULL) { } DynRefImpl(DataRefImpl DynP, const OwningType *Owner); @@ -1108,7 +1106,6 @@ template relocation_iterator ELFObjectFile ::getSectionRelBegin(DataRefImpl Sec) const { DataRefImpl RelData; - memset(&RelData, 0, sizeof(RelData)); const Elf_Shdr *sec = reinterpret_cast(Sec.p); typename RelocMap_t::const_iterator ittr = SectionRelocMap.find(sec); if (sec != 0 && ittr != SectionRelocMap.end()) { @@ -1123,7 +1120,6 @@ template relocation_iterator ELFObjectFile ::getSectionRelEnd(DataRefImpl Sec) const { DataRefImpl RelData; - memset(&RelData, 0, sizeof(RelData)); const Elf_Shdr *sec = reinterpret_cast(Sec.p); typename RelocMap_t::const_iterator ittr = SectionRelocMap.find(sec); if (sec != 0 && ittr != SectionRelocMap.end()) { @@ -1626,7 +1622,6 @@ template symbol_iterator ELFObjectFile ::begin_symbols() const { DataRefImpl SymbolData; - memset(&SymbolData, 0, sizeof(SymbolData)); if (SymbolTableSections.size() <= 1) { SymbolData.d.a = std::numeric_limits::max(); SymbolData.d.b = std::numeric_limits::max(); @@ -1641,7 +1636,6 @@ template symbol_iterator ELFObjectFile ::end_symbols() const { DataRefImpl SymbolData; - memset(&SymbolData, 0, sizeof(SymbolData)); SymbolData.d.a = std::numeric_limits::max(); SymbolData.d.b = std::numeric_limits::max(); return symbol_iterator(SymbolRef(SymbolData, this)); @@ -1651,7 +1645,6 @@ template symbol_iterator ELFObjectFile ::begin_dynamic_symbols() const { DataRefImpl SymbolData; - memset(&SymbolData, 0, sizeof(SymbolData)); if (SymbolTableSections[0] == NULL) { SymbolData.d.a = std::numeric_limits::max(); SymbolData.d.b = std::numeric_limits::max(); @@ -1666,7 +1659,6 @@ template symbol_iterator ELFObjectFile ::end_dynamic_symbols() const { DataRefImpl SymbolData; - memset(&SymbolData, 0, sizeof(SymbolData)); SymbolData.d.a = std::numeric_limits::max(); SymbolData.d.b = std::numeric_limits::max(); return symbol_iterator(SymbolRef(SymbolData, this)); @@ -1676,7 +1668,6 @@ template section_iterator ELFObjectFile ::begin_sections() const { DataRefImpl ret; - memset(&ret, 0, sizeof(DataRefImpl)); ret.p = reinterpret_cast(base() + Header->e_shoff); return section_iterator(SectionRef(ret, this)); } @@ -1685,7 +1676,6 @@ template section_iterator ELFObjectFile ::end_sections() const { DataRefImpl ret; - memset(&ret, 0, sizeof(DataRefImpl)); ret.p = reinterpret_cast(base() + Header->e_shoff + (Header->e_shentsize*getNumSections())); @@ -1696,7 +1686,6 @@ template typename ELFObjectFile::dyn_iterator ELFObjectFile::begin_dynamic_table() const { DataRefImpl DynData; - memset(&DynData, 0, sizeof(DynData)); if (dot_dynamic_sec == NULL || dot_dynamic_sec->sh_size == 0) { DynData.d.a = std::numeric_limits::max(); } else { @@ -1710,7 +1699,6 @@ typename ELFObjectFile::dyn_iterator ELFObjectFile ::end_dynamic_table() const { DataRefImpl DynData; - memset(&DynData, 0, sizeof(DynData)); DynData.d.a = std::numeric_limits::max(); return dyn_iterator(DynRef(DynData, this)); } diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 09eb7fc..d8cda81 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -38,6 +38,9 @@ union DataRefImpl { uint32_t a, b; } d; uintptr_t p; + DataRefImpl() { + std::memset(this, 0, sizeof(DataRefImpl)); + } }; template @@ -94,9 +97,7 @@ class RelocationRef { const ObjectFile *OwningObject; public: - RelocationRef() : OwningObject(NULL) { - std::memset(&RelocationPimpl, 0, sizeof(RelocationPimpl)); - } + RelocationRef() : OwningObject(NULL) { } RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner); @@ -136,9 +137,7 @@ class SectionRef { const ObjectFile *OwningObject; public: - SectionRef() : OwningObject(NULL) { - std::memset(&SectionPimpl, 0, sizeof(SectionPimpl)); - } + SectionRef() : OwningObject(NULL) { } SectionRef(DataRefImpl SectionP, const ObjectFile *Owner); @@ -175,9 +174,7 @@ class SymbolRef { const ObjectFile *OwningObject; public: - SymbolRef() : OwningObject(NULL) { - std::memset(&SymbolPimpl, 0, sizeof(SymbolPimpl)); - } + SymbolRef() : OwningObject(NULL) { } enum Type { ST_Unknown, // Type not specified @@ -236,9 +233,7 @@ class LibraryRef { const ObjectFile *OwningObject; public: - LibraryRef() : OwningObject(NULL) { - std::memset(&LibraryPimpl, 0, sizeof(LibraryPimpl)); - } + LibraryRef() : OwningObject(NULL) { } LibraryRef(DataRefImpl LibraryP, const ObjectFile *Owner); -- cgit v1.1 From c68dda815e64fb2fb463318d1eaa304e22199d50 Mon Sep 17 00:00:00 2001 From: Preston Gurd Date: Thu, 12 Apr 2012 20:13:57 +0000 Subject: This patch improves the MCJIT runtime dynamic loader by adding new handling of zero-initialized sections, virtual sections and common symbols and preventing the loading of sections which are not required for execution such as debug information. Patch by Andy Kaylor! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154610 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/COFF.h | 4 ++++ include/llvm/Object/ELF.h | 50 ++++++++++++++++++++++++++++++++++++++++ include/llvm/Object/MachO.h | 4 ++++ include/llvm/Object/ObjectFile.h | 28 ++++++++++++++++++++++ 4 files changed, 86 insertions(+) (limited to 'include/llvm/Object') diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 91971bb..68b5ca1 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -126,6 +126,10 @@ protected: virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const; virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const; virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const; + virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const; + virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const; + virtual error_code isSectionRequiredForExecution(DataRefImpl Sec, + bool &Res) const; virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb, bool &Result) const; virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const; diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index cb013b9..455a67b 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -33,6 +33,15 @@ namespace llvm { namespace object { +// Subclasses of ELFObjectFile may need this for template instantiation +inline std::pair +getElfArchType(MemoryBuffer *Object) { + if (Object->getBufferSize() < ELF::EI_NIDENT) + return std::make_pair((uint8_t)ELF::ELFCLASSNONE,(uint8_t)ELF::ELFDATANONE); + return std::make_pair( (uint8_t)Object->getBufferStart()[ELF::EI_CLASS] + , (uint8_t)Object->getBufferStart()[ELF::EI_DATA]); +} + // Templates to choose Elf_Addr and Elf_Off depending on is64Bits. template struct ELFDataTypeTypedefHelperCommon { @@ -540,6 +549,10 @@ protected: virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const; virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const; virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const; + virtual error_code isSectionRequiredForExecution(DataRefImpl Sec, + bool &Res) const; + virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const; + virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const; virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb, bool &Result) const; virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const; @@ -1094,6 +1107,43 @@ error_code ELFObjectFile template error_code ELFObjectFile + ::isSectionRequiredForExecution(DataRefImpl Sec, + bool &Result) const { + const Elf_Shdr *sec = reinterpret_cast(Sec.p); + if (sec->sh_flags & ELF::SHF_ALLOC) + Result = true; + else + Result = false; + return object_error::success; +} + +template +error_code ELFObjectFile + ::isSectionVirtual(DataRefImpl Sec, + bool &Result) const { + const Elf_Shdr *sec = reinterpret_cast(Sec.p); + if (sec->sh_type == ELF::SHT_NOBITS) + Result = true; + else + Result = false; + return object_error::success; +} + +template +error_code ELFObjectFile::isSectionZeroInit(DataRefImpl Sec, + bool &Result) const { + const Elf_Shdr *sec = reinterpret_cast(Sec.p); + // For ELF, all zero-init sections are virtual (that is, they occupy no space + // in the object image) and vice versa. + if (sec->sh_flags & ELF::SHT_NOBITS) + Result = true; + else + Result = false; + return object_error::success; +} + +template +error_code ELFObjectFile ::sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb, bool &Result) const { diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 1e409b2..0b73f94 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -72,6 +72,10 @@ protected: virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const; virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const; virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const; + virtual error_code isSectionRequiredForExecution(DataRefImpl Sec, + bool &Res) const; + virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const; + virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const; virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S, bool &Result) const; virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const; diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index d8cda81..4dd7fb5 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -158,11 +158,16 @@ public: error_code isText(bool &Result) const; error_code isData(bool &Result) const; error_code isBSS(bool &Result) const; + error_code isRequiredForExecution(bool &Result) const; + error_code isVirtual(bool &Result) const; + error_code isZeroInit(bool &Result) const; error_code containsSymbol(SymbolRef S, bool &Result) const; relocation_iterator begin_relocations() const; relocation_iterator end_relocations() const; + + DataRefImpl getRawDataRefImpl() const; }; typedef content_iterator section_iterator; @@ -217,6 +222,9 @@ public: /// Get symbol flags (bitwise OR of SymbolRef::Flags) error_code getFlags(uint32_t &Result) const; + /// @brief Return true for common symbols such as uninitialized globals + error_code isCommon(bool &Result) const; + /// @brief Get section this symbol is defined in reference to. Result is /// end_sections() if it is undefined or is an absolute symbol. error_code getSection(section_iterator &Result) const; @@ -299,6 +307,11 @@ protected: virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const = 0; virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const = 0; virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const = 0; + virtual error_code isSectionRequiredForExecution(DataRefImpl Sec, + bool &Res) const = 0; + // A section is 'virtual' if its contents aren't present in the object image. + virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const = 0; + virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const = 0; virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb, bool &Result) const = 0; virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const = 0; @@ -481,6 +494,18 @@ inline error_code SectionRef::isBSS(bool &Result) const { return OwningObject->isSectionBSS(SectionPimpl, Result); } +inline error_code SectionRef::isRequiredForExecution(bool &Result) const { + return OwningObject->isSectionRequiredForExecution(SectionPimpl, Result); +} + +inline error_code SectionRef::isVirtual(bool &Result) const { + return OwningObject->isSectionVirtual(SectionPimpl, Result); +} + +inline error_code SectionRef::isZeroInit(bool &Result) const { + return OwningObject->isSectionZeroInit(SectionPimpl, Result); +} + inline error_code SectionRef::containsSymbol(SymbolRef S, bool &Result) const { return OwningObject->sectionContainsSymbol(SectionPimpl, S.SymbolPimpl, Result); @@ -494,6 +519,9 @@ inline relocation_iterator SectionRef::end_relocations() const { return OwningObject->getSectionRelEnd(SectionPimpl); } +inline DataRefImpl SectionRef::getRawDataRefImpl() const { + return SectionPimpl; +} /// RelocationRef inline RelocationRef::RelocationRef(DataRefImpl RelocationP, -- cgit v1.1 From bdc3adc6c10378e16035467aae866eead51f1d54 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 13 Apr 2012 05:58:19 +0000 Subject: Remove getElfArchType from ELF.h. It's only used in ELFObjectFile.cpp and there's already a copy there. ELF.h was hiding the one there and causing an unused function warning. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154657 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 9 --------- 1 file changed, 9 deletions(-) (limited to 'include/llvm/Object') diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 455a67b..0828985 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -33,15 +33,6 @@ namespace llvm { namespace object { -// Subclasses of ELFObjectFile may need this for template instantiation -inline std::pair -getElfArchType(MemoryBuffer *Object) { - if (Object->getBufferSize() < ELF::EI_NIDENT) - return std::make_pair((uint8_t)ELF::ELFCLASSNONE,(uint8_t)ELF::ELFDATANONE); - return std::make_pair( (uint8_t)Object->getBufferStart()[ELF::EI_CLASS] - , (uint8_t)Object->getBufferStart()[ELF::EI_DATA]); -} - // Templates to choose Elf_Addr and Elf_Off depending on is64Bits. template struct ELFDataTypeTypedefHelperCommon { -- cgit v1.1 From 689ff9c00f4f3dcf3491778bcdbda79e19e2285d Mon Sep 17 00:00:00 2001 From: Preston Gurd Date: Mon, 16 Apr 2012 22:12:58 +0000 Subject: Implement GDB integration for source level debugging of code JITed using the MCJIT execution engine. The GDB JIT debugging integration support works by registering a loaded object image with a pre-defined function that GDB will monitor if GDB is attached. GDB integration support is implemented for ELF only at this time. This integration requires GDB version 7.0 or newer. Patch by Andy Kaylor! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154868 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ELF.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/llvm/Object') diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 0828985..e493f5b 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -33,6 +33,15 @@ namespace llvm { namespace object { +// Subclasses of ELFObjectFile may need this for template instantiation +inline std::pair +getElfArchType(MemoryBuffer *Object) { + if (Object->getBufferSize() < ELF::EI_NIDENT) + return std::make_pair((uint8_t)ELF::ELFCLASSNONE,(uint8_t)ELF::ELFDATANONE); + return std::make_pair( (uint8_t)Object->getBufferStart()[ELF::EI_CLASS] + , (uint8_t)Object->getBufferStart()[ELF::EI_DATA]); +} + // Templates to choose Elf_Addr and Elf_Off depending on is64Bits. template struct ELFDataTypeTypedefHelperCommon { -- cgit v1.1