Bug 27493 - objcopy --weaken-symbol does not weaken undefined symbols
Summary: objcopy --weaken-symbol does not weaken undefined symbols
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
Depends on:
Reported: 2021-03-01 08:47 UTC by Fangrui Song
Modified: 2021-03-03 07:19 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 2021-03-01 08:47:46 UTC
% cat a.s
.globl def
  call undef
% cc -c a.s
% objcopy --weaken-symbol=def --weaken-symbol=undef a.o b.o
% readelf -Ws b.o

Symbol table '.symtab' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    5 
     5: 0000000000000000     0 NOTYPE  WEAK   DEFAULT    1 def
     6: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND undef

--weaken-symbol applies on a defined symbol but not on an undefined symbol.
This was originally raised as a behavior difference between objcopy and llvm-objcopy https://bugs.llvm.org/show_bug.cgi?id=49362 .

My feeling is that weakening undefined symbols matches the documentation and should be done. It is a behavior change but it unlikely causes any trouble.
Comment 1 cvs-commit@gcc.gnu.org 2021-03-03 07:17:42 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:


commit fd5c076a06d88dc53e56a17d43ea4ad5e27515a0
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Mar 3 15:15:23 2021 +1030

    PR27493, objcopy --weaken-symbol does not weaken undefined symbols
            PR 27493
            * objcopy.c (filter_symbols): Apply --weaken to undefined symbols.
            * NEWS: Mention feature.
Comment 2 Alan Modra 2021-03-03 07:19:37 UTC
I think this is reasonable, with the possible exception of plain --weaken but I've gone ahead and made that change too.