[llvm] r219391 - Object, COFF: Move the VirtualSize/SizeOfRawData logic to getSectionSize
David Majnemer
david.majnemer at gmail.com
Thu Oct 9 01:42:31 PDT 2014
Author: majnemer
Date: Thu Oct 9 03:42:31 2014
New Revision: 219391
URL: http://llvm.org/viewvc/llvm-project?rev=219391&view=rev
Log:
Object, COFF: Move the VirtualSize/SizeOfRawData logic to getSectionSize
While getSectionContents was updated to do the right thing,
getSectionSize wasn't. Move the logic to getSectionSize and leverage it
from getSectionContents.
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/lib/Object/COFFObjectFile.cpp
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=219391&r1=219390&r2=219391&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Thu Oct 9 03:42:31 2014
@@ -655,6 +655,7 @@ public:
}
std::error_code getSectionName(const coff_section *Sec, StringRef &Res) const;
+ uint64_t getSectionSize(const coff_section *Sec) const;
std::error_code getSectionContents(const coff_section *Sec,
ArrayRef<uint8_t> &Res) const;
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=219391&r1=219390&r2=219391&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Thu Oct 9 03:42:31 2014
@@ -271,8 +271,7 @@ uint64_t COFFObjectFile::getSectionAddre
}
uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const {
- const coff_section *Sec = toSec(Ref);
- return Sec->SizeOfRawData;
+ return getSectionSize(toSec(Ref));
}
std::error_code COFFObjectFile::getSectionContents(DataRefImpl Ref,
@@ -866,17 +865,7 @@ std::error_code COFFObjectFile::getSecti
return object_error::success;
}
-std::error_code
-COFFObjectFile::getSectionContents(const coff_section *Sec,
- ArrayRef<uint8_t> &Res) const {
- // PointerToRawData and SizeOfRawData won't make sense for BSS sections,
- // don't do anything interesting for them.
- assert((Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) == 0 &&
- "BSS sections don't have contents!");
- // The only thing that we need to verify is that the contents is contained
- // within the file bounds. We don't need to make sure it doesn't cover other
- // data, as there's nothing that says that is not allowed.
- uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData;
+uint64_t COFFObjectFile::getSectionSize(const coff_section *Sec) const {
// SizeOfRawData and VirtualSize change what they represent depending on
// whether or not we have an executable image.
//
@@ -887,15 +876,31 @@ COFFObjectFile::getSectionContents(const
// actual section size is in VirtualSize. It is possible for VirtualSize to
// be greater than SizeOfRawData; the contents past that point should be
// considered to be zero.
- uint32_t DataSize;
+ uint32_t SectionSize;
if (Sec->VirtualSize)
- DataSize = std::min(Sec->VirtualSize, Sec->SizeOfRawData);
+ SectionSize = std::min(Sec->VirtualSize, Sec->SizeOfRawData);
else
- DataSize = Sec->SizeOfRawData;
- uintptr_t ConEnd = ConStart + DataSize;
+ SectionSize = Sec->SizeOfRawData;
+
+ return SectionSize;
+}
+
+std::error_code
+COFFObjectFile::getSectionContents(const coff_section *Sec,
+ ArrayRef<uint8_t> &Res) const {
+ // PointerToRawData and SizeOfRawData won't make sense for BSS sections,
+ // don't do anything interesting for them.
+ assert((Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) == 0 &&
+ "BSS sections don't have contents!");
+ // The only thing that we need to verify is that the contents is contained
+ // within the file bounds. We don't need to make sure it doesn't cover other
+ // data, as there's nothing that says that is not allowed.
+ uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData;
+ uint32_t SectionSize = getSectionSize(Sec);
+ uintptr_t ConEnd = ConStart + SectionSize;
if (ConEnd > uintptr_t(Data.getBufferEnd()))
return object_error::parse_failed;
- Res = makeArrayRef(reinterpret_cast<const uint8_t *>(ConStart), DataSize);
+ Res = makeArrayRef(reinterpret_cast<const uint8_t *>(ConStart), SectionSize);
return object_error::success;
}
More information about the llvm-commits
mailing list