http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55693



--- Comment #31 from Jack Howarth <howarth at nitro dot med.uc.edu> 2013-01-23 
19:41:52 UTC ---

I believe the attached testcase, weak_symbol.tar.bz2, demonstrates that the

solution on darwin is to mark the duplicate symbols in crttme.o as weak.

Consider the following test case...



% cat fun.c

extern void foo(void) __attribute__((weak));

 void fun(void)

 {

   if (foo) foo();

 }



% cat foo.c

#include <stdio.h>



void foo(void)

{

  printf("Hello!\n");

}





% cat bar.c

#include <stdio.h>



void foo(void) __attribute__((weak));



void foo(void)

{

  printf("Goodbye!\n");

}



% cat weak_test.c

#include <stdio.h>



void fun(void);



int main()

{

  fun();

  return 0;

}



compiled as...



clang -c fun.c

clang -dyanmiclib -shared -Wl,-undefined -Wl,dynamic_lookup -o libfun.dylib

fun.o

clang -c foo.c

clang -dyanmiclib -shared -Wl,-undefined -Wl,dynamic_lookup -o libfoo.dylib

foo.o

clang -c bar.c

clang -c weak_test.c

clang -o weak_test weak_test.o ./libfoo.dylib ./libfun.dylib bar.o

clang -o weak_test2 weak_test.o  ./libfun.dylib bar.o



This gives...



setenv DYLD_LIBRARY_PATH .

% ./weak_test

Hello!

% ./weak_test2

Goodbye!



which argues that if we mark the weak symbols from eh_cpp.cc as weak in

crttme.o as well, those symbols can be overridden by the ones in libstdc++ as

expected. Also, this eliminates the need to place libstdc++ first...



% clang -o weak_test3 weak_test.o ./libfun.dylib bar.o ./libfoo.dylib

% ./weak_test3

Hello!

Reply via email to