[PATCH] D40026: [ELF] - Allow applying SHF_MERGE optimization for relocatable output.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 04:44:36 PST 2017
grimar updated this revision to Diff 123158.
grimar added a comment.
- Rebased. Most of changes were gone away.
https://reviews.llvm.org/D40026
Files:
ELF/InputFiles.cpp
ELF/LinkerScript.cpp
ELF/Writer.cpp
test/ELF/merge-reloc.s
Index: test/ELF/merge-reloc.s
===================================================================
--- test/ELF/merge-reloc.s
+++ 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 do 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 {
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -496,7 +496,7 @@
// 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;
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -466,9 +466,10 @@
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.
+ // For relocatable case each input mergeable section contains data grouped by
+ // sh_entsize and we want to allow final link to perform the last merging
+ // optimization, so we emit unique output section for each input.
if (Config->Relocatable && (IS->Flags & SHF_MERGE))
return createSection(IS, OutsecName);
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -288,12 +288,6 @@
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40026.123158.patch
Type: text/x-patch
Size: 3627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171116/344976c7/attachment.bin>
More information about the llvm-commits
mailing list