diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -261,7 +261,7 @@ if (isReserved(sec) || script->shouldKeep(sec)) { enqueue(sec, 0); - } else if (isValidCIdentifier(sec->name)) { + } else if (isValidCIdentifier(sec->name) && !sec->nextInSectionGroup) { cNamedSections[saver.save("__start_" + sec->name)].push_back(sec); cNamedSections[saver.save("__stop_" + sec->name)].push_back(sec); } diff --git a/lld/test/ELF/comdat-gc-startstop.s b/lld/test/ELF/comdat-gc-startstop.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/comdat-gc-startstop.s @@ -0,0 +1,36 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: ld.lld --gc-sections %t.o -o %t +// RUN: llvm-readelf --symbols %t | FileCheck %s + +.weak __start___llvm_prf_data +.weak __stop___llvm_prf_data + +.section .text,"ax",@progbits +.global _start +_start: + .quad __start___llvm_prf_data - . + .quad __stop___llvm_prf_data - . + call f + +.section __llvm_prf_data,"axG",@progbits,f,comdat,unique,0 +.quad 0 + +.section .text.f,"axG",@progbits,f,comdat,unique,0 +.global f +f: + nop + +.section __llvm_prf_data,"axG",@progbits,g,comdat,unique,0 +.quad 0 + +.section .text.g,"axG",@progbits,g,comdat,unique,0 +.global g +g: + nop + +// CHECK: 0000000000201136 0 NOTYPE GLOBAL PROTECTED 2 __start___llvm_prf_data +// CHECK: 000000000020113e 0 NOTYPE GLOBAL PROTECTED 2 __stop___llvm_prf_data +// CHECK: 0000000000201120 0 NOTYPE GLOBAL DEFAULT 1 _start +// CHECK: 0000000000201135 0 NOTYPE GLOBAL DEFAULT 1 f +// CHECK-NOT: 0000000000201136 0 NOTYPE GLOBAL DEFAULT 1 g