Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion secp256k1-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

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.

Copy link
Member Author

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_supported also not universal. But cc makes 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 :).

Copy link
Collaborator

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)x works IIRC which can be used in the define. But I don't know how to apply it to multiple arguments.

.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(""));
Copy link
Member

@tcharding tcharding Nov 2, 2023

Choose a reason for hiding this comment

The 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" {

Copy link
Member

Choose a reason for hiding this comment

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

Also the -Wno-unused-paramater

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

Copy link
Member

Choose a reason for hiding this comment

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

Because there is a bug in cc::Build::flag_if_supported so we are getting loads of warnings. Well on my machine anyways.

Copy link
Member

Choose a reason for hiding this comment

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

Why?

Did you mean why do I think we should put the .define on the wasm-only cc::Build or why the "Also the -Wno-unused-parameter? Ignore the second one, and for the first, I thought this because the code comment specifically mentions that this is a wasm problem so it seems logical to put it in the wasm-only place.

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Expand Down
12 changes: 4 additions & 8 deletions secp256k1-sys/depend/secp256k1/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe delete it completely to ensure it's not called by accident?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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__)
Expand Down
14 changes: 9 additions & 5 deletions secp256k1-sys/depend/util.h.patch
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;