randomenv: Fix MinGW dllimport warning for environ #33570

pull l0rinc wants to merge 1 commits into bitcoin:master from l0rinc:l0rinc/environ-mingw changing 1 files +1 −1
  1. l0rinc commented at 1:14 am on October 8, 2025: contributor

    Related to #33550 (comment)

    Extends 7703884 to guard environ declaration on all Windows builds, not just MSVC. llvm-mingw also defines environ as a macro that expands to a dllimport function, causing the same inconsistent linkage warning.

    Use WIN32 instead of _MSC_VER to match the platform-specific guards already used throughout the file.

    The warning occurs with llvm-mingw (both UCRT and MSVCRT variants as tested by Hebasto), but not with the mingw-w64 toolchain currently used in CI (as mentioned by fanquake).


    The error was reproduced by adding a temporary nightly build pointing to https://github.com/l0rinc/bitcoin/pull/45. On master the failure can be seen in https://github.com/l0rinc/bitcoin-core-nightly/pull/2

    before: https://github.com/l0rinc/bitcoin-core-nightly/actions/runs/18327936488/job/52196728885?pr=2

     0/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/src/randomenv.cpp:61:15: warning: '__p__environ' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [-Winconsistent-dllimport]
     1   61 | extern char** environ; // NOLINT(readability-redundant-declaration): Necessary on some platforms
     2      |               ^
     3/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/stdlib.h:656:17: note: expanded from macro 'environ'
     4  656 | #define environ _environ
     5      |                 ^
     6/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/stdlib.h:225:21: note: expanded from macro '_environ'
     7  225 | #define _environ (* __p__environ())
     8      |                     ^
     9/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/stdlib.h:221:27: note: previous declaration is here
    10  221 |   _CRTIMP char ***__cdecl __p__environ(void);
    11      |                           ^
    12/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/stdlib.h:221:3: note: previous attribute is here
    13  221 |   _CRTIMP char ***__cdecl __p__environ(void);
    14      |   ^
    15/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/_mingw.h:52:40: note: expanded from macro '_CRTIMP'
    16   52 | #      define _CRTIMP  __attribute__ ((__dllimport__))
    17      |                                        ^
    181 warning generated.
    

    after: https://github.com/l0rinc/bitcoin-core-nightly/actions/runs/18329616268/job/52201940831?pr=4

    0[ 28%] Building CXX object src/util/CMakeFiles/bitcoin_util.dir/__/randomenv.cpp.obj
    

    Note that there are some other remaining warnings in the logs that will be fixed in separate PRs

  2. randomenv: Fix MinGW dllimport warning for `environ`
    Extends 7703884a to guard environ declaration on all Windows builds, not just MSVC.
    MinGW also defines environ as a macro that expands to a dllimport function, causing the same inconsistent linkage warning.
    
    Use WIN32 instead of _MSC_VER to match the platform-specific guards already used throughout the file.
    
    Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
    97762b1fcf
  3. DrahtBot commented at 1:14 am on October 8, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33570.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hebasto

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  4. maflcko added the label DrahtBot Guix build requested on Oct 8, 2025
  5. fanquake commented at 9:05 am on October 8, 2025: member

    MinGW also defines environ … causing the same inconsistent linkage warning.

    Can you improve the PR description & commit message? We use mingw-w64 in the CI & Guix build, and it doesn’t produce this warning.

  6. hebasto commented at 11:30 am on October 8, 2025: member

    Extends 7703884 to guard environ declaration on all Windows builds, not just MSVC. MinGW also defines environ as a macro that expands to a dllimport function, causing the same inconsistent linkage warning.

    I suppose this behaviour is specific to UCRT.

    UPDATE. It is not. I tested the MSVCRT variant of the LLVM MinGW toolchain.

  7. l0rinc commented at 5:41 pm on October 8, 2025: contributor
    Thanks for the replies, I have updated the description to clarify this is llvm-mingw specific, let me know if that’s enough.
  8. DrahtBot commented at 1:29 am on October 9, 2025: contributor

    Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

    File commit b510893d00760083ac36948747aa6ebd84656192(master) commit 883c8fecd5e61b32cbcba08dff4f9f876dae3be0(pull/33570/merge)
    *-aarch64-linux-gnu-debug.tar.gz 287ee038591e1aa5... 5451ddd49d8bbb4f...
    *-aarch64-linux-gnu.tar.gz 0852b8c58d9f260d... 25bd538478f9eb41...
    *-arm-linux-gnueabihf-debug.tar.gz 476283a97a4a63bb... a7f5052cdbf7f7a1...
    *-arm-linux-gnueabihf.tar.gz 9521ef406263f7b6... 5a4451c798e27c33...
    *-arm64-apple-darwin-codesigning.tar.gz 82cb6250417e717c... 7de7cc4af586b871...
    *-arm64-apple-darwin-unsigned.tar.gz 8fc23c4c3a991331... e3d67510950c2c81...
    *-arm64-apple-darwin-unsigned.zip b392101c5b361ff9... 4be0697eeada46e2...
    *-powerpc64-linux-gnu-debug.tar.gz 9b43c0b8e25143cf... ce7c3c8574b012be...
    *-powerpc64-linux-gnu.tar.gz 2e9992ef3509b037... 6b5a20204f8083df...
    *-riscv64-linux-gnu-debug.tar.gz ecf900527a72acb0... a6ae0c793a3c2adb...
    *-riscv64-linux-gnu.tar.gz 9d408e2da915b801... fc0624b26a20a94a...
    *-x86_64-apple-darwin-codesigning.tar.gz 9bf52d02ca33fe53... 93c133a51bd98292...
    *-x86_64-apple-darwin-unsigned.tar.gz 236075db81a09bad... 6337f4e8fe8d1973...
    *-x86_64-apple-darwin-unsigned.zip 0c441dc5b75521ac... 129c615e359fe503...
    *-x86_64-linux-gnu-debug.tar.gz 6f97bc61fc54c68f... 38494443fe352c07...
    *-x86_64-linux-gnu.tar.gz 16459e49234e829e... a674ad52e9ab239b...
    *.tar.gz dd7765ebe3b225dd... 7681d1dcb1b82dc3...
    SHA256SUMS.part 63ea3df1b92207e2... 34bacbe246873834...
    guix_build.log 266ffcacd115224c... ea50795b0508ce5e...
    guix_build.log.diff 225bb976da2b3471...
  9. DrahtBot removed the label DrahtBot Guix build requested on Oct 9, 2025
  10. hebasto approved
  11. hebasto commented at 10:32 am on October 9, 2025: member
    ACK 97762b1fcf5d389b4f9c06ae46d6408fb78627b0.
  12. maflcko commented at 10:59 am on October 9, 2025: member
    Reminds me that the windows guix build is actually disabled in DrahtBot: https://github.com/maflcko/DrahtBot/blob/cd13339b9c72a12dc47931cd40e1c8872d9ac74d/guix/src/main.rs#L299, so pls ignore the result above, sry.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-10-10 21:13 UTC

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