]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
objcopy: zap ELF visibility when localizing symbols
authorJan Beulich <jbeulich@suse.com>
Fri, 8 May 2026 09:45:26 +0000 (11:45 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 8 May 2026 09:45:26 +0000 (11:45 +0200)
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.

binutils/objcopy.c
binutils/testsuite/binutils-all/localize-hidden-1.d

index 2098c7b5b3e44f3146a42ed345752a1a8995dbe8..89eb3f72dcd93a394bb896e5e9ff1771f01809ca 100644 (file)
@@ -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
index 72620083d56d25117db982b6eacdcee5ee8f535e..c434b5993dc75f773d88fbc97a490b7f11f800e3 100644 (file)
@@ -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