* const __init
@ 2001-05-20 19:51 Geert Uytterhoeven
2001-05-20 20:06 ` Jeff Garzik
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Geert Uytterhoeven @ 2001-05-20 19:51 UTC (permalink / raw)
To: Linux Kernel Development
Since a while include/linux/init.h contains the line
* Also note, that this data cannot be "const".
Why is this? Because const data will be put in a different section?
However, quite some code defines const __init variables (see list below).
So what should be done now?
1. Remove const from __initdata variables
2. Make __inidata work with const variables
FWIW, many sources still use __init for data, while it should be __initdata.
Gr{oetje,eeting}s,
Geert
Appendix: here's the list of affected source files:
arch/arm/kernel/setup.c
arch/m68k/amiga/config.c
arch/ppc/amiga/config.c
arch/ppc/kernel/residual.c
drivers/acorn/net/ether1.c
drivers/acorn/net/ether3.c
drivers/acorn/net/etherh.c
drivers/atm/ambassador.c
drivers/cdrom/cdu31a.c
drivers/char/dsp56k.c
drivers/char/pc110pad.c
drivers/char/qpmouse.c
drivers/char/softdog.c
drivers/ide/buddha.c
drivers/ide/rapide.c
drivers/net/ewrk3.c
drivers/net/hamradio/6pack.c
drivers/net/hamradio/bpqether.c
drivers/net/hamradio/mkiss.c
drivers/net/hamradio/scc.c
drivers/net/hamradio/yam.c
drivers/net/strip.c
drivers/net/tokenring/ibmtr.c
drivers/net/wan/lapbether.c
drivers/net/wan/z85230.c
drivers/pci/names.c
drivers/scsi/seagate.c
drivers/sound/sonicvibes.c
drivers/video/amifb.c
drivers/video/aty128fb.c
drivers/video/atyfb.c
drivers/video/mdacon.c
drivers/video/modedb.c
drivers/video/newport_con.c
drivers/video/promcon.c
drivers/video/riva/fbdev.c
drivers/video/sticon-bmode.c
drivers/video/sticon.c
drivers/video/tdfxfb.c
drivers/video/vgacon.c
drivers/zorro/names.c
net/ax25/af_ax25.c
net/ipv4/ipip.c
net/ipx/af_ipx.c
net/ipx/af_spx.c
net/lapb/lapb_iface.c
net/netrom/af_netrom.c
net/unix/af_unix.c
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 19:51 const __init Geert Uytterhoeven
@ 2001-05-20 20:06 ` Jeff Garzik
2001-05-20 20:11 ` Geert Uytterhoeven
2001-05-20 20:16 ` Franz Sirl
2001-05-20 22:05 ` Russell King
2 siblings, 1 reply; 13+ messages in thread
From: Jeff Garzik @ 2001-05-20 20:06 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Linux Kernel Development
Geert Uytterhoeven wrote:
>
> Since a while include/linux/init.h contains the line
>
> * Also note, that this data cannot be "const".
>
> Why is this? Because const data will be put in a different section?
Causes a "section type conflict" build error, at least on x86.
> FWIW, many sources still use __init for data, while it should be __initdata.
*blink* wow
--
Jeff Garzik | "Do you have to make light of everything?!"
Building 1024 | "I'm extremely serious about nailing your
MandrakeSoft | step-daughter, but other than that, yes."
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 20:06 ` Jeff Garzik
@ 2001-05-20 20:11 ` Geert Uytterhoeven
2001-05-20 21:34 ` Jeff Garzik
0 siblings, 1 reply; 13+ messages in thread
From: Geert Uytterhoeven @ 2001-05-20 20:11 UTC (permalink / raw)
To: Jeff Garzik; +Cc: Linux Kernel Development
On Sun, 20 May 2001, Jeff Garzik wrote:
> Geert Uytterhoeven wrote:
> > Since a while include/linux/init.h contains the line
> >
> > * Also note, that this data cannot be "const".
> >
> > Why is this? Because const data will be put in a different section?
>
> Causes a "section type conflict" build error, at least on x86.
On m68k I only saw section type conflict errors when using __init while it
should have been __initdata.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 19:51 const __init Geert Uytterhoeven
2001-05-20 20:06 ` Jeff Garzik
@ 2001-05-20 20:16 ` Franz Sirl
2001-05-21 0:58 ` Keith Owens
2001-05-20 22:05 ` Russell King
2 siblings, 1 reply; 13+ messages in thread
From: Franz Sirl @ 2001-05-20 20:16 UTC (permalink / raw)
To: Geert Uytterhoeven, Linux Kernel Development
On Sunday 20 May 2001 21:51, Geert Uytterhoeven wrote:
> Since a while include/linux/init.h contains the line
>
> * Also note, that this data cannot be "const".
>
> Why is this? Because const data will be put in a different section?
Yes, and gcc3 errors on these constructs, cause it cannot decide if the data
should be put into a .data or .rodata section.
Dunno if it's worth to create a __initconstdata/__initrodata though, but it
would be easy implement I guess.
> drivers/video/aty128fb.c
Fixed in bk 2_4.
Franz.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 20:11 ` Geert Uytterhoeven
@ 2001-05-20 21:34 ` Jeff Garzik
2001-05-20 22:19 ` Ingo Oeser
2001-05-21 3:07 ` Keith Owens
0 siblings, 2 replies; 13+ messages in thread
From: Jeff Garzik @ 2001-05-20 21:34 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Linux Kernel Development
Geert Uytterhoeven wrote:
>
> On Sun, 20 May 2001, Jeff Garzik wrote:
> > Geert Uytterhoeven wrote:
> > > Since a while include/linux/init.h contains the line
> > >
> > > * Also note, that this data cannot be "const".
> > >
> > > Why is this? Because const data will be put in a different section?
> >
> > Causes a "section type conflict" build error, at least on x86.
>
> On m68k I only saw section type conflict errors when using __init while it
> should have been __initdata.
This might be a very valid point...
(let me know if the following test is flawed)
> [jgarzik@rum tmp]$ cat > sectest.c
> #include <linux/module.h>
> #include <linux/init.h>
> static const char version[] __initdata = "foo";
> [jgarzik@rum tmp]$ gcc -D__KERNEL__ -I/spare/cvs/linux_2_4/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe -mpreferred-stack-boundary=2 -march=i686 -c -o sectest.o sectest.c
> [jgarzik@rum tmp]$
No section type conflict appears.
--
Jeff Garzik | "Do you have to make light of everything?!"
Building 1024 | "I'm extremely serious about nailing your
MandrakeSoft | step-daughter, but other than that, yes."
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 19:51 const __init Geert Uytterhoeven
2001-05-20 20:06 ` Jeff Garzik
2001-05-20 20:16 ` Franz Sirl
@ 2001-05-20 22:05 ` Russell King
2 siblings, 0 replies; 13+ messages in thread
From: Russell King @ 2001-05-20 22:05 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Linux Kernel Development
On Sun, May 20, 2001 at 09:51:04PM +0200, Geert Uytterhoeven wrote:
> Appendix: here's the list of affected source files:
>
> arch/arm/kernel/setup.c
Thanks for pointing it out.
--
Russell King (rmk@arm.linux.org.uk) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 21:34 ` Jeff Garzik
@ 2001-05-20 22:19 ` Ingo Oeser
2001-05-21 2:43 ` Richard Henderson
2001-05-21 3:07 ` Keith Owens
1 sibling, 1 reply; 13+ messages in thread
From: Ingo Oeser @ 2001-05-20 22:19 UTC (permalink / raw)
To: Jeff Garzik; +Cc: Geert Uytterhoeven, Linux Kernel Development
On Sun, May 20, 2001 at 05:34:48PM -0400, Jeff Garzik wrote:
> This might be a very valid point...
>
> (let me know if the following test is flawed)
It is imho.
> > [jgarzik@rum tmp]$ cat > sectest.c
> > #include <linux/module.h>
> > #include <linux/init.h>
> > static const char version[] __initdata = "foo";
static char version2[] __initdata = "bar";
> > [jgarzik@rum tmp]$ gcc -D__KERNEL__ -I/spare/cvs/linux_2_4/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe -mpreferred-stack-boundary=2 -march=i686 -c -o sectest.o sectest.c
> > [jgarzik@rum tmp]$
>
> No section type conflict appears.
Now it SHOULD conflict on these binutils, but doesn't on mine (2.9.5) ;-)
It is decided to put it into .data.init as expected.
AFAIK "const" is only a promise to the compiler, that we write
this data ONCE and read only after this initial write. So the
decision on the section is implementation defined.
What I don't understand is, why GCC overrides our explicit
override (done by setting the "section attribute" explicitly).
I would consider this a BUG in GCC. I don't understand, why we
support this BUG...
Maybe some GCC people can enlighten me, why GCC ignores such
overrides, that are for the cases where we DO KNOW BETTER than
GCC, what section is correct.
Regards
Ingo Oeser
--
To the systems programmer,
users and applications serve only to provide a test load.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 20:16 ` Franz Sirl
@ 2001-05-21 0:58 ` Keith Owens
0 siblings, 0 replies; 13+ messages in thread
From: Keith Owens @ 2001-05-21 0:58 UTC (permalink / raw)
To: Franz Sirl; +Cc: Geert Uytterhoeven, Linux Kernel Development
On Sun, 20 May 2001 22:16:11 +0200,
Franz Sirl <Franz.Sirl-kernel@lauterbach.com> wrote:
>Yes, and gcc3 errors on these constructs, cause it cannot decide if the data
>should be put into a .data or .rodata section.
>Dunno if it's worth to create a __initconstdata/__initrodata though, but it
>would be easy implement I guess.
Not worth it. Adding finer grained init.data sections requires changes
to every architecture's vmlinux.lds script but it gains you nothing,
the sections are discarded after the kernel has booted.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 22:19 ` Ingo Oeser
@ 2001-05-21 2:43 ` Richard Henderson
2001-05-21 12:41 ` Jamie Lokier
0 siblings, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2001-05-21 2:43 UTC (permalink / raw)
To: Ingo Oeser; +Cc: Jeff Garzik, Geert Uytterhoeven, Linux Kernel Development
On Mon, May 21, 2001 at 12:19:49AM +0200, Ingo Oeser wrote:
> AFAIK "const" is only a promise to the compiler, that we write
> this data ONCE and read only after this initial write. So the
> decision on the section is implementation defined.
No, the problem is not with which section, but what flags that
section should have. If you put only "const" data in a section,
then the section should have SHF_WRITE clear. Conversely, if
you put writable data in a section then SHF_WRITE should be set.
Now, one could argue that gcc should scan the entire file to
see if there are any non-constant data members added to a
particular section, and set SHF_WRITE if any such exist.
My answer is: you would not like gcc's memory usage under these
conditions.
r~
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-20 21:34 ` Jeff Garzik
2001-05-20 22:19 ` Ingo Oeser
@ 2001-05-21 3:07 ` Keith Owens
2001-05-21 7:51 ` Richard Henderson
1 sibling, 1 reply; 13+ messages in thread
From: Keith Owens @ 2001-05-21 3:07 UTC (permalink / raw)
To: Jeff Garzik
Cc: Geert Uytterhoeven, Linux Kernel Development, Richard Henderson
On Sun, 20 May 2001 17:34:48 -0400,
Jeff Garzik <jgarzik@mandrakesoft.com> wrote:
>(let me know if the following test is flawed)
>
> [jgarzik@rum tmp]$ cat > sectest.c
> #include <linux/module.h>
> #include <linux/init.h>
> static const char version[] __initdata = "foo";
> [jgarzik@rum tmp]$ gcc -D__KERNEL__ -I/spare/cvs/linux_2_4/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe -mpreferred-stack-boundary=2 -march=i686 -c -o sectest.o sectest.c
> [jgarzik@rum tmp]$
>
>No section type conflict appears.
With just one variable in initdata there is no conflict, it takes two
to conflict.
static const char var1[] __attribute__ ((__section__ (".data.init"))) = "foo";
int main(void) { return(0); }
static int var2[] __attribute__ ((__section__ (".data.init"))) = {0,1};
does cause a section conflict, egcs 1.1.2.
Interestingly enough, if var[12] are together, without the intervening
text, then gcc does not flag an error, instead it puts both variables
in section .data.init and marks it as read only. This looks like a bug
in gcc.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-21 3:07 ` Keith Owens
@ 2001-05-21 7:51 ` Richard Henderson
2001-05-21 20:01 ` J . A . Magallon
0 siblings, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2001-05-21 7:51 UTC (permalink / raw)
To: Keith Owens; +Cc: Jeff Garzik, Geert Uytterhoeven, Linux Kernel Development
On Mon, May 21, 2001 at 01:07:50PM +1000, Keith Owens wrote:
> does cause a section conflict, egcs 1.1.2.
>
> Interestingly enough, if var[12] are together, without the intervening
> text, then gcc does not flag an error, instead it puts both variables
> in section .data.init and marks it as read only. This looks like a bug
> in gcc.
Fixed in compilers newer than 2 years old.
r~
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-21 2:43 ` Richard Henderson
@ 2001-05-21 12:41 ` Jamie Lokier
0 siblings, 0 replies; 13+ messages in thread
From: Jamie Lokier @ 2001-05-21 12:41 UTC (permalink / raw)
To: Ingo Oeser, Jeff Garzik, Geert Uytterhoeven,
Linux Kernel Development
Richard Henderson wrote:
> No, the problem is not with which section, but what flags that
> section should have. If you put only "const" data in a section,
> then the section should have SHF_WRITE clear. Conversely, if
> you put writable data in a section then SHF_WRITE should be set.
>
> Now, one could argue that gcc should scan the entire file to
> see if there are any non-constant data members added to a
> particular section, and set SHF_WRITE if any such exist.
>
> My answer is: you would not like gcc's memory usage under these
> conditions.
No, I'd argue that gcc should offer a `section_flags' attribute to be
used along with the `section' attribute. Then we change the definition
of __init.
-- Jamie.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: const __init
2001-05-21 7:51 ` Richard Henderson
@ 2001-05-21 20:01 ` J . A . Magallon
0 siblings, 0 replies; 13+ messages in thread
From: J . A . Magallon @ 2001-05-21 20:01 UTC (permalink / raw)
To: Richard Henderson
Cc: Keith Owens, Jeff Garzik, Geert Uytterhoeven,
Linux Kernel Development
On 05.21 Richard Henderson wrote:
> On Mon, May 21, 2001 at 01:07:50PM +1000, Keith Owens wrote:
> > does cause a section conflict, egcs 1.1.2.
> >
> > Interestingly enough, if var[12] are together, without the intervening
> > text, then gcc does not flag an error, instead it puts both variables
> > in section .data.init and marks it as read only. This looks like a bug
> > in gcc.
>
> Fixed in compilers newer than 2 years old.
>
Somebody should officially certify 2.95.2 (or better 2.95.3, if all the
kernel related bugs are solved), and change:
"The recommended compiler for the kernel is egcs 1.1.2 (gcc 2.91.66), and it
should be used when you need absolute stability. You may use gcc 2.95.x
instead if you wish, although it may cause problems."
--
J.A. Magallon # Let the source be with you...
mailto:jamagallon@able.es
Linux Mandrake release 8.1 (Cooker) for i586
Linux werewolf 2.4.4-ac11 #2 SMP Fri May 18 12:27:06 CEST 2001 i686
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2001-05-21 20:01 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-05-20 19:51 const __init Geert Uytterhoeven
2001-05-20 20:06 ` Jeff Garzik
2001-05-20 20:11 ` Geert Uytterhoeven
2001-05-20 21:34 ` Jeff Garzik
2001-05-20 22:19 ` Ingo Oeser
2001-05-21 2:43 ` Richard Henderson
2001-05-21 12:41 ` Jamie Lokier
2001-05-21 3:07 ` Keith Owens
2001-05-21 7:51 ` Richard Henderson
2001-05-21 20:01 ` J . A . Magallon
2001-05-20 20:16 ` Franz Sirl
2001-05-21 0:58 ` Keith Owens
2001-05-20 22:05 ` Russell King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox