This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RFA: unique sections for unitialised data on the MIPS


Hi Guys,

  I would like permission to apply the following patch.  It fixes the
  UNIQUE_SECTION macro for the ELF mips variants so that uninitialised
  data is not always placed into the .data section by default when
  -fdata-sections is used.  The problem is that some uninitialised
  data ought to go into the .sdata section, and GCC generates relocs
  that will not work if the data has been placed into the .data
  section.

  This patch also makes the UNIQUE_SECTION macro behave in the same
  way as the version defined in gcc/config/elfos.h.

  The problem can be demonstrated by compiling the test case below:

---------------foo.h-------------
typedef union
{
    int arr[2];
} foo_t;
 
extern const foo_t foo;
---------------foo.c-------------
#include "foo.h"
 
const foo_t foo = { {1, 2} };
---------------main.c------------
#include "foo.h"
 
int main()
{
    if (foo.arr[0] == 5)
        return 0;
    else
        return 1;
}
---------------------------------
gcc -O2 -fdata-sections foo.c main.c
---------------------------------

Cheers
	Nick


2000-09-11  Nick Clifton  <nickc@redhat.com>

	* config/mips/elf64.h (UNIQUE_SECTION): Do not put unitialised
	data into the .data section by default.  It may need to go into
	the .sdata section.
	
	* config/mips/elf.h (UNIQUE_SECTION): Ditto.

Index: config/mips/elf64.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/elf64.h,v
retrieving revision 1.24
diff -p -r1.24 elf64.h
*** elf64.h	2000/08/11 03:18:05	1.24
--- elf64.h	2000/09/11 18:59:45
*************** do {									   \
*** 207,215 ****
       0=text, 1=rodata, 2=data, 3=sdata, [4=bss].  */			   \
    if (TREE_CODE (DECL) == FUNCTION_DECL)				   \
      sec = 0;								   \
    else if (DECL_INITIAL (DECL) == 0					   \
             || DECL_INITIAL (DECL) == error_mark_node)			   \
!     sec = 2;								   \
    else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16)			   \
        && TREE_CODE (decl) == STRING_CST					   \
        && !flag_writable_strings)					   \
--- 207,218 ----
       0=text, 1=rodata, 2=data, 3=sdata, [4=bss].  */			   \
    if (TREE_CODE (DECL) == FUNCTION_DECL)				   \
      sec = 0;								   \
+   /* Do not assume that uninitialised data should go into the .data        \
+      section, it may need to go into the .sdata section instead.	   \
+      Leave the tests below to  sort this out.                              \
    else if (DECL_INITIAL (DECL) == 0					   \
             || DECL_INITIAL (DECL) == error_mark_node)			   \
!     sec = 2;  */							   \
    else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16)			   \
        && TREE_CODE (decl) == STRING_CST					   \
        && !flag_writable_strings)					   \

Index: config/mips/elf.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/elf.h,v
retrieving revision 1.21
diff -p -r1.21 elf.h
*** elf.h	2000/08/11 03:18:05	1.21
--- elf.h	2000/09/11 18:59:45
*************** do {									   \
*** 226,234 ****
       0=text, 1=rodata, 2=data, 3=sdata, [4=bss].  */			   \
    if (TREE_CODE (DECL) == FUNCTION_DECL)				   \
      sec = 0;								   \
    else if (DECL_INITIAL (DECL) == 0					   \
             || DECL_INITIAL (DECL) == error_mark_node)			   \
!     sec = 2;								   \
    else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16)			   \
        && TREE_CODE (decl) == STRING_CST					   \
        && !flag_writable_strings)					   \
--- 226,237 ----
       0=text, 1=rodata, 2=data, 3=sdata, [4=bss].  */			   \
    if (TREE_CODE (DECL) == FUNCTION_DECL)				   \
      sec = 0;								   \
+   /* Do not assume that uninitialised data should go into the .data        \
+      section, it may need to go into the .sdata section instead.	   \
+      Leave the tests below to  sort this out.                              \
    else if (DECL_INITIAL (DECL) == 0					   \
             || DECL_INITIAL (DECL) == error_mark_node)			   \
!     sec = 2;  */							   \
    else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16)			   \
        && TREE_CODE (decl) == STRING_CST					   \
        && !flag_writable_strings)					   \

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]