aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp26
-rw-r--r--llvm/lib/Object/WindowsMachineFlag.cpp4
2 files changed, 26 insertions, 4 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index e09dc94..c2f4560 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -1978,20 +1978,42 @@ uint64_t MachOObjectFile::getSectionSize(DataRefImpl Sec) const {
return SectSize;
}
-ArrayRef<uint8_t> MachOObjectFile::getSectionContents(uint32_t Offset,
+ArrayRef<uint8_t> MachOObjectFile::getSectionContents(uint64_t Offset,
uint64_t Size) const {
return arrayRefFromStringRef(getData().substr(Offset, Size));
}
Expected<ArrayRef<uint8_t>>
MachOObjectFile::getSectionContents(DataRefImpl Sec) const {
- uint32_t Offset;
+ uint64_t Offset;
uint64_t Size;
if (is64Bit()) {
MachO::section_64 Sect = getSection64(Sec);
Offset = Sect.offset;
Size = Sect.size;
+ // Check for large mach-o files where the section contents might exceed
+ // 4GB. MachO::section_64 objects only have 32 bit file offsets to the
+ // section contents and can overflow in dSYM files. We can track this and
+ // adjust the section offset to be 64 bit safe. If sections overflow then
+ // section ordering is enforced. If sections are not ordered, then an error
+ // will be returned stopping invalid section data from being returned.
+ uint64_t PrevTrueOffset = 0;
+ uint64_t SectOffsetAdjust = 0;
+ for (uint32_t SectIdx = 0; SectIdx < Sec.d.a; ++SectIdx) {
+ MachO::section_64 CurrSect =
+ getStruct<MachO::section_64>(*this, Sections[SectIdx]);
+ uint64_t CurrTrueOffset = (uint64_t)CurrSect.offset + SectOffsetAdjust;
+ if ((SectOffsetAdjust > 0) && (PrevTrueOffset > CurrTrueOffset))
+ return malformedError("section data exceeds 4GB and section file "
+ "offsets are not ordered");
+ const uint64_t EndSectFileOffset =
+ (uint64_t)CurrSect.offset + CurrSect.size;
+ if (EndSectFileOffset > UINT32_MAX)
+ SectOffsetAdjust += EndSectFileOffset & 0xFFFFFFFF00000000ull;
+ PrevTrueOffset = CurrTrueOffset;
+ }
+ Offset += SectOffsetAdjust;
} else {
MachO::section Sect = getSection(Sec);
Offset = Sect.offset;
diff --git a/llvm/lib/Object/WindowsMachineFlag.cpp b/llvm/lib/Object/WindowsMachineFlag.cpp
index caf357e8..14c14f6 100644
--- a/llvm/lib/Object/WindowsMachineFlag.cpp
+++ b/llvm/lib/Object/WindowsMachineFlag.cpp
@@ -23,8 +23,8 @@ using namespace llvm;
COFF::MachineTypes llvm::getMachineType(StringRef S) {
// Flags must be a superset of Microsoft lib.exe /machine flags.
return StringSwitch<COFF::MachineTypes>(S.lower())
- .Cases("x64", "amd64", COFF::IMAGE_FILE_MACHINE_AMD64)
- .Cases("x86", "i386", COFF::IMAGE_FILE_MACHINE_I386)
+ .Cases({"x64", "amd64"}, COFF::IMAGE_FILE_MACHINE_AMD64)
+ .Cases({"x86", "i386"}, COFF::IMAGE_FILE_MACHINE_I386)
.Case("arm", COFF::IMAGE_FILE_MACHINE_ARMNT)
.Case("arm64", COFF::IMAGE_FILE_MACHINE_ARM64)
.Case("arm64ec", COFF::IMAGE_FILE_MACHINE_ARM64EC)