LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] kernel programming curiosity

[ILUG] kernel programming curiosity

Kenn Humborg kenn at linux.ie
Sat Apr 21 12:04:30 IST 2001


On Sat, Apr 21, 2001 at 01:45:19AM +0100, Fergal Daly wrote:
> Hi,
> 	I was just playing about with some simple Kernel programming and I ran 
> into something I thought was odd. I had a simple module which used the 
> put_user function, the module compiled fine but whenever I insmodded I got 
> an error of "unresolved symbol __put_user_X" and sure enough if you do an 
> nm on the module you'll see
> 
>           U __put_user_1
>           U __put_user_2
>           U __put_user_4
>           U __put_user_X
> 
> as part of the output. I can't find tail of trace of __put_user_X in any 
> header files or in /proc/ksyms although __put_user_x does get a mention in 
> /usr/include/linux/asm/uaccess.h
> 
> The funny thing is that if I add -O to the gcc options the problem goes 
> away. All the __put_user_ functions are optimised away except for 
> __put_user_1 which is a valid kernel symbol and I can now insmod the module 
> (although the example below is NOT a module you should try insmodding, I've 
> just cut the whole thing down to a tiny example that still reproduces the 
> problem).

In my experience, you _need_ to compile with -O.  With no optimisations
enabled, GCC doesn't inline _any_ functions, even ones specifically marked
__inline__.  Calls to __put_user_N and other inlined stuff gets translated
to regular function calls.  Then either of these can happen:

   o  When compiled the kernel itself, this function may be declared
      as static inline and no global symbol will be created for it,
      so linking will fail

   o  When compiling a module, this symbol was never EXPORT_SYMBOL()ed
      (or whatever the macro is called...), so module loading will fail.


> What's the story? I thought -O wasn't meant to make any difference except 
> speedwise. Is there something that says that all kernel code must be 
> compiled with a -O switch? Where is gcc getting this capital X instead of a 
> small x?

Take a look into the innards of include/asm/uaccess.h.  __put_user(addr,x) gets
broken out to something like __put_user_X via some GCC-specific keywords
and some pre-processor magic.  This, then, allows for byte, word and longword
copies to be optimized individually.

The code is complex, but the generated code is simple.

Later,
Kenn





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell