Skip to content

Commit

Permalink
[profile][test] Improve coverage-linkage.cpp with ld.lld --gc-sections
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MaskRay committed Jul 6, 2021
1 parent 4ec7c02 commit 7b6b15e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion 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 <stdio.h>

Expand Down

0 comments on commit 7b6b15e

Please sign in to comment.