Repository navigation
Fix Subprocess.cpp build with clang and glibc >= 2.40 fortify - #2757
Open
adiroy28852 wants to merge 1 commit into
Open
adiroy28852 wants to merge 1 commit into
adiroy28852 wants to merge 1 commit into
Conversation
Summary: With glibc 2.40 or newer, clang and `_FORTIFY_SOURCE`, `bits/fcntl2.h` declares `open` and `openat` as `__attribute__((overloadable))` overload sets. The libc X-macros in `Subprocess.cpp` spell the field types as `decltype(&::open)` and deduce the loader's return type from `&::open`. Neither can pick an overload, so the build fails with "reference to overloaded function could not be resolved". GCC doesn't take that glibc path, so only clang builds break. Now each X-macro entry carries its function type: - The other entries use `decltype(::func)`, so their types are unchanged. - `open` and `openat` use `subprocess_libc_open_t` and `subprocess_libc_openat_t`, their libc signatures. This also covers Bionic's `__open_real` and `__openat_real`. - The initializer does `static_cast<type*>(&::func)`, which picks the libc function out of the overload set. Fixes meta#2751. Test Plan: On Debian trixie (glibc 2.41, clang 19), with `-O2 -D_FORTIFY_SOURCE=2`: - Before: `Subprocess.cpp` fails with the errors in meta#2751. After: it builds, and so does `libfolly.a`. - It also builds with clang without fortify, with clang and ASAN (the `dlsym` path), and with GCC, with no new warnings under `-Wall`. - A smoke test linked against `libfolly.a` passes. It runs a child with `stdinFd(DEV_NULL)` (`open`), and with `setLinuxCGroupPath` on a plain directory (`open`, then `openat` reports `ENOENT`) and on a missing path (`open` reports `ENOENT`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
With glibc 2.40 or newer, clang and
_FORTIFY_SOURCE,bits/fcntl2.hdeclaresopenandopenatas__attribute__((overloadable))overload sets. The libc X-macros inSubprocess.cppspell the field types asdecltype(&::open)and deduce the loader's return type from&::open. Neither can pick an overload, so the build fails with "reference to overloaded function could not be resolved". GCC doesn't take that glibc path, so only clang builds break.Now each X-macro entry carries its function type:
decltype(::func), so their types are unchanged.openandopenatusesubprocess_libc_open_tandsubprocess_libc_openat_t, their libc signatures. This also covers Bionic's__open_realand__openat_real.static_cast<type*>(&::func), which picks the libc function out of the overload set.Fixes #2751.
Test Plan:
On Debian trixie (glibc 2.41, clang 19), with
-O2 -D_FORTIFY_SOURCE=2:Subprocess.cppfails with the errors in Build fails with clang infolly/Subprocess.cpp:error: reference to overloaded function could not be resolved#2751. After: it builds, and so doeslibfolly.a.dlsympath), and with GCC, with no new warnings under-Wall.libfolly.apasses. It runs a child withstdinFd(DEV_NULL)(open), and withsetLinuxCGroupPathon a plain directory (open, thenopenatreportsENOENT) and on a missing path (openreportsENOENT).