[HACL] The `HACL_CAN_COMPILE_VEC128` macro is not defined when building Python with `-Wundef`

未關閉 適合新手
#162,219 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@tamaki0575-cloud 已經在處理了。

開始於 2026年11月21日。

  • #162393 來自 @tamaki0575-cloud —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
64/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
c, python
領域
build-system

研究方向

警告來自 #if HACL_CAN_COMPILE_VEC128 / ..._VEC256,它們位於 Modules/_hacl/Hacl_Streaming_HMAC.c 中(約 18 處),而 Modules/blake2module.c 和 Modules/hmacmodule.c 展示了巨集通常如何從 _Py_HACL_CAN_COMPILE_VEC* 轉發。首先確定修復位置:保護每個 #if(位於 .c 檔案中),或在 Modules/_hacl/internal/Hacl_Streaming_HMAC.h 中定義這些巨集——編輯前檢查 _hacl 原始碼是如何 vendored/重新產生的,因為產生的檔案可能被覆寫。用 -Wundef 重新建置(見 gh-162214),並確認 Hacl_Streaming_HMAC 的警告已消失;完成意味著一次乾淨的建置,而不只是靜默的建置。

由索引模型根據 Issue 內容生成。

描述

build extension-modules topic-C-API type-bug

The HACL_CAN_COMPILE_VEC128 and HACL_CAN_COMPILE_VEC256 macros are not defined when building Python with -Wundef. See issue gh-162214 for -Wundef flag.

Build logs:

gcc -Wno-unused-variable -c -I./Modules/_hacl -I./Modules/_hacl/include -D_BSD_SOURCE -D_DEFAULT_SOURCE -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer  -fno-strict-overflow -Wsign-compare -g -Og -Wall -Wundef    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -fPIC -o Modules/_hacl/Hacl_Streaming_HMAC.o ./Modules/_hacl/Hacl_Streaming_HMAC.c
./Modules/_hacl/Hacl_Streaming_HMAC.c: In function 'malloc_':
./Modules/_hacl/Hacl_Streaming_HMAC.c:477:13: warning: 'HACL_CAN_COMPILE_VEC128' is not defined, evaluates to '0' [-Wundef]
  477 |         #if HACL_CAN_COMPILE_VEC128
      |             ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c:540:13: warning: 'HACL_CAN_COMPILE_VEC256' is not defined, evaluates to '0' [-Wundef]
  540 |         #if HACL_CAN_COMPILE_VEC256
      |             ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c: In function 'init':
./Modules/_hacl/Hacl_Streaming_HMAC.c:654:9: warning: 'HACL_CAN_COMPILE_VEC128' is not defined, evaluates to '0' [-Wundef]
  654 |     #if HACL_CAN_COMPILE_VEC128
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c:671:9: warning: 'HACL_CAN_COMPILE_VEC256' is not defined, evaluates to '0' [-Wundef]
  671 |     #if HACL_CAN_COMPILE_VEC256
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c: In function 'update_multi':
./Modules/_hacl/Hacl_Streaming_HMAC.c:771:9: warning: 'HACL_CAN_COMPILE_VEC128' is not defined, evaluates to '0' [-Wundef]
  771 |     #if HACL_CAN_COMPILE_VEC128
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c:796:9: warning: 'HACL_CAN_COMPILE_VEC256' is not defined, evaluates to '0' [-Wundef]
  796 |     #if HACL_CAN_COMPILE_VEC256
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c: In function 'update_last':
./Modules/_hacl/Hacl_Streaming_HMAC.c:897:9: warning: 'HACL_CAN_COMPILE_VEC128' is not defined, evaluates to '0' [-Wundef]
  897 |     #if HACL_CAN_COMPILE_VEC128
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c:921:9: warning: 'HACL_CAN_COMPILE_VEC256' is not defined, evaluates to '0' [-Wundef]
  921 |     #if HACL_CAN_COMPILE_VEC256
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c: In function 'finish':
./Modules/_hacl/Hacl_Streaming_HMAC.c:1043:9: warning: 'HACL_CAN_COMPILE_VEC128' is not defined, evaluates to '0' [-Wundef]
 1043 |     #if HACL_CAN_COMPILE_VEC128
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c:1060:9: warning: 'HACL_CAN_COMPILE_VEC256' is not defined, evaluates to '0' [-Wundef]
 1060 |     #if HACL_CAN_COMPILE_VEC256
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c: In function 'copy':
./Modules/_hacl/Hacl_Streaming_HMAC.c:1342:9: warning: 'HACL_CAN_COMPILE_VEC128' is not defined, evaluates to '0' [-Wundef]
 1342 |     #if HACL_CAN_COMPILE_VEC128
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c:1381:9: warning: 'HACL_CAN_COMPILE_VEC256' is not defined, evaluates to '0' [-Wundef]
 1381 |     #if HACL_CAN_COMPILE_VEC256
      |         ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c: In function 'hash':
./Modules/_hacl/Hacl_Streaming_HMAC.c:1468:13: warning: 'HACL_CAN_COMPILE_VEC128' is not defined, evaluates to '0' [-Wundef]
 1468 |         #if HACL_CAN_COMPILE_VEC128
      |             ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c:1480:13: warning: 'HACL_CAN_COMPILE_VEC256' is not defined, evaluates to '0' [-Wundef]
 1480 |         #if HACL_CAN_COMPILE_VEC256
      |             ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c: In function '_Py_LibHacl_Hacl_Streaming_HMAC_malloc_':
./Modules/_hacl/Hacl_Streaming_HMAC.c:1971:8: warning: 'HACL_CAN_COMPILE_VEC256' is not defined, evaluates to '0' [-Wundef]
 1971 |   #if !HACL_CAN_COMPILE_VEC256
      |        ^~~~~~~~~~~~~~~~~~~~~~~
./Modules/_hacl/Hacl_Streaming_HMAC.c:1977:8: warning: 'HACL_CAN_COMPILE_VEC128' is not defined, evaluates to '0' [-Wundef]
 1977 |   #if !HACL_CAN_COMPILE_VEC128
      |        ^~~~~~~~~~~~~~~~~~~~~~~

One solution would be to replace #if HACL_CAN_COMPILE_VEC128 with #if defined(HACL_CAN_COMPILE_VEC128) && HACL_CAN_COMPILE_VEC128 (and same change for the 256 macro) in Modules/_hacl/Hacl_Streaming_HMAC.c.

Modules/blake2module.c and Modules/hmacmodule.c define the two macros. Example:

#if defined(__APPLE__) && defined(__arm64__)
#  undef _Py_HACL_CAN_COMPILE_VEC128
#  undef _Py_HACL_CAN_COMPILE_VEC256
#endif

// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable
// the corresponding SIMD instructions so we need to "forward" the values
// we just deduced above.
#define HACL_CAN_COMPILE_VEC128 _Py_HACL_CAN_COMPILE_VEC128
#define HACL_CAN_COMPILE_VEC256 _Py_HACL_CAN_COMPILE_VEC256

But Modules/_hacl/internal/Hacl_Streaming_HMAC.h doesn't set these macros.

主要語言
Python
星號
78.4k
分支
36.6k
平均合併
23 小時 34 分鐘
30 天內合併 PR
610

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。