Stack overflow checking with stack probes.
This adds a libcall name, a calling convention, and settings for emitting stack probes, and implements them for x86 system_v ABIs.
This commit is contained in:
@@ -591,12 +591,25 @@ stack_check = Instruction(
|
||||
|
||||
The global variable must be accessible and naturally aligned for a
|
||||
pointer-sized value.
|
||||
|
||||
`stack_check` is an alternative way to detect stack overflow, when using
|
||||
a calling convention that doesn't perform stack probes.
|
||||
""",
|
||||
ins=GV, can_trap=True)
|
||||
|
||||
delta = Operand('delta', Int)
|
||||
adjust_sp_down = Instruction(
|
||||
'adjust_sp_down', r"""
|
||||
Subtracts ``delta`` offset value from the stack pointer register.
|
||||
|
||||
This instruction is used to adjust the stack pointer by a dynamic amount.
|
||||
""",
|
||||
ins=(delta,),
|
||||
other_side_effects=True)
|
||||
|
||||
StackOffset = Operand('Offset', imm64, 'Offset from current stack pointer')
|
||||
adjust_sp_imm = Instruction(
|
||||
'adjust_sp_imm', r"""
|
||||
adjust_sp_up_imm = Instruction(
|
||||
'adjust_sp_up_imm', r"""
|
||||
Adds ``Offset`` immediate offset value to the stack pointer register.
|
||||
|
||||
This instruction is used to adjust the stack pointer, primarily in function
|
||||
@@ -606,6 +619,19 @@ adjust_sp_imm = Instruction(
|
||||
ins=(StackOffset,),
|
||||
other_side_effects=True)
|
||||
|
||||
StackOffset = Operand('Offset', imm64, 'Offset from current stack pointer')
|
||||
adjust_sp_down_imm = Instruction(
|
||||
'adjust_sp_down_imm', r"""
|
||||
Subtracts ``Offset`` immediate offset value from the stack pointer
|
||||
register.
|
||||
|
||||
This instruction is used to adjust the stack pointer, primarily in function
|
||||
prologues and epilogues. ``Offset`` is constrained to the size of a signed
|
||||
32-bit integer.
|
||||
""",
|
||||
ins=(StackOffset,),
|
||||
other_side_effects=True)
|
||||
|
||||
f = Operand('f', iflags)
|
||||
|
||||
ifcmp_sp = Instruction(
|
||||
|
||||
@@ -38,17 +38,27 @@ call_conv = EnumSetting(
|
||||
- system_v: System V-style convention used on many platforms
|
||||
- fastcall: Windows "fastcall" convention, also used for x64 and ARM
|
||||
- baldrdash: SpiderMonkey WebAssembly convention
|
||||
- probestack: specialized convention for the probestack function
|
||||
|
||||
The default calling convention may be overridden by individual
|
||||
functions.
|
||||
""",
|
||||
'fast', 'cold', 'system_v', 'fastcall', 'baldrdash')
|
||||
'fast', 'cold', 'system_v', 'fastcall', 'baldrdash', 'probestack')
|
||||
|
||||
# Note that Cretonne doesn't currently need an is_pie flag, because PIE is just
|
||||
# PIC where symbols can't be pre-empted, which can be expressed with the
|
||||
# `colocated` flag on external functions and global variables.
|
||||
is_pic = BoolSetting("Enable Position-Independent Code generation")
|
||||
|
||||
colocated_libcalls = BoolSetting(
|
||||
"""
|
||||
Use colocated libcalls.
|
||||
|
||||
Generate code that assumes that libcalls can be declared "colocated",
|
||||
meaning they will be defined along with the current function, such that
|
||||
they can use more efficient addressing.
|
||||
""")
|
||||
|
||||
return_at_end = BoolSetting(
|
||||
"""
|
||||
Generate functions with at most a single return instruction at the
|
||||
@@ -115,4 +125,31 @@ allones_funcaddrs = BoolSetting(
|
||||
Emit not-yet-relocated function addresses as all-ones bit patterns.
|
||||
""")
|
||||
|
||||
#
|
||||
# Stack probing options.
|
||||
#
|
||||
probestack_enabled = BoolSetting(
|
||||
"""
|
||||
Enable the use of stack probes, for calling conventions which support
|
||||
this functionality.
|
||||
""",
|
||||
default=True)
|
||||
|
||||
probestack_func_adjusts_sp = BoolSetting(
|
||||
"""
|
||||
Set this to true of the stack probe function modifies the stack pointer
|
||||
itself.
|
||||
""")
|
||||
|
||||
probestack_size_log2 = NumSetting(
|
||||
"""
|
||||
The log2 of the size of the stack guard region.
|
||||
|
||||
Stack frames larger than this size will have stack overflow checked
|
||||
by calling the probestack function.
|
||||
|
||||
The default is 12, which translates to a size of 4096.
|
||||
""",
|
||||
default=12)
|
||||
|
||||
group.close(globals())
|
||||
|
||||
Reference in New Issue
Block a user