Index: lib/Core/SymbolTable.cpp =================================================================== --- lib/Core/SymbolTable.cpp +++ lib/Core/SymbolTable.cpp @@ -339,6 +339,12 @@ 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 lc = l->rawContent(); ArrayRef rc = r->rawContent(); return memcmp(lc.data(), rc.data(), lc.size()) == 0; Index: test/core/custom-section-coalesce.objtxt =================================================================== --- /dev/null +++ test/core/custom-section-coalesce.objtxt @@ -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