Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interrupt handler calls functions with misaligned stack #26851

Closed
hjl-tools opened this issue Feb 4, 2016 · 3 comments
Closed

interrupt handler calls functions with misaligned stack #26851

hjl-tools opened this issue Feb 4, 2016 · 3 comments
Labels
backend:X86 bugzilla Issues migrated from bugzilla

Comments

@hjl-tools
Copy link
Contributor

hjl-tools commented Feb 4, 2016

Bugzilla Link 26477
Version trunk
OS Linux
CC @hfinkel

Extended Description

Incoming stack of x86 interrupt handler is aligned at 4 bytes (8 bytes for
64-bit). When it calls extern functions, it needs to realign the stack
to 16-byte aligned if it is required:

[hjl@gnu-6 interrupt-1]$ cat xx.i 
extern void bar (void);

extern int i;

void
 __attribute__ ((interrupt))
foo (void *frame)
{
  bar ();
  i = 0;
}
[hjl@gnu-6 interrupt-1]$ /export/build/gnu/gcc-5/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc-5/build-x86_64-linux/gcc/ -O2 xx.i -m32 -mno-sse -S
[hjl@gnu-6 interrupt-1]$  cat xx.s
	.file	"xx.i"
	.section	.text.unlikely,"ax",@progbits
.LCOLDB0:
	.text
.LHOTB0:
	.p2align 4,,15
	.globl	foo
	.type	foo, @function
foo:
.LFB0:
	.cfi_startproc
	pushl	%ebp
	.cfi_def_cfa_offset 8
	.cfi_offset 5, -8
	movl	%esp, %ebp
	.cfi_def_cfa_register 5
	pushl	%ecx
	pushl	%edx
	pushl	%eax
	andl	$-16, %esp  <<<<<<<<<<<< Align stack
	cld
	.cfi_offset 1, -12
	.cfi_offset 2, -16
	.cfi_offset 0, -20
	call	bar
	movl	$0, i
	leal	-12(%ebp), %esp
	popl	%eax
	.cfi_restore 0
	popl	%edx
	.cfi_restore 2
	popl	%ecx
	.cfi_restore 1
	popl	%ebp
	.cfi_restore 5
	.cfi_def_cfa 4, 4
	iret
	.cfi_endproc
.LFE0:
	.size	foo, .-foo
	.section	.text.unlikely
.LCOLDE0:
	.text
.LHOTE0:
	.ident	"GCC: (GNU) 5.3.1 20160201"
	.section	.note.GNU-stack,"",@progbits
[hjl@gnu-6 interrupt-1]$ 

But clang doesn't align stack:

[hjl@gnu-6 interrupt-1]$ /net/gnu-mic-2//export/build/gnu/llvm-clang/build-x86_64-linux/bin/clang -O2 xx.i -m32 -mno-sse -S
[hjl@gnu-6 interrupt-1]$  cat xx.s
	.text
	.file	"xx.i"
	.globl	foo
	.p2align	4, 0x90
	.type	foo,@function
foo:                                    # @foo
# BB#0:
	pushl	%esp
	pushl	%edx
	pushl	%ecx
	pushl	%eax
	subl	$12, %esp
	calll	bar
	movl	$0, i
	addl	$12, %esp
	popl	%eax
	popl	%ecx
	popl	%edx
	popl	%esp
	iretl
.Lfunc_end0:
	.size	foo, .Lfunc_end0-foo


	.ident	"clang version 3.9.0 (http://llvm.org/git/clang.git bf1d31e84aa2722174da56b8aff311ae04f4d9e1) (http://llvm.org/git/llvm.git 6cced9c3cd18f529420a03b100970d97512bb9a4)"
	.section	".note.GNU-stack","",@progbits
[hjl@gnu-6 interrupt-1]$
@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@antangelo
Copy link
Contributor

I am interested in working on this for the 32-bit case. I believe the 64-bit case is already solved.

@RKSimon
Copy link
Collaborator

RKSimon commented May 25, 2023

Candidate Patch: https://reviews.llvm.org/D151400

@llvmbot
Copy link
Member

llvmbot commented May 25, 2023

@llvm/issue-subscribers-backend-x86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

4 participants