The macros TEXT_SECTION_ASM_OP, DATA_SECTION_ASM_OP, SDATA_SECTION_ASM_OP,
READONLY_DATA_SECTION_ASM_OP, CTORS_SECTION_ASM_OP, DTORS_SECTION_ASM_OP,
BSS_SECTION_ASM_OP and SBSS_SECTION_ASM_OP are used by
varasm.c:init_varasm_once
to pass their value to get_unnamed_section; the result of that function call
is then stored into a ggc root.
That means that pch fails if the string value one of these macros is in storage
that is not pch-safe, and the string is subsequently used in a compilation
useing
a precompiled header.
In particular, ggc-allocated strings are safe; string literals might be safe,
if they come from a cc1 binary (rather than a dso), and no address space
randomization is in effect.  (x)malloced emmory is not safe.

What I see with some gcc/dg/pch test cases for a port which uses xmalloed
memory is that the sections are swaitched around, most often .text against
.data (for valid-2.c Letext0 ended up in .data), but also .text or .rodata
against nothing (i.e. carry on in previous section), or just some garbage
string. 

We should either remove this restriction, or document it.

Considering that many ports use string literals, and many hosts in the wild
now use address space randomization, I think we should remove this
restriction by copying the string to ggc-allocated memory.

As far as I can see, all uses of get_unnamed_section pass a NULL or string
as third parameter, except for the rs6000, which passes pointers to
global variables - which in the case of address space randomization on the
host is just as unsuitable as a string literal.
The rs6000 cannot be converted trivially to using strings, since the variables
addresses are used in code called from backend_init, while the initialization
of the variables is called from do_compile, which is three lines down in
toplev.c:do_compile.

So I think the easiest solution is change get_unnamed_section to take a char*
for the third argument, which is copied to ggc-ed memory if not NULL, and
have another function providing the old functionality of get_unnamed_section
for the rs6000 target non-string usages.

The rs6000 target port could presumably be fixed to
work on a host with address space randomization by using indices into an
array instead of pointers, or by forcing initialization of the section names
from rs6000_xcoff_asm_init_sections, but this is really a separate issue.


-- 
           Summary: *_SECTION_ASM_OP storage has undocumented constraints
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Keywords: wrong-code, ice-on-valid-code, wrong-debug, link-
                    failure, assemble-failure
          Severity: normal
          Priority: P3
         Component: pch
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: amylaar at gcc dot gnu dot org


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

Reply via email to