Ver código fonte

Semonstrate a problem where weak symbols referenced in shared libs are not
being overridden when those same symbols _are_ overridden by other shared libs
in the main app. Ick.
-Erik

Eric Andersen 22 anos atrás
pai
commit
a74fc341b9
4 arquivos alterados com 74 adições e 5 exclusões
  1. 2 0
      test/ldso/.cvsignore
  2. 19 2
      test/ldso/Makefile
  3. 45 0
      test/ldso/dlttest.c
  4. 8 3
      test/ldso/howdy.c

+ 2 - 0
test/ldso/.cvsignore

@@ -1,3 +1,5 @@
 dltest
 libhowdy.so
 dltest2
+dlttest
+dlttest2

+ 19 - 2
test/ldso/Makefile

@@ -21,6 +21,13 @@ include $(TESTDIR)/Rules.mak
 
 CFLAGS+=--uclibc-ctors
 all: dltest2 dltest libhowdy.so run
+all: dlttest dlttest2 dltest2 dltest libhowdy.so 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
 
 dltest2: dltest2.c
 	$(CC) $(CFLAGS) dltest2.c -o dltest2 -ldl
@@ -37,10 +44,20 @@ libhowdy.so: howdy.o
 
 dltest: dltest.o
 	$(CC) $(CFLAGS) -o dltest dltest.o -ldl
-	
-run: dltest libhowdy.so
+
+dlttest: dlttest.o
+	$(CC) $(CFLAGS) -o dlttest dlttest.o -ldl -lpthread
+
+dlttest2: dlttest2.o
+	$(CC) $(CFLAGS) -o dlttest2 dlttest2.o -ldl -lpthread
+
+run: dltest dlttest dlttest2 libhowdy.so
 	@echo Running dltest
 	./dltest
+	@echo Running dlttest
+	./dlttest
+	@echo Running dlttest2
+	./dlttest2
 
 clean:
 	rm -f *.o *.so dltest2 dltest core libhowdy.so

+ 45 - 0
test/ldso/dlttest.c

@@ -0,0 +1,45 @@
+#include <pthread.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+extern void _dlinfo();
+extern int __pthread_return_0 (void);
+#undef __UCLIBC__
+
+int main(int argc, char **argv) {
+	void *handle;
+	int (*myhowdy)(const char *s);
+	char *error;
+
+#ifdef __UCLIBC__
+	_dlinfo();   /* not supported by ld.so.2 */
+#endif
+
+	handle = dlopen ("./libhowdy.so", RTLD_LAZY);
+
+	if (!handle) {
+		fputs (dlerror(), stderr);
+		exit(1);
+	}
+
+	myhowdy = dlsym(handle, "howdy");
+	if ((error = dlerror()) != NULL)  {
+		fputs(error, stderr);
+		exit(1);
+	}
+
+#ifdef FORCE
+	printf("main:   __pthread_return_0 = %p\n", __pthread_return_0);
+#endif
+	myhowdy("hello world!\n");
+
+#ifdef __UCLIBC__
+	_dlinfo();   /* not supported by ld.so.2 */
+#endif
+
+	dlclose(handle);
+
+	return EXIT_SUCCESS;
+}

+ 8 - 3
test/ldso/howdy.c

@@ -1,18 +1,23 @@
+#include <pthread.h>
 #include <stdio.h>
 
+extern int __pthread_return_0 (void);
+
 int howdy(const char *s)
 {
-	return printf("howdy: %s\n", 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");
+    printf("I am the libhowdy constructor!\n");
 }
 
 void __attribute__((destructor)) howdy_dtor(void)
 {
-	printf("I am the libhowdy destructor!\n");
+    printf("I am the libhowdy destructor!\n");
 }