[ELF] Omit PT_NOTE for SHT_NOTE without SHF_ALLOC
authorEd Maste <emaste@freebsd.org>
Thu, 10 May 2018 11:12:18 +0000 (11:12 +0000)
committerEd Maste <emaste@freebsd.org>
Thu, 10 May 2018 11:12:18 +0000 (11:12 +0000)
commit6556aa6848926a7defd52fdd80f1c25dcc6275bc
treeb61857c79ab8dfcb1ca574ea7cd00e198403147c
parentd621037788c3038a57e13eacb0d537954bc1556c
[ELF] Omit PT_NOTE for SHT_NOTE without SHF_ALLOC

A non-alloc note section should not have a PT_NOTE program header.

Found while linking ghc (Haskell compiler) with lld on FreeBSD.
ghc emits a .debug-ghc-link-info note section (as the name suggests, it
contains link information) as a SHT_NOTE section without SHF_ALLOC set.

For this case ld.bfd does not emit a PT_NOTE segment for the
.debug-ghc-link-info section.  lld previously emitted a PT_NOTE with
p_vaddr = 0 and FreeBSD's rtld segfaulted when trying to parse a note at
address 0.

llvm.org/pr37361

Differential Revision: https://reviews.llvm.org/D46623

llvm-svn: 331973
lld/ELF/Writer.cpp
lld/test/ELF/note-noalloc.s [new file with mode: 0644]