Skip to content

Commit 98a335d

Browse files
dumper for SHT_NOTE
1 parent a94a82b commit 98a335d

File tree

8 files changed

+694
-197
lines changed

8 files changed

+694
-197
lines changed

src/dwarf/dwarf_elf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dw_is_dwarf_present_from_elf_bin(String8 data, ELF_Bin *bin)
88
for EachIndex(idx, bin->shdrs.count)
99
{
1010
ELF_Shdr64 *shdr = &bin->shdrs.v[idx];
11-
if(shdr->sh_type != ELF_SectionCode_ProgBits) { continue; }
11+
if(shdr->sh_type != ELF_ShType_ProgBits) { continue; }
1212
String8 name = elf_name_from_shdr64(data, bin, shdr);
1313
DW_SectionKind s = dw_section_kind_from_string(name);
1414
if(s == DW_Section_Null)
@@ -35,7 +35,7 @@ dw_input_from_elf_bin(Arena *arena, String8 data, ELF_Bin *bin)
3535
for(U64 section_idx = 1; section_idx < bin->shdrs.count; section_idx += 1)
3636
{
3737
ELF_Shdr64 *shdr = &bin->shdrs.v[section_idx];
38-
if(shdr->sh_type != ELF_SectionCode_ProgBits) { continue; } // skip BSS sections
38+
if(shdr->sh_type != ELF_ShType_ProgBits) { continue; } // skip BSS sections
3939

4040
//- rjf: unpack section
4141
String8 section_name = elf_name_from_shdr64(data, bin, shdr);

src/elf/elf.h

Lines changed: 53 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -151,40 +151,42 @@ enum
151151
ELF_PFlag_Read = (1 << 2),
152152
};
153153

154-
typedef U32 ELF_SectionCode;
154+
typedef U32 ELF_ShType;
155155
enum
156156
{
157-
ELF_SectionCode_Null = 0,
158-
ELF_SectionCode_ProgBits = 1,
159-
ELF_SectionCode_Symtab = 2,
160-
ELF_SectionCode_Strtab = 3,
161-
ELF_SectionCode_Rela = 4,
162-
ELF_SectionCode_Hash = 5,
163-
ELF_SectionCode_Dynamic = 6,
164-
ELF_SectionCode_Note = 7,
165-
ELF_SectionCode_NoBits = 8,
166-
ELF_SectionCode_Rel = 9,
167-
ELF_SectionCode_Shlib = 10,
168-
ELF_SectionCode_Dynsym = 11,
169-
ELF_SectionCode_InitArray = 14,
170-
ELF_SectionCode_FiniArray = 15, // Array of ptrs to init functions
171-
ELF_SectionCode_PreinitArray = 16, // Array of ptrs to finish functions
172-
ELF_SectionCode_Group = 17, // Array of ptrs to pre-init funcs
173-
ELF_SectionCode_SymtabShndx = 18, // Section contains a section group
174-
ELF_SectionCode_GNU_IncrementalInputs = 0x6fff4700, // Indices for SHN_XINDEX entries
175-
ELF_SectionCode_GNU_Attributes = 0x6ffffff5, // Incremental build data
176-
ELF_SectionCode_GNU_Hash = 0x6ffffff6, // Object attributes
177-
ELF_SectionCode_GNU_LibList = 0x6ffffff7, // GNU style symbol hash table
178-
ELF_SectionCode_SUNW_verdef = 0x6ffffffd,
179-
ELF_SectionCode_SUNW_verneed = 0x6ffffffe, // Versions defined by file
180-
ELF_SectionCode_SUNW_versym = 0x6fffffff, // Versions needed by file
157+
ELF_ShType_Null = 0,
158+
ELF_ShType_ProgBits = 1,
159+
ELF_ShType_Symtab = 2,
160+
ELF_ShType_Strtab = 3,
161+
ELF_ShType_Rela = 4,
162+
ELF_ShType_Hash = 5,
163+
ELF_ShType_Dynamic = 6,
164+
ELF_ShType_Note = 7,
165+
ELF_ShType_NoBits = 8,
166+
ELF_ShType_Rel = 9,
167+
ELF_ShType_Shlib = 10,
168+
ELF_ShType_Dynsym = 11,
169+
ELF_ShType_InitArray = 14,
170+
ELF_ShType_FiniArray = 15, // Array of ptrs to init functions
171+
ELF_ShType_PreinitArray = 16, // Array of ptrs to finish functions
172+
ELF_ShType_Group = 17, // Array of ptrs to pre-init funcs
173+
ELF_ShType_SymtabShndx = 18, // Section contains a section group
174+
175+
ELF_ShType_GNU_IncrementalInputs = 0x6fff4700, // Indices for SHN_XINDEX entries
176+
ELF_ShType_GNU_Attributes = 0x6ffffff5, // Incremental build data
177+
ELF_ShType_GNU_Hash = 0x6ffffff6, // Object attributes
178+
ELF_ShType_GNU_LibList = 0x6ffffff7, // GNU style symbol hash table
179+
180+
ELF_ShType_SUNW_verdef = 0x6ffffffd,
181+
ELF_ShType_SUNW_verneed = 0x6ffffffe, // Versions defined by file
182+
ELF_ShType_SUNW_versym = 0x6fffffff, // Versions needed by file
181183

182184
// Symbol versions
183-
ELF_SectionCode_GNU_verdef = ELF_SectionCode_SUNW_verdef,
184-
ELF_SectionCode_GNU_verneed = ELF_SectionCode_SUNW_verneed,
185-
ELF_SectionCode_GNU_versym = ELF_SectionCode_SUNW_versym,
186-
ELF_SectionCode_Proc,
187-
ELF_SectionCode_User,
185+
ELF_ShType_GNU_verdef = ELF_ShType_SUNW_verdef,
186+
ELF_ShType_GNU_verneed = ELF_ShType_SUNW_verneed,
187+
ELF_ShType_GNU_versym = ELF_ShType_SUNW_versym,
188+
ELF_ShType_Proc,
189+
ELF_ShType_User,
188190
};
189191

190192
typedef U32 ELF_SectionIndex;
@@ -527,140 +529,7 @@ enum
527529
typedef U32 ELF_NoteType;
528530
enum
529531
{
530-
ELF_NoteType_GNU_Abi = 1,
531-
ELF_NoteType_GNU_HwCap = 2,
532-
ELF_NoteType_GNU_BuildId = 3,
533-
ELF_NoteType_GNU_GoldVersion = 4,
534-
ELF_NoteType_GNU_PropertyType0 = 5,
535-
};
536-
537-
typedef U32 ELF_GnuABITag;
538-
enum
539-
{
540-
ELF_GnuABITag_Linux = 0,
541-
ELF_GnuABITag_Hurd = 1,
542-
ELF_GnuABITag_Solaris = 2,
543-
ELF_GnuABITag_FreeBsd = 3,
544-
ELF_GnuABITag_NetBsd = 4,
545-
ELF_GnuABITag_Syllable = 5,
546-
ELF_GnuABITag_Nacl = 6,
547-
};
548-
549-
typedef S32 ELF_GnuProperty;
550-
enum
551-
{
552-
ELF_GnuProperty_LoProc = 0xc0000000,
553-
// processor-specific range
554-
ELF_GnuProperty_HiProc = 0xdfffffff,
555-
ELF_GnuProperty_LoUser = 0xe0000000,
556-
// application-specific range
557-
ELF_GnuProperty_HiUser = 0xffffffff,
558-
ELF_GnuProperty_StackSize = 1,
559-
ELF_GnuProperty_NoCopyOnProtected = 2,
560-
};
561-
562-
typedef U32 ELF_GnuPropertyX86Isa1;
563-
enum
564-
{
565-
ELF_GnuPropertyX86Isa1_BaseLine = (1 << 0),
566-
ELF_GnuPropertyX86Isa1_V2 = (1 << 1),
567-
ELF_GnuPropertyX86Isa1_V3 = (1 << 2),
568-
ELF_GnuPropertyX86Isa1_V4 = (1 << 3),
569-
};
570-
571-
typedef U32 ELF_GnuPropertyX86Compat1Isa1;
572-
enum
573-
{
574-
ELF_GnuPropertyX86Compat1Isa1_486 = (1 << 0),
575-
ELF_GnuPropertyX86Compat1Isa1_586 = (1 << 1),
576-
ELF_GnuPropertyX86Compat1Isa1_686 = (1 << 2),
577-
ELF_GnuPropertyX86Compat1Isa1_SSE = (1 << 3),
578-
ELF_GnuPropertyX86Compat1Isa1_SSE2 = (1 << 4),
579-
ELF_GnuPropertyX86Compat1Isa1_SSE3 = (1 << 5),
580-
ELF_GnuPropertyX86Compat1Isa1_SSSE3 = (1 << 6),
581-
ELF_GnuPropertyX86Compat1Isa1_SSE4_1 = (1 << 7),
582-
ELF_GnuPropertyX86Compat1Isa1_SSE4_2 = (1 << 8),
583-
ELF_GnuPropertyX86Compat1Isa1_AVX = (1 << 9),
584-
ELF_GnuPropertyX86Compat1Isa1_AVX2 = (1 << 10),
585-
ELF_GnuPropertyX86Compat1Isa1_AVX512F = (1 << 11),
586-
ELF_GnuPropertyX86Compat1Isa1_AVX512ER = (1 << 12),
587-
ELF_GnuPropertyX86Compat1Isa1_AVX512PF = (1 << 13),
588-
ELF_GnuPropertyX86Compat1Isa1_AVX512VL = (1 << 14),
589-
ELF_GnuPropertyX86Compat1Isa1_AVX512DQ = (1 << 15),
590-
ELF_GnuPropertyX86Compat1Isa1_AVX512BW = (1 << 16),
591-
};
592-
593-
typedef U32 ELF_GnuPropertyX86Compat2Isa1;
594-
enum
595-
{
596-
ELF_GnuPropertyX86Compat2Isa1_CMOVE = (1 << 0),
597-
ELF_GnuPropertyX86Compat2Isa1_SSE = (1 << 1),
598-
ELF_GnuPropertyX86Compat2Isa1_SSE2 = (1 << 2),
599-
ELF_GnuPropertyX86Compat2Isa1_SSE3 = (1 << 3),
600-
ELF_GnuPropertyX86Compat2Isa1_SSE4_1 = (1 << 4),
601-
ELF_GnuPropertyX86Compat2Isa1_SSE4_2 = (1 << 5),
602-
ELF_GnuPropertyX86Compat2Isa1_AVX = (1 << 6),
603-
ELF_GnuPropertyX86Compat2Isa1_AVX2 = (1 << 7),
604-
ELF_GnuPropertyX86Compat2Isa1_FMA = (1 << 8),
605-
ELF_GnuPropertyX86Compat2Isa1_AVX512F = (1 << 9),
606-
ELF_GnuPropertyX86Compat2Isa1_AVX512CD = (1 << 10),
607-
ELF_GnuPropertyX86Compat2Isa1_AVX512ER = (1 << 11),
608-
ELF_GnuPropertyX86Compat2Isa1_AVX512PF = (1 << 12),
609-
ELF_GnuPropertyX86Compat2Isa1_AVX512VL = (1 << 13),
610-
ELF_GnuPropertyX86Compat2Isa1_AVX512DQ = (1 << 14),
611-
ELF_GnuPropertyX86Compat2Isa1_AVX512BW = (1 << 15),
612-
ELF_GnuPropertyX86Compat2Isa1_AVX512_4FMAPS = (1 << 16),
613-
ELF_GnuPropertyX86Compat2Isa1_AVX512_4VNNIW = (1 << 17),
614-
ELF_GnuPropertyX86Compat2Isa1_AVX512_BITALG = (1 << 18),
615-
ELF_GnuPropertyX86Compat2Isa1_AVX512_IFMA = (1 << 19),
616-
ELF_GnuPropertyX86Compat2Isa1_AVX512_VBMI = (1 << 20),
617-
ELF_GnuPropertyX86Compat2Isa1_AVX512_VBMI2 = (1 << 21),
618-
ELF_GnuPropertyX86Compat2Isa1_AVX512_VNNI = (1 << 22),
619-
ELF_GnuPropertyX86Compat2Isa1_AVX512_BF16 = (1 << 23),
620-
};
621-
622-
typedef S32 ELF_GnuPropertyX86;
623-
enum
624-
{
625-
ELF_GnuPropertyX86_Feature1And = 0xc0000002,
626-
ELF_GnuPropertyX86_Feature2Used = 0xc0010001,
627-
ELF_GnuPropertyX86_Isa1needed = 0xc0008002,
628-
ELF_GnuPropertyX86_Isa2Needed = 0xc0008001,
629-
ELF_GnuPropertyX86_Isa1Used = 0xc0010002,
630-
ELF_GnuPropertyX86_Compat_isa_1_used = 0xc0000000,
631-
ELF_GnuPropertyX86_Compat_isa_1_needed = 0xc0000001,
632-
ELF_GnuPropertyX86_UInt32AndLo = ELF_GnuPropertyX86_Feature1And,
633-
ELF_GnuPropertyX86_UInt32AndHi = 0xc0007fff,
634-
ELF_GnuPropertyX86_UInt32OrLo = 0xc0008000,
635-
ELF_GnuPropertyX86_UInt32OrHi = 0xc000ffff,
636-
ELF_GnuPropertyX86_UInt32OrAndLo = 0xc0010000,
637-
ELF_GnuPropertyX86_UInt32OrAndHi = 0xc0017fff,
638-
};
639-
640-
typedef U32 ELF_GnuPropertyX86Feature1;
641-
enum
642-
{
643-
ELF_GnuPropertyX86Feature1_Ibt = (1 << 0),
644-
ELF_GnuPropertyX86Feature1_Shstk = (1 << 1),
645-
ELF_GnuPropertyX86Feature1_LamU48 = (1 << 2),
646-
ELF_GnuPropertyX86Feature1_LamU57 = (1 << 3),
647-
};
648-
649-
typedef U32 ELF_GnuPropertyX86Feature2;
650-
enum
651-
{
652-
ELF_GnuPropertyX86Feature2_X86 = (1 << 0),
653-
ELF_GnuPropertyX86Feature2_X87 = (1 << 1),
654-
ELF_GnuPropertyX86Feature2_MMX = (1 << 2),
655-
ELF_GnuPropertyX86Feature2_XMM = (1 << 3),
656-
ELF_GnuPropertyX86Feature2_YMM = (1 << 4),
657-
ELF_GnuPropertyX86Feature2_ZMM = (1 << 5),
658-
ELF_GnuPropertyX86Feature2_FXSR = (1 << 6),
659-
ELF_GnuPropertyX86Feature2_XSAVE = (1 << 7),
660-
ELF_GnuPropertyX86Feature2_XSAVEOPT = (1 << 8),
661-
ELF_GnuPropertyX86Feature2_XSAVEC = (1 << 9),
662-
ELF_GnuPropertyX86Feature2_TMM = (1 << 10),
663-
ELF_GnuPropertyX86Feature2_MASK = (1 << 11),
532+
ELF_NoteType_STapSdt = 3, // System Tap probes
664533
};
665534

666535
#define ELF_HdrIs64Bit(e_ident) (e_ident[ELF_Identifier_Class] == ELF_Class_64)
@@ -721,30 +590,30 @@ typedef struct ELF_Hdr32
721590

722591
typedef struct ELF_Shdr64
723592
{
724-
U32 sh_name;
725-
U32 sh_type;
726-
U64 sh_flags;
727-
U64 sh_addr;
728-
U64 sh_offset;
729-
U64 sh_size;
730-
U32 sh_link;
731-
U32 sh_info;
732-
U64 sh_addralign;
733-
U64 sh_entsize;
593+
U32 sh_name;
594+
ELF_ShType sh_type;
595+
U64 sh_flags;
596+
U64 sh_addr;
597+
U64 sh_offset;
598+
U64 sh_size;
599+
U32 sh_link;
600+
U32 sh_info;
601+
U64 sh_addralign;
602+
U64 sh_entsize;
734603
} ELF_Shdr64;
735604

736605
typedef struct ELF_Shdr32
737606
{
738-
U32 sh_name;
739-
U32 sh_type;
740-
U32 sh_flags;
741-
U32 sh_addr;
742-
U32 sh_offset;
743-
U32 sh_size;
744-
U32 sh_link;
745-
U32 sh_info;
746-
U32 sh_addralign;
747-
U32 sh_entsize;
607+
U32 sh_name;
608+
ELF_ShType sh_type;
609+
U32 sh_flags;
610+
U32 sh_addr;
611+
U32 sh_offset;
612+
U32 sh_size;
613+
U32 sh_link;
614+
U32 sh_info;
615+
U32 sh_addralign;
616+
U32 sh_entsize;
748617
} ELF_Shdr32;
749618

750619
typedef struct ELF_Phdr64

0 commit comments

Comments
 (0)