Skip to content

Commit 2240120

Browse files
committed
C backend: inline asm - don't add rsp/esp to the clobber list
- it's deprecated in newer gcc versions and silently ignored in older versions - gcc requires a valid stack to preserve registers and if the asm code clobbers esp/rsp then there is no way to get it back after esp/rsp changes to something else. - User is always responsoble for handling the stack registers.
1 parent 44adf4f commit 2240120

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Version 1.08.0
134134
- C backend: switch to .text section after writing the exports to the C file in the explicit asm block. gcc can move sections around with optimizations and there is a change between 7.x and 8.x that causes issue with where the directive section is located
135135
- sf.net #917: optimize 'm += s' string concatenations to fix the long compile times in the gcc backend (which makes heavy use of string building).
136136
- github #217: C backend, fix gcc array out of bounds warning when compiled with -O2 or higher optimizations and accessing non-zero lower bound fixed length string arrays
137+
- C backend: inline asm - don't add rsp/esp to the clobber list, it's deprecated in newer gcc versions and silently ignored in older versions
137138

138139

139140
Version 1.07.0

src/compiler/ir-hlc.bas

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,15 +3572,20 @@ private sub _emitAsmLine( byval asmtokenhead as ASTASMTOK ptr )
35723572
ln += " : " + inputconstraints
35733573

35743574
'' We don't know what registers etc. will be trashed,
3575-
'' so assume everything...
3575+
'' so assume everything... except for rsp/esp - gcc requires a valid
3576+
'' stack to preserve registers and if the asm code clobbers esp/rsp
3577+
'' then there is no way to get it back after esp/rsp changes to
3578+
'' something else. User is always responsible for handling the stack
3579+
'' registers.
3580+
''
35763581
ln += " : ""cc"", ""memory"""
35773582

35783583
select case( fbGetCpuFamily( ) )
35793584
case FB_CPUFAMILY_X86, FB_CPUFAMILY_X86_64
35803585
if( fbGetCpuFamily( ) = FB_CPUFAMILY_X86 ) then
3581-
ln += ", ""eax"", ""ebx"", ""ecx"", ""edx"", ""esp"", ""edi"", ""esi"""
3586+
ln += ", ""eax"", ""ebx"", ""ecx"", ""edx"", ""edi"", ""esi"""
35823587
else
3583-
ln += ", ""rax"", ""rbx"", ""rcx"", ""rdx"", ""rsp"", ""rdi"", ""rsi"""
3588+
ln += ", ""rax"", ""rbx"", ""rcx"", ""rdx"", ""rdi"", ""rsi"""
35843589
ln += ", ""r8"", ""r9"", ""r10"", ""r11"", ""r12"", ""r13"", ""r14"", ""r15"""
35853590
end if
35863591

0 commit comments

Comments
 (0)