From 19703503bafc826c854479cc150305545e0122e0 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Wed, 9 May 2018 11:17:01 +0000 Subject: [PATCH] lld: 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. Haskell emits a .debug-ghc-link-info note section (as the name suggests, it contains link info) as a SHT_NOTE section without SHF_ALLOC set. For this case ld.bfd does not emit a PT_NOTE segment for .debug-ghc-link-info. 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 PR: https://llvm.org/pr37361 LLVM review: https://reviews.llvm.org/D46623 PR: 226872 Reviewed by: dim Sponsored by: The FreeBSD Foundation --- contrib/llvm/tools/lld/ELF/Writer.cpp | 2 +- lib/clang/include/lld/Common/Version.inc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/llvm/tools/lld/ELF/Writer.cpp b/contrib/llvm/tools/lld/ELF/Writer.cpp index 1c3b6495a0d1..d130bd603933 100644 --- a/contrib/llvm/tools/lld/ELF/Writer.cpp +++ b/contrib/llvm/tools/lld/ELF/Writer.cpp @@ -1708,7 +1708,7 @@ template std::vector Writer::createPhdrs() { // Create one PT_NOTE per a group of contiguous .note sections. PhdrEntry *Note = nullptr; for (OutputSection *Sec : OutputSections) { - if (Sec->Type == SHT_NOTE) { + if (Sec->Type == SHT_NOTE && (Sec->Flags & SHF_ALLOC)) { if (!Note || Sec->LMAExpr) Note = AddHdr(PT_NOTE, PF_R); Note->add(Sec); diff --git a/lib/clang/include/lld/Common/Version.inc b/lib/clang/include/lld/Common/Version.inc index 8cee847ece7c..e785138fd2f2 100644 --- a/lib/clang/include/lld/Common/Version.inc +++ b/lib/clang/include/lld/Common/Version.inc @@ -7,4 +7,4 @@ #define LLD_REPOSITORY_STRING "FreeBSD" // - -#define LLD_REVISION_STRING "326565-1200001" +#define LLD_REVISION_STRING "326565-1200002"