[llvm] [llvm-objcopy] Add llvm-objcopy option --ignore-symbol (PR #80873)
Ilia Kuklin via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 27 11:41:48 PST 2024
https://github.com/kuilpd updated https://github.com/llvm/llvm-project/pull/80873
>From b73e69022a7e0bf1ce56f0d9c57e35eb35bba6ad Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Tue, 6 Feb 2024 21:19:50 +0500
Subject: [PATCH 01/11] Add llvm-objcopy option --ignore-symbol
---
llvm/include/llvm/ObjCopy/ELF/ELFConfig.h | 3 ++
llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 2 +
.../llvm-objcopy/ELF/ignore-symbols.test | 41 +++++++++++++++++++
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | 9 ++++
llvm/tools/llvm-objcopy/ObjcopyOpts.td | 14 +++++++
5 files changed, 69 insertions(+)
create mode 100644 llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
diff --git a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
index d77cb69b159db6..52874ea55414d5 100644
--- a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
+++ b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
@@ -9,6 +9,7 @@
#ifndef LLVM_OBJCOPY_ELF_ELFCONFIG_H
#define LLVM_OBJCOPY_ELF_ELFCONFIG_H
+#include "llvm/ObjCopy/CommonConfig.h"
#include "llvm/Object/ELFTypes.h"
namespace llvm {
@@ -18,6 +19,8 @@ namespace objcopy {
struct ELFConfig {
uint8_t NewSymbolVisibility = (uint8_t)ELF::STV_DEFAULT;
+ NameMatcher SymbolsToIgnore;
+
// ELF entry point address expression. The input parameter is an entry point
// address in the input ELF file. The entry address in the output file is
// calculated with EntryExpr(input_address), when either --set-start or
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 1b3a58298ec08a..056afe5560e955 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -292,6 +292,8 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config,
return Error::success();
Obj.SymbolTable->updateSymbols([&](Symbol &Sym) {
+ if (ELFConfig.SymbolsToIgnore.matches(Sym.Name))
+ return;
// Common and undefined symbols don't make sense as local symbols, and can
// even cause crashes if we localize those, so skip them.
if (!Sym.isCommon() && Sym.getShndx() != SHN_UNDEF &&
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
new file mode 100644
index 00000000000000..13a15b46038ee7
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
@@ -0,0 +1,41 @@
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: echo 'foo[2-3]' > %t.ignore.regex
+
+# RUN: cp %t.o %t1.o
+# RUN: llvm-objcopy %t1.o --localize-hidden --ignore-symbols=%t.ignore.regex --regex
+# RUN: llvm-readelf -s %t1.o | FileCheck %s --check-prefix=SYMS
+# SYMS-DAG: LOCAL HIDDEN 1 foo1
+# SYMS-DAG: GLOBAL HIDDEN 1 foo2
+# SYMS-DAG: GLOBAL HIDDEN 1 foo3
+
+# RUN: cp %t.o %t1.o
+# RUN: llvm-objcopy %t1.o --localize-hidden --ignore-symbol=foo3
+# RUN: llvm-readelf -s %t1.o | FileCheck %s --check-prefix=SYM
+# SYM-DAG: LOCAL HIDDEN 1 foo1
+# SYM-DAG: LOCAL HIDDEN 1 foo2
+# SYM-DAG: GLOBAL HIDDEN 1 foo3
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+Symbols:
+ - Name: foo1
+ Section: .text
+ Binding: STB_GLOBAL
+ Other: [ STV_HIDDEN ]
+ - Name: foo2
+ Section: .text
+ Binding: STB_GLOBAL
+ Other: [ STV_HIDDEN ]
+ - Name: foo3
+ Section: .text
+ Binding: STB_GLOBAL
+ Other: [ STV_HIDDEN ]
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index 9a9b631e98bcf7..84ec83db0b5e0f 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -960,6 +960,15 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
addSymbolsFromFile(Config.SymbolsToKeep, DC.Alloc, Arg->getValue(),
SymbolMatchStyle, ErrorCallback))
return std::move(E);
+ for (auto *Arg : InputArgs.filtered(OBJCOPY_ignore_symbol))
+ if (Error E = ELFConfig.SymbolsToIgnore.addMatcher(NameOrPattern::create(
+ Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
+ return std::move(E);
+ for (auto *Arg : InputArgs.filtered(OBJCOPY_ignore_symbols))
+ if (Error E = addSymbolsFromFile(ELFConfig.SymbolsToIgnore, DC.Alloc,
+ Arg->getValue(), SymbolMatchStyle,
+ ErrorCallback))
+ return std::move(E);
for (auto *Arg : InputArgs.filtered(OBJCOPY_add_symbol)) {
Expected<NewSymbolInfo> SymInfo = parseNewSymbolInfo(Arg->getValue());
if (!SymInfo)
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index bd041fabbdd7ac..a86d1459acfc59 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -196,6 +196,20 @@ defm keep_symbols
"be repeated to read symbols from many files">,
MetaVarName<"filename">;
+defm ignore_symbol : Eq<"ignore-symbol", "Do not change parameters of symbol <symbol> "
+ "when executing other options that can change the symbol's "
+ "name, binding or visibility">,
+ MetaVarName<"symbol">;
+
+defm ignore_symbols
+ : Eq<"ignore-symbols",
+ "Reads a list of symbols from <filename> and runs as if "
+ "--ignore-symbol=<symbol> is set for each one. <filename> "
+ "contains one symbol per line and may contain comments beginning with "
+ "'#'. Leading and trailing whitespace is stripped from each line. May "
+ "be repeated to read symbols from many files">,
+ MetaVarName<"filename">;
+
defm dump_section
: Eq<"dump-section",
"Dump contents of section named <section> into file <file>">,
>From 1a78662999ece8667dd3e7334951f82c064d6a73 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Mon, 12 Feb 2024 20:10:24 +0500
Subject: [PATCH 02/11] Adjust and expand ignore-symbols.test
---
.../llvm-objcopy/ELF/ignore-symbols.test | 44 +++++++++++++------
1 file changed, 30 insertions(+), 14 deletions(-)
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
index 13a15b46038ee7..1d3bb81e12f589 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
@@ -2,19 +2,36 @@
# RUN: yaml2obj %s -o %t.o
# RUN: echo 'foo[2-3]' > %t.ignore.regex
-# RUN: cp %t.o %t1.o
-# RUN: llvm-objcopy %t1.o --localize-hidden --ignore-symbols=%t.ignore.regex --regex
-# RUN: llvm-readelf -s %t1.o | FileCheck %s --check-prefix=SYMS
-# SYMS-DAG: LOCAL HIDDEN 1 foo1
-# SYMS-DAG: GLOBAL HIDDEN 1 foo2
-# SYMS-DAG: GLOBAL HIDDEN 1 foo3
-
-# RUN: cp %t.o %t1.o
-# RUN: llvm-objcopy %t1.o --localize-hidden --ignore-symbol=foo3
-# RUN: llvm-readelf -s %t1.o | FileCheck %s --check-prefix=SYM
-# SYM-DAG: LOCAL HIDDEN 1 foo1
-# SYM-DAG: LOCAL HIDDEN 1 foo2
-# SYM-DAG: GLOBAL HIDDEN 1 foo3
+# Check --ignore-symbols functionality when changing symbol bindings
+# RUN: llvm-objcopy %t.o %t1.o --localize-hidden --ignore-symbols=%t.ignore.regex --regex
+# RUN: llvm-readelf -s %t1.o | FileCheck %s --check-prefix=LH-SYMS
+# LH-SYMS-DAG: LOCAL HIDDEN 1 foo1
+# LH-SYMS-DAG: GLOBAL HIDDEN 1 foo2
+# LH-SYMS-DAG: GLOBAL HIDDEN 1 foo3
+
+# Check --ignore-symbol functionality when changing symbol bindings
+# RUN: llvm-objcopy %t.o %t2.o --localize-hidden --ignore-symbol=foo3
+# RUN: llvm-readelf -s %t2.o | FileCheck %s --check-prefix=LH-SYM
+# LH-SYM-DAG: LOCAL HIDDEN 1 foo1
+# LH-SYM-DAG: LOCAL HIDDEN 1 foo2
+# LH-SYM-DAG: GLOBAL HIDDEN 1 foo3
+
+
+# Check --ignore-symbols functionality when changing symbol names
+# RUN: echo -e "foo1 bar1\nfoo2 bar2" > %t.renames.list
+# RUN: llvm-objcopy %t.o %t3.o --redefine-syms=%t.renames.list --ignore-symbols=%t.ignore.regex --regex
+# RUN: llvm-readelf -s %t3.o | FileCheck %s --check-prefix=RS-SYMS
+# RS-SYMS-DAG: bar1
+# RS-SYMS-DAG: foo2
+# RS-SYMS-DAG: foo3
+
+# Check --ignore-symbols functionality when changing symbol names
+# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --ignore-symbol=fo.* --regex
+# RUN: llvm-readelf -s %t4.o | FileCheck %s --check-prefix=RS-SYM
+# RS-SYM-DAG: foo1
+# RS-SYM-DAG: foo2
+# RS-SYM-DAG: foo3
+
!ELF
FileHeader:
@@ -25,7 +42,6 @@ FileHeader:
Sections:
- Name: .text
Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Symbols:
- Name: foo1
Section: .text
>From da233c7325b65301642cef2427abfee0cef25d3a Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Mon, 12 Feb 2024 20:30:22 +0500
Subject: [PATCH 03/11] Update the llvm-objcopy documentation
---
llvm/docs/CommandGuide/llvm-objcopy.rst | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/llvm/docs/CommandGuide/llvm-objcopy.rst b/llvm/docs/CommandGuide/llvm-objcopy.rst
index b823be9e828249..3d16c36f235f0e 100644
--- a/llvm/docs/CommandGuide/llvm-objcopy.rst
+++ b/llvm/docs/CommandGuide/llvm-objcopy.rst
@@ -346,6 +346,18 @@ them.
symbol, with leading and trailing whitespace ignored, as is anything following
a '#'. Can be specified multiple times to read names from multiple files.
+.. option:: --ignore-symbol <symbol>
+
+ Do not change parameters of symbol <symbol> when executing other options that
+ can change the symbol's name, binding or visibility
+
+.. option:: --ignore-symbols <filename>
+
+ Reads a list of symbols from <filename> and runs as if --ignore-symbol=<symbol>
+ is set for each one. <filename> contains one symbol per line and may contain
+ comments beginning with '#'. Leading and trailing whitespace is stripped from
+ each line. May be repeated to read symbols from many files.
+
.. option:: --input-target <format>, -I
Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
>From c94c1f68152a7f939ae1dd74b58f9de09c3773be Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Mon, 12 Feb 2024 20:31:58 +0500
Subject: [PATCH 04/11] Add a test for checking various error cases
---
.../ELF/ignore-symbols-check-errors.test | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
new file mode 100644
index 00000000000000..a92fecb88b3b07
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
@@ -0,0 +1,19 @@
+
+# RUN: yaml2obj %s -o %t.o
+
+# Check if using an invalid symbol pattern generates an error
+# RUN: echo '*.' > %t.symbols.regex
+# RUN: not llvm-objcopy %t.o --ignore-symbols=%t.symbols.regex --regex 2>&1 | FileCheck %s --check-prefix=SYMBOL
+# RUN: not llvm-objcopy %t.o --ignore-symbol=*. --regex 2>&1 | FileCheck %s --check-prefix=SYMBOL
+# SYMBOL: error: cannot compile regular expression '*.': repetition-operator operand invalid
+
+# Check passing an invalid filename generates an error
+# RUN: not llvm-objcopy %t.o --ignore-symbols=no_file 2>&1 | FileCheck %s --check-prefix=FILE
+# FILE: error: 'no_file': No such file or directory
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
>From a9713218a9826215731b986f7739d006fb139225 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Thu, 15 Feb 2024 21:28:36 +0500
Subject: [PATCH 05/11] Adjust formatting and wording in tests
---
.../ELF/ignore-symbols-check-errors.test | 14 +++++-----
.../llvm-objcopy/ELF/ignore-symbols.test | 26 +++++++++----------
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
index a92fecb88b3b07..74ab9e186441b2 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
@@ -1,14 +1,16 @@
-
# RUN: yaml2obj %s -o %t.o
-# Check if using an invalid symbol pattern generates an error
+## Check that using an invalid symbol pattern generates an error
# RUN: echo '*.' > %t.symbols.regex
-# RUN: not llvm-objcopy %t.o --ignore-symbols=%t.symbols.regex --regex 2>&1 | FileCheck %s --check-prefix=SYMBOL
-# RUN: not llvm-objcopy %t.o --ignore-symbol=*. --regex 2>&1 | FileCheck %s --check-prefix=SYMBOL
+# RUN: not llvm-objcopy %t.o --ignore-symbols=%t.symbols.regex --regex 2>&1 | \
+# RUN: FileCheck %s --check-prefix=SYMBOL
+# RUN: not llvm-objcopy %t.o --ignore-symbol=*. --regex 2>&1 | \
+# RUN: FileCheck %s --check-prefix=SYMBOL
# SYMBOL: error: cannot compile regular expression '*.': repetition-operator operand invalid
-# Check passing an invalid filename generates an error
-# RUN: not llvm-objcopy %t.o --ignore-symbols=no_file 2>&1 | FileCheck %s --check-prefix=FILE
+## Check passing an invalid filename generates an error
+# RUN: not llvm-objcopy %t.o --ignore-symbols=no_file 2>&1 | \
+# RUN: FileCheck %s --check-prefix=FILE
# FILE: error: 'no_file': No such file or directory
!ELF
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
index 1d3bb81e12f589..47bf190c9c2d1f 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
@@ -1,47 +1,45 @@
-
# RUN: yaml2obj %s -o %t.o
# RUN: echo 'foo[2-3]' > %t.ignore.regex
-# Check --ignore-symbols functionality when changing symbol bindings
+## Check --ignore-symbols functionality when changing symbol bindings
# RUN: llvm-objcopy %t.o %t1.o --localize-hidden --ignore-symbols=%t.ignore.regex --regex
# RUN: llvm-readelf -s %t1.o | FileCheck %s --check-prefix=LH-SYMS
# LH-SYMS-DAG: LOCAL HIDDEN 1 foo1
# LH-SYMS-DAG: GLOBAL HIDDEN 1 foo2
# LH-SYMS-DAG: GLOBAL HIDDEN 1 foo3
-# Check --ignore-symbol functionality when changing symbol bindings
+## Check --ignore-symbol functionality when changing symbol bindings
# RUN: llvm-objcopy %t.o %t2.o --localize-hidden --ignore-symbol=foo3
# RUN: llvm-readelf -s %t2.o | FileCheck %s --check-prefix=LH-SYM
# LH-SYM-DAG: LOCAL HIDDEN 1 foo1
# LH-SYM-DAG: LOCAL HIDDEN 1 foo2
# LH-SYM-DAG: GLOBAL HIDDEN 1 foo3
-
-# Check --ignore-symbols functionality when changing symbol names
+## Check --ignore-symbols functionality when changing symbol names
# RUN: echo -e "foo1 bar1\nfoo2 bar2" > %t.renames.list
-# RUN: llvm-objcopy %t.o %t3.o --redefine-syms=%t.renames.list --ignore-symbols=%t.ignore.regex --regex
+# RUN: llvm-objcopy %t.o %t3.o --redefine-syms=%t.renames.list \
+# RUN: --ignore-symbols=%t.ignore.regex --regex
# RUN: llvm-readelf -s %t3.o | FileCheck %s --check-prefix=RS-SYMS
# RS-SYMS-DAG: bar1
# RS-SYMS-DAG: foo2
# RS-SYMS-DAG: foo3
-# Check --ignore-symbols functionality when changing symbol names
+## Check --ignore-symbol functionality when changing symbol names
# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --ignore-symbol=fo.* --regex
# RUN: llvm-readelf -s %t4.o | FileCheck %s --check-prefix=RS-SYM
# RS-SYM-DAG: foo1
# RS-SYM-DAG: foo2
# RS-SYM-DAG: foo3
-
!ELF
FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
Sections:
- - Name: .text
- Type: SHT_PROGBITS
+ - Name: .text
+ Type: SHT_PROGBITS
Symbols:
- Name: foo1
Section: .text
>From 7633fbf4c5d9893b1f6d1be1c930ae4aa5feb362 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Thu, 15 Feb 2024 21:33:38 +0500
Subject: [PATCH 06/11] Use %errc_ENOENT for 'No such file or directory'
message
---
.../tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
index 74ab9e186441b2..23ef3d46c1b91b 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
@@ -10,8 +10,8 @@
## Check passing an invalid filename generates an error
# RUN: not llvm-objcopy %t.o --ignore-symbols=no_file 2>&1 | \
-# RUN: FileCheck %s --check-prefix=FILE
-# FILE: error: 'no_file': No such file or directory
+# RUN: FileCheck %s --check-prefix=FILE -DMSG=%errc_ENOENT
+# FILE: error: 'no_file': [[MSG]]
!ELF
FileHeader:
>From 40f7524957e18555b0f7924278ddb041e2e8bdf5 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Thu, 15 Feb 2024 21:50:31 +0500
Subject: [PATCH 07/11] Use a wildcard instead of a regex in one of the test
cases
---
llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
index 47bf190c9c2d1f..738f20c452292f 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
@@ -25,7 +25,7 @@
# RS-SYMS-DAG: foo3
## Check --ignore-symbol functionality when changing symbol names
-# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --ignore-symbol=fo.* --regex
+# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --ignore-symbol=fo* --wildcard
# RUN: llvm-readelf -s %t4.o | FileCheck %s --check-prefix=RS-SYM
# RS-SYM-DAG: foo1
# RS-SYM-DAG: foo2
>From 900bda547075c14faf091482b6828f924bbee99b Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Sat, 17 Feb 2024 00:31:43 +0500
Subject: [PATCH 08/11] Adjust test formatting
---
.../ELF/ignore-symbols-check-errors.test | 12 ++++++------
llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test | 8 ++++----
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
index 23ef3d46c1b91b..3cf34c6c1c59e9 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
@@ -1,6 +1,6 @@
# RUN: yaml2obj %s -o %t.o
-## Check that using an invalid symbol pattern generates an error
+## Check that using an invalid symbol pattern generates an error.
# RUN: echo '*.' > %t.symbols.regex
# RUN: not llvm-objcopy %t.o --ignore-symbols=%t.symbols.regex --regex 2>&1 | \
# RUN: FileCheck %s --check-prefix=SYMBOL
@@ -8,14 +8,14 @@
# RUN: FileCheck %s --check-prefix=SYMBOL
# SYMBOL: error: cannot compile regular expression '*.': repetition-operator operand invalid
-## Check passing an invalid filename generates an error
+## Check passing an invalid filename generates an error.
# RUN: not llvm-objcopy %t.o --ignore-symbols=no_file 2>&1 | \
# RUN: FileCheck %s --check-prefix=FILE -DMSG=%errc_ENOENT
# FILE: error: 'no_file': [[MSG]]
!ELF
FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
index 738f20c452292f..6403b7cfe6e86f 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
@@ -1,21 +1,21 @@
# RUN: yaml2obj %s -o %t.o
# RUN: echo 'foo[2-3]' > %t.ignore.regex
-## Check --ignore-symbols functionality when changing symbol bindings
+## Check --ignore-symbols functionality when changing symbol bindings.
# RUN: llvm-objcopy %t.o %t1.o --localize-hidden --ignore-symbols=%t.ignore.regex --regex
# RUN: llvm-readelf -s %t1.o | FileCheck %s --check-prefix=LH-SYMS
# LH-SYMS-DAG: LOCAL HIDDEN 1 foo1
# LH-SYMS-DAG: GLOBAL HIDDEN 1 foo2
# LH-SYMS-DAG: GLOBAL HIDDEN 1 foo3
-## Check --ignore-symbol functionality when changing symbol bindings
+## Check --ignore-symbol functionality when changing symbol bindings.
# RUN: llvm-objcopy %t.o %t2.o --localize-hidden --ignore-symbol=foo3
# RUN: llvm-readelf -s %t2.o | FileCheck %s --check-prefix=LH-SYM
# LH-SYM-DAG: LOCAL HIDDEN 1 foo1
# LH-SYM-DAG: LOCAL HIDDEN 1 foo2
# LH-SYM-DAG: GLOBAL HIDDEN 1 foo3
-## Check --ignore-symbols functionality when changing symbol names
+## Check --ignore-symbols functionality when changing symbol names.
# RUN: echo -e "foo1 bar1\nfoo2 bar2" > %t.renames.list
# RUN: llvm-objcopy %t.o %t3.o --redefine-syms=%t.renames.list \
# RUN: --ignore-symbols=%t.ignore.regex --regex
@@ -24,7 +24,7 @@
# RS-SYMS-DAG: foo2
# RS-SYMS-DAG: foo3
-## Check --ignore-symbol functionality when changing symbol names
+## Check --ignore-symbol functionality when changing symbol names.
# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --ignore-symbol=fo* --wildcard
# RUN: llvm-readelf -s %t4.o | FileCheck %s --check-prefix=RS-SYM
# RS-SYM-DAG: foo1
>From 041599db7d696937b8c3e00241fc2102e87f1f2a Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Wed, 28 Feb 2024 00:26:43 +0500
Subject: [PATCH 09/11] Rename the options to --skip-symbols(s)
---
llvm/docs/CommandGuide/llvm-objcopy.rst | 24 +++++++++----------
llvm/include/llvm/ObjCopy/ELF/ELFConfig.h | 2 +-
llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 2 +-
...rs.test => skip-symbols-check-errors.test} | 6 ++---
...{ignore-symbols.test => skip-symbols.test} | 18 +++++++-------
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | 8 +++----
llvm/tools/llvm-objcopy/ObjcopyOpts.td | 10 ++++----
7 files changed, 35 insertions(+), 35 deletions(-)
rename llvm/test/tools/llvm-objcopy/ELF/{ignore-symbols-check-errors.test => skip-symbols-check-errors.test} (73%)
rename llvm/test/tools/llvm-objcopy/ELF/{ignore-symbols.test => skip-symbols.test} (66%)
diff --git a/llvm/docs/CommandGuide/llvm-objcopy.rst b/llvm/docs/CommandGuide/llvm-objcopy.rst
index 3d16c36f235f0e..9bffac6ae908ea 100644
--- a/llvm/docs/CommandGuide/llvm-objcopy.rst
+++ b/llvm/docs/CommandGuide/llvm-objcopy.rst
@@ -346,18 +346,6 @@ them.
symbol, with leading and trailing whitespace ignored, as is anything following
a '#'. Can be specified multiple times to read names from multiple files.
-.. option:: --ignore-symbol <symbol>
-
- Do not change parameters of symbol <symbol> when executing other options that
- can change the symbol's name, binding or visibility
-
-.. option:: --ignore-symbols <filename>
-
- Reads a list of symbols from <filename> and runs as if --ignore-symbol=<symbol>
- is set for each one. <filename> contains one symbol per line and may contain
- comments beginning with '#'. Leading and trailing whitespace is stripped from
- each line. May be repeated to read symbols from many files.
-
.. option:: --input-target <format>, -I
Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
@@ -467,6 +455,18 @@ them.
Set the start address of the output to ``<addr>``. Overrides any previously
specified :option:`--change-start` or :option:`--adjust-start` options.
+.. option:: --skip-symbol <symbol>
+
+ Do not change parameters of symbol <symbol> when executing other options that
+ can change the symbol's name, binding or visibility
+
+.. option:: --skip-symbols <filename>
+
+ Read a list of symbols from <filename> and run as if --skip-symbol=<symbol>
+ is set for each one. <filename> contains one symbol per line and may contain
+ comments beginning with '#'. Leading and trailing whitespace is stripped from
+ each line. May be repeated to read symbols from many files.
+
.. option:: --split-dwo <dwo-file>
Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
diff --git a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
index 52874ea55414d5..796b1e9f00baad 100644
--- a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
+++ b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
@@ -19,7 +19,7 @@ namespace objcopy {
struct ELFConfig {
uint8_t NewSymbolVisibility = (uint8_t)ELF::STV_DEFAULT;
- NameMatcher SymbolsToIgnore;
+ NameMatcher SymbolsToSkip;
// ELF entry point address expression. The input parameter is an entry point
// address in the input ELF file. The entry address in the output file is
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 056afe5560e955..d7fd8dd1d69d4a 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -292,7 +292,7 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config,
return Error::success();
Obj.SymbolTable->updateSymbols([&](Symbol &Sym) {
- if (ELFConfig.SymbolsToIgnore.matches(Sym.Name))
+ if (ELFConfig.SymbolsToSkip.matches(Sym.Name))
return;
// Common and undefined symbols don't make sense as local symbols, and can
// even cause crashes if we localize those, so skip them.
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols-check-errors.test
similarity index 73%
rename from llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
rename to llvm/test/tools/llvm-objcopy/ELF/skip-symbols-check-errors.test
index 3cf34c6c1c59e9..db55346f2d97c0 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols-check-errors.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols-check-errors.test
@@ -2,14 +2,14 @@
## Check that using an invalid symbol pattern generates an error.
# RUN: echo '*.' > %t.symbols.regex
-# RUN: not llvm-objcopy %t.o --ignore-symbols=%t.symbols.regex --regex 2>&1 | \
+# RUN: not llvm-objcopy %t.o --skip-symbols=%t.symbols.regex --regex 2>&1 | \
# RUN: FileCheck %s --check-prefix=SYMBOL
-# RUN: not llvm-objcopy %t.o --ignore-symbol=*. --regex 2>&1 | \
+# RUN: not llvm-objcopy %t.o --skip-symbol=*. --regex 2>&1 | \
# RUN: FileCheck %s --check-prefix=SYMBOL
# SYMBOL: error: cannot compile regular expression '*.': repetition-operator operand invalid
## Check passing an invalid filename generates an error.
-# RUN: not llvm-objcopy %t.o --ignore-symbols=no_file 2>&1 | \
+# RUN: not llvm-objcopy %t.o --skip-symbols=no_file 2>&1 | \
# RUN: FileCheck %s --check-prefix=FILE -DMSG=%errc_ENOENT
# FILE: error: 'no_file': [[MSG]]
diff --git a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
similarity index 66%
rename from llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
rename to llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
index 6403b7cfe6e86f..24a118f3f88f37 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/ignore-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
@@ -1,31 +1,31 @@
# RUN: yaml2obj %s -o %t.o
-# RUN: echo 'foo[2-3]' > %t.ignore.regex
+# RUN: echo 'foo[2-3]' > %t.skip.regex
-## Check --ignore-symbols functionality when changing symbol bindings.
-# RUN: llvm-objcopy %t.o %t1.o --localize-hidden --ignore-symbols=%t.ignore.regex --regex
+## Check --skip-symbols functionality when changing symbol bindings.
+# RUN: llvm-objcopy %t.o %t1.o --localize-hidden --skip-symbols=%t.skip.regex --regex
# RUN: llvm-readelf -s %t1.o | FileCheck %s --check-prefix=LH-SYMS
# LH-SYMS-DAG: LOCAL HIDDEN 1 foo1
# LH-SYMS-DAG: GLOBAL HIDDEN 1 foo2
# LH-SYMS-DAG: GLOBAL HIDDEN 1 foo3
-## Check --ignore-symbol functionality when changing symbol bindings.
-# RUN: llvm-objcopy %t.o %t2.o --localize-hidden --ignore-symbol=foo3
+## Check --skip-symbol functionality when changing symbol bindings.
+# RUN: llvm-objcopy %t.o %t2.o --localize-hidden --skip-symbol=foo3
# RUN: llvm-readelf -s %t2.o | FileCheck %s --check-prefix=LH-SYM
# LH-SYM-DAG: LOCAL HIDDEN 1 foo1
# LH-SYM-DAG: LOCAL HIDDEN 1 foo2
# LH-SYM-DAG: GLOBAL HIDDEN 1 foo3
-## Check --ignore-symbols functionality when changing symbol names.
+## Check --skip-symbols functionality when changing symbol names.
# RUN: echo -e "foo1 bar1\nfoo2 bar2" > %t.renames.list
# RUN: llvm-objcopy %t.o %t3.o --redefine-syms=%t.renames.list \
-# RUN: --ignore-symbols=%t.ignore.regex --regex
+# RUN: --skip-symbols=%t.skip.regex --regex
# RUN: llvm-readelf -s %t3.o | FileCheck %s --check-prefix=RS-SYMS
# RS-SYMS-DAG: bar1
# RS-SYMS-DAG: foo2
# RS-SYMS-DAG: foo3
-## Check --ignore-symbol functionality when changing symbol names.
-# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --ignore-symbol=fo* --wildcard
+## Check --skip-symbol functionality when changing symbol names.
+# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --skip-symbol=fo* --wildcard
# RUN: llvm-readelf -s %t4.o | FileCheck %s --check-prefix=RS-SYM
# RS-SYM-DAG: foo1
# RS-SYM-DAG: foo2
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index 84ec83db0b5e0f..bc9d0895a346b5 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -960,12 +960,12 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
addSymbolsFromFile(Config.SymbolsToKeep, DC.Alloc, Arg->getValue(),
SymbolMatchStyle, ErrorCallback))
return std::move(E);
- for (auto *Arg : InputArgs.filtered(OBJCOPY_ignore_symbol))
- if (Error E = ELFConfig.SymbolsToIgnore.addMatcher(NameOrPattern::create(
+ for (auto *Arg : InputArgs.filtered(OBJCOPY_skip_symbol))
+ if (Error E = ELFConfig.SymbolsToSkip.addMatcher(NameOrPattern::create(
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
return std::move(E);
- for (auto *Arg : InputArgs.filtered(OBJCOPY_ignore_symbols))
- if (Error E = addSymbolsFromFile(ELFConfig.SymbolsToIgnore, DC.Alloc,
+ for (auto *Arg : InputArgs.filtered(OBJCOPY_skip_symbols))
+ if (Error E = addSymbolsFromFile(ELFConfig.SymbolsToSkip, DC.Alloc,
Arg->getValue(), SymbolMatchStyle,
ErrorCallback))
return std::move(E);
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index a86d1459acfc59..e4c3602c764db0 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -196,15 +196,15 @@ defm keep_symbols
"be repeated to read symbols from many files">,
MetaVarName<"filename">;
-defm ignore_symbol : Eq<"ignore-symbol", "Do not change parameters of symbol <symbol> "
+defm skip_symbol : Eq<"skip-symbol", "Do not change parameters of symbol <symbol> "
"when executing other options that can change the symbol's "
"name, binding or visibility">,
MetaVarName<"symbol">;
-defm ignore_symbols
- : Eq<"ignore-symbols",
- "Reads a list of symbols from <filename> and runs as if "
- "--ignore-symbol=<symbol> is set for each one. <filename> "
+defm skip_symbols
+ : Eq<"skip-symbols",
+ "Read a list of symbols from <filename> and run as if "
+ "--skip-symbol=<symbol> is set for each one. <filename> "
"contains one symbol per line and may contain comments beginning with "
"'#'. Leading and trailing whitespace is stripped from each line. May "
"be repeated to read symbols from many files">,
>From a9e9171bf446a4b087b590f732624f824b98e277 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Wed, 28 Feb 2024 00:29:04 +0500
Subject: [PATCH 10/11] Merge tests into one file
---
.../ELF/skip-symbols-check-errors.test | 21 -------------------
.../tools/llvm-objcopy/ELF/skip-symbols.test | 15 ++++++++++++-
2 files changed, 14 insertions(+), 22 deletions(-)
delete mode 100644 llvm/test/tools/llvm-objcopy/ELF/skip-symbols-check-errors.test
diff --git a/llvm/test/tools/llvm-objcopy/ELF/skip-symbols-check-errors.test b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols-check-errors.test
deleted file mode 100644
index db55346f2d97c0..00000000000000
--- a/llvm/test/tools/llvm-objcopy/ELF/skip-symbols-check-errors.test
+++ /dev/null
@@ -1,21 +0,0 @@
-# RUN: yaml2obj %s -o %t.o
-
-## Check that using an invalid symbol pattern generates an error.
-# RUN: echo '*.' > %t.symbols.regex
-# RUN: not llvm-objcopy %t.o --skip-symbols=%t.symbols.regex --regex 2>&1 | \
-# RUN: FileCheck %s --check-prefix=SYMBOL
-# RUN: not llvm-objcopy %t.o --skip-symbol=*. --regex 2>&1 | \
-# RUN: FileCheck %s --check-prefix=SYMBOL
-# SYMBOL: error: cannot compile regular expression '*.': repetition-operator operand invalid
-
-## Check passing an invalid filename generates an error.
-# RUN: not llvm-objcopy %t.o --skip-symbols=no_file 2>&1 | \
-# RUN: FileCheck %s --check-prefix=FILE -DMSG=%errc_ENOENT
-# FILE: error: 'no_file': [[MSG]]
-
-!ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
diff --git a/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
index 24a118f3f88f37..a3e6cd99c0e0ed 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
@@ -25,12 +25,25 @@
# RS-SYMS-DAG: foo3
## Check --skip-symbol functionality when changing symbol names.
-# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --skip-symbol=fo* --wildcard
+# RUN: llvm-objcopy %t.o %t4.o --redefine-sym=foo1=bar1 --skip-symbol='fo*' --wildcard
# RUN: llvm-readelf -s %t4.o | FileCheck %s --check-prefix=RS-SYM
# RS-SYM-DAG: foo1
# RS-SYM-DAG: foo2
# RS-SYM-DAG: foo3
+## Check that using an invalid symbol pattern generates an error.
+# RUN: echo '*.' > %t.symbols.regex
+# RUN: not llvm-objcopy %t.o --skip-symbols=%t.symbols.regex --regex 2>&1 | \
+# RUN: FileCheck %s --check-prefix=SYMBOL
+# RUN: not llvm-objcopy %t.o --skip-symbol='*.' --regex 2>&1 | \
+# RUN: FileCheck %s --check-prefix=SYMBOL
+# SYMBOL: error: cannot compile regular expression '*.': repetition-operator operand invalid
+
+## Check passing an invalid filename generates an error.
+# RUN: not llvm-objcopy %t.o --skip-symbols=no_file 2>&1 | \
+# RUN: FileCheck %s --check-prefix=FILE -DMSG=%errc_ENOENT
+# FILE: error: 'no_file': [[MSG]]
+
!ELF
FileHeader:
Class: ELFCLASS64
>From 62a4b6f8a0496318870b382caec9658741107053 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Wed, 28 Feb 2024 00:35:18 +0500
Subject: [PATCH 11/11] Added the options to release notes
---
llvm/docs/ReleaseNotes.rst | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 120e8b637136a6..1be38237be3bef 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -137,6 +137,10 @@ Changes to the Debug Info
Changes to the LLVM tools
---------------------------------
+* llvm-objcopy now supports ``--skip-symbol`` and ``--skip-symbols`` options
+ for ELF input to skip the specified symbols when executing other options
+ that can change a symbol's name, binding or visibility.
+
Changes to LLDB
---------------------------------
More information about the llvm-commits
mailing list