Bug 26405 - [objdump, readelf] - PT_OPENBSD_* segments are not recognised.
Summary: [objdump, readelf] - PT_OPENBSD_* segments are not recognised.
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-19 12:26 UTC by georgerim
Modified: 2020-08-27 08:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
sample test object with PT_OPENBSD_* segments (92 bytes, application/x-executable)
2020-08-19 12:26 UTC, georgerim
Details

Note You need to log in before you can comment on or make changes to this bug.
Description georgerim 2020-08-19 12:26:31 UTC
Created attachment 12779 [details]
sample test object with PT_OPENBSD_* segments

Currently, both objdump/readelf tools do not recognise PT_OPENBSD_* segments,
defined as:

PT_OPENBSD_RANDOMIZE = 0x65a3dbe6, // Fill with random data.
PT_OPENBSD_WXNEEDED = 0x65a3dbe7,  // Program does W^X violations.
PT_OPENBSD_BOOTDATA = 0x65a41be6,  // Section for boot arguments.

E.g., "objdump -p 1.o" prints:

Program Header:
0x65a3dbe6 off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags ---
0x65a3dbe7 off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags ---
0x65a41be6 off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags ---

The expected output is:

OPENBSD_RANDOMIZE off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0
     filesz 0x0000000000000000 memsz 0x0000000000000000 flags ---
OPENBSD_WXNEEDED off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0
     filesz 0x0000000000000000 memsz 0x0000000000000000 flags ---
OPENBSD_BOOTDATA off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0
     filesz 0x0000000000000000 memsz 0x0000000000000000 flags ---

"readelf 1.o --program-headers" prints:

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOOS+0x5a3dbe6 0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000         0x1
  LOOS+0x5a3dbe7 0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000         0x1
  LOOS+0x5a41be6 0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000         0x1

The expected output is:

Program Headers:
  Type              Offset             VirtAddr           PhysAddr
                    FileSiz            MemSiz              Flags  Align
  OPENBSD_RANDOMIZE 0x0000000000000000 0x0000000000000000 0x0000000000000000
                    0x0000000000000000 0x0000000000000000         0x1
  OPENBSD_WXNEEDED  0x0000000000000000 0x0000000000000000 0x0000000000000000
                    0x0000000000000000 0x0000000000000000         0x1
  OPENBSD_BOOTDATA  0x0000000000000000 0x0000000000000000 0x0000000000000000
                    0x0000000000000000 0x0000000000000000         0x1
Comment 1 Sourceware Commits 2020-08-26 14:15:40 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3eba3ef344b6d22187e50be0dcea883e8254609d

commit 3eba3ef344b6d22187e50be0dcea883e8254609d
Author: Nick Clifton <nickc@redhat.com>
Date:   Wed Aug 26 15:13:41 2020 +0100

    Add support to readelf for the OpenBSD segment types.
    
            PR 26405
    binutils* readelf.c (get_segment_type): Handle OpenBSD segment types.
    
    include * elf/common.h (PT_OPENBSD_BOOTDATA): Define.
            (PT_OPENBSD_RANDOMIZE): Define.
            (PT_OPENBSD_WXNEEDED): Define.
Comment 2 Nick Clifton 2020-08-26 14:16:59 UTC
Thanks for reporting this problem.  I have now checked in a patch to add the missing definitions to the relevant header file and the decoding to readelf.
Comment 3 georgerim 2020-08-27 08:32:31 UTC
Thanks, Nick!