Skip to content

Commit

Permalink
C backend: inline asm - don't add rsp/esp to the clobber list
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
jayrm committed Apr 26, 2021
1 parent 44adf4f commit 2240120
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Version 1.08.0
- 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
- 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).
- 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
- 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


Version 1.07.0
Expand Down
11 changes: 8 additions & 3 deletions src/compiler/ir-hlc.bas
Original file line number Diff line number Diff line change
Expand Up @@ -3572,15 +3572,20 @@ private sub _emitAsmLine( byval asmtokenhead as ASTASMTOK ptr )
ln += " : " + inputconstraints

'' We don't know what registers etc. will be trashed,
'' so assume everything...
'' so assume everything... except for rsp/esp - 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 responsible for handling the stack
'' registers.
''
ln += " : ""cc"", ""memory"""

select case( fbGetCpuFamily( ) )
case FB_CPUFAMILY_X86, FB_CPUFAMILY_X86_64
if( fbGetCpuFamily( ) = FB_CPUFAMILY_X86 ) then
ln += ", ""eax"", ""ebx"", ""ecx"", ""edx"", ""esp"", ""edi"", ""esi"""
ln += ", ""eax"", ""ebx"", ""ecx"", ""edx"", ""edi"", ""esi"""
else
ln += ", ""rax"", ""rbx"", ""rcx"", ""rdx"", ""rsp"", ""rdi"", ""rsi"""
ln += ", ""rax"", ""rbx"", ""rcx"", ""rdx"", ""rdi"", ""rsi"""
ln += ", ""r8"", ""r9"", ""r10"", ""r11"", ""r12"", ""r13"", ""r14"", ""r15"""
end if

Expand Down

0 comments on commit 2240120

Please sign in to comment.