[llvm] [llvm-objcopy] Add llvm-objcopy option --ignore-symbol (PR #80873)
Ilia Kuklin via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 09:50:07 PST 2024
https://github.com/kuilpd updated https://github.com/llvm/llvm-project/pull/80873
>From ea46888e71c34ff13dad18f9e5d7a0eda763db75 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/14] Add llvm-objcopy option --ignore-symbol
---
llvm/include/llvm/ObjCopy/ELF/ELFConfig.h | 1 +
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, 67 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 eafed92516c7df..ee0673a6961f11 100644
--- a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
+++ b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
@@ -19,6 +19,7 @@ namespace objcopy {
struct ELFConfig {
uint8_t NewSymbolVisibility = (uint8_t)ELF::STV_DEFAULT;
+ NameMatcher SymbolsToIgnore;
std::vector<std::pair<NameMatcher, uint8_t>> SymbolsToSetVisibility;
// ELF entry point address expression. The input parameter is an entry point
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index f52bcb74938d15..140953c6727f3c 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 6318578b110048..c5369a66efcd86 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -977,6 +977,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 3c0e5cd475a36b..fccfaaecc45cef 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -206,6 +206,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 d986c606520936529839aa21c3aa5adbf2cf48c8 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/14] 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 91ecf0ee7587e662918d4ca85ecf2473f2d404ff 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/14] 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 9d0cb7ad119589..9193296c3dfbbc 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 342c3c0064fbae079c7de3d6386b49f1a273174e 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/14] 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 411702d8f9768ddc5baae20d9e590566b7726a45 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/14] 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 f897a2dd92c7163290b80aff1f4a13cabfd3033e 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/14] 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 fc49f9a16ef82fcaf8bbe50e713f3717b8bdd3bf 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/14] 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 af3375cf91f2ab76fd74b68650bdcbd5324bc14c 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/14] 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 89da016d44bbe6b08e30483b28135b32c93eb338 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/14] 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 9193296c3dfbbc..cbf16c174304be 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
@@ -476,6 +464,18 @@ them.
Read a list of symbols from <filename> and change their visibility to the
specified value. Visibility values: default, internal, hidden, protected.
+.. 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 ee0673a6961f11..6e1119699ca6bc 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;
std::vector<std::pair<NameMatcher, uint8_t>> SymbolsToSetVisibility;
// ELF entry point address expression. The input parameter is an entry point
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 140953c6727f3c..0e8115f58ef640 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 c5369a66efcd86..a4730ce8f5b6c0 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -977,12 +977,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 fccfaaecc45cef..be02616e8c68e3 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -206,15 +206,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 cab328508e3fa78ad64e10f072cee206f834ea43 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/14] 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 5170bac4a89c8a0d657075c9902e0fee8bb47d45 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/14] 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 51b6527f65bb04..aa6f093826c5d4 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -151,6 +151,10 @@ Changes to the LLVM tools
``--set-symbols-visibility`` options for ELF input to change the
visibility of symbols.
+* 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
---------------------------------
>From ed0d49be975893108b9d43adafac0748f603a253 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Wed, 28 Feb 2024 21:44:18 +0500
Subject: [PATCH 12/14] Address nits
---
llvm/docs/CommandGuide/llvm-objcopy.rst | 2 +-
llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/docs/CommandGuide/llvm-objcopy.rst b/llvm/docs/CommandGuide/llvm-objcopy.rst
index cbf16c174304be..e8b3c1415127f5 100644
--- a/llvm/docs/CommandGuide/llvm-objcopy.rst
+++ b/llvm/docs/CommandGuide/llvm-objcopy.rst
@@ -467,7 +467,7 @@ them.
.. 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
+ can change the symbol's name, binding or visibility.
.. option:: --skip-symbols <filename>
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 0e8115f58ef640..6ebe9e667aca90 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -294,6 +294,7 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config,
Obj.SymbolTable->updateSymbols([&](Symbol &Sym) {
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.
if (!Sym.isCommon() && Sym.getShndx() != SHN_UNDEF &&
>From 1e93ef4a595ee7788f93d0c86d8a1909b8bcd88d Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Wed, 28 Feb 2024 22:28:36 +0500
Subject: [PATCH 13/14] Move the option to common config and add checks in
config manager
---
llvm/include/llvm/ObjCopy/CommonConfig.h | 1 +
llvm/include/llvm/ObjCopy/ELF/ELFConfig.h | 1 -
llvm/lib/ObjCopy/ConfigManager.cpp | 8 ++++----
llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 2 +-
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | 8 ++++----
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/ObjCopy/CommonConfig.h b/llvm/include/llvm/ObjCopy/CommonConfig.h
index 383395941475a4..4bba8d9486c55f 100644
--- a/llvm/include/llvm/ObjCopy/CommonConfig.h
+++ b/llvm/include/llvm/ObjCopy/CommonConfig.h
@@ -235,6 +235,7 @@ struct CommonConfig {
NameMatcher UnneededSymbolsToRemove;
NameMatcher SymbolsToWeaken;
NameMatcher SymbolsToKeepGlobal;
+ NameMatcher SymbolsToSkip;
// Map options
StringMap<SectionRename> SectionsToRename;
diff --git a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
index 6e1119699ca6bc..eafed92516c7df 100644
--- a/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
+++ b/llvm/include/llvm/ObjCopy/ELF/ELFConfig.h
@@ -19,7 +19,6 @@ namespace objcopy {
struct ELFConfig {
uint8_t NewSymbolVisibility = (uint8_t)ELF::STV_DEFAULT;
- NameMatcher SymbolsToSkip;
std::vector<std::pair<NameMatcher, uint8_t>> SymbolsToSetVisibility;
// ELF entry point address expression. The input parameter is an entry point
diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp
index e46b595a56dc44..6442f1b958fb4d 100644
--- a/llvm/lib/ObjCopy/ConfigManager.cpp
+++ b/llvm/lib/ObjCopy/ConfigManager.cpp
@@ -15,7 +15,7 @@ namespace objcopy {
Expected<const COFFConfig &> ConfigManager::getCOFFConfig() const {
if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
- !Common.SymbolsPrefixRemove.empty() ||
+ !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
!Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||
!Common.SymbolsToGlobalize.empty() || !Common.SymbolsToKeep.empty() ||
!Common.SymbolsToLocalize.empty() || !Common.SymbolsToWeaken.empty() ||
@@ -34,7 +34,7 @@ Expected<const COFFConfig &> ConfigManager::getCOFFConfig() const {
Expected<const MachOConfig &> ConfigManager::getMachOConfig() const {
if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
- !Common.SymbolsPrefixRemove.empty() ||
+ !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
!Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||
!Common.SymbolsToGlobalize.empty() || !Common.SymbolsToKeep.empty() ||
!Common.SymbolsToLocalize.empty() ||
@@ -56,7 +56,7 @@ Expected<const MachOConfig &> ConfigManager::getMachOConfig() const {
Expected<const WasmConfig &> ConfigManager::getWasmConfig() const {
if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
- !Common.SymbolsPrefixRemove.empty() ||
+ !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
!Common.AllocSectionsPrefix.empty() ||
Common.DiscardMode != DiscardType::None || !Common.SymbolsToAdd.empty() ||
!Common.SymbolsToGlobalize.empty() || !Common.SymbolsToLocalize.empty() ||
@@ -77,7 +77,7 @@ Expected<const WasmConfig &> ConfigManager::getWasmConfig() const {
Expected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const {
if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
- !Common.SymbolsPrefixRemove.empty() ||
+ !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
!Common.AllocSectionsPrefix.empty() ||
Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||
!Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() ||
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 6ebe9e667aca90..95b3cc27934e17 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.SymbolsToSkip.matches(Sym.Name))
+ if (Config.SymbolsToSkip.matches(Sym.Name))
return;
// Common and undefined symbols don't make sense as local symbols, and can
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index a4730ce8f5b6c0..808e8fb701cc18 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -978,13 +978,13 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
SymbolMatchStyle, ErrorCallback))
return std::move(E);
for (auto *Arg : InputArgs.filtered(OBJCOPY_skip_symbol))
- if (Error E = ELFConfig.SymbolsToSkip.addMatcher(NameOrPattern::create(
+ if (Error E = Config.SymbolsToSkip.addMatcher(NameOrPattern::create(
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
return std::move(E);
for (auto *Arg : InputArgs.filtered(OBJCOPY_skip_symbols))
- if (Error E = addSymbolsFromFile(ELFConfig.SymbolsToSkip, DC.Alloc,
- Arg->getValue(), SymbolMatchStyle,
- ErrorCallback))
+ if (Error E =
+ addSymbolsFromFile(Config.SymbolsToSkip, DC.Alloc, Arg->getValue(),
+ SymbolMatchStyle, ErrorCallback))
return std::move(E);
for (auto *Arg : InputArgs.filtered(OBJCOPY_add_symbol)) {
Expected<NewSymbolInfo> SymInfo = parseNewSymbolInfo(Arg->getValue());
>From ac06362ef970d2fff125a6b1a9bf324a195ff0d7 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Wed, 28 Feb 2024 22:43:28 +0500
Subject: [PATCH 14/14] Add a test to check both multiple uses and order with
--set-symbol-visibility
---
llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
index a3e6cd99c0e0ed..1728af797be1a5 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/skip-symbols.test
@@ -31,6 +31,16 @@
# RS-SYM-DAG: foo2
# RS-SYM-DAG: foo3
+## Check the functionality when using skip options multiple times.
+# RUN: echo "foo3" > %t.symbol.list
+# RUN: llvm-objcopy %t.o %t5.o --set-symbol-visibility='foo*'=internal --wildcard \
+# RUN: --skip-symbol=foo1 --skip-symbol=foo2 --skip-symbols=%t.symbol.list
+# RUN: llvm-readelf -s %t5.o | FileCheck %s --check-prefix=BOTH
+## All the symbols are skipped
+# BOTH-DAG: GLOBAL HIDDEN 1 foo1
+# BOTH-DAG: GLOBAL HIDDEN 1 foo2
+# BOTH-DAG: GLOBAL HIDDEN 1 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 | \
More information about the llvm-commits
mailing list