From 2d53967b486fa213613f4ced6b3087050997b82b Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 23 Feb 2018 10:37:33 +0000 Subject: [PATCH] Recommit "[ELF] - Do not crash with --emit-relocs and --icf=all together." Latest patch version now. Original commit message: [ELF] - Do not crash with --emit-relocs and --icf=all together. Previously we would crash because did not mark .rel[a] sections as dead and they tried to access parent which was not live after ICF and therefore was null. Differential revision: https://reviews.llvm.org/D43241 llvm-svn: 325879 --- lld/ELF/ICF.cpp | 15 ++++++--------- lld/test/ELF/emit-relocs-icf.s | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 lld/test/ELF/emit-relocs-icf.s diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index c3b96bd..8b58c99 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -437,17 +437,14 @@ template void ICF::run() { for (size_t I = Begin + 1; I < End; ++I) { print(" removing identical section " + toString(Sections[I])); Sections[Begin]->replace(Sections[I]); + + // At this point we know sections merged are fully identical and hence + // we want to remove duplicate implicit dependencies such as link order + // and relocation sections. + for (InputSection *IS : Sections[I]->DependentSections) + IS->Live = false; } }); - - // Mark ARM Exception Index table sections that refer to folded code - // sections as not live. These sections have an implict dependency - // via the link order dependency. - if (Config->EMachine == EM_ARM) - for (InputSectionBase *Sec : InputSections) - if (auto *S = dyn_cast(Sec)) - if (S->Flags & SHF_LINK_ORDER) - S->Live = S->getLinkOrderDep()->Live; } // ICF entry point function. diff --git a/lld/test/ELF/emit-relocs-icf.s b/lld/test/ELF/emit-relocs-icf.s new file mode 100644 index 0000000..59e003f --- /dev/null +++ b/lld/test/ELF/emit-relocs-icf.s @@ -0,0 +1,33 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: ld.lld --emit-relocs --icf=all %t1.o -o %t +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section {{.*}} .rela.text { +# CHECK-NEXT: R_X86_64_32 .text 0x1 +# CHECK-NEXT: R_X86_64_PLT32 fn 0xFFFFFFFFFFFFFFFC +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.section .text.fn,"ax",@progbits,unique,0 +.globl fn +.type fn,@function +fn: + nop + +bar: + movl $bar, %edx + callq fn@PLT + nop + +.section .text.fn2,"ax",@progbits,unique,1 +.globl fn2 +.type fn2,@function +fn2: + nop + +foo: + movl $foo, %edx + callq fn2@PLT + nop -- 2.7.4