Skip to content

Commit f5b85a0

Browse files
committed
Add helper functions and comment
1 parent 2e19467 commit f5b85a0

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
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"
@@ -1619,7 +1620,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
16191620

16201621
if (Sanitize.needsMemProfRt())
16211622
if (hasExportSymbolDirective(Args))
1622-
addExportedSymbol(CmdArgs, "___memprof_default_options_str");
1623+
addExportedSymbol(
1624+
CmdArgs,
1625+
llvm::memprof::getMemprofOptionsSymbolDarwinLinkageName().data());
16231626

16241627
const XRayArgs &XRay = getXRayArgs();
16251628
if (XRay.needsXRayRt()) {

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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.
4344
static_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+
4556
enum class Meta : uint64_t {
4657
Start = 0,
4758
#define MIBEntryDef(NameTag, Name, Type) NameTag,

llvm/lib/Transforms/Instrumentation/MemProfiler.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,9 @@ void createMemprofHistogramFlagVar(Module &M) {
568568
void 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);

0 commit comments

Comments
 (0)