#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <mach-o/dyld_priv.h>
#include "test_support.h"
int mainSymbol = 4;
int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
void* fooHandle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY);
if ( fooHandle == NULL ) {
FAIL("libfoo.dylib could not be loaded, %s", dlerror());
}
void* barHandle = dlopen(RUN_DIR "/libbar.dylib", RTLD_LAZY);
if ( barHandle == NULL ) {
FAIL("libbar.dylib could not be loaded, %s", dlerror());
}
if ( dlsym(fooHandle, "mainSymbol") != NULL ) {
FAIL("mainSymbol was found with fooHandle");
}
if ( dlsym(fooHandle, "foo") == NULL ) {
FAIL("foo not found with fooHandle");
}
if ( dlsym(fooHandle, "base") == NULL ) {
FAIL("base not found with fooHandle");
}
if ( dlsym(fooHandle, "bar") != NULL ) {
FAIL("bar found with fooHandle");
}
if ( dlsym(barHandle, "bar") == NULL ) {
FAIL("bar not found with barHandle");
}
if ( dlsym(barHandle, "base") == NULL ) {
FAIL("base not found with barHandle");
}
if ( dlsym(barHandle, "foo") != NULL ) {
FAIL("foo found with barHandle");
}
if ( dlsym(RTLD_DEFAULT, "strcmp") == NULL ) {
FAIL("strcmp not found");
}
if ( dlsym((void*)0xdeadbeef, "malloc") != NULL ) {
FAIL("malloc found with bad handle");
}
else {
const char* message = dlerror();
if ( strstr(message, "invalid") == NULL ) {
FAIL(" invalid handle error message missing 'invalid'");
}
}
PASS("Success");
}