[BOLT] Give precedence to first AddressMap entries

When parsing AddressMap and there is a conflict in keys,
where two entries share the same key, consider the first entry as the
correct one, instead of the last. This matches previous behavior in
BOLT and covers case such as BOLT creating a new basic block but
sharing the same input offset of the previous (or entry) basic
block. In this case, instead of translating debuginfo to use the newly
created BB, translate using the BB that was originally read from
input. This will increase our chances of getting debuginfo right.

Tested via binary comparison in tests:
X86/dwarf4-df-input-lowpc-ranges.test
X86/dwarf5-df-input-lowpc-ranges.test

Reviewed By: #bolt, maksfb, jobnoorman

Differential Revision: https://reviews.llvm.org/D158686
This commit is contained in:
Rafael Auler 2023-08-23 16:41:58 -07:00
parent 4d27dffb43
commit b5ac1697c8

View File

@ -52,7 +52,8 @@ AddressMap AddressMap::parse(StringRef Buffer, const BinaryContext &BC) {
while (Cursor && !DE.eof(Cursor)) {
const auto Input = DE.getAddress(Cursor);
const auto Output = DE.getAddress(Cursor);
Parsed.Map.insert({Input, Output});
if (!Parsed.Map.count(Input))
Parsed.Map.insert({Input, Output});
}
assert(Cursor && "Error reading address map section");