Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -210,7 +210,7 @@ uint64_t val, uint8_t stOther = STV_HIDDEN, uint8_t binding = STB_GLOBAL) { Symbol *s = symtab->find(name); - if (!s || s->isDefined()) + if (!s || s->isDefined() || !s->isUsedInRegularObj) return nullptr; s->resolve(Defined{/*file=*/nullptr, name, binding, stOther, STT_NOTYPE, val, Index: lld/test/ELF/Inputs/nodef-reserved-in-dep.s =================================================================== --- /dev/null +++ lld/test/ELF/Inputs/nodef-reserved-in-dep.s @@ -0,0 +1,2 @@ +.globl _edata + _edata = 0x123 Index: lld/test/ELF/nodef-reserved-in-dep.s =================================================================== --- /dev/null +++ lld/test/ELF/nodef-reserved-in-dep.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/nodef-reserved-in-dep.s -o %t.o +# RUN: ld.lld %t.o -o %t.so -shared -soname=so + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t2.o +# RUN: ld.lld -o %t %t2.o %t.so +# RUN: llvm-readobj --symbols -S %t | FileCheck %s + +## _edata should not appear anywhere in the binary. +# CHECK-NOT: _edata + +.global _start +_start: + xor %eax, %eax