From 6ff82bd0ec7ddfd991cb8e57e2dfbf23f068c992 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 18 Oct 2016 00:02:28 +0000 Subject: [PATCH] [profile] Mark lprofCurFilename as COMPILER_RT_WEAK This makes __llvm_profile_set_filename() work across dylib boundaries on Darwin. This functionality was originally meant to work on all platforms, but was moved to a Linux-only directory with r272404. The root cause of the test failure on Darwin was that lprofCurFilename was not marked weak. Each dylib maintained its own copy of the variable due to the two-level namespace. Tested with check-profile (on Darwin). I don't expect this to regress other platforms. Differential Revision: https://reviews.llvm.org/D25707 llvm-svn: 284440 --- compiler-rt/lib/profile/InstrProfilingFile.c | 3 ++- .../profile/{Linux => }/instrprof-set-filename-shared.test | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) rename compiler-rt/test/profile/{Linux => }/instrprof-set-filename-shared.test (81%) diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c index e264f63886bc..44f5d9ab859f 100644 --- a/compiler-rt/lib/profile/InstrProfilingFile.c +++ b/compiler-rt/lib/profile/InstrProfilingFile.c @@ -82,7 +82,8 @@ typedef struct lprofFilename { ProfileNameSpecifier PNS; } lprofFilename; -lprofFilename lprofCurFilename = {0, 0, 0, {0}, {0}, 0, 0, 0, PNS_unknown}; +COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0, 0, 0, {0}, {0}, + 0, 0, 0, PNS_unknown}; int getpid(void); static int getCurFilenameLength(); diff --git a/compiler-rt/test/profile/Linux/instrprof-set-filename-shared.test b/compiler-rt/test/profile/instrprof-set-filename-shared.test similarity index 81% rename from compiler-rt/test/profile/Linux/instrprof-set-filename-shared.test rename to compiler-rt/test/profile/instrprof-set-filename-shared.test index 29e6713289d9..afcb4b4fd2d6 100644 --- a/compiler-rt/test/profile/Linux/instrprof-set-filename-shared.test +++ b/compiler-rt/test/profile/instrprof-set-filename-shared.test @@ -1,7 +1,7 @@ # Test that __llvm_profile_set_filename is honored by shared libary too. RUN: mkdir -p %t.d -RUN: %clang_profgen=%t.shared.profraw -fPIC -shared -o %t.d/t.shared %S/../Inputs/instrprof-dlopen-func.c -RUN: %clang_profgen -DCALL_SHARED -o %t.m -O3 -rpath %t.d %t.d/t.shared %S/../instrprof-set-filename.c +RUN: %clang_profgen=%t.shared.profraw -fPIC -shared -o %t.d/t.shared %S/Inputs/instrprof-dlopen-func.c +RUN: %clang_profgen -DCALL_SHARED -o %t.m -O3 -rpath %t.d %t.d/t.shared %S/instrprof-set-filename.c RUN: %run %t.m %t.main.profraw RUN: llvm-profdata show %t.main.profraw | FileCheck --check-prefix=SHARED %s