* configure.ac (HAVE_AS_REL16): Test for R_PPC_REL16 relocs. * config.in: Regenerate. * configure: Regenerate. * config/rs6000/sysv4.h (MASK_DATA_PLT): Define. (SUBTARGET_SWITCHES): Add "data-plt" and "bss-plt". Move "newlib". (SUBTARGET_OVERRIDE_OPTIONS): Error if -mdata-plt given without assembler support. * config/rs6000/rs6000.h: Update target_flags free bits comment. (TARGET_DATA_PLT): Define. * config/rs6000/rs6000.c (rs6000_emit_load_toc_table): Handle TARGET_DATA_PLT got register load sequence. * config/rs6000/rs6000.md (elf_high, elf_low): Move after toc load insns. (load_toc_v4_PIC_1) Enable for TARGET_DATA_PLT. (load_toc_v4_PIC_3b, load_toc_v4_PIC_3c): New insns. (call, call_value): Mark pic_offset_table_rtx used for TARGET_DATA_PLT. (call_nonlocal_sysv, call_value_nonlocal_sysv, sibcall_nonlocal_sysv, sibcall_value_nonlocal_sysv): Add 32768 offset when TARGET_DATA_PLT and -fPIC. * config/rs6000/t-rs6000 (DATA_PLT): New shell variable. * config/rs6000/t-linux64 (TARGET_LIBGCC2_CFLAGS): Add $DATA_PLT. (MULTILIB_EXTRA_OPTS): Likewise. * config/rs6000/t-netbsd (MULTILIB_EXTRA_OPTS): Likewise. * config/rs6000/t-ppcos (MULTILIB_EXTRA_OPTS): Likewise. * config/rs6000/t-ppccomm (CRTSTUFF_T_CFLAGS_S): Likewise. diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/configure.ac gcc-3.4/gcc/configure.ac --- gcc-3.4-virgin/gcc/configure.ac 2005-01-13 16:01:15.000000000 +1030 +++ gcc-3.4/gcc/configure.ac 2005-05-18 14:17:30.000000000 +0930 @@ -2465,6 +2467,25 @@ changequote([,])dnl [$conftest_s],, [AC_DEFINE(HAVE_AS_MFCRF, 1, [Define if your assembler supports mfcr field.])]) + + case $target in + *-*-aix*) conftest_s=' .csect .text[[PR]] +LCF..0: + addis 11,30,_GLOBAL_OFFSET_TABLE_-LCF..0@ha';; + *-*-darwin*) + conftest_s=' .text +LCF0: + addis r11,r30,_GLOBAL_OFFSET_TABLE_-LCF0@ha';; + *) conftest_s=' .text +.LCF0: + addis 11,30,_GLOBAL_OFFSET_TABLE_-.LCF0@ha';; + esac + + gcc_GAS_CHECK_FEATURE([rel16 relocs], + gcc_cv_as_powerpc_rel16, [2,17,0], -a32, + [$conftest_s],, + [AC_DEFINE(HAVE_AS_REL16, 1, + [Define if your assembler supports R_PPC_REL16 relocs.])]) ;; mips*-*-*) diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/sysv4.h gcc-3.4/gcc/config/rs6000/sysv4.h --- gcc-3.4-virgin/gcc/config/rs6000/sysv4.h 2005-02-14 20:08:09.000000000 +1030 +++ gcc-3.4/gcc/config/rs6000/sysv4.h 2005-05-18 23:41:45.000000000 +0930 @@ -55,6 +55,7 @@ extern enum rs6000_sdata_type rs6000_sda #define MASK_REGNAMES 0x02000000 /* Use alternate register names. */ #define MASK_PROTOTYPE 0x01000000 /* Only prototyped fcns pass variable args. */ #define MASK_NO_BITFIELD_WORD 0x00800000 /* Bitfields cannot cross word boundaries */ +#define MASK_DATA_PLT 0x00400000 /* Use non-exec PLT/GOT. */ #define TARGET_NO_BITFIELD_TYPE (target_flags & MASK_NO_BITFIELD_TYPE) #define TARGET_STRICT_ALIGN (target_flags & MASK_STRICT_ALIGN) @@ -149,12 +150,16 @@ extern const char *rs6000_tls_size_strin N_("Set the PPC_EMB bit in the ELF flags header") }, \ { "windiss", 0, N_("Use the WindISS simulator") }, \ { "shlib", 0, N_("no description yet") }, \ + { "newlib", 0, N_("no description yet") }, \ { "64", MASK_64BIT | MASK_POWERPC64 | MASK_POWERPC, \ N_("Generate 64-bit code") }, \ { "32", - (MASK_64BIT | MASK_POWERPC64), \ N_("Generate 32-bit code") }, \ - EXTRA_SUBTARGET_SWITCHES \ - { "newlib", 0, N_("no description yet") }, + { "data-plt", MASK_DATA_PLT, \ + N_("Generate code for non-exec PLT and GOT") },\ + { "bss-plt", -MASK_DATA_PLT, \ + N_("Generate code for exec BSS PLT") }, \ + EXTRA_SUBTARGET_SWITCHES /* This is meant to be redefined in the host dependent files. */ #define EXTRA_SUBTARGET_SWITCHES @@ -294,6 +304,11 @@ do { \ error ("-mcall-aixdesc must be big endian"); \ } \ \ + if (TARGET_DATA_PLT != (target_flags & MASK_DATA_PLT)) \ + { \ + error ("-mdata-plt not supported by your assembler"); \ + } \ + \ /* Treat -fPIC the same as -mrelocatable. */ \ if (flag_pic > 1 && DEFAULT_ABI != ABI_AIX) \ target_flags |= MASK_RELOCATABLE | MASK_MINIMAL_TOC | MASK_NO_FP_IN_TOC; \ diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/rs6000.h gcc-3.4/gcc/config/rs6000/rs6000.h --- gcc-3.4-virgin/gcc/config/rs6000/rs6000.h 2005-02-22 15:19:24.000000000 +1030 +++ gcc-3.4/gcc/config/rs6000/rs6000.h 2005-05-17 16:53:52.000000000 +0930 @@ -197,8 +201,8 @@ extern int target_flags; /* Use single field mfcr instruction. */ #define MASK_MFCRF 0x00080000 -/* The only remaining free bits are 0x00600000. linux64.h uses - 0x00100000, and sysv4.h uses 0x00800000 -> 0x40000000. +/* The only remaining free bit is 0x00200000. linux64.h uses + 0x00100000, and sysv4.h uses 0x00400000 -> 0x40000000. 0x80000000 is not available because target_flags is signed. */ #define TARGET_POWER (target_flags & MASK_POWER) @@ -230,6 +234,11 @@ extern int target_flags; #define TARGET_MFCRF 0 #endif +#ifdef HAVE_AS_REL16 +#define TARGET_DATA_PLT (target_flags & MASK_DATA_PLT) +#else +#define TARGET_DATA_PLT 0 +#endif #define TARGET_32BIT (! TARGET_64BIT) #define TARGET_HARD_FLOAT (! TARGET_SOFT_FLOAT) diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/rs6000.c gcc-3.4/gcc/config/rs6000/rs6000.c --- gcc-3.4-virgin/gcc/config/rs6000/rs6000.c 2005-04-29 09:52:17.000000000 +0930 +++ gcc-3.4/gcc/config/rs6000/rs6000.c 2005-05-18 22:59:46.000000000 +0930 @@ -11452,15 +11502,49 @@ rs6000_emit_load_toc_table (int fromprol rtx dest, insn; dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); - if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1) + if (TARGET_ELF && TARGET_DATA_PLT && DEFAULT_ABI != ABI_AIX && flag_pic) { - rtx temp = (fromprolog - ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) - : gen_reg_rtx (Pmode)); - insn = emit_insn (gen_load_toc_v4_pic_si (temp)); + char buf[30]; + rtx lab, tmp1, tmp2, got, tempLR; + + ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); + lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); + if (flag_pic == 2) + got = gen_rtx_SYMBOL_REF (Pmode, toc_label_name); + else + got = rs6000_got_sym (); + tmp1 = tmp2 = dest; + if (!fromprolog) + { + tmp1 = gen_reg_rtx (Pmode); + tmp2 = gen_reg_rtx (Pmode); + } + tempLR = (fromprolog + ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) + : gen_reg_rtx (Pmode)); + insn = emit_insn (gen_load_toc_v4_PIC_1 (tempLR, lab)); if (fromprolog) rs6000_maybe_dead (insn); - insn = emit_move_insn (dest, temp); + insn = emit_move_insn (tmp1, tempLR); + if (fromprolog) + rs6000_maybe_dead (insn); + insn = emit_insn (gen_load_toc_v4_PIC_3b (tmp2, tmp1, got, lab)); + if (fromprolog) + rs6000_maybe_dead (insn); + insn = emit_insn (gen_load_toc_v4_PIC_3c (dest, tmp2, got, lab)); + if (fromprolog) + rs6000_maybe_dead (insn); + } + else if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1) + { + rtx tempLR = (fromprolog + ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) + : gen_reg_rtx (Pmode)); + + insn = emit_insn (gen_load_toc_v4_pic_si (tempLR)); + if (fromprolog) + rs6000_maybe_dead (insn); + insn = emit_move_insn (dest, tempLR); if (fromprolog) rs6000_maybe_dead (insn); } diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/rs6000.md gcc-3.4/gcc/config/rs6000/rs6000.md --- gcc-3.4-virgin/gcc/config/rs6000/rs6000.md 2005-03-31 21:07:06.000000000 +0930 +++ gcc-3.4/gcc/config/rs6000/rs6000.md 2005-05-19 20:14:57.000000000 +0930 @@ -7454,25 +7454,6 @@ ;; Now define ways of moving data around. -;; Elf specific ways of loading addresses for non-PIC code. -;; The output of this could be r0, but we make a very strong -;; preference for a base register because it will usually -;; be needed there. -(define_insn "elf_high" - [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r") - (high:SI (match_operand 1 "" "")))] - "TARGET_ELF && ! TARGET_64BIT" - "{liu|lis} %0,%1@ha") - -(define_insn "elf_low" - [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r") - (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r") - (match_operand 2 "" "")))] - "TARGET_ELF && ! TARGET_64BIT" - "@ - {cal|la} %0,%2@l(%1) - {ai|addic} %0,%1,%K2") - ;; Mach-O PIC trickery. (define_insn "macho_high" [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r") @@ -10044,7 +10026,8 @@ [(set (match_operand:SI 0 "register_operand" "=l") (match_operand:SI 1 "immediate_operand" "s")) (use (unspec [(match_dup 1)] UNSPEC_TOC))] - "TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2" + "TARGET_ELF && DEFAULT_ABI != ABI_AIX + && (flag_pic == 2 || (flag_pic && TARGET_DATA_PLT))" "bcl 20,31,%1\\n%1:" [(set_attr "type" "branch") (set_attr "length" "4")]) @@ -10067,6 +10050,23 @@ "{l|lwz} %0,%2-%3(%1)" [(set_attr "type" "load")]) +(define_insn "load_toc_v4_PIC_3b" + [(set (match_operand:SI 0 "gpc_reg_operand" "=b") + (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r") + (high:SI + (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s") + (match_operand:SI 3 "symbol_ref_operand" "s")))))] + "TARGET_ELF && TARGET_DATA_PLT && DEFAULT_ABI != ABI_AIX && flag_pic" + "{cau|addis} %0,%1,%2-%3@ha") + +(define_insn "load_toc_v4_PIC_3c" + [(set (match_operand:SI 0 "gpc_reg_operand" "=r") + (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b") + (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s") + (match_operand:SI 3 "symbol_ref_operand" "s"))))] + "TARGET_ELF && TARGET_DATA_PLT && DEFAULT_ABI != ABI_AIX && flag_pic" + "{cal|addi} %0,%1,%2-%3@l") + (define_insn "load_macho_picbase" [(set (match_operand:SI 0 "register_operand" "=l") (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")] @@ -10119,6 +10119,26 @@ rs6000_emit_load_toc_table (FALSE); DONE; }") + +;; Elf specific ways of loading addresses for non-PIC code. +;; The output of this could be r0, but we make a very strong +;; preference for a base register because it will usually +;; be needed there. +(define_insn "elf_high" + [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r") + (high:SI (match_operand 1 "" "")))] + "TARGET_ELF && ! TARGET_64BIT" + "{liu|lis} %0,%1@ha") + +(define_insn "elf_low" + [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r") + (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r") + (match_operand 2 "" "")))] + "TARGET_ELF && ! TARGET_64BIT" + "@ + {cal|la} %0,%2@l(%1) + {ai|addic} %0,%1,%K2") + ;; A function pointer under AIX is a pointer to a data area whose first word ;; contains the actual address of the function, whose second word contains a @@ -10235,6 +10255,25 @@ operands[0] = XEXP (operands[0], 0); + if (DEFAULT_ABI == ABI_V4 && TARGET_DATA_PLT + && flag_pic + && GET_CODE (operands[0]) == SYMBOL_REF + && !SYMBOL_REF_LOCAL_P (operands[0])) + { + rtx call; + rtvec tmp; + + tmp = gen_rtvec (3, + gen_rtx_CALL (VOIDmode, + gen_rtx_MEM (SImode, operands[0]), + operands[1]), + gen_rtx_USE (VOIDmode, operands[2]), + gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode))); + call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp)); + use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx); + DONE; + } + if (GET_CODE (operands[0]) != SYMBOL_REF || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[0])) || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[2]) & CALL_LONG) != 0)) @@ -10283,6 +10322,28 @@ operands[1] = XEXP (operands[1], 0); + if (DEFAULT_ABI == ABI_V4 && TARGET_DATA_PLT + && flag_pic + && GET_CODE (operands[1]) == SYMBOL_REF + && !SYMBOL_REF_LOCAL_P (operands[1])) + { + rtx call; + rtvec tmp; + + tmp = gen_rtvec (3, + gen_rtx_SET (VOIDmode, + operands[0], + gen_rtx_CALL (VOIDmode, + gen_rtx_MEM (SImode, + operands[1]), + operands[2])), + gen_rtx_USE (VOIDmode, operands[3]), + gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (SImode))); + call = emit_call_insn (gen_rtx_PARALLEL (VOIDmode, tmp)); + use_reg (&CALL_INSN_FUNCTION_USAGE (call), pic_offset_table_rtx); + DONE; + } + if (GET_CODE (operands[1]) != SYMBOL_REF || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (operands[1])) || (DEFAULT_ABI != ABI_DARWIN && (INTVAL (operands[3]) & CALL_LONG) != 0)) @@ -10553,7 +10613,18 @@ #if TARGET_MACHO return output_call(insn, operands, 0, 2); #else - return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@plt" : "bl %z0"; + if (DEFAULT_ABI == ABI_V4 && flag_pic) + { + if (TARGET_DATA_PLT && flag_pic == 2) + /* The magic 32768 offset here and in the other sysv call insns + corresponds to the offset of r30 in .got2, as given by LCTOC1. + See sysv4.h:toc_section. */ + return "bl %z0+32768@plt"; + else + return "bl %z0@plt"; + } + else + return "bl %z0"; #endif } [(set_attr "type" "branch,branch") @@ -10598,7 +10669,15 @@ #if TARGET_MACHO return output_call(insn, operands, 1, 3); #else - return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@plt" : "bl %z1"; + if (DEFAULT_ABI == ABI_V4 && flag_pic) + { + if (TARGET_DATA_PLT && flag_pic == 2) + return "bl %z1+32768@plt"; + else + return "bl %z1@plt"; + } + else + return "bl %z1"; #endif } [(set_attr "type" "branch,branch") @@ -10813,7 +10891,15 @@ else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn (\"creqv 6,6,6\", operands); - return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z0@plt\" : \"b %z0\"; + if (DEFAULT_ABI == ABI_V4 && flag_pic) + { + if (TARGET_DATA_PLT && flag_pic == 2) + return \"b %z0+32768@plt\"; + else + return \"b %z0@plt\"; + } + else + return \"b %z0\"; }" [(set_attr "type" "branch,branch") (set_attr "length" "4,8")]) @@ -10859,7 +10944,15 @@ else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn (\"creqv 6,6,6\", operands); - return (DEFAULT_ABI == ABI_V4 && flag_pic) ? \"b %z1@plt\" : \"b %z1\"; + if (DEFAULT_ABI == ABI_V4 && flag_pic) + { + if (TARGET_DATA_PLT && flag_pic == 2) + return \"b %z1+32768@plt\"; + else + return \"b %z1@plt\"; + } + else + return \"b %z1\"; }" [(set_attr "type" "branch,branch") (set_attr "length" "4,8")]) diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/t-rs6000 gcc-3.4/gcc/config/rs6000/t-rs6000 --- gcc-3.4-virgin/gcc/config/rs6000/t-rs6000 2003-06-16 10:39:14.000000000 +0930 +++ gcc-3.4/gcc/config/rs6000/t-rs6000 2005-05-18 14:27:25.000000000 +0930 @@ -18,3 +18,6 @@ rs6000-c.o: $(srcdir)/config/rs6000/rs60 # The rs6000 backend doesn't cause warnings in these files. insn-conditions.o-warn = + +# Whether to use -mdata-plt in other t-files. +DATA_PLT := $(shell sed -n -e 's/\#define HAVE_AS_REL16 1/mdata-plt/p' auto-host.h) diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/t-linux64 gcc-3.4/gcc/config/rs6000/t-linux64 --- gcc-3.4-virgin/gcc/config/rs6000/t-linux64 2005-03-02 09:09:26.000000000 +1030 +++ gcc-3.4/gcc/config/rs6000/t-linux64 2005-05-19 20:16:53.000000000 +0930 @@ -5,13 +5,13 @@ LIB2FUNCS_EXTRA = tramp.S $(srcdir)/conf LIB2FUNCS_STATIC_EXTRA = eabi.S $(srcdir)/config/rs6000/darwin-ldouble.c LIB2FUNCS_SHARED_EXTRA = $(srcdir)/config/rs6000/darwin-ldouble-shared.c -TARGET_LIBGCC2_CFLAGS = -mno-minimal-toc -fPIC -specs=bispecs +TARGET_LIBGCC2_CFLAGS = -mno-minimal-toc -fPIC $(DATA_PLT:m%=-m%) -specs=bispecs SHLIB_MAPFILES += $(srcdir)/config/rs6000/libgcc-ppc64.ver MULTILIB_OPTIONS = m64/m32 msoft-float MULTILIB_DIRNAMES = 64 32 nof -MULTILIB_EXTRA_OPTS = fPIC mstrict-align +MULTILIB_EXTRA_OPTS = fPIC $(DATA_PLT) mstrict-align MULTILIB_EXCEPTIONS = m64/msoft-float MULTILIB_EXCLUSIONS = m64/!m32/msoft-float MULTILIB_OSDIRNAMES = ../lib64 ../lib nof diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/t-netbsd gcc-3.4/gcc/config/rs6000/t-netbsd --- gcc-3.4-virgin/gcc/config/rs6000/t-netbsd 2002-11-26 10:35:07.000000000 +1030 +++ gcc-3.4/gcc/config/rs6000/t-netbsd 2005-05-19 20:16:53.000000000 +0930 @@ -26,7 +26,7 @@ MULTILIB_MATCHES_FLOAT = msoft-float=mcp MULTILIB_OPTIONS = msoft-float MULTILIB_DIRNAMES = soft-float -MULTILIB_EXTRA_OPTS = fPIC mstrict-align +MULTILIB_EXTRA_OPTS = fPIC $(DATA_PLT) mstrict-align MULTILIB_EXCEPTIONS = MULTILIB_MATCHES = ${MULTILIB_MATCHES_FLOAT} diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/t-ppccomm gcc-3.4/gcc/config/rs6000/t-ppccomm --- gcc-3.4-virgin/gcc/config/rs6000/t-ppccomm 2002-12-20 22:53:07.000000000 +1030 +++ gcc-3.4/gcc/config/rs6000/t-ppccomm 2005-05-19 20:16:53.000000000 +0930 @@ -60,4 +60,4 @@ $(T)crtsavres$(objext): crtsavres.S CRTSTUFF_T_CFLAGS = -msdata=none # Make sure crt*.o are built with -fPIC even if configured with # --enable-shared --disable-multilib -CRTSTUFF_T_CFLAGS_S = -fPIC -msdata=none +CRTSTUFF_T_CFLAGS_S = -fPIC $(DATA_PLT:m%=-m%) -msdata=none diff -urp -xCVS -x'*~' -x'.#*' gcc-3.4-virgin/gcc/config/rs6000/t-ppcos gcc-3.4/gcc/config/rs6000/t-ppcos --- gcc-3.4-virgin/gcc/config/rs6000/t-ppcos 2001-11-25 00:32:46.000000000 +1030 +++ gcc-3.4/gcc/config/rs6000/t-ppcos 2005-05-19 20:16:53.000000000 +0930 @@ -2,7 +2,7 @@ MULTILIB_OPTIONS = msoft-float MULTILIB_DIRNAMES = nof -MULTILIB_EXTRA_OPTS = fPIC mstrict-align +MULTILIB_EXTRA_OPTS = fPIC $(DATA_PLT) mstrict-align MULTILIB_EXCEPTIONS = MULTILIB_MATCHES = ${MULTILIB_MATCHES_FLOAT}