linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Kernel Module; globals badly initialized, help needed.
@ 2002-03-07 15:38 Goddeeris Frederic
  2002-03-28  0:49 ` Paul Mackerras
  0 siblings, 1 reply; 5+ messages in thread
From: Goddeeris Frederic @ 2002-03-07 15:38 UTC (permalink / raw)
  To: ''linuxppc-dev@lists.linuxppc.org' '


Hi,

I am having lots of problems with global variables that are badly
initialized in a kernel
module. I wrote some very simple code showing the problem. The compiler I
use is gcc 2.95.3
(the one that comes with HHL2.0).

Is this a compiler problem -do I need to use some special options?- or could
it
be a problem with insmod, the kernel, ...?

I had this problem before with DECLARE_WAIT_QUEUE_HEAD where the pointers
inside the structure where badly initialized. The only sollution was to
reinitialize the fields at runtime. I posted this issue and somebody
reported he had seen the same issue.

Who can help we with this?

Thanks!
Frederic


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>


#if defined(CONFIG_SMP)
#define __SMP__
#endif

#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif

char MyMemSpace[2*0x100];
char *MemPointers[2] = {&(MyMemSpace[0]), &(MyMemSpace[0x100])};

typedef struct
{
	char *szName;
	char *szName2;
} MyStruct_t;

MyStruct_t MyStruct[] = {{"A", "A2"}, {"B", "B2"}};

int init_module(void)
{
	printk("TestDriver 3 Loaded\n");

	printk("MyMemSpace: 0x%lx 0x%lx \n",  (long)&(MyMemSpace[0]),
(long)&(MyMemSpace[0x100]));
	printk("MemPointers: 0x%lx 0x%lx \n", (long)(MemPointers[0]),
(long)(MemPointers[1]));

	printk("First Char is MyStruct[0].szName %c\n",
MyStruct[0].szName[0]);


	return -1;
}

void cleanup_module(void)
{
	return;
}




This is what I get:

MyMemSpace: 0xc304a1ec 0xc304a2ec
MemPointers: 0xc304a1ec 0xc304a3ec
First Char is MyStruct[0].szName e

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Kernel Module; globals badly initialized, help needed.
@ 2002-03-14  7:39 Goddeeris Frederic
  2002-03-19  0:22 ` Bruno Vetel
  0 siblings, 1 reply; 5+ messages in thread
From: Goddeeris Frederic @ 2002-03-14  7:39 UTC (permalink / raw)
  To: 'linuxppc-embedded@lists.linuxppc.org'


(This messages was already posted on the linuxppc-dev list, put posting it
to this list failed...)

Hi,

I am having lots of problems with global variables that are badly
initialized in a kernel
module. I wrote some very simple code showing the problem. The compiler
I use is gcc 2.95.3
(the one that comes with HHL2.0).

Is this a compiler problem -do I need to use some special options?- or
could it
be a problem with insmod, the kernel, ...?

I had this problem before with DECLARE_WAIT_QUEUE_HEAD where the
pointers inside the structure where badly initialized. The only
sollution was to reinitialize the fields at runtime. I posted this issue
and somebody reported he had seen the same issue.

Who can help we with this?

Thanks!
Frederic


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>


#if defined(CONFIG_SMP)
#define __SMP__
#endif

#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif

char MyMemSpace[2*0x100];
char *MemPointers[2] = {&(MyMemSpace[0]), &(MyMemSpace[0x100])};

typedef struct
{
	char *szName;
	char *szName2;
} MyStruct_t;

MyStruct_t MyStruct[] = {{"A", "A2"}, {"B", "B2"}};

int init_module(void)
{
	printk("TestDriver 3 Loaded\n");

	printk("MyMemSpace: 0x%lx 0x%lx \n",  (long)&(MyMemSpace[0]),
(long)&(MyMemSpace[0x100]));
	printk("MemPointers: 0x%lx 0x%lx \n", (long)(MemPointers[0]),
(long)(MemPointers[1]));

	printk("First Char is MyStruct[0].szName %c\n",
MyStruct[0].szName[0]);


	return -1;
}

void cleanup_module(void)
{
	return;
}




This is what I get:

MyMemSpace: 0xc304a1ec 0xc304a2ec
MemPointers: 0xc304a1ec 0xc304a3ec
First Char is MyStruct[0].szName e


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Kernel Module; globals badly initialized, help needed.
  2002-03-14  7:39 Goddeeris Frederic
