Skip to content

stream: Fix MacOS build. fsync as alias for fdatasync. #6882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

devnexen
Copy link
Member

No description provided.

@nikic
Copy link
Member

nikic commented Apr 20, 2021

I'm confused about why this works in CI (using macos 10.15). Was this function recently added/removed?

@devnexen
Copy link
Member Author

I spotted it because of implicit declaration... warning and indeed macos does not have it.

@nikic
Copy link
Member

nikic commented Apr 20, 2021

That just leaves me more confused. We build with -Werror in CI, and I also checked that the test case for fdatasync is running and passing. The build seems to be picking up the symbol from somewhere...

@devnexen
Copy link
Member Author

There is a syscall id mentioning it but not wrapper function, no man page entry for it.
And seems before it was not neither gbrault/picoc#145 (comment)

@devnexen
Copy link
Member Author

That just leaves me more confused. We build with -Werror in CI, and I also checked that the test case for fdatasync is running and passing. The build seems to be picking up the symbol from somewhere...

Does it imply -Werror-implicit-function-declaration (or should be added to CI) ?

@nikic
Copy link
Member

nikic commented Apr 20, 2021

I just double checked this, and this the the used compilation command:

/bin/sh /Users/runner/work/1/s/libtool --silent --preserve-dup-deps --mode=compile cc -Imain/streams/ -I/Users/runner/work/1/s/main/streams/ -I/Users/runner/work/1/s/include -I/Users/runner/work/1/s/main -I/Users/runner/work/1/s -I/Users/runner/work/1/s/ext/date/lib -I/usr/local/Cellar/libxml2/2.9.10_2/include/libxml2 -I/usr/local/Cellar/krb5/1.19.1/include -I/usr/local/Cellar/[email protected]/1.1.1k/include -I/usr/local/Cellar/zlib/1.2.11/include -I/usr/local/opt/bzip2/include -I/usr/local/Cellar/libffi/3.3_3/include -I/usr/local/Cellar/libpng/1.6.37/include/libpng16 -I/usr/local/Cellar/webp/1.2.0/include -I/usr/local/Cellar/jpeg/9d/include -I/usr/local/opt/freetype/include/freetype2 -I/usr/local/opt/gettext/include -I/usr/local/opt/gmp/include -I/usr/local/opt/libiconv/include -I/usr/local/Cellar/icu4c/68.2/include -I/usr/local/Cellar/oniguruma/6.9.6/include -I/Users/runner/work/1/s/ext/mbstring/libmbfl -I/Users/runner/work/1/s/ext/mbstring/libmbfl/mbfl -I/usr/local/opt/libpq/include -I/usr/local/opt/aspell/include/pspell -I/usr/local/opt/readline/include -I/usr/local/Cellar/libsodium/1.0.18_1/include -I/usr/local/opt/tidyp/include/tidyp -I/usr/local/Cellar/libxslt/1.1.34_2/include -I/usr/local/Cellar/libzip/1.7.3/include -I/Users/runner/work/1/s/TSRM -I/Users/runner/work/1/s/Zend -fno-common -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g -fvisibility=hidden -O0 -DZEND_SIGNALS -Werror -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /Users/runner/work/1/s/main/streams/plain_wrapper.c -o main/streams/plain_wrapper.lo -MMD -MF main/streams/plain_wrapper.dep -MT main/streams/plain_wrapper.lo

It includes -Wall -Wextra -Werror, so should definitely catch implicit function declarations.

My best guess is that we're pulling in a header somewhere that has an fdatasync compatibility define...

@devnexen
Copy link
Member Author

Then yes it is the only reason it could happen I locally does not use so many dependencies.

@devnexen devnexen force-pushed the stream_ext_macos_fix branch from 0e638d9 to b90bdbe Compare April 20, 2021 10:19
@nikic
Copy link
Member

nikic commented Apr 20, 2021

I've dumped the preprocessed code (-E) for the file: https://dev.azure.com/phpazuredevops/eb1f6f74-bc61-47a6-a414-0e3ff41c9bb4/_apis/build/builds/16109/logs/28

fdatasync() is being called directly and there is no declaration for it, so it's not the case that it was defined by some other header. But for some reason the build does not fail. I even added an explicit -Werror=implicit-function-declaration, but that also had no effect.

@devnexen
Copy link
Member Author

devnexen commented Apr 20, 2021

I have a slighty better idea what is happening now. I did a quick sample local code and if I compile with clang from Xcode then it is fine fdatasync symbol is picked up rightfully (but fdatasync not present in the headers tough), however with gcc/clang compilers from homebrew then I get the warning. Maybe the best course of action would be configure time detection then what do you think ?

@nikic
Copy link
Member

nikic commented Apr 21, 2021

I have a slighty better idea what is happening now. I did a quick sample local code and if I compile with clang from Xcode then it is fine fdatasync symbol is picked up rightfully (but fdatasync not present in the headers tough), however with gcc/clang compilers from homebrew then I get the warning.

Any idea where Xcode is getting the symbol from?

Maybe the best course of action would be configure time detection then what do you think ?

Yes, I think this would make the most sense. After all, macos may also not be the only system without this function. We can add it to the list in

AC_CHECK_FUNCS(

@devnexen devnexen force-pushed the stream_ext_macos_fix branch from b90bdbe to dcb05eb Compare April 21, 2021 08:07
@devnexen
Copy link
Member Author

No idea, it seems part of Apple's secret sauce :)

@nikic nikic merged commit 7aba6de into php:master Apr 21, 2021
@morrisonlevi
Copy link
Contributor

fdatasync doesn't exist in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain on Mac OS 10.15. There is a function which is not defined in a header: https://github.com/apple/darwin-xnu/blob/d4061fb0260b3ed486147341b72468f836ed6c8f/bsd/vfs/vfs_syscalls.c#L7708.

I have no idea why. My guess... don't use it?

@trowski
Copy link
Member

trowski commented Jun 8, 2021

I'm still seeing php-src/main/streams/plain_wrapper.c:559:11: warning: implicit declaration of function 'fdatasync' is invalid in C99 when compiling with clang on macOS. Is there a path or something else I need to be setting, or is there still an issue with fdatasync on macOS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants