[binutils-gdb] objcopy: zap ELF visibility when localizing symbols
Jan Beulich via Binutils-cvs <[email protected]>
| Newsgroups | gmane.comp.gnu.binutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e7e4f9d6401f8e5679a91de52a1a97bf023f66d5 commit e7e4f9d6401f8e5679a91de52a1a97bf023f66d5 Author: Jan Beulich <[email protected]> Date: Fri May 8 11:45:26 2026 +0200 objcopy: zap ELF visibility when localizing symbols The spec explicitly precludes STB_LOCAL together with STV_PROTECTED (and, implicitly, STV_HIDDEN or STV_INTERNAL), so we better wouldn't (entirely silently) write out symbols violating this. Diff: --- binutils/objcopy.c | 10 ++++++++++ binutils/testsuite/binutils-all/localize-hidden-1.d | 14 +++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 2098c7b5b3e..89eb3f72dcd 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -1532,6 +1532,15 @@ is_hidden_symbol (asymbol *sym) return false; } +static void +clear_visibility (asymbol *sym) +{ + elf_symbol_type *elf_sym = elf_symbol_from (sym); + + if (elf_sym != NULL) + elf_sym->internal_elf_sym.st_other &= ~ELF_ST_VISIBILITY (~0); +} + /* Empty name is hopefully never a valid symbol name. */ static const char * empty_name = ""; @@ -1765,6 +1774,7 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms, { flags &= ~(BSF_GLOBAL | BSF_WEAK); flags |= BSF_LOCAL; + clear_visibility (sym); } else if (!undefined diff --git a/binutils/testsuite/binutils-all/localize-hidden-1.d b/binutils/testsuite/binutils-all/localize-hidden-1.d index 72620083d56..c434b5993dc 100644 --- a/binutils/testsuite/binutils-all/localize-hidden-1.d +++ b/binutils/testsuite/binutils-all/localize-hidden-1.d @@ -4,15 +4,15 @@ #name: --localize-hidden test 1 #warning_output: localize-hidden-1.l #... -0+1200 l .*\*ABS\* 0+ \.hidden Lhidden -0+1300 l .*\*ABS\* 0+ \.internal Linternal -0+1400 l .*\*ABS\* 0+ \.protected Lprotected +0+1200 l .*\*ABS\* 0+ (\.hidden )?Lhidden +0+1300 l .*\*ABS\* 0+ (\.internal )?Linternal +0+1400 l .*\*ABS\* 0+ (\.protected )?Lprotected 0+1100 l .*\*ABS\* 0+ Ldefault #... -0+2200 l .*\*ABS\* 0+ \.hidden Ghidden -0+2300 l .*\*ABS\* 0+ \.internal Ginternal -0+3200 l .*\*ABS\* 0+ \.hidden Whidden -0+3300 l .*\*ABS\* 0+ \.internal Winternal +0+2200 l .*\*ABS\* 0+ Ghidden +0+2300 l .*\*ABS\* 0+ Ginternal +0+3200 l .*\*ABS\* 0+ Whidden +0+3300 l .*\*ABS\* 0+ Winternal #... 0+2100 g .*\*ABS\* 0+ Gdefault 0+2400 g .*\*ABS\* 0+ \.protected Gprotected