[lld] 8825ffd - [ELF] --time-trace: Trace "Write sections"

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 20 10:51:28 PST 2021


Author: Fangrui Song
Date: 2021-12-20T10:51:24-08:00
New Revision: 8825ffdbde01941110b4f4ee3b7e8e129b9a2289

URL: https://github.com/llvm/llvm-project/commit/8825ffdbde01941110b4f4ee3b7e8e129b9a2289
DIFF: https://github.com/llvm/llvm-project/commit/8825ffdbde01941110b4f4ee3b7e8e129b9a2289.diff

LOG: [ELF] --time-trace: Trace "Write sections"

writeSections is typically a bottleneck.
This was used to track down the following bottlenecks:

* Output section .rela.dyn (9115d75117b57115fe45153e5f38f2c444c0cd91)
* Output section .debug_str (3aae04c744b03eb3eec7376f9d34fa3e42f8d108)
* posix_fallocate is slow for Linux tmpfs: D115957

Reviewed By: ikudrin

Differential Revision: https://reviews.llvm.org/D115984

Added: 
    

Modified: 
    lld/ELF/OutputSections.cpp
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index fc0b1ecef2b8c..00f961ec7d238 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -332,6 +332,7 @@ static void writeInt(uint8_t *buf, uint64_t data, uint64_t size) {
 }
 
 template <class ELFT> void OutputSection::writeTo(uint8_t *buf) {
+  llvm::TimeTraceScope timeScope("Write sections", name);
   if (type == SHT_NOBITS)
     return;
 

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 7ad5f1acecb6d..9390027487ed2 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2893,6 +2893,8 @@ template <class ELFT> void Writer<ELFT>::writeTrapInstr() {
 
 // Write section contents to a mmap'ed file.
 template <class ELFT> void Writer<ELFT>::writeSections() {
+  llvm::TimeTraceScope timeScope("Write sections");
+
   // In -r or --emit-relocs mode, write the relocation sections first as in
   // ELf_Rel targets we might find out that we need to modify the relocated
   // section while doing it.


        


More information about the llvm-commits mailing list