Skip to content

CDRIVER-5641: Build fix for _FORTIFY_SOURCE #1899

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
Mar 6, 2025

Conversation

mdbmes
Copy link
Contributor

@mdbmes mdbmes commented Mar 6, 2025

This is a follow-up for #1868 to fix a build break in the abi-compliance-check task.

The break isn't straightforward to reproduce. It seems to require gcc-9(?), -D_FORTIFY_SOURCE=2 and -Og.

The cause is a set of tests that intentionally generate an oversized memcpy within dead code, to ensure the surrounding guard prevents the binary vector read/write operation. When _FORTIFY_SOURCE is set, additional checks are enabled for string functions like memcpy, enforcing a maximum object size of SIZE_MAX/2. In this patch, any time we build with _FORTIFY_SOURCE the maximum counts for these memcpy are adjusted so we don't overflow even for the largest element type (float32).

@mdbmes mdbmes requested a review from eramongodb March 6, 2025 22:21
@mdbmes
Copy link
Contributor Author

mdbmes commented Mar 6, 2025

Here's the abi-compliance-check evergreen task, it's not included in the usual builds for pull requests:
https://spruce.mongodb.com/version/67ca1d3445a9cf0007b19064/tasks

Copy link
Collaborator

@eramongodb eramongodb left a comment

Choose a reason for hiding this comment

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

Interesting find. It looks like the details involve use of Object Size Checking Built-in Functions (e.g. for memcpy) and selecting "a closest surrounding subobject" as "the object a pointer points to" when _FORTIFY_SOURCE > 1. However, I am unable to determine why this behavior may be restricted to specific GCC versions.

@mdbmes
Copy link
Contributor Author

mdbmes commented Mar 6, 2025

why this behavior may be restricted to specific GCC versions

I'm guessing both the gcc version and the -Og dependency relate to dead code elimination maybe?
Thanks for the review!

@mdbmes mdbmes merged commit 01101f4 into mongodb:master Mar 6, 2025
40 of 42 checks passed
@mdbmes mdbmes deleted the CDRIVER-5641-b branch March 6, 2025 22:55
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.

2 participants