summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2016-10-05 11:04:25 +0300
committerIvan Maidanski <ivmai@mail.ru>2016-10-05 11:05:21 +0300
commit43c543923af72ad495f8c44eaab25ceebe379c4f (patch)
treef9c0ea151e77ff42128b41f51ac68a31c63bdc1b /tools
parent03bb5fb61138482085be2330c4da9491a081ec52 (diff)
downloadbdwgc-43c543923af72ad495f8c44eaab25ceebe379c4f.tar.gz
Fix tools/setjmp_t to prevent nested_sp inlining
Inlined nested_sp might cause incorrect result of nested_sp()<sp. * tools/setjmp_t.c (nested_sp): Change return from int* to word. * tools/setjmp_t.c (nested_sp_fn): New global volatile variable initialized to nested_sp. * tools/setjmp_t.c (main): Use nested_sp_fn instead of nested_sp; remove redundant cast.
Diffstat (limited to 'tools')
-rw-r--r--tools/setjmp_t.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/setjmp_t.c b/tools/setjmp_t.c
index 9ba9d285..1bd715dd 100644
--- a/tools/setjmp_t.c
+++ b/tools/setjmp_t.c
@@ -60,13 +60,16 @@ struct {
char * a_b;
} a;
-int * nested_sp(void)
+word nested_sp(void)
{
volatile word sp;
sp = (word)(&sp);
- return (int *)sp;
+ return sp;
}
+/* To prevent nested_sp inlining. */
+word (*volatile nested_sp_fn)(void) = nested_sp;
+
int g(int x);
int main(void)
@@ -79,7 +82,7 @@ int main(void)
sp = (word)(&sp);
printf("This appears to be a %s running %s\n", MACH_TYPE, OS_TYPE);
- if ((word)nested_sp() < sp) {
+ if (nested_sp_fn() < sp) {
printf("Stack appears to grow down, which is the default.\n");
printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
((unsigned long)sp + ps) & ~(ps-1));