Gnu: binutils: ld: .gnu.warning.链接时的主动警告 glibc

这个是一个gnu的extension,glibc会使用这个功能,标记即将被淘汰的符号,产生链接时的警告,比如:

cpp 复制代码
/* When a reference to SYMBOL is encountered, the linker will emit a
   warning message MSG.  */
/* We want the .gnu.warning.SYMBOL section to be unallocated.  */
#define __make_section_unallocated(section_string)	\
  asm (".section " section_string "\n\t.previous");
  
#define link_warning(symbol, msg) \
  __make_section_unallocated (".gnu.warning." #symbol) \
  static const char __evoke_link_warning_##symbol[]	\
    __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
    = msg;
    
link_warning (pthread_attr_setstackaddr,
              "the use of `pthread_attr_setstackaddr' is deprecated, use `pthread_attr_setstack'")

效果

cpp 复制代码
/tmp/ccVxpFwZ.o: In function `main':
warning1.c:(.text+0xe): warning: the use of `pthread_attr_setstackaddr' is deprecated, use `pthread_attr_setstack'

需要注意,如果函数和main函数是再一个编译单元,不会trigger这个warning。需要变成成单独的o/so文件,在链接时才会报错。

相关推荐
FreeBuf_3 天前
GNU Screen 曝多漏洞:本地提权与终端劫持风险浮现
安全·web安全·gnu
runing_an_min17 天前
centos升级glibc
linux·centos·glibc
lsnm17 天前
【LINUX操作系统】线程操作
linux·jvm·c++·ubuntu·centos·gnu
PLUS_WAVE22 天前
【CUDA 编译 bug】ld: cannot find -lcudart
服务器·c++·bug·环境·编译·cuda·ld
心随_风动24 天前
Debian GNU/Linux的新手入门介绍
linux·debian·gnu
木木不迷茫(˵¯͒¯͒˵)25 天前
Keil MDK‑5 中使用 GNU ARM GCC 的 -Wno-* 选项屏蔽编译警告
arm开发·gnu·keil
菜一头包1 个月前
GNU,GDB,GCC,G++是什么?与其他编译器又有什么关系?
linux·c++·学习·gnu
MobiCetus1 个月前
Linux Kernel 9
java·linux·运维·服务器·windows·ubuntu·gnu
MobiCetus1 个月前
Linux Kernel 7
linux·运维·服务器·windows·ubuntu·centos·gnu
Bl_a_ck1 个月前
【C++基础】GNU简介
开发语言·c++·gnu