This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Also use DW_AT_linkage_name when gathering information about variables for error messages.
ClosedPublic

Authored by grimar on May 25 2018, 6:50 AM.

Details

Summary

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:

  1. A::bar has: DW_AT_name [DW_FORM_string] ("bar") DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x00000006] = "_ZN1A3barE")
  1. Z::bar has: DW_AT_name [DW_FORM_string] ("bar") DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x0000003f] = "_ZN1Z3barE")
  1. 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)

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.May 25 2018, 6:50 AM
peter.smith accepted this revision.Jun 1 2018, 3:06 AM
peter.smith added a subscriber: peter.smith.

This looks sensible to me. If I've got this right when the DW_AT_linkage name differs from the DW_AT_name the symbol name will match the DW_AT_linkage_name so the lookup by symbol name won't succeed if done via DW_AT_name.

This revision is now accepted and ready to land.Jun 1 2018, 3:06 AM
grimar added a comment.Jun 1 2018, 3:09 AM

This looks sensible to me. If I've got this right when the DW_AT_linkage name differs from the DW_AT_name the symbol name will match the DW_AT_linkage_name so the lookup by symbol name won't succeed if done via DW_AT_name.

Yes, that is the case. Thanks!

This revision was automatically updated to reflect the committed changes.