[lld] d4bed61 - [ELF] -r: keep sh_entsize for SHF_MERGE sections with relocations

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 23 14:32:37 PST 2024


Author: Fangrui Song
Date: 2024-11-23T14:32:32-08:00
New Revision: d4bed617f4378873d7ddf4b53c041e7b39d1a9ca

URL: https://github.com/llvm/llvm-project/commit/d4bed617f4378873d7ddf4b53c041e7b39d1a9ca
DIFF: https://github.com/llvm/llvm-project/commit/d4bed617f4378873d7ddf4b53c041e7b39d1a9ca.diff

LOG: [ELF] -r: keep sh_entsize for SHF_MERGE sections with relocations

Follow-up to the NFC refactoring
43e3871a327b8e2ff57e16b46d5bc44beb430d91 and test cleanup
3cecf17065919da0a7fa9b38f37592e5462c2f85.

SHF_MERGE sections with relocations are handled as InputSection (without
duplicate elimination). The output section retains the original
sh_entsize in non-relocatable links. This patch ports the behavior for
relocatable links as well.

https://github.com/ClangBuiltLinux/linux/issues/2057

Added: 
    

Modified: 
    lld/ELF/InputFiles.cpp
    lld/test/ELF/merge-reloc.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index b89faa57985ceb..14131dd9f765ce 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -904,7 +904,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
       // is acceptable because section merging is optional.
       if (auto *ms = dyn_cast<MergeInputSection>(s)) {
         s = makeThreadLocal<InputSection>(ms->file, ms->name, ms->type,
-                                          ms->flags, ms->addralign, 0,
+                                          ms->flags, ms->addralign, ms->entsize,
                                           ms->contentMaybeDecompress());
         sections[info] = s;
       }

diff  --git a/lld/test/ELF/merge-reloc.s b/lld/test/ELF/merge-reloc.s
index 044fef5ab4f26a..75a48099f50892 100644
--- a/lld/test/ELF/merge-reloc.s
+++ b/lld/test/ELF/merge-reloc.s
@@ -12,9 +12,9 @@
 # CHECK-NEXT:  [ 1] .text             PROGBITS        0000000000000000 000040 000000 00  AX  0   0  4
 # CHECK-NEXT:  [ 2] .rodata.1         PROGBITS        0000000000000000 000040 000004 04  AM  0   0  4
 # CHECK-NEXT:  [ 3] .rodata.2         PROGBITS        0000000000000000 000048 000008 08  AM  0   0  8
-# CHECK-NEXT:  [ 4] .rodata.cst8      PROGBITS        0000000000000000 000050 000010 00  AM  0   0  1
+# CHECK-NEXT:  [ 4] .rodata.cst8      PROGBITS        0000000000000000 000050 000010 08  AM  0   0  1
 # CHECK-NEXT:  [ 5] .rela.rodata.cst8 RELA            0000000000000000 000068 000030 18   I  9   4  8
-# CHECK-NEXT:  [ 6] .cst4             PROGBITS        0000000000000000 000060 000008 00  AM  0   0  1
+# CHECK-NEXT:  [ 6] .cst4             PROGBITS        0000000000000000 000060 000008 04  AM  0   0  1
 # CHECK-NEXT:  [ 7] .rela.cst4        RELA            0000000000000000 000098 000030 18   I  9   6  8
 
 # OBJDUMP:      Contents of section .rodata.1:
@@ -26,7 +26,7 @@
 # OBJDUMP:      Contents of section .cst4:
 # OBJDUMP-NEXT:  0000 00000000 00000000                    ........
 
-# CHECK-PDE: [ 2] .cst4             PROGBITS        0000000000200140 000140 000008 00  AM  0   0  1
+# CHECK-PDE: [ 2] .cst4             PROGBITS        0000000000200140 000140 000008 04  AM  0   0  1
 
 foo:
 


        


More information about the llvm-commits mailing list