[lld] r268056 - ELF: Add -O0 (produce output as fast as possible) mode.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 09:12:29 PDT 2016


Author: ruiu
Date: Fri Apr 29 11:12:29 2016
New Revision: 268056

URL: http://llvm.org/viewvc/llvm-project?rev=268056&view=rev
Log:
ELF: Add -O0 (produce output as fast as possible) mode.

This patch redefines the default optimization level as 1 and adds
new level 0. In the command line, it is -O0. The flag disables
costly but optional features so that the linker produces semantically
correct but larger output quickly. Currently it only disables
section merging.

This flag is not intended to be used for final production linking.
It is intended to be used in compile-link-test cycle.

Time to link clang with debug info is about 2x faster with the flag.

  Head:
  13.24 seconds
  Output size: 1227189664 bytes

  With this patch:
  7.41 seconds
  Output size: 2490281784 bytes

Differential Revision: http://reviews.llvm.org/D19705

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/test/ELF/merge-string.s

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=268056&r1=268055&r2=268056&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Apr 29 11:12:29 2016
@@ -356,7 +356,7 @@ void LinkerDriver::readConfigs(opt::Inpu
   Config->SoName = getString(Args, OPT_soname);
   Config->Sysroot = getString(Args, OPT_sysroot);
 
-  Config->Optimize = getInteger(Args, OPT_O, 0);
+  Config->Optimize = getInteger(Args, OPT_O, 1);
   Config->LtoO = getInteger(Args, OPT_lto_O, 2);
   if (Config->LtoO > 3)
     error("invalid optimization level for LTO: " + getString(Args, OPT_lto_O));

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=268056&r1=268055&r2=268056&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Apr 29 11:12:29 2016
@@ -143,6 +143,12 @@ elf::ObjectFile<ELFT>::getShtGroupEntrie
 
 template <class ELFT> static bool shouldMerge(const typename ELFT::Shdr &Sec) {
   typedef typename ELFT::uint uintX_t;
+
+  // We don't merge sections if -O0 (default is -O1). This makes sometimes
+  // the linker significantly faster, although the output will be bigger.
+  if (Config->Optimize == 0)
+    return false;
+
   uintX_t Flags = Sec.sh_flags;
   if (!(Flags & SHF_MERGE))
     return false;

Modified: lld/trunk/test/ELF/merge-string.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/merge-string.s?rev=268056&r1=268055&r2=268056&view=diff
==============================================================================
--- lld/trunk/test/ELF/merge-string.s (original)
+++ lld/trunk/test/ELF/merge-string.s Fri Apr 29 11:12:29 2016
@@ -4,6 +4,8 @@
 // RUN: llvm-readobj -s -section-data -t %t.so | FileCheck %s
 // RUN: ld.lld -O1 %t.o -o %t.so -shared
 // RUN: llvm-readobj -s -section-data -t %t.so | FileCheck --check-prefix=NOTAIL %s
+// RUN: ld.lld -O0 %t.o -o %t.so -shared
+// RUN: llvm-readobj -s -section-data -t %t.so | FileCheck --check-prefix=NOMERGE %s
 
         .section	.rodata.str1.1,"aMS", at progbits,1
 	.asciz	"abc"
@@ -55,6 +57,24 @@ zed:
 // NOTAIL-NEXT:   0000: 61626300 626300                     |abc.bc.|
 // NOTAIL-NEXT: )
 
+// NOMERGE:      Name:    .rodata
+// NOMERGE-NEXT: Type:    SHT_PROGBITS
+// NOMERGE-NEXT: Flags [
+// NOMERGE-NEXT:   SHF_ALLOC
+// NOMERGE-NEXT:   SHF_MERGE
+// NOMERGE-NEXT:   SHF_STRINGS
+// NOMERGE-NEXT: ]
+// NOMERGE-NEXT: Address:         0x1C8
+// NOMERGE-NEXT: Offset:  0x1C8
+// NOMERGE-NEXT: Size:    16
+// NOMERGE-NEXT: Link: 0
+// NOMERGE-NEXT: Info: 0
+// NOMERGE-NEXT: AddressAlignment: 2
+// NOMERGE-NEXT: EntrySize: 0
+// NOMERGE-NEXT: SectionData (
+// NOMERGE-NEXT:   0000: 61626300 61626300 62630000 14000000  |abc.abc.bc......|
+// NOMERGE-NEXT: )
+
 // CHECK:      Name: .rodata
 // CHECK-NEXT: Type: SHT_PROGBITS
 // CHECK-NEXT: Flags [




More information about the llvm-commits mailing list