Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -240,6 +240,8 @@ Loc = Buf; if (uint32_t Filler = Script::X->getFiller(this->Name)) fill(Buf, this->Size, Filler); + else if (Flags & SHF_EXECINSTR) + fill(Buf, this->Size, Target->DefaultExecutableFill); auto Fn = [=](InputSection *IS) { IS->writeTo(Buf); }; forEach(Sections.begin(), Sections.end(), Fn); Index: ELF/Target.h =================================================================== --- ELF/Target.h +++ ELF/Target.h @@ -98,6 +98,8 @@ virtual void relaxTlsGdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; virtual void relaxTlsIeToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; virtual void relaxTlsLdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; + + uint32_t DefaultExecutableFill = 0; }; uint64_t getPPC64TocBase(); Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -355,6 +355,8 @@ PltEntrySize = 16; PltHeaderSize = 16; TlsGdRelaxSkip = 2; + // 0xCC is the "int3" (call debug exception handler) instruction. + DefaultExecutableFill = 0xcccccccc; } RelExpr X86TargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const { @@ -647,6 +649,8 @@ // Align to the large page size (known as a superpage or huge page). // FreeBSD automatically promotes large, superpage-aligned allocations. DefaultImageBase = 0x200000; + // 0xCC is the "int3" (call debug exception handler) instruction. + DefaultExecutableFill = 0xcccccccc; } template Index: test/ELF/default-fill.s =================================================================== --- test/ELF/default-fill.s +++ test/ELF/default-fill.s @@ -0,0 +1,22 @@ +# REQUIRES: x86 +# Verify that the fill between sections has a default of interrupt instructions +# (0xcc on x86) + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t.elf +# RUN: llvm-objdump -disassemble %t.elf | FileCheck %s +# CHECK-NOT: 00 00 addb +# CHECK: cc int3 +# CHECK-NOT: 00 00 addb + +.section .text.1,"ax",@progbits +.align 16 +.globl _start +_start: + retq + +.section .text.2,"ax",@progbits +.align 16 +.globl other +other: + retq Index: test/ELF/linkerscript/excludefile.s =================================================================== --- test/ELF/linkerscript/excludefile.s +++ test/ELF/linkerscript/excludefile.s @@ -13,11 +13,13 @@ # CHECK: _start: # CHECK-NEXT: : 48 c7 c0 3c 00 00 00 movq $60, %rax # CHECK-NEXT: : 48 c7 c7 2a 00 00 00 movq $42, %rdi -# CHECK-NEXT: : 00 00 addb %al, (%rax) +# CHECK-NEXT: : cc int3 +# CHECK-NEXT: : cc int3 # CHECK: _potato: # CHECK-NEXT: : 90 nop # CHECK-NEXT: : 90 nop -# CHECK-NEXT: : 00 00 addb %al, (%rax) +# CHECK-NEXT: : cc int3 +# CHECK-NEXT: : cc int3 # CHECK: tomato: # CHECK-NEXT: : b8 01 00 00 00 movl $1, %eax @@ -31,7 +33,8 @@ # EXCLUDE: _start: # EXCLUDE-NEXT: : 48 c7 c0 3c 00 00 00 movq $60, %rax # EXCLUDE-NEXT: : 48 c7 c7 2a 00 00 00 movq $42, %rdi -# EXCLUDE-NEXT: : 00 00 addb %al, (%rax) +# EXCLUDE-NEXT: : cc int3 +# EXCLUDE-NEXT: : cc int3 # EXCLUDE: _potato: # EXCLUDE-NEXT: : 90 nop # EXCLUDE-NEXT: : 90 nop