Drop conflicting sh_entsize values.

An output section can include elements from two input sections with
different sh_entsize. When that happens the output section itself
should not have a sh_entsize.

llvm-svn: 318311
This commit is contained in:
Rafael Espindola 2017-11-15 17:35:22 +00:00
parent 3f0b575363
commit 8bc2a19ef8
3 changed files with 34 additions and 9 deletions

View File

@ -91,9 +91,10 @@ static bool canMergeToProgbits(unsigned Type) {
void OutputSection::addSection(InputSection *IS) {
if (!Live) {
// If IS is the first section to be added to this section,
// initialize Type by IS->Type.
// initialize Type and Entsize from IS.
Live = true;
Type = IS->Type;
Entsize = IS->Entsize;
} else {
// Otherwise, check if new type or flags are compatible with existing ones.
if ((Flags & (SHF_ALLOC | SHF_TLS)) != (IS->Flags & (SHF_ALLOC | SHF_TLS)))
@ -124,13 +125,10 @@ void OutputSection::addSection(InputSection *IS) {
this->Size = IS->OutSecOff + IS->getSize();
// If this section contains a table of fixed-size entries, sh_entsize
// holds the element size. Consequently, if this contains two or more
// input sections, all of them must have the same sh_entsize. However,
// you can put different types of input sections into one output
// section by using linker scripts. I don't know what to do here.
// Probably we sholuld handle that as an error. But for now we just
// pick the largest sh_entsize.
this->Entsize = std::max(this->Entsize, IS->Entsize);
// holds the element size. If it contains elements of different size we
// set sh_entsize to 0.
if (Entsize != IS->Entsize)
Entsize = 0;
if (!IS->Assigned) {
IS->Assigned = true;

View File

@ -21,7 +21,7 @@
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
# CHECK-NEXT: AddressAlignment: 2
# CHECK-NEXT: EntrySize: 2
# CHECK-NEXT: EntrySize: 0
# CHECK-NEXT: }
# CHECK: Name: begin

View File

@ -0,0 +1,27 @@
// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: ld.lld %t.o -o %t
// RUN: llvm-readobj -s %t | FileCheck %s
.section .rodata.1,"aM",@progbits,1
.byte 0x42
.section .rodata.2,"aM",@progbits,2
.short 0x42
// Since the output section has both .rodata.1 and .rodata.2, it
// contains elements of different sizes and we use an entsize of 0.
// CHECK: Name: .rodata (
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_ALLOC
// CHECK-NEXT: SHF_MERGE
// CHECK-NEXT: ]
// CHECK-NEXT: Address:
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size:
// CHECK-NEXT: Link:
// CHECK-NEXT: Info:
// CHECK-NEXT: AddressAlignment:
// CHECK-NEXT: EntrySize: 0