Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -226,6 +226,11 @@ if (Sections[I] == &InputSection::Discarded) continue; + if (Sec.sh_flags & SHF_EXCLUDE) { + Sections[I] = &InputSection::Discarded; + continue; + } + switch (Sec.sh_type) { case SHT_GROUP: Sections[I] = &InputSection::Discarded; 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"