[llvm-bugs] [Bug 47687] New: Orphan section incorrectly placed in PT_GNU_EH_FRAME segment if read-only with linker script

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 30 02:00:41 PDT 2020


            Bug ID: 47687
           Summary: Orphan section incorrectly placed in PT_GNU_EH_FRAME
                    segment if read-only with linker script
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: jh7370.2008 at my.bristol.ac.uk
                CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com

Given the following linker script:

    ph_ro PT_LOAD FLAGS (0x4);
    ph_ehframe PT_GNU_EH_FRAME FLAGS(0x4);
    ph_text PT_LOAD FLAGS (0x1 | 0x4);

    .rodata : { *(.rodata .rodata.*) } : ph_ro
    .eh_frame : { *(.eh_frame) } : ph_ro
    .eh_frame_hdr : { *(.eh_frame_hdr) } : ph_ro : ph_ehframe
    .text : { *(.text .text.*) } : ph_text

And input that contributes towards each of .rodata, .eh_frame, and .text, and
an orphan section which is SHF_ALLOC, but not SHF_WRITE or SHF_EXECINSTR (i.e.
read-only), LLD will place the orphan section inside the PT_GNU_EH_FRAME
segment, if --eh-frame-hdr is provided. This is because .eh_frame_hdr is
treated the same as any other RO section with regards to the section ranking,
so the orphan section matches it and gets assigned next to it (and consequently
in the .eh_frame_hdr segment). I think the fix is to add .eh_frame_hdr as a
special rank element, similar to how relro sections are treated distinctly.
This will mean that it will be impossible for orphans to match it, and instead
they'll get placed elsewhere in the read-only segment.

Example inputs:
// test.cpp
const int x = 42;

extern "C" int _start(){
  return 42;

// test2.s
.section orphan_ro,"a", at progbits
  .byte 1

Compile, then link with the following command:
ld.lld test.o test2.o -o test.elf --eh-frame-hdr

Giving you the following section to segment mapping:
Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  LOAD           0x001000 0x0000000000000000 0x0000000000000000 0x000051
0x000051 R   0x1000
  GNU_EH_FRAME   0x00103c 0x000000000000003c 0x000000000000003c 0x000015
0x000015 R   0x4
  LOAD           0x001060 0x0000000000000060 0x0000000000000060 0x00000c
0x00000c R E 0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .rodata .eh_frame .eh_frame_hdr orphan_ro 
   01     .eh_frame_hdr orphan_ro 
   02     .text 
   None   .comment .symtab .shstrtab .strtab

This isn't an issue if no script is specified, or when the .eh_frame_hdr
segement appears first, or when using ld.bfd.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200930/0a9d70df/attachment.html>

More information about the llvm-bugs mailing list