[ELF] Update st_size when merging a common symbol with a shared symbol
authorFangrui Song <maskray@google.com>
Sat, 7 Dec 2019 05:18:31 +0000 (21:18 -0800)
committerFangrui Song <maskray@google.com>
Fri, 13 Dec 2019 17:23:36 +0000 (09:23 -0800)
commit69d10d282e5896821e16d4bc5dd190adc0131520
treed1ce5e36ad1d4fff86d640584c6ce056db4dcdf5
parented4618edb35688567fcf107785776e27028f4062
[ELF] Update st_size when merging a common symbol with a shared symbol

When a common symbol is merged with a shared symbol, increase st_size if
the shared symbol has a larger st_size. At runtime, the executable's
symbol overrides the shared symbol.  The shared symbol may be created
from common symbols in a previous link.  This rule makes sure we pick
the largest size among all common symbols.

This behavior matches GNU ld. See
https://sourceware.org/bugzilla/show_bug.cgi?id=25236 for discussions.

A shared symbol does not hold alignment constraints. Ignore the
alignment update.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D71161
lld/ELF/Symbols.cpp
lld/test/ELF/common-shared.s [new file with mode: 0644]