#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <dlfcn.h>
#include <mach-o/getsect.h>
#include "test_support.h"
#if __LP64__
extern struct mach_header_64 __dso_handle;
#else
extern struct mach_header __dso_handle;
#endif
int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_NOW);
if ( handle != NULL ) {
FAIL("dlopen(\"libfoo.dylib\", RTLD_NOW) should have failed");
}
#if __arm64e__
bool supportsLazyBinding = false;
#else
unsigned long sectSize = 0;
bool supportsLazyBinding = (getsectiondata(&__dso_handle, "__DATA", "__la_symbol_ptr", §Size) != NULL);
#if __ARM_ARCH_7K__
if ( !supportsLazyBinding )
supportsLazyBinding = (getsectiondata(&__dso_handle, "__DATA", "__lazy_symbol", §Size) != NULL);
#endif
#endif
handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY);
if ( supportsLazyBinding ) {
if ( handle == NULL ) {
FAIL("dlopen(\"libfoo.dylib\", RTLD_LAZY) should have succeeded: %s", dlerror());
}
}
else {
if ( handle != NULL ) {
FAIL("dlopen(\"libfoo.dylib\", RTLD_LAZY) should have failed becuase a symbol was missing");
}
}
PASS("Success");
}