Remove SECP256K1_GNUC_PREREQ? #1868

issue real-or-random opened this issue on June 10, 2026
  1. real-or-random commented at 11:27 AM on June 10, 2026: contributor

    We have a SECP256K1_GNUC_PREREQ macro (defined in terms of __GNUC__ and __GNUC_MINOR__ for checking gcc versions):

    https://github.com/bitcoin-core/secp256k1/blob/0f4a7e6bf9d971addb2b851df7cd2777fc62b212/include/secp256k1.h#L104-L111

    Current usage in the codebase:

     ❯ git grep _GNUC_
    examples/examples_util.h:#elif defined(__GNUC__)
    include/secp256k1.h:# if !defined(SECP256K1_GNUC_PREREQ)
    include/secp256k1.h:#  if defined(__GNUC__)&&defined(__GNUC_MINOR__)
    include/secp256k1.h:#   define SECP256K1_GNUC_PREREQ(_maj,_min) \
    include/secp256k1.h: ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
    include/secp256k1.h:#   define SECP256K1_GNUC_PREREQ(_maj,_min) 0
    include/secp256k1.h:#        elif !defined(_WIN32) && defined (__GNUC__) && (__GNUC__ >= 4)
    include/secp256k1.h:# if defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
    include/secp256k1.h:# if !defined(SECP256K1_BUILD) && defined(__GNUC__) && SECP256K1_GNUC_PREREQ(3, 4)
    src/checkmem.h:#  elif defined(__GNUC__) && (__GNUC__ >= 15)
    src/checkmem.h:#  elif defined(__GNUC__) && (__GNUC__ >= 15)
    src/int128_native.h:SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t;
    src/int128_native.h:SECP256K1_GNUC_EXT typedef __int128 int128_t;
    src/util.h:#  if SECP256K1_GNUC_PREREQ(2,7)
    src/util.h:#if SECP256K1_GNUC_PREREQ(3, 0)
    src/util.h:#  if SECP256K1_GNUC_PREREQ(3,0)
    src/util.h:#if defined(__GNUC__)
    src/util.h:# define SECP256K1_GNUC_EXT __extension__
    src/util.h:# define SECP256K1_GNUC_EXT
    src/util.h:#elif defined(__GNUC__)
    src/util.h:#if (__has_builtin(__builtin_ctz) || SECP256K1_GNUC_PREREQ(3,4))
    src/util.h:#if (__has_builtin(__builtin_ctzl) || SECP256K1_GNUC_PREREQ(3,4))
    src/util.h:#if (__has_builtin(__builtin_ctzl) || SECP256K1_GNUC_PREREQ(3,4))
    src/util.h:#if (__has_builtin(__builtin_ctzll) || SECP256K1_GNUC_PREREQ(3,4))
    src/util_local_visibility.h:#if !defined(_WIN32) && defined(__GNUC__) && (__GNUC__ >= 4)
    
    • It's currently used only for ancient GCC versions (see above). The only check against a contemporary GCC version is in checkmem.h but here we don't even use the macro. (#1865 would add a (4, 2) check but I consider this also ancient). If you have an ancient compiler, it's reasonable to except that you're on your own.
    • Contributors apparently don't remember its existence (see the checkmem.h case, and also util_local_visibility.h and even secp256k1.h itself).
    • It's misleading because __GNUC__ is defined also in Clang. Clang sets __GNUC__ to 4 and __GNUC_MINOR__ to 2 (mimicking GCC 4.2) by default for compatibility, regardless of the actual Clang version. Modern Clang (8+) supports -fgnuc-version=major.minor.patch to override these values, but that's of no use to us.

    I suggest removing the macro and just checking defined(__GNUC__) instead (when it comes to ancient versions), or something like (__GNUC__) && (__GNUC__ >= 15), or __has_builtin when appropriate (introduced in GCC 10).

  2. real-or-random added the label tweak/refactor on Jun 10, 2026
  3. real-or-random added the label meta/development on Jun 10, 2026
  4. hebasto commented at 4:30 PM on June 10, 2026: member

    I agree with all three points mentioned above.

    Wasn't __inline__ available even earlier than GCC 2.7: https://github.com/bitcoin-core/secp256k1/blob/0f4a7e6bf9d971addb2b851df7cd2777fc62b212/src/util.h#L49-L50 ?

    I suggest removing the macro and just checking defined(__GNUC__) instead (when it comes to ancient versions), or something like (__GNUC__) && (__GNUC__ >= 15), or __has_builtin when appropriate (introduced in GCC 10).

    I wonder whether this would allow dropping this line:https://github.com/bitcoin-core/secp256k1/blob/0f4a7e6bf9d971addb2b851df7cd2777fc62b212/src/util.h#L10 ?

  5. real-or-random commented at 2:35 PM on June 11, 2026: contributor

    Wasn't __inline__ available even earlier than GCC 2.7:

    I could imagine that, whoever wrote this code, didn't look for earlier versions than 2.7. (On godbolt, they have a gcc 1.27 but no 2.xx versions :D).

    I wonder whether this would allow dropping this line:

    I don't know but this would be nice.

  6. real-or-random assigned Copilot on Jun 12, 2026
  7. real-or-random assigned real-or-random on Jun 12, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-06-12 09:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me