[英]EXPORT_SYMBOL causes undefined reference in one direction, but not the other (relocation truncated)
I'm working on the 4.9 Linux kernel on a aarch64 machine, specifically mm/memory.c and a custom platform device driver.我正在 aarch64 机器上处理 4.9 Linux 内核,特别是mm/memory.c和自定义平台设备驱动程序。 My goal is to have my device driver communicate some information to hardware that originates in functions in memory.c .我的目标是让我的设备驱动程序将一些信息传递给源自memory.c中的函数的硬件。
At first, I tried the same approach I always use for communicating across (platform) device drivers:起初,我尝试了我一直用于跨(平台)设备驱动程序通信的相同方法:
EXPORT_SYMBOL
for the respective function in driver A EXPORT_SYMBOL
用于驱动程序 A 中的相应功能Usually works like a charm, but this time I came across the following error when linking, with the platform driver EXPORT ing and memory.c
using extern :通常像魅力一样工作,但这次我在链接时遇到以下错误,平台驱动程序EXPORT ing 和memory.c
使用extern :
mm/memory.c:164:(.text+0x2a874): relocation truncated to fit: R_AARCH64_ADR_PREL_PG_HI21 against undefined symbol `my_func'
However, if I do the opposite, that is:但是,如果我做相反的事情,那就是:
EXPORT_SYMBOL
a function pointer in memory.c
在memory.c
定义和EXPORT_SYMBOL
函数指针... it works! ... 有用!
Specifically...具体来说...
Platform Driver:平台驱动:
void my_func(args){ ... };
EXPORT_SYMBOL(my_func);
memory.c:内存.c:
extern void my_func(args);
... causes the linker error described above. ...导致上述链接器错误。
But ...但 ...
Platform Driver:平台驱动:
extern void (*funcptr)(args);
driver_probe() {
...
funcptr = &my_func;
....
}
memory.c:内存.c:
void (*funcptr)(args) = NULL;
EXPORT_SYMBOL(funcptr);
... works ! ...工作!
A quick google search hinted that the linker error is concerned with the gcc options PIC/PIE, but I couldn't find a definitive answer.快速谷歌搜索暗示链接器错误与 gcc 选项 PIC/PIE 有关,但我找不到明确的答案。
It works now ... but WHY?它现在有效......但为什么呢? :-) :-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.