File tree Expand file tree Collapse file tree 4 files changed +28
-4
lines changed
lib/Transforms/Instrumentation Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 21
21
#include " llvm/ADT/StringSwitch.h"
22
22
#include " llvm/Option/ArgList.h"
23
23
#include " llvm/ProfileData/InstrProf.h"
24
+ #include " llvm/ProfileData/MemProf.h"
24
25
#include " llvm/Support/Path.h"
25
26
#include " llvm/Support/ScopedPrinter.h"
26
27
#include " llvm/Support/Threading.h"
@@ -1617,6 +1618,12 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
1617
1618
}
1618
1619
}
1619
1620
1621
+ if (Sanitize.needsMemProfRt ())
1622
+ if (hasExportSymbolDirective (Args))
1623
+ addExportedSymbol (
1624
+ CmdArgs,
1625
+ llvm::memprof::getMemprofOptionsSymbolDarwinLinkageName ().data ());
1626
+
1620
1627
const XRayArgs &XRay = getXRayArgs ();
1621
1628
if (XRay.needsXRayRt ()) {
1622
1629
AddLinkRuntimeLib (Args, CmdArgs, " xray" );
Original file line number Diff line number Diff line change 17
17
18
18
// RUN: not %clangxx --target=x86_64-linux-gnu -fprofile-generate -fmemory-profile-use=foo %s -### 2>&1 | FileCheck %s --check-prefix=CONFLICTWITHPGOINSTR
19
19
// CONFLICTWITHPGOINSTR: error: invalid argument '-fmemory-profile-use=foo' not allowed with '-fprofile-generate'
20
+
21
+ // Test that we export the __memprof_default_options_str on Darwin because it has WeakAnyLinkage
22
+ // RUN: %clangxx --target=arm64-apple-ios -fmemory-profile %s -### 2>&1 | FileCheck %s --check-prefix=EXPORT-BASE --implicit-check-not=exported_symbol
23
+ // RUN: %clangxx --target=arm64-apple-ios -fmemory-profile -exported_symbols_list /dev/null %s -### 2>&1 | FileCheck %s --check-prefixes=EXPORT-BASE,EXPORT
24
+ // FIXME: Darwin needs to link in the runtime, then we can use the regular CHECK prefix
25
+ // EXPORT-BASE: "-cc1" {{.*}} "-fmemory-profile"
26
+ // EXPORT: "-exported_symbol" "___memprof_default_options_str"
Original file line number Diff line number Diff line change 6
6
#include " llvm/ADT/STLForwardCompat.h"
7
7
#include " llvm/ADT/STLFunctionalExtras.h"
8
8
#include " llvm/ADT/SmallVector.h"
9
+ #include " llvm/ADT/StringRef.h"
9
10
#include " llvm/IR/GlobalValue.h"
10
11
#include " llvm/ProfileData/MemProfData.inc"
11
12
#include " llvm/Support/BLAKE3.h"
@@ -42,6 +43,16 @@ constexpr uint64_t MaximumSupportedVersion = Version3;
42
43
// Verify that the minimum and maximum satisfy the obvious constraint.
43
44
static_assert (MinimumSupportedVersion <= MaximumSupportedVersion);
44
45
46
+ inline llvm::StringRef getMemprofOptionsSymbolDarwinLinkageName () {
47
+ return " ___memprof_default_options_str" ;
48
+ }
49
+
50
+ inline llvm::StringRef getMemprofOptionsSymbolName () {
51
+ // Darwin linkage names are prefixed with an extra "_". See
52
+ // DataLayout::getGlobalPrefix().
53
+ return getMemprofOptionsSymbolDarwinLinkageName ().drop_front ();
54
+ }
55
+
45
56
enum class Meta : uint64_t {
46
57
Start = 0 ,
47
58
#define MIBEntryDef (NameTag, Name, Type ) NameTag,
Original file line number Diff line number Diff line change @@ -568,10 +568,9 @@ void createMemprofHistogramFlagVar(Module &M) {
568
568
void createMemprofDefaultOptionsVar (Module &M) {
569
569
Constant *OptionsConst = ConstantDataArray::getString (
570
570
M.getContext (), MemprofRuntimeDefaultOptions, /* AddNull=*/ true );
571
- GlobalVariable *OptionsVar =
572
- new GlobalVariable (M, OptionsConst->getType (), /* isConstant=*/ true ,
573
- GlobalValue::WeakAnyLinkage, OptionsConst,
574
- " __memprof_default_options_str" );
571
+ GlobalVariable *OptionsVar = new GlobalVariable (
572
+ M, OptionsConst->getType (), /* isConstant=*/ true ,
573
+ GlobalValue::WeakAnyLinkage, OptionsConst, getMemprofOptionsSymbolName ());
575
574
Triple TT (M.getTargetTriple ());
576
575
if (TT.supportsCOMDAT ()) {
577
576
OptionsVar->setLinkage (GlobalValue::ExternalLinkage);
You can’t perform that action at this time.
0 commit comments