一个编译告警可能导致的严重错误

1 /* foo5.c */
2 #include <stdio.h>
3 void f(void);
4
5 int y = 15212;
6 int x = 15213;
7
8 int main()
9 {
10 f();
11 printf(″x = 0x%x y = 0x%x n″,
12 x, y);
13 return 0;
14 }

 

1 /* bar5.c */
2 double x;
3
4 void f()
5 {
6 x = -0.0;
7 }

以上两个文件用以下命令编译时:

gcc -Wall -Og -o foobar5 foo5.c bar5.c

只有一个简单的告警:/usr/bin/ld: warning: alignment 4 of symbol `x' in /tmp/ccYmFWmR.o is smaller than 8 in /tmp/ccIuZptR.o

但是其实埋藏了很严重的问题。直接上书的的原文:

 

7.6.1 How Linkers Resolve Duplicate Symbol Names
The input to the linker is a collection of relocatable object modules. Each of these modules defines a set of symbols, some of which are local (visible only to the module that defines it), and some of which are global (visible to other modules). What happens if multiple modules define global symbols with the same name? Here is the approach that Linux co

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值