@ 2002-03-19  0:22 ` Bruno Vetel
  0 siblings, 0 replies; 5+ messages in thread
From: Bruno Vetel @ 2002-03-19  0:22 UTC (permalink / raw)
  To: Goddeeris Frederic; +Cc: 'linuxppc-embedded@lists.linuxppc.org'


Hi

We had a problem similar to yours with an HHL 1.0. An update of insmod et rmmod from busybox
solved our problem

        Bruno

Goddeeris Frederic <Frederic.Goddeeris@siemens.atea.be> writes:

> (This messages was already posted on the linuxppc-dev list, put posting it
> to this list failed...)
>
> Hi,
>
> I am having lots of problems with global variables that are badly
> initialized in a kernel
> module. I wrote some very simple code showing the problem. The compiler
> I use is gcc 2.95.3
> (the one that comes with HHL2.0).
>
> Is this a compiler problem -do I need to use some special options?- or
> could it
> be a problem with insmod, the kernel, ...?
>
> I had this problem before with DECLARE_WAIT_QUEUE_HEAD where the
> pointers inside the structure where badly initialized. The only
> sollution was to reinitialize the fields at runtime. I posted this issue
> and somebody reported he had seen the same issue.
>
> Who can help we with this?
>
> Thanks!
> Frederic
>
>
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/init.h>
>
>
> #if defined(CONFIG_SMP)
> #define __SMP__
> #endif
>
> #if defined(CONFIG_MODVERSIONS)
> #define MODVERSIONS
> #include <linux/modversions.h>
> #endif
>
> char MyMemSpace[2*0x100];
> char *MemPointers[2] = {&(MyMemSpace[0]), &(MyMemSpace[0x100])};
>
> typedef struct
> {
> 	char *szName;
> 	char *szName2;
> } MyStruct_t;
>
> MyStruct_t MyStruct[] = {{"A", "A2"}, {"B", "B2"}};
>
> int init_module(void)
> {
> 	printk("TestDriver 3 Loaded\n");
>
> 	printk("MyMemSpace: 0x%lx 0x%lx \n",  (long)&(MyMemSpace[0]),
> (long)&(MyMemSpace[0x100]));
> 	printk("MemPointers: 0x%lx 0x%lx \n", (long)(MemPointers[0]),
> (long)(MemPointers[1]));
>
> 	printk("First Char is MyStruct[0].szName %c\n",
> MyStruct[0].szName[0]);
>
>
> 	return -1;
> }
>
> void cleanup_module(void)
> {
> 	return;
> }
>
>
>
>
> This is what I get:
>
> MyMemSpace: 0xc304a1ec 0xc304a2ec
> MemPointers: 0xc304a1ec 0xc304a3ec
> First Char is MyStruct[0].szName e
>
>
>
>

--

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Kernel Module; globals badly initialized, help needed.
  2002-03-07 15:38 Kernel Module; globals badly initialized, help needed Goddeeris Frederic
@ 2002-03-28  0:49 ` Paul Mackerras
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Mackerras @ 2002-03-28  0:49 UTC (permalink / raw)
  To: Goddeeris Frederic; +Cc: linuxppc-dev


Goddeeris Frederic writes:

> I am having lots of problems with global variables that are badly
> initialized in a kernel
> module. I wrote some very simple code showing the problem. The compiler I
> use is gcc 2.95.3

Hmmm.  I just tried your test module and it worked fine.  It produced
the following output:

TestDriver 3 Loaded
MyMemSpace: 0xd18b92a0 0xd18b93a0
MemPointers: 0xd18b92a0 0xd18b93a0
First Char is MyStruct[0].szName A

which looks fine to me.  This was with a 2.4.18 kernel.

The command line I used to compile it was:

bash-2.05a$ gcc -D__KERNEL__ -I/home/paulus/kernel/pmac-2.4.18/include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fomit-frame-pointer -fno-strict-aliasing -fno-common -I/home/paulus/kernel/pmac-2.4.18/arch/ppc -fsigned-char -msoft-float -pipe -ffixed-r2 -Wno-uninitialized -mmultiple -mstring -DMODULE  -DKBUILD_BASENAME=modtest -c modtest.c

I got this by doing `make modules' in a kernel tree and taking the
command that it used for the first module it came across (which
happened to be serial.c) and substituting modtest for serial.

I did some minor cleanups to the code, the actual code I used is
below.

Paul.

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

char MyMemSpace[2*0x100];
char *MemPointers[2] = {&(MyMemSpace[0]), &(MyMemSpace[0x100])};

typedef struct
{
	char *szName;
	char *szName2;
} MyStruct_t;

MyStruct_t MyStruct[] = {{"A", "A2"}, {"B", "B2"}};

int init_module(void)
{
	printk("TestDriver 3 Loaded\n");

	printk("MyMemSpace: 0x%lx 0x%lx \n",  (long)&(MyMemSpace[0]),
	       (long)&(MyMemSpace[0x100]));
	printk("MemPointers: 0x%lx 0x%lx \n", (long)(MemPointers[0]),
	       (long)(MemPointers[1]));

	printk("First Char is MyStruct[0].szName %c\n",
	       MyStruct[0].szName[0]);


	return -1;
}

void cleanup_module(void)
{
	return;
}

MODULE_LICENSE("GPL");

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Kernel Module; globals badly initialized, help needed.
@ 2002-03-28  8:42 Goddeeris Frederic
  0 siblings, 0 replies; 5+ messages in thread
From: Goddeeris Frederic @ 2002-03-28  8:42 UTC (permalink / raw)
  To: 'paulus@samba.org', 'mcharleb@qualcomm.com'; +Cc: linuxppc-dev


Hi Paul,
Hi Marc,

It looks like the issue is caused by insmod of Busybox...

I posted a question about it on the BusyBox mailing list.
Somebody mailed me that he has a similar problem that he solved by updating
his busybox but I did not see any reference to this issue in the BB
changelog.

Thanks,
Frederic

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-03-28  8:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-07 15:38 Kernel Module; globals badly initialized, help needed Goddeeris Frederic
2002-03-28  0:49 ` Paul Mackerras
  -- strict thread matches above, loose matches on Subject: below --
2002-03-14  7:39 Goddeeris Frederic
2002-03-19  0:22 ` Bruno Vetel
2002-03-28  8:42 Goddeeris Frederic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).