Message ID | CA9BBF0458F83C4F9051448B941B57D124D8EF71@glaexch3 |
---|---|
State | New |
Headers | show |
James Bowman schrieb: > The FT32 binutils use a bias to distinguish between RAM and flash > addresses. > > This fix adds an ASM_OUTPUT_SYMBOL_REF() that unbiases references to > RAM symbols. > > Only references to RAM objects have the bias applied. Flash objects > (that is, objects in ADDR SPACE 1) are not biased, so for these no bias > should be applied. Likewise references in the gdb section need to use > the biased address, so references in debug sections are not unbiased. > > gcc/ChangeLog: > > 2016-07-08 James Bowman <james.bowman@ftdichip.com> > > * config/ft32/ft32.c (ft32_elf_encode_section_info): New function. > * config/ft32/ft32.h (ASM_OUTPUT_SYMBOL_REF): New function. Huh, ASM_OUTPUT_SYMBOL_REF it's a macro. > > Index: gcc/config/ft32/ft32.c > =================================================================== > --- gcc/config/ft32/ft32.c (revision 237998) > +++ gcc/config/ft32/ft32.c (working copy) > @@ -35,6 +35,7 @@ > #include "calls.h" > #include "expr.h" > #include "builtins.h" > +#include "print-tree.h" Seems this include is no more needed as you commented-out below the used functions. If the header is actually needed it should be mentioned in the ChangeLog. > /* This file should be included last. */ > #include "target-def.h" > @@ -895,6 +896,46 @@ yes: > return 1; > } > > +#undef TARGET_ENCODE_SECTION_INFO > +#define TARGET_ENCODE_SECTION_INFO ft32_elf_encode_section_info > + > +void > +ft32_elf_encode_section_info (tree decl, rtx rtl, int first) Can't this function be static? > +{ > + enum tree_code code; > + rtx symbol; > + > + /* Careful not to prod global register variables. */ > + if (!MEM_P (rtl)) > + return; > + symbol = XEXP (rtl, 0); > + if (GET_CODE (symbol) != SYMBOL_REF) We have SYMBOL_REF_P ==> if (!SYMBOL_REF_P (symbol)) ... > + return; > + > + default_encode_section_info (decl, rtl, first); > + > + code = TREE_CODE (decl); > + switch (TREE_CODE_CLASS (code)) > + { > + case tcc_declaration: > + { > + tree type = TREE_TYPE (decl); > + int is_flash = (type && TYPE_P (type) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))); Line too long, should be wrapped, e.g. before the "&&". > + if ((code == VAR_DECL) && !is_flash) > + SYMBOL_REF_FLAGS (symbol) |= 0x1000; "0x1000" is fragile. If rtl.h::SYMBOL_FLAG_MACH_DEP_SHIFT is bumped in a future version because generic symbol_ref flags are added, hard-coded flags like these will break your code. > + } > + break; > + case tcc_constant: > + case tcc_exceptional: > + if (code == STRING_CST) > + SYMBOL_REF_FLAGS (symbol) |= 0x1000; Same here. > + } > + > + // debug_tree (decl); > + // debug_rtx (rtl); > + // printf("\n"); No code in comments. > +} > + > struct gcc_target targetm = TARGET_INITIALIZER; > > #include "gt-ft32.h" > Index: gcc/config/ft32/ft32.h > =================================================================== > --- gcc/config/ft32/ft32.h (revision 237998) > +++ gcc/config/ft32/ft32.h (working copy) > @@ -506,4 +506,14 @@ do { \ > > extern int ft32_is_mem_pm(rtx o); Such prototypes usually live in ft32-protos.h, not in ft32.h. > > +#define ASM_OUTPUT_SYMBOL_REF(stream, sym) \ > + do { \ > + assemble_name (stream, XSTR (sym, 0)); \ > + int section_debug = in_section && \ > + (SECTION_STYLE (in_section) == SECTION_NAMED) && \ If lines are wrapped, then before operators like "&&", not after them. > + (in_section->named.common.flags & SECTION_DEBUG); \ > + if (!section_debug && SYMBOL_REF_FLAGS (sym) & 0x1000) \ Same here with magic "0x1000". > + asm_fprintf (stream, "-0x800000"); \ > + } while (0) > + > #endif /* GCC_FT32_H */ Johann
Index: gcc/config/ft32/ft32.c =================================================================== --- gcc/config/ft32/ft32.c (revision 237998) +++ gcc/config/ft32/ft32.c (working copy) @@ -35,6 +35,7 @@ #include "calls.h" #include "expr.h" #include "builtins.h" +#include "print-tree.h" /* This file should be included last. */ #include "target-def.h" @@ -895,6 +896,46 @@ yes: return 1; } +#undef TARGET_ENCODE_SECTION_INFO +#define TARGET_ENCODE_SECTION_INFO ft32_elf_encode_section_info + +void +ft32_elf_encode_section_info (tree decl, rtx rtl, int first) +{ + enum tree_code code; + rtx symbol; + + /* Careful not to prod global register variables. */ + if (!MEM_P (rtl)) + return; + symbol = XEXP (rtl, 0); + if (GET_CODE (symbol) != SYMBOL_REF) + return; + + default_encode_section_info (decl, rtl, first); + + code = TREE_CODE (decl); + switch (TREE_CODE_CLASS (code)) + { + case tcc_declaration: + { + tree type = TREE_TYPE (decl); + int is_flash = (type && TYPE_P (type) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))); + if ((code == VAR_DECL) && !is_flash) + SYMBOL_REF_FLAGS (symbol) |= 0x1000; + } + break; + case tcc_constant: + case tcc_exceptional: + if (code == STRING_CST) + SYMBOL_REF_FLAGS (symbol) |= 0x1000; + } + + // debug_tree (decl); + // debug_rtx (rtl); + // printf("\n"); +} + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-ft32.h" Index: gcc/config/ft32/ft32.h =================================================================== --- gcc/config/ft32/ft32.h (revision 237998) +++ gcc/config/ft32/ft32.h (working copy) @@ -506,4 +506,14 @@ do { \ extern int ft32_is_mem_pm(rtx o); +#define ASM_OUTPUT_SYMBOL_REF(stream, sym) \ + do { \ + assemble_name (stream, XSTR (sym, 0)); \ + int section_debug = in_section && \ + (SECTION_STYLE (in_section) == SECTION_NAMED) && \ + (in_section->named.common.flags & SECTION_DEBUG); \ + if (!section_debug && SYMBOL_REF_FLAGS (sym) & 0x1000) \ + asm_fprintf (stream, "-0x800000"); \ + } while (0) + #endif /* GCC_FT32_H */