[PATCH] D41640: [ELF] - Do not ignore discarding of .rela.plt/.rela.dyn

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 16:23:08 PST 2018


LGTM

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

> grimar created this revision.
> grimar added reviewers: ruiu, rafael.
>
> Currently when we build input sections list in linker script
> we ignore all rel[a] sections. That was done to support
> scripts like `.rela.dyn : { *(.rela.data) }` for emit relocs.
>
> Though as a result following scripts were also silently ignored:
>
> /DISCARD/ : { *(.rela.plt)
> /DISCARD/ : { *(.rela.dyn)
>
> and we produced output with this sections. That is not ideal.
> Solution this patch suggests is simple: do not ignore synthetic
> rel[a] sections. That way we can enable common discarding logic
> for them and report proper error.
>
>
> https://reviews.llvm.org/D41640
>
> Files:
>   ELF/LinkerScript.cpp
>   test/ELF/linkerscript/discard-section-err.s
>
>
> Index: test/ELF/linkerscript/discard-section-err.s
> ===================================================================
> --- test/ELF/linkerscript/discard-section-err.s
> +++ test/ELF/linkerscript/discard-section-err.s
> @@ -22,4 +22,14 @@
>  # RUN:   FileCheck -check-prefix=DYNSTR %s
>  # DYNSTR: discarding .dynstr section is not allowed
>  
> +# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.plt) } }" > %t.script
> +# RUN: not ld.lld -pie -o %t --script %t.script %t.o %t.so 2>&1 | \
> +# RUN:   FileCheck -check-prefix=RELAPLT %s
> +# RELAPLT: discarding .rela.plt section is not allowed
> +
> +# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.dyn) } }" > %t.script
> +# RUN: not ld.lld -pie -o %t --script %t.script %t.o %t.so 2>&1 | \
> +# RUN:   FileCheck -check-prefix=RELADYN %s
> +# RELADYN: discarding .rela.dyn section is not allowed
> +
>  .comm foo,4,4
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -290,7 +290,8 @@
>        // For -emit-relocs we have to ignore entries like
>        //   .rela.dyn : { *(.rela.data) }
>        // which are common because they are in the default bfd script.
> -      if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA)
> +      if (!isa<SyntheticSection>(Sec) &&
> +          (Sec->Type == SHT_REL || Sec->Type == SHT_RELA))
>          continue;
>  
>        std::string Filename = getFilename(Sec->File);
> @@ -315,7 +316,7 @@
>  void LinkerScript::discard(ArrayRef<InputSection *> V) {
>    for (InputSection *S : V) {
>      if (S == InX::ShStrTab || S == InX::Dynamic || S == InX::DynSymTab ||
> -        S == InX::DynStrTab)
> +        S == InX::DynStrTab || S == InX::RelaPlt || S == InX::RelaDyn)
>        error("discarding " + S->Name + " section is not allowed");
>  
>      S->Assigned = false;
>
>
> Index: test/ELF/linkerscript/discard-section-err.s
> ===================================================================
> --- test/ELF/linkerscript/discard-section-err.s
> +++ test/ELF/linkerscript/discard-section-err.s
> @@ -22,4 +22,14 @@
>  # RUN:   FileCheck -check-prefix=DYNSTR %s
>  # DYNSTR: discarding .dynstr section is not allowed
>  
> +# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.plt) } }" > %t.script
> +# RUN: not ld.lld -pie -o %t --script %t.script %t.o %t.so 2>&1 | \
> +# RUN:   FileCheck -check-prefix=RELAPLT %s
> +# RELAPLT: discarding .rela.plt section is not allowed
> +
> +# RUN: echo "SECTIONS { /DISCARD/ : { *(.rela.dyn) } }" > %t.script
> +# RUN: not ld.lld -pie -o %t --script %t.script %t.o %t.so 2>&1 | \
> +# RUN:   FileCheck -check-prefix=RELADYN %s
> +# RELADYN: discarding .rela.dyn section is not allowed
> +
>  .comm foo,4,4
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -290,7 +290,8 @@
>        // For -emit-relocs we have to ignore entries like
>        //   .rela.dyn : { *(.rela.data) }
>        // which are common because they are in the default bfd script.
> -      if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA)
> +      if (!isa<SyntheticSection>(Sec) &&
> +          (Sec->Type == SHT_REL || Sec->Type == SHT_RELA))
>          continue;
>  
>        std::string Filename = getFilename(Sec->File);
> @@ -315,7 +316,7 @@
>  void LinkerScript::discard(ArrayRef<InputSection *> V) {
>    for (InputSection *S : V) {
>      if (S == InX::ShStrTab || S == InX::Dynamic || S == InX::DynSymTab ||
> -        S == InX::DynStrTab)
> +        S == InX::DynStrTab || S == InX::RelaPlt || S == InX::RelaDyn)
>        error("discarding " + S->Name + " section is not allowed");
>  
>      S->Assigned = false;


More information about the llvm-commits mailing list