Bug 28871 - gold: --no-define-common is incompatible with GNU ld
Summary: gold: --no-define-common is incompatible with GNU ld
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-08 08:57 UTC by Fangrui Song
Modified: 2022-02-09 05:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2022-02-08 08:57:02 UTC
In 2001-09, [optionally postpone assignment of Common](https://sourceware.org/pipermail/binutils/2001-September/014015.html) added --no-define-common to be used with -shared. --define-common is not implemented.
Here is my understanding: glibc around 2.1.3 used to have a ld.so bug that the ELF interposition might not work. Using --no-define-common with shared objects can make COMMON symbols undefined and circumvent the bug.

gold confuses --define-common with -d/FORCE_COMMON_ALLOCATION (commit 0dfbdef4c43cfe12bb3e2505ebe5acc651a35c98) and implements --define-common with -d semantics. Its --no-define-common is incompatible with GNU ld.

I suggest that gold removes --[no-]define-common. Debian Code Search says no project uses this option.
Comment 1 Fangrui Song 2022-02-08 09:08:43 UTC
https://sourceware.org/pipermail/binutils/2022-February/119689.html [PATCH] gold: Remove GNU ld incompatible --[no-]define-common [BZ #28871]
Comment 2 Cary Coutant 2022-02-09 03:05:20 UTC
I do not see how gold's --no-define-common is incompatible with ld's. According to the ld manual, and from looking at the original ld patch, they seem to do exactly the same thing, which is in fact the opposite of -d.

If your complaint is that --define-common is accepted by gold but not by ld, I do not see that as sufficient grounds to remove it from gold.
Comment 3 Fangrui Song 2022-02-09 05:07:46 UTC
The semantics are different.

% ld.bfd -r --no-define-common a.o -o a.ro && readelf -Ws a.ro
ld.bfd: --no-define-common may not be used without -shared

% ld.bfd -shared --no-define-common a.o -o a.so && readelf -Ws a.so

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

Symbol table '.symtab' contains 3 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000002f40     0 OBJECT  LOCAL  DEFAULT    7 _DYNAMIC
     2: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  UND x


See that x is undefined in GNU ld. In gold, --[no-]define-common controls whether st_shndx is SHN_COMMON or not (allocated space or not).