Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -642,6 +642,9 @@ if (DtFlags1) ++NumEntries; // DT_FLAGS_1 + if (!Config->Entry.empty() && Config->EMachine != EM_MIPS) + ++NumEntries; // DT_DEBUG + if (Config->EMachine == EM_MIPS) { ++NumEntries; // DT_MIPS_RLD_VERSION ++NumEntries; // DT_MIPS_FLAGS @@ -740,6 +743,8 @@ WriteVal(DT_FLAGS, DtFlags); if (DtFlags1) WriteVal(DT_FLAGS_1, DtFlags1); + if (!Config->Entry.empty() && Config->EMachine != EM_MIPS) + WriteVal(DT_DEBUG, 0); // See "Dynamic Section" in Chapter 5 in the following document // for detailed description: Index: test/ELF/dt_tags.s =================================================================== --- /dev/null +++ test/ELF/dt_tags.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd %s -o %t +# RUN: ld.lld -shared %t -o %t.so +# RUN: ld.lld %t %t.so -o %t.exe +# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DSO %s +# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck -check-prefix=EXE %s + +# EXE: DynamicSection [ +# EXE: 0x0000000000000015 DEBUG 0x0 +# EXE: ] + +# DSO: DynamicSection [ +# DSO-NOT: 0x0000000000000015 DEBUG 0x0 +# DSO: ] + +.globl _start +_start: