|
From: Nicholas N. <nj...@ca...> - 2004-10-18 11:52:30
|
CVS commit by nethercote:
Arch-abstraction: a nice change that removes the need for ume_entry.S. Instead
of using an assembly hack to find the stack pointer at startup, we find it from
argv. It's much simpler, avoids linking games, is platform independent, and
works on PPC.
M +2 -4 coregrind/Makefile.am 1.90
M +9 -4 coregrind/stage1.c 1.24
M +0 -2 coregrind/ume.h 1.13
M +14 -6 coregrind/vg_main.c 1.217
M +1 -2 coregrind/x86/Makefile.am 1.14
M +0 -2 memcheck/tests/Makefile.am 1.46
M +20 -16 memcheck/tests/vgtest_ume.c 1.4
R coregrind/x86/ume_entry.S 1.3
--- valgrind/coregrind/Makefile.am #1.89:1.90
@@ -31,10 +31,9 @@
valgrind_SOURCES = \
ume.c \
- ${VG_ARCH}/ume_entry.S \
\
stage1.c \
${VG_ARCH}/jmp_with_stack.c
valgrind_DEPENDENCIES =
-valgrind_LDFLAGS=-static -g -Wl,-e,_ume_entry
+valgrind_LDFLAGS=-static -g
valgrind_LDADD=
@@ -47,5 +46,4 @@
stage2_SOURCES = \
ume.c \
- ${VG_ARCH}/ume_entry.S \
\
vg_scheduler.c \
@@ -82,5 +80,5 @@
vg_cpuid.S
stage2_DEPENDENCIES = $(srcdir)/valgrind.vs ${VG_ARCH}/stage2.lds
-stage2_LDFLAGS=-Wl,--export-dynamic -Wl,-e,_ume_entry -g \
+stage2_LDFLAGS=-Wl,--export-dynamic -g \
-Wl,-defsym,kickstart_base=$(KICKSTART_BASE) \
-Wl,-T,${VG_ARCH}/stage2.lds \
--- valgrind/coregrind/stage1.c #1.23:1.24
@@ -47,4 +47,7 @@
static int stack[SIGSTKSZ*4];
+// Initial stack pointer, which points to argc.
+static void* init_sp;
+
/* Where we expect to find all our aux files (namely, stage2) */
static const char *valgrind_lib = VG_LIBDIR;
@@ -258,5 +261,5 @@ static void main2(void)
info.exe_base = PGROUNDUP(&_end);
- info.exe_end = PGROUNDDN(ume_exec_esp);
+ info.exe_end = PGROUNDDN(init_sp);
/* XXX FIXME: how can stage1 know where stage2 wants things placed?
@@ -284,5 +287,5 @@ static void main2(void)
as_pad(0, (void *)info.map_base, padfile);
- esp = fix_auxv(ume_exec_esp, &info, padfile);
+ esp = fix_auxv(init_sp, &info, padfile);
if (0) {
@@ -295,5 +298,5 @@ static void main2(void)
}
-int main(void)
+int main(int argc, char** argv)
{
struct rlimit rlim;
@@ -303,5 +306,7 @@ int main(void)
valgrind_lib = cp;
- assert(ume_exec_esp != NULL);
+ // Initial stack pointer is to argc, which is immediately before argv[0]
+ // on the stack.
+ init_sp = argv - 1;
/* Set the address space limit as high as it will go, since we make
--- valgrind/coregrind/ume.h #1.12:1.13
@@ -56,6 +56,4 @@ void foreach_map(int (*fn)(char *start,
typedef ESZ(Addr) addr_t;
-extern void *ume_exec_esp; /* esp on entry at exec time */
-
// Jump to a new 'ip' with the stack 'sp'.
void jmp_with_stack(addr_t ip, addr_t sp) __attribute__((noreturn));
--- valgrind/coregrind/vg_main.c #1.216:1.217
@@ -363,7 +363,7 @@ static void newpid(ThreadId unused)
/* Look for our AUXV table */
-int scan_auxv(void)
+int scan_auxv(void* init_sp)
{
- const struct ume_auxv *auxv = find_auxv((int *)ume_exec_esp);
+ const struct ume_auxv *auxv = find_auxv((int *)init_sp);
int padfile = -1, found = 0;
@@ -909,5 +909,6 @@ static char *copy_str(char **tab, const
: :
*/
-static Addr setup_client_stack(char **orig_argv, char **orig_envp,
+static Addr setup_client_stack(void* init_sp,
+ char **orig_argv, char **orig_envp,
const struct exeinfo *info,
UInt** client_auxv)
@@ -929,5 +930,5 @@ static Addr setup_client_stack(char **or
/* use our own auxv as a prototype */
- orig_auxv = find_auxv(ume_exec_esp);
+ orig_auxv = find_auxv(init_sp);
/* ==================== compute sizes ==================== */
@@ -2577,5 +2578,8 @@ int main(int argc, char **argv)
// p: n/a
//--------------------------------------------------------------
- padfile = scan_auxv();
+ {
+ void* init_sp = argv - 1;
+ padfile = scan_auxv(init_sp);
+ }
if (0) {
@@ -2651,5 +2655,9 @@ int main(int argc, char **argv)
// p: fix_environment() [for 'env']
//--------------------------------------------------------------
- esp_at_startup = setup_client_stack(cl_argv, env, &info, &client_auxv);
+ {
+ void* init_sp = argv - 1;
+ esp_at_startup = setup_client_stack(init_sp, cl_argv, env, &info,
+ &client_auxv);
+ }
if (0)
--- valgrind/coregrind/x86/Makefile.am #1.13:1.14
@@ -12,6 +12,5 @@
EXTRA_DIST = \
- jmp_with_stack.c \
- ume_entry.S
+ jmp_with_stack.c
BUILT_SOURCES = stage2.lds
--- valgrind/memcheck/tests/Makefile.am #1.45:1.46
@@ -166,7 +166,5 @@
-Wl,-T,../../coregrind/${VG_ARCH}/stage2.lds
vgtest_ume_SOURCES = vgtest_ume.c
-vgtest_ume_LDFLAGS = -Wl,-e,_ume_entry
vgtest_ume_LDADD = ../../coregrind/ume.o \
- ../../coregrind/ume_entry.o \
../../coregrind/jmp_with_stack.o
--- valgrind/memcheck/tests/vgtest_ume.c #1.3:1.4
@@ -1,5 +1,5 @@
#define ELFSZ 32
-// This file is a unit self-test for ume.c, ume_entry.c, jmp_with_stack.c
+// This file is a unit self-test for ume.c, jmp_with_stack.c
#include <stdlib.h>
@@ -11,9 +11,11 @@
#define STKSZ (64*1024)
+static void* init_sp;
+
//-------------------------------------------------------------------
// Test foreach_map()
//-------------------------------------------------------------------
-static int x;
+static int x[8];
static int f(char *start, char *end, const char *perm, off_t off,
@@ -21,14 +23,14 @@ static int f(char *start, char *end, con
// Just do some nonsense action with each of the values so that Memcheck
// checks that they are valid.
- x = ( start == 0 ? 0 : 1 );
- x = ( end == 0 ? 0 : 1 );
- x = ( perm == 0 ? 0 : 1 );
- x = ( off == 0 ? 0 : 1 );
- x = ( maj == 0 ? 0 : 1 );
- x = ( min == 0 ? 0 : 1 );
- x = ( ino == 0 ? 0 : 1 );
- x = ( dummy == 0 ? 0 : 1 );
+ x[0] = ( start == 0 ? 0 : 1 );
+ x[1] = ( end == 0 ? 0 : 1 );
+ x[2] = ( perm == 0 ? 0 : 1 );
+ x[3] = ( off == 0 ? 0 : 1 );
+ x[4] = ( maj == 0 ? 0 : 1 );
+ x[5] = ( min == 0 ? 0 : 1 );
+ x[6] = ( ino == 0 ? 0 : 1 );
+ x[7] = ( dummy == 0 ? 0 : 1 );
- return /*True*/1;
+ return /*True*/1 + x[0] + x[1] + x[2] + x[3] + x[4] + x[5] + x[6] + x[7];
}
@@ -47,12 +49,12 @@ static void test__find_auxv(void)
struct ume_auxv *auxv;
- assert(ume_exec_esp != NULL);
+ assert(init_sp != NULL);
fprintf(stderr, "Calling find_auxv()\n");
- auxv = find_auxv((int*)ume_exec_esp);
+ auxv = find_auxv((int*)init_sp);
// Check the auxv value looks sane
- assert((void*)auxv > (void*)ume_exec_esp);
- assert((unsigned int)auxv - (unsigned int)ume_exec_esp < 0x10000);
+ assert((void*)auxv > (void*)init_sp);
+ assert((unsigned int)auxv - (unsigned int)init_sp < 0x10000);
// Scan the auxv, check it looks sane
@@ -137,6 +139,8 @@ static void test__do_exec(void)
}
-int main(void)
+int main(int argc, char** argv)
{
+ init_sp = argv - 1;
+
test__foreach_map();
test__find_auxv();
|