[PATCH] D55679: # Enter a commit message. #

Tiancong Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 13 15:04:17 PST 2018


tcwang created this revision.
tcwang added a reviewer: ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.

Place .text.hot section before .text.

Objects with profiling information can mark symbols with .hot prefix/suffix.
With the option -z keep-text-section-prefix, all the symbols marked as hot
will be put into a separate section named as '.text.hot' (as well as cold
symbols, (.text.unlikely), .text.startup, .text.exit, .text.unliekly, etc.)

The previous version of lld does not specify ordering for these text sections
and all the sections with prefix comes after .text section. This doesn't benefit
performance in some cases and is different than the ordering of gold. (In gold,
these secctions are ordered as .text.hot, .text, .text.startup, .text.exit,
.text.unlikely)

This commit reorders the text sections by putting .text.hot before .text, in
the same order as gold (only for text sections with prefix, other section orders
are still different than gold as previous version).

The change only affects linking results when -z keep-text-section-prefix is passed.

Unit test text-section-prefix is changed accordingly.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D55679

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
@@ -7,8 +7,8 @@
 # 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
 # CHECK: .text.startup
 # CHECK: .text.exit
 # CHECK: .text.unlikely
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -729,12 +729,13 @@
 // * 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 << 18,
-  RF_NOT_INTERP = 1 << 17,
-  RF_NOT_ALLOC = 1 << 16,
-  RF_WRITE = 1 << 15,
-  RF_EXEC_WRITE = 1 << 14,
-  RF_EXEC = 1 << 13,
+  RF_NOT_ADDR_SET = 1 << 19,
+  RF_NOT_INTERP = 1 << 18,
+  RF_NOT_ALLOC = 1 << 17,
+  RF_WRITE = 1 << 16,
+  RF_EXEC_WRITE = 1 << 15,
+  RF_EXEC = 1 << 14,
+  RF_EXEC_HOT = 1 << 13,
   RF_RODATA = 1 << 12,
   RF_NON_TLS_BSS = 1 << 11,
   RF_NON_TLS_BSS_RO = 1 << 10,
@@ -787,8 +788,12 @@
   if (IsExec) {
     if (IsWrite)
       Rank |= RF_EXEC_WRITE;
-    else
-      Rank |= RF_EXEC;
+    else {
+      if (isSectionPrefix(".text.hot.", Sec->Name))
+        Rank |= RF_EXEC_HOT;
+      else
+        Rank |= RF_EXEC;
+    }
   } else if (IsWrite) {
     Rank |= RF_WRITE;
   } else if (Sec->Type == SHT_PROGBITS) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55679.178145.patch
Type: text/x-patch
Size: 1512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181213/d1e4aede/attachment.bin>


More information about the llvm-commits mailing list