Add BinaryRef binary_size() method.

This avoids making assumptions about the data representation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183349 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sean Silva 2013-06-05 23:32:27 +00:00
parent 2b1068952a
commit 63958fba58
2 changed files with 10 additions and 4 deletions

View File

@ -43,6 +43,13 @@ public:
assert(isBinary); assert(isBinary);
return Data; return Data;
} }
/// \brief The number of bytes that are represented by this BinaryRef.
/// This is the number of bytes that writeAsBinary() will write.
ArrayRef<uint8_t>::size_type binary_size() const {
if (!isBinary)
return Data.size() / 2;
return Data.size();
}
bool operator==(const BinaryRef &Ref) { bool operator==(const BinaryRef &Ref) {
// Special case for default constructed BinaryRef. // Special case for default constructed BinaryRef.
if (Ref.Data.empty() && Data.empty()) if (Ref.Data.empty() && Data.empty())

View File

@ -129,9 +129,8 @@ static bool layoutCOFF(COFFParser &CP) {
for (std::vector<COFFYAML::Section>::iterator i = CP.Obj.Sections.begin(), for (std::vector<COFFYAML::Section>::iterator i = CP.Obj.Sections.begin(),
e = CP.Obj.Sections.end(); e = CP.Obj.Sections.end();
i != e; ++i) { i != e; ++i) {
StringRef SecData = i->SectionData.getHex(); if (i->SectionData.binary_size() > 0) {
if (!SecData.empty()) { i->Header.SizeOfRawData = i->SectionData.binary_size();
i->Header.SizeOfRawData = SecData.size()/2;
i->Header.PointerToRawData = CurrentSectionDataOffset; i->Header.PointerToRawData = CurrentSectionDataOffset;
CurrentSectionDataOffset += i->Header.SizeOfRawData; CurrentSectionDataOffset += i->Header.SizeOfRawData;
if (!i->Relocations.empty()) { if (!i->Relocations.empty()) {
@ -154,7 +153,7 @@ static bool layoutCOFF(COFFParser &CP) {
for (std::vector<COFFYAML::Symbol>::iterator i = CP.Obj.Symbols.begin(), for (std::vector<COFFYAML::Symbol>::iterator i = CP.Obj.Symbols.begin(),
e = CP.Obj.Symbols.end(); e = CP.Obj.Symbols.end();
i != e; ++i) { i != e; ++i) {
unsigned AuxBytes = i->AuxiliaryData.getHex().size() / 2; unsigned AuxBytes = i->AuxiliaryData.binary_size();
if (AuxBytes % COFF::SymbolSize != 0) { if (AuxBytes % COFF::SymbolSize != 0) {
errs() << "AuxiliaryData size not a multiple of symbol size!\n"; errs() << "AuxiliaryData size not a multiple of symbol size!\n";
return false; return false;