-
Notifications
You must be signed in to change notification settings - Fork 306
Patch out any instances of printf in upstream #663
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,11 +20,16 @@ fn main() { | |
| .include("depend/secp256k1/include") | ||
| .include("depend/secp256k1/src") | ||
| .flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream | ||
| .flag_if_supported("-Wno-unused-parameter") // patching out printf causes this warning | ||
| .define("SECP256K1_API", Some("")) | ||
| .define("ENABLE_MODULE_ECDH", Some("1")) | ||
| .define("ENABLE_MODULE_SCHNORRSIG", Some("1")) | ||
| .define("ENABLE_MODULE_EXTRAKEYS", Some("1")) | ||
| .define("ENABLE_MODULE_ELLSWIFT", Some("1")); | ||
| .define("ENABLE_MODULE_ELLSWIFT", Some("1")) | ||
| // upstream sometimes introduces calls to printf, which we cannot compile | ||
| // with WASM due to its lack of libc. printf is never necessary and we can | ||
| // just #define it away. | ||
| .define("printf(...)", Some("")); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should only use this if the target is wasm ie., put it in: // WASM headers and size/align defines.
if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "wasm32" {
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there is a bug in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Did you mean why do I think we should put the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's wasm-only. It would be any linker that tries to resolve libc symbols before pruning unused code. |
||
|
|
||
| if cfg!(feature = "lowmemory") { | ||
| base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume negligible memory | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,7 @@ | |
| #define SECP256K1_UTIL_H | ||
|
|
||
| #include "../include/secp256k1.h" | ||
| extern int rustsecp256k1_v0_9_0_ecdsa_signature_parse_compact( | ||
| const rustsecp256k1_v0_9_0_context *ctx, | ||
| rustsecp256k1_v0_9_0_ecdsa_signature *sig, const unsigned char *input64); | ||
|
|
||
| #include <stdlib.h> | ||
| #include <stdint.h> | ||
| #include <stdio.h> | ||
|
|
@@ -147,11 +145,9 @@ static const rustsecp256k1_v0_9_0_callback default_error_callback = { | |
| #endif | ||
|
|
||
| static SECP256K1_INLINE void *checked_malloc(const rustsecp256k1_v0_9_0_callback* cb, size_t size) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe delete it completely to ensure it's not called by accident?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I would need to delete all the functions that call it, and so on, which is much more invasive.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sucks. Also I wonder how does it interact with the system library. Will anything break if it has different code?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. It's not an exposed function, it's only used internally. |
||
| void *ret = malloc(size); | ||
| if (ret == NULL) { | ||
| rustsecp256k1_v0_9_0_callback_call(cb, "Out of memory"); | ||
| } | ||
| return ret; | ||
| (void) cb; | ||
| (void) size; | ||
| return NULL; | ||
| } | ||
|
|
||
| #if defined(__BIGGEST_ALIGNMENT__) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| 10c10,12 | ||
| < | ||
| 148,152c148,150 | ||
| < void *ret = malloc(size); | ||
| < if (ret == NULL) { | ||
| < secp256k1_callback_call(cb, "Out of memory"); | ||
| < } | ||
| < return ret; | ||
| --- | ||
| > extern int secp256k1_ecdsa_signature_parse_compact( | ||
| > const secp256k1_context *ctx, | ||
| > secp256k1_ecdsa_signature *sig, const unsigned char *input64); | ||
| > (void) cb; | ||
| > (void) size; | ||
| > return NULL; |
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 think this can be solved more locally but I haven't used C for a while so I don't remember how.
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.
There's no standard C way to do it. Any specific compiler would have annotations but they wouldn't work for others. (Of course,
flag_if_supportedalso not universal. Butccmakes an effort to translate it for the common compilers.)And in any case, if I wanted a more local solution, I'd just patch out the offending methods entirely :).
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 mean something like using
(void)xworks IIRC which can be used in the define. But I don't know how to apply it to multiple arguments.