Linker Lab 中函数定义不在 relocTable 中是否正常呢?

计算机系统导论 135 views 2 replies
#1 ·

在调试 test4 时,void foo() 函数在 strongdef.c 中声明,weakdef.c 中定义,但 weakdef.c 对应的 relocTable 中找不到 foo 符号,因此 linker 返回“undefined reference for symbol foo”

strongdef.c
weakdef.c
image|690x74

请问这是正常的吗,我是否需要通过其它方法判断函数是否有定义,例如 symbolTable?
#2 ·

我发现两个文件的 SymbolTable 中有 foo 函数的符号表,所以要函数的强弱符号只能根据它们来判断是吗?
image|690x152

#3 · (edited)

定义是不会进入 relocTable 的,只有引用才会。
weakdef.c 没有引用 foo,所以自然不需要对 foo 符号进行重定向,relocTable 中也就没有 foo 符号。