Skip to content

Commit

Permalink
Added a test that would have triggered set_brk() bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 14, 2009
1 parent 4033ed4 commit a1b37dc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
9 changes: 9 additions & 0 deletions test/hello-dlopen.c
Expand Up @@ -7,6 +7,15 @@ typedef int (*hellofn)(void);
int main(void)
{
int retval = 1;

/* have a buffer bigger than a page, so we can maybe find out
if we put the data segment in the wrong place. */
int i;
static char buffer[128 * 1024];
for (i = 0; i < sizeof (buffer); i++)
buffer[i] = (char) i;


void *lib = dlopen("./hello.so", RTLD_NOW | RTLD_GLOBAL);
if (lib == NULL)
perror("dlopen");
Expand Down
8 changes: 8 additions & 0 deletions test/hello-lib.c
Expand Up @@ -15,6 +15,14 @@
int hello(void)
{
printf("hello from a shared library! This binary's arch is: %s!\n", cpu);

/* have a buffer bigger than a page, so we can maybe find out
if we put the data segment in the wrong place. */
int i;
static char buffer[128 * 1024];
for (i = 0; i < sizeof (buffer); i++)
buffer[i] = (char) i;

return 0;
}

Expand Down
12 changes: 11 additions & 1 deletion test/hello.c
@@ -1,2 +1,12 @@
int hello(void);
int main(void) { return hello(); }
int main(void)
{
/* have a buffer bigger than a page, so we can maybe find out
if we put the data segment in the wrong place. */
int i;
static char buffer[128 * 1024];
for (i = 0; i < sizeof (buffer); i++)
buffer[i] = (char) i;

return hello();
}
25 changes: 13 additions & 12 deletions test/test.sh
Expand Up @@ -19,16 +19,16 @@ make -j2

# Build some test programs (hello world, hello world with shared library,
# hello world that uses dlopen() on shared library).
gcc -O0 -ggdb3 -o hello.so ../hello-lib.c -shared -fPIC -m32
gcc -O0 -ggdb3 -c -o hello-x86.o ../hello.c hello.so -m32 -Wl,-rpath,.
gcc -O0 -ggdb3 -o hello-x86 hello-x86.o hello.so -m32 -Wl,-rpath,.
gcc -O0 -ggdb3 -o hello-dlopen-x86 ../hello-dlopen.c -ldl -m32
gcc --std=c99 -O0 -ggdb3 -o hello.so ../hello-lib.c -shared -fPIC -m32
gcc --std=c99 -O0 -ggdb3 -c -o hello-x86.o ../hello.c hello.so -m32 -Wl,-rpath,.
gcc --std=c99 -O0 -ggdb3 -o hello-x86 hello-x86.o hello.so -m32 -Wl,-rpath,.
gcc --std=c99 -O0 -ggdb3 -o hello-dlopen-x86 ../hello-dlopen.c -ldl -m32
mv hello.so hello-x86.so

gcc -O0 -ggdb3 -o hello.so ../hello-lib.c -shared -fPIC -m64
gcc -O0 -ggdb3 -c -o hello-amd64.o ../hello.c hello.so -m64 -Wl,-rpath,.
gcc -O0 -ggdb3 -o hello-amd64 hello-amd64.o hello.so -m64 -Wl,-rpath,.
gcc -O0 -ggdb3 -o hello-dlopen-amd64 ../hello-dlopen.c -ldl -m64
gcc --std=c99 -O0 -ggdb3 -o hello.so ../hello-lib.c -shared -fPIC -m64
gcc --std=c99 -O0 -ggdb3 -c -o hello-amd64.o ../hello.c hello.so -m64 -Wl,-rpath,.
gcc --std=c99 -O0 -ggdb3 -o hello-amd64 hello-amd64.o hello.so -m64 -Wl,-rpath,.
gcc --std=c99 -O0 -ggdb3 -o hello-dlopen-amd64 ../hello-dlopen.c -ldl -m64
mv hello.so hello-amd64.so

# Glue them into FatELF binaries.
Expand Down Expand Up @@ -78,12 +78,12 @@ objdump -x ./hello-dlopen
gdb -x ../test.gdb ./hello

# Link directly against a FatELF object file (binutils test).
gcc -m64 -O0 -ggdb3 -o hello-fatlink-obj-amd64 hello.o hello.so -Wl,-rpath,.
gcc -m32 -O0 -ggdb3 -o hello-fatlink-obj-x86 hello.o hello.so -Wl,-rpath,.
gcc --std=c99 -m64 -O0 -ggdb3 -o hello-fatlink-obj-amd64 hello.o hello.so -Wl,-rpath,.
gcc --std=c99 -m32 -O0 -ggdb3 -o hello-fatlink-obj-x86 hello.o hello.so -Wl,-rpath,.

# Link directly against a FatELF shared library (binutils test).
gcc -m64 -O0 -ggdb3 -o hello-fatlink-amd64 ../hello.c hello.so -Wl,-rpath,.
gcc -m32 -O0 -ggdb3 -o hello-fatlink-x86 ../hello.c hello.so -Wl,-rpath,.
gcc --std=c99 -m64 -O0 -ggdb3 -o hello-fatlink-amd64 ../hello.c hello.so -Wl,-rpath,.
gcc --std=c99 -m32 -O0 -ggdb3 -o hello-fatlink-x86 ../hello.c hello.so -Wl,-rpath,.

# and, you know...run the programs themselves (glibc, kernel tests).
./hello
Expand All @@ -95,3 +95,4 @@ gcc -m32 -O0 -ggdb3 -o hello-fatlink-x86 ../hello.c hello.so -Wl,-rpath,.

# end of test.sh ...


0 comments on commit a1b37dc

Please sign in to comment.