-
Notifications
You must be signed in to change notification settings - Fork 704
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
refactor: clean up CMakelists.txt #4779
base: main
Are you sure you want to change the base?
Conversation
I actually can't replace the other shared lib with the one used for unit tests, because the fuzz tests need to be dynamically linked because they rely on LD_PRELOAD to clobber certain symbols.
no-missing-braces is required for GCC 4 support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not disagreeing with the section header, but you can get syntax highlighting on CMake file if you get extension on VS Code which made my life x10 easier.
Thank you for cleaning this up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the cleanup!
My suggestion for a PR like this would be to comment on your own PR in-line with explanations of the various changes, rather than summarizing in the description. I've found that helps when the reasoning behind line changes aren't clear, but a persistent code comment wouldn't make sense (particularly for deletes).
# GCC 4 fails to parse our macros with a "missing-braces" error | ||
-Wno-missing-braces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have an issue for this? ARE macros missing braces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ARE macros missing braces?
My understanding is that the answer is "no" otherwise things would actually be broken.
/codebuild/output/src491586333/src/github.com/aws/s2n-tls/s2n_head/tests/unit/s2n_x509_validator_time_verification_test.c: In function 'main':
/codebuild/output/src491586333/src/github.com/aws/s2n-tls/s2n_head/tests/unit/s2n_x509_validator_time_verification_test.c:116:34: warning: missing braces around initializer [-Wmissing-braces]
DEFER_CLEANUP(struct s2n_stuffer cert_chain_stuffer = { 0 }, s2n_stuffer_free);
^
/codebuild/output/src491586333/src/github.com/aws/s2n-tls/s2n_head/./utils/s2n_safety.h:62:43: note: in definition of macro 'DEFER_CLEANUP'
__attribute__((cleanup(_thecleanup))) _thealloc
^
Other people have run into similar false positives with old versions of GCC.
OP-TEE/optee_os#1998
I did find a bug report that seems related, but it says the fix was backported to GCC 4.8.3 and our CI version is 4.8.5
# NAME_WE: name without extension | ||
get_filename_component(test_case_name ${test_case} NAME_WE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat, a very cmake way to do it!
-Wall -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized | ||
-Wshadow -Wcast-align -Wwrite-strings -Wformat-security | ||
-Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-deprecated -std=gnu99 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably out of scope of this refactor, but it'd be nice if we had a list of common warnings we want enabled. It's not clear whether this matches the warnings on the main library, and whether the differences are intentional or just a mistake because someone forgot to update everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I think the proper way to do this is to define
S2N_COMMON_WARNINGS
And then if S2N_WERROR_ALL
is set then you would just make the compile options on libs2n
public, ensuring that all of the associated items (test utility library, fuzz tests, unit tests) all just get them by default. I'll open an issue for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an action item for this in #4792
target_include_directories(${test_case_name} PRIVATE ./) | ||
target_link_libraries(${test_case_name} PRIVATE testss2n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea what these target_include_directories are trying to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_include_directories
is used to indicate the header file locations that are necessary for that specific target.
This is an odd directive to use for an individual test binary, because those test binaries don't have associated header files.
I think the generic thought was "test binary needs access to the test headers" but those test headers are already publicly associated with testss2n
. So when testss2n
is linked to the test binary, the test binary will also get the test headers.
Line 453 in 2467416
target_include_directories(testss2n PUBLIC tests) |
# GCC 4 fails to parse our macros with a "missing-braces" error | ||
-Wno-missing-braces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ARE macros missing braces?
My understanding is that the answer is "no" otherwise things would actually be broken.
/codebuild/output/src491586333/src/github.com/aws/s2n-tls/s2n_head/tests/unit/s2n_x509_validator_time_verification_test.c: In function 'main':
/codebuild/output/src491586333/src/github.com/aws/s2n-tls/s2n_head/tests/unit/s2n_x509_validator_time_verification_test.c:116:34: warning: missing braces around initializer [-Wmissing-braces]
DEFER_CLEANUP(struct s2n_stuffer cert_chain_stuffer = { 0 }, s2n_stuffer_free);
^
/codebuild/output/src491586333/src/github.com/aws/s2n-tls/s2n_head/./utils/s2n_safety.h:62:43: note: in definition of macro 'DEFER_CLEANUP'
__attribute__((cleanup(_thecleanup))) _thealloc
^
Other people have run into similar false positives with old versions of GCC.
OP-TEE/optee_os#1998
I did find a bug report that seems related, but it says the fix was backported to GCC 4.8.3 and our CI version is 4.8.5
target_include_directories(${test_case_name} PRIVATE ./) | ||
target_link_libraries(${test_case_name} PRIVATE testss2n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_include_directories
is used to indicate the header file locations that are necessary for that specific target.
This is an odd directive to use for an individual test binary, because those test binaries don't have associated header files.
I think the generic thought was "test binary needs access to the test headers" but those test headers are already publicly associated with testss2n
. So when testss2n
is linked to the test binary, the test binary will also get the test headers.
Line 453 in 2467416
target_include_directories(testss2n PUBLIC tests) |
add_custom_command( | ||
TARGET testss2n POST_BUILD | ||
COMMAND | ||
objcopy --redefine-syms libcrypto.symbols lib/libtestss2n.a | ||
) | ||
endif() | ||
|
||
#run unit tests | ||
file (GLOB TEST_LD_PRELOAD "tests/LD_PRELOAD/*.c") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this because it is unused. I searched the entire codebase (not just CMakeLists.txt) and found that this library is only used when unit tests are run through make. See the PR overview for my thoughts on why we should totally delete this library.
|
||
add_library(testss2n STATIC ${TESTLIB_HEADERS} ${TESTLIB_SRC} ${EXAMPLES_SRC}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Headers shouldn't be included as part of the add_library
directive. Generally the add_library
directive is just used for things that generate object files. Header should then be added through target_include_directories
, but that is already configured to add the tests/
path.
-Wall -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized | ||
-Wshadow -Wcast-align -Wwrite-strings -Wformat-security | ||
-Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-deprecated -std=gnu99 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I think the proper way to do this is to define
S2N_COMMON_WARNINGS
And then if S2N_WERROR_ALL
is set then you would just make the compile options on libs2n
public, ensuring that all of the associated items (test utility library, fuzz tests, unit tests) all just get them by default. I'll open an issue for it.
Description of changes:
I was reading through out CMakeLists.txt and noticed a number of odd/unused configurations. This PR removes them.
jk, GCC 4 strikes againWno-missing-braces
is not needed for libs2nget_filename_component
-fPIC
compile option on tests, since it is already specified as a public option on libs2n_POSIX_C_SOURCE=200809L
using the dedicatedtarget_compile_definition
syntax-fsanitize=fuzzer -lstdc++
using the dedicatedtarget_link_options
syntaxtarget_include_directories(${TEST_NAME} PRIVATE ./)
allocator_overrides
Call-outs:
Allocator Overrides
allocator_overrides
is never used when tests are run through CMake. Original motivation for the test can be found in these PRsFrom the above PRs, the goal with the allocator overrides was the help catch places that we were using uninitialized variables. My current take is the
-Wuninitialized
(which we currently use) and clang-static-analyze (which we don't) are more robust ways of catching these errors. As such, I would vote for fully removing the allocator overrides ones we have deprecated the make builds.Section Headers
I know that my big section header comments might be polarizing, but the motivation was as follows
That's why I think the very hefty section headers are justified. A single comment is just going to get lost in the wash of monocolored text.
Compile Options: Individual Lines
The compile options were getting very difficult to read. Additionally, having them on a single line makes the git blame much more useful.
Testing:
All CI should pass
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.