[PATCH] D43241: [ELF] - Do not crash with --emit-relocs and --icf=all together.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 09:02:46 PST 2018


LGTM.

Thanks!
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> grimar updated this revision to Diff 134859.
> grimar added a comment.
>
> - Addressed comments.
>
>
> https://reviews.llvm.org/D43241
>
> Files:
>   ELF/ICF.cpp
>   test/ELF/emit-relocs-icf.s
>
>
> Index: test/ELF/emit-relocs-icf.s
> ===================================================================
> --- test/ELF/emit-relocs-icf.s
> +++ 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", at progbits,unique,0
> +.globl fn
> +.type fn, at function
> +fn:
> + nop
> +
> +bar:
> +  movl $bar, %edx
> +  callq fn at PLT
> +  nop
> +
> +.section .text.fn2,"ax", at progbits,unique,1
> +.globl fn2
> +.type fn2, at function
> +fn2:
> + nop
> +
> +foo:
> +  movl $foo, %edx
> +  callq fn2 at PLT
> +  nop
> Index: ELF/ICF.cpp
> ===================================================================
> --- ELF/ICF.cpp
> +++ ELF/ICF.cpp
> @@ -437,17 +437,14 @@
>      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<InputSection>(Sec))
> -        if (S->Flags & SHF_LINK_ORDER)
> -          S->Live = S->getLinkOrderDep()->Live;
>  }
>  
>  // ICF entry point function.
>
>
> Index: test/ELF/emit-relocs-icf.s
> ===================================================================
> --- test/ELF/emit-relocs-icf.s
> +++ 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", at progbits,unique,0
> +.globl fn
> +.type fn, at function
> +fn:
> + nop
> +
> +bar:
> +  movl $bar, %edx
> +  callq fn at PLT
> +  nop
> +
> +.section .text.fn2,"ax", at progbits,unique,1
> +.globl fn2
> +.type fn2, at function
> +fn2:
> + nop
> +
> +foo:
> +  movl $foo, %edx
> +  callq fn2 at PLT
> +  nop
> Index: ELF/ICF.cpp
> ===================================================================
> --- ELF/ICF.cpp
> +++ ELF/ICF.cpp
> @@ -437,17 +437,14 @@
>      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<InputSection>(Sec))
> -        if (S->Flags & SHF_LINK_ORDER)
> -          S->Live = S->getLinkOrderDep()->Live;
>  }
>  
>  // ICF entry point function.


More information about the llvm-commits mailing list