[ELF] Name MergeSyntheticSection using an input section instead of the output section
authorFangrui Song <i@maskray.me>
Tue, 2 May 2023 16:35:00 +0000 (09:35 -0700)
committerFangrui Song <i@maskray.me>
Tue, 2 May 2023 16:35:00 +0000 (09:35 -0700)
In a link map, the input section name gives more information. See the updated
merge-entsize.s for an example. The output file is unchanged.

Compiler generated input sections with the SHF_MERGE flag have names such as
.rodata.str1.1 and .rodata.cstN, and are not affected by -fdata-sections.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D149466

lld/ELF/OutputSections.cpp
lld/test/ELF/merge-entsize.s
lld/test/ELF/merge-string-align.s

index a1aec83..97f676f 100644 (file)
@@ -217,7 +217,7 @@ void OutputSection::finalizeInputSections() {
       });
       if (i == mergeSections.end()) {
         MergeSyntheticSection *syn =
-            createMergeSynthetic(name, ms->type, ms->flags, ms->addralign);
+            createMergeSynthetic(s->name, ms->type, ms->flags, ms->addralign);
         mergeSections.push_back(syn);
         i = std::prev(mergeSections.end());
         syn->entsize = ms->entsize;
index 080d71b..f45b334 100644 (file)
@@ -1,8 +1,12 @@
 // REQUIRES: x86
 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-// RUN: ld.lld %t.o -o %t
+// RUN: ld.lld %t.o -o %t -M | FileCheck %s --check-prefix=MAP
 // RUN: llvm-readobj -S %t | FileCheck %s
 
+// MAP:      .rodata{{$}}
+// MAP-NEXT:         <internal>:(.rodata.1)
+// MAP-NEXT:         <internal>:(.rodata.2)
+
         .section  .rodata.1,"aM",@progbits,1
         .p2align 2
         .byte 0x42
index 0098d95..661019d 100644 (file)
@@ -1,8 +1,13 @@
 // REQUIRES: x86
 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-// RUN: ld.lld %t.o -o %t.so -shared
+// RUN: ld.lld %t.o -o %t.so -shared -M | FileCheck %s --check-prefix=MAP
 // RUN: llvm-readobj -S --section-data %t.so | FileCheck %s
 
+// MAP:      .rodata{{$}}
+// MAP-NEXT:         <internal>:(.rodata.foo)
+// MAP-NEXT: .rodata2
+// MAP-NEXT:         <internal>:(.rodata2)
+
         .section        .rodata.foo,"aMS",@progbits,1
         .align  16
         .asciz "foo"