Skip to content

Commit

Permalink
[ELF] Allow sh_entsize to be unrelated to sh_addralign and not a powe…
Browse files Browse the repository at this point in the history
…r of 2

Summary:
This implements Rui Ueyama's idea in PR39044.
I've checked that ld.bfd and gold do not have the power-of-2 requirement
and do not require sh_entsize to be a multiple of sh_align.

Now on the updated test merge-entsize.s, all the 3 linkers happily
create .rodata that is not 3-byte aligned.

This has a use case in Linux arch/x86/crypto/sha512-avx2-asm.S
It uses sh_entsize of 640, which is not a power of 2.
See ClangBuiltLinux/linux#417

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: nickdesaulniers, E5ten, emaste, arichardson, llvm-commits

Tags: #llvm

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

llvm-svn: 356428
  • Loading branch information
MaskRay committed Mar 18, 2019
1 parent ad4d52a commit 1092fc9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
5 changes: 2 additions & 3 deletions lld/ELF/SyntheticSections.cpp
Expand Up @@ -3016,7 +3016,6 @@ void elf::mergeSections() {
}

StringRef OutsecName = getOutputSectionName(MS);
uint32_t Alignment = std::max<uint32_t>(MS->Alignment, MS->Entsize);

auto I = llvm::find_if(MergeSections, [=](MergeSyntheticSection *Sec) {
// While we could create a single synthetic section for two different
Expand All @@ -3028,11 +3027,11 @@ void elf::mergeSections() {
// Using Entsize in here also allows us to propagate it to the synthetic
// section.
return Sec->Name == OutsecName && Sec->Flags == MS->Flags &&
Sec->Entsize == MS->Entsize && Sec->Alignment == Alignment;
Sec->Entsize == MS->Entsize && Sec->Alignment == MS->Alignment;
});
if (I == MergeSections.end()) {
MergeSyntheticSection *Syn =
createMergeSynthetic(OutsecName, MS->Type, MS->Flags, Alignment);
createMergeSynthetic(OutsecName, MS->Type, MS->Flags, MS->Alignment);
MergeSections.push_back(Syn);
I = std::prev(MergeSections.end());
S = Syn;
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/icf-merged-sections.s
Expand Up @@ -19,7 +19,7 @@
# CHECK-NEXT: Size: 16
# CHECK-NEXT: Link:
# CHECK-NEXT: Info:
# CHECK-NEXT: AddressAlignment: 8
# CHECK-NEXT: AddressAlignment: 1
# CHECK-NEXT: EntrySize: 0
# CHECK-NEXT: SectionData (
# CHECK-NEXT: 0000: 67452301 10325476 67452301 10325476
Expand Down
9 changes: 7 additions & 2 deletions lld/test/ELF/merge-entsize.s
Expand Up @@ -4,10 +4,15 @@
// RUN: llvm-readobj -s %t | FileCheck %s

.section .rodata.1,"aM",@progbits,1
.p2align 2
.byte 0x42

.section .rodata.2,"aM",@progbits,2
// sh_addralign = 4 while sh_entsize = 3.
// sh_entsize is not necessarily a power of 2 and it can be unrelated to sh_addralign.
.section .rodata.2,"aM",@progbits,3
.p2align 2
.short 0x42
.byte 0

// Since the output section has both .rodata.1 and .rodata.2, it
// contains elements of different sizes and we use an entsize of 0.
Expand All @@ -23,5 +28,5 @@
// CHECK-NEXT: Size:
// CHECK-NEXT: Link:
// CHECK-NEXT: Info:
// CHECK-NEXT: AddressAlignment:
// CHECK-NEXT: AddressAlignment: 4
// CHECK-NEXT: EntrySize: 0
4 changes: 2 additions & 2 deletions lld/test/ELF/merge-gc-piece.s
Expand Up @@ -10,7 +10,7 @@
# CHECK-NEXT: SHF_ALLOC
# CHECK-NEXT: SHF_MERGE
# CHECK-NEXT: ]
# CHECK-NEXT: Address: 0x200
# CHECK-NEXT: Address: 0x1FD

# CHECK: Name: .bar
# CHECK-NEXT: Type: SHT_PROGBITS
Expand All @@ -24,7 +24,7 @@
# CHECK-NEXT: AddressAlignment:
# CHECK-NEXT: EntrySize:
# CHECK-NEXT: SectionData (
# CHECK-NEXT: 0000: 01020000 00000000 02020000 00000000
# CHECK-NEXT: 0000: FE010000 00000000 FF010000 00000000
# CHECK-NEXT: )

.section .foo,"aM",@progbits,8
Expand Down
4 changes: 2 additions & 2 deletions lld/test/ELF/merge-reloc-O0.s
Expand Up @@ -16,7 +16,7 @@
# CHECK-NEXT: Size: 16
# CHECK-NEXT: Link:
# CHECK-NEXT: Info:
# CHECK-NEXT: AddressAlignment: 8
# CHECK-NEXT: AddressAlignment: 1
# CHECK-NEXT: EntrySize: 8
# CHECK-NEXT: SectionData (
# CHECK-NEXT: 0000: 41000000 00000000 42000000 00000000
Expand All @@ -33,7 +33,7 @@
# CHECK-NEXT: Size: 8
# CHECK-NEXT: Link:
# CHECK-NEXT: Info:
# CHECK-NEXT: AddressAlignment: 4
# CHECK-NEXT: AddressAlignment: 1
# CHECK-NEXT: EntrySize: 4
# CHECK-NEXT: SectionData (
# CHECK-NEXT: 0000: 41000000 42000000
Expand Down
4 changes: 2 additions & 2 deletions lld/test/ELF/merge-sym.s
Expand Up @@ -15,7 +15,7 @@ foo:
// CHECK-NEXT: SHF_ALLOC
// CHECK-NEXT: SHF_MERGE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x210
// CHECK-NEXT: Address: 0x20D

// CHECK: Name: foo
// CHECK-NEXT: Value: 0x212
// CHECK-NEXT: Value: 0x20F

0 comments on commit 1092fc9

Please sign in to comment.