Relocations put in read-only segment?

Charles M. Hannum mycroft@mit.edu
Fri Apr 24 16:23:00 GMT 1998


Jeffrey A Law <law@hurl.cygnus.com> writes:

>   In message < 199804240119.VAA15305@lunacity.ne.mediaone.net >you write:
>   > When I compile the following code with egcs 1.0.2, using `-O -fPIC',
>   > on either i386-*-netbsd or i586-*-linux-gnulibc1, the relocation for
>   > `XtStrings+788' is put in a read-only section (the text section under
>   > NetBSD, rodata under Linux).  While it's true that ld.so on both
>   > platforms is careful to make this work, it's canonically wrong.  If
>   > the relocation is done in a data section at all, it should be in a
>   > writable section.
> This is a pretty common problem; generally it's fixed by having
> SELECT_SECTION and related functions put these things into the
> data section for PIC code generation.  Unfortunately many ports
> do not handle this case correctly.

That doesn't quite follow.  There is currently no SELECT_SECTION on
the platforms I mentioned.  This means they use the default code:

      if (DECL_READONLY_SECTION (decl, reloc))
        readonly_data_section ();
      else
        data_section ();

Note that DECL_READONLY_SECTION specifically does:

   && ! (RELOC && (flag_pic || DECL_ONE_ONLY (DECL))))

This implies that `reloc' is false in this case, which would be a bug.




More information about the Gcc mailing list