Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lld creates PT_NOTE phdr for non-allocatable note #36709

Closed
emaste opened this issue May 8, 2018 · 2 comments
Closed

lld creates PT_NOTE phdr for non-allocatable note #36709

emaste opened this issue May 8, 2018 · 2 comments
Labels
bugzilla Issues migrated from bugzilla lld:ELF

Comments

@emaste
Copy link
Member

emaste commented May 8, 2018

Bugzilla Link 37361
Resolution FIXED
Resolved on May 10, 2018 04:13
Version unspecified
OS FreeBSD

Extended Description

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)

@emaste
Copy link
Member Author

emaste commented May 8, 2018

@emaste
Copy link
Member Author

emaste commented May 10, 2018

r331973

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld:ELF
Projects
None yet
Development

No branches or pull requests

1 participant