This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Check COMMON symbols for PROVIDE and don't redefine COMMON symbols edata/end/etext
ClosedPublic

Authored by MaskRay on Feb 22 2022, 11:29 PM.

Details

Summary

In GNU ld, the definition precedence is: regular symbol assignment > relocatable object definition > PROVIDE symbol assignment.

GNU ld's internal linker scripts define the non-reserved (by C and C++)
edata/end/etext with PROVIDE so the relocatable object definition takes
precedence. This makes sense because int end; is valid.

We currently redefine such symbols if they are COMMON, but not if they are
regular definitions, so int end; with -fcommon is essentially a UB in ld.lld.
Fix this (also improve consistency and match GNU ld) by using the
isDefined code path for isCommon. In GNU ld, reserved identifiers like
__ehdr_start do not use PROVIDE, while we treat them all as PROVIDE, this
seems fine.

Diff Detail

Event Timeline

MaskRay created this revision.Feb 22 2022, 11:29 PM
MaskRay requested review of this revision.Feb 22 2022, 11:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2022, 11:29 PM
peter.smith accepted this revision.Feb 23 2022, 6:29 AM

LGTM, makes sense to me.

This revision is now accepted and ready to land.Feb 23 2022, 6:29 AM
MaskRay edited the summary of this revision. (Show Details)Feb 23 2022, 10:11 AM
MaskRay edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Feb 23 2022, 10:15 AM
This revision was automatically updated to reflect the committed changes.

Sorry, should be fixed by 53c5bd9da285be20325f6c63b3685865ae267ef6

I'll recommend that you don't set --dump-input=never. The link does not provide any information to act on the failure.

********************
Failed Tests (1):
  lld :: ELF/edata-etext.s


Testing Time: 8.11s
  Unsupported:  434
  Passed     : 2166
  Failed     :    1

1 warning(s) in tests