<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 - -z separate-loadable-segments doesn't work with LTO enabled"
   href="https://bugs.llvm.org/show_bug.cgi?id=50004">50004</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-z separate-loadable-segments doesn't work with LTO enabled
          </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>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>rianquinn@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>If I enabled LTO "using "-flto" in clang, and I include -z
separate-loadable-segments (or remove it, as it doesn't seem to make a
difference), I get the following:

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  LOAD           0x001000 0x0000028000000000 0x0000028000000000 0x001f48
0x001f48 R   0x1000
  LOAD           0x003000 0x0000028000002000 0x0000028000002000 0x020325
0x020325 R E 0x1000
  LOAD           0x024328 0x0000028000022328 0x0000028000022328 0x006e80
0x01f2d1 RW  0x1000
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000
0x000000 RW  0

The RW section is not properly aligned. I am using version 11. Below is my
linker script. I am not sure if this is a bug or not, and it works fine when
LTO is disabled, but I would like to enable LTO and I am not sure what I am
doing wrong at this point. 

ENTRY(mk_main_entry)
OUTPUT_FORMAT(elf64-x86-64)

SECTIONS {
    . = 0x0000028000000000;
    .text : ALIGN(0x1000) {
        *(.text)
    }
    .init : ALIGN(0x1000) {
        *(.init)
    }
    .init_array : ALIGN(0x1000) {
        *(.init_array)
    }
    .fini : ALIGN(0x1000) {
        *(.fini)
    }
    .fini_array : ALIGN(0x1000) {
        *(.fini_array)
    }
    .rodata : ALIGN(0x1000) {
        *(.rodata)
    }
    .data : ALIGN(0x1000) {
        *(.data)
    }
    .bss : ALIGN(0x1000) {
        *(.bss)
    }
}</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>