This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Don't put constructors in .rodata on PPC/SYSV
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Don't put constructors in .rodata on PPC/SYSV
- From: Franz Sirl <Franz dot Sirl-kernel at lauterbach dot com>
- Date: Wed, 17 May 2000 00:23:54 +0200
Hi,
this little testcase segfaults on powerpc-linux-gnu:
struct test_type
{
int value;
char *string;
};
void
callout (struct test_type *test_data)
{
test_data->string = "ho there";
}
int main ()
{
callout (&(struct test_type) { 3, "hey there" });
exit (0);
}
The reason is that the structure is put into the .rodata section and thus the
elements cannot be overwritten. This is simplified from linux kernel code and
prevents the use of ROM for the kernel image.
The appended patch fixes that, and was already used here:
2000-04-11 Alexandre Oliva <oliva@lsd.ic.unicamp.br>
* config/elfos.h (SELECT_SECTION): Decide whether to use a data or
const section to output a CONSTRUCTOR based on the same conditions
used for VAR_DECLs.
2000-04-29 Richard Henderson <rth@cygnus.com>
* config/alpha/elf.h (SELECT_SECTION): Treat CONSTRUCTOR like
VAR_DECL.
OK to commit patch and testcase to the mainline?
OK to commit Richards, Alexandres and my patch to the gcc-2_95-branch?
Franz.
* config/rs6000/sysv4.h (SELECT_SECTION): Treat CONSTRUCTOR like VAR_DECL.
Index: rs6000.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.123
diff -u -p -r1.123 rs6000.c
--- rs6000.c 2000/05/14 21:42:32 1.123
+++ rs6000.c 2000/05/16 21:09:34
@@ -6875,7 +6875,7 @@ rs6000_select_section (decl, reloc)
else
data_section ();
}
- else if (TREE_CODE (decl) == VAR_DECL)
+ else if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONSTRUCTOR)
{
if ((flag_pic && reloc)
|| ! TREE_READONLY (decl)