Skip to content

Commit

Permalink
libdwarf: allow pointers in DwarfLoc lr_number2
Browse files Browse the repository at this point in the history
For a few DWARF types, a pointer is smuggled through the DwarfLoc
lr_number2 member.  Add a new Dwarf_Uintptr type and use it to allow
this to work on CHERI.  It differs from the standard uintptr_t in that it
is always capable of holding a 64-bit integer.

This allows `readelf -wi /usr/lib/debug/lib/libc.so.7.debug` to succeed.
  • Loading branch information
brooksdavis authored and bsdjhb committed Aug 29, 2024
1 parent e3006e3 commit 1a9b006
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions contrib/elftoolchain/libdwarf/libdwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ typedef uint8_t Dwarf_Small;
typedef int64_t Dwarf_Signed;
typedef uint64_t Dwarf_Addr;
typedef void *Dwarf_Ptr;
#ifdef __CHERI_PURE_CAPABILITY__
typedef uintptr_t Dwarf_Uintptr;
#else
typedef uint64_t Dwarf_Uintptr;
#endif

typedef struct _Dwarf_Abbrev *Dwarf_Abbrev;
typedef struct _Dwarf_Arange *Dwarf_Arange;
Expand Down Expand Up @@ -109,9 +114,9 @@ typedef int (*Dwarf_Callback_Func_b)(char *_name, int _size,
typedef Dwarf_Unsigned Dwarf_Tag;

typedef struct {
Dwarf_Small lr_atom;
Dwarf_Unsigned lr_number;
Dwarf_Unsigned lr_number2;
Dwarf_Small lr_atom;
Dwarf_Unsigned lr_number;
Dwarf_Uintptr lr_number2;
Dwarf_Unsigned lr_offset;
} Dwarf_Loc;

Expand Down
6 changes: 3 additions & 3 deletions contrib/elftoolchain/libdwarf/libdwarf_loc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ _dwarf_loc_fill_loc(Dwarf_Debug dbg, Dwarf_Locdesc *lbuf, uint8_t pointer_size,
{
int count;
uint64_t operand1;
uint64_t operand2;
Dwarf_Uintptr operand2;
uint8_t *ps, *pe, s;

count = 0;
Expand Down Expand Up @@ -293,7 +293,7 @@ _dwarf_loc_fill_loc(Dwarf_Debug dbg, Dwarf_Locdesc *lbuf, uint8_t pointer_size,
case DW_OP_implicit_value:
case DW_OP_GNU_entry_value:
operand1 = _dwarf_decode_uleb128(&p);
operand2 = (Dwarf_Unsigned) (uintptr_t) p;
operand2 = (uintptr_t) p;
p += operand1;
break;

Expand Down Expand Up @@ -343,7 +343,7 @@ _dwarf_loc_fill_loc(Dwarf_Debug dbg, Dwarf_Locdesc *lbuf, uint8_t pointer_size,
*/
case DW_OP_GNU_const_type:
operand1 = _dwarf_decode_uleb128(&p);
operand2 = (Dwarf_Unsigned) (uintptr_t) p;
operand2 = (uintptr_t) p;
s = *p++;
p += s;
break;
Expand Down

0 comments on commit 1a9b006

Please sign in to comment.