Skip to content
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

Build failure in release configuration due to -Werror=stringop-truncation errors #7274

Open
edeiana opened this issue Feb 12, 2025 · 5 comments

Comments

@edeiana
Copy link
Contributor

edeiana commented Feb 12, 2025

Build errors occur when compiling DynamoRIO in release mode using gcc 14.2.0 and g++ 13.3.0 on Ubuntu 24.04.
These errors are specifically related to the -Werror=stringop-truncation warning, indicating potential string truncation issues due to the specified bounds depending on the source argument's length. Some are false positives, others seem to highlight genuine potential problems within the code.

The following commands were used to configure and build DynamoRIO:

cmake -DBUILD_TESTS=ON -DCMAKE_C_COMPILER=$(which gcc) -DCMAKE_CXX_COMPILER=$(which g++) -B build -S $(pwd)
make -C build -j10

Note:
Building tests with -DBUILD_TESTS=ON generates additional stringop-truncation errors, some of which are likely false positives.

@Flandini
Copy link
Contributor

What version of DynamoRIO are you using? latest master
Does the latest build from https://github.com/DynamoRIO/dynamorio/releases solve the problem? no
What operating system version are you running on? ("Windows 10" is not sufficient: give the release number.) see above
Is your application 32-bit or 64-bit? N/A

@Flandini
Copy link
Contributor

I configure and make dynamorio as:

cmake -DBUILD_TESTS=ON -DCMAKE_C_COMPILER=$(which gcc) -DCMAKE_CXX_COMPILER=$(which g++) -B build -S $(pwd)
make -C build -j10

@derekbruening
Copy link
Contributor

These stringop warnings are disabled in core/:

$ git grep -n stringop-truncation
CMakeLists.txt:920:    CHECK_C_COMPILER_FLAG("-Wstringop-truncation" stringop_truncation_avail)
CMakeLists.txt:922:      set(WARN "${WARN} -Wno-stringop-truncation")

@Flandini
Copy link
Contributor

Looks like I foobar'd my cmake build directory. I generated a compile_commands.json for use with my editor, and it is missing these warn disables and some other ones for the files in this accompanying PR. Rebuilding with a fresh cmake build directory, I don't have these errors anymore and things compile fine.

Happy to close the accompanying PR as user error, or fix up the truncation warning problem and revert the other changes, whichever y'all want.

@derekbruening
Copy link
Contributor

The issue of strncpy wasting time padding the entire buffer with nulls is also covered here. Since we use the dr_snprintf BUFFER_SIZE_ELEMENTS;NULL_TERMINATE_BUFFER pattern for construction in many places, and there is no simple strncpy replacement, we are considering replacing strncpy when the buffer is often larger than the source with dr_snprintf %s.

edeiana pushed a commit that referenced this issue Feb 14, 2025
Substitutes `strncpy()` with `dr_snprintf()` and warn on possible
name truncation in func_trace.cpp. Avoid null byte copies.

Issue: #7274
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants