On Wed, Apr 18, 2018 at 6:57 PM, Michael Eager <[email protected]> wrote:
>
> Hi Andrew --
>
> Check indents in the following files:
> (Make sure that your tabs are set at 8 chars.)
> --- gcc/config/microblaze/microblaze.c
> --- gcc/config/microblaze/microblaze.md
>
I have re-run check_GNU_Style.sh and no are issues are found now.
> Just a couple coding notes:
>
> microblaze.c:
>
> @@ -858,6 +879,16 @@ microblaze_classify_address (struct microblaze_add
> + && strict == 2)
>
> Include comment in function header describing meaning of strict == 2.
Done
>
> @@ -1022,7 +1065,7 @@ microblaze_legitimize_address (rtx x, rtx oldx ATT
> else if (flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL)
> {
> ...
> }
> else if (flag_pic == 2 && TARGET_PIC_DATA_TEXT_REL)
> {
> ...
> }
>
> It's better to factor this into
> else if (flag_pic == 2)
> {
> if (TARGET_PIC_DATA_TEXT_REL)
> {
> ...
> }
> else
> {
> ...
> }
> }
>
Done
> microblaze.md:
>
> @@ -1848,7 +1850,7 @@
>
> + if (!flag_pic || (flag_pic && TARGET_PIC_DATA_TEXT_REL))
>
> Test for flag_pic is redundant. This can be
>
> + if (!flag_pic || TARGET_PIC_DATA_TEXT_REL)
Done
> doc/invoke.texi:
> -mpic-data-text-rel -- include description
> Is this different from -mpic-data-is-text-relative?
> (Yes, that's a bit of a wordy option.)
Changed the name and added description, now it's like ARM's option
> doc/tm.texi:
> +Return a flag for either generating ADDR_DIF_VEC table
> +or ADDR_VEC table for jumps in case of -fPIC.
>
> Explicitly state what true or false means.
Done
> target.def:
>
> +(generate_pic_addr_diff_vec,
>
> Explicitly state what true or false means.
Done
> targhooks.c:
>
> +bool
> +default_generate_pic_addr_diff_vec (void)
> +{
> + return true;
> +}
>
> This doesn't appear to match the description in target.def.
>
Adapted
>
> --
> Michael Eager [email protected]
>
> 1960 Park Blvd., Palo Alto, CA 94306
Please find patch attached
and also in
(https://github.com/andrewsadek/microblaze-pic-data-text-rel/blob/pic_data_text_rel/PATCH_BUNDLE/gcc.patch)
--
Andrew
Index: gcc/config/microblaze/microblaze-protos.h
===================================================================
--- gcc/config/microblaze/microblaze-protos.h (revision 258312)
+++ gcc/config/microblaze/microblaze-protos.h (working copy)
@@ -24,6 +24,7 @@
#ifdef RTX_CODE
extern int pic_address_needs_scratch (rtx);
+extern bool microblaze_constant_address_p (rtx x);
extern void expand_block_move (rtx *);
extern void microblaze_expand_prologue (void);
extern void microblaze_expand_epilogue (void);
Index: gcc/config/microblaze/microblaze.c
===================================================================
--- gcc/config/microblaze/microblaze.c (revision 258312)
+++ gcc/config/microblaze/microblaze.c (working copy)
@@ -91,7 +91,8 @@ enum microblaze_address_type
ADDRESS_SYMBOLIC,
ADDRESS_GOTOFF,
ADDRESS_PLT,
- ADDRESS_TLS
+ ADDRESS_TLS,
+ ADDRESS_SYMBOLIC_TXT_REL
};
/* Classifies symbols
@@ -650,6 +651,10 @@ microblaze_classify_unspec (struct microblaze_addr
info->type = ADDRESS_TLS;
info->tls_type = tls_reloc (INTVAL (XVECEXP (x, 0, 1)));
}
+ else if (XINT (x, 1) == UNSPEC_TEXT)
+ {
+ info->type = ADDRESS_SYMBOLIC_TXT_REL;
+ }
else
{
return false;
@@ -701,8 +706,10 @@ get_base_reg (rtx x)
}
/* Return true if X is a valid address for machine mode MODE. If it is,
- fill in INFO appropriately. STRICT is true if we should only accept
- hard base registers.
+ fill in INFO appropriately.
+ STRICT > 0 if we should only accept hard base registers.
+ STRICT = 2 if the operand address is being printed thus
+ function has been called by print_operand_address.
type regA regB offset symbol
@@ -728,6 +735,7 @@ microblaze_classify_address (struct microblaze_add
{
rtx xplus0;
rtx xplus1;
+ rtx offset;
info->type = ADDRESS_INVALID;
info->regA = NULL;
@@ -735,6 +743,7 @@ microblaze_classify_address (struct microblaze_add
info->offset = NULL;
info->symbol = NULL;
info->symbol_type = SYMBOL_TYPE_INVALID;
+ offset = NULL;
switch (GET_CODE (x))
{
@@ -795,9 +804,14 @@ microblaze_classify_address (struct microblaze_add
/* for (plus x const_int) just look at x. */
if (GET_CODE (xconst0) == PLUS
&& GET_CODE (XEXP (xconst0, 1)) == CONST_INT
- && SMALL_INT (XEXP (xconst0, 1)))
+ && (SMALL_INT (XEXP (xconst0, 1))
+ || GET_CODE (XEXP (xconst0, 0)) == UNSPEC))
{
- /* This is ok as info->symbol is set to xplus1 the full
+ /* Hold CONST_INT Value in offset in case of
+ UNSPEC + CONST_INT. */
+ offset = XEXP (xconst0, 1);
+
+ /* This is ok as info->symbol is set to xplus1 the full
const-expression below. */
xconst0 = XEXP (xconst0, 0);
}
@@ -814,6 +828,15 @@ microblaze_classify_address (struct microblaze_add
return true;
}
+ if (GET_CODE (xconst0) == UNSPEC && TARGET_PIC_DATA_TEXT_REL)
+ {
+ if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
+ return false;
+
+ info->offset = offset;
+ return microblaze_classify_unspec (info, xconst0);
+ }
+
/* Not base + symbol || base + UNSPEC. */
return false;
@@ -858,6 +881,16 @@ microblaze_classify_address (struct microblaze_add
return !(flag_pic && pic_address_needs_scratch (x));
}
+ /* Avoid error in print_operand_address in case UNSPEC
+ is removed from SYMBOL or LABEL REFS during optimization. */
+ if ((GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
+ && flag_pic && TARGET_PIC_DATA_TEXT_REL
+ && strict == 2)
+ {
+ info->type = ADDRESS_SYMBOLIC_TXT_REL;
+ return true;
+ }
+
if (flag_pic == 2)
return false;
else if (microblaze_tls_symbol_p(x))
@@ -891,8 +924,18 @@ microblaze_legitimate_address_p (machine_mode mode
struct microblaze_address_info addr;
return microblaze_classify_address (&addr, x, mode, strict);
+
}
+bool
+microblaze_constant_address_p (rtx x)
+{
+ return ((GET_CODE (x) == LABEL_REF) || (GET_CODE (x) == SYMBOL_REF)
+ || GET_CODE (x) == CONST_INT
+ || (GET_CODE (x) == CONST
+ && ! (flag_pic && pic_address_needs_scratch (x))));
+}
+
int
microblaze_valid_pic_const (rtx x)
{
@@ -910,9 +953,11 @@ microblaze_valid_pic_const (rtx x)
int
microblaze_legitimate_pic_operand (rtx x)
{
- if (flag_pic == 2 && (symbol_mentioned_p(x) || label_mentioned_p(x)))
+ if (flag_pic == 2 && (symbol_mentioned_p (x) || label_mentioned_p (x))
+ && !(TARGET_PIC_DATA_TEXT_REL && call_insn_operand (x,VOIDmode)))
return 0;
+
if (microblaze_tls_referenced_p(x))
return 0;
@@ -1023,19 +1068,37 @@ microblaze_legitimize_address (rtx x, rtx oldx ATT
return result;
}
else if (flag_pic == 2)
- {
- rtx pic_ref, reg;
- reg = gen_reg_rtx (Pmode);
+ {
+ if (!TARGET_PIC_DATA_TEXT_REL)
+ {
+ rtx pic_ref, reg;
+ reg = gen_reg_rtx (Pmode);
- pic_ref = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xplus1),
- UNSPEC_GOTOFF);
- pic_ref = gen_rtx_CONST (Pmode, pic_ref);
- pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pic_ref);
- pic_ref = gen_const_mem (Pmode, pic_ref);
- emit_move_insn (reg, pic_ref);
- result = gen_rtx_PLUS (Pmode, xplus0, reg);
- return result;
- }
+ pic_ref = gen_rtx_UNSPEC (Pmode,
+ gen_rtvec (1, xplus1),
+ UNSPEC_GOTOFF);
+ pic_ref = gen_rtx_CONST (Pmode, pic_ref);
+ pic_ref = gen_rtx_PLUS (Pmode,
+ pic_offset_table_rtx, pic_ref);
+ pic_ref = gen_const_mem (Pmode, pic_ref);
+ emit_move_insn (reg, pic_ref);
+ result = gen_rtx_PLUS (Pmode, xplus0, reg);
+ return result;
+ }
+ else
+ {
+ rtx pic_ref, reg;
+ reg = gen_reg_rtx (Pmode);
+ pic_ref = gen_rtx_UNSPEC (Pmode,
+ gen_rtvec (1, xplus1),
+ UNSPEC_TEXT);
+ pic_ref = gen_rtx_CONST (Pmode, pic_ref);
+ emit_insn (gen_addsi3 (reg,
+ pic_offset_table_rtx, xplus0));
+ result = gen_rtx_PLUS (Pmode, reg, pic_ref);
+ return result;
+ }
+ }
}
}
}
@@ -1047,7 +1110,7 @@ microblaze_legitimize_address (rtx x, rtx oldx ATT
{
reg = microblaze_legitimize_tls_address (xinsn, NULL_RTX);
}
- else
+ else if (flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL)
{
rtx pic_ref;
@@ -1060,6 +1123,19 @@ microblaze_legitimize_address (rtx x, rtx oldx ATT
pic_ref = gen_const_mem (Pmode, pic_ref);
reg = pic_ref;
}
+ else if (flag_pic == 2 && TARGET_PIC_DATA_TEXT_REL)
+ {
+ rtx pic_ref;
+
+ if (reload_in_progress)
+ df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
+
+ pic_ref = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xinsn), UNSPEC_TEXT);
+ pic_ref = gen_rtx_CONST (Pmode, pic_ref);
+ pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pic_ref);
+ reg = pic_ref;
+
+ }
return reg;
}
@@ -1388,6 +1464,7 @@ microblaze_address_insns (rtx x, machine_mode mode
case ADDRESS_REG_INDEX:
return 1;
case ADDRESS_SYMBOLIC:
+ case ADDRESS_SYMBOLIC_TXT_REL:
case ADDRESS_GOTOFF:
return 2;
case ADDRESS_TLS:
@@ -2066,7 +2143,7 @@ compute_frame_size (HOST_WIDE_INT size)
total_size = var_size + args_size;
- if (flag_pic == 2)
+ if (flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL)
/* force setting GOT. */
df_set_regs_ever_live (MB_ABI_PIC_ADDR_REGNUM, true);
@@ -2322,6 +2399,7 @@ print_operand (FILE * file, rtx op, int letter)
case ADDRESS_REG:
case ADDRESS_CONST_INT:
case ADDRESS_SYMBOLIC:
+ case ADDRESS_SYMBOLIC_TXT_REL:
case ADDRESS_GOTOFF:
case ADDRESS_TLS:
fputs ("i", file);
@@ -2489,7 +2567,7 @@ print_operand_address (FILE * file, rtx addr)
{
struct microblaze_address_info info;
enum microblaze_address_type type;
- if (!microblaze_classify_address (&info, addr, GET_MODE (addr), 1))
+ if (!microblaze_classify_address (&info, addr, GET_MODE (addr), 2))
fatal_insn ("insn contains an invalid address !", addr);
type = info.type;
@@ -2515,6 +2593,7 @@ print_operand_address (FILE * file, rtx addr)
output_addr_const (file, info.offset);
break;
case ADDRESS_SYMBOLIC:
+ case ADDRESS_SYMBOLIC_TXT_REL:
case ADDRESS_GOTOFF:
case ADDRESS_PLT:
case ADDRESS_TLS:
@@ -2529,6 +2608,16 @@ print_operand_address (FILE * file, rtx addr)
{
fputs ("@PLT", file);
}
+ else if (type == ADDRESS_SYMBOLIC_TXT_REL)
+ {
+ if (info.offset != NULL && CONST_INT_P (info.offset)
+ && INTVAL (info.offset) > 0)
+ {
+ fprintf (file, "+");
+ output_addr_const (file, info.offset);
+ }
+ fputs ("@TXTREL", file);
+ }
else if (type == ADDRESS_TLS)
{
switch (info.tls_type)
@@ -2960,8 +3049,19 @@ microblaze_expand_prologue (void)
if ((flag_pic == 2 || TLS_NEEDS_GOT )
&& df_regs_ever_live_p (MB_ABI_PIC_ADDR_REGNUM))
{
- SET_REGNO (pic_offset_table_rtx, MB_ABI_PIC_ADDR_REGNUM);
- emit_insn (gen_set_got (pic_offset_table_rtx)); /* setting GOT. */
+ if ((flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL) || TLS_NEEDS_GOT)
+ {
+ SET_REGNO (pic_offset_table_rtx, MB_ABI_PIC_ADDR_REGNUM);
+ /* setting GOT. */
+ emit_insn (gen_set_got (pic_offset_table_rtx));
+ }
+ else
+ {
+ SET_REGNO (pic_offset_table_rtx, MB_ABI_PIC_ADDR_REGNUM);
+ /* setting start of text. */
+ emit_insn (gen_set_text (pic_offset_table_rtx));
+
+ }
}
/* If we are profiling, make sure no instructions are scheduled before
@@ -3154,7 +3254,15 @@ microblaze_elf_in_small_data_p (const_tree decl)
return (size > 0 && size <= microblaze_section_threshold);
}
+/* We need to disable address diff vectors in
+case of pic data text relative mode. */
+static bool
+microblaze_gen_pic_addr_dif_vec (void)
+{
+ return (flag_pic && !TARGET_PIC_DATA_TEXT_REL);
+}
+
static section *
microblaze_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
{
@@ -3187,10 +3295,19 @@ static rtx
expand_pic_symbol_ref (machine_mode mode ATTRIBUTE_UNUSED, rtx op)
{
rtx result;
- result = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), UNSPEC_GOTOFF);
+ bool isFunc = (GET_CODE (op) == SYMBOL_REF
+ && (SYMBOL_REF_FLAGS (op) & SYMBOL_FLAG_FUNCTION));
+ result = (!TARGET_PIC_DATA_TEXT_REL)
+ ? gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), UNSPEC_GOTOFF):
+ gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), UNSPEC_TEXT);
result = gen_rtx_CONST (Pmode, result);
- result = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, result);
- result = gen_const_mem (Pmode, result);
+ result = (TARGET_PIC_DATA_TEXT_REL && isFunc)
+ ? gen_rtx_PLUS (Pmode, gen_raw_REG (Pmode,
+ get_base_reg (op)), result):
+ gen_rtx_PLUS (Pmode, pic_offset_table_rtx, result);
+ result = (!TARGET_PIC_DATA_TEXT_REL)
+ ? gen_const_mem (Pmode, result) : result;
+
return result;
}
@@ -3294,10 +3411,38 @@ microblaze_expand_move (machine_mode mode, rtx ope
if (reload_in_progress)
df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
result = expand_pic_symbol_ref (mode, op1);
+
+ if (TARGET_PIC_DATA_TEXT_REL && GET_CODE (op0) == REG
+ && REGNO (op0) >= FIRST_PSEUDO_REGISTER)
+ result = force_reg (SImode, result);
+
emit_move_insn (op0, result);
return true;
}
}
+ if (GET_CODE (op1) == PLUS && GET_CODE (XEXP (op1,1)) == CONST)
+ {
+ rtx p0, p1, result, temp;
+
+ p0 = XEXP (XEXP (op1,1), 0);
+
+ if (GET_CODE (p0) == PLUS)
+ {
+ p1 = XEXP (p0, 1);
+ p0 = XEXP (p0, 0);
+ }
+
+ if (GET_CODE (p0) == UNSPEC && GET_CODE (p1) == CONST_INT
+ && flag_pic && TARGET_PIC_DATA_TEXT_REL)
+ {
+ result = gen_rtx_CONST (Pmode, p0);
+ result = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, result);
+ temp = force_reg (SImode, result);
+ emit_move_insn (op0, gen_rtx_PLUS (SImode, temp, p1));
+ return true;
+ }
+
+ }
/* Handle Case of (const (plus symbol const_int)). */
if (GET_CODE (op1) == CONST && GET_CODE (XEXP (op1,0)) == PLUS)
{
@@ -3912,6 +4057,9 @@ microblaze_starting_frame_offset (void)
#undef TARGET_LEGITIMATE_CONSTANT_P
#define TARGET_LEGITIMATE_CONSTANT_P microblaze_legitimate_constant_p
+#undef TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+#define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC microblaze_gen_pic_addr_dif_vec
+
#undef TARGET_MACHINE_DEPENDENT_REORG
#define TARGET_MACHINE_DEPENDENT_REORG microblaze_machine_dependent_reorg
Index: gcc/config/microblaze/microblaze.h
===================================================================
--- gcc/config/microblaze/microblaze.h (revision 258312)
+++ gcc/config/microblaze/microblaze.h (working copy)
@@ -518,11 +518,7 @@ typedef struct microblaze_args
/* Identify valid constant addresses. Exclude if PIC addr which
needs scratch register. */
-#define CONSTANT_ADDRESS_P(X) \
- (GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF \
- || GET_CODE (X) == CONST_INT \
- || (GET_CODE (X) == CONST \
- && ! (flag_pic && pic_address_needs_scratch (X))))
+#define CONSTANT_ADDRESS_P(X) microblaze_constant_address_p(X)
/* Define this, so that when PIC, reload won't try to reload invalid
addresses which require two reload registers. */
Index: gcc/config/microblaze/microblaze.md
===================================================================
--- gcc/config/microblaze/microblaze.md (revision 258312)
+++ gcc/config/microblaze/microblaze.md (working copy)
@@ -41,6 +41,8 @@
(UNSPEC_CMP 104) ;; signed compare
(UNSPEC_CMPU 105) ;; unsigned compare
(UNSPEC_TLS 106) ;; jump table
+ (UNSPEC_SET_TEXT 107) ;; set text start
+ (UNSPEC_TEXT 108) ;; data text relative
])
(define_c_enum "unspec" [
@@ -1848,7 +1850,7 @@
{
gcc_assert (GET_MODE (operands[0]) == Pmode);
- if (!flag_pic)
+ if (!flag_pic || TARGET_PIC_DATA_TEXT_REL)
emit_jump_insn (gen_tablejump_internal1 (operands[0], operands[1]));
else
emit_jump_insn (gen_tablejump_internal3 (operands[0], operands[1]));
@@ -2053,7 +2055,8 @@
{
rtx addr = XEXP (operands[0], 0);
- if (flag_pic == 2 && GET_CODE (addr) == SYMBOL_REF
+ if (flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL
+ && GET_CODE (addr) == SYMBOL_REF
&& !SYMBOL_REF_LOCAL_P (addr))
{
rtx temp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PLT);
@@ -2156,7 +2159,8 @@
{
rtx addr = XEXP (operands[1], 0);
- if (flag_pic == 2 && GET_CODE (addr) == SYMBOL_REF
+ if (flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL
+ && GET_CODE (addr) == SYMBOL_REF
&& !SYMBOL_REF_LOCAL_P (addr))
{
rtx temp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PLT);
@@ -2313,6 +2317,18 @@
[(set_attr "type" "multi")
(set_attr "length" "12")])
+;; The insn to set TEXT.
+;; The hardcoded number "8" accounts for $pc difference
+;; between "mfs" and "addik" instructions.
+(define_insn "set_text"
+ [(set (match_operand:SI 0 "register_operand" "=r")
+ (unspec:SI[(const_int 0)] UNSPEC_SET_TEXT))]
+ ""
+ "mfs\t%0,rpc\n\taddik\t%0,%0,8@TXTPCREL"
+ [(set_attr "type" "multi")
+ (set_attr "length" "12")])
+
+
;; This insn gives the count of leading number of zeros for the second
;; operand and stores the result in first operand.
(define_insn "clzsi2"
Index: gcc/config/microblaze/microblaze.opt
===================================================================
--- gcc/config/microblaze/microblaze.opt (revision 258312)
+++ gcc/config/microblaze/microblaze.opt (working copy)
@@ -127,5 +127,9 @@ mxl-prefetch
Target Mask(PREFETCH)
Use hardware prefetch instruction
+mpic-data-is-text-relative
+Target Mask(PIC_DATA_TEXT_REL)
+Data referenced by offset from start of text instead of GOT (with -fPIC/-fPIE).
+
mxl-mode-xilkernel
Target
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi (revision 258312)
+++ gcc/doc/invoke.texi (working copy)
@@ -867,7 +867,8 @@ Objective-C and Objective-C++ Dialects}.
-mmemcpy -mxl-soft-mul -mxl-soft-div -mxl-barrel-shift @gol
-mxl-pattern-compare -mxl-stack-check -mxl-gp-opt -mno-clearbss @gol
-mxl-multiply-high -mxl-float-convert -mxl-float-sqrt @gol
--mbig-endian -mlittle-endian -mxl-reorder -mxl-mode-@var{app-model}}
+-mbig-endian -mlittle-endian -mxl-reorder -mxl-mode-@var{app-model}
+-mpic-data-is-text-relative}
@emph{MIPS Options}
@gccoptlist{-EL -EB -march=@var{arch} -mtune=@var{arch} @gol
@@ -20095,6 +20096,12 @@ Select application model @var{app-model}. Valid m
@item executable
normal executable (default), uses startup code @file{crt0.o}.
+@item -mpic-data-is-text-relative
+@opindex mpic-data-is-text-relative
+Assume that the displacement between the text and data segments is fixed
+at static link time. This allows data to be referenced by offset from start of
+text address instead of GOT since PC-relative addressing is not supported.
+
@item xmdstub
for use with Xilinx Microprocessor Debugger (XMD) based
software intrusive debug agent called xmdstub. This uses startup file
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi (revision 258312)
+++ gcc/doc/tm.texi (working copy)
@@ -7491,6 +7491,14 @@ when the target cannot support (some kinds of) dyn
in read-only sections even in executables.
@end deftypefn
+@deftypefn {Target Hook} bool TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC (void)
+Return true to generate ADDR_DIF_VEC table
+or false to generate ADDR_VEC table for jumps in case of -fPIC.
+
+The default version of this function returns true if flag_pic
+equals true and false otherwise
+@end deftypefn
+
@deftypefn {Target Hook} {section *} TARGET_ASM_SELECT_SECTION (tree
@var{exp}, int @var{reloc}, unsigned HOST_WIDE_INT @var{align})
Return the section into which @var{exp} should be placed. You can
assume that @var{exp} is either a @code{VAR_DECL} node or a constant of
Index: gcc/doc/tm.texi.in
===================================================================
--- gcc/doc/tm.texi.in (revision 258312)
+++ gcc/doc/tm.texi.in (working copy)
@@ -4922,6 +4922,8 @@ This macro is irrelevant if there is no separate r
@hook TARGET_ASM_RELOC_RW_MASK
+@hook TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+
@hook TARGET_ASM_SELECT_SECTION
@defmac USE_SELECT_SECTION_FOR_FUNCTIONS
Index: gcc/stmt.c
===================================================================
--- gcc/stmt.c (revision 258312)
+++ gcc/stmt.c (working copy)
@@ -847,7 +847,8 @@ emit_case_dispatch_table (tree index_expr, tree in
/* Output the table. */
emit_label (table_label);
- if (CASE_VECTOR_PC_RELATIVE || flag_pic)
+ if (CASE_VECTOR_PC_RELATIVE
+ || (flag_pic && targetm.asm_out.generate_pic_addr_diff_vec ()))
emit_jump_table_data (gen_rtx_ADDR_DIFF_VEC (CASE_VECTOR_MODE,
gen_rtx_LABEL_REF (Pmode,
table_label),
Index: gcc/target.def
===================================================================
--- gcc/target.def (revision 258312)
+++ gcc/target.def (working copy)
@@ -507,6 +507,19 @@ in read-only sections even in executables.",
int, (void),
default_reloc_rw_mask)
+
+ /* Return a flag for either generating ADDR_DIF_VEC table
+ or ADDR_VEC table for jumps in case of -fPIC/-fPIE. */
+DEFHOOK
+(generate_pic_addr_diff_vec,
+"Return true to generate ADDR_DIF_VEC table\n\
+or false to generate ADDR_VEC table for jumps in case of -fPIC.\n\
+\n\
+The default version of this function returns true if flag_pic\n\
+equals true and false otherwise",
+ bool, (void),
+ default_generate_pic_addr_diff_vec)
+
/* Return a section for EXP. It may be a DECL or a constant. RELOC
is nonzero if runtime relocations must be applied; bit 1 will be
set if the runtime relocations require non-local name resolution.
Index: gcc/targhooks.c
===================================================================
--- gcc/targhooks.c (revision 258312)
+++ gcc/targhooks.c (working copy)
@@ -1196,6 +1196,15 @@ default_reloc_rw_mask (void)
return flag_pic ? 3 : 0;
}
+/* By default, address diff vectors are generated
+for jump tables when flag_pic is true. */
+
+bool
+default_generate_pic_addr_diff_vec (void)
+{
+ return flag_pic;
+}
+
/* By default, do no modification. */
tree default_mangle_decl_assembler_name (tree decl ATTRIBUTE_UNUSED,
tree id)
Index: gcc/targhooks.h
===================================================================
--- gcc/targhooks.h (revision 258312)
+++ gcc/targhooks.h (working copy)
@@ -175,6 +175,7 @@ extern machine_mode default_secondary_memory_neede
extern void default_target_option_override (void);
extern void hook_void_bitmap (bitmap);
extern int default_reloc_rw_mask (void);
+extern bool default_generate_pic_addr_diff_vec (void);
extern tree default_mangle_decl_assembler_name (tree, tree);
extern tree default_emutls_var_fields (tree, tree *);
extern tree default_emutls_var_init (tree, tree, tree);
Index: gcc/testsuite/gcc.target/microblaze/others/data_var1.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/data_var1.c (revision
258312)
+++ gcc/testsuite/gcc.target/microblaze/others/data_var1.c (working copy)
@@ -3,6 +3,6 @@ int global;
int testfunc ()
{
-/* { dg-final { scan-assembler "\lwi\tr(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),r0" } }
*/
+/* { dg-final { scan-assembler
"\lwi\tr(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),r(0|20)" } } */
return global;
}
Index: gcc/testsuite/gcc.target/microblaze/others/data_var2.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/data_var2.c (revision
258312)
+++ gcc/testsuite/gcc.target/microblaze/others/data_var2.c (working copy)
@@ -3,6 +3,6 @@ int global = 10;
int testfunc ()
{
-/* { dg-final { scan-assembler "\lwi\tr(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),r0" } }
*/
+/* { dg-final { scan-assembler
"\lwi\tr(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),r(0|20)" } } */
return global;
}
Index: gcc/testsuite/gcc.target/microblaze/others/picdtr.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/picdtr.c (nonexistent)
+++ gcc/testsuite/gcc.target/microblaze/others/picdtr.c (working copy)
@@ -0,0 +1,80 @@
+/* { dg-options "-fPIE -mpic-data-text-rel -save-temps" } */
+/* { dg-do run } */
+
+#define TEST_VAR(var,val) (var) = (val); if( (var) != (val)) return 0;
+
+int foo(unsigned int i);
+extern void abort(void);
+extern void exit(int);
+
+unsigned char data[8];
+long bigData[7];
+long var;
+typedef struct {int a; short b; long c[1000][1000]; long long d[3][3]; char e;
} myDef;
+myDef def;
+const char* myString;
+
+/* { dg-final { scan-assembler "mfs\tr20,rpc" } } */
+/* { dg-final { scan-assembler "addik\tr20,r20,8@TXTPCREL" } } */
+/* { dg-final { scan-assembler ",r20,\[^\n]*var\[^\n]*@TXTREL" } } */
+/* { dg-final { scan-assembler-not ",r0,\[^\n]*var" } } */
+/* { dg-final { scan-assembler ",r20,\[^\n]*bigData\[^\n]*@TXTREL" } } */
+/* { dg-final { scan-assembler-not ",r0,\[^\n]*bigData" } } */
+/* { dg-final { scan-assembler ",r20,\[^\n]*def\[^\n]*@TXTREL" } } */
+/* { dg-final { scan-assembler-not ",r0,\[^\n]*def" } } */
+/* { dg-final { scan-assembler ",r20,\[^\n]*data\[^\n]*@TXTREL" } } */
+/* { dg-final { scan-assembler-not ",r0,\[^\n]*data" } } */
+/* { dg-final { scan-assembler ",r20,\[^\n]*L\[^\n]*@TXTREL" } } */
+/* { dg-final { scan-assembler-not ",r0,\[^\n]*L" } } */
+
+
+
+void foo2() {
+ var++;
+}
+
+int foo (unsigned int i) {
+
+ TEST_VAR(var,123)
+ TEST_VAR(data[i],77)
+ TEST_VAR(data[2],88)
+ TEST_VAR(def.a,897)
+ TEST_VAR(bigData[i],78)
+ TEST_VAR(bigData[2],777)
+ TEST_VAR(def.b,12333);
+ TEST_VAR(def.c[i][i],5);
+ TEST_VAR(def.c[0][1],7);
+ TEST_VAR(def.d[1][2],123);
+ TEST_VAR(def.e,7);
+ TEST_VAR(bigData[i+1],bigData[i*2]);
+
+ foo2();
+
+ myString = "Hello";
+
+ switch(i){
+
+ case 1: var += 2; break;
+ case 2: var += 3; break;
+ case 3: var += 5; break;
+ case 4: var += 7; break;
+ case 5: var += 8; break;
+ default: var = 0;
+
+ }
+
+ return 1;
+
+}
+
+int main() {
+
+ int result = foo(3);
+ if(result != 1 || var != 129) {
+ abort();
+ }
+
+ exit(0);
+
+}
+
Index: gcc/testsuite/gcc.target/microblaze/others/sdata_var1.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/sdata_var1.c (revision
258312)
+++ gcc/testsuite/gcc.target/microblaze/others/sdata_var1.c (working copy)
@@ -1,4 +1,4 @@
-/* { dg-options "-mxl-gp-opt" } */
+/* { dg-options "-mxl-gp-opt -fno-pic" } */
/* { dg-final { scan-assembler "\.sbss\[^2]+" } } */
typedef int Boolean;
Index: gcc/testsuite/gcc.target/microblaze/others/sdata_var2.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/sdata_var2.c (revision
258312)
+++ gcc/testsuite/gcc.target/microblaze/others/sdata_var2.c (working copy)
@@ -1,4 +1,4 @@
-/* { dg-options "-mxl-gp-opt" } */
+/* { dg-options "-mxl-gp-opt -fno-pic" } */
/* { dg-final { scan-assembler "\.sdata\[^2]+" } } */
int global = 10;
Index: gcc/testsuite/gcc.target/microblaze/others/sdata_var3.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/sdata_var3.c (revision
258312)
+++ gcc/testsuite/gcc.target/microblaze/others/sdata_var3.c (working copy)
@@ -1,4 +1,4 @@
-/* { dg-options "-mxl-gp-opt" } */
+/* { dg-options "-mxl-gp-opt -fno-pic" } */
extern int a;
Index: gcc/testsuite/gcc.target/microblaze/others/sdata_var4.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/sdata_var4.c (revision
258312)
+++ gcc/testsuite/gcc.target/microblaze/others/sdata_var4.c (working copy)
@@ -1,4 +1,4 @@
-/* { dg-options "-mxl-gp-opt -G 16" } */
+/* { dg-options "-mxl-gp-opt -G 16 -fno-pic" } */
/* { dg-final { scan-assembler "\.sbss\[^2]+" } } */
struct test_s {
Index: gcc/testsuite/gcc.target/microblaze/others/sdata_var5.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/sdata_var5.c (revision
258312)
+++ gcc/testsuite/gcc.target/microblaze/others/sdata_var5.c (working copy)
@@ -1,4 +1,4 @@
-/* { dg-options "-mxl-gp-opt -G 16" } */
+/* { dg-options "-mxl-gp-opt -G 16 -fno-pic" } */
/* { dg-final { scan-assembler "\.sdata\[^2]+" } } */
struct test_s {
Index: gcc/testsuite/gcc.target/microblaze/others/sdata_var6.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/sdata_var6.c (revision
258312)
+++ gcc/testsuite/gcc.target/microblaze/others/sdata_var6.c (working copy)
@@ -1,5 +1,4 @@
-/* { dg-options "-mxl-gp-opt -G 16" } */
-
+/* { dg-options "-mxl-gp-opt -G 16 -fno-pic" } */
struct test_s {
int a;
int b;
Index: gcc/testsuite/gcc.target/microblaze/others/string_cst1_gpopt.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/string_cst1_gpopt.c
(revision 258312)
+++ gcc/testsuite/gcc.target/microblaze/others/string_cst1_gpopt.c
(working copy)
@@ -1,4 +1,4 @@
-/* { dg-options "-mxl-gp-opt" } */
+/* { dg-options "-mxl-gp-opt -fno-pic" } */
#include <string.h>
Index: gcc/testsuite/gcc.target/microblaze/others/string_cst2_gpopt.c
===================================================================
--- gcc/testsuite/gcc.target/microblaze/others/string_cst2_gpopt.c
(revision 258312)
+++ gcc/testsuite/gcc.target/microblaze/others/string_cst2_gpopt.c
(working copy)
@@ -1,4 +1,4 @@
-/* { dg-options "-mxl-gp-opt" } */
+/* { dg-options "-mxl-gp-opt -fno-pic" } */
#include <string.h>