From 7b6b15e010664ec444f3c20a9b15ff4324c8971c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 6 Jul 2021 11:08:47 -0700 Subject: [PATCH] [profile][test] Improve coverage-linkage.cpp with ld.lld --gc-sections The __llvm_prf_names section uses SHF_GNU_RETAIN. However, GNU ld before 2015-10 (https://sourceware.org/bugzilla/show_bug.cgi?id=19161) neither supports it nor retains __llvm_prf_names according to __start___llvm_prf_names. So --gc-sections does not work on such old GNU ld. This is not a problem for gold and sufficiently new lld. --- .../test/profile/Linux/coverage-linkage.cpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/compiler-rt/test/profile/Linux/coverage-linkage.cpp b/compiler-rt/test/profile/Linux/coverage-linkage.cpp index 32a63fb000955..8a52bfc97d949 100644 --- a/compiler-rt/test/profile/Linux/coverage-linkage.cpp +++ b/compiler-rt/test/profile/Linux/coverage-linkage.cpp @@ -1,9 +1,33 @@ /// Test instrumentation can handle various linkages. +// REQUIRES: lld-available // RUN: %clang_profgen -fcoverage-mapping %s -o %t // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t +// RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s -// RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -Wl,--gc-sections %s -o %t +// RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -fuse-ld=lld -Wl,--gc-sections %s -o %t // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t +// RUN: llvm-profdata show %t.profraw --all-functions | FileCheck %s + +// CHECK: {{.*}}external{{.*}}: +// CHECK-NEXT: Hash: +// CHECK-NEXT: Counters: 1 +// CHECK-NEXT: Function count: 1 +// CHECK: {{.*}}weak{{.*}}: +// CHECK-NEXT: Hash: +// CHECK-NEXT: Counters: 1 +// CHECK-NEXT: Function count: 1 +// CHECK: main: +// CHECK-NEXT: Hash: +// CHECK-NEXT: Counters: 1 +// CHECK-NEXT: Function count: 1 +// CHECK: {{.*}}internal{{.*}}: +// CHECK-NEXT: Hash: +// CHECK-NEXT: Counters: 1 +// CHECK-NEXT: Function count: 1 +// CHECK: {{.*}}linkonce_odr{{.*}}: +// CHECK-NEXT: Hash: +// CHECK-NEXT: Counters: 1 +// CHECK-NEXT: Function count: 1 #include