[llvm] r354083 - [symbolizer] Avoid collecting symbols belonging to invalid sections.

Matt Davis via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 14 15:50:35 PST 2019


Author: mattd
Date: Thu Feb 14 15:50:35 2019
New Revision: 354083

URL: http://llvm.org/viewvc/llvm-project?rev=354083&view=rev
Log:
[symbolizer] Avoid collecting symbols belonging to invalid sections.

Summary:
llvm-symbolizer would originally report symbols that belonged to an invalid object file section.
Specifically the case where: `*Symbol.getSection() == ObjFile.section_end()`
This patch prevents the Symbolizer from collecting symbols that belong to invalid sections.

The test  (from PR40591) introduces a case where two symbols have address 0,
one symbol is defined, 'foo', and the other is not defined, 'bar'.  This patch will cause
the Symbolizer to keep 'foo' and ignore 'bar'.

As a side note, the logic for adding symbols to the Symbolizer's store
(`SymbolizableObjectFile::addSymbol`) replaces symbols with the
same <address, size> pair.  At some point that logic should be revisited as in the
aforementioned case, 'bar' was overwriting 'foo' in the Symbolizer's store,
and 'foo' was forgotten.

This fixes PR40591

Reviewers: jhenderson, rupprecht

Reviewed By: rupprecht

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58146

Added:
    llvm/trunk/test/tools/llvm-symbolizer/ignore-undefined-symbols.s
Modified:
    llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp

Modified: llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp?rev=354083&r1=354082&r2=354083&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp Thu Feb 14 15:50:35 2019
@@ -136,6 +136,11 @@ std::error_code SymbolizableObjectFile::
                                                   uint64_t SymbolSize,
                                                   DataExtractor *OpdExtractor,
                                                   uint64_t OpdAddress) {
+  // Avoid adding symbols from an unknown/undefined section.
+  const ObjectFile *Obj = Symbol.getObject();
+  Expected<section_iterator> Sec = Symbol.getSection();
+  if (!Sec || (Obj && Obj->section_end() == *Sec))
+    return std::error_code();
   Expected<SymbolRef::Type> SymbolTypeOrErr = Symbol.getType();
   if (!SymbolTypeOrErr)
     return errorToErrorCode(SymbolTypeOrErr.takeError());

Added: llvm/trunk/test/tools/llvm-symbolizer/ignore-undefined-symbols.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/ignore-undefined-symbols.s?rev=354083&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/ignore-undefined-symbols.s (added)
+++ llvm/trunk/test/tools/llvm-symbolizer/ignore-undefined-symbols.s Thu Feb 14 15:50:35 2019
@@ -0,0 +1,12 @@
+# REQUIRES: x86-registered-target
+# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.o -g
+# RUN: llvm-symbolizer --obj=%t.o 0 | FileCheck %s --implicit-check-not=bar
+
+# CHECK:      foo
+# CHECK-NEXT: ignore-undefined-symbols.s:12:0
+
+.type bar, at function
+.type foo, at function
+.global foo
+foo:
+    call bar




More information about the llvm-commits mailing list