When generating non-PIC code on Linux, the linker support allows us to put both local and global relocs in read-only data. On HP-UX, we can put local relocs in read-only data. We can also put constant data in read-only data on the HP-UX SOM target when generating PIC code.
This patch implements the above. Tested on hppa2.0w-hp-hpux11.11, hppa64-hp-hpux11.11 and hppa-unknown-linux-gnu. Committed to trunk and gcc-9. Dave -- John David Anglin dave.ang...@bell.net 2019-07-17 John David Anglin <dang...@gcc.gnu.org> * config/pa/pa.c (pa_som_asm_init_sections): Don't force all constant data into data section when generating PIC code. (pa_select_section): Use pa_reloc_rw_mask() to qualify relocs. (pa_reloc_rw_mask): Return 3 when generating PIC code and when generating code for SOM targets earlier than HP-UX 11. Otherwise, return 2 for SOM and 0 for other targets. Index: config/pa/pa.c =================================================================== --- config/pa/pa.c (revision 273480) +++ config/pa/pa.c (working copy) @@ -9805,20 +9805,23 @@ = get_unnamed_section (0, output_section_asm_op, "\t.SPACE $PRIVATE$\n\t.SUBSPA $TM_CLONE_TABLE$"); - /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups - which reference data within the $TEXT$ space (for example constant + /* HPUX ld generates incorrect GOT entries for "T" fixups which + reference data within the $TEXT$ space (for example constant strings in the $LIT$ subspace). The assemblers (GAS and HP as) both have problems with handling - the difference of two symbols which is the other correct way to + the difference of two symbols. This is the other correct way to reference constant data during PIC code generation. - So, there's no way to reference constant data which is in the - $TEXT$ space during PIC generation. Instead place all constant - data into the $PRIVATE$ subspace (this reduces sharing, but it - works correctly). */ - readonly_data_section = flag_pic ? data_section : som_readonly_data_section; + Thus, we can't put constant data needing relocation in the $TEXT$ + space during PIC generation. + Previously, we placed all constant data into the $DATA$ subspace + when generating PIC code. This reduces sharing, but it works + correctly. Now we rely on pa_reloc_rw_mask() for section selection. + This puts constant data not needing relocation into the $TEXT$ space. */ + readonly_data_section = som_readonly_data_section; + /* We must not have a reference to an external symbol defined in a shared library in a readonly section, else the SOM linker will complain. @@ -9850,7 +9853,7 @@ && DECL_INITIAL (exp) && (DECL_INITIAL (exp) == error_mark_node || TREE_CONSTANT (DECL_INITIAL (exp))) - && !reloc) + && !(reloc & pa_reloc_rw_mask ())) { if (TARGET_SOM && DECL_ONE_ONLY (exp) @@ -9859,7 +9862,8 @@ else return readonly_data_section; } - else if (CONSTANT_CLASS_P (exp) && !reloc) + else if (CONSTANT_CLASS_P (exp) + && !(reloc & pa_reloc_rw_mask ())) return readonly_data_section; else if (TARGET_SOM && TREE_CODE (exp) == VAR_DECL @@ -9875,12 +9879,11 @@ static int pa_reloc_rw_mask (void) { - /* We force (const (plus (symbol) (const_int))) to memory when the - const_int doesn't fit in a 14-bit integer. The SOM linker can't - handle this construct in read-only memory and we want to avoid - this for ELF. So, we always force an RTX needing relocation to - the data section. */ - return 3; + if (flag_pic || (TARGET_SOM && !TARGET_HPUX_11)) + return 3; + + /* HP linker does not support global relocs in readonly memory. */ + return TARGET_SOM ? 2 : 0; } static void