Skip to content

Commit 885d7b7

Browse files
committed
[compiler-rt] [builtins] Remove unused/misnamed x86 chkstk functions
For both MSVC and MinGW targets, the compiler generates calls to functions for probing the stack, in functions that allocate a larger amount of stack space. The exact behaviour of these functions differ per architecture (some decrement the stack, some actually decrement the stack pointer, some only probe the stack). In MSVC mode, the compiler always generates calls to a symbol named "__chkstk". In MinGW mode, the symbol is named "__alloca" on i386 and "___chkstk_ms" on x86_64, but the functions behave exactly the same as their MSVC counterparts despite the differing names. (On i386, these names are the raw symbol names - if considering a C level function name with the extra implicit leading underscore, they would be called "_chkstk" and "_alloca".) Remove the misleading duplicate and unused functions. These were added in fbfed86 / c27de5b (adding "___chkstk_ms" for both architectures, even if that symbol name only was used on x86_64) and 40eb83b (adding "__alloca" and "___chkstk", even if the former only was used on i386, and the latter seeming like a misspelled form of the MSVC function, with three underscores instead of two). The x86_64 "___chkstk" was doubly surprising as that function had the same behaviour as the function used on i386, while the "__chkstk" that MSVC emitted calls to should behave exactly like the preexisting "___chkstk_ms". Remove the unused functions, and rename the misspelled MSVC-like symbols to the correct name that MSVC mode actually uses. Note that these files aren't assembled at all when building compiler-rt builtins in MSVC mode, as they are expected to be provided by MSVC libraries when building code in MSVC mode. Differential Revision: https://reviews.llvm.org/D159139
1 parent 95062d7 commit 885d7b7

File tree

5 files changed

+4
-82
lines changed

5 files changed

+4
-82
lines changed

compiler-rt/lib/builtins/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ if (NOT MSVC)
330330
set(x86_64_SOURCES
331331
${x86_64_SOURCES}
332332
x86_64/chkstk.S
333-
x86_64/chkstk2.S
334333
)
335334
endif()
336335

@@ -363,7 +362,6 @@ if (NOT MSVC)
363362
if (WIN32)
364363
set(i386_SOURCES
365364
${i386_SOURCES}
366-
i386/chkstk.S
367365
i386/chkstk2.S
368366
)
369367
endif()

compiler-rt/lib/builtins/i386/chkstk.S

-35
This file was deleted.

compiler-rt/lib/builtins/i386/chkstk2.S

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
.text
1515
.balign 4
1616
DEFINE_COMPILERRT_FUNCTION(_alloca) // _chkstk and _alloca are the same function
17-
DEFINE_COMPILERRT_FUNCTION(__chkstk)
17+
DEFINE_COMPILERRT_FUNCTION(_chkstk)
1818
push %ecx
1919
cmp $0x1000,%eax
2020
lea 8(%esp),%ecx // esp before calling this routine -> ecx
@@ -35,7 +35,7 @@ DEFINE_COMPILERRT_FUNCTION(__chkstk)
3535
push (%eax) // push return address onto the stack
3636
sub %esp,%eax // restore the original value in eax
3737
ret
38-
END_COMPILERRT_FUNCTION(__chkstk)
38+
END_COMPILERRT_FUNCTION(_chkstk)
3939
END_COMPILERRT_FUNCTION(_alloca)
4040

4141
#endif // __i386__

compiler-rt/lib/builtins/x86_64/chkstk.S

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
.text
1919
.balign 4
2020
DEFINE_COMPILERRT_FUNCTION(___chkstk_ms)
21+
DEFINE_COMPILERRT_FUNCTION(__chkstk)
2122
push %rcx
2223
push %rax
2324
cmp $0x1000,%rax
@@ -35,6 +36,7 @@ DEFINE_COMPILERRT_FUNCTION(___chkstk_ms)
3536
pop %rax
3637
pop %rcx
3738
ret
39+
END_COMPILERRT_FUNCTION(__chkstk)
3840
END_COMPILERRT_FUNCTION(___chkstk_ms)
3941

4042
#endif // __x86_64__

compiler-rt/lib/builtins/x86_64/chkstk2.S

-43
This file was deleted.

0 commit comments

Comments
 (0)