[PATCH] D30033: [ELF] - Do not crash when discarding sections that are referenced by others.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 16 08:14:47 PST 2017
LGTM.
Cheers,
Rafael
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar created this revision.
>
> SHF_LINK_ORDER sections adds special ordering requirements.
> Such sections references other sections. Previously we would crash
> if section that other were referenced to was discarded by script.
>
> Patch fixes that by discarding all dependent sections in that case.
> It supports chained dependencies, testcase is provided.
>
>
> https://reviews.llvm.org/D30033
>
> Files:
> ELF/LinkerScript.cpp
> test/ELF/linkerscript/discard-section-metadata.s
>
>
> Index: test/ELF/linkerscript/discard-section-metadata.s
> ===================================================================
> --- test/ELF/linkerscript/discard-section-metadata.s
> +++ test/ELF/linkerscript/discard-section-metadata.s
> @@ -0,0 +1,32 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> +# RUN: echo "SECTIONS { /DISCARD/ : { *(.foo) } }" > %t.script
> +# RUN: ld.lld -o %t1 --script %t.script %t
> +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
> +
> +# CHECK-NOT: .foo
> +# CHECK-NOT: .bar
> +# CHECK-NOT: .zed
> +# CHECK-NOT: .moo
> +
> +## Sections dependency tree for testcase is:
> +## (.foo)
> +## | |
> +## | --(.bar)
> +## |
> +## --(.zed)
> +## |
> +## --(.moo)
> +##
> +
> +.section .foo,"a"
> +.quad 0
> +
> +.section .bar,"am", at progbits,.foo
> +.quad 0
> +
> +.section .zed,"am", at progbits,.foo
> +.quad 0
> +
> +.section .moo,"am", at progbits,.zed
> +.quad 0
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -272,6 +272,11 @@
> for (InputSectionBase<ELFT> *S : V) {
> S->Live = false;
> reportDiscarded(S);
> +
> + InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S);
> + if (!IS || IS->DependentSections.empty())
> + continue;
> + discard(IS->DependentSections);
> }
> }
>
>
>
> Index: test/ELF/linkerscript/discard-section-metadata.s
> ===================================================================
> --- test/ELF/linkerscript/discard-section-metadata.s
> +++ test/ELF/linkerscript/discard-section-metadata.s
> @@ -0,0 +1,32 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> +# RUN: echo "SECTIONS { /DISCARD/ : { *(.foo) } }" > %t.script
> +# RUN: ld.lld -o %t1 --script %t.script %t
> +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
> +
> +# CHECK-NOT: .foo
> +# CHECK-NOT: .bar
> +# CHECK-NOT: .zed
> +# CHECK-NOT: .moo
> +
> +## Sections dependency tree for testcase is:
> +## (.foo)
> +## | |
> +## | --(.bar)
> +## |
> +## --(.zed)
> +## |
> +## --(.moo)
> +##
> +
> +.section .foo,"a"
> +.quad 0
> +
> +.section .bar,"am", at progbits,.foo
> +.quad 0
> +
> +.section .zed,"am", at progbits,.foo
> +.quad 0
> +
> +.section .moo,"am", at progbits,.zed
> +.quad 0
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -272,6 +272,11 @@
> for (InputSectionBase<ELFT> *S : V) {
> S->Live = false;
> reportDiscarded(S);
> +
> + InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S);
> + if (!IS || IS->DependentSections.empty())
> + continue;
> + discard(IS->DependentSections);
> }
> }
>
More information about the llvm-commits
mailing list