[PATCH] D45841: Keep the output text sections with prefixes ".text.hot" , ".text.unlikely", ".text.startup", ".text.exit" separate

Sriraman Tallam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 19 15:17:17 PDT 2018


tmsriram created this revision.
tmsriram added a reviewer: ruiu.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.

Separate output sections for selected text section prefixes to enable TLB optimizations and for readablilty.

I committed a patch to gold linker recently to do this although that was via a flag.  Talking to Rui offline, he suggested I make this the default.  This is useful for the following reasons:

- We have tools to map specific code to huge pages and we do not want to do this for unlikely executed code, improves huge page TLB.
- We also munlock code that is unlikely executed and it is easier to find it with this.
- This is also useful or code layout verification.

Is this alright?


https://reviews.llvm.org/D45841

Files:
  ELF/Writer.cpp
  test/ELF/text-section-prefix.s


Index: test/ELF/text-section-prefix.s
===================================================================
--- test/ELF/text-section-prefix.s
+++ test/ELF/text-section-prefix.s
@@ -0,0 +1,34 @@
+# RUN: llvm-mc -filetype=obj %s -o %t
+# RUN: ld.lld %t -o %t2
+# RUN: llvm-readelf -l %t2 | FileCheck %s
+
+# CHECK: .text
+# CHECK: .text.hot
+# CHECK: .text.startup
+# CHECK: .text.exit
+# CHECK: .text.unlikely
+
+
+.globl _start, f, f_hot, f_startup, f_exit, f_unlikely
+_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
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -104,7 +104,8 @@
   }
 
   for (StringRef V :
-       {".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.rel.ro.",
+       {".text.hot.", ".text.unlikely.", ".text.startup.", ".text.exit.",
+        ".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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45841.143170.patch
Type: text/x-patch
Size: 1338 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180419/4889ed73/attachment.bin>


More information about the llvm-commits mailing list