Skip to content

Commit 2d98bdc

Browse files
authored
Revert "[llvm][clang] Allocate a new stack instead of spawning a new … (#135865)
…thread to get more stack space (#133173)" This change breaks the Clang build on Mac AArch64. This reverts commit d0c973a. This reverts commit 429a84f. This reverts commit 4f64c80.
1 parent d037217 commit 2d98bdc

File tree

12 files changed

+30
-250
lines changed

12 files changed

+30
-250
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ Non-comprehensive list of changes in this release
195195
- Added `__builtin_elementwise_exp10`.
196196
- For AMDPGU targets, added `__builtin_v_cvt_off_f32_i4` that maps to the `v_cvt_off_f32_i4` instruction.
197197
- Added `__builtin_elementwise_minnum` and `__builtin_elementwise_maxnum`.
198-
- Clang itself now uses split stacks instead of threads for allocating more
199-
stack space when running on Apple AArch64 based platforms. This means that
200-
stack traces of Clang from debuggers, crashes, and profilers may look
201-
different than before.
202198

203199
New Compiler Flags
204200
------------------

clang/include/clang/Basic/Stack.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ namespace clang {
2727

2828
/// Call this once on each thread, as soon after starting the thread as
2929
/// feasible, to note the approximate address of the bottom of the stack.
30-
///
31-
/// \param ForceSet set to true if you know the call is near the bottom of a
32-
/// new stack. Used for split stacks.
33-
void noteBottomOfStack(bool ForceSet = false);
30+
void noteBottomOfStack();
3431

3532
/// Determine whether the stack is nearly exhausted.
3633
bool isStackNearlyExhausted();

clang/lib/Basic/Stack.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,33 @@
1313

1414
#include "clang/Basic/Stack.h"
1515
#include "llvm/Support/CrashRecoveryContext.h"
16-
#include "llvm/Support/ProgramStack.h"
1716

18-
static LLVM_THREAD_LOCAL uintptr_t BottomOfStack = 0;
17+
#ifdef _MSC_VER
18+
#include <intrin.h> // for _AddressOfReturnAddress
19+
#endif
1920

20-
void clang::noteBottomOfStack(bool ForceSet) {
21-
if (!BottomOfStack || ForceSet)
22-
BottomOfStack = llvm::getStackPointer();
21+
static LLVM_THREAD_LOCAL void *BottomOfStack = nullptr;
22+
23+
static void *getStackPointer() {
24+
#if __GNUC__ || __has_builtin(__builtin_frame_address)
25+
return __builtin_frame_address(0);
26+
#elif defined(_MSC_VER)
27+
return _AddressOfReturnAddress();
28+
#else
29+
char CharOnStack = 0;
30+
// The volatile store here is intended to escape the local variable, to
31+
// prevent the compiler from optimizing CharOnStack into anything other
32+
// than a char on the stack.
33+
//
34+
// Tested on: MSVC 2015 - 2019, GCC 4.9 - 9, Clang 3.2 - 9, ICC 13 - 19.
35+
char *volatile Ptr = &CharOnStack;
36+
return Ptr;
37+
#endif
38+
}
39+
40+
void clang::noteBottomOfStack() {
41+
if (!BottomOfStack)
42+
BottomOfStack = getStackPointer();
2343
}
2444

2545
bool clang::isStackNearlyExhausted() {
@@ -31,8 +51,7 @@ bool clang::isStackNearlyExhausted() {
3151
if (!BottomOfStack)
3252
return false;
3353

34-
intptr_t StackDiff =
35-
(intptr_t)llvm::getStackPointer() - (intptr_t)BottomOfStack;
54+
intptr_t StackDiff = (intptr_t)getStackPointer() - (intptr_t)BottomOfStack;
3655
size_t StackUsage = (size_t)std::abs(StackDiff);
3756

3857
// If the stack pointer has a surprising value, we do not understand this
@@ -47,12 +66,9 @@ bool clang::isStackNearlyExhausted() {
4766
void clang::runWithSufficientStackSpaceSlow(llvm::function_ref<void()> Diag,
4867
llvm::function_ref<void()> Fn) {
4968
llvm::CrashRecoveryContext CRC;
50-
// Preserve the BottomOfStack in case RunSafelyOnNewStack uses split stacks.
51-
uintptr_t PrevBottom = BottomOfStack;
52-
CRC.RunSafelyOnNewStack([&] {
53-
noteBottomOfStack(true);
69+
CRC.RunSafelyOnThread([&] {
70+
noteBottomOfStack();
5471
Diag();
5572
Fn();
5673
}, DesiredStackSize);
57-
BottomOfStack = PrevBottom;
5874
}

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ bool CompilerInstance::compileModule(SourceLocation ImportLoc,
12651265

12661266
// Execute the action to actually build the module in-place. Use a separate
12671267
// thread so that we get a stack large enough.
1268-
bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnNewStack(
1268+
bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnThread(
12691269
[&]() {
12701270
GenerateModuleFromModuleMapAction Action;
12711271
Instance.ExecuteAction(Action);

llvm/include/llvm/Support/CrashRecoveryContext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ class CrashRecoveryContext {
9797
return RunSafelyOnThread([&]() { Fn(UserData); }, RequestedStackSize);
9898
}
9999

100-
bool RunSafelyOnNewStack(function_ref<void()>,
101-
unsigned RequestedStackSize = 0);
102-
103100
/// Explicitly trigger a crash recovery in the current process, and
104101
/// return failure from RunSafely(). This function does not return.
105102
[[noreturn]] void HandleExit(int RetCode);

llvm/include/llvm/Support/ProgramStack.h

Lines changed: 0 additions & 63 deletions
This file was deleted.

llvm/include/llvm/Support/thread.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ inline thread::id get_id() { return std::this_thread::get_id(); }
213213

214214
#else // !LLVM_ENABLE_THREADS
215215

216-
#include "llvm/Support/ErrorHandling.h"
217216
#include <utility>
218217

219218
namespace llvm {

llvm/lib/Support/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ add_llvm_component_library(LLVMSupport
295295
Path.cpp
296296
Process.cpp
297297
Program.cpp
298-
ProgramStack.cpp
299298
RWMutex.cpp
300299
Signals.cpp
301300
Threading.cpp

llvm/lib/Support/CrashRecoveryContext.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "llvm/Config/llvm-config.h"
1111
#include "llvm/Support/ErrorHandling.h"
1212
#include "llvm/Support/ExitCodes.h"
13-
#include "llvm/Support/ProgramStack.h"
1413
#include "llvm/Support/Signals.h"
1514
#include "llvm/Support/thread.h"
1615
#include <cassert>
@@ -524,13 +523,3 @@ bool CrashRecoveryContext::RunSafelyOnThread(function_ref<void()> Fn,
524523
CRC->setSwitchedThread();
525524
return Info.Result;
526525
}
527-
528-
bool CrashRecoveryContext::RunSafelyOnNewStack(function_ref<void()> Fn,
529-
unsigned RequestedStackSize) {
530-
#ifdef LLVM_HAS_SPLIT_STACKS
531-
return runOnNewStack(RequestedStackSize,
532-
function_ref<bool()>([&]() { return RunSafely(Fn); }));
533-
#else
534-
return RunSafelyOnThread(Fn, RequestedStackSize);
535-
#endif
536-
}

llvm/lib/Support/ProgramStack.cpp

Lines changed: 0 additions & 114 deletions
This file was deleted.

llvm/unittests/Support/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ add_llvm_unittest(SupportTests
7070
PerThreadBumpPtrAllocatorTest.cpp
7171
ProcessTest.cpp
7272
ProgramTest.cpp
73-
ProgramStackTest.cpp
7473
RecyclerTest.cpp
7574
RegexTest.cpp
7675
ReverseIterationTest.cpp

llvm/unittests/Support/ProgramStackTest.cpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)