[Bug backends/27564] New: arm: Use correct address when comparing symbol values

mark at klomp dot org sourceware-bugzilla@sourceware.org
Thu Mar 11 17:11:48 GMT 2021


https://sourceware.org/bugzilla/show_bug.cgi?id=27564

            Bug ID: 27564
           Summary: arm: Use correct address when comparing symbol values
           Product: elfutils
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: backends
          Assignee: unassigned at sourceware dot org
          Reporter: mark at klomp dot org
                CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

arm32 has special rules for the symbol value.

https://static.docs.arm.com/ihi0044/g/aaelf32.pdf

Section 5.5.3 Symbol Values

•  If the symbol addresses a Thumb instruction, its value is the address of the
instruction with bit zero set (in a relocatable object, the section offset with
bit zero set).

 This allows a linker to distinguish Arm and Thumb code symbols without having
to refer to the map.  An Arm symbol will always have an even value, while a
Thumb symbol will always have an odd value.

We already have ebl_func_addr_mask which is used frame_unwind. But it isn't
consistently used when searching for and matching symbols by address.

This causes e.g. the libabigail ./tests/data/test-read-dwarf/test-libandroid.so
to produce wrong function names:

 $ eu-readelf --debug-dump=info ./tests/data/test-read-dwarf/test-libandroid.so
| grep -2 AAssetDir_close | head -4
  [ 2498b]    subprogram           abbrev: 140
              low_pc               (addr) +0x0000ce62 <AAssetDir_rewind+0x5>
              high_pc              (data4) 38 (+0x0000ce88
<AAssetDir_close+0x25>)
              frame_base           (exprloc) 
 $ eu-readelf -s ./tests/data/test-read-dwarf/test-libandroid.so | grep
AAssetDir_close
   500: 0000ce63     38 FUNC    GLOBAL DEFAULT       15
AAssetDir_close@@LIBANDROID
  1618: 0000ce63     38 FUNC    GLOBAL DEFAULT       15 AAssetDir_close

Possible fix:

diff --git a/libdwfl/dwfl_module_addrsym.c b/libdwfl/dwfl_module_addrsym.c
index 2336b602..33841f5d 100644
--- a/libdwfl/dwfl_module_addrsym.c
+++ b/libdwfl/dwfl_module_addrsym.c
@@ -251,7 +251,7 @@ __libdwfl_addrsym (Dwfl_Module *_mod, GElf_Addr _addr,
GElf_Off *off,

   struct search_state state =
     {
-      .addr = _addr,
+      .addr = _addr & ebl_func_addr_mask (_mod->ebl),
       .mod = _mod,
       .closest_sym = _closest_sym,
       .adjust_st_value = _adjust_st_value,
diff --git a/libdwfl/dwfl_module_getsym.c b/libdwfl/dwfl_module_getsym.c
index 8de9a3eb..c46b1310 100644
--- a/libdwfl/dwfl_module_getsym.c
+++ b/libdwfl/dwfl_module_getsym.c
@@ -179,6 +179,7 @@ __libdwfl_getsym (Dwfl_Module *mod, int ndx, GElf_Sym *sym,
GElf_Addr *addr,
       break;
     }

+  st_value &= ebl_func_addr_mask (mod->ebl);
   if (adjust_st_value)
     sym->st_value = st_value;


Then eu-readelf produces:

 [ 2498b]    subprogram           abbrev: 140
             low_pc               (addr) +0x0000ce62 <AAssetDir_close>
             high_pc              (data4) 38 (+0x0000ce88 <AAsset_read>)
             frame_base           (exprloc) 

We possibly only should do this for STT_FUNC symbols.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Elfutils-devel mailing list