LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 37361 - lld creates PT_NOTE phdr for non-allocatable note
Summary: lld creates PT_NOTE phdr for non-allocatable note
Status: RESOLVED FIXED
Alias: None
Product: lld
Classification: Unclassified
Component: ELF (show other bugs)
Version: unspecified
Hardware: PC FreeBSD
: P enhancement
Assignee: Unassigned LLVM Bugs
URL: https://reviews.llvm.org/D46623
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-07 18:06 PDT by emaste
Modified: 2018-05-10 04:13 PDT (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description emaste 2018-05-07 18:06:38 PDT
This issue was found while trying to link ghc (Haskell compiler) with lld, and reported in FreeBSD bug 226872 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=226872. 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)
Comment 1 emaste 2018-05-07 18:09:33 PDT
Reproducer located at https://people.freebsd.org/~emaste/llvm-pr-37361/reproduce.tar.xz
Comment 2 emaste 2018-05-10 04:12:28 PDT
r331973