X-Git-Url: https://oss.titaniummirror.com/gitweb?p=msp430-binutils.git;a=blobdiff_plain;f=ld%2Fldexp.c;fp=ld%2Fldexp.c;h=2d0382815f1e5b333294bb90f1195e2b6f0040eb;hp=f57210ff8a03e8f974b2e7a896f229334302408f;hb=d5da4f291af551c0b8b79e1d4a9b173d60e5c10e;hpb=7b5ea4fcdf2819e070665ab5610f8b48e3867c10 diff --git a/ld/ldexp.c b/ld/ldexp.c index f57210f..2d03828 100644 --- a/ld/ldexp.c +++ b/ld/ldexp.c @@ -1,6 +1,6 @@ /* This module handles expression trees. Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001, 2002, 2003, 2004, 2005, 2006, 2007 + 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Written by Steve Chamberlain of Cygnus Support . @@ -103,7 +103,10 @@ exp_print_token (token_code_type code, int infix_p) { ADDR, "ADDR" }, { LOADADDR, "LOADADDR" }, { CONSTANT, "CONSTANT" }, - { MAX_K, "MAX_K" }, + { ABSOLUTE, "ABSOLUTE" }, + { MAX_K, "MAX" }, + { MIN_K, "MIN" }, + { ASSERT_K, "ASSERT" }, { REL, "relocatable" }, { DATA_SEGMENT_ALIGN, "DATA_SEGMENT_ALIGN" }, { DATA_SEGMENT_RELRO_END, "DATA_SEGMENT_RELRO_END" }, @@ -151,25 +154,25 @@ new_abs (bfd_vma value) etree_type * exp_intop (bfd_vma value) { - etree_type *new = stat_alloc (sizeof (new->value)); - new->type.node_code = INT; - new->type.lineno = lineno; - new->value.value = value; - new->value.str = NULL; - new->type.node_class = etree_value; - return new; + etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->value)); + new_e->type.node_code = INT; + new_e->type.lineno = lineno; + new_e->value.value = value; + new_e->value.str = NULL; + new_e->type.node_class = etree_value; + return new_e; } etree_type * exp_bigintop (bfd_vma value, char *str) { - etree_type *new = stat_alloc (sizeof (new->value)); - new->type.node_code = INT; - new->type.lineno = lineno; - new->value.value = value; - new->value.str = str; - new->type.node_class = etree_value; - return new; + etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->value)); + new_e->type.node_code = INT; + new_e->type.lineno = lineno; + new_e->value.value = value; + new_e->value.str = str; + new_e->type.node_class = etree_value; + return new_e; } /* Build an expression representing an unnamed relocatable value. */ @@ -177,13 +180,13 @@ exp_bigintop (bfd_vma value, char *str) etree_type * exp_relop (asection *section, bfd_vma value) { - etree_type *new = stat_alloc (sizeof (new->rel)); - new->type.node_code = REL; - new->type.lineno = lineno; - new->type.node_class = etree_rel; - new->rel.section = section; - new->rel.value = value; - return new; + etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->rel)); + new_e->type.node_code = REL; + new_e->type.lineno = lineno; + new_e->type.node_class = etree_rel; + new_e->rel.section = section; + new_e->rel.value = value; + return new_e; } static void @@ -279,10 +282,13 @@ fold_unary (etree_type *tree) static void fold_binary (etree_type *tree) { + etree_value_type lhs; exp_fold_tree_1 (tree->binary.lhs); /* The SEGMENT_START operator is special because its first - operand is a string, not the name of a symbol. */ + operand is a string, not the name of a symbol. Note that the + operands have been swapped, so binary.lhs is second (default) + operand, binary.rhs is first operand. */ if (expld.result.valid_p && tree->type.node_code == SEGMENT_START) { const char *segment_name; @@ -296,170 +302,170 @@ fold_binary (etree_type *tree) seg->used = TRUE; expld.result.value = seg->value; expld.result.str = NULL; - expld.result.section = NULL; + expld.result.section = expld.section; break; } + return; } - else if (expld.result.valid_p) - { - etree_value_type lhs = expld.result; - exp_fold_tree_1 (tree->binary.rhs); - if (expld.result.valid_p) + lhs = expld.result; + exp_fold_tree_1 (tree->binary.rhs); + expld.result.valid_p &= lhs.valid_p; + + if (expld.result.valid_p) + { + /* If the values are from different sections, or this is an + absolute expression, make both the source arguments + absolute. However, adding or subtracting an absolute + value from a relative value is meaningful, and is an + exception. */ + if (expld.section != bfd_abs_section_ptr + && lhs.section == bfd_abs_section_ptr + && tree->type.node_code == '+') { - /* If the values are from different sections, or this is an - absolute expression, make both the source arguments - absolute. However, adding or subtracting an absolute - value from a relative value is meaningful, and is an - exception. */ - if (expld.section != bfd_abs_section_ptr - && lhs.section == bfd_abs_section_ptr - && tree->type.node_code == '+') - { - /* Keep the section of the rhs term. */ - expld.result.value = lhs.value + expld.result.value; - return; - } - else if (expld.section != bfd_abs_section_ptr - && expld.result.section == bfd_abs_section_ptr - && (tree->type.node_code == '+' - || tree->type.node_code == '-')) - { - /* Keep the section of the lhs term. */ - expld.result.section = lhs.section; - } - else if (expld.result.section != lhs.section - || expld.section == bfd_abs_section_ptr) - { - make_abs (); - lhs.value += lhs.section->vma; - } + /* Keep the section of the rhs term. */ + expld.result.value = lhs.value + expld.result.value; + return; + } + else if (expld.section != bfd_abs_section_ptr + && expld.result.section == bfd_abs_section_ptr + && (tree->type.node_code == '+' + || tree->type.node_code == '-')) + { + /* Keep the section of the lhs term. */ + expld.result.section = lhs.section; + } + else if (expld.result.section != lhs.section + || expld.section == bfd_abs_section_ptr) + { + make_abs (); + lhs.value += lhs.section->vma; + } - switch (tree->type.node_code) - { - case '%': - if (expld.result.value != 0) - expld.result.value = ((bfd_signed_vma) lhs.value - % (bfd_signed_vma) expld.result.value); - else if (expld.phase != lang_mark_phase_enum) - einfo (_("%F%S %% by zero\n")); - break; + switch (tree->type.node_code) + { + case '%': + if (expld.result.value != 0) + expld.result.value = ((bfd_signed_vma) lhs.value + % (bfd_signed_vma) expld.result.value); + else if (expld.phase != lang_mark_phase_enum) + einfo (_("%F%S %% by zero\n")); + break; - case '/': - if (expld.result.value != 0) - expld.result.value = ((bfd_signed_vma) lhs.value - / (bfd_signed_vma) expld.result.value); - else if (expld.phase != lang_mark_phase_enum) - einfo (_("%F%S / by zero\n")); - break; + case '/': + if (expld.result.value != 0) + expld.result.value = ((bfd_signed_vma) lhs.value + / (bfd_signed_vma) expld.result.value); + else if (expld.phase != lang_mark_phase_enum) + einfo (_("%F%S / by zero\n")); + break; #define BOP(x, y) \ case x: \ expld.result.value = lhs.value y expld.result.value; \ break; - BOP ('+', +); - BOP ('*', *); - BOP ('-', -); - BOP (LSHIFT, <<); - BOP (RSHIFT, >>); - BOP (EQ, ==); - BOP (NE, !=); - BOP ('<', <); - BOP ('>', >); - BOP (LE, <=); - BOP (GE, >=); - BOP ('&', &); - BOP ('^', ^); - BOP ('|', |); - BOP (ANDAND, &&); - BOP (OROR, ||); - - case MAX_K: - if (lhs.value > expld.result.value) - expld.result.value = lhs.value; - break; + BOP ('+', +); + BOP ('*', *); + BOP ('-', -); + BOP (LSHIFT, <<); + BOP (RSHIFT, >>); + BOP (EQ, ==); + BOP (NE, !=); + BOP ('<', <); + BOP ('>', >); + BOP (LE, <=); + BOP (GE, >=); + BOP ('&', &); + BOP ('^', ^); + BOP ('|', |); + BOP (ANDAND, &&); + BOP (OROR, ||); + + case MAX_K: + if (lhs.value > expld.result.value) + expld.result.value = lhs.value; + break; - case MIN_K: - if (lhs.value < expld.result.value) - expld.result.value = lhs.value; - break; + case MIN_K: + if (lhs.value < expld.result.value) + expld.result.value = lhs.value; + break; - case ALIGN_K: - expld.result.value = align_n (lhs.value, expld.result.value); - break; + case ALIGN_K: + expld.result.value = align_n (lhs.value, expld.result.value); + break; - case DATA_SEGMENT_ALIGN: - if (expld.phase != lang_first_phase_enum - && expld.section == bfd_abs_section_ptr - && (expld.dataseg.phase == exp_dataseg_none - || expld.dataseg.phase == exp_dataseg_adjust - || expld.dataseg.phase == exp_dataseg_relro_adjust - || expld.phase == lang_final_phase_enum)) - { - bfd_vma maxpage = lhs.value; - bfd_vma commonpage = expld.result.value; + case DATA_SEGMENT_ALIGN: + expld.dataseg.relro = exp_dataseg_relro_start; + if (expld.phase != lang_first_phase_enum + && expld.section == bfd_abs_section_ptr + && (expld.dataseg.phase == exp_dataseg_none + || expld.dataseg.phase == exp_dataseg_adjust + || expld.dataseg.phase == exp_dataseg_relro_adjust + || expld.phase == lang_final_phase_enum)) + { + bfd_vma maxpage = lhs.value; + bfd_vma commonpage = expld.result.value; - expld.result.value = align_n (expld.dot, maxpage); - if (expld.dataseg.phase == exp_dataseg_relro_adjust) - expld.result.value = expld.dataseg.base; - else if (expld.dataseg.phase != exp_dataseg_adjust) + expld.result.value = align_n (expld.dot, maxpage); + if (expld.dataseg.phase == exp_dataseg_relro_adjust) + expld.result.value = expld.dataseg.base; + else if (expld.dataseg.phase != exp_dataseg_adjust) + { + expld.result.value += expld.dot & (maxpage - 1); + if (expld.phase == lang_allocating_phase_enum) { - expld.result.value += expld.dot & (maxpage - 1); - if (expld.phase == lang_allocating_phase_enum) - { - expld.dataseg.phase = exp_dataseg_align_seen; - expld.dataseg.min_base = align_n (expld.dot, maxpage); - expld.dataseg.base = expld.result.value; - expld.dataseg.pagesize = commonpage; - expld.dataseg.maxpagesize = maxpage; - expld.dataseg.relro_end = 0; - } + expld.dataseg.phase = exp_dataseg_align_seen; + expld.dataseg.min_base = expld.dot; + expld.dataseg.base = expld.result.value; + expld.dataseg.pagesize = commonpage; + expld.dataseg.maxpagesize = maxpage; + expld.dataseg.relro_end = 0; } - else if (commonpage < maxpage) - expld.result.value += ((expld.dot + commonpage - 1) - & (maxpage - commonpage)); } - else - expld.result.valid_p = FALSE; - break; - - case DATA_SEGMENT_RELRO_END: - if (expld.phase != lang_first_phase_enum - && (expld.dataseg.phase == exp_dataseg_align_seen - || expld.dataseg.phase == exp_dataseg_adjust - || expld.dataseg.phase == exp_dataseg_relro_adjust - || expld.phase == lang_final_phase_enum)) - { - if (expld.dataseg.phase == exp_dataseg_align_seen - || expld.dataseg.phase == exp_dataseg_relro_adjust) - expld.dataseg.relro_end = lhs.value + expld.result.value; + else if (commonpage < maxpage) + expld.result.value += ((expld.dot + commonpage - 1) + & (maxpage - commonpage)); + } + else + expld.result.valid_p = FALSE; + break; - if (expld.dataseg.phase == exp_dataseg_relro_adjust - && (expld.dataseg.relro_end - & (expld.dataseg.pagesize - 1))) - { - expld.dataseg.relro_end += expld.dataseg.pagesize - 1; - expld.dataseg.relro_end &= ~(expld.dataseg.pagesize - 1); - expld.result.value = (expld.dataseg.relro_end - - expld.result.value); - } - else - expld.result.value = lhs.value; + case DATA_SEGMENT_RELRO_END: + expld.dataseg.relro = exp_dataseg_relro_end; + if (expld.phase != lang_first_phase_enum + && (expld.dataseg.phase == exp_dataseg_align_seen + || expld.dataseg.phase == exp_dataseg_adjust + || expld.dataseg.phase == exp_dataseg_relro_adjust + || expld.phase == lang_final_phase_enum)) + { + if (expld.dataseg.phase == exp_dataseg_align_seen + || expld.dataseg.phase == exp_dataseg_relro_adjust) + expld.dataseg.relro_end = lhs.value + expld.result.value; - if (expld.dataseg.phase == exp_dataseg_align_seen) - expld.dataseg.phase = exp_dataseg_relro_seen; + if (expld.dataseg.phase == exp_dataseg_relro_adjust + && (expld.dataseg.relro_end + & (expld.dataseg.pagesize - 1))) + { + expld.dataseg.relro_end += expld.dataseg.pagesize - 1; + expld.dataseg.relro_end &= ~(expld.dataseg.pagesize - 1); + expld.result.value = (expld.dataseg.relro_end + - expld.result.value); } else - expld.result.valid_p = FALSE; - break; + expld.result.value = lhs.value; - default: - FAIL (); + if (expld.dataseg.phase == exp_dataseg_align_seen) + expld.dataseg.phase = exp_dataseg_relro_seen; } + else + expld.result.valid_p = FALSE; + break; + + default: + FAIL (); } - else - expld.result.valid_p = FALSE; } } @@ -487,7 +493,7 @@ fold_name (etree_type *tree) /* Don't find the real header size if only marking sections; The bfd function may cache incorrect data. */ if (expld.phase != lang_mark_phase_enum) - hdr_size = bfd_sizeof_headers (output_bfd, &link_info); + hdr_size = bfd_sizeof_headers (link_info.output_bfd, &link_info); new_abs (hdr_size); } break; @@ -501,7 +507,8 @@ fold_name (etree_type *tree) int def_iteration = lang_symbol_definition_iteration (tree->name.name); - h = bfd_wrapped_link_hash_lookup (output_bfd, &link_info, + h = bfd_wrapped_link_hash_lookup (link_info.output_bfd, + &link_info, tree->name.name, FALSE, FALSE, TRUE); expld.result.value = (h != NULL @@ -510,7 +517,7 @@ fold_name (etree_type *tree) || h->type == bfd_link_hash_common) && (def_iteration == lang_statement_iteration || def_iteration == -1)); - expld.result.section = bfd_abs_section_ptr; + expld.result.section = expld.section; expld.result.valid_p = TRUE; } break; @@ -524,7 +531,8 @@ fold_name (etree_type *tree) { struct bfd_link_hash_entry *h; - h = bfd_wrapped_link_hash_lookup (output_bfd, &link_info, + h = bfd_wrapped_link_hash_lookup (link_info.output_bfd, + &link_info, tree->name.name, TRUE, FALSE, TRUE); if (!h) @@ -601,7 +609,8 @@ fold_name (etree_type *tree) else { exp_fold_tree_1 (os->load_base); - make_abs (); + if (expld.result.valid_p) + make_abs (); } } } @@ -626,7 +635,8 @@ fold_name (etree_type *tree) bfd_vma val; if (tree->type.node_code == SIZEOF) - val = os->bfd_section->size / bfd_octets_per_byte (output_bfd); + val = (os->bfd_section->size + / bfd_octets_per_byte (link_info.output_bfd)); else val = (bfd_vma)1 << os->bfd_section->alignment_power; @@ -663,9 +673,9 @@ fold_name (etree_type *tree) case CONSTANT: if (strcmp (tree->name.name, "MAXPAGESIZE") == 0) - new_abs (bfd_emul_get_maxpagesize (default_target)); + new_abs (config.maxpagesize); else if (strcmp (tree->name.name, "COMMONPAGESIZE") == 0) - new_abs (bfd_emul_get_commonpagesize (default_target)); + new_abs (config.commonpagesize); else einfo (_("%F%S: unknown constant `%s' referenced in expression\n"), tree->name.name); @@ -841,7 +851,7 @@ exp_fold_tree_no_dot (etree_type *tree) etree_type * exp_binop (int code, etree_type *lhs, etree_type *rhs) { - etree_type value, *new; + etree_type value, *new_e; value.type.node_code = code; value.type.lineno = lhs->type.lineno; @@ -852,15 +862,15 @@ exp_binop (int code, etree_type *lhs, etree_type *rhs) if (expld.result.valid_p) return exp_intop (expld.result.value); - new = stat_alloc (sizeof (new->binary)); - memcpy (new, &value, sizeof (new->binary)); - return new; + new_e = (etree_type *) stat_alloc (sizeof (new_e->binary)); + memcpy (new_e, &value, sizeof (new_e->binary)); + return new_e; } etree_type * exp_trinop (int code, etree_type *cond, etree_type *lhs, etree_type *rhs) { - etree_type value, *new; + etree_type value, *new_e; value.type.node_code = code; value.type.lineno = lhs->type.lineno; @@ -872,15 +882,15 @@ exp_trinop (int code, etree_type *cond, etree_type *lhs, etree_type *rhs) if (expld.result.valid_p) return exp_intop (expld.result.value); - new = stat_alloc (sizeof (new->trinary)); - memcpy (new, &value, sizeof (new->trinary)); - return new; + new_e = (etree_type *) stat_alloc (sizeof (new_e->trinary)); + memcpy (new_e, &value, sizeof (new_e->trinary)); + return new_e; } etree_type * exp_unop (int code, etree_type *child) { - etree_type value, *new; + etree_type value, *new_e; value.unary.type.node_code = code; value.unary.type.lineno = child->type.lineno; @@ -890,15 +900,15 @@ exp_unop (int code, etree_type *child) if (expld.result.valid_p) return exp_intop (expld.result.value); - new = stat_alloc (sizeof (new->unary)); - memcpy (new, &value, sizeof (new->unary)); - return new; + new_e = (etree_type *) stat_alloc (sizeof (new_e->unary)); + memcpy (new_e, &value, sizeof (new_e->unary)); + return new_e; } etree_type * exp_nameop (int code, const char *name) { - etree_type value, *new; + etree_type value, *new_e; value.name.type.node_code = code; value.name.type.lineno = lineno; @@ -909,24 +919,24 @@ exp_nameop (int code, const char *name) if (expld.result.valid_p) return exp_intop (expld.result.value); - new = stat_alloc (sizeof (new->name)); - memcpy (new, &value, sizeof (new->name)); - return new; + new_e = (etree_type *) stat_alloc (sizeof (new_e->name)); + memcpy (new_e, &value, sizeof (new_e->name)); + return new_e; } etree_type * exp_assop (int code, const char *dst, etree_type *src) { - etree_type *new; - - new = stat_alloc (sizeof (new->assign)); - new->type.node_code = code; - new->type.lineno = src->type.lineno; - new->type.node_class = etree_assign; - new->assign.src = src; - new->assign.dst = dst; - return new; + etree_type *new_e; + + new_e = (etree_type *) stat_alloc (sizeof (new_e->assign)); + new_e->type.node_code = code; + new_e->type.lineno = src->type.lineno; + new_e->type.node_class = etree_assign; + new_e->assign.src = src; + new_e->assign.dst = dst; + return new_e; } /* Handle PROVIDE. */ @@ -936,7 +946,7 @@ exp_provide (const char *dst, etree_type *src, bfd_boolean hidden) { etree_type *n; - n = stat_alloc (sizeof (n->assign)); + n = (etree_type *) stat_alloc (sizeof (n->assign)); n->assign.type.node_code = '='; n->assign.type.lineno = src->type.lineno; n->assign.type.node_class = etree_provide; @@ -953,7 +963,7 @@ exp_assert (etree_type *exp, const char *message) { etree_type *n; - n = stat_alloc (sizeof (n->assert_s)); + n = (etree_type *) stat_alloc (sizeof (n->assert_s)); n->assert_s.type.node_code = '!'; n->assert_s.type.lineno = exp->type.lineno; n->assert_s.type.node_class = etree_assert; @@ -1052,7 +1062,7 @@ exp_get_vma (etree_type *tree, bfd_vma def, char *name) if (expld.result.valid_p) return expld.result.value; else if (name != NULL && expld.phase != lang_mark_phase_enum) - einfo (_("%F%S nonconstant expression for %s\n"), name); + einfo (_("%F%S: nonconstant expression for %s\n"), name); } return def; } @@ -1077,7 +1087,7 @@ exp_get_fill (etree_type *tree, fill_type *def, char *name) if (!expld.result.valid_p) { if (name != NULL && expld.phase != lang_mark_phase_enum) - einfo (_("%F%S nonconstant expression for %s\n"), name); + einfo (_("%F%S: nonconstant expression for %s\n"), name); return def; } @@ -1085,7 +1095,7 @@ exp_get_fill (etree_type *tree, fill_type *def, char *name) { unsigned char *dst; unsigned char *s; - fill = xmalloc ((len + 1) / 2 + sizeof (*fill) - 1); + fill = (fill_type *) xmalloc ((len + 1) / 2 + sizeof (*fill) - 1); fill->size = (len + 1) / 2; dst = fill->data; s = (unsigned char *) expld.result.str; @@ -1110,7 +1120,7 @@ exp_get_fill (etree_type *tree, fill_type *def, char *name) } else { - fill = xmalloc (4 + sizeof (*fill) - 1); + fill = (fill_type *) xmalloc (4 + sizeof (*fill) - 1); val = expld.result.value; fill->data[0] = (val >> 24) & 0xff; fill->data[1] = (val >> 16) & 0xff;