Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -650,11 +650,12 @@ // In ELF assembly .L symbols are normally discarded by the assembler. // If the assembler fails to do so, the linker discards them if - // * --discard-locals is used. + // * --discard-locals is used, or if the architecture is riscv. // * The symbol is in a SHF_MERGE section, which is normally the reason for // 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: