Skip to content

Support GCC14 #1150

Closed
Closed
@AlejandroCabeza

Description

Description

Compiling the test binary with gcc14 doesn't work because there's a type issue.

Context

Nim doesn't do C const pointers, and now gcc cares because the BearSSL library (properly, correctly) declares its argument to be a const pointer
Nim compiles through C, so this does matter
addr (of some var Foo) becomes Foo** not const Foo**
and BearSSL wants const Foo**
-- @tersec

see https://github.com/status-im/nim-bearssl/pull/58/files and https://github.com/status-im/nim-bearssl/pull/61/files for how part was already fixed.

There's already a PrngClassPointerConst* {.importc: "const br_prng_class**", header: "bearssl_rand.h", bycopy.} = pointer which is defined manually and then
proc ecKeygen*(rngCtx: PrngClassPointerConst; impl: ptr EcImpl; sk: ptr EcPrivateKey;

is defined in those terms
that's for another keygen. And, yeah, it's arguably a nim-bearssl issue still, just not one anyone else has run across yet
the gimmick here is that it steps outside the Nim type system proper and simply inserts the C const Foo** directly
-- @tersec

Logs

When calling nimble --mm:refc test

~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c: In function ‘random__testrsa_u138’:
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c:1703:31: error: passing argument 1 of ‘keygen’ from incompatible pointer type [-Wincompatible-pointer-types]
 1703 |                 T7_ = keygen(((br_prng_class**) (&(*rng_p1).vtable)), ((br_rsa_private_key*) ((&(*res).seck))), ((void*) ((&(*res).buffer->data[sko]))), ((br_rsa_public_key*) ((&(*res).pubk))), ((void*) ((&(*res).buffer->data[pko]))), ((unsigned int) (bits_p2)), pubexp_p3);
      |                              ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               br_prng_class ** {aka struct br_prng_class_ **}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c:1703:31: note: expected ‘const br_prng_class **’ {aka ‘const struct br_prng_class_ **’} but argument is of type ‘br_prng_class **’ {aka ‘struct br_prng_class_ **’}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c: In function ‘sign__testrsa_u2751’:
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c:4270:37: error: passing argument 1 of ‘kv->init’ from incompatible pointer type [-Wincompatible-pointer-types]
 4270 |         nimln_(757);    (*kv).init(((br_hash_class**) (&hc.vtable)));
      |                                    ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                     |
      |                                     br_hash_class ** {aka struct br_hash_class_ **}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c:4270:37: note: expected ‘const br_hash_class **’ {aka ‘const struct br_hash_class_ **’} but argument is of type ‘br_hash_class **’ {aka ‘struct br_hash_class_ **’}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c:4274:31: error: passing argument 1 of ‘kv->update’ from incompatible pointer type [-Wincompatible-pointer-types]
 4274 |                 (*kv).update(((br_hash_class**) (&hc.vtable)), ((void*) ((&message_p1[((NI)0)]))), ((NU) (message_p1Len_0)));
      |                              ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               br_hash_class ** {aka struct br_hash_class_ **}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c:4274:31: note: expected ‘const br_hash_class **’ {aka ‘const struct br_hash_class_ **’} but argument is of type ‘br_hash_class **’ {aka ‘struct br_hash_class_ **’}
compilation terminated due to -fmax-errors=3.
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@secnist.nim.c: In function ‘sign__testecnist_u2611’:
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@secnist.nim.c:2967:53: error: passing argument 1 of ‘kv->init’ from incompatible pointer type [-Wincompatible-pointer-types]
 2967 |                 nimln_(943);            (*kv).init(((br_hash_class**) (&hc.vtable)));
      |                                                    ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                     |
      |                                                     br_hash_class ** {aka struct br_hash_class_ **}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@secnist.nim.c:2967:53: note: expected ‘const br_hash_class **’ {aka ‘const struct br_hash_class_ **’} but argument is of type ‘br_hash_class **’ {aka ‘struct br_hash_class_ **’}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@secnist.nim.c:2971:39: error: passing argument 1 of ‘kv->update’ from incompatible pointer type [-Wincompatible-pointer-types]
 2971 |                         (*kv).update(((br_hash_class**) (&hc.vtable)), ((void*) ((&message_p1[((NI)0)]))), ((NU) (message_p1Len_0)));
      |                                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                       |
      |                                       br_hash_class ** {aka struct br_hash_class_ **}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@secnist.nim.c:2971:39: note: expected ‘const br_hash_class **’ {aka ‘const struct br_hash_class_ **’} but argument is of type ‘br_hash_class **’ {aka ‘struct br_hash_class_ **’}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@secnist.nim.c:2976:71: error: passing argument 1 of ‘kv->update’ from incompatible pointer type [-Wincompatible-pointer-types]
 2976 |                         nimln_(947);                    (*kv).update(((br_hash_class**) (&hc.vtable)), NIM_NIL, ((NU)0));
      |                                                                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                       |
      |                                                                       br_hash_class ** {aka struct br_hash_class_ **}
~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@secnist.nim.c:2976:71: note: expected ‘const br_hash_class **’ {aka ‘const struct br_hash_class_ **’} but argument is of type ‘br_hash_class **’ {aka ‘struct br_hash_class_ **’}
compilation terminated due to -fmax-errors=3.
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3 -pthread -I~/.nimble/pkgs2/bearssl-0.2.4-f350e073a33be84afd879416279a4679c227c6d4/bearssl/abi -I~/.nimble/pkgs2/bearssl-0.2.4-f350e073a33be84afd879416279a4679c227c6d4/bearssl/abi/../csources/src/ -I~/.nimble/pkgs2/bearssl-0.2.4-f350e073a33be84afd879416279a4679c227c6d4/bearssl/abi/../csources/inc/ -I~/.nimble/pkgs2/bearssl-0.2.4-f350e073a33be84afd879416279a4679c227c6d4/bearssl/abi/../csources/tools/ -DBR_USE_UNIX_TIME=1 -DBR_USE_URANDOM=1 -DBR_LE_UNALIGNED=1 -DBR_64=1  -DBR_amd64=1 -DBR_INT128=1 -O3 -fno-strict-aliasing -fno-ident -fno-math-errno   -I~/.choosenim/toolchains/nim-2.0.8/lib -I~/Projects/nim-libp2p-2/tests -o ~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c.o ~/.cache/nim/testnative_d/@m..@slibp2p@scrypto@srsa.nim.c' failed with exit code: 1


stack trace: (most recent call last)
/tmp/nimblecache-1634003104/nimscriptapi_1746015816.nim(212, 16)
~/Projects/nim-libp2p-2/libp2p.nimble(53, 10) testnativeTask
~/Projects/nim-libp2p-2/libp2p.nimble(36, 3) runTest
~/.choosenim/toolchains/nim-2.0.8/lib/system/nimscript.nim(265, 7) exec
~/.choosenim/toolchains/nim-2.0.8/lib/system/nimscript.nim(265, 7) Error: unhandled exception: FAILED: nim c -d:debug  --styleCheck:usages --styleCheck:error --verbosity:0 --hints:off --skipParentCfg --skipUserCfg -f --threads:on --opt:speed  -d:libp2p_pubsub_sign=true -d:libp2p_pubsub_verify=true   -r  tests/testnative [OSError]
       Tip: 223 messages have been suppressed, use --verbose to show them.
nimscriptwrapper.nim(161) execScript

    Error:  Exception raised during nimble script execution
stack trace: (most recent call last)
/tmp/nimblecache-1634003104/nimscriptapi_1746015816.nim(212, 16)
~/Projects/nim-libp2p-2/libp2p.nimble(95, 3) testTask
~/.choosenim/toolchains/nim-2.0.8/lib/system/nimscript.nim(265, 7) exec
~/.choosenim/toolchains/nim-2.0.8/lib/system/nimscript.nim(265, 7) Error: unhandled exception: FAILED: nimble testnative [OSError]
       Tip: 223 messages have been suppressed, use --verbose to show them.
nimscriptwrapper.nim(161) execScript

    Error:  Exception raised during nimble script execution

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status

      done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions