[dsymutil] Fix .debug_addr index calculation
authorJonas Devlieghere <jonas@devlieghere.com>
Fri, 16 Jun 2023 19:24:27 +0000 (12:24 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 16 Jun 2023 20:27:32 +0000 (13:27 -0700)
commit8119ab9bf78b3c0af26eb820527be1193a77c97d
tree9bde427c88043736b3df05fab8a90a506829e864
parent70b1c3999c912c81f2783112980dc2fa7bef270b
[dsymutil] Fix .debug_addr index calculation

The DW_OP_addrx operation encodes a zero-based index into the
.debug_addr section. The index is relative to the DW_AT_addr_base
attribute of the associated compilation unit. In order to compute the
offset into the .debug_addr section and find the associated relocation,
we need to add the add the add base offset and multiply the index with
the address size.

This patch fixes a bug in this computation, where the multiplication was
omitted. This went unnoticed because for small test cases, the index for
interesting addresses (such as the main subprogram) is often zero.

rdar://110881668

Differential revision: https://reviews.llvm.org/D153162
llvm/test/tools/dsymutil/ARM/dwarf5-addrx-0x0-last.test [new file with mode: 0644]
llvm/test/tools/dsymutil/Inputs/private/tmp/dwarf5/dwarf5-addrx-0x0-last.o [new file with mode: 0644]
llvm/test/tools/dsymutil/Inputs/private/tmp/dwarf5/dwarf5-addrx-0x0-last.out [new file with mode: 0755]
llvm/tools/dsymutil/DwarfLinkerForBinary.cpp