简体   繁体   English

EXPORT_SYMBOL 导致在一个方向上未定义的引用,而不是另一个方向(重定位被截断)

[英]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 中的相应功能
  • Defining the symbol as extern in driver B and accessing在驱动程序 B 中将符号定义为extern并访问

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:但是,如果我做相反的事情,那就是:

  • Define and EXPORT_SYMBOL a function pointer in memory.cmemory.c定义和EXPORT_SYMBOL函数指针
  • Assign a pointer to the platform driver function to the exported 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?它现在有效......但为什么呢? :-) :-)

I think the given picture will clarify whats the mistake here.我认为给定的图片将澄清这里的错误。 Symbols exported by modules can not be used by the kernel.内核不能使用模块导出的符号。 On the first place kernel won't build giving linker error as you are facing.首先,内核不会在您面临时生成链接器错误。

内核符号导出知识

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EXPORT_SYMBOL和static关键字 - EXPORT_SYMBOL and the static keyword cygwin 64库:未定义引用,重定位被截断以适合:R_X86_64_PC32对未定义的符号 - cygwin 64 library: undefined reference, relocation truncated to fit: R_X86_64_PC32 against undefined symbol 为什么当我使用__EXPORT_SYMBOL时只得到一个部分 - Why I get just one section when I use __EXPORT_SYMBOL 截断重定位以适合:R_X86_64_PC32针对未定义符号`cfree' - relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cfree' 如何使用函数的参数唯一地EXPORT_SYMBOL? - How to EXPORT_SYMBOL uniquely with the function's arguments? Linux内核代码中“EXPORT_SYMBOL”的含义是什么? - What's meaning of “EXPORT_SYMBOL” in Linux kernel code? EXPORT_SYMBOL 宏给出冲突类型错误 - EXPORT_SYMBOL macro is giving conflicting types error 尽管 Linux kernel 模块中有 EXPORT_SYMBOL,如何防止“错误:此处未声明'符号'”? - How to prevent “error: 'symbol' undeclared here” despite EXPORT_SYMBOL in a Linux kernel module? 如何使用EXPORT_SYMBOL或等效的方法在两个内核模块之间导出结构? - How to export a struct between two kernel modules using EXPORT_SYMBOL or equivalent? 错误:c:87 :(。text + 0x247):重定位被截断以适合:R_X86_64_PC32针对未定义的符号“ course_insert” - Error: c:87:(.text+0x247): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `course_insert'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM