From: Jeff Epler <jepler@unpythonic.net>
To: Chuck Ebbert <cebbert.lkml@gmail.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86: Clean up stack access code in irq_32.c
Date: Sun, 12 Oct 2014 12:00:03 -0500 [thread overview]
Message-ID: <20141012170003.GA96036@unpythonic.net> (raw)
In-Reply-To: <20141012115332.5ec3db90@as>
It looks like the proposed variant still miscompiles in clang 3.4 and 3.5, the
two versions I had handy to test.
I extracted your code to a simple standalone C translation unit and
inspected various compilers' results via objdump.
// cut here for cso.c
struct thread_info { long l[32]; }; // who knows
#define STACK_WARN (1024)
#define PAGE_SIZE (4096)
#define THREAD_SIZE_ORDER 2
#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
#define THREAD_SIZE_MASK (THREAD_SIZE - 1)
#define CURRENT_MASK (~THREAD_SIZE_MASK)
/* how to get the current stack pointer from C */
#define current_stack_pointer ({ \
register unsigned long sp asm("esp"); \
sp; \
})
int check_stack_overflow0(void)
{
long sp;
__asm__ __volatile__("andl %%esp,%0" :
"=r" (sp) : "0" (THREAD_SIZE - 1));
return sp < (sizeof(struct thread_info) + STACK_WARN);
}
int check_stack_overflow1(void)
{
return (current_stack_pointer & THREAD_SIZE_MASK)
< sizeof(struct thread_info) + STACK_WARN;
}
// end cso.c
Typical compiler invocation:
clang-3.5 -m32 -Os -c cso.c
Both clang-3.4 and clang-3.5 as packaged for debian jessie seem to get
check_stack_overflow1 wrong, yielding a function which always returns true:
00000000 <check_stack_overflow1>:
0: b8 01 00 00 00 mov $0x1,%eax
5: c3 ret
Jeff
next prev parent reply other threads:[~2014-10-12 17:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-12 16:43 Chuck Ebbert
2014-10-12 16:47 ` H. Peter Anvin
2014-10-12 16:53 ` Chuck Ebbert
2014-10-12 17:00 ` Jeff Epler [this message]
2014-10-12 17:40 ` Chuck Ebbert
2014-10-12 17:13 ` H. Peter Anvin
2014-10-12 19:34 ` Chuck Ebbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141012170003.GA96036@unpythonic.net \
--to=jepler@unpythonic.net \
--cc=cebbert.lkml@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome