Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-129838: Don't redefine _Py_NO_SANITIZE_UNDEFINED #129839

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
Feb 20, 2025

Conversation

collinfunk
Copy link
Contributor

@collinfunk collinfunk commented Feb 8, 2025

This macro is redefined because the code was written at a time when LLVM supported:

__attribute__((no_sanitize("undefined")))

and GCC supported:

__attribute__((no_sanitize_undefined))

In 2018, GCC (then 9.0.0) was updated to also accept the LLVM syntax [1]. Since __has_feature was added to GCC in 2023 we can assume __has_feature(undefined_behavior_sanitizer) being true also means __attribute__((no_sanitize("undefined"))) is supported.

Then we just check that the macro isn't defined before checking for the GCC version to use the older syntax.

[1] gcc-mirror/gcc@1991606

Newer GCC versions accept both __attribute__((no_sanitize("undefined")))
and __attribute__((no_sanitize_undefined)) so check that the macro is
not already defined.
Copy link
Contributor

@zanieb zanieb left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for contributing :)

Did you test against old and new gcc versions?

@collinfunk
Copy link
Contributor Author

Did you test against old and new gcc versions?

Good point. I just tested two which use different versions of the macro and work correctly.

On my host machine:

$ gcc --version
gcc (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7)

On cfarm117 [1]:

$ gcc --version
gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516

[1] https://portal.cfarm.net/machines/list/

@colesbury colesbury requested a review from vstinner February 10, 2025 14:56
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinner vstinner merged commit 568db40 into python:main Feb 20, 2025
52 checks passed
@vstinner vstinner added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Feb 20, 2025
@miss-islington-app
Copy link

Thanks @collinfunk for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @collinfunk for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 20, 2025
…29839)

Newer GCC versions accept both __attribute__((no_sanitize("undefined")))
and __attribute__((no_sanitize_undefined)) so check that the macro is
not already defined.
(cherry picked from commit 568db40)

Co-authored-by: Collin Funk <collin.funk1@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Feb 20, 2025

GH-130365 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Feb 20, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 20, 2025
…29839)

Newer GCC versions accept both __attribute__((no_sanitize("undefined")))
and __attribute__((no_sanitize_undefined)) so check that the macro is
not already defined.
(cherry picked from commit 568db40)

Co-authored-by: Collin Funk <collin.funk1@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Feb 20, 2025

GH-130366 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Feb 20, 2025
@vstinner
Copy link
Member

Merged, thanks for the fix @collinfunk!

vstinner pushed a commit that referenced this pull request Feb 20, 2025
#130365)

gh-129838: Don't redefine _Py_NO_SANITIZE_UNDEFINED (GH-129839)

Newer GCC versions accept both __attribute__((no_sanitize("undefined")))
and __attribute__((no_sanitize_undefined)) so check that the macro is
not already defined.
(cherry picked from commit 568db40)

Co-authored-by: Collin Funk <collin.funk1@gmail.com>
vstinner pushed a commit that referenced this pull request Feb 20, 2025
#130366)

gh-129838: Don't redefine _Py_NO_SANITIZE_UNDEFINED (GH-129839)

Newer GCC versions accept both __attribute__((no_sanitize("undefined")))
and __attribute__((no_sanitize_undefined)) so check that the macro is
not already defined.
(cherry picked from commit 568db40)

Co-authored-by: Collin Funk <collin.funk1@gmail.com>
@collinfunk collinfunk deleted the no-sanitize-undefined-redefinition branch February 20, 2025 18:42
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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.