Skip to content

Fix Subprocess.cpp with clang + _FORTIFY_SOURCE on glibc >= 2.40#2519

Open
mszabo-wikia wants to merge 1 commit intofacebook:mainfrom
mszabo-wikia:fix-openat-overload-fortify
Open

Fix Subprocess.cpp with clang + _FORTIFY_SOURCE on glibc >= 2.40#2519
mszabo-wikia wants to merge 1 commit intofacebook:mainfrom
mszabo-wikia:fix-openat-overload-fortify

Conversation

@mszabo-wikia
Copy link
Copy Markdown
Contributor

On glibc >= 2.40, _FORTIFY_SOURCE overloads openat() when building with clang, causing the decltype call in Subprocess.cpp to fail since the target becomes ambiguous. So, explicitly specify our overload of choice in this case.

Reproduce/test by setting CMAKE_CXX_FLAGS=-D_FORTIFY_SOURCE=3 -DCMAKE_CXX_COMPILER=clang++.

On glibc >= 2.40, _FORTIFY_SOURCE overloads openat() when building with
clang, causing the `decltype` call in Subprocess.cpp to fail since the target
becomes ambiguous. So, explicitly specify our overload of choice in this case.

Reproduce/test by setting `CMAKE_CXX_FLAGS=-D_FORTIFY_SOURCE=3 -DCMAKE_CXX_COMPILER=clang++`.
@meta-cla meta-cla Bot added the CLA Signed label Oct 10, 2025
mszabo-wikia added a commit to mszabo-wikia/hhvm that referenced this pull request Nov 18, 2025
Update and extend the list of hardening-related compiler flags
used by HHVM to better represent modern distro defaults.

* Convert the existing `ENABLE_SSP` build option into a new
  `ENABLE_HARDENING` option and put an updated list of security flags behind it.
  Both clang and GCC have been supporting these options for a while now,
  so we can set them irrespective of the compiler.
* Put PIE-related options behind a separate `ENABLE_PIE` build option
  so that we can produce and compare non-PIE and PIE builds once we fix
  compatibility with PIE.
* Forward `CMAKE_BUILD_TYPE` to vendored subprojects. Lack of this
  was causing the projects to be built without compiler optimizations,
  which doesn't play well with `FORTIFY_SOURCE`.

On systems with glibc >= 2.40, facebook/folly#2519
is needed for this option to work.

The overhead from these flags is likely to be limited, as many of them
have been set by default for distribution packages for several years now.[1]

[1] https://github.com/jvoisin/compiler-flags-distro
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Nov 24, 2025

@Wilfred has imported this pull request. If you are a Meta employee, you can view this in D87780304.

mszabo-wikia added a commit to mszabo-wikia/hhvm that referenced this pull request Nov 24, 2025
Update and extend the list of hardening-related compiler flags
used by HHVM to better represent modern distro defaults.

* Convert the existing `ENABLE_SSP` build option into a new
  `ENABLE_HARDENING` option and put an updated list of security flags behind it.
  Both clang and GCC have been supporting these options for a while now,
  so we can set them irrespective of the compiler.
* Put PIE-related options behind a separate `ENABLE_PIE` build option
  so that we can produce and compare non-PIE and PIE builds once we fix
  compatibility with PIE.
* Forward `CMAKE_BUILD_TYPE` to vendored subprojects. Lack of this
  was causing the projects to be built without compiler optimizations,
  which doesn't play well with `FORTIFY_SOURCE`.

On systems with glibc >= 2.40, facebook/folly#2519
is needed for this option to work.

The overhead from these flags is likely to be limited, as many of them
have been set by default for distribution packages for several years now.[1]

[1] https://github.com/jvoisin/compiler-flags-distro
meta-codesync Bot pushed a commit to facebook/hhvm that referenced this pull request Nov 25, 2025
Summary:
Update and extend the list of hardening-related compiler flags used by HHVM to better represent modern distro defaults.

* Convert the existing `ENABLE_SSP` build option into a new `ENABLE_HARDENING` option and put an updated list of security flags behind it. Both clang and GCC have been supporting these options for a while now, so we can set them irrespective of the compiler.
* Put PIE-related options behind a separate `ENABLE_PIE` build option so that we can produce and compare non-PIE and PIE builds once we fix compatibility with PIE.
* Forward `CMAKE_BUILD_TYPE` to vendored subprojects. Lack of this was causing the projects to be built without compiler optimizations, which doesn't play well with `FORTIFY_SOURCE`.

On systems with glibc >= 2.40, facebook/folly#2519 is needed for this option to work.

The overhead from these flags is likely to be limited, as many of them have been set by default for distribution packages for several years now.[1]

[1] https://github.com/jvoisin/compiler-flags-distro

Pull Request resolved: #9672

Reviewed By: Wilfred

Differential Revision: D87347762

fbshipit-source-id: cdfbf29184e6022999e89258d7fa3475c971e01a
@Wilfred
Copy link
Copy Markdown
Contributor

Wilfred commented Nov 25, 2025

FWIW we're seeing build failures here:

error: no member named '__openat_2' in the global namespace

and openat_2 has existed since at least glibc 2.7: https://github.com/bminor/glibc/blob/glibc-2.7/include/fcntl.h#L29

Are you sure this is correct?

Copy link
Copy Markdown
Contributor

@Wilfred Wilfred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment on the PR.

@mszabo-wikia
Copy link
Copy Markdown
Contributor Author

So this was aiming to workaround the glibc 2.40+ changes introduced in bminor/glibc@86889e2 that only manifest with FORTIFY_SOURCE defined. Not sure what might be causing those failures, I'll look into it!

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.

2 participants