Skip to content

Commit

Permalink
dwarf-reader: Ignore zero length location expressions from DW_AT_loca…
Browse files Browse the repository at this point in the history
…tion

Location expressions might occasionally be of length 0. E.g. a reason
for that are thread local variables that do not exactly have a location
to refer to. Compilers/Linkers may choose an empty location description.
E.g. see the dwarfdump output for the added testcase based on
libandroid.so (from AOSP).

$ dwarfdump libandroid.so|egrep -B9 "gChoreographerE$"

LOCAL_SYMBOLS:
< 1><0x00000022> DW_TAG_namespace
                   DW_AT_name           android
< 2><0x00000027>   DW_TAG_variable
                     DW_AT_name           gChoreographer
                     DW_AT_type           <0x00000b65>
                     DW_AT_decl_file      0x00000003 .../choreographer.cpp
                     DW_AT_decl_line      0x00000059
                     DW_AT_location       len 0x0000: :
                     DW_AT_linkage_name   _ZN7androidL14gChoreographerE

The DW_AT_location is properly read by elfutils' dwarf_location(), but
is not useful for us to proceed with. Hence early exit on this.

	* src/abg-dwarf-reader.cc (die_location_expr): Ignore zero
	  length location expressions.
	* tests/data/Makefile.am: Add new test files.
	* tests/data/test-read-dwarf/test-libandroid.so: New test file.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/test-read-dwarf.cc: Add new test case.

Reported-by: Dan Albert <danalbert@google.com>
Reviewed-by: Giuliano Procida <gprocida@google.com>
Cc: Mark Wielaard <mark@klomp.org>
Signed-off-by: Matthias Maennich <maennich@google.com>
  • Loading branch information
metti committed Oct 29, 2020
1 parent 22644b4 commit eb8c694
Show file tree
Hide file tree
Showing 5 changed files with 86,964 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/abg-dwarf-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9385,9 +9385,9 @@ compare_dies_cu_decl_file(const Dwarf_Die* l, const Dwarf_Die *r, bool &result)
/// @param expr_len the length of the resulting dwarf expression.
/// This is set iff the function returns true.
///
/// @return true if the attribute exists and has a dwarf expression as
/// value. In that case the expr and expr_len arguments are set to
/// the resulting dwarf exprssion.
/// @return true if the attribute exists and has a non-empty dwarf expression
/// as value. In that case the expr and expr_len arguments are set to the
/// resulting dwarf expression.
static bool
die_location_expr(const Dwarf_Die* die,
unsigned attr_name,
Expand All @@ -9404,6 +9404,9 @@ die_location_expr(const Dwarf_Die* die,
size_t len = 0;
bool result = (dwarf_getlocation(&attr, expr, &len) == 0);

// Ignore location expressions where reading succeeded but their length is 0.
result &= len > 0;

if (result)
*expr_len = len;

Expand Down
2 changes: 2 additions & 0 deletions tests/data/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ test-read-dwarf/test-PR26568-2.o \
test-read-dwarf/test-PR26568-1.o \
test-read-dwarf/test-PR26568-1.o.abi \
test-read-dwarf/test-PR26568-2.o.abi \
test-read-dwarf/test-libandroid.so \
test-read-dwarf/test-libandroid.so.abi \
\
test-annotate/test0.abi \
test-annotate/test1.abi \
Expand Down
Binary file added tests/data/test-read-dwarf/test-libandroid.so
Binary file not shown.
Loading

0 comments on commit eb8c694

Please sign in to comment.