dwgrep needs to programmatically work with ELF constants, so I put
together the attached script.
The basic idea is the same as with known-dwarf, but elf.h has some extra
challenges to address:
- It's not entirely predictable which constants are bona fide values,
and which are metavalues that e.g. count numbers of other constants,
or e.g. flags. The script handles this by having a whitelist of
constant types to admit, and then some heuristics to remove the
- Arch- and OS-specific values are rather the norm in ELF. I didn't
find any collisions in per-OS ranges, but plenty of them in per-PROC
ranges, so the latter is actually addressed in the generated headers.
The following example illustrates how the facility is used.
/* Per-constant executor. */
#define ELF_ONE_KNOWN_STB(SHORT, LONG) /* ... */
/* Visit generic constants. */
/* STB_ per-arch executor. */
#define ELF_ONE_KNOWN_STB_ARCH(ARCH) \
/* ... */ \
/* Visit STB_ARCH_* constants. */ \
/* ... */
/* Visit arches known for STB_ constants. */
I'm attaching the script as well as the generated .h for preliminary
assesment. Let me know if you think this would be a good addition to
elfutils, and any comments that you might have. If this seems
acceptable, I'll send a full-fledged patch.