[dsymutil] Track uncloned references in the DIEInfo.
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 20 Dec 2022 19:28:57 +0000 (11:28 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 20 Dec 2022 20:53:17 +0000 (12:53 -0800)
commitc9cbe6937b1fe797f805648216257ae88bde4ad7
tree765ff7b660943d8be55078c0f7bc74f4d29a80af
parent66ba7c32add07204dd0b8a7e0c14b44f0d3b850d
[dsymutil] Track uncloned references in the DIEInfo.

To improve deduplication across CUs within a single object file,
2b747241a6a0 changed the way we track ODR canonical candidates. The
result is that some assumptions no longer hold. Because of the
aforementioned change, the following condition

  assert(Ref > InputDIE.getOffset());

in DWARFLinker::DIECloner::cloneDieReferenceAttribute is no longer an
invariant. An example of a situation where this assertion no longer
holds is when we have decided to replace a backward reference in the
current CU with a forward reference in a subsequent CU. The ODR
canonical DIE hasn't been emitted yet, but the references DIE has an
offset smaller than the current DIE. The assertion is only true if the
referenced DIE was the ODR canonical DIE, which is no longer guaranteed
to be part of the same CU.

Big thanks to Alexey for putting a test together.

Differential revision: https://reviews.llvm.org/D138176
llvm/include/llvm/DWARFLinker/DWARFLinkerCompileUnit.h
llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp
llvm/test/tools/dsymutil/odr-two-units-in-single-file.test [new file with mode: 0644]