Skip to content

radlink: match MSVC for discarded associative COMDAT relocations - #940

Closed
honkstar1 wants to merge 1 commit into
EpicGames:devfrom
honkstar1:codex/radlink-asan-associative-pr
Closed

radlink: match MSVC for discarded associative COMDAT relocations#940
honkstar1 wants to merge 1 commit into
EpicGames:devfrom
honkstar1:codex/radlink-asan-associative-pr

Conversation

@honkstar1

Copy link
Copy Markdown

Summary

Match Microsoft link.exe's handling of relocations to discarded associative COMDAT metadata. This fixes an ASan-instrumented BlankProgram link without disabling ASan, REF, or ICF.

ASan can share a filename string between metadata attached to different COMDAT owners. If the filename's owner loses duplicate selection but another referring owner survives, the existing linker reports Error(031) for the surviving reference. The issue also reproduces with raw COFF, so it is not specific to compressed objects.

Compatibility policy

Microsoft link.exe accepts this case. A small COFF reproducer establishes that the discarded target contributes RVA zero, section zero, and section offset zero. Its original symbol offset is discarded; the relocation addend and ordinary image-base adjustment remain. For example, ADDR64 with addend 5 produces image_base + 5, not a pointer to the winning owner's metadata. Loader base relocations must still be emitted.

LLD 20.1.8 rejects the same discarded-section references. This PR deliberately follows the MSVC behaviour; it does not claim to recover a missing diagnostic filename.

Implementation

  • Tag discarded associative symbols using the existing internal removed-symbol representation, and preserve the tag through symbol fixups.
  • Apply ordinary relocation calculations with a zero target for those tagged references.
  • Keep ordinary removed-section diagnostics and existing debug-relocation handling unchanged.
  • Do not revive discarded sections, redirect to another object's metadata, add new per-symbol storage, or globally suppress relocation errors.

The regression covers both input orders, REF on/off, live and discarded targets, nonzero symbol offsets/addends, ADDR64, ADDR32NB, SECREL, SECTION, REL32, and loader rebasing. It sits with the associative-COMDAT tests, separately from #939's insertion point.

Validation

  • Standalone against dev@47de6bf3; no optimization/compressed-object stack included in this PR.
  • Clang/LLD 20.1.8 Release build; upstream linker suite: 141 passed, 0 failed/crashed, 1 excluded (import_export, whose export-offset assertion was separately reproduced on the unmodified upstream baseline).
  • New regression fails on the unmodified upstream linker and passes with the fix. The same regression passes against Microsoft link.exe 14.51.36231.
  • The standalone PR implementation successfully links the captured raw BlankProgram ASan inputs.
  • The equivalent combined implementation is in test binary/source 5f2c8d69: 183 passed, one existing Microsoft-linker-comparison exclusion; captured BlankProgram links succeed with both compressed and raw objects. An assertion-enabled build also completes the link, with separate VTune CodeView forward-reference diagnostics.

No proprietary Engine objects are added as fixtures. Engine-installed binaries and original inputs were not replaced. The resulting BlankProgram was not launched; no runtime ASan-reporting, farm/Wine/UBA soak, or performance result is claimed.

@NikitaSmith057

Copy link
Copy Markdown
Collaborator

ported fix in 40c2d64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants