load-noobjc.m 963 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. TEST_BUILD
  3. $C{COMPILE} $DIR/load-noobjc.m -o load-noobjc.exe
  4. $C{COMPILE} $DIR/load-noobjc2.m -o libload-noobjc2.dylib -bundle -bundle_loader load-noobjc.exe
  5. $C{COMPILE} $DIR/load-noobjc3.m -o libload-noobjc3.dylib -bundle -bundle_loader load-noobjc.exe
  6. END
  7. */
  8. #include "test.h"
  9. #include <dlfcn.h>
  10. int state = 0;
  11. semaphore_t go;
  12. void *thread(void *arg __unused)
  13. {
  14. dlopen("libload-noobjc2.dylib", RTLD_LAZY);
  15. fail("dlopen should not have returned");
  16. }
  17. int main()
  18. {
  19. semaphore_create(mach_task_self(), &go, SYNC_POLICY_FIFO, 0);
  20. pthread_t th;
  21. pthread_create(&th, nil, &thread, nil);
  22. // Wait for thread to stop in libload-noobjc2's +load method.
  23. semaphore_wait(go);
  24. // run nooobjc3's constructor function.
  25. // There's no objc code here so it shouldn't require the +load lock.
  26. void *dlh = dlopen("libload-noobjc3.dylib", RTLD_LAZY);
  27. testassert(dlh);
  28. testassert(state == 1);
  29. succeed(__FILE__);
  30. }