gcenforcer-preflight.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma clang diagnostic ignored "-Wcomment"
  2. /*
  3. fixme disabled in BATS because of gcfiles
  4. TEST_CONFIG OS=macosx BATS=0
  5. TEST_BUILD
  6. cp $DIR/gcfiles/* .
  7. $C{COMPILE} $DIR/gcenforcer-preflight.m -o gcenforcer-preflight.exe
  8. END
  9. */
  10. #include "test.h"
  11. #include <dlfcn.h>
  12. void check(int expected, const char *name)
  13. {
  14. int fd = open(name, O_RDONLY);
  15. testassert(fd >= 0);
  16. int result = objc_appRequiresGC(fd);
  17. close(fd);
  18. testprintf("want %2d got %2d for %s\n", expected, result, name);
  19. if (result != expected) {
  20. fail("want %2d got %2d for %s\n", expected, result, name);
  21. }
  22. testassert(result == expected);
  23. }
  24. int main()
  25. {
  26. int i;
  27. for (i = 0; i < 1000; i++) {
  28. // dlopen_preflight
  29. testassert(dlopen_preflight("libsupportsgc.dylib"));
  30. testassert(dlopen_preflight("libnoobjc.dylib"));
  31. testassert(! dlopen_preflight("librequiresgc.dylib"));
  32. testassert(dlopen_preflight("libnogc.dylib"));
  33. // objc_appRequiresGC
  34. // noobjc: no ObjC content
  35. // nogc: ordinary not GC
  36. // aso: trivial AppleScriptObjC wrapper that can run without GC
  37. // gc: -fobjc-gc
  38. // gconly: -fobjc-gc-only
  39. // gcaso: non-trivial AppleScriptObjC with too many classrefs
  40. // gcaso2: non-trivial AppleScriptObjC with too many class impls
  41. check(0, "x86_64-noobjc");
  42. check(0, "x86_64-nogc");
  43. check(0, "x86_64-aso");
  44. check(1, "x86_64-gc");
  45. check(1, "x86_64-gconly");
  46. check(1, "x86_64-gcaso");
  47. check(1, "x86_64-gcaso2");
  48. check(0, "i386-noobjc");
  49. check(0, "i386-nogc");
  50. check(0, "i386-aso");
  51. check(1, "i386-gc");
  52. check(1, "i386-gconly");
  53. check(1, "i386-gcaso");
  54. check(1, "i386-gcaso2");
  55. // fat files
  56. check(0, "i386-aso--x86_64-aso");
  57. check(0, "i386-nogc--x86_64-nogc");
  58. check(1, "i386-gc--x86_64-gc");
  59. check(1, "i386-gc--x86_64-nogc");
  60. check(1, "i386-nogc--x86_64-gc");
  61. // broken files
  62. check(-1, "x86_64-broken");
  63. check(-1, "i386-broken");
  64. check(-1, "i386-broken--x86_64-gc");
  65. check(-1, "i386-broken--x86_64-nogc");
  66. check(-1, "i386-gc--x86_64-broken");
  67. check(-1, "i386-nogc--x86_64-broken");
  68. // evil files
  69. // evil1: claims to have 4 billion load commands of size 0
  70. check(-1, "evil1");
  71. }
  72. succeed(__FILE__);
  73. }