[PATCH] D38721: [ELF] - Teach LLD to report line numbers for data symbols.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 20:39:42 PDT 2017


ruiu accepted this revision.
ruiu added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: ELF/InputFiles.cpp:87
+
+  // Get information about global variables location.
+  DWARFCompileUnit *CU = Dwarf.getCompileUnitAtIndex(0);
----------------
Loop over variable records and insert them to VariableLoc.


================
Comment at: ELF/InputFiles.cpp:95
+
+    // Skip variables that are invisible outside the compilation unit.
+    if (!dwarf::toUnsigned(Die.find(dwarf::DW_AT_external), 0))
----------------
Skip if a local variable because we don't need them for generating error messages. In general, only non-local symbols can fail to be linked.


================
Comment at: ELF/InputFiles.cpp:99-100
+
+    // Take file number in the line number information table. Skip if
+    // no source file is available.
+    unsigned File = dwarf::toUnsigned(Die.find(dwarf::DW_AT_decl_file), 0);
----------------
Get the source filename index for the variable.


================
Comment at: ELF/InputFiles.cpp:105
+
+    // Take source line number where declared object appears.
+    unsigned Line = dwarf::toUnsigned(Die.find(dwarf::DW_AT_decl_line), 0);
----------------
Get the line number on which the variable is declared.


================
Comment at: ELF/InputFiles.cpp:108-109
+
+    // Take the name of variable. Ignore it if no name available, it can
+    // happen if some debug information is missing or corrupted.
+    StringRef Name = dwarf::toString(Die.find(dwarf::DW_AT_name), "");
----------------
Get the name of the variable and add the collected information to VariableLoc. Usually Name is non-empty, but it can be empty if the input object file lacks some debug info.


================
Comment at: ELF/InputSection.cpp:287-288
 
-  Optional<DILineInfo> Info = File->getDILineInfo(this, Offset);
+  // We want to get location string here. At first we try to get information
+  // from .debug_line which contains table from offsets to source locations.
+  if (Optional<DILineInfo> Info = File->getDILineInfo(this, Offset))
----------------
// In DWARF, functions and variables are stored to different places.  First, lookup a function for a given offset.


================
Comment at: ELF/InputSection.cpp:292-293
+
+  // If no line information was available, we are trying to take information
+  // from .debug_info section instead.
+  if (Optional<std::pair<std::string, unsigned>> FileLine =
----------------
// If it failed, lookup again as a variable.


https://reviews.llvm.org/D38721





More information about the llvm-commits mailing list