Index: lib/Transforms/Instrumentation/SafeStack.cpp =================================================================== --- lib/Transforms/Instrumentation/SafeStack.cpp +++ lib/Transforms/Instrumentation/SafeStack.cpp @@ -47,6 +47,10 @@ #define DEBUG_TYPE "safestack" +static cl::opt UseTLS("safe-stack-tls", + cl::Hidden, cl::init(true), + cl::desc("Use thread-local storage for the unsafe stack pointer")); + namespace llvm { STATISTIC(NumFunctions, "Total number of functions"); @@ -345,18 +349,22 @@ dyn_cast_or_null(M.getNamedValue(UnsafeStackPtrVar)); if (!UnsafeStackPtr) { + auto TLSModel = UseTLS ? + GlobalValue::InitialExecTLSModel : + GlobalValue::NotThreadLocal; // The global variable is not defined yet, define it ourselves. // We use the initial-exec TLS model because we do not support the // variable living anywhere other than in the main executable. UnsafeStackPtr = new GlobalVariable( M, StackPtrTy, false, GlobalValue::ExternalLinkage, nullptr, - UnsafeStackPtrVar, nullptr, GlobalValue::InitialExecTLSModel); + UnsafeStackPtrVar, nullptr, TLSModel); } else { // The variable exists, check its type and attributes. if (UnsafeStackPtr->getValueType() != StackPtrTy) report_fatal_error(Twine(UnsafeStackPtrVar) + " must have void* type"); - if (!UnsafeStackPtr->isThreadLocal()) - report_fatal_error(Twine(UnsafeStackPtrVar) + " must be thread-local"); + if (UseTLS != UnsafeStackPtr->isThreadLocal()) + report_fatal_error(Twine(UnsafeStackPtrVar) + " must " + + (UseTLS ? "" : "not ") + "be thread-local"); } return UnsafeStackPtr; }