[lld] r331823 - New option -z keep-text-section-prefix to keep text sections with prefixes separate.
Sriraman Tallam via llvm-commits
llvm-commits at lists.llvm.org
Tue May 8 16:19:50 PDT 2018
Author: tmsriram
Date: Tue May 8 16:19:50 2018
New Revision: 331823
URL: http://llvm.org/viewvc/llvm-project?rev=331823&view=rev
Log:
New option -z keep-text-section-prefix to keep text sections with prefixes separate.
Separate output sections for selected text section prefixes to enable TLB optimizations and for readablilty.
Differential Revision: https://reviews.llvm.org/D45841
Added:
lld/trunk/test/ELF/text-section-prefix.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=331823&r1=331822&r2=331823&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Tue May 8 16:19:50 2018
@@ -171,6 +171,7 @@ struct Configuration {
bool ZCopyreloc;
bool ZExecstack;
bool ZHazardplt;
+ bool ZKeepTextSectionPrefix;
bool ZNodelete;
bool ZNodlopen;
bool ZNow;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=331823&r1=331822&r2=331823&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue May 8 16:19:50 2018
@@ -764,6 +764,8 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->ZCopyreloc = getZFlag(Args, "copyreloc", "nocopyreloc", true);
Config->ZExecstack = getZFlag(Args, "execstack", "noexecstack", false);
Config->ZHazardplt = hasZOption(Args, "hazardplt");
+ Config->ZKeepTextSectionPrefix = getZFlag(
+ Args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);
Config->ZNodelete = hasZOption(Args, "nodelete");
Config->ZNodlopen = hasZOption(Args, "nodlopen");
Config->ZNow = getZFlag(Args, "now", "lazy", false);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=331823&r1=331822&r2=331823&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue May 8 16:19:50 2018
@@ -88,6 +88,10 @@ private:
};
} // anonymous namespace
+static bool isSectionPrefix(StringRef Prefix, StringRef Name) {
+ return Name.startswith(Prefix) || Name == Prefix.drop_back();
+}
+
StringRef elf::getOutputSectionName(InputSectionBase *S) {
if (Config->Relocatable)
return S->Name;
@@ -104,13 +108,25 @@ StringRef elf::getOutputSectionName(Inpu
}
}
+ // This check is for -z keep-text-section-prefix. This option separates text
+ // sections with prefix ".text.hot", ".text.unlikely", ".text.startup" or
+ // ".text.exit".
+ // When enabled, this allows identifying the hot code region (.text.hot) in
+ // the final binary which can be selectively mapped to huge pages or mlocked,
+ // for instance.
+ if (Config->ZKeepTextSectionPrefix)
+ for (StringRef V :
+ {".text.hot.", ".text.unlikely.", ".text.startup.", ".text.exit."}) {
+ if (isSectionPrefix(V, S->Name))
+ return V.drop_back();
+ }
+
for (StringRef V :
{".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.rel.ro.",
".bss.", ".init_array.", ".fini_array.", ".ctors.", ".dtors.", ".tbss.",
".gcc_except_table.", ".tdata.", ".ARM.exidx.", ".ARM.extab."}) {
- StringRef Prefix = V.drop_back();
- if (S->Name.startswith(V) || S->Name == Prefix)
- return Prefix;
+ if (isSectionPrefix(V, S->Name))
+ return V.drop_back();
}
// CommonSection is identified as "COMMON" in linker scripts.
Added: lld/trunk/test/ELF/text-section-prefix.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/text-section-prefix.s?rev=331823&view=auto
==============================================================================
--- lld/trunk/test/ELF/text-section-prefix.s (added)
+++ lld/trunk/test/ELF/text-section-prefix.s Tue May 8 16:19:50 2018
@@ -0,0 +1,38 @@
+# RUN: llvm-mc -filetype=obj %s -o %t
+# RUN: ld.lld -z keep-text-section-prefix %t -o %t2
+# RUN: llvm-readelf -l %t2 | FileCheck %s
+# RUN: ld.lld %t -o %t3
+# RUN: llvm-readelf -l %t3 | FileCheck --check-prefix=CHECKNO %s
+# RUN: ld.lld -z nokeep-text-section-prefix %t -o %t4
+# RUN: llvm-readelf -l %t4 | FileCheck --check-prefix=CHECKNO %s
+
+# CHECK: .text
+# CHECK: .text.hot
+# CHECK: .text.startup
+# CHECK: .text.exit
+# CHECK: .text.unlikely
+# CHECKNO: .text
+# CHECKNO-NOT: .text.hot
+
+_start:
+ ret
+
+.section .text.f,"ax"
+f:
+ nop
+
+.section .text.hot.f_hot,"ax"
+f_hot:
+ nop
+
+.section .text.startup.f_startup,"ax"
+f_startup:
+ nop
+
+.section .text.exit.f_exit,"ax"
+f_exit:
+ nop
+
+.section .text.unlikely.f_unlikely,"ax"
+f_unlikely:
+ nop
More information about the llvm-commits
mailing list