diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-09-26 22:32:16 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-09-26 22:32:16 +0000 |
| commit | dac39857d6545e32f20f0735a04b934f36b6c1d9 (patch) | |
| tree | a969577804c80a12810628209ad39403b5edd65b | |
| parent | b774a0e75071f4b32e741297b4e017615b01a8a9 (diff) | |
| download | bcm5719-llvm-dac39857d6545e32f20f0735a04b934f36b6c1d9.tar.gz bcm5719-llvm-dac39857d6545e32f20f0735a04b934f36b6c1d9.zip | |
Object: BSS/virtual sections don't have contents
Users of getSectionContents shouldn't try to pass in BSS or virtual
sections. In all instances, this is a bug in the code calling this
routine.
N.B. Some COFF implementations (like CL) will mark their BSS sections as
taking space on disk. This would confuse COFFObjectFile into thinking
the section is larger than the file.
llvm-svn: 218549
| -rw-r--r-- | llvm/lib/DebugInfo/DWARFContext.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/MC/PowerPC/lcomm.s | 1 | ||||
| -rw-r--r-- | llvm/tools/llvm-readobj/COFFDumper.cpp | 3 | ||||
| -rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 2 | ||||
| -rw-r--r-- | llvm/tools/llvm-readobj/MachODumper.cpp | 11 |
6 files changed, 24 insertions, 6 deletions
diff --git a/llvm/lib/DebugInfo/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARFContext.cpp index 1be0691a1d9..62e3b9ccf64 100644 --- a/llvm/lib/DebugInfo/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARFContext.cpp @@ -565,6 +565,15 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile &Obj) for (const SectionRef &Section : Obj.sections()) { StringRef name; Section.getName(name); + // Skip BSS and Virtual sections, they aren't interesting. + bool IsBSS; + Section.isBSS(IsBSS); + if (IsBSS) + continue; + bool IsVirtual; + Section.isVirtual(IsVirtual); + if (IsVirtual) + continue; StringRef data; Section.getContents(data); diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index 7daef06f035..45de4341b3f 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -840,6 +840,10 @@ std::error_code COFFObjectFile::getSectionName(const coff_section *Sec, 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. diff --git a/llvm/test/MC/PowerPC/lcomm.s b/llvm/test/MC/PowerPC/lcomm.s index b6beedea5fd..a84f138479b 100644 --- a/llvm/test/MC/PowerPC/lcomm.s +++ b/llvm/test/MC/PowerPC/lcomm.s @@ -19,4 +19,3 @@ // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 16 // CHECK-NEXT: EntrySize: 0 -// CHECK-NEXT: SectionData ( diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp index 99a374d5a6a..3d71d832f99 100644 --- a/llvm/tools/llvm-readobj/COFFDumper.cpp +++ b/llvm/tools/llvm-readobj/COFFDumper.cpp @@ -635,7 +635,8 @@ void COFFDumper::printSections() { if (Name == ".debug$S" && opts::CodeViewLineTables) printCodeViewLineTables(Sec); - if (opts::SectionData) { + if (opts::SectionData && + !(Section->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)) { StringRef Data; if (error(Sec.getContents(Data))) break; diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 1791f5a3247..6da3318c931 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -604,7 +604,7 @@ void ELFDumper<ELFT>::printSections() { } } - if (opts::SectionData) { + if (opts::SectionData && Section->sh_type != ELF::SHT_NOBITS) { ArrayRef<uint8_t> Data = errorOrDefault(Obj->getSectionContents(Section)); W.printBinaryBlock("SectionData", StringRef((const char *)Data.data(), Data.size())); diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp index 41a78e762fb..2d09282f11f 100644 --- a/llvm/tools/llvm-readobj/MachODumper.cpp +++ b/llvm/tools/llvm-readobj/MachODumper.cpp @@ -266,11 +266,16 @@ void MachODumper::printSections(const MachOObjectFile *Obj) { } if (opts::SectionData) { - StringRef Data; - if (error(Section.getContents(Data))) + bool IsBSS; + if (error(Section.isBSS(IsBSS))) break; + if (!IsBSS) { + StringRef Data; + if (error(Section.getContents(Data))) + break; - W.printBinaryBlock("SectionData", Data); + W.printBinaryBlock("SectionData", Data); + } } } } |

