Skip to content

Commit 020f22e

Browse files
authored
compat.c-ares: CARES_STATICLIB reaches the consumer (gRPC's Windows startup crash) (#856)
* compat.c-ares: CARES_STATICLIB reaches the consumer (Windows: a dllimport slot lld-link discards under /OPT:REF) * CHANGELOG: compat.c-ares passes CARES_STATICLIB to its consumers
1 parent bd276ab commit 020f22e

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174

175175
### Fixed
176176

177+
- **compat.c-ares:`CARES_STATICLIB` 传给使用方(Windows 上 gRPC 启动即崩溃的根因)。** 此前只有包自身以该宏编译,使用方看到的 `<ares.h>` 把每个入口声明为 `__declspec(dllimport)`,经 lld-link 本地补全的 `__imp_` 槽调用静态库(LNK4217)。lld-link 在不带 `/DEBUG` 时默认 `/OPT:REF`,该槽不保住它的定义:定义所在目标文件只因随后被丢弃的代码而载入时,定义被丢弃、槽内为映像基址。gRPC 的 `ares_library_init` 正是如此,`grpc_init` 跳到 PE 头(0xC0000005,mcpp 报 exit 133);四行 C 即可复现(llvm 23.1.3)。上游的 Bazel(`defines`)与 CMake(INTERFACE 定义)都把该宏传给依赖方;此处按 compat.curl 的写法以 `default` 隐含的 feature `defines` 传递。在装有旧 compat.c-ares 的 home 上实测生效,无需 packaging revision;gRPC 的模块测试在 Windows 默认链接参数下通过(grpc-m#10)。
177178
- **mcpp.plugins 0.23.1。** `dist-apk` 把构建程序在输出目录(`mcpp::out_dir()`、`target/`)中生成的 Java 或 Kotlin 根只作为
178179
`javac` 动作的输入,不再为其声明永远无法命中的重跑 glob,消除每次构建的警告。`latest` 指向 0.23.1
179180
(mcpp-community/mcpp-plugins#57)。

‎pkgs/c/compat.c-ares.lua‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ package = {
7676
-- fail with implicit-declaration errors.
7777
cflags = { "-DCARES_STATICLIB", "-DHAVE_CONFIG_H", "-D_GNU_SOURCE", "-D_HAS_EXCEPTIONS=0" },
7878

79+
-- CARES_STATICLIB IS THE CONSUMER'S TOO. Without it <ares.h> declares
80+
-- every entry point __declspec(dllimport) on Windows, and a consumer
81+
-- calls this static library through an `__imp_` slot that lld-link
82+
-- fills locally (LNK4217). Under /OPT:REF, lld's default without
83+
-- /DEBUG, that slot does not keep its definition alive: when the
84+
-- object was pulled in only by code that is later discarded, the
85+
-- definition goes and the slot holds the image base. gRPC's
86+
-- `ares_library_init` was exactly that, and grpc_init jumped to the
87+
-- PE header (0xC0000005). Upstream propagates the define to
88+
-- dependents (cares.BUILD `defines`, CMake's INTERFACE definition);
89+
-- here a feature's `defines` reach the consumer and `default`
90+
-- implies it unconditionally, as compat.curl does for CURL_STATICLIB.
91+
features = {
92+
["default"] = { implies = { "staticlib" } },
93+
["staticlib"] = { defines = { "CARES_STATICLIB" } },
94+
},
95+
7996
-- ONE SNAPSHOT PER C ENVIRONMENT, AND THE PREPROCESSOR PICKS.
8097
--
8198
-- These are gRPC 1.83.0's three frozen `ares_config.h` files, verbatim,

0 commit comments

Comments
 (0)