Author: csjp
Date: Fri Jun  7 14:51:55 2019
New Revision: 348776
URL: https://svnweb.freebsd.org/changeset/base/348776

Log:
  Teach readelf about some OpenBSD ELF program headers
  
  - Add constants for OpenBSD wxneeded, bootdata and randomize to the
    FreeBSD elf_common.h file. This is the file that gets used by the
    elftoolchain library.
  - Update readelf and elfdump utilities to decode these program headers
    if they are encountered.
  
  Note: FreeBSD has it's own version of elfdump(1), which will be updated
  in a subsequent commit. I am adding it here anyway because this diff is
  going to be submitted upstream.
  
  Discussed with:       emaste
  Reviewed by:  imp
  MFC afer:     2 weeks
  Differential Revision:        https://reviews.freebsd.org/D20548
  
  M    contrib/elftoolchain/elfdump/elfdump.c
  M    contrib/elftoolchain/readelf/readelf.c
  M    sys/sys/elf_common.h

Modified:
  head/contrib/elftoolchain/elfdump/elfdump.c
  head/contrib/elftoolchain/readelf/readelf.c
  head/sys/sys/elf_common.h

Modified: head/contrib/elftoolchain/elfdump/elfdump.c
==============================================================================
--- head/contrib/elftoolchain/elfdump/elfdump.c Fri Jun  7 10:09:43 2019        
(r348775)
+++ head/contrib/elftoolchain/elfdump/elfdump.c Fri Jun  7 14:51:55 2019        
(r348776)
@@ -343,17 +343,20 @@ elf_phdr_type_str(unsigned int type)
        static char s_type[32];
 
        switch (type) {
-       case PT_NULL:           return "PT_NULL";
-       case PT_LOAD:           return "PT_LOAD";
-       case PT_DYNAMIC:        return "PT_DYNAMIC";
-       case PT_INTERP:         return "PT_INTERP";
-       case PT_NOTE:           return "PT_NOTE";
-       case PT_SHLIB:          return "PT_SHLIB";
-       case PT_PHDR:           return "PT_PHDR";
-       case PT_TLS:            return "PT_TLS";
-       case PT_GNU_EH_FRAME:   return "PT_GNU_EH_FRAME";
-       case PT_GNU_STACK:      return "PT_GNU_STACK";
-       case PT_GNU_RELRO:      return "PT_GNU_RELRO";
+       case PT_NULL:                   return "PT_NULL";
+       case PT_LOAD:                   return "PT_LOAD";
+       case PT_DYNAMIC:                return "PT_DYNAMIC";
+       case PT_INTERP:                 return "PT_INTERP";
+       case PT_NOTE:                   return "PT_NOTE";
+       case PT_SHLIB:                  return "PT_SHLIB";
+       case PT_PHDR:                   return "PT_PHDR";
+       case PT_TLS:                    return "PT_TLS";
+       case PT_GNU_EH_FRAME:           return "PT_GNU_EH_FRAME";
+       case PT_GNU_STACK:              return "PT_GNU_STACK";
+       case PT_GNU_RELRO:              return "PT_GNU_RELRO";
+       case PT_OPENBSD_RANDOMIZE:      return "PT_OPENBSD_RANDOMIZE";
+       case PT_OPENBSD_WXNEEDED:       return "PT_OPENBSD_WXNEEDED";
+       case PT_OPENBSD_BOOTDATA:       return "PT_OPENBSD_BOOTDATA";
        }
        snprintf(s_type, sizeof(s_type), "<unknown: %#x>", type);
        return (s_type);

Modified: head/contrib/elftoolchain/readelf/readelf.c
==============================================================================
--- head/contrib/elftoolchain/readelf/readelf.c Fri Jun  7 10:09:43 2019        
(r348775)
+++ head/contrib/elftoolchain/readelf/readelf.c Fri Jun  7 14:51:55 2019        
(r348776)
@@ -674,6 +674,9 @@ phdr_type(unsigned int mach, unsigned int ptype)
        case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
        case PT_GNU_STACK: return "GNU_STACK";
        case PT_GNU_RELRO: return "GNU_RELRO";
+       case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE";
+       case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED";
+       case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA";
        default:
                if (ptype >= PT_LOOS && ptype <= PT_HIOS)
                        snprintf(s_ptype, sizeof(s_ptype), "LOOS+%#x",

Modified: head/sys/sys/elf_common.h
==============================================================================
--- head/sys/sys/elf_common.h   Fri Jun  7 10:09:43 2019        (r348775)
+++ head/sys/sys/elf_common.h   Fri Jun  7 14:51:55 2019        (r348776)
@@ -535,6 +535,10 @@ typedef struct {
 #define        PT_ARM_EXIDX    0x70000001      /* ARM exception unwind tables. 
*/
 #define        PT_HIPROC       0x7fffffff      /* Last processor-specific 
type. */
 
+#define        PT_OPENBSD_RANDOMIZE    0x65A3DBE6      /* OpenBSD random data 
segment */
+#define        PT_OPENBSD_WXNEEDED     0x65A3DBE7      /* OpenBSD EXEC/WRITE 
pages needed */
+#define        PT_OPENBSD_BOOTDATA     0x65A41BE6      /* OpenBSD section for 
boot args */
+
 /* Values for p_flags. */
 #define        PF_X            0x1             /* Executable. */
 #define        PF_W            0x2             /* Writable. */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to