浏览代码

A better test for a dlopen problem with weak symbols, based
on a much improve test by mjn3.

Eric Andersen 22 年之前
父节点
当前提交
9efccabb26
共有 5 个文件被更改,包括 57 次插入78 次删除
  1. 2 3
      test/ldso/.cvsignore
  2. 15 33
      test/ldso/Makefile
  3. 24 18
      test/ldso/dltest.c
  4. 0 24
      test/ldso/howdy.c
  5. 16 0
      test/ldso/libtest.c

+ 2 - 3
test/ldso/.cvsignore

@@ -1,5 +1,4 @@
 dltest
-libhowdy.so
 dltest2
-dlttest
-dlttest2
+libtest.so
+libtest2.so

+ 15 - 33
test/ldso/Makefile

@@ -1,6 +1,6 @@
 # Makefile for uClibc
 #
-# Copyright (C) 2000,2001 Erik Andersen <andersen@uclibc.org>
+# Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
 #
 # This program is free software; you can redistribute it and/or modify it under
 # the terms of the GNU Library General Public License as published by the Free
@@ -19,44 +19,26 @@
 TESTDIR=../
 include $(TESTDIR)/Rules.mak
 
-all: dltest2 dltest libhowdy.so run
-all: dlttest dlttest2 dltest2 dltest libhowdy.so run
+all: run
 
-dlttest.o: dlttest.c
-	$(CC) $(CFLAGS) -c dlttest.c -o dlttest.o
 
-dlttest2.o: dlttest.c
-	$(CC) $(CFLAGS) -DFORCE -c dlttest.c -o dlttest2.o
+dltest: dltest.c
+	$(CC) $(CFLAGS) -DLIBNAME="\"./libtest.so\"" dltest.c -ldl -lpthread -o dltest
 
-dltest2: dltest2.c
-	$(CC) $(CFLAGS) dltest2.c -o dltest2 -ldl
-	./dltest2
-
-dltest.o: dltest.c
-	$(CC) $(CFLAGS) -c dltest.c -o dltest.o
-
-howdy.o: howdy.c
-	$(CC) $(CFLAGS) -fPIC -c howdy.c -o howdy.o
-
-libhowdy.so: howdy.o
-	$(CC) $(CFLAGS) -shared -o libhowdy.so -Wl,-soname,libhowdy.so howdy.o
+libtest.so: libtest.c
+	$(CC) $(CFLAGS) -fPIC -shared -Wl,-soname,libtest.so libtest.c -o libtest.so
 
-dltest: dltest.o
-	$(CC) $(CFLAGS) -o dltest dltest.o -ldl
+# Second time, directly link libtest2.so with libpthread
+dltest2: dltest.c
+	$(CC) $(CFLAGS) -DLIBNAME="\"./libtest2.so\"" dltest.c -ldl -lpthread -o dltest2
 
-dlttest: dlttest.o
-	$(CC) $(CFLAGS) -o dlttest dlttest.o -ldl -lpthread
+libtest2.so: libtest.c
+	$(CC) $(CFLAGS) -fPIC -shared -Wl,-soname,libtest2.so libtest.c -o libtest2.so -lpthread
 
-dlttest2: dlttest2.o
-	$(CC) $(CFLAGS) -o dlttest2 dlttest2.o -ldl -lpthread
-
-run: dltest dlttest dlttest2 libhowdy.so
-	@echo Running dltest
+run: dltest libtest.so dltest2 libtest2.so
+	./dltest2
 	./dltest
-	@echo Running dlttest
-	./dlttest
-	@echo Running dlttest2
-	./dlttest2
 
 clean:
-	rm -f *.o *.so dltest2 dltest core libhowdy.so dlttest dlttest2
+	rm -f *.o dltest dltest2 libtest.so libtest2.so
+

+ 24 - 18
test/ldso/dltest.c

@@ -2,38 +2,44 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <dlfcn.h>
-
-extern void _dlinfo();
-
-int main(int argc, char **argv) {
-	void *handle;
-	int (*myhowdy)(const char *s);
-	char *error;
+#include <stdint.h>
 
 #ifdef __UCLIBC__
-	_dlinfo();   /* not supported by ld.so.2 */
+extern void _dlinfo(void);
 #endif
 
-	handle = dlopen ("./libhowdy.so", RTLD_LAZY);
+int main(int argc, char **argv) 
+{
+	int ret = EXIT_SUCCESS;
+	void *handle;
+	void (*mydltest)(void *value1, void *value2);
+	char *error;
+	uint32_t *value1, *value2;
 
+	handle = dlopen (LIBNAME, RTLD_LAZY);
 	if (!handle) {
-		fputs (dlerror(), stderr);
+		fprintf(stderr, "Could not open ./libtest.so: %s\n", dlerror());
 		exit(1);
 	}
 
-	myhowdy = dlsym(handle, "howdy");
+	mydltest = dlsym(handle, "dltest");
 	if ((error = dlerror()) != NULL)  {
-		fputs(error, stderr);
+		fprintf(stderr, "Could not locate symbol 'dltest': %s\n", error);
 		exit(1);
 	}
 
-	myhowdy("hello world!\n");
-
-#ifdef __UCLIBC__
-	_dlinfo();   /* not supported by ld.so.2 */
-#endif
+	mydltest(&value1, &value2);
+	printf("dltest: __pthread_return_0=%p\n", value1);
+	printf("dltest: pthread_self=%p\n", value2);
+	if (value1 == value2) {
+	    ret = EXIT_FAILURE;
+	    printf("dltest: values should NOT be equal  Weak values resolved incorrectly!\n");
+	} else {
+	    printf("dltest: weak symbols resoved correctly.\n");
+	}
 
 	dlclose(handle);
 
-	return EXIT_SUCCESS;
+	return ret;
 }
+

+ 0 - 24
test/ldso/howdy.c

@@ -1,24 +0,0 @@
-#include <pthread.h>
-#include <stdio.h>
-
-extern int __pthread_return_0 (void);
-
-int howdy(const char *s)
-{
-    return printf("howdy:  __pthread_return_0 = %p\n"
-		  "howdy: pthread_cond_signal = %p\n",
-		  __pthread_return_0, pthread_cond_signal);
-}
-
-void __attribute__((constructor)) howdy_ctor(void)
-{
-    printf("I am the libhowdy constructor!\n");
-}
-
-void __attribute__((destructor)) howdy_dtor(void)
-{
-    printf("I am the libhowdy destructor!\n");
-}
-
-
-

+ 16 - 0
test/ldso/libtest.c

@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <pthread.h>
+#include <stdint.h>
+
+extern int __pthread_return_0(void);
+
+void dltest(uint32_t **value1, uint32_t **value2)
+{
+	*value1 = (uint32_t *) __pthread_return_0;
+	*value2 = (uint32_t *) pthread_self;
+#if 0
+	printf("dltest: __pthread_return_0=%p\n", __pthread_return_0);
+	printf("dltest: pthread_self=%p\n", pthread_self);
+#endif
+}
+