Skip to content

Instantly share code, notes, and snippets.

@lewurm
Last active April 1, 2020 08:12
Show Gist options
  • Save lewurm/210b320cb6037ca8ad4a370adf1bde11 to your computer and use it in GitHub Desktop.
Save lewurm/210b320cb6037ca8ad4a370adf1bde11 to your computer and use it in GitHub Desktop.
$ make set_xcode11.3
sudo xcode-select -s /Applications/Xcode113.app/Contents/Developer
$ xcodebuild -version
Xcode 11.3
Build version 11C29

$ cat c.c
#include <sys/select.h>

int foo (void) {
        fd_set s;
        FD_SET (0, &s);
        return FD_ISSET (0, &s);
}

$ make c.dylib
clang -c -mmacosx-version-min=10.9 -o c.o c.c
clang -dynamiclib -mmacosx-version-min=10.9 -Wl,-no_weak_imports -o c.dylib c.o
$ nm c.o
0000000000000060 t ___darwin_fd_isset
0000000000000000 T _foo
$ make clean
rm -f c.dylib c.o

$ make set_xcode11.4
sudo xcode-select -s /Applications/Xcode114.app/Contents/Developer
$ xcodebuild -version
Xcode 11.4
Build version 11E146

$ make c.dylib
clang -c -mmacosx-version-min=10.9 -o c.o c.c
clang -dynamiclib -mmacosx-version-min=10.9 -Wl,-no_weak_imports -o c.dylib c.o
ld: weak import of symbol '___darwin_check_fd_set_overflow' not supported because of option: -no_weak_imports for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [c.dylib] Error 1
$ nm c.o
                 U ___darwin_check_fd_set_overflow
0000000000000000 T _foo

Probably caused by this change:

$ diff \
	/Applications/Xcode113.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_types/_fd_def.h \
	/Applications/Xcode114.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_types/_fd_def.h
31c31,32
< #include <machine/types.h> /* __int32_t */
---
> #include <machine/types.h> /* __int32_t and uintptr_t */
> #include <Availability.h>
51a53,54
>
> int __darwin_check_fd_set_overflow(int, const void *, int) __attribute__((__weak_import__));
53a57,70
> __header_always_inline int
> __darwin_check_fd_set(int _a, const void *_b)
> {
> 	if ((uintptr_t)&__darwin_check_fd_set_overflow != (uintptr_t) 0) {
> #if defined(_DARWIN_UNLIMITED_SELECT) || defined(_DARWIN_C_SOURCE)
> 		return __darwin_check_fd_set_overflow(_a, _b, 1);
> #else
> 		return __darwin_check_fd_set_overflow(_a, _b, 0);
> #endif
> 	} else {
> 		return 1;
> 	}
> }
>
55,56c72,83
< static __inline int
< __darwin_fd_isset(int _n, const struct fd_set *_p)
---
> __header_always_inline int
> __darwin_fd_isset(int _fd, const struct fd_set *_p)
> {
> 	if (__darwin_check_fd_set(_fd, (const void *) _p)) {
> 		return _p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] & ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS)));
> 	}
>
> 	return 0;
> }
>
> __header_always_inline void
> __darwin_fd_set(int _fd, struct fd_set *const _p)
58c85,87
< 	return _p->fds_bits[(unsigned long)_n / __DARWIN_NFDBITS] & ((__int32_t)(((unsigned long)1) << ((unsigned long)_n % __DARWIN_NFDBITS)));
---
> 	if (__darwin_check_fd_set(_fd, (const void *) _p)) {
> 		(_p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] |= ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS))));
> 	}
61,62c90,100
< #define __DARWIN_FD_SET(n, p)   do { int __fd = (n); ((p)->fds_bits[(unsigned long)__fd/__DARWIN_NFDBITS] |= ((__int32_t)(((unsigned long)1)<<((unsigned long)__fd % __DARWIN_NFDBITS)))); } while(0)
< #define __DARWIN_FD_CLR(n, p)   do { int __fd = (n); ((p)->fds_bits[(unsigned long)__fd/__DARWIN_NFDBITS] &= ~((__int32_t)(((unsigned long)1)<<((unsigned long)__fd % __DARWIN_NFDBITS)))); } while(0)
---
> __header_always_inline void
> __darwin_fd_clr(int _fd, struct fd_set *const _p)
> {
> 	if (__darwin_check_fd_set(_fd, (const void *) _p)) {
> 		(_p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] &= ~((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS))));
> 	}
> }
>
>
> #define __DARWIN_FD_SET(n, p)   __darwin_fd_set((n), (p))
> #define __DARWIN_FD_CLR(n, p)   __darwin_fd_clr((n), (p))

bug reports

#include <sys/select.h>
int foo (void) {
fd_set s;
FD_SET (0, &s);
return FD_ISSET (0, &s);
}
.PHONY: set_xcode11.3 set_xcode11.4 clean
c.dylib: c.o
clang -dynamiclib -mmacosx-version-min=10.9 -Wl,-no_weak_imports -o $@ $^
c.o: c.c
clang -c -mmacosx-version-min=10.9 -o $@ $^
set_xcode11.3:
sudo xcode-select -s /Applications/Xcode113.app/Contents/Developer
set_xcode11.4:
sudo xcode-select -s /Applications/Xcode114.app/Contents/Developer
clean:
rm -f c.dylib c.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment