|
|
Log in / Subscribe / Register

Improving EXPORT_SYMBOL()

Improving EXPORT_SYMBOL()

Posted Feb 4, 2016 16:04 UTC (Thu) by viro (subscriber, #7872)
Parent article: Improving EXPORT_SYMBOL()

For what it's worth, there turned out to be another interesting problem in EXPORT_SYMBOL() - while alignment issues are easy to handle, some of the architectures with function descriptors are trickier. That had been dealt with in the second iteration of the patchset, but it went out late on Wednesday, apparently too late for this article.

Usually a pointer to function is represented as the address of its entry point. However, on some architectures that's not the only thing required for calling an arbitrary function. Consider e.g. ppc64 - a register (r2) is dedicated to accessing variables local to an object file. As the result, the calling sequence includes "set r2 to the right value"; in case of local calls it doesn't require doing anything since r2 is already pointing where needed, but indirect calls absolutely must set it right. Which means that pointer to function needs to encode both where we jump and what we put into r2. Since a lot of code assumes that function pointers and data pointers are of the same size, going for 128bit function pointers would've been a bad idea and they introduced a small static structure associated with function. That structure (function descriptor) contains all information needed for a function call and pointer to function is actually an address of that structure.

Very similar things exist on ia64 and 64bit parisc; several MMU-less architectures (blackfin, frv, sh) also have such ABI variants (selected by -mfdpic, usually). However, frv, sh and blackfin kernels are built with -mno-fdpic, so while the kernel needs to be aware of userland code doing that kind of stuff, it's limited to dealing with signal handlers. ppc64, ia64 and parisc64, OTOH, have kernels built that way.

Suppose we have
int foo(void);
int bar;
and are exporting a function foo(). Initializing struct kernel_symbol needs the right thing stored in its ->value. And for our 3 architectures that's the address of function descriptor. That's where the things get nasty: in ppc64 assembler it will be spelled out as foo, in ia64 one - @fptr(foo) and in parisc - P%foo. ppc64 case is fine - it looks exactly as if no function descriptors existed, but both for itanic and parisc we are not that lucky.

The real trouble is that if next to our EXPORT_SYMBOL(foo) we have EXPORT_SYMBOL(bar), ia64 will need to put @fptr(foo) in one and bar in another.
Compiler can tell that foo is a function and bar isn't; assembler obviously can't, so we end up having to supply that information manually. Since there's a lot more function exports than data ones, I prefer to keep EXPORT_SYMBOL for the former and add EXPORT_DATA_SYMBOL for the latter; on normal architectures they expand to the same thing. but on ia64 and parisc we need to use the right one in assembler files.


The LWN site is currently under high scraper load, so comment display has been suppressed for anonymous users. If you are a human, you may read the comments by clicking the button below:

Note: you can avoid this step in the future by logging into your LWN account.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds