[llvm] 621e5cd - Revert "[llvm-objcopy][ELF] Add an option to remove notes (#118739)"

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 14:59:16 PST 2025


Author: Igor Kudrin
Date: 2025-01-23T14:57:29-08:00
New Revision: 621e5cd8204596874c2ec7c8c169044d8e6865e3

URL: https://github.com/llvm/llvm-project/commit/621e5cd8204596874c2ec7c8c169044d8e6865e3
DIFF: https://github.com/llvm/llvm-project/commit/621e5cd8204596874c2ec7c8c169044d8e6865e3.diff

LOG: Revert "[llvm-objcopy][ELF] Add an option to remove notes (#118739)"

This reverts commit 9324e6a7a5c5adc5b5c38c3e3cbecd7e1e98876a.

Added: 
    

Modified: 
    llvm/docs/CommandGuide/llvm-objcopy.rst
    llvm/include/llvm/ObjCopy/CommonConfig.h
    llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
    llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
    llvm/lib/ObjCopy/ELF/ELFObject.cpp
    llvm/lib/ObjCopy/ELF/ELFObject.h
    llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
    llvm/tools/llvm-objcopy/ObjcopyOpts.td
    llvm/tools/llvm-objcopy/llvm-objcopy.cpp

Removed: 
    llvm/test/tools/llvm-objcopy/ELF/remove-note.test


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-objcopy.rst b/llvm/docs/CommandGuide/llvm-objcopy.rst
index 8dc1357635e1b4..be4876cad6760f 100644
--- a/llvm/docs/CommandGuide/llvm-objcopy.rst
+++ b/llvm/docs/CommandGuide/llvm-objcopy.rst
@@ -477,11 +477,6 @@ them.
 
  Preserve access and modification timestamps in the output.
 
-.. option:: --remove-note [<name>/]<type>
-
- Remove notes of integer type ``<type>`` and name ``<name>`` from SHT_NOTE
- sections that are not in a segment. Can be specified multiple times.
-
 .. option:: --rename-section <old>=<new>[,<flag>,...]
 
  Rename sections called ``<old>`` to ``<new>`` in the output, and apply any

diff  --git a/llvm/include/llvm/ObjCopy/CommonConfig.h b/llvm/include/llvm/ObjCopy/CommonConfig.h
index aea9cd6f9a9c72..5ae09760e9a542 100644
--- a/llvm/include/llvm/ObjCopy/CommonConfig.h
+++ b/llvm/include/llvm/ObjCopy/CommonConfig.h
@@ -281,11 +281,6 @@ struct CommonConfig {
 
   SmallVector<std::pair<NameMatcher, llvm::DebugCompressionType>, 0>
       compressSections;
-
-  // ErrorCallback is used to handle recoverable errors. An Error returned
-  // by the callback aborts the execution and is then returned to the caller.
-  // If the callback is not set, the errors are not issued.
-  std::function<Error(Error)> ErrorCallback;
 };
 
 } // namespace objcopy

