Bug 28926 - objcopy --weaken-symbol does not weaken STB_GNU_UNIQUE symbols
Summary: objcopy --weaken-symbol does not weaken STB_GNU_UNIQUE symbols
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2022-02-28 00:56 UTC by Fangrui Song
Modified: 2022-03-16 16:47 UTC (History)
0 users

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2022-02-28 00:56:09 UTC
echo '.data; .type x, @gnu_unique_object; x:' | as - -o a.o
objcopy -W x a.o
readelf -Ws a.o

The symbol 'x' remains STB_GNU_UNIQUE:

Symbol table '.symtab' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 OBJECT  UNIQUE DEFAULT    2 x

I think with the explicit request, it makes sense to weaken 'x'.

The documentation for --weaken is:

           Change all global symbols in the file to be weak.  This can be useful when building an object which will be linked against other objects using the -R option to the linker.  This option is only effective when using an object file format which supports weak symbols.

If we consider STB_GNU_UNIQUE "global", then --weaken probably should weaken STB_GNU_UNIQUE, too.
Comment 2 Sourceware Commits 2022-03-16 16:43:16 UTC
The master branch has been updated by Fangrui Song <maskray@sourceware.org>:


commit 260ecdcec427146f760836092a040f957427760b
Author: Fangrui Song <i@maskray.me>
Date:   Wed Mar 16 09:38:37 2022 -0700

    objcopy --weaken-symbol: apply to STB_GNU_UNIQUE symbols
        PR binutils/28926
        * objcopy.c (filter_symbols): Apply weaken to STB_GNU_UNIQUE symbols
        * NEWS: Mention feature.
        * testsuite/binutils-all/objcopy.exp (objcopy_test_symbol_manipulation): New test.
        * testsuite/binutils-all/weaken-gnu-unique.s: New.
Comment 3 Fangrui Song 2022-03-16 16:47:04 UTC
Fixed for 2.39