[Lldb-commits] [PATCH] D72595: Fix lookup of symbols at the same address with no size vs. size

Jan Kratochvil via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jan 13 03:20:00 PST 2020


jankratochvil created this revision.
jankratochvil added reviewers: labath, omjavaid.
jankratochvil added a project: LLDB.
Herald added a subscriber: kristof.beyls.
jankratochvil planned changes to this revision.
jankratochvil added a parent revision: D63540: Fix lookup of symbols with the same address range but different binding.

The Fedora problem has been fixed by D63540 <https://reviews.llvm.org/D63540>.
But as reported by @omjavaid it regressed arm32: Ubuntu Xenial, Bionic and Debian Buster
I found it also reproducible with on Fedora in chroot with `ubuntu-18.04-server-cloudimg-armhf`.
The regression is due to:

`GetAddressClass` fails to recognized `0x102f0` as a code address:

  PASS:
  (lldb) p (void)sync()
  GetAddressClass:0x102f1
  GetAddressClass:0x102f1=(null) ValueIsAddress=1 section_type=1
  GetAddressClass:0x96040
  GetAddressClass:0x96040=__mmap ValueIsAddress=1 section_type=1
  GetAddressClass:0x102f1
  GetAddressClass:0x102f1=(null) ValueIsAddress=1 section_type=1
  GetAddressClass:0x102f0
  GetAddressClass:0x102f0=(null) ValueIsAddress=1 section_type=1
  ...
  
  FAIL:
  (lldb) p (void)sync()
  GetAddressClass:0x102f1
  GetAddressClass:0x102f1=_start ValueIsAddress=1 section_type=1
  GetAddressClass:0x96040
  GetAddressClass:0x96040=__mmap ValueIsAddress=1 section_type=1
  GetAddressClass:0x102f1
  GetAddressClass:0x102f1=_start ValueIsAddress=1 section_type=1
  GetAddressClass:0x102f0
  ...

That is due to:

  symtab.fail:[   11]     12     Invalid         0x00000000000102f0                    0x0000000000000000 0x00000003
  symtab.fail:[   66]     99   X Code            0x00000000000102f0                    0x0000000000000030 0x00000012 _start
  symtab.pass:[   11]     12     Invalid         0x00000000000102f0                    0x0000000000000030 0x00000003
  symtab.pass:[   66]     99   X Code            0x00000000000102f0                    0x0000000000000030 0x00000012 _start

The difference is in the 'Invalid' symbol which is:

  Num:    Value  Size Type    Bind   Vis      Ndx Name
   12: 000102f0     0 SECTION LOCAL  DEFAULT   12

Apparently ARM32 relies on that section symbol to have proper size. I do not see how `Symtab::InitAddressIndexes` could handle `STT_SECTION` in a special way as that is ELF-type specific `Symbol` characteristics:

  uint32_t m_flags; // A copy of the flags from the original symbol table, the
                    // ObjectFile plug-in can interpret these


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72595

Files:
  lldb/lit/SymbolFile/Inputs/sizeless-symbol.s
  lldb/lit/SymbolFile/sizeless-symbol.test
  lldb/source/Symbol/Symtab.cpp


Index: lldb/source/Symbol/Symtab.cpp
===================================================================
--- lldb/source/Symbol/Symtab.cpp
+++ lldb/source/Symbol/Symtab.cpp
@@ -890,8 +890,14 @@
       for (size_t i = 0; i < num_entries; i++) {
         FileRangeToIndexMap::Entry *entry =
             m_file_addr_to_index.GetMutableEntryAtIndex(i);
-        if (entry->GetByteSize() == 0) {
-          addr_t curr_base_addr = entry->GetRangeBase();
+        if (entry->GetByteSize() > 0)
+          continue;
+        addr_t curr_base_addr = entry->GetRangeBase();
+        // Symbols with non-zero size will show after zero-sized symbols on the
+        // same address. So do not set size of a non-last zero-sized symbol.
+        if (i == num_entries - 1 ||
+            m_file_addr_to_index.GetMutableEntryAtIndex(i + 1)
+                    ->GetRangeBase() != curr_base_addr) {
           const RangeVector<addr_t, addr_t>::Entry *containing_section =
               section_ranges.FindEntryThatContains(curr_base_addr);
 
Index: lldb/lit/SymbolFile/sizeless-symbol.test
===================================================================
--- /dev/null
+++ lldb/lit/SymbolFile/sizeless-symbol.test
@@ -0,0 +1,14 @@
+# Some targets do not have the .size directive.
+# RUN: %clang -target x86_64-unknown-unknown-elf %S/Inputs/sizeless-symbol.s -c -o %t.o
+# RUN: %lldb %t.o -s %s -o quit | FileCheck %s
+
+image lookup --address 1
+# CHECK: Summary: sizeless-symbol.test.tmp.o`sizeful
+image lookup --address 2
+# CHECK: Summary: sizeless-symbol.test.tmp.o`sizeful + 1
+image dump symtab
+# CHECK:     Index   UserID DSX Type            File Address/Value Load Address       Size               Flags      Name
+# CHECK-NEXT:------- ------ --- --------------- ------------------ ------------------ ------------------ ---------- ----------------------------------
+# CHECK-NEXT:[    0]      1     Code            0x0000000000000003                    0x0000000000000000 0x00000000 sizeend
+# CHECK-NEXT:[    1]      2     Code            0x0000000000000001                    0x0000000000000002 0x00000000 sizeful
+# CHECK-NEXT:[    2]      3     Code            0x0000000000000001                    0x0000000000000000 0x00000000 sizeless
Index: lldb/lit/SymbolFile/Inputs/sizeless-symbol.s
===================================================================
--- /dev/null
+++ lldb/lit/SymbolFile/Inputs/sizeless-symbol.s
@@ -0,0 +1,8 @@
+        .text
+        .byte   0
+sizeless:
+sizeful:
+        .byte   0
+        .byte   0
+sizeend:
+        .size   sizeful, sizeend - sizeful


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72595.237611.patch
Type: text/x-patch
Size: 2589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200113/e573abb7/attachment.bin>


More information about the lldb-commits mailing list