[PATCH] D24966: [ELF] Ignore sections flagged with SHF_EXCLUDE

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 27 09:25:04 PDT 2016


LGTM, but please simplify the test. You don't need a linker script for example.

On 27 September 2016 at 08:15, Eugene Leviant <evgeny.leviant at gmail.com> wrote:
> evgeny777 created this revision.
> evgeny777 added reviewers: ruiu, rafael.
> evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
> evgeny777 set the repository for this revision to rL LLVM.
> evgeny777 added a project: lld.
>
> The spec says:
>
>> This section is excluded from input to the link-edit of an executable or shared object. This flag is ignored if the SHF_ALLOC flag is also set, or if relocations exist against the section.
>
> However both gold and ld seem to always discard such sections. The same approach was chosen for this patch.
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D24966
>
> Files:
>   ELF/InputFiles.cpp
>   test/ELF/exclude.s
>
> Index: test/ELF/exclude.s
> ===================================================================
> --- test/ELF/exclude.s
> +++ test/ELF/exclude.s
> @@ -0,0 +1,12 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> +# RUN: echo "SECTIONS { .text : { *(.text*) } }" > %t.script
> +# RUN: ld.lld -o %t1 --script %t.script %t
> +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
> +# CHECK-NOT:      .aaa
> +
> +.globl _start
> +_start:
> +  jmp _start
> +
> +.section .aaa,"ae"
> Index: ELF/InputFiles.cpp
> ===================================================================
> --- ELF/InputFiles.cpp
> +++ ELF/InputFiles.cpp
> @@ -226,6 +226,11 @@
>      if (Sections[I] == &InputSection<ELFT>::Discarded)
>        continue;
>
> +    if (Sec.sh_flags & SHF_EXCLUDE) {
> +      Sections[I] = &InputSection<ELFT>::Discarded;
> +      continue;
> +    }
> +
>      switch (Sec.sh_type) {
>      case SHT_GROUP:
>        Sections[I] = &InputSection<ELFT>::Discarded;
>
>


More information about the llvm-commits mailing list