summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/InputFiles.cpp6
-rw-r--r--lld/ELF/LinkerScript.cpp6
-rw-r--r--lld/ELF/Writer.cpp2
-rw-r--r--lld/test/ELF/merge-reloc.s15
4 files changed, 11 insertions, 18 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index c8ff74a7101..e2b46357068 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -288,12 +288,6 @@ template <class ELFT> bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &Sec) {
if (Config->Optimize == 0)
return false;
- // Do not merge sections if generating a relocatable object. It makes
- // the code simpler because we do not need to update relocation addends
- // to reflect changes introduced by merging.
- if (Config->Relocatable)
- return false;
-
// A mergeable section with size 0 is useless because they don't have
// any data to merge. A mergeable string section with size 0 can be
// argued as invalid because it doesn't end with a null character.
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 0f4b0f978e7..2140eb4148e 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -465,9 +465,9 @@ static OutputSection *addInputSec(StringMap<OutputSection *> &Map,
return Out->RelocationSection;
}
- // When control reaches here, mergeable sections have already been
- // merged except the -r case. If that's the case, we do not combine them
- // and let final link to handle this optimization.
+ // When control reaches here, mergeable sections have already been merged into
+ // synthetic sections. For relocatable case we want to create one output
+ // section per syntetic section so that they have a valid sh_entsize.
if (Config->Relocatable && (IS->Flags & SHF_MERGE))
return createSection(IS, OutsecName);
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index f44185812eb..6a3655a1438 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -496,7 +496,7 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
// Unlike other synthetic sections, mergeable output sections contain data
// copied from input sections, and there may be a relocation pointing to its
- // contents if -emit-reloc is given.
+ // contents if -r or -emit-reloc are given.
if (isa<SyntheticSection>(IS) && !(IS->Flags & SHF_MERGE))
continue;
diff --git a/lld/test/ELF/merge-reloc.s b/lld/test/ELF/merge-reloc.s
index bdb83743ec1..3dde6aa3529 100644
--- a/lld/test/ELF/merge-reloc.s
+++ b/lld/test/ELF/merge-reloc.s
@@ -3,10 +3,9 @@
# RUN: ld.lld %t.o -r -o %t-rel
# RUN: llvm-readobj -s -section-data %t-rel | FileCheck %s
-# When linker generates a relocatable object it should keep "merge"
-# sections as-is: do not merge content, do not join regular and
-# "merge" sections, do not joint "merge" sections with different
-# entry size.
+# When linker generates a relocatable object it does string merging in the same
+# way as for regular link. It should keep SHF_MERGE flag and set proper sh_entsize
+# value so that final link can perform the final merging optimization.
# CHECK: Section {
# CHECK: Index:
@@ -18,13 +17,13 @@
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset:
-# CHECK-NEXT: Size: 12
+# CHECK-NEXT: Size: 4
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
# CHECK-NEXT: AddressAlignment: 4
# CHECK-NEXT: EntrySize: 4
# CHECK-NEXT: SectionData (
-# CHECK-NEXT: 0000: 42000000 42000000 42000000
+# CHECK-NEXT: 0000: 42000000
# CHECK-NEXT: )
# CHECK-NEXT: }
# CHECK: Section {
@@ -37,13 +36,13 @@
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset:
-# CHECK-NEXT: Size: 16
+# CHECK-NEXT: Size: 8
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
# CHECK-NEXT: AddressAlignment: 8
# CHECK-NEXT: EntrySize: 8
# CHECK-NEXT: SectionData (
-# CHECK-NEXT: 0000: 42000000 42000000 42000000 42000000
+# CHECK-NEXT: 0000: 42000000 42000000
# CHECK-NEXT: )
# CHECK-NEXT: }
# CHECK: Section {
OpenPOWER on IntegriCloud