mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 00:24:26 +00:00
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
This commit is contained in:
@ -33,6 +33,15 @@
|
||||
namespace llvm {
|
||||
namespace object {
|
||||
|
||||
// Subclasses of ELFObjectFile may need this for template instantiation
|
||||
inline std::pair<unsigned char, unsigned char>
|
||||
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<support::endianness target_endianness>
|
||||
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;
|
||||
@ -1092,6 +1105,43 @@ error_code ELFObjectFile<target_endianness, is64Bits>
|
||||
return object_error::success;
|
||||
}
|
||||
|
||||
template<support::endianness target_endianness, bool is64Bits>
|
||||
error_code ELFObjectFile<target_endianness, is64Bits>
|
||||
::isSectionRequiredForExecution(DataRefImpl Sec,
|
||||
bool &Result) const {
|
||||
const Elf_Shdr *sec = reinterpret_cast<const Elf_Shdr *>(Sec.p);
|
||||
if (sec->sh_flags & ELF::SHF_ALLOC)
|
||||
Result = true;
|
||||
else
|
||||
Result = false;
|
||||
return object_error::success;
|
||||
}
|
||||
|
||||
template<support::endianness target_endianness, bool is64Bits>
|
||||
error_code ELFObjectFile<target_endianness, is64Bits>
|
||||
::isSectionVirtual(DataRefImpl Sec,
|
||||
bool &Result) const {
|
||||
const Elf_Shdr *sec = reinterpret_cast<const Elf_Shdr *>(Sec.p);
|
||||
if (sec->sh_type == ELF::SHT_NOBITS)
|
||||
Result = true;
|
||||
else
|
||||
Result = false;
|
||||
return object_error::success;
|
||||
}
|
||||
|
||||
template<support::endianness target_endianness, bool is64Bits>
|
||||
error_code ELFObjectFile<target_endianness, is64Bits>::isSectionZeroInit(DataRefImpl Sec,
|
||||
bool &Result) const {
|
||||
const Elf_Shdr *sec = reinterpret_cast<const Elf_Shdr *>(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<support::endianness target_endianness, bool is64Bits>
|
||||
error_code ELFObjectFile<target_endianness, is64Bits>
|
||||
::sectionContainsSymbol(DataRefImpl Sec,
|
||||
|
Reference in New Issue
Block a user