Skip to content

Commit dd6c147

Browse files
[libc][darwin] avoid importing macros conflicting with function names in overlay mode (#171691)
MacOS SDK defines certain functions as macros in its stdio header. This leads to problems in overlay mode. This patch add undefs to macros that may conflict with function names in overlay header. We don't expect to import them via overlay macro headers anyway. ```bash FAILED: [code=1] libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o sccache /usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_22_0_0_git -D_DEBUG -I/Users/runner/work/llvm-project/llvm-project/libc -isystem /Users/runner/work/llvm-project/llvm-project/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -std=gnu++17 -arch arm64 -I /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_COPT_STRING_LENGTH_IMPL=element -DLIBC_COPT_FIND_FIRST_CHARACTER_IMPL=element -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -DLIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM -DLIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=100 -fpie -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -MD -MT libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o -MF libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o.d -o libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o -c /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9: /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected member name or ';' after declaration specifiers 260 | void clearerr_unlocked() { err = false; } | ~~~~ ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked' 495 | #define clearerr_unlocked(p) __sclearerr(p) | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:26: note: expanded from macro '__sclearerr' 383 | #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) | ^ In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9: /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected ')' /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked' 495 | #define clearerr_unlocked(p) __sclearerr(p) | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:26: note: expanded from macro '__sclearerr' 383 | #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) | ^ /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: note: to match this '(' /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked' 495 | #define clearerr_unlocked(p) __sclearerr(p) | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:25: note: expanded from macro '__sclearerr' 383 | #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) | ^ In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9: /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: unknown type name '_flags' 260 | void clearerr_unlocked() { err = false; } | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked' 495 | #define clearerr_unlocked(p) __sclearerr(p) | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:37: note: expanded from macro '__sclearerr' 383 | #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) | ^ In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9: /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: a type specifier is required for all declarations /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked' 495 | #define clearerr_unlocked(p) __sclearerr(p) | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:34: note: expanded from macro '__sclearerr' 383 | #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) | ^ In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9: /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected ')' /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked' 495 | #define clearerr_unlocked(p) __sclearerr(p) | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:44: note: expanded from macro '__sclearerr' 383 | #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) | ^ /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: note: to match this '(' /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked' 495 | #define clearerr_unlocked(p) __sclearerr(p) | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:31: note: expanded from macro '__sclearerr' 383 | #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) | ^ /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:426:23: error: out-of-line definition of 'mode_flags' does not match any declaration in '__llvm_libc_22_0_0_git::File' 426 | File::ModeFlags File::mode_flags(const char *mode) { | ^~~~~~~~~~ 6 errors generated. ```
1 parent 3e414b9 commit dd6c147

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

libc/hdr/stdio_overlay.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,18 @@
6666
#undef LIBC_OLD_USE_EXTERN_INLINES
6767
#endif
6868

69+
// undefine symbolic macros for Apple platforms in overlay mode
70+
#ifdef __APPLE__
71+
#undef getc_unlocked
72+
#undef putc_unlocked
73+
#undef getchar_unlocked
74+
#undef putchar_unlocked
75+
#undef fropen
76+
#undef fwopen
77+
#undef feof_unlocked
78+
#undef ferror_unlocked
79+
#undef clearerr_unlocked
80+
#undef fileno_unlocked
81+
#endif
82+
6983
#endif // LLVM_LIBC_HDR_STDIO_OVERLAY_H

0 commit comments

Comments
 (0)