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

Fix C++98 compatibility in our header files #2193

Merged
merged 3 commits into from
Feb 19, 2025

Conversation

samuel40791765
Copy link
Contributor

Issues:

Addresses CryptoAlg-2693

Description of changes:

We encountered this when trying to compile Xtrabackup on gcc versions lower than 10. Apparently scoped enums are a C++11 feature, which the compiler can't understand without additional linker flags.

/home/ubuntu/workplace/percona-xtrabackup/aws-lc/test_build_dir/include/openssl/ssl.h:174:30: warning: scoped enums only available with ‘-std=c++11’ or ‘-std=gnu++11’
  174 | #define BORINGSSL_ENUM_INT : int
      |                              ^~~
...
      |                              ^~~
/home/ubuntu/workplace/percona-xtrabackup/aws-lc/test_build_dir/include/openssl/ssl.h:4783:31: note: in expansion of macro ‘BORINGSSL_ENUM_INT’
 4783 | enum ssl_select_cert_result_t BORINGSSL_ENUM_INT {
      |                               ^~~~~~~~~~~~~~~~~~
make[2]: *** [libmysql/CMakeFiles/clientlib.dir/build.make:149: libmysql/CMakeFiles/clientlib.dir/__/sql-common/client_authentication.cc.o] Error 1
make[2]: Leaving directory '/home/ubuntu/workplace/percona-xtrabackup/build'

We also encountered this in 42a8dba, which prompted us to move it to ssl.h. Upon closer examination, I don't think the C++11 usage is a necessity especially with the pure C fallback that was included. Predeclaring enums reduces compilation dependencies and build times, but our build seems to work fine without it. Removing this would let us encounter less build issues with projects that aren't expecting C++ in our header files.

Call-outs:

N/A

Testing:

CI

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.04%. Comparing base (ead47e8) to head (b98b993).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2193   +/-   ##
=======================================
  Coverage   79.04%   79.04%           
=======================================
  Files         612      612           
  Lines      106222   106222           
  Branches    15008    15006    -2     
=======================================
+ Hits        83959    83965    +6     
+ Misses      21612    21606    -6     
  Partials      651      651           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

justsmth
justsmth previously approved these changes Feb 13, 2025
@justsmth
Copy link
Contributor

Pre-push check is failing:

[Container] 2025/02/13 01:52:19.380053 Running command (cd util && go run ./doc.go)
Failed to generate output: while parsing include/openssl/ssl.h: comment for "SSL_CTX_get0_chain" doesn't seem to match line include/openssl/ssl.h:1274

exit status 1

@samuel40791765 samuel40791765 marked this pull request as ready for review February 13, 2025 18:14
@samuel40791765 samuel40791765 requested a review from a team as a code owner February 13, 2025 18:14
justsmth
justsmth previously approved these changes Feb 13, 2025
Copy link
Contributor

@andrewhop andrewhop left a comment

Choose a reason for hiding this comment

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

Can you update c99_gcc_test.sh to also check for C++ header compatibility (and maybe rename the file). Also double check that it's running, I'm not sure anything defines AWSLC_C99_TEST right now....

@samuel40791765 samuel40791765 changed the title Don't predeclare enums with C++ Fix C++98 compatibility in our header files Feb 19, 2025
@samuel40791765 samuel40791765 force-pushed the c11-usage branch 4 times, most recently from 82c3577 to cb654a3 Compare February 19, 2025 01:29
@@ -24,8 +24,7 @@ INCLUDE_FILES=`ls $INCLUDE_DIR/openssl/*.h | grep -v $INCLUDE_DIR/openssl/arm_ar
# some non-ISO practices, but not all — only those for which ISO C requires a
# diagnostic, and some others for which diagnostics have been added."
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

${CC} -std=c99 -c -I${INCLUDE_DIR} -include ${INCLUDE_FILES} -Wpedantic -fsyntax-only -Werror
${CC} -std=c99 -c -I${INCLUDE_DIR} $(echo ${INCLUDE_FILES} | sed 's/[^ ]* */-include &/g') -Wpedantic -fsyntax-only -Werror ./tests/compiler_features_tests/builtin_swap_check.c
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this sed removing from the list? And why add the builtin_swap_check to all of these targets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sed's mainly in charge of prepending an -include to each file in $INCLUDE_FILES. What we had previously didn't actually work :(. This also needs a basic "c" file to compile, so I chose builtin_swap_check since that was a good existing example that works with older compilers

@samuel40791765 samuel40791765 merged commit c8ef580 into aws:main Feb 19, 2025
116 of 119 checks passed
@samuel40791765 samuel40791765 deleted the c11-usage branch February 19, 2025 19:46
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.

4 participants