Skip to content

Commit

Permalink
[compiler-rt] [builtins] Remove unused/misnamed x86 chkstk functions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mstorsjo committed Sep 1, 2023
1 parent 95062d7 commit 885d7b7
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 82 deletions.
2 changes: 0 additions & 2 deletions compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ if (NOT MSVC)
set(x86_64_SOURCES
${x86_64_SOURCES}
x86_64/chkstk.S
x86_64/chkstk2.S
)
endif()

Expand Down Expand Up @@ -363,7 +362,6 @@ if (NOT MSVC)
if (WIN32)
set(i386_SOURCES
${i386_SOURCES}
i386/chkstk.S
i386/chkstk2.S
)
endif()
Expand Down
35 changes: 0 additions & 35 deletions compiler-rt/lib/builtins/i386/chkstk.S

This file was deleted.

4 changes: 2 additions & 2 deletions compiler-rt/lib/builtins/i386/chkstk2.S
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.text
.balign 4
DEFINE_COMPILERRT_FUNCTION(_alloca) // _chkstk and _alloca are the same function
DEFINE_COMPILERRT_FUNCTION(__chkstk)
DEFINE_COMPILERRT_FUNCTION(_chkstk)
push %ecx
cmp $0x1000,%eax
lea 8(%esp),%ecx // esp before calling this routine -> ecx
Expand All @@ -35,7 +35,7 @@ DEFINE_COMPILERRT_FUNCTION(__chkstk)
push (%eax) // push return address onto the stack
sub %esp,%eax // restore the original value in eax
ret
END_COMPILERRT_FUNCTION(__chkstk)
END_COMPILERRT_FUNCTION(_chkstk)
END_COMPILERRT_FUNCTION(_alloca)

#endif // __i386__
2 changes: 2 additions & 0 deletions compiler-rt/lib/builtins/x86_64/chkstk.S
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
.text
.balign 4
DEFINE_COMPILERRT_FUNCTION(___chkstk_ms)
DEFINE_COMPILERRT_FUNCTION(__chkstk)
push %rcx
push %rax
cmp $0x1000,%rax
Expand All @@ -35,6 +36,7 @@ DEFINE_COMPILERRT_FUNCTION(___chkstk_ms)
pop %rax
pop %rcx
ret
END_COMPILERRT_FUNCTION(__chkstk)
END_COMPILERRT_FUNCTION(___chkstk_ms)

#endif // __x86_64__
43 changes: 0 additions & 43 deletions compiler-rt/lib/builtins/x86_64/chkstk2.S

This file was deleted.

0 comments on commit 885d7b7

Please sign in to comment.