X-Git-Url: https://oss.titaniummirror.com/gitweb?p=msp430-binutils.git;a=blobdiff_plain;f=gas%2Fehopt.c;h=c09eb15b4983f86f9884b5590dfafabbf1c2c1ec;hp=2b0609be005df59ab1423ea342f56bb3c966e9d4;hb=88750007d7869f178f0ba528f41efd3b74c424cf;hpb=6df9443a374e2b81278c61b8afc0a1eef7db280b diff --git a/gas/ehopt.c b/gas/ehopt.c index 2b0609b..c09eb15 100644 --- a/gas/ehopt.c +++ b/gas/ehopt.c @@ -1,5 +1,6 @@ /* ehopt.c--optimize gcc exception frame information. - Copyright 1998, 2000, 2001, 2003, 2005, 2007 Free Software Foundation, Inc. + Copyright 1998, 2000, 2001, 2003, 2005, 2007, 2008, 2009 + Free Software Foundation, Inc. Written by Ian Lance Taylor . This file is part of GAS, the GNU Assembler. @@ -21,12 +22,13 @@ #include "as.h" #include "subsegs.h" +#include "struc-symbol.h" /* We include this ELF file, even though we may not be assembling for ELF, since the exception frame information is always in a format derived from DWARF. */ -#include "elf/dwarf2.h" +#include "dwarf2.h" /* Try to optimize gcc 2.8 exception frame information. @@ -225,6 +227,19 @@ get_cie_info (struct cie_info *info) return 1; } +enum frame_state +{ + state_idle, + state_saw_size, + state_saw_cie_offset, + state_saw_pc_begin, + state_seeing_aug_size, + state_skipping_aug, + state_wait_loc4, + state_saw_loc4, + state_error, +}; + /* This function is called from emit_expr. It looks for cases which we can optimize. @@ -243,18 +258,7 @@ check_eh_frame (expressionS *exp, unsigned int *pnbytes) { struct frame_data { - enum frame_state - { - state_idle, - state_saw_size, - state_saw_cie_offset, - state_saw_pc_begin, - state_seeing_aug_size, - state_skipping_aug, - state_wait_loc4, - state_saw_loc4, - state_error, - } state; + enum frame_state state; int cie_info_ok; struct cie_info cie_info; @@ -275,6 +279,11 @@ check_eh_frame (expressionS *exp, unsigned int *pnbytes) if (flag_traditional_format) return 0; +#ifdef md_allow_eh_opt + if (! md_allow_eh_opt) + return 0; +#endif + /* Select the proper section data. */ if (strcmp (segment_name (now_seg), ".eh_frame") == 0) d = &eh_frame_data; @@ -317,7 +326,7 @@ check_eh_frame (expressionS *exp, unsigned int *pnbytes) case state_saw_size: case state_saw_cie_offset: /* Assume whatever form it appears in, it appears atomically. */ - d->state += 1; + d->state = (enum frame_state) (d->state + 1); break; case state_saw_pc_begin: @@ -393,13 +402,10 @@ check_eh_frame (expressionS *exp, unsigned int *pnbytes) subtracted were in the same frag and the expression was reduced to a constant. We can do the optimization entirely in this function. */ - if (d->cie_info.code_alignment > 0 - && exp->X_add_number % d->cie_info.code_alignment == 0 - && exp->X_add_number / d->cie_info.code_alignment < 0x40) + if (exp->X_add_number < 0x40) { d->loc4_frag->fr_literal[d->loc4_fix] - = DW_CFA_advance_loc - | (exp->X_add_number / d->cie_info.code_alignment); + = DW_CFA_advance_loc | exp->X_add_number; /* No more bytes needed. */ return 1; } @@ -414,23 +420,39 @@ check_eh_frame (expressionS *exp, unsigned int *pnbytes) *pnbytes = 2; } } - else if (exp->X_op == O_subtract) + else if (exp->X_op == O_subtract && d->cie_info.code_alignment == 1) { /* This is a case we can optimize. The expression was not reduced, so we can not finish the optimization until the end of the assembly. We set up a variant frag which we handle later. */ - int fr_subtype; - - if (d->cie_info.code_alignment > 0) - fr_subtype = d->cie_info.code_alignment << 3; - else - fr_subtype = 0; - - frag_var (rs_cfa, 4, 0, fr_subtype, make_expr_symbol (exp), + frag_var (rs_cfa, 4, 0, 1 << 3, make_expr_symbol (exp), d->loc4_fix, (char *) d->loc4_frag); return 1; } + else if ((exp->X_op == O_divide + || exp->X_op == O_right_shift) + && d->cie_info.code_alignment > 1) + { + if (exp->X_add_symbol->bsym + && exp->X_op_symbol->bsym + && exp->X_add_symbol->sy_value.X_op == O_subtract + && exp->X_op_symbol->sy_value.X_op == O_constant + && ((exp->X_op == O_divide + ? exp->X_op_symbol->sy_value.X_add_number + : (offsetT) 1 << exp->X_op_symbol->sy_value.X_add_number) + == (offsetT) d->cie_info.code_alignment)) + { + /* This is a case we can optimize as well. The expression was + not reduced, so we can not finish the optimization until the + end of the assembly. We set up a variant frag which we + handle later. */ + frag_var (rs_cfa, 4, 0, d->cie_info.code_alignment << 3, + make_expr_symbol (&exp->X_add_symbol->sy_value), + d->loc4_fix, (char *) d->loc4_frag); + return 1; + } + } break; case state_error: @@ -454,7 +476,9 @@ eh_frame_estimate_size_before_relax (fragS *frag) diff = resolve_symbol_value (frag->fr_symbol); - if (ca > 0 && diff % ca == 0 && diff / ca < 0x40) + gas_assert (ca > 0); + diff /= ca; + if (diff < 0x40) ret = 0; else if (diff < 0x100) ret = 1; @@ -491,31 +515,31 @@ eh_frame_convert_frag (fragS *frag) { offsetT diff; fragS *loc4_frag; - int loc4_fix; + int loc4_fix, ca; loc4_frag = (fragS *) frag->fr_opcode; loc4_fix = (int) frag->fr_offset; diff = resolve_symbol_value (frag->fr_symbol); + ca = frag->fr_subtype >> 3; + gas_assert (ca > 0); + diff /= ca; switch (frag->fr_subtype & 7) { case 0: - { - int ca = frag->fr_subtype >> 3; - assert (ca > 0 && diff % ca == 0 && diff / ca < 0x40); - loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc | (diff / ca); - } + gas_assert (diff < 0x40); + loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc | diff; break; case 1: - assert (diff < 0x100); + gas_assert (diff < 0x100); loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc1; frag->fr_literal[frag->fr_fix] = diff; break; case 2: - assert (diff < 0x10000); + gas_assert (diff < 0x10000); loc4_frag->fr_literal[loc4_fix] = DW_CFA_advance_loc2; md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 2); break;