diff  --git a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
index 01a8762cfb9c37..59960b65307430 100644
--- a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
+++ b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
@@ -15,12 +15,6 @@
 namespace llvm {
 namespace objcopy {
 
-// Note to remove info specified by --remove-note option.
-struct RemoveNoteInfo {
-  StringRef Name;
-  uint32_t TypeId;
-};
-
 // ELF specific configuration for copying/stripping a single file.
 struct ELFConfig {
   uint8_t NewSymbolVisibility = (uint8_t)ELF::STV_DEFAULT;
@@ -37,9 +31,6 @@ struct ELFConfig {
   bool KeepFileSymbols = false;
   bool LocalizeHidden = false;
   bool VerifyNoteSections = true;
-
-  // Notes specified by --remove-note option.
-  SmallVector<RemoveNoteInfo, 0> NotesToRemove;
 };
 
 } // namespace objcopy

diff  --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 42581af387d8db..4793651f1d4e0b 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -609,112 +609,6 @@ static void addSymbol(Object &Obj, const NewSymbolInfo &SymInfo,
       Sec ? (uint16_t)SYMBOL_SIMPLE_INDEX : (uint16_t)SHN_ABS, 0);
 }
 
-namespace {
-struct RemoveNoteDetail {
-  struct DeletedRange {
-    uint64_t OldFrom;
-    uint64_t OldTo;
-  };
-
-  template <class ELFT>
-  static std::vector<DeletedRange>
-  findNotesToRemove(ArrayRef<uint8_t> Data, size_t Align,
-                    ArrayRef<RemoveNoteInfo> NotesToRemove);
-  static std::vector<uint8_t> updateData(ArrayRef<uint8_t> OldData,
-                                         ArrayRef<DeletedRange> ToRemove);
-};
-} // namespace
-
-template <class ELFT>
-std::vector<RemoveNoteDetail::DeletedRange>
-RemoveNoteDetail::findNotesToRemove(ArrayRef<uint8_t> Data, size_t Align,
-                                    ArrayRef<RemoveNoteInfo> NotesToRemove) {
-  LLVM_ELF_IMPORT_TYPES_ELFT(ELFT);
-  std::vector<DeletedRange> ToRemove;
-  uint64_t CurPos = 0;
-  while (CurPos + sizeof(Elf_Nhdr) <= Data.size()) {
-    auto Nhdr = reinterpret_cast<const Elf_Nhdr *>(Data.data() + CurPos);
-    size_t FullSize = Nhdr->getSize(Align);
-    if (CurPos + FullSize > Data.size())
-      break;
-    Elf_Note Note(*Nhdr);
-    bool ShouldRemove =
-        llvm::any_of(NotesToRemove, [&Note](const RemoveNoteInfo &NoteInfo) {
-          return NoteInfo.TypeId == Note.getType() &&
-                 (NoteInfo.Name.empty() || NoteInfo.Name == Note.getName());
-        });
-    if (ShouldRemove)
-      ToRemove.push_back({CurPos, CurPos + FullSize});
-    CurPos += FullSize;
-  }
-  return ToRemove;
-}
-
-std::vector<uint8_t>
-RemoveNoteDetail::updateData(ArrayRef<uint8_t> OldData,
-                             ArrayRef<DeletedRange> ToRemove) {
-  std::vector<uint8_t> NewData;
-  NewData.reserve(OldData.size());
-  uint64_t CurPos = 0;
-  for (const DeletedRange &RemRange : ToRemove) {
-    if (CurPos < RemRange.OldFrom) {
-      auto Slice = OldData.slice(CurPos, RemRange.OldFrom - CurPos);
-      NewData.insert(NewData.end(), Slice.begin(), Slice.end());
-    }
-    CurPos = RemRange.OldTo;
-  }
-  if (CurPos < OldData.size()) {
-    auto Slice = OldData.slice(CurPos);
-    NewData.insert(NewData.end(), Slice.begin(), Slice.end());
-  }
-  return NewData;
-}
-
-static Error removeNotes(Object &Obj, endianness Endianness,
-                         ArrayRef<RemoveNoteInfo> NotesToRemove,
-                         function_ref<Error(Error)> ErrorCallback) {
-  // TODO: Support note segments.
-  if (ErrorCallback) {
-    for (Segment &Seg : Obj.segments()) {
-      if (Seg.Type == PT_NOTE) {
-        if (Error E = ErrorCallback(createStringError(
-                errc::not_supported, "note segments are not supported")))
-          return E;
-        break;
-      }
-    }
-  }
-  for (auto &Sec : Obj.sections()) {
-    if (Sec.Type != SHT_NOTE || !Sec.hasContents())
-      continue;
-    // TODO: Support note sections in segments.
-    if (Sec.ParentSegment) {
-      if (ErrorCallback)
-        if (Error E = ErrorCallback(createStringError(
-                errc::not_supported,
-                "cannot remove note(s) from " + Sec.Name +
-                    ": sections in segments are not supported")))
-          return E;
-      continue;
-    }
-    ArrayRef<uint8_t> OldData = Sec.getContents();
-    size_t Align = std::max<size_t>(4, Sec.Align);
-    // Note: notes for both 32-bit and 64-bit ELF files use 4-byte words in the
-    // header, so the parsers are the same.
-    auto ToRemove = (Endianness == endianness::little)
-                        ? RemoveNoteDetail::findNotesToRemove<ELF64LE>(
-                              OldData, Align, NotesToRemove)
-                        : RemoveNoteDetail::findNotesToRemove<ELF64BE>(
-                              OldData, Align, NotesToRemove);
-    if (!ToRemove.empty()) {
-      if (Error E = Obj.updateSectionData(
-              Sec, RemoveNoteDetail::updateData(OldData, ToRemove)))
-        return E;
-    }
-  }
-  return Error::success();
-}
-
 static Error
 handleUserSection(const NewSectionInfo &NewSection,
                   function_ref<Error(StringRef, ArrayRef<uint8_t>)> F) {
@@ -905,12 +799,6 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
                      ? endianness::little
                      : endianness::big;
 
-  if (!ELFConfig.NotesToRemove.empty()) {
-    if (Error Err =
-            removeNotes(Obj, E, ELFConfig.NotesToRemove, Config.ErrorCallback))
-      return Err;
-  }
-
   for (const NewSectionInfo &AddedSection : Config.AddSection) {
     auto AddSection = [&](StringRef Name, ArrayRef<uint8_t> Data) -> Error {
       OwnedDataSection &NewSection =

diff  --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index 45c7ea49b5d938..01c2f24629077a 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -2154,46 +2154,37 @@ ELFWriter<ELFT>::ELFWriter(Object &Obj, raw_ostream &Buf, bool WSH,
     : Writer(Obj, Buf), WriteSectionHeaders(WSH && Obj.HadShdrs),
       OnlyKeepDebug(OnlyKeepDebug) {}
 
-Error Object::updateSectionData(SecPtr &Sec, ArrayRef<uint8_t> Data) {
-  if (!Sec->hasContents())
+Error Object::updateSection(StringRef Name, ArrayRef<uint8_t> Data) {
+  auto It = llvm::find_if(Sections,
+                          [&](const SecPtr &Sec) { return Sec->Name == Name; });
+  if (It == Sections.end())
+    return createStringError(errc::invalid_argument, "section '%s' not found",
+                             Name.str().c_str());
+
+  auto *OldSec = It->get();
+  if (!OldSec->hasContents())
     return createStringError(
         errc::invalid_argument,
         "section '%s' cannot be updated because it does not have contents",
-        Sec->Name.c_str());
+        Name.str().c_str());
 
-  if (Data.size() > Sec->Size && Sec->ParentSegment)
+  if (Data.size() > OldSec->Size && OldSec->ParentSegment)
     return createStringError(errc::invalid_argument,
                              "cannot fit data of size %zu into section '%s' "
                              "with size %" PRIu64 " that is part of a segment",
-                             Data.size(), Sec->Name.c_str(), Sec->Size);
+                             Data.size(), Name.str().c_str(), OldSec->Size);
 
-  if (!Sec->ParentSegment) {
-    Sec = std::make_unique<OwnedDataSection>(*Sec, Data);
+  if (!OldSec->ParentSegment) {
+    *It = std::make_unique<OwnedDataSection>(*OldSec, Data);
   } else {
     // The segment writer will be in charge of updating these contents.
-    Sec->Size = Data.size();
-    UpdatedSections[Sec.get()] = Data;
+    OldSec->Size = Data.size();
+    UpdatedSections[OldSec] = Data;
   }
 
   return Error::success();
 }
 
-Error Object::updateSection(StringRef Name, ArrayRef<uint8_t> Data) {
-  auto It = llvm::find_if(Sections,
-                          [&](const SecPtr &Sec) { return Sec->Name == Name; });
-  if (It == Sections.end())
-    return createStringError(errc::invalid_argument, "section '%s' not found",
-                             Name.str().c_str());
-  return updateSectionData(*It, Data);
-}
-
-Error Object::updateSectionData(SectionBase &S, ArrayRef<uint8_t> Data) {
-  auto It = llvm::find_if(Sections,
-                          [&](const SecPtr &Sec) { return Sec.get() == &S; });
-  assert(It != Sections.end() && "The section should belong to the object");
-  return updateSectionData(*It, Data);
-}
-
 Error Object::removeSections(
     bool AllowBrokenLinks, std::function<bool(const SectionBase &)> ToRemove) {
 

diff  --git a/llvm/lib/ObjCopy/ELF/ELFObject.h b/llvm/lib/ObjCopy/ELF/ELFObject.h
index d8f79a4b1a3cc6..6ccf85387131e4 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.h
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.h
@@ -549,7 +549,6 @@ class SectionBase {
   virtual void
   replaceSectionReferences(const DenseMap<SectionBase *, SectionBase *> &);
   virtual bool hasContents() const { return false; }
-  virtual ArrayRef<uint8_t> getContents() const { return {}; }
   // Notify the section that it is subject to removal.
   virtual void onRemove();
 
@@ -620,8 +619,6 @@ class Section : public SectionBase {
   bool hasContents() const override {
     return Type != ELF::SHT_NOBITS && Type != ELF::SHT_NULL;
   }
-  ArrayRef<uint8_t> getContents() const override { return Contents; }
-
   void restoreSymTabLink(SymbolTableSection &SymTab) override;
 };
 
@@ -657,7 +654,6 @@ class OwnedDataSection : public SectionBase {
   Error accept(SectionVisitor &Sec) const override;
   Error accept(MutableSectionVisitor &Visitor) override;
   bool hasContents() const override { return true; }
-  ArrayRef<uint8_t> getContents() const override { return Data; }
 };
 
 class CompressedSection : public SectionBase {
@@ -1168,8 +1164,6 @@ class Object {
     return Sec.Flags & ELF::SHF_ALLOC;
   };
 
-  Error updateSectionData(SecPtr &Sec, ArrayRef<uint8_t> Data);
-
 public:
   template <class T>
   using ConstRange = iterator_range<pointee_iterator<
@@ -1212,7 +1206,6 @@ class Object {
 
   const auto &getUpdatedSections() const { return UpdatedSections; }
   Error updateSection(StringRef Name, ArrayRef<uint8_t> Data);
-  Error updateSectionData(SectionBase &S, ArrayRef<uint8_t> Data);
 
   SectionBase *findSection(StringRef Name) {
     auto SecIt =

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/remove-note.test b/llvm/test/tools/llvm-objcopy/ELF/remove-note.test
deleted file mode 100644
index f8936bf9ea7312..00000000000000
--- a/llvm/test/tools/llvm-objcopy/ELF/remove-note.test
+++ /dev/null
@@ -1,198 +0,0 @@
-## Check incompatible options.
-# RUN: not llvm-objcopy --remove-note=1 --remove-section=.test - 2>&1 | FileCheck %s --check-prefix=ERR-REMSEC
-# RUN: not llvm-objcopy --remove-note=1 --add-section=.test=%s - 2>&1 | FileCheck %s --check-prefix=ERR-ADDSEC
-# RUN: not llvm-objcopy --remove-note=1 --update-section=.test=%s - 2>&1 | FileCheck %s --check-prefix=ERR-UPDSEC
-
-# ERR-REMSEC: error: cannot specify both --remove-note and --remove-section
-# ERR-ADDSEC: error: cannot specify both --remove-note and --add-section
-# ERR-UPDSEC: error: cannot specify both --remove-note and --update-section
-
-## Check invalid argument formats.
-# RUN: not llvm-objcopy --remove-note= - 2>&1 | FileCheck %s --check-prefix=ERR-NOTYPEID
-# RUN: not llvm-objcopy --remove-note=CORE/ - 2>&1 | FileCheck %s --check-prefix=ERR-NOTYPEID
-# RUN: not llvm-objcopy --remove-note=/1 - 2>&1 | FileCheck %s --check-prefix=ERR-EMPTYNAME
-# RUN: not llvm-objcopy --remove-note=CORE/1/2 - 2>&1 | FileCheck %s --check-prefix=ERR-INVNUM1
-# RUN: not llvm-objcopy --remove-note=Notanumber - 2>&1 | FileCheck %s --check-prefix=ERR-INVNUM2
-# RUN: not llvm-objcopy --remove-note=CORE/Notanumber - 2>&1 | FileCheck %s --check-prefix=ERR-INVNUM2
-
-# ERR-NOTYPEID: error: bad format for --remove-note, missing type_id
-# ERR-EMPTYNAME: error: bad format for --remove-note, note name is empty
-# ERR-INVNUM1: error: bad note type_id for --remove-note: '1/2'
-# ERR-INVNUM2: error: bad note type_id for --remove-note: 'Notanumber'
-
-## Check deleting notes:
-## * --remove-note=1 will remove note "CORE/1" and "LINUX/1",
-## * --remove-note=DUMMY/2 will not remove any notes because there are no notes with this owner,
-## * --remove-note=CORE/3 will remove "CORE/3" but preserve "LINUX/3".
-# RUN: yaml2obj --docnum=1 -D ALIGN=8 -D ELFCLASS=64 -D ENDIANNESS=LSB %s -o %t8.64.lsb
-# RUN: llvm-objcopy --remove-note=0x01 --remove-note=DUMMY/2 --remove-note=CORE/0x03 %t8.64.lsb %t8.64.lsb.o
-# RUN: llvm-readobj --segments --sections --notes %t8.64.lsb.o | \
-# RUN:   FileCheck %s -D#SIZE0=32 -D#SIZE1=64
-
-# RUN: yaml2obj --docnum=1 -D ALIGN=4 -D ELFCLASS=64 -D ENDIANNESS=MSB %s -o %t4.64.msb
-# RUN: llvm-objcopy --remove-note=0x01 --remove-note=DUMMY/0x02 --remove-note=CORE/3 %t4.64.msb %t4.64.msb.o
-# RUN: llvm-readobj --segments --sections --notes %t4.64.msb.o | \
-# RUN:   FileCheck %s -D#SIZE0=24 -D#SIZE1=48
-
-# RUN: yaml2obj --docnum=1 -D ALIGN=4 -D ELFCLASS=32 -D ENDIANNESS=LSB %s -o %t4.32.lsb
-# RUN: llvm-objcopy --remove-note=1 --remove-note=DUMMY/0x02 --remove-note=CORE/3 %t4.32.lsb %t4.32.lsb.o
-# RUN: llvm-readobj --segments --sections --notes %t4.32.lsb.o | \
-# RUN:   FileCheck %s -D#SIZE0=24 -D#SIZE1=48
-
-# CHECK:      Sections [
-# CHECK:        Section {
-# CHECK:          Name: .note0
-# CHECK-NEXT:     Type: SHT_NOTE
-# CHECK-NEXT:     Flags [
-# CHECK-NEXT:     ]
-# CHECK-NEXT:     Address:
-# CHECK-NEXT:     Offset:
-# CHECK-NEXT:     Size: [[#%d,SIZE0]]
-# CHECK:          Name: .note1
-# CHECK-NEXT:     Type: SHT_NOTE
-# CHECK-NEXT:     Flags [
-# CHECK-NEXT:     ]
-# CHECK-NEXT:     Address:
-# CHECK-NEXT:     Offset:
-# CHECK-NEXT:     Size: [[#%d,SIZE1]]
-# CHECK:          Name: .note2
-# CHECK-NEXT:     Type: SHT_NOTE
-# CHECK-NEXT:     Flags [
-# CHECK-NEXT:     ]
-# CHECK-NEXT:     Address:
-# CHECK-NEXT:     Offset:
-# CHECK-NEXT:     Size: 0
-
-# CHECK:      NoteSections [
-# CHECK-NEXT:   NoteSection {
-# CHECK-NEXT:     Name: .note0
-# CHECK-NEXT:     Offset:
-# CHECK-NEXT:     Size: 0x[[#%X,SIZE0]]
-# CHECK-NEXT:     Notes [
-# CHECK-NEXT:       {
-# CHECK-NEXT:         Owner: CORE
-# CHECK-NEXT:         Data size: 0x2
-# CHECK-NEXT:         Type: NT_ARCH
-# CHECK-NEXT:         Description data (
-# CHECK-NEXT:           0000: 0201
-# CHECK-NEXT:         )
-# CHECK-NEXT:       }
-# CHECK-NEXT:     ]
-# CHECK-NEXT:   }
-# CHECK-NEXT:   NoteSection {
-# CHECK-NEXT:     Name: .note1
-# CHECK-NEXT:     Offset:
-# CHECK-NEXT:     Size: 0x[[#%X,SIZE1]]
-# CHECK-NEXT:     Notes [
-# CHECK-NEXT:       {
-# CHECK-NEXT:         Owner: LINUX
-# CHECK-NEXT:         Data size: 0x2
-# CHECK-NEXT:         Type: Unknown (0x00000003)
-# CHECK-NEXT:         Description data (
-# CHECK-NEXT:           0000: 0301
-# CHECK-NEXT:         )
-# CHECK-NEXT:       }
-# CHECK-NEXT:       {
-# CHECK-NEXT:         Owner: CORE
-# CHECK-NEXT:         Data size: 0x2
-# CHECK-NEXT:         Type: Unknown (0x00000004)
-# CHECK-NEXT:         Description data (
-# CHECK-NEXT:           0000: 0401
-# CHECK-NEXT:         )
-# CHECK-NEXT:       }
-# CHECK-NEXT:     ]
-# CHECK-NEXT:   }
-# CHECK-NEXT:   NoteSection {
-# CHECK-NEXT:     Name: .note2
-# CHECK-NEXT:     Offset:
-# CHECK-NEXT:     Size: 0x0
-# CHECK-NEXT:     Notes [
-# CHECK-NEXT:     ]
-# CHECK-NEXT:   }
-
---- !ELF
-FileHeader:
-  Class:          ELFCLASS[[ELFCLASS]]
-  Data:           ELFDATA2[[ENDIANNESS]]
-  Type:           ET_REL
-  Machine:        EM_X86_64
-Sections:
-  - Name:         .note0
-    Type:         SHT_NOTE
-    AddressAlign: [[ALIGN]]
-    Notes:
-      - Name:   CORE
-        Type:   0x01
-        Desc:   0101
-      - Name:   CORE
-        Type:   0x02
-        Desc:   0201
-  - Name:         .note1
-    Type:         SHT_NOTE
-    AddressAlign: [[ALIGN]]
-    Notes:
-      - Name:   LINUX
-        Type:   0x03
-        Desc:   0301
-      - Name:   CORE
-        Type:   0x03
-        Desc:   0302
-      - Name:   CORE
-        Type:   0x04
-        Desc:   0401
-  - Name:         .note2
-    Type:         SHT_NOTE
-    AddressAlign: [[ALIGN]]
-    Notes:
-      - Name:   LINUX
-        Type:   0x01
-        Desc:   0102
-
-# RUN: yaml2obj --docnum=2 %s -o %t2
-# RUN: llvm-objcopy --remove-note=1 %t2 %t2o 2>&1 | FileCheck %s --check-prefix=TEST2
-# TEST2: warning: note segments are not supported
-# TEST2-NOT: note segments are not supported
-
---- !ELF
-FileHeader:
-  Class:          ELFCLASS64
-  Data:           ELFDATA2LSB
-  Type:           ET_CORE
-  Machine:        EM_X86_64
-ProgramHeaders:
-  - Type:         PT_NOTE
-    FirstSec:     .data0
-    LastSec:      .data0
-  - Type:         PT_NOTE
-    FirstSec:     .data1
-    LastSec:      .data1
-Sections:
-  - Name:         .data0
-    Type:         Fill
-    Size:         8
-  - Name:         .data1
-    Type:         Fill
-    Size:         8
-
-# RUN: yaml2obj --docnum=3 %s -o %t3
-# RUN: llvm-objcopy --remove-note=1 %t3 %t3o 2>&1 | FileCheck %s --check-prefix=TEST3
-# TEST3: warning: cannot remove note(s) from .note: sections in segments are not supported
-
---- !ELF
-FileHeader:
-  Class:          ELFCLASS64
-  Data:           ELFDATA2LSB
-  Type:           ET_EXEC
-  Machine:        EM_X86_64
-ProgramHeaders:
-  - Type:         PT_LOAD
-    FirstSec:     .note
-    LastSec:      .note
-Sections:
-  - Name:         .note
-    Type:         SHT_NOTE
-    AddressAlign: 4
-    Notes:
-      - Name:     ABC
-        Type:     1
-        Desc:     0102

diff  --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index 0d209590655ef3..0925fc55317f7d 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -538,38 +538,6 @@ static Expected<NewSymbolInfo> parseNewSymbolInfo(StringRef FlagValue) {
   return SI;
 }
 
-static Expected<RemoveNoteInfo> parseRemoveNoteInfo(StringRef FlagValue) {
-  // Parse value given with --remove-note option. The format is:
-  //
-  // [name/]type_id
-  //
-  // where:
-  // <name>    - optional note name. If not given, all notes with the specified
-  //             <type_id> are removed.
-  // <type_id> - note type value, can be decimal or hexadecimal number prefixed
-  //             with 0x.
-  RemoveNoteInfo NI;
-  StringRef TypeIdStr;
-  if (auto Idx = FlagValue.find('/'); Idx != StringRef::npos) {
-    if (Idx == 0)
-      return createStringError(
-          errc::invalid_argument,
-          "bad format for --remove-note, note name is empty");
-    NI.Name = FlagValue.slice(0, Idx);
-    TypeIdStr = FlagValue.substr(Idx + 1);
-  } else {
-    TypeIdStr = FlagValue;
-  }
-  if (TypeIdStr.empty())
-    return createStringError(errc::invalid_argument,
-                             "bad format for --remove-note, missing type_id");
-  if (TypeIdStr.getAsInteger(0, NI.TypeId))
-    return createStringError(errc::invalid_argument,
-                             "bad note type_id for --remove-note: '%s'",
-                             TypeIdStr.str().c_str());
-  return NI;
-}
-
 // Parse input option \p ArgValue and load section data. This function
 // extracts section name and name of the file keeping section data from
 // ArgValue, loads data from the file, and stores section name and data
@@ -1253,29 +1221,6 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
       };
     }
 
-  for (auto *Arg : InputArgs.filtered(OBJCOPY_remove_note)) {
-    Expected<RemoveNoteInfo> NoteInfo = parseRemoveNoteInfo(Arg->getValue());
-    if (!NoteInfo)
-      return NoteInfo.takeError();
-
-    ELFConfig.NotesToRemove.push_back(*NoteInfo);
-  }
-
-  if (!ELFConfig.NotesToRemove.empty()) {
-    if (!Config.ToRemove.empty())
-      return createStringError(
-          errc::invalid_argument,
-          "cannot specify both --remove-note and --remove-section");
-    if (!Config.AddSection.empty())
-      return createStringError(
-          errc::invalid_argument,
-          "cannot specify both --remove-note and --add-section");
-    if (!Config.UpdateSection.empty())
-      return createStringError(
-          errc::invalid_argument,
-          "cannot specify both --remove-note and --update-section");
-  }
-
   if (Config.DecompressDebugSections &&
       Config.CompressionType != DebugCompressionType::None) {
     return createStringError(

diff  --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index fbc6a59d9461e7..434b5ff92324eb 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -297,7 +297,3 @@ defm pad_to
                    "of zero or the value specified by the --gap-fill option. "
                    "This option is only supported for ELF input and binary output">,
       MetaVarName<"address">;
-
-defm remove_note
-    : Eq<"remove-note", "Remove note(s) with <type_id> and optional <name>">,
-      MetaVarName<"[name/]type_id">;

diff  --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 7e708e309f207b..ad3e60472369bf 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -248,8 +248,6 @@ int llvm_objcopy_main(int argc, char **argv, const llvm::ToolContext &) {
     return 1;
   }
   for (ConfigManager &ConfigMgr : DriverConfig->CopyConfigs) {
-    assert(!ConfigMgr.Common.ErrorCallback);
-    ConfigMgr.Common.ErrorCallback = reportWarning;
     if (Error E = executeObjcopy(ConfigMgr)) {
       logAllUnhandledErrors(std::move(E), WithColor::error(errs(), ToolName));
       return 1;


        


More information about the llvm-commits mailing list