https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119312

            Bug ID: 119312
           Summary: Constant array not allocated in read-only segment
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

Created attachment 60779
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60779&action=edit
test case foo.c

When constant data is allocated in a read-only segment, it is more efficient
than in the .data segment (namely, the OS does not need to copy such a memory
page to the swap when memory is tight).

When compiling this program, although the array 'html5' contains only constant
data (note that the struct has no holes and has alignment 1), gcc puts it in
the .data segment.

How to reproduce:
$ gcc -O2 -c foo.c
$ size foo.o
   text    data     bss     dec     hex filename
    270     230       0     500     1f4 foo.o

Only when I add an additional 'const' to the 'html5' array, does gcc put it
into the .rodata or .text segment.

Reply via email to