From 670ec21de99faddc3a86f9e18fb9ef1a093b3dbf Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Tue, 27 Jul 2004 11:37:12 +0000 Subject: Add CRX insns: pushx, popx Add support to GAS for expressions which are the difference of two symbols --- gas/config/obj-coff.c | 2 +- gas/config/tc-crx.c | 73 ++++++++++++++++++++++++++++++++++++++++++++------- gas/config/tc-crx.h | 8 ++++-- gas/config/tc-ppc.c | 9 +++---- 4 files changed, 75 insertions(+), 17 deletions(-) (limited to 'gas/config') diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c index ee37b08..1451d9d 100644 --- a/gas/config/obj-coff.c +++ b/gas/config/obj-coff.c @@ -1327,7 +1327,7 @@ coff_frob_symbol (symp, punt) order to call SA_SET_SYM_ENDNDX correctly. */ if (! symbol_used_in_reloc_p (symp) && ((symbol_get_bfdsym (symp)->flags & BSF_SECTION_SYM) != 0 - || (! S_IS_EXTERNAL (symp) + || (! (S_IS_EXTERNAL (symp) || S_IS_WEAK (symp)) && ! symbol_get_tc (symp)->output && S_GET_STORAGE_CLASS (symp) != C_FILE))) *punt = 1; diff --git a/gas/config/tc-crx.c b/gas/config/tc-crx.c index 3b3c49e..3062118 100644 --- a/gas/config/tc-crx.c +++ b/gas/config/tc-crx.c @@ -292,6 +292,34 @@ reset_vars (char *op, ins *crx_ins) strcpy (ins_parse, op); } +/* This macro decides whether a particular reloc is an entry in a + switch table. It is used when relaxing, because the linker needs + to know about all such entries so that it can adjust them if + necessary. */ + +#define SWITCH_TABLE(fix) \ + ( (fix)->fx_addsy != NULL \ + && (fix)->fx_subsy != NULL \ + && S_GET_SEGMENT ((fix)->fx_addsy) == \ + S_GET_SEGMENT ((fix)->fx_subsy) \ + && S_GET_SEGMENT (fix->fx_addsy) != undefined_section \ + && ( (fix)->fx_r_type == BFD_RELOC_CRX_NUM8 \ + || (fix)->fx_r_type == BFD_RELOC_CRX_NUM16 \ + || (fix)->fx_r_type == BFD_RELOC_CRX_NUM32)) + +/* See whether we need to force a relocation into the output file. + This is used to force out switch and PC relative relocations when + relaxing. */ + +int +crx_force_relocation (fixS *fix) +{ + if (generic_force_reloc (fix) || SWITCH_TABLE (fix)) + return 1; + + return 0; +} + /* Generate a relocation entry for a fixup. */ arelent * @@ -306,15 +334,42 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS * fixP) reloc->addend = fixP->fx_offset; if (fixP->fx_subsy != NULL) - /* We don't resolve difference expressions. */ - as_bad_where (fixP->fx_file, fixP->fx_line, - _("can't resolve `%s' {%s section} - `%s' {%s section}"), - fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0", - segment_name (fixP->fx_addsy - ? S_GET_SEGMENT (fixP->fx_addsy) - : absolute_section), - S_GET_NAME (fixP->fx_subsy), - segment_name (S_GET_SEGMENT (fixP->fx_addsy))); + { + if (SWITCH_TABLE (fixP)) + { + /* Keep the current difference in the addend. */ + reloc->addend = (S_GET_VALUE (fixP->fx_addsy) + - S_GET_VALUE (fixP->fx_subsy) + fixP->fx_offset); + + switch (fixP->fx_r_type) + { + case BFD_RELOC_CRX_NUM8: + fixP->fx_r_type = BFD_RELOC_CRX_SWITCH8; + break; + case BFD_RELOC_CRX_NUM16: + fixP->fx_r_type = BFD_RELOC_CRX_SWITCH16; + break; + case BFD_RELOC_CRX_NUM32: + fixP->fx_r_type = BFD_RELOC_CRX_SWITCH32; + break; + default: + abort (); + break; + } + } + else + { + /* We only resolve difference expressions in the same section. */ + as_bad_where (fixP->fx_file, fixP->fx_line, + _("can't resolve `%s' {%s section} - `%s' {%s section}"), + fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0", + segment_name (fixP->fx_addsy + ? S_GET_SEGMENT (fixP->fx_addsy) + : absolute_section), + S_GET_NAME (fixP->fx_subsy), + segment_name (S_GET_SEGMENT (fixP->fx_addsy))); + } + } assert ((int) fixP->fx_r_type > 0); reloc->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type); diff --git a/gas/config/tc-crx.h b/gas/config/tc-crx.h index dc26a70..29e59fe 100644 --- a/gas/config/tc-crx.h +++ b/gas/config/tc-crx.h @@ -48,6 +48,10 @@ extern const struct relax_type md_relax_table[]; linker relaxations easier. */ #define tc_fix_adjustable(fixP) 0 +/* We need to force out some relocations when relaxing. */ +#define TC_FORCE_RELOCATION(FIXP) crx_force_relocation (FIXP) +extern int crx_force_relocation (struct fix *); + /* Fixup debug sections since we will never relax them. */ #define TC_LINKRELAX_FIXUP(seg) (seg->flags & SEC_ALLOC) @@ -58,8 +62,8 @@ extern const struct relax_type md_relax_table[]; /* This is called by emit_expr when creating a reloc for a cons. We could use the definition there, except that we want to handle the CRX reloc type specially, rather than the BFD_RELOC type. */ -#define TC_CONS_FIX_NEW(FRAG,OFF,LEN,EXP) \ - fix_new_exp (FRAG, OFF, (int)LEN, EXP, 0, \ +#define TC_CONS_FIX_NEW(FRAG, OFF, LEN, EXP) \ + fix_new_exp (FRAG, OFF, (int) LEN, EXP, 0, \ LEN == 1 ? BFD_RELOC_CRX_NUM8 \ : LEN == 2 ? BFD_RELOC_CRX_NUM16 \ : LEN == 4 ? BFD_RELOC_CRX_NUM32 \ diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c index d4893e7..7bc7011 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -1918,9 +1918,8 @@ ppc_frob_file_before_adjust () free (dotname); if (dotsym != NULL && (symbol_used_p (dotsym) || symbol_used_in_reloc_p (dotsym))) - { - symbol_mark_used (symp); - } + symbol_mark_used (symp); + } /* Don't emit .TOC. symbol. */ @@ -4843,7 +4842,7 @@ ppc_frob_symbol (sym) table. */ if (! symbol_used_in_reloc_p (sym) && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0 - || (! S_IS_EXTERNAL (sym) + || (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym)) && ! symbol_get_tc (sym)->output && S_GET_STORAGE_CLASS (sym) != C_FILE))) return 1; @@ -4909,7 +4908,7 @@ ppc_frob_symbol (sym) } } - if (! S_IS_EXTERNAL (sym) + if (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym)) && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0 && S_GET_STORAGE_CLASS (sym) != C_FILE && S_GET_STORAGE_CLASS (sym) != C_FCN -- cgit v1.1