diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/tools/llvm-objcopy/COFF | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/tools/llvm-objcopy/COFF')
3 files changed, 57 insertions, 57 deletions
diff --git a/contrib/libs/llvm12/tools/llvm-objcopy/COFF/COFFObjcopy.cpp b/contrib/libs/llvm12/tools/llvm-objcopy/COFF/COFFObjcopy.cpp index b5de8a45a8..cb2d66df74 100644 --- a/contrib/libs/llvm12/tools/llvm-objcopy/COFF/COFFObjcopy.cpp +++ b/contrib/libs/llvm12/tools/llvm-objcopy/COFF/COFFObjcopy.cpp @@ -39,12 +39,12 @@ static uint64_t getNextRVA(const Object &Obj) { Obj.IsPE ? Obj.PeHeader.SectionAlignment : 1); } -static Expected<std::vector<uint8_t>> -createGnuDebugLinkSectionContents(StringRef File) { +static Expected<std::vector<uint8_t>> +createGnuDebugLinkSectionContents(StringRef File) { ErrorOr<std::unique_ptr<MemoryBuffer>> LinkTargetOrErr = MemoryBuffer::getFile(File); if (!LinkTargetOrErr) - return createFileError(File, LinkTargetOrErr.getError()); + return createFileError(File, LinkTargetOrErr.getError()); auto LinkTarget = std::move(*LinkTargetOrErr); uint32_t CRC32 = llvm::crc32(arrayRefFromStringRef(LinkTarget->getBuffer())); @@ -81,17 +81,17 @@ static void addSection(Object &Obj, StringRef Name, ArrayRef<uint8_t> Contents, Obj.addSections(Sec); } -static Error addGnuDebugLink(Object &Obj, StringRef DebugLinkFile) { - Expected<std::vector<uint8_t>> Contents = +static Error addGnuDebugLink(Object &Obj, StringRef DebugLinkFile) { + Expected<std::vector<uint8_t>> Contents = createGnuDebugLinkSectionContents(DebugLinkFile); - if (!Contents) - return Contents.takeError(); - - addSection(Obj, ".gnu_debuglink", *Contents, + if (!Contents) + return Contents.takeError(); + + addSection(Obj, ".gnu_debuglink", *Contents, IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE); - - return Error::success(); + + return Error::success(); } static void setSectionFlags(Section &Sec, SectionFlag AllFlags) { @@ -179,7 +179,7 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) { Sym.Name = I->getValue(); } - auto ToRemove = [&](const Symbol &Sym) -> Expected<bool> { + auto ToRemove = [&](const Symbol &Sym) -> Expected<bool> { // For StripAll, all relocations have been stripped and we remove all // symbols. if (Config.StripAll || Config.StripAllGNU) @@ -188,10 +188,10 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) { if (Config.SymbolsToRemove.matches(Sym.Name)) { // Explicitly removing a referenced symbol is an error. if (Sym.Referenced) - return createStringError( - llvm::errc::invalid_argument, - "'" + Config.OutputFilename + "': not stripping symbol '" + - Sym.Name.str() + "' because it is named in a relocation"); + return createStringError( + llvm::errc::invalid_argument, + "'" + Config.OutputFilename + "': not stripping symbol '" + + Sym.Name.str() + "' because it is named in a relocation"); return true; } @@ -216,12 +216,12 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) { } return false; - }; - - // Actually do removals of symbols. - if (Error Err = Obj.removeSymbols(ToRemove)) - return Err; + }; + // Actually do removals of symbols. + if (Error Err = Obj.removeSymbols(ToRemove)) + return Err; + if (!Config.SetSectionFlags.empty()) for (Section &Sec : Obj.getMutableSections()) { const auto It = Config.SetSectionFlags.find(Sec.Name); @@ -246,8 +246,8 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) { } if (!Config.AddGnuDebugLink.empty()) - if (Error E = addGnuDebugLink(Obj, Config.AddGnuDebugLink)) - return E; + if (Error E = addGnuDebugLink(Obj, Config.AddGnuDebugLink)) + return E; if (Config.AllowBrokenLinks || !Config.BuildIdLinkDir.empty() || Config.BuildIdLinkInput || Config.BuildIdLinkOutput || diff --git a/contrib/libs/llvm12/tools/llvm-objcopy/COFF/Object.cpp b/contrib/libs/llvm12/tools/llvm-objcopy/COFF/Object.cpp index 1c17b8408e..166ddce160 100644 --- a/contrib/libs/llvm12/tools/llvm-objcopy/COFF/Object.cpp +++ b/contrib/libs/llvm12/tools/llvm-objcopy/COFF/Object.cpp @@ -31,23 +31,23 @@ void Object::updateSymbols() { } const Symbol *Object::findSymbol(size_t UniqueId) const { - return SymbolMap.lookup(UniqueId); + return SymbolMap.lookup(UniqueId); } -Error Object::removeSymbols( - function_ref<Expected<bool>(const Symbol &)> ToRemove) { - Error Errs = Error::success(); - llvm::erase_if(Symbols, [ToRemove, &Errs](const Symbol &Sym) { - Expected<bool> ShouldRemove = ToRemove(Sym); - if (!ShouldRemove) { - Errs = joinErrors(std::move(Errs), ShouldRemove.takeError()); - return false; - } - return *ShouldRemove; - }); - +Error Object::removeSymbols( + function_ref<Expected<bool>(const Symbol &)> ToRemove) { + Error Errs = Error::success(); + llvm::erase_if(Symbols, [ToRemove, &Errs](const Symbol &Sym) { + Expected<bool> ShouldRemove = ToRemove(Sym); + if (!ShouldRemove) { + Errs = joinErrors(std::move(Errs), ShouldRemove.takeError()); + return false; + } + return *ShouldRemove; + }); + updateSymbols(); - return Errs; + return Errs; } Error Object::markSymbols() { @@ -83,34 +83,34 @@ void Object::updateSections() { } const Section *Object::findSection(ssize_t UniqueId) const { - return SectionMap.lookup(UniqueId); + return SectionMap.lookup(UniqueId); } void Object::removeSections(function_ref<bool(const Section &)> ToRemove) { DenseSet<ssize_t> AssociatedSections; auto RemoveAssociated = [&AssociatedSections](const Section &Sec) { - return AssociatedSections.contains(Sec.UniqueId); + return AssociatedSections.contains(Sec.UniqueId); }; do { DenseSet<ssize_t> RemovedSections; - llvm::erase_if(Sections, [ToRemove, &RemovedSections](const Section &Sec) { - bool Remove = ToRemove(Sec); - if (Remove) - RemovedSections.insert(Sec.UniqueId); - return Remove; - }); + llvm::erase_if(Sections, [ToRemove, &RemovedSections](const Section &Sec) { + bool Remove = ToRemove(Sec); + if (Remove) + RemovedSections.insert(Sec.UniqueId); + return Remove; + }); // Remove all symbols referring to the removed sections. AssociatedSections.clear(); - llvm::erase_if( - Symbols, [&RemovedSections, &AssociatedSections](const Symbol &Sym) { - // If there are sections that are associative to a removed - // section, - // remove those as well as nothing will include them (and we can't - // leave them dangling). - if (RemovedSections.count(Sym.AssociativeComdatTargetSectionId) == 1) - AssociatedSections.insert(Sym.TargetSectionId); - return RemovedSections.contains(Sym.TargetSectionId); - }); + llvm::erase_if( + Symbols, [&RemovedSections, &AssociatedSections](const Symbol &Sym) { + // If there are sections that are associative to a removed + // section, + // remove those as well as nothing will include them (and we can't + // leave them dangling). + if (RemovedSections.count(Sym.AssociativeComdatTargetSectionId) == 1) + AssociatedSections.insert(Sym.TargetSectionId); + return RemovedSections.contains(Sym.TargetSectionId); + }); ToRemove = RemoveAssociated; } while (!AssociatedSections.empty()); updateSections(); diff --git a/contrib/libs/llvm12/tools/llvm-objcopy/COFF/Object.h b/contrib/libs/llvm12/tools/llvm-objcopy/COFF/Object.h index 0e854b58cb..77d8467c61 100644 --- a/contrib/libs/llvm12/tools/llvm-objcopy/COFF/Object.h +++ b/contrib/libs/llvm12/tools/llvm-objcopy/COFF/Object.h @@ -26,7 +26,7 @@ namespace coff { struct Relocation { Relocation() = default; - Relocation(const object::coff_relocation &R) : Reloc(R) {} + Relocation(const object::coff_relocation &R) : Reloc(R) {} object::coff_relocation Reloc; size_t Target = 0; @@ -116,7 +116,7 @@ struct Object { const Symbol *findSymbol(size_t UniqueId) const; void addSymbols(ArrayRef<Symbol> NewSymbols); - Error removeSymbols(function_ref<Expected<bool>(const Symbol &)> ToRemove); + Error removeSymbols(function_ref<Expected<bool>(const Symbol &)> ToRemove); // Set the Referenced field on all Symbols, based on relocations in // all sections. |