You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译glibc 2.24出现__EI___errno_location属性限制报错如何解决

问题原因

这个错误出现在使用GCC 7及以上版本编译glibc 2.24的场景:高版本GCC新增了-Wmissing-attributes检查项,而glibc 2.24发布时还没有适配该检查,加上glibc默认开启-Werror将所有警告转为错误,最终触发编译失败。

你之前的补丁不生效主要有两个原因:

  • 补丁中使用的是HTML转义后的",实际写入文件需要替换为英文双引号,否则GCC无法识别诊断指令
  • 诊断指令的作用范围没有完全覆盖宏展开后的声明逻辑,部分触发警告的代码仍然在检查范围内

解决方法

优先选择无需修改源码的方案,按优先级从高到低排序:

方案1:编译配置时禁用Werror

glibc官方提供了关闭警告转错误的编译参数,配置时直接添加即可:

# 请在单独的构建目录下执行configure,不要在源码根目录编译
../configure 你的原有配置参数 --disable-werror

该方案不会屏蔽警告本身,只是不会将警告转为错误中断编译,适配性最好。

方案2:编译配置时指定忽略指定警告

如果不想全局关闭Werror,可以单独把missing-attributes警告排除在错误范围外:

../configure 你的原有配置参数 CFLAGS="-O2 -g -Wno-error=missing-attributes"

方案3:修正你的补丁

如果必须通过修改头文件解决,将补丁中的转义字符替换为实际符号即可,修正后的补丁如下:

diff -Naur glibc_orig/include/libc-symbols.h glibc/include/libc-symbols.h
--- glibc_orig/include/libc-symbols.h   2021-08-26 10:16:34.327141852 +0300
+++ glibc/include/libc-symbols.h    2021-08-26 12:08:13.654205932 +0300
@@ -388,6 +388,7 @@
    versioned_symbol (libc, __real_foo, foo, GLIBC_2_1);
    libc_hidden_ver (__real_foo, foo)  */
 
+
 #if defined SHARED && !defined NO_HIDDEN
 # ifndef __ASSEMBLER__
 #  define __hidden_proto_hiddenattr(attrs...) \
@@ -403,6 +404,10 @@
   __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
 #  define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
 #  define __hidden_asmname2(prefix, name) #prefix name
+
+   #pragma GCC diagnostic push
+   #pragma GCC diagnostic ignored "-Wmissing-attributes"
+
 #  define __hidden_ver1(local, internal, name) \
   extern __typeof (name) __EI_##name __asm__(__hidden_asmname (#internal)); \
   extern __typeof (name) __EI_##name \
@@ -759,5 +764,6 @@
 #else
 # define inhibit_loop_to_libcall
 #endif
+#pragma GCC diagnostic pop
 
 #endif /* libc-symbols.h */

修改后需要完全清理之前的编译缓存,再重新执行配置和编译流程。


内容的提问来源于stack exchange,提问作者Ivan Ivanovich

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 08:15:04