[lld] r218893 - Preserve custom section names when coalescing.

Nick Kledzik kledzik at apple.com
Thu Oct 2 10:22:06 PDT 2014


Author: kledzik
Date: Thu Oct  2 12:22:05 2014
New Revision: 218893

URL: http://llvm.org/viewvc/llvm-project?rev=218893&view=rev
Log:
Preserve custom section names when coalescing.

The mergeByContent attribute on DefinedAtoms triggers the symbol table to
coalesce atoms with the exact same content. The problem is that atoms can also
have a required custom section. The coalescing should never change the custom
section of an atom.

The fix is to only consider to atoms to have the same content if their
sectionChoice() and customSectionName() attributes match.

Added:
    lld/trunk/test/core/custom-section-coalesce.objtxt
Modified:
    lld/trunk/lib/Core/SymbolTable.cpp

Modified: lld/trunk/lib/Core/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=218893&r1=218892&r2=218893&view=diff
==============================================================================
--- lld/trunk/lib/Core/SymbolTable.cpp (original)
+++ lld/trunk/lib/Core/SymbolTable.cpp Thu Oct  2 12:22:05 2014
@@ -339,6 +339,12 @@ bool SymbolTable::AtomMappingInfo::isEqu
     return false;
   if (l->size() != r->size())
     return false;
+  if (l->sectionChoice() != r->sectionChoice())
+    return false;
+  if (l->sectionChoice() == DefinedAtom::sectionCustomRequired) {
+    if (!l->customSectionName().equals(r->customSectionName()))
+      return false;
+  }
   ArrayRef<uint8_t> lc = l->rawContent();
   ArrayRef<uint8_t> rc = r->rawContent();
   return memcmp(lc.data(), rc.data(), lc.size()) == 0;

Added: lld/trunk/test/core/custom-section-coalesce.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/core/custom-section-coalesce.objtxt?rev=218893&view=auto
==============================================================================
--- lld/trunk/test/core/custom-section-coalesce.objtxt (added)
+++ lld/trunk/test/core/custom-section-coalesce.objtxt Thu Oct  2 12:22:05 2014
@@ -0,0 +1,78 @@
+# RUN: lld -core %s | FileCheck %s
+
+#
+# Test that custom sections are preserved when duplicate merge-by-content
+# constants are coalesced.
+#
+
+---
+defined-atoms:
+    - ref-name:          L1
+      type:              constant
+      merge:             by-content
+      content:           [ 01, 02, 03, 04 ]
+      section-choice:    custom-required
+      section-name:      .mysection
+
+    - ref-name:          L2
+      type:              constant
+      merge:             by-content
+      content:           [ 05, 06, 07, 08 ]
+      section-choice:    custom-required
+      section-name:      .mysection
+
+    - ref-name:          L3
+      type:              constant
+      merge:             by-content
+      content:           [ 01, 02, 03, 04 ]
+
+---
+defined-atoms:
+    - ref-name:          L1
+      type:              constant
+      merge:             by-content
+      content:           [ 01, 02, 03, 04 ]
+      section-choice:    custom-required
+      section-name:      .mysection
+
+    - ref-name:          L2
+      type:              constant
+      merge:             by-content
+      content:           [ 01, 02, 03, 04 ]
+      section-choice:    custom-required
+      section-name:      .mysection2
+---
+defined-atoms:
+    - ref-name:          L1
+      type:              constant
+      merge:             by-content
+      content:           [ 05, 06, 07, 08 ]
+      section-choice:    custom-required
+      section-name:      .mysection
+
+    - ref-name:          L2
+      type:              constant
+      merge:             by-content
+      content:           [ 01, 02, 03, 04 ]
+...
+
+
+# CHECK:defined-atoms:
+# CHECK:  - type:            constant
+# CHECK:    content:         [ 01, 02, 03, 04 ]
+# CHECK:    merge:           by-content
+# CHECK:    section-choice:  custom-required
+# CHECK:    section-name:    .mysection
+# CHECK:  - type:            constant
+# CHECK:    content:         [ 05, 06, 07, 08 ]
+# CHECK:    merge:           by-content
+# CHECK:    section-choice:  custom-required
+# CHECK:    section-name:    .mysection
+# CHECK:  - type:            constant
+# CHECK:    content:         [ 01, 02, 03, 04 ]
+# CHECK:    merge:           by-content
+# CHECK:  - type:            constant
+# CHECK:    content:         [ 01, 02, 03, 04 ]
+# CHECK:    merge:           by-content
+# CHECK:    section-choice:  custom-required
+# CHECK:    section-name:    .mysection2





More information about the llvm-commits mailing list