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: --weaken 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.
Patch: https://sourceware.org/pipermail/binutils/2022-March/119916.html
The master branch has been updated by Fangrui Song <maskray@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=260ecdcec427146f760836092a040f957427760b 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.
Fixed for 2.39