I'm not sure that DW_CIE_ID belongs in dwarf.h as it is.
The CIE_id value is 0xffffffff only in 32-bit DWARF. In 64-bit DWARF, it's 0xffffffffffffffff.
So there isn't a single value that is correct for DW_CIE_ID.
In my unwind branch, I didn't add any CIE_id constant to dwarf.h at all. Instead, I only use a header parser (dwarf_next_cfi) that canonicalizes the CIE_id/CIE_pointer field to a Dwarf_Off (i.e. 64 bits) and so the single CIE_ID constant I provide is the 64-bit one. (That's all in unwind.h on the branch, but would go in libdw.h when merged.)
But dwarf.h is for the literal format constants in raw form, not for canonicalized constants in the libdw interface. So if anything is in dwarf.h for this, I think it has to be both of the two variants with variant names. e.g. DW32_CIE_ID and DW64_CIE_ID. (Or maybe it's better to keep the uniform DW_ prefix and make them DW_CIE_ID_{32,64} or some other names.)
i.e. like the patch below. This works fine for me, but I am a little worried that the 64-bit constant in an enum might upset the compiler (version or anality switch-set) used for some application's build.
What say you?
Thanks, Roland
======
diff --git a/libdw/dwarf.h b/libdw/dwarf.h index 3b9d40c..0000000 100644 --- a/libdw/dwarf.h +++ b/libdw/dwarf.h @@ -677,7 +677,8 @@ enum /* ID indicating CIE as opposed to FDE in .debug_frame. */ enum { - DW_CIE_ID = 0xffffffff + DW32_CIE_ID = 0xffffffff, + DW64_CIE_ID = 0xffffffffffffffff };
diff --git a/src/readelf.c b/src/readelf.c index f4ed033..0000000 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -4673,9 +4673,13 @@ print_debug_frame_section (Dwfl_Module * if (unlikely (cieend > dataend || readp + 8 > dataend)) goto invalid_data;
- Dwarf_Word cie_id; + Dwarf_Off cie_id; if (length == 4) - cie_id = read_4ubyte_unaligned_inc (dbg, readp); + { + cie_id = read_4ubyte_unaligned_inc (dbg, readp); + if (!is_eh_frame && cie_id == DW32_CIE_ID) + cie_id = DW64_CIE_ID; + } else cie_id = read_8ubyte_unaligned_inc (dbg, readp);
@@ -4686,7 +4690,7 @@ print_debug_frame_section (Dwfl_Module * Dwarf_Word initial_location = 0; Dwarf_Word vma_base = 0;
- if (cie_id == (is_eh_frame ? 0 : DW_CIE_ID)) + if (cie_id == (is_eh_frame ? 0 : DW64_CIE_ID)) { uint_fast8_t version = *readp++; const char *const augmentation = (const char *) readp;
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Roland McGrath wrote:
The CIE_id value is 0xffffffff only in 32-bit DWARF. In 64-bit DWARF, it's 0xffffffffffffffff.
Make it a signed value which automatically extend to the larger type?
Probably error prone. I'm fine with DW_CIE_ID_{32,64}.
- -- ➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
elfutils-devel@lists.fedorahosted.org