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

Fergal Daly fergal at esatclear.ie
Sat Apr 21 01:46:18 IST 2001


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).

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?

Any light shed would be appreciated, the details are below,

Fergal

Without -O

 > kgcc -DMODULE -D__KERNEL__ -c broken.c
/home/fergal/tmp/ccAONDH5.s: Assembler messages:
/home/fergal/tmp/ccAONDH5.s:9: Warning: Ignoring changed section attributes 
for .modinfo
 > nm broken.o
00000000 b Message_Ptr
00000000 ? __module_kernel_version
          U __put_user_1
          U __put_user_2
          U __put_user_4
          U __put_user_X
00000000 t gcc2_compiled.
00000000 T init_module

with -O

 > kgcc -DMODULE -D__KERNEL__ -O -c broken.c
/home/fergal/tmp/cc4hqC3e.s: Assembler messages:
/home/fergal/tmp/cc4hqC3e.s:9: Warning: Ignoring changed section attributes 
for .modinfo
 > nm broken.o
00000000 b Message_Ptr
00000000 ? __module_kernel_version
          U __put_user_1
00000000 t gcc2_compiled.
00000000 T init_module

 > cat broken.c
#include <linux/kernel.h>
#include <linux/module.h>
#include <asm/uaccess.h>

static char *Message_Ptr;

int init_module()
{
     char *buffer;
     put_user(*(Message_Ptr++), buffer++);
}






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