Skip to content
  1. Jan 12, 2017
  2. Jan 06, 2017
  3. Dec 20, 2016
  4. Dec 19, 2016
    • Rui Ueyama's avatar
      Remove inappropriate use of CachedHashStringRef. · 8f687f71
      Rui Ueyama authored
      Use of CachedHashStringRef makes sense only when we reuse hash values.
      Sprinkling it to all DenseMap has no benefits and just complicates data types.
      Basically we shouldn't use CachedHashStringRef unless there is a strong
      reason to to do so.
      
      llvm-svn: 290076
      8f687f71
  5. Dec 06, 2016
    • Rui Ueyama's avatar
      Inline MergeInputSection::getData(). · c8e68848
      Rui Ueyama authored
      This change seems to make LLD 0.6% faster when linking Clang with
      debug info. I don't want us to have lots of local optimizations,
      but this function is very hot, and the improvement is small but
      not negligible, so I think it's worth doing.
      
      llvm-svn: 288757
      c8e68848
  6. Dec 05, 2016
  7. Dec 01, 2016
    • Rui Ueyama's avatar
      Updates file comments and variable names. · 91ae861a
      Rui Ueyama authored
      Use "color" instead of "group id" to describe the ICF algorithm.
      
      llvm-svn: 288409
      91ae861a
    • Rui Ueyama's avatar
      Parallelize ICF to make LLD's ICF really fast. · c1835319
      Rui Ueyama authored
      ICF is short for Identical Code Folding. It is a size optimization to
      identify two or more functions that happened to have the same contents
      to merges them. It usually reduces output size by a few percent.
      
      ICF is slow because it is computationally intensive process. I tried
      to paralellize it before but failed because I couldn't make a
      parallelized version produce consistent outputs. Although it didn't
      create broken executables, every invocation of the linker generated
      slightly different output, and I couldn't figure out why.
      
      I think I now understand what was going on, and also came up with a
      simple algorithm to fix it. So is this patch.
      
      The result is very exciting. Chromium for example has 780,662 input
      sections in which 20,774 are reducible by ICF. LLD previously took
      7.980 seconds for ICF. Now it finishes in 1.065 seconds.
      
      As a result, LLD can now link a Chromium binary (output size 1.59 GB)
      in 10.28 seconds on my machine with ICF enabled. Compared to gold
      which takes 40.94 seconds to do the same thing, this is an amazing
      number.
      
      From here, I'll describe what we are doing for ICF, what was the
      previous problem, and what I did in this patch.
      
      In ICF, two sections are considered identical if they have the same
      section flags, section data, and relocations. Relocations are tricky,
      becuase two relocations are considered the same if they have the same
      relocation type, values, and if they point to the same section _in
      terms of ICF_.
      
      Here is an example. If foo and bar defined below are compiled to the
      same machine instructions, ICF can (and should) merge the two,
      although their relocations point to each other.
      
        void foo() { bar(); }
        void bar() { foo(); }
      
      This is not an easy problem to solve.
      
      What we are doing in LLD is some sort of coloring algorithm. We color
      non-identical sections using different colors repeatedly, and sections
      in the same color when the algorithm terminates are considered
      identical. Here is the details:
      
        1. First, we color all sections using their hash values of section
        types, section contents, and numbers of relocations. At this moment,
        relocation targets are not taken into account. We just color
        sections that apparently differ in different colors.
      
        2. Next, for each color C, we visit sections having color C to see
        if their relocations are the same. Relocations are considered equal
        if their targets have the same color. We then recolor sections that
        have different relocation targets in new colors.
      
        3. If we recolor some section in step 2, relocations that were
        previously pointing to the same color targets may now be pointing to
        different colors. Therefore, repeat 2 until a convergence is
        obtained.
      
      Step 2 is a heavy operation. For Chromium, the first iteration of step
      2 takes 2.882 seconds, and the second iteration takes 1.038 seconds,
      and in total it needs 23 iterations.
      
      Parallelizing step 1 is easy because we can color each section
      independently. This patch does that.
      
      Parallelizing step 2 is tricky. We could work on each color
      independently, but we cannot recolor sections in place, because it
      will break the invariance that two possibly-identical sections must
      have the same color at any moment.
      
      Consider sections S1, S2, S3, S4 in the same color C, where S1 and S2
      are identical, S3 and S4 are identical, but S2 and S3 are not. Thread
      A is about to recolor S1 and S2 in C'. After thread A recolor S1 in
      C', but before recolor S2 in C', other thread B might observe S1 and
      S2. Then thread B will conclude that S1 and S2 are different, and it
      will split thread B's sections into smaller groups wrongly. Over-
      splitting doesn't produce broken results, but it loses a chance to
      merge some identical sections. That was the cause of indeterminism.
      
      To fix the problem, I made sections have two colors, namely current
      color and next color. At the beginning of each iteration, both colors
      are the same. Each thread reads from current color and writes to next
      color. In this way, we can avoid threads from reading partial
      results. After each iteration, we flip current and next.
      
      This is a very simple solution and is implemented in less than 50
      lines of code.
      
      I tested this patch with Chromium and confirmed that this parallelized
      ICF produces the identical output as the non-parallelized one.
      
      Differential Revision: https://reviews.llvm.org/D27247
      
      llvm-svn: 288373
      c1835319
  8. Nov 26, 2016
    • Rui Ueyama's avatar
      Change return types of split{Non,}Strings. · e8a077ba
      Rui Ueyama authored
      They return new vectors, but at the same time they mutate other vectors,
      so returning values doesn't make much sense. We should just mutate two
      vectors.
      
      llvm-svn: 287979
      e8a077ba
  9. Nov 25, 2016
  10. Nov 23, 2016
  11. Nov 21, 2016
    • Rui Ueyama's avatar
      Add a flag to InputSectionBase for linker script. · f94efddd
      Rui Ueyama authored
      Previously, we set (uintptr_t)-1 to InputSectionBase::OutSec to record
      that a section has already been set to be assigned to some output section
      by linker scripts. Later, we restored nullptr to the pointer to use
      the field for the original purpose. That overloading is not very easy to
      understand.
      
      This patch adds a bit flag for that purpose, so that we don't need
      to piggyback the flag on an unrelated pointer.
      
      llvm-svn: 287508
      f94efddd
  12. Nov 20, 2016
    • Rui Ueyama's avatar
      Do not expose ICF class from the file. · bd1f0630
      Rui Ueyama authored
      Also this patch uses file-scope functions instead of class member function.
      
      Now that ICF class is not visible from outside, InputSection class
      can no longer be "friend" of it. So I removed the friend relation
      and just make it expose the features to public.
      
      llvm-svn: 287480
      bd1f0630
  13. Nov 18, 2016
    • Rui Ueyama's avatar
      Simplify MergeOutputSection. · 77f2a875
      Rui Ueyama authored
      MergeOutputSection class was a bit hard to use because it provdes
      a series of finalize functions that have to be called in a right way
      at a right time. It also intereacted with MergeInputSection, and the
      logic was somewhat entangled between the two classes.
      
      This patch simplifies it by providing only one finalize function.
      Now, all you have to do is to call MergeOutputSection::finalize
      when you have added all sections to the output section. Then, it
      internally merges strings and initliazes StringPiece objects.
      I think this is much easier to understand.
      
      This patch also adds comments.
      
      llvm-svn: 287314
      77f2a875
  14. Nov 14, 2016
  15. Nov 11, 2016
  16. Nov 10, 2016
    • Rafael Espindola's avatar
      Parse relocations only once. · 9f0c4bb7
      Rafael Espindola authored
      Relocations are the last thing that we wore storing a raw section
      pointer to and parsing on demand.
      
      With this patch we parse it only once and store a pointer to the
      actual data.
      
      The patch also changes where we store it. It is now in
      InputSectionBase. Not all sections have relocations, but most do and
      this simplifies the logic. It also means that we now only support one
      relocation section per section. Given that that constraint is
      maintained even with -r with gold bfd and lld, I think it is OK.
      
      llvm-svn: 286459
      9f0c4bb7
    • Eugene Leviant's avatar
      [ELF] Convert .got.plt section to input section · 41ca327b
      Eugene Leviant authored
      Differential revision: https://reviews.llvm.org/D26349
      
      llvm-svn: 286443
      41ca327b
    • Rafael Espindola's avatar
      Make OutputSectionBase a class instead of class template. · e08e78df
      Rafael Espindola authored
      The disadvantage is that we use uint64_t instad of uint32_t for some
      value in 32 bit files. The advantage is a substantially simpler code,
      faster builds and less code duplication.
      
      llvm-svn: 286414
      e08e78df
  17. Nov 09, 2016
    • Simon Atanasyan's avatar
      [ELF][MIPS] Convert .MIPS.abiflags section to synthetic input section · fa03b0fa
      Simon Atanasyan authored
      Previously, we have both input and output section for .MIPS.abiflags.
      Now we have only one class for .MIPS.abiflags, which is MipsAbiFlagsSection.
      This class is a synthetic input section.
      
      .MIPS.abiflags sections are handled as regular sections until
      the control reaches Writer. Writer then aggregates all sections
      whose type is SHT_MIPS_ABIFLAGS to create a single synthesized
      input section. The synthesized section is then processed normally
      as if it came from an input file.
      
      llvm-svn: 286398
      fa03b0fa
    • Simon Atanasyan's avatar
      [ELF][MIPS] Convert .reginfo and .MIPS.options sections to synthetic input sections · ce02cf00
      Simon Atanasyan authored
      Previously, we have both input and output sections for .reginfo and
      .MIPS.options. Now for each such sections we have one synthetic input
      sections: MipsReginfoSection and MipsOptionsSection respectively.
      
      Both sections are handled as regular sections until the control reaches
      Writer. Writer then aggregates all sections whose type is SHT_MIPS_REGINFO
      or SHT_MIPS_OPTIONS to create a single synthesized input section. In that
      moment Writer also save GP0 value to the MipsGp0 field of the corresponding
      ObjectFile. This value required for R_MIPS_GPREL16 and R_MIPS_GPREL32
      relocations calculation.
      
      Differential revision: https://reviews.llvm.org/D26444
      
      llvm-svn: 286397
      ce02cf00
    • Rafael Espindola's avatar
      Make Discarded a InputSection. · 6ff570a3
      Rafael Espindola authored
      It was quite confusing that it had SectionKind of Regular, but was not
      actually a InputSection.
      
      llvm-svn: 286379
      6ff570a3
    • Rafael Espindola's avatar
      Add a convenience getObj method. NFC. · 77dbe9a4
      Rafael Espindola authored
      llvm-svn: 286370
      77dbe9a4
  18. Nov 08, 2016
  19. Nov 07, 2016
  20. Nov 06, 2016
    • Rui Ueyama's avatar
      Rewrite CommonInputSection as a synthetic input section. · e8a6102f
      Rui Ueyama authored
      A CommonInputSection is a section containing all common symbols.
      That was an input section but was abstracted in a different way
      than the synthetic input sections because it was written before
      the synthetic input section was invented.
      
      This patch rewrites CommonInputSection as a synthetic input section
      so that it behaves better with other sections.
      
      llvm-svn: 286053
      e8a6102f
  21. Nov 01, 2016
  22. Oct 27, 2016
  23. Oct 26, 2016
    • Rafael Espindola's avatar
      Pass a InputSectionData to classoff. · 99558efe
      Rafael Espindola authored
      This allows a non template class to hold input sections.
      
      llvm-svn: 285221
      99558efe
    • Rafael Espindola's avatar
      Delete trivial getters. NFC. · 1854a8eb
      Rafael Espindola authored
      llvm-svn: 285190
      1854a8eb
    • Rafael Espindola's avatar
      Read section headers upfront. · 0e090522
      Rafael Espindola authored
      Instead of storing a pointer, store the members we need.
      
      The reason for doing this is that it makes it far easier to create
      synthetic sections. It also avoids reading data from files multiple
      times., which might help with cross endian linking and host
      architectures with slow unaligned access.
      
      There are obvious compacting opportunities, but this already has mixed
      results even on native x86_64 linking.
      
      There is also the possibility of better refactoring the code for
      handling common symbols, but this already shows that a custom class is
      not necessary.
      
      llvm-svn: 285148
      0e090522
  24. Oct 25, 2016
  25. Oct 20, 2016
    • Hans Wennborg's avatar
      Fix SectionPiece size when compiling with MSVC · 7314c48b
      Hans Wennborg authored
      Builds were failing with:
      
        InputSection.h(139): error C2338: SectionPiece is too big
      
      because MSVC does record layout differently, probably not packing the
      'OutputOff' and 'Live' bitfields because their types are of different
      size. Using size_t for 'Live' seems to fix it.
      
      llvm-svn: 284740
      7314c48b
    • Rafael Espindola's avatar
      Compact SectionPiece. · 113860b9
      Rafael Espindola authored
      We allocate a lot of these when linking debug info. This speeds up the
      link of debug programs by 1% to 2%.
      
      llvm-svn: 284716
      113860b9
Loading