Skip to content

Commit 5939422

Browse files
[compiler-rt][profile] Use encapsulation symbols for Wasm format
Use `InstrProfilingPlatformLinux.c` for Wasm as well as Wasm format has encapsulation symbols (`__start_` and `__stop_`) similar to ELF. This unlocks several additional profile features like value profiling.
1 parent 605e1ad commit 5939422

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

compiler-rt/lib/profile/InstrProfilingPlatformLinux.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
|*
77
\*===----------------------------------------------------------------------===*/
88

9-
#if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
10-
(defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) || \
11-
defined(_AIX)
9+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
10+
(defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) || \
11+
defined(_AIX) || defined(__wasm__)
1212

13-
#if !defined(_AIX)
13+
#if !defined(_AIX) && !defined(__wasm__)
1414
#include <elf.h>
1515
#include <link.h>
1616
#endif

compiler-rt/lib/profile/InstrProfilingPlatformOther.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \
1010
!defined(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) && \
11-
!defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX)
11+
!defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX) && \
12+
!defined(__wasm__)
1213

1314
#include <stdlib.h>
1415
#include <stdio.h>

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,9 +1406,10 @@ static inline Constant *getFuncAddrForProfData(Function *Fn) {
14061406

14071407
static bool needsRuntimeRegistrationOfSectionRange(const Triple &TT) {
14081408
// compiler-rt uses linker support to get data/counters/name start/end for
1409-
// ELF, COFF, Mach-O and XCOFF.
1409+
// ELF, COFF, Mach-O, XCOFF, and Wasm.
14101410
if (TT.isOSBinFormatELF() || TT.isOSBinFormatCOFF() ||
1411-
TT.isOSBinFormatMachO() || TT.isOSBinFormatXCOFF())
1411+
TT.isOSBinFormatMachO() || TT.isOSBinFormatXCOFF() ||
1412+
TT.isOSBinFormatWasm())
14121413
return false;
14131414

14141415
return true;

llvm/test/Instrumentation/InstrProfiling/profiling.ll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ declare void @llvm.instrprof.increment(ptr, i64, i32, i32)
114114
; PS: %[[REG:.*]] = load i32, ptr @__llvm_profile_runtime
115115
; XCOFF-NOT: define .* __llvm_profile_runtime_user
116116

117-
; WASM: define internal void @__llvm_profile_register_functions() unnamed_addr {
118-
; WASM-NEXT: call void @__llvm_profile_register_function(ptr @__profd_foo)
119-
; WASM-NEXT: call void @__llvm_profile_register_function(ptr @__profd_foo_weak)
120-
; WASM: call void @__llvm_profile_register_names_function(ptr @__llvm_prf_nm
121-
; WASM-NEXT: ret void
122-
; WASM-NEXT: }
117+
; WASM-NOT: internal void @__llvm_profile_register_functions()
123118

124119
; XCOFF-NOT: internal void @__llvm_profile_register_functions()

0 commit comments

Comments
 (0)