<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Sections in non-PT_LOAD segments are assigned non-zero sh_addr"
   href="https://bugs.llvm.org/show_bug.cgi?id=47094">47094</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Sections in non-PT_LOAD segments are assigned non-zero sh_addr
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>edd-llvm@mr-edd.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>A change in behaviour was introduced by <a href="https://reviews.llvm.org/D85100">https://reviews.llvm.org/D85100</a>.

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
(<a href="https://www.sco.com/developers/gabi/latest/ch4.sheader.html">https://www.sco.com/developers/gabi/latest/ch4.sheader.html</a>), 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).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>