diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index bf501e473a7e6..bde9c1aa2fd63 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -433,9 +433,9 @@ static void markUsedLocalSymbolsImpl(ObjFile *file, // The function ensures that the "used" field of local symbols reflects the fact // that the symbol is used in a relocation from a live section. template static void markUsedLocalSymbols(Ctx &ctx) { - // With --gc-sections, the field is already filled. + // With --gc-sections, the field is already filled, unless -r is specified. // See MarkLive::resolveReloc(). - if (ctx.arg.gcSections) + if (ctx.arg.gcSections && !ctx.arg.relocatable) return; for (ELFFileBase *file : ctx.objectFiles) { ObjFile *f = cast>(file);