forked from OSchip/llvm-project
Add a minimal fix for PR36878.
When looking for the output section and the output offset the expectation was that the caller had looked at Repl. That works fine for InputSections, but in the case of MergeInputSections the caller doesn't have the section that is actually replaced. The original testcase was failing because getOutputSection was returning null. The slightly extended testcase also checks that getOffset also checks Repl. I will send a refactoring separetelly. llvm-svn: 328332
This commit is contained in:
parent
256f149bf0
commit
4376cffb57
|
@ -156,7 +156,7 @@ uint64_t SectionBase::getOffset(uint64_t Offset) const {
|
|||
case Merge:
|
||||
const MergeInputSection *MS = cast<MergeInputSection>(this);
|
||||
if (InputSection *IS = MS->getParent())
|
||||
return IS->OutSecOff + MS->getOffset(Offset);
|
||||
return cast<InputSection>(IS->Repl)->OutSecOff + MS->getOffset(Offset);
|
||||
return MS->getOffset(Offset);
|
||||
}
|
||||
llvm_unreachable("invalid section kind");
|
||||
|
@ -165,14 +165,14 @@ uint64_t SectionBase::getOffset(uint64_t Offset) const {
|
|||
OutputSection *SectionBase::getOutputSection() {
|
||||
InputSection *Sec;
|
||||
if (auto *IS = dyn_cast<InputSection>(this))
|
||||
return IS->getParent();
|
||||
Sec = IS;
|
||||
else if (auto *MS = dyn_cast<MergeInputSection>(this))
|
||||
Sec = MS->getParent();
|
||||
else if (auto *EH = dyn_cast<EhInputSection>(this))
|
||||
Sec = EH->getParent();
|
||||
else
|
||||
return cast<OutputSection>(this);
|
||||
return Sec ? Sec->getParent() : nullptr;
|
||||
return Sec ? cast<InputSection>(Sec->Repl)->getParent() : nullptr;
|
||||
}
|
||||
|
||||
// Decompress section contents if required. Note that this function
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
# REQUIRES: x86
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
|
||||
# RUN: ld.lld %t.o -o %t --icf=all --ignore-data-address-equality --print-icf-sections | FileCheck %s --check-prefix ICF
|
||||
# RUN: llvm-objdump -s -d -print-imm-hex %t | FileCheck %s
|
||||
|
||||
# ICF: selected section <internal>:(.rodata)
|
||||
# ICF-NEXT: removing identical section <internal>:(.rodata)
|
||||
|
||||
# CHECK: {{^}}.text:
|
||||
# CHECK-NEXT: movq 0x[[ADDR:[0-9a-f]+]], %rax
|
||||
# CHECK-NEXT: movq 0x[[ADDR]], %rax
|
||||
# CHECK: Contents of section .rodata:
|
||||
# CHECK-NEXT: 2a000000 00000000 67452301 10325476
|
||||
|
||||
.section .rodata, "a"
|
||||
.quad 42
|
||||
|
||||
.section .rodata.cst4,"aM",@progbits,4
|
||||
rodata4:
|
||||
.long 0x01234567
|
||||
.long 0x76543210
|
||||
.long 0x01234567
|
||||
.long 0x76543210
|
||||
|
||||
.section .rodata.cst8,"aM",@progbits,8
|
||||
rodata8:
|
||||
.long 0x01234567
|
||||
.long 0x76543210
|
||||
|
||||
.section .text,"ax"
|
||||
movq rodata4, %rax
|
||||
movq rodata8, %rax
|
Loading…
Reference in New Issue