summaryrefslogtreecommitdiff
path: root/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-11-27 10:37:47 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-11-27 10:37:47 +0000
commit790552c20fbd8daa77d343419f0f6ec4e7fa1457 (patch)
tree548fd44cb22491e6367bc1c611bfab583b7730d1 /lib/Object/MachOObjectFile.cpp
parent7096692fd9ab5753f17500a27d400d1544b6d3d8 (diff)
downloadllvm-790552c20fbd8daa77d343419f0f6ec4e7fa1457.tar.gz
llvm-790552c20fbd8daa77d343419f0f6ec4e7fa1457.tar.bz2
llvm-790552c20fbd8daa77d343419f0f6ec4e7fa1457.tar.xz
Revert r145180 as it is causing test failures on all the bots.
Original commit message: Fixed ObjectFile functions: - getSymbolOffset() renamed as getSymbolFileOffset() - getSymbolFileOffset(), getSymbolAddress(), getRelocationAddress() returns same result for ELFObjectFile, MachOObjectFile and COFFObjectFile. - added getRelocationOffset() - fixed MachOObjectFile::getSymbolSize() - fixed MachOObjectFile::getSymbolSection() - fixed MachOObjectFile::getSymbolOffset() for symbols without section data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145182 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Object/MachOObjectFile.cpp')
-rw-r--r--lib/Object/MachOObjectFile.cpp83
1 files changed, 11 insertions, 72 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp
index bb4f6a275b..65ce5f882a 100644
--- a/lib/Object/MachOObjectFile.cpp
+++ b/lib/Object/MachOObjectFile.cpp
@@ -125,27 +125,23 @@ error_code MachOObjectFile::getSymbolName(DataRefImpl DRI,
return object_error::success;
}
-error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl DRI,
- uint64_t &Result) const {
+error_code MachOObjectFile::getSymbolOffset(DataRefImpl DRI,
+ uint64_t &Result) const {
+ uint64_t SectionOffset;
+ uint8_t SectionIndex;
if (MachOObj->is64Bit()) {
InMemoryStruct<macho::Symbol64TableEntry> Entry;
getSymbol64TableEntry(DRI, Entry);
Result = Entry->Value;
- if (Entry->SectionIndex) {
- InMemoryStruct<macho::Section64> Section;
- getSection64(Sections[Entry->SectionIndex-1], Section);
- Result += Section->Offset - Section->Address;
- }
+ SectionIndex = Entry->SectionIndex;
} else {
InMemoryStruct<macho::SymbolTableEntry> Entry;
getSymbolTableEntry(DRI, Entry);
Result = Entry->Value;
- if (Entry->SectionIndex) {
- InMemoryStruct<macho::Section> Section;
- getSection(Sections[Entry->SectionIndex-1], Section);
- Result += Section->Offset - Section->Address;
- }
+ SectionIndex = Entry->SectionIndex;
}
+ getSectionAddress(Sections[SectionIndex-1], SectionOffset);
+ Result -= SectionOffset;
return object_error::success;
}
@@ -166,50 +162,7 @@ error_code MachOObjectFile::getSymbolAddress(DataRefImpl DRI,
error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI,
uint64_t &Result) const {
- uint32_t LoadCommandCount = MachOObj->getHeader().NumLoadCommands;
- uint64_t BeginOffset;
- uint64_t EndOffset = 0;
- uint8_t SectionIndex;
- if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(DRI, Entry);
- BeginOffset = Entry->Value;
- SectionIndex = Entry->SectionIndex;
- if (!SectionIndex) {
- Result = UnknownAddressOrSize;
- return object_error::success;
- }
- DRI.d.b++;
- moveToNextSymbol(DRI);
- if (DRI.d.a < LoadCommandCount) {
- getSymbol64TableEntry(DRI, Entry);
- if (Entry->SectionIndex == SectionIndex)
- EndOffset += Entry->Value;
- }
- } else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(DRI, Entry);
- BeginOffset = Entry->Value;
- SectionIndex = Entry->SectionIndex;
- if (!SectionIndex) {
- Result = UnknownAddressOrSize;
- return object_error::success;
- }
- DRI.d.b++;
- moveToNextSymbol(DRI);
- if (DRI.d.a < LoadCommandCount) {
- getSymbolTableEntry(DRI, Entry);
- if (Entry->SectionIndex == SectionIndex)
- EndOffset += Entry->Value;
- }
- }
- if (!EndOffset) {
- uint64_t Size;
- getSectionSize(Sections[SectionIndex-1], Size);
- getSectionAddress(Sections[SectionIndex-1], EndOffset);
- EndOffset += Size;
- }
- Result = EndOffset - BeginOffset;
+ Result = UnknownAddressOrSize;
return object_error::success;
}
@@ -322,7 +275,7 @@ error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb,
if (index == 0)
Res = end_sections();
else
- Res = section_iterator(SectionRef(Sections[index-1], this));
+ Res = section_iterator(SectionRef(Sections[index], this));
return object_error::success;
}
@@ -661,7 +614,7 @@ error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
bool isScattered = (Arch != Triple::x86_64) &&
(RE->Word0 & macho::RF_Scattered);
uint64_t RelAddr = 0;
- if (isScattered)
+ if (isScattered)
RelAddr = RE->Word0 & 0xFFFFFF;
else
RelAddr = RE->Word0;
@@ -669,20 +622,6 @@ error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
Res = reinterpret_cast<uintptr_t>(sectAddress + RelAddr);
return object_error::success;
}
-error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel,
- uint64_t &Res) const {
- InMemoryStruct<macho::RelocationEntry> RE;
- getRelocation(Rel, RE);
-
- unsigned Arch = getArch();
- bool isScattered = (Arch != Triple::x86_64) &&
- (RE->Word0 & macho::RF_Scattered);
- if (isScattered)
- Res = RE->Word0 & 0xFFFFFF;
- else
- Res = RE->Word0;
- return object_error::success;
-}
error_code MachOObjectFile::getRelocationSymbol(DataRefImpl Rel,
SymbolRef &Res) const {
InMemoryStruct<macho::RelocationEntry> RE;