Skip to content

order limits.h before stdlib.h to workaround for glibc _FORTIFY_SOURCE #1184

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lhoward
Copy link

@lhoward lhoward commented Jun 28, 2025

limits.h must be included before stdlib.h when building with glibc and having _FORTIFY_SOURCE set to a non-zero value.

When building with _FORTIFY_SOURCE, realpath() is inlined, and its definition depends on whether limits.h has been included or not (clearly, this is a terrible idea in terms of interacting with Clang modules and should probably be fixed upstream). If the definition differs from the one in SwiftGlibc, then _TestingInternals will not build.

lhoward added a commit to PADL/meta-swift that referenced this pull request Jun 28, 2025
`limits.h` must be included before `stdlib.h` when building with glibc and
having `_FORTIFY_SOURCE` set to a non-zero value.

When building with `_FORTIFY_SOURCE`, `realpath()` is inlined, and its
definition depends on whether `limits.h` has been included or not (clearly,
this is a terrible idea in terms of interacting with Clang modules and should
probably be fixed upstream). If the definition differs from the one in
SwiftGlibc, then _TestingInternals will not build.

swiftlang/swift-testing#1184
Copy link
Contributor

@grynspan grynspan left a comment

Choose a reason for hiding this comment

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

Can we put it in alphabetical position? Also, can you include a URL to whatever issue tracks the upstream fix?

@grynspan grynspan added bug 🪲 Something isn't working linux 🐧 Linux support (all distros) workaround Workaround for an issue in another component (may need to revert later) build 🧱 Affects the project's build configuration or process labels Jun 28, 2025
@grynspan grynspan added this to the Swift 6.x (main) milestone Jun 28, 2025
@grynspan
Copy link
Contributor

@swift-ci test

@lhoward
Copy link
Author

lhoward commented Jun 28, 2025

Obviously we could also conditionalise this based on platform but I presume it's generally safe to include <limits.h> first.

@lhoward
Copy link
Author

lhoward commented Jun 28, 2025

Can we put it in alphabetical position? Also, can you include a URL to whatever issue tracks the upstream fix?

Yes, will do.

`limits.h` must be included before `stdlib.h` when building with glibc and
having `_FORTIFY_SOURCE` set to a non-zero value.

When building with `_FORTIFY_SOURCE`, `realpath()` is inlined, and its
definition depends on whether `limits.h` has been included or not (clearly,
this is a terrible idea in terms of interacting with Clang modules and should
probably be fixed upstream). If the definition differs from the one in
SwiftGlibc, then _TestingInternals will not build.
@grynspan
Copy link
Contributor

Is there a URL we can point to tracking the issue in glibc?

@lhoward
Copy link
Author

lhoward commented Jun 29, 2025

Is there a URL we can point to tracking the issue in glibc?

I haven't filed a bug yet, will do (sorry, it's Sunday, negotiating bug fixing around family life!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working build 🧱 Affects the project's build configuration or process linux 🐧 Linux support (all distros) workaround Workaround for an issue in another component (may need to revert later)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants