-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Include common.h from all library source files #3454
Include common.h from all library source files #3454
Conversation
d54ea42
to
ceb8327
Compare
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.
LGTM
When compiling library files under `3rdparty/`, the directory containing the `.c` file that is being compiled is not the current directory, so headers from the `library/` directory are not found. Fix this by adding `.` to the include path. This was not detected until now because as of this commit, no 3rdparty source file requires a header under `library/`. Signed-off-by: Gilles Peskine <[email protected]>
In library source files, include "common.h", which takes care of including "mbedtls/config.h" (or the alternative MBEDTLS_CONFIG_FILE) and other things that are used throughout the library. FROM=$'#if !defined(MBEDTLS_CONFIG_FILE)\n#include "mbedtls/config.h"\n#else\n#include MBEDTLS_CONFIG_FILE\n#endif' perl -i -0777 -pe 's~\Q$ENV{FROM}~#include "common.h"~' library/*.c 3rdparty/*/library/*.c scripts/data_files/error.fmt scripts/data_files/version_features.fmt Signed-off-by: Gilles Peskine <[email protected]>
ceb8327
to
db09ef6
Compare
I rebased due to a merge conflict (in an automatically generated file, but that would still have prevented an automatic merge). The result is identical to merging |
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.
Re-approving after checking that the result of the rebase is indeed equivalent to a merge of development into the version I previously approved.
Because of the recent changes on CMake build system, you will probably need to do the same kind of change you've done to the make build system to the CMake build system. |
By the way I can do the change to the CMake build system if you prefer. |
All libraries (should) rely on the same directory structure. Instead of repeating the same clauses 6 times (3 libraries times 2 build modes), set the include paths, compile definitions and install instructions with a single piece of code. Include the 3rdparty directory for all libraries, not just crypto. It's currently only needed for crypto, but that's just happenstance. Signed-off-by: Gilles Peskine <[email protected]>
I'm working on the cmake change. |
"Include the library directory for the sake of 3rdparty" did the job for Make and Visual Studio. This commit does the job for CMake. Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
CMake update. @ronald-cron-arm (and CI) please let me know if that's not the right way to do 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.
I have a question not directly on this PR but related. I am wondering if it has been considered to put those library restricted headers in a dedicated folder? There are already a fair amount of files in ./library with a mix of *.c and .h files thus ordering those files a bit more would make sense to me. Furthermore if we put the header files into an ./library/internal folder for example, the pattern to include the headers could be made to be internal/.h making it explicit that this is a private/internal header file that is included.
I'm the one who introduced |
I've explained two benefits I see but I acknowledge that those are not definitive arguments. It would look better to me to see something like <internal/common.h> or <mbedtls-internal/common.h> than just <common.h>. The mbedtls private/internal nature of the header would be explicit and this would align with the mbedtls/.h, psa/.h, test/*.h ways of including headers. |
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
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.
LGTM
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.
LGTM
Include
common.h
fromlibrary/*.c
.This is a precursor to doing useful things with it, such as declaring macros related to test hooks, or things that we would have put in
platform.h
for lack of a better place. For the time being, it just contains the universal idiom for including the config file.This should not be backported because we don't add new files in LTS branches. Anything that gets added to
common.h
will need to be added or kept elsewhere in LTS branches.