-
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
Fix VS2022 build error #7502
Fix VS2022 build error #7502
Conversation
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
library/bignum_core.h
Outdated
@@ -109,7 +109,38 @@ | |||
* \return The number of leading zero bits in \p a, if \p a != 0. | |||
* If \p a == 0, the result is undefined. | |||
*/ | |||
size_t mbedtls_mpi_core_clz(mbedtls_mpi_uint a); | |||
static inline size_t mbedtls_mpi_core_clz(mbedtls_mpi_uint a) |
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.
It's weird that arranging to have two copies of the function (since it's used in two different C files) makes the code smaller. How is this happening? Is this maybe only on platforms that have a CLZ instruction — what's the impact on platforms that don't?
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.
Without clz
there’s still a 16-byte saving in bignum_core.o
, it's just that it is 20 bytes bigger without clz
in both development
and this PR (code size goes from 2446 to 2466 without clz
)
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.
Ah - the clz function is only used in bignum.o
if we don't have MBEDTLS_HAVE_UDBL
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 suspect a clz instruction is near-universal. E.g., Arm has had it since Armv5. So this function will almost always turn into a single instruction.
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.
It seems to get inlined regardless of marking it static inline
(at least on my machine where the clz
instruction is present). So the effect of the static inline
is really just to eliminate the not-inlined copy of the function, which is small and presumably eliminated during the final link stage. Do we want to simplify and drop the inlining?
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.
static
in a header gives you a copy of the function in every module that includes the header. Most compilers are smart enough to eliminate the function if the module doesn't use it at all, but that still leaves two copies in the two modules that do use this particular function (and possibly more later). So no, we shouldn't have static
functions in a header.
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.
Err, actually static
restricts visibility. If nothing needs an actual not-inlined function, the compiler is free to not include it, and I would expect most modern compilers will do this. An out-of-line function implementation is usually only needed if the address of the function is taken at some point
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.
Sorry, I meant: should we return it to bignum_core.c, as a non-inline, non-static function, and retain a declaration only in the header?
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.
This PR saved bytes over the code in development. I think it is okay
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 return it to bignum_core.c, as a non-inline, non-static function, and retain a declaration only in the header?
Yes, we should do the simple thing (declare in header, define in .c) unless there's a compelling reason to do otherwise. And it seems that there's no compelling reason after all.
I'd like the know why the CI didn't catch this problem. Is it just Visual Studio 2022? In which case, we really need to update the compiler versions we use... |
@@ -33,39 +33,6 @@ | |||
#include "bn_mul.h" | |||
#include "constant_time_internal.h" | |||
|
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.
What could we put in our CI to ensure that if someone tries this again, the CI will complain?
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.
Yes, I'd like to know that too!
Hmm, seen in the CI logs this morning
|
I remember we have a discrepancy in the set of Windows tests we run in nightlies vs in pull requests: PR jobs only test with VS2013, but nightlies also test VS2015 and VS2017. To my recollection this is the first time the VS2013 job passes but not the more recent versions (which is why we didn't really care about the discrepancy until now). |
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
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.
This needs to go in to fix the nightlies
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.
Keeping things simple, I like it.
Description
Fixes #7501 .
Gatekeeper checklist