<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 - lld creates PT_NOTE phdr for non-allocatable note"
   href="https://bugs.llvm.org/show_bug.cgi?id=37361">37361</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lld creates PT_NOTE phdr for non-allocatable note
          </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>FreeBSD
          </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>ELF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>emaste@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This issue was found while trying to link ghc (Haskell compiler) with lld, and
reported in FreeBSD bug 226872
<a href="https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=226872">https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=226872</a>. lld-linked Haskell
binaries crash FreeBSD's rtld as the phdr includes a PT_NOTE segment at
VirtAddr = 0

% readelf -lW HsColour

Elf file type is EXEC (Executable file)
Entry point 0x22a000
There are 11 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  PHDR           0x000040 0x0000000000200040 0x0000000000200040 0x000268
0x000268 R   0x8
  INTERP         0x0002a8 0x00000000002002a8 0x00000000002002a8 0x000015
0x000015 R   0x1
      [Requesting program interpreter: /libexec/ld-elf.so.1]
  LOAD           0x000000 0x0000000000200000 0x0000000000200000 0x029aa0
0x029aa0 R   0x1000
  LOAD           0x02a000 0x000000000022a000 0x000000000022a000 0x12f390
0x12f390 R E 0x1000
  LOAD           0x15a000 0x000000000035a000 0x000000000035a000 0x01ae68
0x027a6c RW  0x1000
  DYNAMIC        0x174cb0 0x0000000000374cb0 0x0000000000374cb0 0x0001b0
0x0001b0 RW  0x8
  GNU_RELRO      0x16f000 0x000000000036f000 0x000000000036f000 0x005e68
0x007000 R   0x1
  GNU_EH_FRAME   0x0234b0 0x00000000002234b0 0x00000000002234b0 0x00111c
0x00111c R   0x1
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000
0x000000 RW  0
  NOTE           0x0002c0 0x00000000002002c0 0x00000000002002c0 0x000030
0x000030 R   0x4
  NOTE           0x342dcc 0x0000000000000000 0x0000000000000000 0x000c40
0x000c40 R   0x4
...

% readelf -SW HsColour
There are 44 section headers, starting at offset 0x3c4aa0:

Section Headers:
  [Nr] Name              Type            Addr             Off    Size   ES Flg
Lk Inf Al
...
  [ 2] .note.tag         NOTE            00000000002002c0 0002c0 000030 00   A 
0   0  4
...
  [39] .debug-ghc-link-i NOTE            0000000000000000 342dcc 000c40 00     
0   0  4
...

Observe that the section headers show the second note section is not SHF_ALLOC.

When linking with ld.bfd we still have the two NOTE sections, one SHF_ALLOC and
one not:

% readelf -SW HsColour     
There are 43 section headers, starting at offset 0x3c1ec0:

Section Headers:
  [Nr] Name              Type            Addr             Off    Size   ES Flg
Lk Inf Al
...
  [ 2] .note.tag         NOTE            0000000000400218 000218 000030 00   A 
0   0  4
...
  [39] .debug-ghc-link-i NOTE            0000000000000000 33de1c 000c40 00     
0   0  4
...

but ld.bfd omits the PT_NOTE phdr for the non-alloc note:

% readelf -lW HsColour

Elf file type is EXEC (Executable file)
Entry point 0x4050a0
There are 8 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  PHDR           0x000040 0x0000000000400040 0x0000000000400040 0x0001c0
0x0001c0 R   0x8
  INTERP         0x000200 0x0000000000400200 0x0000000000400200 0x000015
0x000015 R   0x1
      [Requesting program interpreter: /libexec/ld-elf.so.1]
  LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x157fa8
0x157fa8 R E 0x200000
  LOAD           0x158000 0x0000000000758000 0x0000000000758000 0x01bec8
0x027990 RW  0x200000
  DYNAMIC        0x15ed30 0x000000000075ed30 0x000000000075ed30 0x000200
0x000200 RW  0x8
  NOTE           0x000218 0x0000000000400218 0x0000000000400218 0x000030
0x000030 R   0x4
  GNU_EH_FRAME   0x151f80 0x0000000000551f80 0x0000000000551f80 0x001124
0x001124 R   0x4
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000
0x000000 RWE 0x10

Versions:
% ld.bfd --version
GNU ld (GNU Binutils) 2.30
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
% ld.lld --version
LLD 6.0.0 (FreeBSD 326565-1200001) (compatible with GNU linkers)</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>