summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Writer.cpp6
-rw-r--r--lld/test/ELF/note.s18
2 files changed, 24 insertions, 0 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index bf347e72a5f..d7e13e80aad 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1247,6 +1247,7 @@ template <class ELFT> void Writer<ELFT>::createPhdrs() {
Phdr TlsHdr(PT_TLS, PF_R);
Phdr RelRo(PT_GNU_RELRO, PF_R);
+ Phdr Note(PT_NOTE, PF_R);
for (OutputSectionBase<ELFT> *Sec : OutputSections) {
if (!(Sec->getFlags() & SHF_ALLOC))
break;
@@ -1273,6 +1274,8 @@ template <class ELFT> void Writer<ELFT>::createPhdrs() {
if (isRelroSection(Sec))
AddSec(RelRo, Sec);
+ if (Sec->getType() == SHT_NOTE)
+ AddSec(Note, Sec);
}
// Add the TLS segment unless it's empty.
@@ -1301,6 +1304,9 @@ template <class ELFT> void Writer<ELFT>::createPhdrs() {
// pages for the stack non-executable.
if (!Config->ZExecStack)
AddHdr(PT_GNU_STACK, PF_R | PF_W);
+
+ if (Note.First)
+ Phdrs.push_back(std::move(Note));
}
// Used for relocatable output (-r). In this case we create only ELF file
diff --git a/lld/test/ELF/note.s b/lld/test/ELF/note.s
new file mode 100644
index 00000000000..a383b95c990
--- /dev/null
+++ b/lld/test/ELF/note.s
@@ -0,0 +1,18 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld %t.o -o %t -shared
+// RUN: llvm-readobj -program-headers %t | FileCheck %s
+
+// CHECK: Type: PT_NOTE
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: VirtualAddress:
+// CHECK-NEXT: PhysicalAddress:
+// CHECK-NEXT: FileSize: 8
+// CHECK-NEXT: MemSize: 8
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: PF_R
+// CHECK-NEXT: ]
+// CHECK-NEXT: Alignment: 1
+
+ .section .note.test,"a",@note
+ .quad 42
OpenPOWER on IntegriCloud