Skip to content

compat.c-ares: CARES_STATICLIB reaches the consumer (gRPC's Windows startup crash) - #856

Merged
Sunrisepeak merged 2 commits into
mainfrom
fix/c-ares-staticlib-consumers
Nov 20, 2026
Merged

Sunrisepeak merged 2 commits into
mainfrom
fix/c-ares-staticlib-consumers

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

compat.c-ares: CARES_STATICLIB reaches the consumer. Root cause of grpc-m's Windows startup crash ("exit 133").

Only the package's own translation units were compiled with CARES_STATICLIB; a consumer's <ares.h> declared every entry point __declspec(dllimport), so gRPC called the static library through an __imp_ slot lld-link fills locally (LNK4217). Under /OPT:REF — lld-link's default without /DEBUG — that slot does not keep its definition alive: when the object was pulled in only by code that is later discarded, the definition is dropped and the slot holds the image base. grpc_init → AresInit → ares_library_init jumped to the PE header (0xC0000005, execute at MZ).

Evidence (mcpplibs/grpc-m#10, diagnostic draft):

  • relinking only: /opt:noref or -g pass, /opt:ref fails, /opt:noicf still fails;
  • cdb with symbols: the fault at AresInit+0x46 (ares_resolver.cc:960), target = image base;
  • a 4-line C reproduction with llvm 23.1.3's lld-link (__imp_foo = 0x140000000 under /opt:ref).

Fix: upstream propagates the define (Bazel defines, CMake's INTERFACE definition); here a feature's defines reach consumers and default implies it unconditionally — compat.curl's CURL_STATICLIB pattern. Verified: gRPC's module test passes on windows-2025 with default link flags, on a home that already had the old compat.c-ares installed (so no packaging revision is needed); a Linux consumer sees the define.

Not in this PR: gRPC code generation on Windows (compat.protobuf's protoc host tool) is a separate open issue; grpc-m will claim Windows only with it or with codegen explicitly excluded.

@Sunrisepeak
Sunrisepeak merged commit 020f22e into main Nov 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant