[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.
This commit is contained in:
Fangrui Song 2021-07-06 11:08:47 -07:00
parent 4ec7c02197
commit 7b6b15e010
1 changed files with 25 additions and 1 deletions

View File

@ -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 <stdio.h>