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 2121#include " llvm/ADT/StringSwitch.h"
2222#include " llvm/Option/ArgList.h"
2323#include " llvm/ProfileData/InstrProf.h"
24+ #include " llvm/ProfileData/MemProf.h"
2425#include " llvm/Support/Path.h"
2526#include " llvm/Support/ScopedPrinter.h"
2627#include " llvm/Support/Threading.h"
@@ -1617,6 +1618,12 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
16171618 }
16181619 }
16191620
1621+ if (Sanitize.needsMemProfRt ())
1622+ if (hasExportSymbolDirective (Args))
1623+ addExportedSymbol (
1624+ CmdArgs,
1625+ llvm::memprof::getMemprofOptionsSymbolDarwinLinkageName ().data ());
1626+
16201627 const XRayArgs &XRay = getXRayArgs ();
16211628 if (XRay.needsXRayRt ()) {
16221629 AddLinkRuntimeLib (Args, CmdArgs, " xray" );
Original file line number Diff line number Diff line change 1717
1818// RUN: not %clangxx --target=x86_64-linux-gnu -fprofile-generate -fmemory-profile-use=foo %s -### 2>&1 | FileCheck %s --check-prefix=CONFLICTWITHPGOINSTR
1919// 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 66#include " llvm/ADT/STLForwardCompat.h"
77#include " llvm/ADT/STLFunctionalExtras.h"
88#include " llvm/ADT/SmallVector.h"
9+ #include " llvm/ADT/StringRef.h"
910#include " llvm/IR/GlobalValue.h"
1011#include " llvm/ProfileData/MemProfData.inc"
1112#include " llvm/Support/BLAKE3.h"
@@ -42,6 +43,16 @@ constexpr uint64_t MaximumSupportedVersion = Version3;
4243// Verify that the minimum and maximum satisfy the obvious constraint.
4344static_assert (MinimumSupportedVersion <= MaximumSupportedVersion);
4445
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+
4556enum class Meta : uint64_t {
4657 Start = 0 ,
4758#define MIBEntryDef (NameTag, Name, Type ) NameTag,
Original file line number Diff line number Diff line change @@ -568,10 +568,9 @@ void createMemprofHistogramFlagVar(Module &M) {
568568void createMemprofDefaultOptionsVar (Module &M) {
569569 Constant *OptionsConst = ConstantDataArray::getString (
570570 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 ());
575574 Triple TT (M.getTargetTriple ());
576575 if (TT.supportsCOMDAT ()) {
577576 OptionsVar->setLinkage (GlobalValue::ExternalLinkage);
You can’t perform that action at this time.
0 commit comments