Skip to content

Commit

Permalink
Add a test for weak symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
shinh committed Apr 10, 2011
1 parent 4b8b3a5 commit 60f5043
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mach/dylib/weak.h
@@ -0,0 +1,8 @@
template <class T>
class C {
public:
static int weak;
};

template <class T>
int C<T>::weak = 0;
9 changes: 9 additions & 0 deletions mach/dylib/weak_lib.cc
@@ -0,0 +1,9 @@
#include <stdio.h>

#include "weak.h"

__attribute__((constructor)) void init_weak() {
printf("init_weak before: %d %p\n", C<int>::weak, &C<int>::weak);
C<int>::weak = 42;
printf("init_weak after: %d %p\n", C<int>::weak, &C<int>::weak);
}
24 changes: 24 additions & 0 deletions mach/dylib/weak_main.cc
@@ -0,0 +1,24 @@
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

#include "weak.h"

int main() {
#ifdef DL
int dlflags = RTLD_NOW;
# ifdef __APPLE__
void* h = dlopen("mach/dylib/weak_lib.dylib", dlflags);
# else
void* h = dlopen("mach/dylib/weak_lib.so", dlflags);
# endif
if (!h) {
printf("%s\n", dlerror());
abort();
}
#endif
printf("%d %p\n", C<int>::weak, &C<int>::weak);
if (C<int>::weak != 42) {
abort();
}
}
13 changes: 13 additions & 0 deletions runtests.sh
Expand Up @@ -74,6 +74,19 @@ apple gcc --sysroot=$MAC_TOOL_DIR -g mach/dylib/dlfcn.c -o mach/dylib/dlfcn
echo "Running mach/dylib/dlfcn"
mach/dylib/dlfcn

echo "Running dylib tests with a weak symbol"

apple g++ -g -fPIC -dynamiclib mach/dylib/weak_lib.cc -o mach/dylib/weak_lib.dylib
apple g++ -g -fPIC mach/dylib/weak_main.cc -o mach/dylib/weak_main mach/dylib/weak_lib.dylib
apple g++ -g -fPIC mach/dylib/weak_main.cc -o mach/dylib/weak_main-dl -DDL

echo "Running mach/dylib/weak_main"
mach/dylib/weak_main

echo "Running mach/dylib/weak_main-dl"
mach/dylib/weak_main-dl


# Need this file from Xcode 4
CLANG=$MAC_BIN_DIR/clang-137
if [ -x $CLANG ]; then
Expand Down

0 comments on commit 60f5043

Please sign in to comment.