[Bug c/15423] New: -fmerge-constants prodcues wrong object files

gruenewa at hni dot upb dot de gcc-bugzilla@gcc.gnu.org
Fri May 14 12:21:00 GMT 2004


If the optimization -fmerge-constants is used, the rodata section in the 
produced object files are not tagged with the flags LOAD, ALLOC and DATA. The 
result is that the linker does not link the rodata section in the final memory 
image. Here is an example: 
 
hello_world.c: 
 
main() 
{ 
  // Test printf 
  while(1) { 
    puts("Hello world!"); 
  } 
} 
 
Translated with: 
 
   mcore-elf-gcc -m210 -mbig-endian -O1 -c -o hello_world.o hello_world.c 
 
objdump says: 
 
   mcore-elf-objdump -h hello_world.o 
 
hello_world.o:     file format elf32-mcore-big 
 
Sections: 
Idx Name          Size      VMA       LMA       File off  Algn 
  0 .text         00000014  00000000  00000000  00000034  2**2 
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 
  1 .data         00000000  00000000  00000000  00000048  2**0 
                  CONTENTS, ALLOC, LOAD, DATA 
  2 .bss          00000000  00000000  00000000  00000048  2**0 
                  ALLOC 
  3 .rodata.str1.4 0000000d  00000000  00000000  00000048  2**2 
                  CONTENTS, READONLY 
  4 .comment      00000012  00000000  00000000  00000055  2**0 
                  CONTENTS, READONLY 
 
The flags are missing in .rodata.str1.4. If we create a srec memory image from 
the linked .elf file, it will not contain the rodata section. The effect is 
that the programm running on the M-Core does call puts, but nothing is 
displayed. 
 
Compiling the program with: 
 
mcore-elf-gcc -m210 -mbig-endian -O1 -fno-merge-constants -c -o hello_world.o 
hello_world.c 
 
results in: 
 
hello_world.o:     file format elf32-mcore-big 
 
Sections: 
Idx Name          Size      VMA       LMA       File off  Algn 
  0 .text         00000014  00000000  00000000  00000034  2**2 
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 
  1 .data         00000000  00000000  00000000  00000048  2**0 
                  CONTENTS, ALLOC, LOAD, DATA 
  2 .bss          00000000  00000000  00000000  00000048  2**0 
                  ALLOC 
  3 .rodata       0000000d  00000000  00000000  00000048  2**2 
                  CONTENTS, ALLOC, LOAD, READONLY, DATA 
  4 .comment      00000012  00000000  00000000  00000055  2**0 
                  CONTENTS, READONLY 
 
The flags are set correctly. The linker will generate a correct .elf file, and 
objcopy will generate a srec file that contains the Hello world string.

-- 
           Summary: -fmerge-constants prodcues wrong object files
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gruenewa at hni dot upb dot de
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: mcore-elf-unknown


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15423



More information about the Gcc-bugs mailing list