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