[lld] r326410 - Do not create multiple NOTE segments.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 18:31:29 PST 2018
Author: ruiu
Date: Wed Feb 28 18:31:29 2018
New Revision: 326410
URL: http://llvm.org/viewvc/llvm-project?rev=326410&view=rev
Log:
Do not create multiple NOTE segments.
Previously, we didn't try to make effort to put .note sections next
to each other in the output file, so two .note sections were likely
to be stored to two separate NOTE segments. That's undesirable because
we should create as few segments as possible in general.
Differential Revision: https://reviews.llvm.org/D43858
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/note-contiguous.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=326410&r1=326409&r2=326410&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Feb 28 18:31:29 2018
@@ -668,16 +668,17 @@ static bool isRelroSection(const OutputS
// * It is easy to check if a give branch was taken.
// * It is easy two see how similar two ranks are (see getRankProximity).
enum RankFlags {
- RF_NOT_ADDR_SET = 1 << 16,
- RF_NOT_INTERP = 1 << 15,
- RF_NOT_ALLOC = 1 << 14,
- RF_WRITE = 1 << 13,
- RF_EXEC_WRITE = 1 << 12,
- RF_EXEC = 1 << 11,
- RF_NON_TLS_BSS = 1 << 10,
- RF_NON_TLS_BSS_RO = 1 << 9,
- RF_NOT_TLS = 1 << 8,
- RF_BSS = 1 << 7,
+ RF_NOT_ADDR_SET = 1 << 18,
+ RF_NOT_INTERP = 1 << 17,
+ RF_NOT_ALLOC = 1 << 16,
+ RF_WRITE = 1 << 15,
+ RF_EXEC_WRITE = 1 << 13,
+ RF_EXEC = 1 << 12,
+ RF_NON_TLS_BSS = 1 << 11,
+ RF_NON_TLS_BSS_RO = 1 << 10,
+ RF_NOT_TLS = 1 << 9,
+ RF_BSS = 1 << 8,
+ RF_NOTE = 1 << 7,
RF_PPC_NOT_TOCBSS = 1 << 6,
RF_PPC_OPD = 1 << 5,
RF_PPC_TOCL = 1 << 4,
@@ -765,6 +766,12 @@ static unsigned getSectionRank(const Out
if (IsNoBits)
Rank |= RF_BSS;
+ // We create a NOTE segment for contiguous .note sections, so make
+ // them contigous if there are more than one .note section with the
+ // same attributes.
+ if (Sec->Type == SHT_NOTE)
+ Rank |= RF_NOTE;
+
// Some architectures have additional ordering restrictions for sections
// within the same PT_LOAD.
if (Config->EMachine == EM_PPC64) {
@@ -790,6 +797,7 @@ static unsigned getSectionRank(const Out
if (Name == ".branch_lt")
Rank |= RF_PPC_BRANCH_LT;
}
+
if (Config->EMachine == EM_MIPS) {
// All sections with SHF_MIPS_GPREL flag should be grouped together
// because data in these sections is addressable with a gp relative address.
Modified: lld/trunk/test/ELF/note-contiguous.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/note-contiguous.s?rev=326410&r1=326409&r2=326410&view=diff
==============================================================================
--- lld/trunk/test/ELF/note-contiguous.s (original)
+++ lld/trunk/test/ELF/note-contiguous.s Wed Feb 28 18:31:29 2018
@@ -8,12 +8,13 @@
// CHECK-NEXT: Offset:
// CHECK-NEXT: VirtualAddress:
// CHECK-NEXT: PhysicalAddress:
-// CHECK-NEXT: FileSize: 8
-// CHECK-NEXT: MemSize: 8
+// CHECK-NEXT: FileSize: 16
+// CHECK-NEXT: MemSize: 16
// CHECK-NEXT: Flags [
// CHECK-NEXT: PF_R
// CHECK-NEXT: ]
// CHECK-NEXT: Alignment: 1
+// CHECK-NOT: Type: PT_NOTE
// RUN: echo "SECTIONS { .note : { *(.note.a) *(.note.b) } }" > %t.script
// RUN: ld.lld %t.o --script %t.script -o %t2
@@ -29,6 +30,7 @@
// SCRIPT-NEXT: PF_R
// SCRIPT-NEXT: ]
// SCRIPT-NEXT: Alignment: 1
+// SCRIPT-NOT: Type: PT_NOTE
.section .note.a, "a", @note
.quad 0
More information about the llvm-commits
mailing list