diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/ObjCopy/COFF')
4 files changed, 18 insertions, 9 deletions
diff --git a/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp b/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp index 782d5b2f70c3..cebcb823e689 100644 --- a/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp +++ b/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp @@ -183,10 +183,18 @@ static Error handleArgs(const CommonConfig &Config, }); if (Config.OnlyKeepDebug) { + const data_directory *DebugDir = + Obj.DataDirectories.size() > DEBUG_DIRECTORY + ? &Obj.DataDirectories[DEBUG_DIRECTORY] + : nullptr; // For --only-keep-debug, we keep all other sections, but remove their // content. The VirtualSize field in the section header is kept intact. - Obj.truncateSections([](const Section &Sec) { + Obj.truncateSections([DebugDir](const Section &Sec) { return !isDebugSection(Sec) && Sec.Name != ".buildid" && + !(DebugDir && DebugDir->Size > 0 && + DebugDir->RelativeVirtualAddress >= Sec.Header.VirtualAddress && + DebugDir->RelativeVirtualAddress < + Sec.Header.VirtualAddress + Sec.Header.SizeOfRawData) && ((Sec.Header.Characteristics & (IMAGE_SCN_CNT_CODE | IMAGE_SCN_CNT_INITIALIZED_DATA)) != 0); }); diff --git a/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFObject.cpp b/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFObject.cpp index 1d27b7eaa891..5fa13391c908 100644 --- a/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFObject.cpp +++ b/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFObject.cpp @@ -8,7 +8,6 @@ #include "COFFObject.h" #include "llvm/ADT/DenseSet.h" -#include <algorithm> namespace llvm { namespace objcopy { diff --git a/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFReader.cpp b/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFReader.cpp index 32aceb805a2a..62a71d41ded5 100644 --- a/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFReader.cpp +++ b/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFReader.cpp @@ -70,8 +70,7 @@ Error COFFReader::readSections(Object &Obj) const { return E; S.setContentsRef(Contents); ArrayRef<coff_relocation> Relocs = COFFObj.getRelocations(Sec); - for (const coff_relocation &R : Relocs) - S.Relocs.push_back(R); + llvm::append_range(S.Relocs, Relocs); if (Expected<StringRef> NameOrErr = COFFObj.getSectionName(Sec)) S.Name = *NameOrErr; else diff --git a/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFWriter.cpp b/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFWriter.cpp index 1f4893592915..350c4aec572c 100644 --- a/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFWriter.cpp +++ b/contrib/llvm-project/llvm/lib/ObjCopy/COFF/COFFWriter.cpp @@ -120,8 +120,11 @@ void COFFWriter::layoutSections() { Expected<size_t> COFFWriter::finalizeStringTable() { for (const auto &S : Obj.getSections()) - if (S.Name.size() > COFF::NameSize) - StrTabBuilder.add(S.Name); + if (S.Name.size() > COFF::NameSize) { + // Put the section name at the start of strtab to ensure its offset is + // less than Max7DecimalOffset. Otherwise, lldb/gdb will not read it. + StrTabBuilder.add(S.Name, /*Priority=*/UINT8_MAX); + } for (const auto &S : Obj.getSymbols()) if (S.Name.size() > COFF::NameSize) @@ -317,7 +320,7 @@ void COFFWriter::writeSections() { uint8_t *Ptr = reinterpret_cast<uint8_t *>(Buf->getBufferStart()) + S.Header.PointerToRawData; ArrayRef<uint8_t> Contents = S.getContents(); - std::copy(Contents.begin(), Contents.end(), Ptr); + llvm::copy(Contents, Ptr); // For executable sections, pad the remainder of the raw data size with // 0xcc, which is int3 on x86. @@ -355,7 +358,7 @@ template <class SymbolTy> void COFFWriter::writeSymbolStringTables() { // For file symbols, just write the string into the aux symbol slots, // assuming that the unwritten parts are initialized to zero in the memory // mapped file. - std::copy(S.AuxFile.begin(), S.AuxFile.end(), Ptr); + llvm::copy(S.AuxFile, Ptr); Ptr += S.Sym.NumberOfAuxSymbols * sizeof(SymbolTy); } else { // For other auxillary symbols, write their opaque payload into one symbol @@ -364,7 +367,7 @@ template <class SymbolTy> void COFFWriter::writeSymbolStringTables() { // entry. for (const AuxSymbol &AuxSym : S.AuxData) { ArrayRef<uint8_t> Ref = AuxSym.getRef(); - std::copy(Ref.begin(), Ref.end(), Ptr); + llvm::copy(Ref, Ptr); Ptr += sizeof(SymbolTy); } } |
