[MacPorts] #66188: libsdl2: re-enable universal building i386/x86_64

MacPorts noreply at macports.org
Tue Nov 8 02:51:25 UTC 2022

#66188: libsdl2: re-enable universal building i386/x86_64
  Reporter:  kencu    |      Owner:  jmroot
      Type:  defect   |     Status:  assigned
  Priority:  Normal   |  Milestone:
 Component:  ports    |    Version:
Resolution:           |   Keywords:
      Port:  libsdl2  |

Comment (by kencu):

 I would test ARC in the i386 slice, if I can see how to.

 I believe that at first there was no autoreleasepool support for i386, but
 later on they added it to libobjc. My theory is that the ancient clang
 that comes with 10.7 doesn't know this, but newer clangs do.

 This is on 10.7.5:

 $ nm -arch i386 /usr/lib/libobjc.A.dylib | grep autorelease
 000d8798 s _SEL_autorelease
 0000bdb2 t
 00009a9d T __objc_autoreleasePoolPop
 0001eb25 T __objc_autoreleasePoolPrint
 00008fc8 T __objc_autoreleasePoolPush
 0001e5a0 T _objc_autorelease
 0001e92c t _objc_autoreleaseNoPool
 0001eb00 T _objc_autoreleasePoolPop
 00008fd1 T _objc_autoreleasePoolPush
 0000b3be T _objc_autoreleaseReturnValue
 0001e5c6 T _objc_retain_autorelease

 example file:
 $ cat writeback.m
 // clang -fobjc-arc -arch i386  -o writeback writeback.m

 #import <Foundation/Foundation.h>
 #import <Foundation/NSObjCRuntime.h>

 __weak id weak;

 int writeBack(id *aValue)
   *aValue = [NSObject new];
   weak = *aValue;
   return 0;

 int main(void)
     id object;
     NSLog(@"Object: %@", object);
     object = nil;
     NSLog(@"Object: %@", weak);
   NSLog(@"Object: %@", weak);
   return 0;

 system clang build works x86_64:
 $ /usr/bin/clang -fobjc-arc -arch x86_64  -o writeback writeback.m
 $ ./writeback
 2022-11-07 18:44:28.328 writeback[387:707] Object: <NSObject: 0x10b014050>
 2022-11-07 18:44:28.333 writeback[387:707] Object: <NSObject: 0x10b014050>
 2022-11-07 18:44:28.337 writeback[387:707] Object: (null)
 but fails i386:
 $ /usr/bin/clang -fobjc-arc -arch i386  -o writeback writeback.m
 error: -fobjc-arc is not supported on platforms using the legacy runtime
 but macports-clang-11 works i386:
 $ clang-mp-11  -fobjc-arc -arch i386   -o writeback writeback.m
 $ file writeback
 writeback: Mach-O executable i386
 Kens-107-VM-Parallels:~ cunningh$ ./writeback
 2022-11-07 18:47:55.544 writeback[399:507] Object: <NSObject: 0x148160>
 2022-11-07 18:47:55.549 writeback[399:507] Object: <NSObject: 0x148160>
 2022-11-07 18:47:55.552 writeback[399:507] Object: (null)

 Aside: for obscure reasons, the clang-mp-11 x86_64 build has to be done a
 little differently, in two stages. That's not relevant here to this so I
 left that bit out for now.

Ticket URL: <https://trac.macports.org/ticket/66188#comment:2>
MacPorts <https://www.macports.org/>
Ports system for macOS

More information about the macports-tickets mailing list