X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gas%2Fconfig%2Ftc-xtensa.c;h=ca261ae19c4cc8f70060ee70db5572b81a2b40b2;hb=feb4bea70a297eb6316d1b0685bbbb8095b7fb29;hp=3025d29f238e34c34086194d7a381fdbacb38ee7;hpb=17b9d67d4e6bcf2b2b4eecc91b0ff6af35e0fef5;p=deliverable%2Fbinutils-gdb.git diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c index 3025d29f23..ca261ae19c 100644 --- a/gas/config/tc-xtensa.c +++ b/gas/config/tc-xtensa.c @@ -29,6 +29,7 @@ #include "xtensa-istack.h" #include "struc-symbol.h" #include "xtensa-config.h" +#include "elf/xtensa.h" /* Provide default values for new configuration settings. */ #ifndef XSHAL_ABI @@ -213,8 +214,6 @@ int generating_literals = 0; /* Required branch target alignment. */ #define XTENSA_PROP_BT_ALIGN_REQUIRE 0x3 -#define GET_XTENSA_PROP_BT_ALIGN(flag) \ - (((unsigned) ((flag) & (XTENSA_PROP_BT_ALIGN_MASK))) >> 9) #define SET_XTENSA_PROP_BT_ALIGN(flag, align) \ (((flag) & (~XTENSA_PROP_BT_ALIGN_MASK)) | \ (((align) << 9) & XTENSA_PROP_BT_ALIGN_MASK)) @@ -235,8 +234,6 @@ int generating_literals = 0; #define XTENSA_PROP_ALIGNMENT_MASK 0x0001f000 -#define GET_XTENSA_PROP_ALIGNMENT(flag) \ - (((unsigned) ((flag) & (XTENSA_PROP_ALIGNMENT_MASK))) >> 12) #define SET_XTENSA_PROP_ALIGNMENT(flag, align) \ (((flag) & (~XTENSA_PROP_ALIGNMENT_MASK)) | \ (((align) << 12) & XTENSA_PROP_ALIGNMENT_MASK)) @@ -364,7 +361,7 @@ struct suffix_reloc_map const char *suffix; int length; bfd_reloc_code_real_type reloc; - unsigned char operator; + operatorT operator; }; #define SUFFIX_MAP(str, reloc, op) { str, sizeof (str) - 1, reloc, op } @@ -380,7 +377,6 @@ static struct suffix_reloc_map suffix_relocs[] = SUFFIX_MAP ("tlscall", BFD_RELOC_XTENSA_TLS_CALL, O_tlscall), SUFFIX_MAP ("tpoff", BFD_RELOC_XTENSA_TLS_TPOFF, O_tpoff), SUFFIX_MAP ("dtpoff", BFD_RELOC_XTENSA_TLS_DTPOFF, O_dtpoff), - { (char *) 0, 0, BFD_RELOC_UNUSED, 0 } }; @@ -529,10 +525,6 @@ static void xtensa_switch_section_emit_state (emit_state *, segT, subsegT); static void xtensa_restore_emit_state (emit_state *); static segT cache_literal_section (bfd_boolean); -/* Import from elf32-xtensa.c in BFD library. */ - -extern asection *xtensa_make_property_section (asection *, const char *); - /* op_placement_info functions. */ static void init_op_placement_info_table (void); @@ -1067,7 +1059,7 @@ xtensa_add_insn_label (symbolS *sym) sym_list *l; if (!free_insn_labels) - l = (sym_list *) xmalloc (sizeof (sym_list)); + l = XNEW (sym_list); else { l = free_insn_labels; @@ -1167,7 +1159,7 @@ directive_push (directiveE directive, bfd_boolean negated, const void *datum) { const char *file; unsigned int line; - state_stackS *stack = (state_stackS *) xmalloc (sizeof (state_stackS)); + state_stackS *stack = XNEW (state_stackS); file = as_where (&line); @@ -1323,7 +1315,7 @@ xtensa_begin_directive (int ignore ATTRIBUTE_UNUSED) insn_labels = NULL; } as_warn (_(".begin literal is deprecated; use .literal instead")); - state = (emit_state *) xmalloc (sizeof (emit_state)); + state = XNEW (emit_state); xtensa_switch_to_literal_fragment (state); directive_push (directive_literal, negated, state); break; @@ -1342,7 +1334,7 @@ xtensa_begin_directive (int ignore ATTRIBUTE_UNUSED) /* Allocate the literal state for this section and push onto the directive stack. */ - ls = xmalloc (sizeof (lit_state)); + ls = XNEW (lit_state); gas_assert (ls); *ls = default_lit_sections; @@ -1594,10 +1586,7 @@ xtensa_literal_prefix (void) "abcdefghijklmnopqrstuvwxyz_/0123456789.$"); /* Get a null-terminated copy of the name. */ - name = xmalloc (len + 1); - gas_assert (name); - strncpy (name, input_line_pointer, len); - name[len] = 0; + name = xmemdup0 (input_line_pointer, len); /* Skip the name in the input line. */ input_line_pointer += len; @@ -1727,7 +1716,7 @@ xtensa_elf_suffix (char **str_p, expressionS *exp_p) char *str2; int ch; int len; - struct suffix_reloc_map *ptr; + unsigned int i; if (*str++ != '@') return BFD_RELOC_NONE; @@ -1744,10 +1733,10 @@ xtensa_elf_suffix (char **str_p, expressionS *exp_p) len = str2 - ident; ch = ident[0]; - for (ptr = &suffix_relocs[0]; ptr->length > 0; ptr++) - if (ch == ptr->suffix[0] - && len == ptr->length - && memcmp (ident, ptr->suffix, ptr->length) == 0) + for (i = 0; i < ARRAY_SIZE (suffix_relocs); i++) + if (ch == suffix_relocs[i].suffix[0] + && len == suffix_relocs[i].length + && memcmp (ident, suffix_relocs[i].suffix, suffix_relocs[i].length) == 0) { /* Now check for "identifier@suffix+constant". */ if (*str == '-' || *str == '+') @@ -1768,7 +1757,7 @@ xtensa_elf_suffix (char **str_p, expressionS *exp_p) } *str_p = str; - return ptr->reloc; + return suffix_relocs[i].reloc; } return BFD_RELOC_UNUSED; @@ -1776,21 +1765,21 @@ xtensa_elf_suffix (char **str_p, expressionS *exp_p) /* Find the matching operator type. */ -static unsigned char +static operatorT map_suffix_reloc_to_operator (bfd_reloc_code_real_type reloc) { - struct suffix_reloc_map *sfx; - unsigned char operator = (unsigned char) -1; + operatorT operator = O_illegal; + unsigned int i; - for (sfx = &suffix_relocs[0]; sfx->suffix; sfx++) + for (i = 0; i < ARRAY_SIZE (suffix_relocs); i++) { - if (sfx->reloc == reloc) + if (suffix_relocs[i].reloc == reloc) { - operator = sfx->operator; + operator = suffix_relocs[i].operator; break; } } - gas_assert (operator != (unsigned char) -1); + gas_assert (operator != O_illegal); return operator; } @@ -1799,14 +1788,14 @@ map_suffix_reloc_to_operator (bfd_reloc_code_real_type reloc) static bfd_reloc_code_real_type map_operator_to_reloc (unsigned char operator, bfd_boolean is_literal) { - struct suffix_reloc_map *sfx; + unsigned int i; bfd_reloc_code_real_type reloc = BFD_RELOC_UNUSED; - for (sfx = &suffix_relocs[0]; sfx->suffix; sfx++) + for (i = 0; i < ARRAY_SIZE (suffix_relocs); i++) { - if (sfx->operator == operator) + if (suffix_relocs[i].operator == operator) { - reloc = sfx->reloc; + reloc = suffix_relocs[i].reloc; break; } } @@ -2026,7 +2015,7 @@ tokenize_arguments (char **args, char *str) arg_end += 1; arg_len = arg_end - input_line_pointer; - arg = (char *) xmalloc ((saw_colon ? 1 : 0) + arg_len + 1); + arg = XNEWVEC (char, (saw_colon ? 1 : 0) + arg_len + 1); args[num_args] = arg; if (saw_colon) @@ -2239,8 +2228,7 @@ xg_reverse_shift_count (char **cnt_argp) cnt_arg = *cnt_argp; /* replace the argument with "31-(argument)" */ - new_arg = (char *) xmalloc (strlen (cnt_arg) + 6); - sprintf (new_arg, "31-(%s)", cnt_arg); + new_arg = concat ("31-(", cnt_arg, ")", (char *) NULL); free (cnt_arg); *cnt_argp = new_arg; @@ -2274,8 +2262,7 @@ static void xg_replace_opname (char **popname, const char *newop) { free (*popname); - *popname = (char *) xmalloc (strlen (newop) + 1); - strcpy (*popname, newop); + *popname = xstrdup (newop); } @@ -2370,8 +2357,7 @@ xg_translate_sysreg_op (char **popname, int *pnum_args, char **arg_strings) /* Another special case for "WSR.INTSET".... */ if (is_write && !is_user && !strcasecmp ("interrupt", sr_name)) sr_name = "intset"; - new_opname = (char *) xmalloc (strlen (sr_name) + 6); - sprintf (new_opname, "%s.%s", *popname, sr_name); + new_opname = concat (*popname, ".", sr_name, (char *) NULL); free (*popname); *popname = new_opname; @@ -2430,7 +2416,7 @@ xtensa_translate_old_userreg_ops (char **popname) /* Translate the opcode. */ sr_name = xtensa_sysreg_name (isa, sr); - new_opname = (char *) xmalloc (strlen (sr_name) + 6); + new_opname = XNEWVEC (char, strlen (sr_name) + 6); sprintf (new_opname, "%s%cur.%s", (has_underbar ? "_" : ""), opname[0], sr_name); free (*popname); @@ -2495,8 +2481,7 @@ xg_translate_idioms (char **popname, int *pnum_args, char **arg_strings) if (xg_check_num_args (pnum_args, 2, opname, arg_strings)) return -1; xg_replace_opname (popname, (has_underbar ? "_or" : "or")); - arg_strings[2] = (char *) xmalloc (strlen (arg_strings[1]) + 1); - strcpy (arg_strings[2], arg_strings[1]); + arg_strings[2] = xstrdup (arg_strings[1]); *pnum_args = 3; } return 0; @@ -2536,12 +2521,9 @@ xg_translate_idioms (char **popname, int *pnum_args, char **arg_strings) if (xg_check_num_args (pnum_args, 0, opname, arg_strings)) return -1; xg_replace_opname (popname, (has_underbar ? "_or" : "or")); - arg_strings[0] = (char *) xmalloc (3); - arg_strings[1] = (char *) xmalloc (3); - arg_strings[2] = (char *) xmalloc (3); - strcpy (arg_strings[0], "a1"); - strcpy (arg_strings[1], "a1"); - strcpy (arg_strings[2], "a1"); + arg_strings[0] = xstrdup ("a1"); + arg_strings[1] = xstrdup ("a1"); + arg_strings[2] = xstrdup ("a1"); *pnum_args = 3; } return 0; @@ -4131,7 +4113,7 @@ xtensa_add_literal_sym (symbolS *sym) { sym_list *l; - l = (sym_list *) xmalloc (sizeof (sym_list)); + l = XNEW (sym_list); l->sym = sym; l->next = literal_syms; literal_syms = l; @@ -5501,9 +5483,7 @@ md_assemble (char *str) /* Split off the opcode. */ opnamelen = strspn (str, "abcdefghijklmnopqrstuvwxyz_/0123456789."); - opname = xmalloc (opnamelen + 1); - memcpy (opname, str, opnamelen); - opname[opnamelen] = '\0'; + opname = xstrndup (str, opnamelen); num_args = tokenize_arguments (arg_strings, str + opnamelen); if (num_args == -1) @@ -6081,7 +6061,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg) } -char * +const char * md_atof (int type, char *litP, int *sizeP) { return ieee_md_atof (type, litP, sizeP, target_big_endian); @@ -6103,8 +6083,8 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp) { arelent *reloc; - reloc = (arelent *) xmalloc (sizeof (arelent)); - reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); + reloc = XNEW (arelent); + reloc->sym_ptr_ptr = XNEW (asymbol *); *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; @@ -6149,7 +6129,7 @@ new_resource_table (void *data, opcode_funcUnit_use_stage_func ousf) { int i; - resource_table *rt = (resource_table *) xmalloc (sizeof (resource_table)); + resource_table *rt = XNEW (resource_table); rt->data = data; rt->cycles = cycles; rt->allocated_cycles = cycles; @@ -6159,9 +6139,9 @@ new_resource_table (void *data, rt->opcode_unit_use = ouuf; rt->opcode_unit_stage = ousf; - rt->units = (unsigned char **) xcalloc (cycles, sizeof (unsigned char *)); + rt->units = XCNEWVEC (unsigned char *, cycles); for (i = 0; i < cycles; i++) - rt->units[i] = (unsigned char *) xcalloc (nu, sizeof (unsigned char)); + rt->units[i] = XCNEWVEC (unsigned char, nu); return rt; } @@ -6191,13 +6171,11 @@ resize_resource_table (resource_table *rt, int cycles) old_cycles = rt->allocated_cycles; rt->allocated_cycles = cycles; - rt->units = xrealloc (rt->units, - rt->allocated_cycles * sizeof (unsigned char *)); + rt->units = XRESIZEVEC (unsigned char *, rt->units, rt->allocated_cycles); for (i = 0; i < old_cycles; i++) - rt->units[i] = xrealloc (rt->units[i], - rt->num_units * sizeof (unsigned char)); + rt->units[i] = XRESIZEVEC (unsigned char, rt->units[i], rt->num_units); for (i = old_cycles; i < cycles; i++) - rt->units[i] = xcalloc (rt->num_units, sizeof (unsigned char)); + rt->units[i] = XCNEWVEC (unsigned char, rt->num_units); } @@ -6975,7 +6953,7 @@ emit_single_op (TInsn *orig_insn) case ITYPE_LABEL: { static int relaxed_sym_idx = 0; - char *label = xmalloc (strlen (FAKE_LABEL_NAME) + 12); + char *label = XNEWVEC (char, strlen (FAKE_LABEL_NAME) + 12); sprintf (label, "%s_rl_%x", FAKE_LABEL_NAME, relaxed_sym_idx++); colon (label); gas_assert (label_sym == NULL); @@ -7448,7 +7426,7 @@ xtensa_create_trampoline_frag (bfd_boolean needs_jump_around) if (ts == NULL) { - ts = (struct trampoline_seg *)xcalloc(sizeof (struct trampoline_seg), 1); + ts = XCNEW(struct trampoline_seg); ts->next = trampoline_seg_list.next; trampoline_seg_list.next = ts; ts->seg = now_seg; @@ -7464,7 +7442,7 @@ xtensa_create_trampoline_frag (bfd_boolean needs_jump_around) trampoline_buf = xtensa_insnbuf_alloc (xtensa_default_isa); trampoline_slotbuf = xtensa_insnbuf_alloc (xtensa_default_isa); } - tf = (struct trampoline_frag *)xmalloc(sizeof (struct trampoline_frag)); + tf = XNEW (struct trampoline_frag); tf->next = ts->trampoline_list.next; ts->trampoline_list.next = tf; tf->needs_jump_around = needs_jump_around; @@ -7563,7 +7541,7 @@ xtensa_maybe_create_literal_pool_frag (bfd_boolean create, if (lps == NULL) { - lps = (struct litpool_seg *)xcalloc (sizeof (struct litpool_seg), 1); + lps = XCNEW (struct litpool_seg); lps->next = litpool_seg_list.next; litpool_seg_list.next = lps; lps->seg = now_seg; @@ -7629,7 +7607,7 @@ xtensa_maybe_create_literal_pool_frag (bfd_boolean create, fragP = frag_now; } - lpf = (struct litpool_frag *)xmalloc(sizeof (struct litpool_frag)); + lpf = XNEW (struct litpool_frag); /* Insert at tail of circular list. */ lpf->addr = 0; lps->frag_list.prev->next = lpf; @@ -8646,7 +8624,7 @@ xtensa_add_config_info (void) info_sec = subseg_new (".xtensa.info", 0); bfd_set_section_flags (stdoutput, info_sec, SEC_HAS_CONTENTS | SEC_READONLY); - data = xmalloc (100); + data = XNEWVEC (char, 100); sprintf (data, "USE_ABSOLUTE_LITERALS=%d\nABI=%d\n", XSHAL_USE_ABSOLUTE_LITERALS, XSHAL_ABI); sz = strlen (data) + 1; @@ -9100,8 +9078,7 @@ static void xtensa_realloc_fixup_cache (fixup_cacheS *cache, unsigned add) if (cache->n_fixups + add > cache->n_max) { cache->n_max = (cache->n_fixups + add) * 2; - cache->fixups = xrealloc (cache->fixups, - sizeof (*cache->fixups) * cache->n_max); + cache->fixups = XRESIZEVEC (cached_fixupS, cache->fixups, cache->n_max); } } @@ -10950,7 +10927,7 @@ get_subseg_info (segT seg, subsegT subseg) static subseg_map * add_subseg_info (segT seg, subsegT subseg) { - subseg_map *subseg_e = (subseg_map *) xmalloc (sizeof (subseg_map)); + subseg_map *subseg_e = XNEW (subseg_map); memset (subseg_e, 0, sizeof (subseg_map)); subseg_e->seg = seg; subseg_e->subseg = subseg; @@ -11559,19 +11536,14 @@ cache_literal_section (bfd_boolean use_abs_literals) base_name = use_abs_literals ? ".lit4" : ".literal"; if (group_name) { - name = xmalloc (strlen (base_name) + strlen (group_name) + 2); - sprintf (name, "%s.%s", base_name, group_name); + name = concat (base_name, ".", group_name, (char *) NULL); } else if (strncmp (text_name, ".gnu.linkonce.", linkonce_len) == 0) { suffix = strchr (text_name + linkonce_len, '.'); - name = xmalloc (linkonce_len + strlen (base_name) + 1 - + (suffix ? strlen (suffix) : 0)); - strcpy (name, ".gnu.linkonce"); - strcat (name, base_name); - if (suffix) - strcat (name, suffix); + name = concat (".gnu.linkonce", base_name, suffix ? suffix : "", + (char *) NULL); linkonce = TRUE; } else @@ -11584,7 +11556,7 @@ cache_literal_section (bfd_boolean use_abs_literals) || strncmp (text_name, ".text", 5) == 0)) len -= 5; - name = xmalloc (len + strlen (base_name) + 1); + name = XNEWVEC (char, len + strlen (base_name) + 1); if (strncmp (text_name, ".text", 5) == 0) { strcpy (name, base_name); @@ -11613,7 +11585,7 @@ cache_literal_section (bfd_boolean use_abs_literals) if (! use_abs_literals) { /* Add the newly created literal segment to the list. */ - seg_list *n = (seg_list *) xmalloc (sizeof (seg_list)); + seg_list *n = XNEW (seg_list); n->seg = seg; n->next = literal_head->next; literal_head->next = n; @@ -11990,8 +11962,7 @@ add_xt_block_frags (segT sec, } if (*xt_block == NULL) { - xtensa_block_info *new_block = (xtensa_block_info *) - xmalloc (sizeof (xtensa_block_info)); + xtensa_block_info *new_block = XNEW (xtensa_block_info); new_block->sec = sec; new_block->offset = fragP->fr_address; new_block->size = fragP->fr_fix; @@ -12248,8 +12219,7 @@ add_xt_prop_frags (segT sec, xtensa_block_info *new_block; if ((*xt_block) != NULL) xt_block = &(*xt_block)->next; - new_block = (xtensa_block_info *) - xmalloc (sizeof (xtensa_block_info)); + new_block = XNEW (xtensa_block_info); *new_block = tmp_block; *xt_block = new_block; } @@ -12274,8 +12244,7 @@ init_op_placement_info_table (void) int slot; int num_opcodes = xtensa_isa_num_opcodes (isa); - op_placement_table = (op_placement_info_table) - xmalloc (sizeof (op_placement_info) * num_opcodes); + op_placement_table = XNEWVEC (op_placement_info, num_opcodes); gas_assert (xtensa_isa_num_formats (isa) < MAX_FORMATS); for (opcode = 0; opcode < num_opcodes; opcode++) @@ -13117,7 +13086,7 @@ copy_expr (expressionS *dst, const expressionS *src) struct rename_section_struct { - char *old_name; + const char *old_name; char *new_name; struct rename_section_struct *next; }; @@ -13179,8 +13148,7 @@ build_section_rename (const char *arg) } /* Now add it. */ - r = (struct rename_section_struct *) - xmalloc (sizeof (struct rename_section_struct)); + r = XNEW (struct rename_section_struct); r->old_name = xstrdup (old_name); r->new_name = xstrdup (new_name); r->next = section_rename; @@ -13190,7 +13158,7 @@ build_section_rename (const char *arg) char * -xtensa_section_rename (char *name) +xtensa_section_rename (const char *name) { struct rename_section_struct *r = section_rename; @@ -13200,5 +13168,5 @@ xtensa_section_rename (char *name) return r->new_name; } - return name; + return (char *) name; }