All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Németh Márton" <nm127@freemail.hu>
To: LKML <linux-kernel@vger.kernel.org>
Subject: __devinitdata, __devinitconst and const?
Date: Sun, 06 Dec 2009 17:30:40 +0100	[thread overview]
Message-ID: <4B1BDC30.6020800@freemail.hu> (raw)

Hi,

I would like to understand how __devinitdata and __devinitconst works. I
also would like to see what happens if I make a mistake: is it recognised
by any of the static analyze tools (i.e. by gcc or by modpost).

So I created a little test module and I tried to compile it with gcc 4.3.2.
My expectation would be that the variables a, d, e, h, a_str, d_str, e_str
and h_str are OK. I also expect that the variables b, c, f, g, b_str, c_str,
f_str and g_str are wrong because of section mismatch.

The current result, however, is a bit confusing to me. Here it is:

$ make
make -C /lib/modules/2.6.32-rc8/build M=/home/nmarci/c/hello2 modules
make[1]: Entering directory `/usr/src/linux-2.6.32-rc8'
  CC [M]  /home/nmarci/c/hello2/test.o
/home/nmarci/c/hello2/test.c:5: error: b causes a section type conflict
/home/nmarci/c/hello2/test.c:7: error: d causes a section type conflict
/home/nmarci/c/hello2/test.c:15: error: b_str causes a section type conflict
/home/nmarci/c/hello2/test.c:17: error: d_str causes a section type conflict
/home/nmarci/c/hello2/test.c:20: error: f_str causes a section type conflict
/home/nmarci/c/hello2/test.c:22: error: h_str causes a section type conflict
make[2]: *** [/home/nmarci/c/hello2/test.o] Error 1
make[1]: *** [_module_/home/nmarci/c/hello2] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.32-rc8'
make: *** [default] Error 2

Here is the source code of my test.c:

------>8------- cut here ----->8-------
#include <linux/init.h>
#include <linux/module.h>

int a __devinitdata = 0x11223344;
const int b __devinitdata = 0x55667788; // error: b causes a section type conflict
int c __devinitconst = 0x99AABBCC;
const int d __devinitconst = 0xDDEEFF00; // error: d causes a section type conflict

static int e __devinitdata = 0x12233445;
static const int f __devinitdata = 0x56677889;
static int g __devinitconst = 0x900AABBC;
static const int h __devinitconst = 0xCDDEEFF0;

char a_str[] __devinitdata = "first";
const char b_str[] __devinitdata = "second"; // error: b_str causes a section type conflict
char c_str[] __devinitconst = "third";
const char d_str[] __devinitconst = "fourth"; // error: d_str causes a section type conflict

static char e_str[] __devinitdata = "fifth";
static const char f_str[] __devinitdata = "sixth"; // error: f_str causes a section type conflict
static char g_str[] __devinitconst = "seventh";
static const char h_str[] __devinitconst = "eighth"; // error: h_str causes a section type conflict

static void __devinit probe(void)
{
	printk(KERN_ALERT "a=0x%X\n", a);
	printk(KERN_ALERT "b=0x%X\n", b);
	printk(KERN_ALERT "c=0x%X\n", c);
	printk(KERN_ALERT "d=0x%X\n", d);

	printk(KERN_ALERT "e=0x%X\n", e);
	printk(KERN_ALERT "f=0x%X\n", f);
	printk(KERN_ALERT "g=0x%X\n", g);
	printk(KERN_ALERT "h=0x%X\n", h);

	printk(KERN_ALERT "a_str=%s\n", a_str);
	printk(KERN_ALERT "b_str=%s\n", b_str);
	printk(KERN_ALERT "c_str=%s\n", c_str);
	printk(KERN_ALERT "d_str=%s\n", d_str);

	printk(KERN_ALERT "e_str=%s\n", e_str);
	printk(KERN_ALERT "f_str=%s\n", f_str);
	printk(KERN_ALERT "g_str=%s\n", g_str);
	printk(KERN_ALERT "h_str=%s\n", h_str);
}

static int __init test_init(void)
{
	printk(KERN_ALERT "Test loaded\n");
	probe();

	return 0;
}

static void __exit test_exit(void)
{
	printk(KERN_ALERT "Test unloaded\n");
}

module_init(test_init);
module_exit(test_exit);
------>8------- cut here ----->8-------

Anybody can tell me what went wrong?

Regards,

	Márton Németh


                 reply	other threads:[~2009-12-06 16:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B1BDC30.6020800@freemail.hu \
    --to=nm127@freemail.hu \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.