objdump/elf: Add support for GNU segments - scc - simple c99 compiler
 (HTM) git clone git://git.simple-cc.org/scc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7b4fef3358a0397fe10577d0b0ce55399953ab7d
 (DIR) parent 9b488b2b643bb7e0cd9a8de14223184f74582c16
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
       Date:   Mon, 17 Feb 2025 20:37:48 +0100
       
       objdump/elf: Add support for GNU segments
       
       Diffstat:
         M include/bits/scc/elf/elfphdr.h      |       5 +++++
         M src/cmd/scc-objdump/elf.c           |      26 +++++++++++++++++++++++---
       
       2 files changed, 28 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/include/bits/scc/elf/elfphdr.h b/include/bits/scc/elf/elfphdr.h
       @@ -14,6 +14,11 @@
        #define PT_LOPROC       0x70000000      /* reserved range for processor */
        #define PT_HIPROC       0x7fffffff      /*  specific segment types */
        
       +#define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550) /* Frame unwind information */
       +#define PT_GNU_STACK    (PT_LOOS + 0x474e551) /* Stack flags */
       +#define PT_GNU_RELRO    (PT_LOOS + 0x474e552) /* Read-only after relocation */
       +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) /* GNU property */
       +
        #define PF_X            1               /* Executable */
        #define PF_W            2               /* Writable */
        #define PF_R            4               /* Readable */
 (DIR) diff --git a/src/cmd/scc-objdump/elf.c b/src/cmd/scc-objdump/elf.c
       @@ -657,7 +657,7 @@ printphdr(Elfphdr *phdr, unsigned long n)
                        [PT_LOAD] = "loadable segment",
                        [PT_DYNAMIC] = "dynamic linking section",
                        [PT_INTERP] = "the RTLD",
       -                [PT_NOTE] = "auxiliary information",
       +                [PT_NOTE] = "note information",
                        [PT_SHLIB] = "reserved - purpose undefined",
                        [PT_PHDR] = "program header",
                        [PT_TLS] = "thread local storage",
       @@ -675,9 +675,29 @@ printphdr(Elfphdr *phdr, unsigned long n)
                        unsigned long type;
                        char *stype;
        
       -                type = phdr->type;
       -                stype = (type <= PT_TLS) ? types[type] : "Unknown";
                        f.flags = phdr->flags;
       +                type = phdr->type;
       +                if (type <= PT_TLS) {
       +                        stype = types[type];
       +                } else {
       +                        switch (type) {
       +                        case PT_GNU_EH_FRAME:
       +                                stype = "Frame unwind information";
       +                                break;
       +                        case PT_GNU_STACK:
       +                                stype = "Stack flags";
       +                                break;
       +                        case PT_GNU_RELRO:
       +                                stype = "Read-only after relocation";
       +                                break;
       +                        case PT_GNU_PROPERTY:
       +                                stype = "GNU property";
       +                                break;
       +                        default:
       +                                stype = "Unknown";
       +                                break;
       +                        }
       +                }
        
                        printf("Program header %ld\n"
                               "\tp_type: %#lx, %s\n"