Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -655,6 +655,7 @@ // the assembler keeping the .L symbol. if (sym.getName().startswith(".L") && (config->discard == DiscardPolicy::Locals || + config->emachine == EM_RISCV || (sym.section && (sym.section->flags & SHF_MERGE)))) return false; return true; Index: lld/test/ELF/discard-locals-riscv.s =================================================================== --- /dev/null +++ lld/test/ELF/discard-locals-riscv.s @@ -0,0 +1,12 @@ +# REQUIRES: riscv + +# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.o +# RUN: ld.lld %t.o -o - | llvm-readelf -s - | FileCheck %s + +# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.o -save-temp-labels +# RUN: ld.lld %t.o -o - -discard-none | llvm-readelf -s - | FileCheck %s --check-prefix=NONE + +# CHECK-NOT: .Llabel +# NONE: .Llabel + +.Llabel: