On 04/18/2018 05:44 AM, Andrew Sadek wrote:
Hello Michael,
I have attached the patch as well,
(the same as in :
https://github.com/andrewsadek/microblaze-pic-data-text-rel/blob/pic_data_text_rel/PATCH_BUNDLE/gcc.patch)
On Thu, Mar 22, 2018 at 8:37 PM, Andrew Sadek <andrew.sadek...@gmail.com> wrote:
Hello Michael,
I have adapted the test cases.
Please find the patch below with Change log, description and test results.
Description:
------------------
This branch is regarding a new implemented feature in GCC Microblaze
that allows Position Independent Code to run using Data Text Relative
addressing instead of using Global Offset Table.
Its aim was to make 'PIC' more efficient and flexible as elf size
excess/ performance overhead were noticed when using GOT due to the
indirect addressing.
The change was tested with the dhrystone benchmark on a real Hardware
(Xilinx FPGA Spartan 6) and the test report went successfully for all
optimization levels.
Indeed, Microblaze does not support PC-relative addressing in Hardware like ARM.
The idea was to store the start address of current text section in
'r20' instead of GOT, in the function prologue. Correspondingly, data
references will be an offset from the original reference value to the
start of text thus being added to the 'r20' base register will resolve
the actual address.
Henceforth, 2 new relocations have been created:
- 'R_MICROBLAZE_TEXTPCREL_64': resolves offset of current PC to start
of text in order to set r20
- 'R_MICROBLAZE_TEXTREL_64': resolves offset of mentioned data
reference to start of text
Accordingly, both assembler and linker (binutils) have been adapted.
For extra details:
https://github.com/andrewsadek/microblaze-pic-data-text-rel/blob/pic_data_text_rel/README.md
Change Log:
---------------------
2018-03-22 Andrew Sadek <andrew.sadek...@gmail.com>
Microblaze Target: PIC data text relative
* gcc/config/microblaze/microblaze.opt: add new option
-mpic-data-text-rel.
* gcc/config/microblaze/microblaze-protos.h
(microblaze_constant_address_p):
Add microblaze_constant_address_p function instead of the macro in
microblaze.h
* gcc/config/microblaze/microblaze.c (TARGET_PIC_DATA_TEXT_REL):
New addressing mode
for data-text relative position indepenedent code.
(microblaze_classify_unspec): add 'UNSPEC_TEXT' case ->
'ADDRESS_SYMBOLIC_TXT_REL'.
(microblaze_classify_address): add handling for UNSPEC + CONST_INT.
(microblaze_legitimate_pic_operand): exclude function calls from
pic operands
in case of TARGET_PIC_DATA_TEXT_REL option.
(microblaze_legitimize_address): generate 'UNSPEC_TEXT' for all possible
addresses cases.
(microblaze_address_insns): add 'ADDRESS_SYMBOLIC_TXT_REL' case.
(print_operand): add 'ADDRESS_SYMBOLIC_TXT_REL' case.
(print_operand_address): add 'ADDRESS_SYMBOLIC_TXT_REL' case + handling for
'address + offset'.
(microblaze_expand_prologue): add new function prologue call for
'r20' assignation.
(microblaze_asm_generate_pic_addr_dif_vec): override new target hook
'TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC' to disable address diff vector
table in case of TARGET_PIC_DATA_TEXT_REL.
(expand_pic_symbol_ref): add handling for 'UNSPEC_TEXT'.
* gcc/config/microblaze/microblaze.md (TARGET_PIC_DATA_TEXT_REL):
Add new macros 'UNSPEC_TEXT',
'UNSPEC_SET_TEXT' + add rule for setting r20 in function prologue
+ exclude function calls
from 'UNSPEC_PLT' in case of data text relative mode.
* gcc/doc/tm.texi.in (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC): Add
new target hook for generating
address diff vector tables in case of flag_pic.
* gcc/doc/tm.texi : Regenerate.
* gcc/stmt.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC): append new condition
'targetm.asm_out.generate_pic_addr_diff_vec' to flag_pic in case
of addr diff vector generation.
* gcc/target.def (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC): add
target hook definition.
* gcc/targhooks.h, gcc/targhooks.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
add default function for generate_pic_addr_diff_vec -> flag_pic.
* gcc/doc/invoke.texi (Add new pic option): Add new microblaze pic
option for data text relative.
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
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.
@@ -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
{
...
}
}
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)
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.)
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.
target.def:
+(generate_pic_addr_diff_vec,
Explicitly state what true or false means.
targhooks.c:
+bool
+default_generate_pic_addr_diff_vec (void)
+{
+ return true;
+}
This doesn't appear to match the description in target.def.
--
Michael Eager ea...@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306