[llvm-bugs] [Bug 47094] New: Sections in non-PT_LOAD segments are assigned non-zero sh_addr

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 10 09:48:58 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47094

            Bug ID: 47094
           Summary: Sections in non-PT_LOAD segments are assigned non-zero
                    sh_addr
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: edd-llvm at mr-edd.co.uk
                CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com

A change in behaviour was introduced by https://reviews.llvm.org/D85100.

When using a linker script that arranges sections outside of PT_LOADs, those
sections are assigned non-zero sh_addr values.

Here's a failing repro in lit that puts sections in a segment in the
PT_LOOS-PT_HIOS range:

---
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: echo "PHDRS {text PT_LOAD FILEHDR PHDRS; foo 0x60000000 FLAGS (0); } \
# RUN:       SECTIONS { \
# RUN:         . = SIZEOF_HEADERS; \
# RUN:         .text : { *(.text) } : text \
# RUN:         .foo  : { *(.foo)  } : foo \
# RUN:       }" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readelf --sections %t | FileCheck %s

#        Name  Type     Address          Off    ...
# CHECK: .foo  PROGBITS 0000000000000000 0000b1
#                       ^ actually assigned 0xb1

.global _start
_start:
 nop

.section .foo,""
foo:
 .byte 0
---

This seems to be in violation of the ELF spec
(https://www.sco.com/developers/gabi/latest/ch4.sheader.html), that says:

  sh_addr
    If the section will appear in the memory image of a process, 
    this member gives the address at which the section's first 
    byte should reside. Otherwise, the member contains 0.  

Of course, it's not possible for LLD to know the meaning of downstream phdr
types; perhaps some of them are PT_LOAD-like in behaviour and maybe the
intention is now that the responsibility is with script authors to meet this
aspect of the ELF spec? But PT_LOAD already exists for that purpose, so
sh_addr=0 seems like a more useful behaviour here (and would be easier for us,
downstream).

-- 
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/20200810/474b80b1/attachment.html>


More information about the llvm-bugs mailing list