Skip to content

Fix Subprocess.cpp build with clang and glibc >= 2.40 fortify - #2757

Open
adiroy28852 wants to merge 1 commit into
meta:mainfrom
adiroy28852:fix-subprocess-clang-fortify-open
Open

adiroy28852 wants to merge 1 commit into
meta:mainfrom
adiroy28852:fix-subprocess-clang-fortify-open

Conversation

@adiroy28852

Copy link
Copy Markdown

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 #2751.

Test Plan:
On Debian trixie (glibc 2.41, clang 19), with -O2 -D_FORTIFY_SOURCE=2:

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>
@meta-cla meta-cla Bot added the CLA Signed label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build fails with clang in folly/Subprocess.cpp: error: reference to overloaded function could not be resolved

1 participant