Currently, when LLD do a lookup for variables location, it uses DW_AT_name attribute.
That is not always enough.
Imagine code:
namespace A { int bar = 0; } namespace Z { int bar = 1; } int hoho;
In this case there are 3 variables and their debug attributes are following:
- A::bar has: DW_AT_name [DW_FORM_string] ("bar") DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x00000006] = "_ZN1A3barE")
- Z::bar has: DW_AT_name [DW_FORM_string] ("bar") DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x0000003f] = "_ZN1Z3barE")
- hoho has: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000004a] = "hoho") and has NO DW_AT_linkage_name attribute. Because it would be the same as DW_AT_name and DWARF producers avoids emiting excessive data.
Hence LLD should also use DW_AT_linkage_name when it is available.
(currently, LLD fails to report location correctly because thinks that A::bar and Z::bar are the same things)