$ gcc -O0 -o test_O0.o -c test.c $ g++ test_O0.o -o test_O0 test_O0.o: In function `main': test.c:(.text+0x5): undefined reference to `say' collect2: error: ld returned 1 exit status
分别查看文件test_O0.o和test_O3.o:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ readelf -s test_O0.o
Symbol table '.symtab' contains 10 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS test.c 2: 0000000000000000 0 SECTION LOCAL DEFAULT 1 3: 0000000000000000 0 SECTION LOCAL DEFAULT 3 4: 0000000000000000 0 SECTION LOCAL DEFAULT 4 5: 0000000000000000 0 SECTION LOCAL DEFAULT 6 6: 0000000000000000 0 SECTION LOCAL DEFAULT 7 7: 0000000000000000 0 SECTION LOCAL DEFAULT 5 8: 0000000000000000 16 FUNC GLOBAL DEFAULT 1 main 9: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND say
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ readelf -s test_O3.o
Symbol table '.symtab' contains 13 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS test.c 2: 0000000000000000 0 SECTION LOCAL DEFAULT 1 3: 0000000000000000 0 SECTION LOCAL DEFAULT 2 4: 0000000000000000 0 SECTION LOCAL DEFAULT 3 5: 0000000000000000 0 SECTION LOCAL DEFAULT 4 6: 0000000000000000 0 SECTION LOCAL DEFAULT 5 7: 0000000000000000 0 SECTION LOCAL DEFAULT 6 8: 0000000000000000 0 SECTION LOCAL DEFAULT 9 9: 0000000000000000 0 SECTION LOCAL DEFAULT 10 10: 0000000000000000 0 SECTION LOCAL DEFAULT 8 11: 0000000000000000 21 FUNC GLOBAL DEFAULT 6 main 12: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND puts