From: Alan Modra Date: Tue, 14 Jan 2025 04:38:23 +0000 (+1030) Subject: gas HANDLE_ALIGN and frag_alloc X-Git-Tag: binutils-2_44~94 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b477fdd746f67a4d412420470965b4257f7d7111;p=thirdparty%2Fbinutils-gdb.git gas HANDLE_ALIGN and frag_alloc This adds the section to HANDLE_ALIGN args, so that the frag created by the ppc backend can be properly allocated on the frag obstack. I've added an extra param to frag_alloc too, for cases where we know the frag requires at least some bytes in fr_literal. This simplifies some existing code, for example in compress_debug and relax_segment. In the case of the relax_segment code, I think we may have had a bug there in using obstack_blank_fast, which doesn't check that the frag has room. * config/tc-ppc.c (ppc_handle_align): Add section param, use frag obstack to allocate frag. * config/tc-ppc.h (HANDLE_ALIGN, ppc_handle_align): Add extra param. * config/tc-aarch64.h (HANDLE_ALIGN): Add extra param. * config/tc-alpha.h: Likewise. * config/tc-arc.h: Likewise. * config/tc-arm.h: Likewise. * config/tc-avr.h: Likewise. * config/tc-epiphany.h: Likewise. * config/tc-frv.h: Likewise. * config/tc-i386.h: Likewise. * config/tc-ia64.h: Likewise. * config/tc-kvx.h: Likewise. * config/tc-loongarch.h: Likewise. * config/tc-m32c.h: Likewise. * config/tc-m32r.h: Likewise. * config/tc-metag.h: Likewise. * config/tc-mips.h: Likewise. * config/tc-mn10300.h: Likewise. * config/tc-nds32.h: Likewise. * config/tc-riscv.h: Likewise. * config/tc-rl78.h: Likewise. * config/tc-rx.h: Likewise. * config/tc-sh.h: Likewise. * config/tc-sparc.h: Likewise. * config/tc-spu.h: Likewise. * config/tc-tilegx.h: Likewise. * config/tc-tilepro.h: Likewise. * config/tc-v850.h: Likewise. * config/tc-visium.h: Likewise. * config/tc-wasm32.h: Likewise. * config/tc-xtensa.h: Likewise. * frags.h (frag_alloc): Update prototype. * frags.c (frag_alloc): Add extra size param, allocate extra. (frag_new): Update. * subsegs.c (subseg_set_rest): Update frag_alloc call. * write.c: Formatting. (cvt_frag_to_fill): Pass sec to HANDLE_ALIGN. (compress_frag): Update frag_alloc call. (compress_debug): Use new frag_alloc to simplify frag sizing. (relax_segment): Likewise. --- diff --git a/gas/config/tc-aarch64.h b/gas/config/tc-aarch64.h index 52381e31b24..acf1ce4aa03 100644 --- a/gas/config/tc-aarch64.h +++ b/gas/config/tc-aarch64.h @@ -182,7 +182,7 @@ struct aarch64_frag_type #define TC_FRAG_TYPE struct aarch64_frag_type #define TC_FRAG_INIT(fragp, max_bytes) aarch64_init_frag (fragp, max_bytes) -#define HANDLE_ALIGN(fragp) aarch64_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) aarch64_handle_align (fragp) #define md_do_align(N, FILL, LEN, MAX, LABEL) \ if (FILL == NULL && (N) != 0 && ! need_pass_2 && subseg_text_p (now_seg)) \ diff --git a/gas/config/tc-alpha.h b/gas/config/tc-alpha.h index 6937ba0b0ff..466a7a0d9ac 100644 --- a/gas/config/tc-alpha.h +++ b/gas/config/tc-alpha.h @@ -108,7 +108,7 @@ extern void alpha_define_label (symbolS *); #define md_cons_align(nbytes) alpha_cons_align (nbytes) extern void alpha_cons_align (int); -#define HANDLE_ALIGN(fragp) alpha_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) alpha_handle_align (fragp) extern void alpha_handle_align (struct frag *); #define MAX_MEM_FOR_RS_ALIGN_CODE (3 + 4 + 8) diff --git a/gas/config/tc-arc.h b/gas/config/tc-arc.h index 93a1e8d52e8..727041a7169 100644 --- a/gas/config/tc-arc.h +++ b/gas/config/tc-arc.h @@ -111,7 +111,7 @@ extern const char *arc_target_format; /* HANDLE_ALIGN called after all the assembly has been done, so we can fill in all the rs_align_code type frags with nop instructions. */ -#define HANDLE_ALIGN(FRAGP) arc_handle_align (FRAGP) +#define HANDLE_ALIGN(SEC, FRAGP) arc_handle_align (FRAGP) /* Values passed to md_apply_fix3 don't include the symbol value. */ #define MD_APPLY_SYM_VALUE(FIX) 0 diff --git a/gas/config/tc-arm.h b/gas/config/tc-arm.h index 8274632b9bd..24e2197d7e0 100644 --- a/gas/config/tc-arm.h +++ b/gas/config/tc-arm.h @@ -230,7 +230,7 @@ arm_min (int am_p1, int am_p2) #define TC_FRAG_TYPE struct arm_frag_type #define TC_FRAG_INIT(fragp, max_bytes) arm_init_frag (fragp, max_bytes) #define TC_ALIGN_ZERO_IS_DEFAULT 1 -#define HANDLE_ALIGN(fragp) arm_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) arm_handle_align (fragp) /* PR gas/19276: COFF/PE segment alignment is already handled in coff_frob_section(). */ #ifndef TE_PE #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \ diff --git a/gas/config/tc-avr.h b/gas/config/tc-avr.h index 8e1b7b3d47e..47f6778df73 100644 --- a/gas/config/tc-avr.h +++ b/gas/config/tc-avr.h @@ -228,7 +228,7 @@ extern symbolS* avr_undefined_symbol (char*); #define md_post_relax_hook avr_post_relax_hook () extern void avr_post_relax_hook (void); -#define HANDLE_ALIGN(fragP) avr_handle_align (fragP) +#define HANDLE_ALIGN(sec, fragP) avr_handle_align (fragP) extern void avr_handle_align (fragS *); struct avr_frag_data diff --git a/gas/config/tc-epiphany.h b/gas/config/tc-epiphany.h index 63e5d527fa2..dde673305f4 100644 --- a/gas/config/tc-epiphany.h +++ b/gas/config/tc-epiphany.h @@ -72,7 +72,7 @@ extern void epiphany_cgen_md_operand (expressionS *); epiphany_cgen_parse_fix_exp (opinfo, exp) extern int epiphany_cgen_parse_fix_exp (int, expressionS *); -#define HANDLE_ALIGN(f) epiphany_handle_align (f) +#define HANDLE_ALIGN(s, f) epiphany_handle_align (f) extern void epiphany_handle_align (fragS *); #define TARGET_FORMAT "elf32-epiphany" diff --git a/gas/config/tc-frv.h b/gas/config/tc-frv.h index 9f86a2a5807..21e3bac1095 100644 --- a/gas/config/tc-frv.h +++ b/gas/config/tc-frv.h @@ -99,7 +99,7 @@ extern void frv_frob_file (void); for little gain. This code is not meant to be run anyway, so just emit nops. */ #define MAX_MEM_FOR_RS_ALIGN_CODE (3 + 4) -#define HANDLE_ALIGN(FRAGP) do \ +#define HANDLE_ALIGN(SEC, FRAGP) do \ if ((FRAGP)->fr_type == rs_align_code) \ { \ valueT count = ((FRAGP)->fr_next->fr_address \ diff --git a/gas/config/tc-i386.h b/gas/config/tc-i386.h index 78de263b326..d93de2c7985 100644 --- a/gas/config/tc-i386.h +++ b/gas/config/tc-i386.h @@ -374,7 +374,7 @@ extern void i386_generate_nops (fragS *, char *, offsetT, int); #define md_generate_nops(frag, where, amount, control) \ i386_generate_nops ((frag), (where), (amount), (control)) -#define HANDLE_ALIGN(fragP) \ +#define HANDLE_ALIGN(sec, fragP) \ if (fragP->fr_type == rs_align_code) \ { \ offsetT __count = (fragP->fr_next->fr_address \ diff --git a/gas/config/tc-ia64.h b/gas/config/tc-ia64.h index 5ab7823ec85..0f9810d5fd6 100644 --- a/gas/config/tc-ia64.h +++ b/gas/config/tc-ia64.h @@ -154,7 +154,7 @@ extern void ia64_convert_frag (fragS *); #define MD_PCREL_FROM_SECTION(fix,sec) ia64_pcrel_from_section (fix, sec) #define md_section_align(seg,size) (size) #define md_do_align(n,f,l,m,j) ia64_md_do_align (n,f,l,m) -#define HANDLE_ALIGN(f) ia64_handle_align (f) +#define HANDLE_ALIGN(s, f) ia64_handle_align (f) #define md_elf_section_type(str,len) ia64_elf_section_type (str, len) #define md_after_parse_args() ia64_after_parse_args () #define TC_DWARF2_EMIT_OFFSET ia64_dwarf2_emit_offset diff --git a/gas/config/tc-kvx.h b/gas/config/tc-kvx.h index a33b63c1d79..a4d0e2d9b13 100644 --- a/gas/config/tc-kvx.h +++ b/gas/config/tc-kvx.h @@ -296,8 +296,7 @@ extern void kvx_cons_fix_new (fragS *f, int where, int nbytes, /* Enable special handling for the alignment directive. */ extern void kvx_handle_align (fragS *); -#undef HANDLE_ALIGN -#define HANDLE_ALIGN kvx_handle_align +#define HANDLE_ALIGN(s, f) kvx_handle_align (f) #ifdef OBJ_ELF diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h index 5873ad4d9f6..ebed8e0c049 100644 --- a/gas/config/tc-loongarch.h +++ b/gas/config/tc-loongarch.h @@ -139,7 +139,7 @@ extern void loongarch_pre_output_hook (void); #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0 -#define HANDLE_ALIGN(fragp) loongarch_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) loongarch_handle_align (fragp) extern void loongarch_handle_align (struct frag *); #define MAX_MEM_FOR_RS_ALIGN_CODE (3 + 4) diff --git a/gas/config/tc-m32c.h b/gas/config/tc-m32c.h index cc155a81cbb..bcdca98a191 100644 --- a/gas/config/tc-m32c.h +++ b/gas/config/tc-m32c.h @@ -79,5 +79,5 @@ extern int m32c_is_colon_insn (char *, char *); #define H_TICK_HEX 1 #define NOP_OPCODE (bfd_get_mach (stdoutput) == bfd_mach_m32c ? 0xde : 0x04) -#define HANDLE_ALIGN(fragP) +#define HANDLE_ALIGN(sec, fragP) #define MAX_MEM_FOR_RS_ALIGN_CODE 1 diff --git a/gas/config/tc-m32r.h b/gas/config/tc-m32r.h index 2d50b0a5583..6be96bb3c31 100644 --- a/gas/config/tc-m32r.h +++ b/gas/config/tc-m32r.h @@ -63,7 +63,7 @@ extern long m32r_relax_frag (segT, fragS *, long); /* Fill in rs_align_code fragments. */ extern void m32r_handle_align (fragS *); -#define HANDLE_ALIGN(f) m32r_handle_align (f) +#define HANDLE_ALIGN(s, f) m32r_handle_align (f) #define MAX_MEM_FOR_RS_ALIGN_CODE (1 + 2 + 4) diff --git a/gas/config/tc-metag.h b/gas/config/tc-metag.h index ea7bbb2a0ba..9d112c4ae70 100644 --- a/gas/config/tc-metag.h +++ b/gas/config/tc-metag.h @@ -52,7 +52,7 @@ extern int metag_force_relocation (struct fix *); /* Call md_pcrel_from_section(), not md_pcrel_from(). */ #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from_section (FIX, SEC) -#define HANDLE_ALIGN(fragp) metag_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) metag_handle_align (fragp) extern void metag_handle_align (struct frag *); #define DWARF2_LINE_MIN_INSN_LENGTH 1 diff --git a/gas/config/tc-mips.h b/gas/config/tc-mips.h index 02e211e458d..38a0e39b937 100644 --- a/gas/config/tc-mips.h +++ b/gas/config/tc-mips.h @@ -59,7 +59,7 @@ extern char mips_nop_opcode (void); #define NOP_OPCODE (mips_nop_opcode ()) extern void mips_handle_align (struct frag *); -#define HANDLE_ALIGN(fragp) mips_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) mips_handle_align (fragp) #define MAX_MEM_FOR_RS_ALIGN_CODE (3 + 4) diff --git a/gas/config/tc-mn10300.h b/gas/config/tc-mn10300.h index 77917ef6851..ab6192e2aa0 100644 --- a/gas/config/tc-mn10300.h +++ b/gas/config/tc-mn10300.h @@ -125,7 +125,7 @@ extern bool mn10300_allow_local_subtract (expressionS *, expressionS *, segT); #define TC_FRAG_TYPE bool -#define HANDLE_ALIGN(frag) mn10300_handle_align (frag) +#define HANDLE_ALIGN(sec, frag) mn10300_handle_align (frag) extern void mn10300_handle_align (fragS *); /* Only allow call frame debug info optimization when linker relaxation is diff --git a/gas/config/tc-nds32.h b/gas/config/tc-nds32.h index c5449f43476..14109f09dd0 100644 --- a/gas/config/tc-nds32.h +++ b/gas/config/tc-nds32.h @@ -112,7 +112,7 @@ extern void tc_nds32_frame_initial_instructions (void); #define GAS_SORT_RELOCS 1 /* Values passed to md_apply_fix don't include the symbol value. */ #define MD_APPLY_SYM_VALUE(FIX) 0 -#define HANDLE_ALIGN(f) nds32_handle_align (f) +#define HANDLE_ALIGN(s, f) nds32_handle_align (f) #undef DIFF_EXPR_OK /* They should be fixed in linker. */ #define md_relax_frag(segment, fragP, stretch) nds32_relax_frag (segment, fragP, stretch) #define WORKING_DOT_WORD /* We don't need to handle .word strangely. */ diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c index 9c3adb39950..f9614035748 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -6889,7 +6889,7 @@ ppc_nop_select (void) } void -ppc_handle_align (struct frag *fragP) +ppc_handle_align (segT sec, struct frag *fragP) { valueT count = (fragP->fr_next->fr_address - (fragP->fr_address + fragP->fr_fix)); @@ -6928,7 +6928,9 @@ ppc_handle_align (struct frag *fragP) if (count == 0) return; - rest = xmalloc (SIZEOF_STRUCT_FRAG + 4); + segment_info_type *seginfo = seg_info (sec); + struct obstack *ob = &seginfo->frchainP->frch_obstack; + rest = frag_alloc (ob, 4); memcpy (rest, fragP, SIZEOF_STRUCT_FRAG); fragP->fr_next = rest; fragP = rest; @@ -6952,7 +6954,9 @@ ppc_handle_align (struct frag *fragP) reduce the number of nops in the current frag by one. */ if (count > 4) { - struct frag *group_nop = xmalloc (SIZEOF_STRUCT_FRAG + 4); + segment_info_type *seginfo = seg_info (sec); + struct obstack *ob = &seginfo->frchainP->frch_obstack; + struct frag *group_nop = frag_alloc (ob, 4); memcpy (group_nop, fragP, SIZEOF_STRUCT_FRAG); group_nop->fr_address = group_nop->fr_next->fr_address - 4; diff --git a/gas/config/tc-ppc.h b/gas/config/tc-ppc.h index b0893cd1ab2..f6b37f80ef4 100644 --- a/gas/config/tc-ppc.h +++ b/gas/config/tc-ppc.h @@ -73,14 +73,14 @@ extern const char *ppc_target_format (void); #define WORKING_DOT_WORD #define MAX_MEM_FOR_RS_ALIGN_CODE 4 -#define HANDLE_ALIGN(FRAGP) \ +#define HANDLE_ALIGN(SEC, FRAGP) \ if ((FRAGP)->fr_type == rs_align_code) \ - ppc_handle_align (FRAGP); + ppc_handle_align (SEC, FRAGP); extern unsigned int ppc_nop_select (void); #define NOP_OPCODE ppc_nop_select () -extern void ppc_handle_align (struct frag *); +extern void ppc_handle_align (segT, struct frag *); extern void ppc_frag_check (struct frag *); #ifdef OBJ_ELF diff --git a/gas/config/tc-riscv.h b/gas/config/tc-riscv.h index 6b25a791da8..e2e8e7af876 100644 --- a/gas/config/tc-riscv.h +++ b/gas/config/tc-riscv.h @@ -62,7 +62,7 @@ extern bool riscv_frag_align_code (int); } extern void riscv_handle_align (fragS *); -#define HANDLE_ALIGN riscv_handle_align +#define HANDLE_ALIGN(s, f) riscv_handle_align (f) #define MAX_MEM_FOR_RS_ALIGN_CODE (3 + 4) diff --git a/gas/config/tc-rl78.h b/gas/config/tc-rl78.h index 12aca9ea4c2..4a513250ab9 100644 --- a/gas/config/tc-rl78.h +++ b/gas/config/tc-rl78.h @@ -76,7 +76,7 @@ extern void rl78_cons_fix_new (fragS *, int, int, expressionS *); #define MAX_RELOC_EXPANSION 8 #define MAX_MEM_FOR_RS_ALIGN_CODE 8 -#define HANDLE_ALIGN(FRAG) rl78_handle_align (FRAG) +#define HANDLE_ALIGN(SEC, FRAG) rl78_handle_align (FRAG) extern void rl78_handle_align (fragS *); #define elf_tc_final_processing rl78_elf_final_processing diff --git a/gas/config/tc-rx.h b/gas/config/tc-rx.h index 859a0b77c3a..3c4524f4aa9 100644 --- a/gas/config/tc-rx.h +++ b/gas/config/tc-rx.h @@ -97,7 +97,7 @@ extern void rx_cons_fix_new (fragS *, int, int, expressionS *, } #define MAX_MEM_FOR_RS_ALIGN_CODE 8 -#define HANDLE_ALIGN(FRAG) rx_handle_align (FRAG) +#define HANDLE_ALIGN(SEC, FRAG) rx_handle_align (FRAG) extern void rx_handle_align (fragS *); #define RELOC_EXPANSION_POSSIBLE 1 diff --git a/gas/config/tc-sh.h b/gas/config/tc-sh.h index 38247ebbe17..fb1e4b81244 100644 --- a/gas/config/tc-sh.h +++ b/gas/config/tc-sh.h @@ -53,7 +53,7 @@ extern int sh_optimize_expr (expressionS *, operatorT, expressionS *); /* When relaxing, we need to generate relocations for alignment directives. */ -#define HANDLE_ALIGN(frag) sh_handle_align (frag) +#define HANDLE_ALIGN(sec, frag) sh_handle_align (frag) extern void sh_handle_align (fragS *); #define MAX_MEM_FOR_RS_ALIGN_CODE (1 + 2) diff --git a/gas/config/tc-sparc.h b/gas/config/tc-sparc.h index f18bc1d93ad..b87212f011d 100644 --- a/gas/config/tc-sparc.h +++ b/gas/config/tc-sparc.h @@ -75,7 +75,7 @@ extern int sparc_pic_code; #define md_cons_align(nbytes) sparc_cons_align (nbytes) extern void sparc_cons_align (int); -#define HANDLE_ALIGN(fragp) sparc_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) sparc_handle_align (fragp) extern void sparc_handle_align (struct frag *); #define MAX_MEM_FOR_RS_ALIGN_CODE (3 + 4 + 4) diff --git a/gas/config/tc-spu.h b/gas/config/tc-spu.h index 8c132d3ce0b..4c164856c1f 100644 --- a/gas/config/tc-spu.h +++ b/gas/config/tc-spu.h @@ -102,7 +102,7 @@ extern symbolS *section_symbol (asection *); /* Fill in rs_align_code fragments. */ extern void spu_handle_align (fragS *); -#define HANDLE_ALIGN(frag) spu_handle_align (frag) +#define HANDLE_ALIGN(sec, frag) spu_handle_align (frag) #define MAX_MEM_FOR_RS_ALIGN_CODE (7 + 8) diff --git a/gas/config/tc-tilegx.h b/gas/config/tc-tilegx.h index 08a87ae48d4..06db4416ec5 100644 --- a/gas/config/tc-tilegx.h +++ b/gas/config/tc-tilegx.h @@ -39,7 +39,7 @@ extern const char * tilegx_target_format (void); #define DIFF_EXPR_OK /* foo-. gets turned into PC relative relocs */ -#define HANDLE_ALIGN(fragp) tilegx_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) tilegx_handle_align (fragp) extern void tilegx_handle_align (struct frag *); #define MAX_MEM_FOR_RS_ALIGN_CODE (7 + 8) diff --git a/gas/config/tc-tilepro.h b/gas/config/tc-tilepro.h index 6fb98532c7c..945d1cac9a1 100644 --- a/gas/config/tc-tilepro.h +++ b/gas/config/tc-tilepro.h @@ -39,7 +39,7 @@ #define DIFF_EXPR_OK /* foo-. gets turned into PC relative relocs */ -#define HANDLE_ALIGN(fragp) tilepro_handle_align (fragp) +#define HANDLE_ALIGN(sec, fragp) tilepro_handle_align (fragp) extern void tilepro_handle_align (struct frag *); #define MAX_MEM_FOR_RS_ALIGN_CODE (7 + 8) diff --git a/gas/config/tc-v850.h b/gas/config/tc-v850.h index c06ab6848be..1e234416cd6 100644 --- a/gas/config/tc-v850.h +++ b/gas/config/tc-v850.h @@ -69,7 +69,7 @@ extern const struct relax_type md_relax_table[]; /* When relaxing, we need to generate relocations for alignment directives. */ -#define HANDLE_ALIGN(frag) v850_handle_align (frag) +#define HANDLE_ALIGN(sec, frag) v850_handle_align (frag) extern void v850_handle_align (fragS *); /* We need space in a frag's fixed size to allow for alignment when relaxing. */ diff --git a/gas/config/tc-visium.h b/gas/config/tc-visium.h index 6a5e8e2c67b..01f86285d3f 100644 --- a/gas/config/tc-visium.h +++ b/gas/config/tc-visium.h @@ -45,7 +45,7 @@ #define tc_fix_adjustable(FIXP) visium_fix_adjustable (FIXP) extern bool visium_fix_adjustable (struct fix *); -#define HANDLE_ALIGN(FRAGP) \ +#define HANDLE_ALIGN(SEC, FRAGP) \ if ((FRAGP)->fr_type == rs_align_code) \ visium_handle_align (FRAGP); extern void visium_handle_align (struct frag *); diff --git a/gas/config/tc-wasm32.h b/gas/config/tc-wasm32.h index 32d7d8783b3..b2ccf1cff59 100644 --- a/gas/config/tc-wasm32.h +++ b/gas/config/tc-wasm32.h @@ -75,7 +75,7 @@ extern int wasm32_force_relocation (struct fix *); #define elf_tc_final_processing() #define md_post_relax_hook #define md_start_line_hook() -#define HANDLE_ALIGN(fragP) +#define HANDLE_ALIGN(sec, fragP) extern bool wasm32_fix_adjustable (struct fix *); diff --git a/gas/config/tc-xtensa.h b/gas/config/tc-xtensa.h index 00d03c01943..3d757e8413c 100644 --- a/gas/config/tc-xtensa.h +++ b/gas/config/tc-xtensa.h @@ -378,7 +378,7 @@ extern void xtensa_init (int, char **); #define TEXT_SECTION_NAME xtensa_section_rename (".text") #define DATA_SECTION_NAME xtensa_section_rename (".data") #define BSS_SECTION_NAME xtensa_section_rename (".bss") -#define HANDLE_ALIGN(fragP) xtensa_handle_align (fragP) +#define HANDLE_ALIGN(sec, fragP) xtensa_handle_align (fragP) #define MAX_MEM_FOR_RS_ALIGN_CODE 1 diff --git a/gas/frags.c b/gas/frags.c index a57a4d56187..d067bb4761e 100644 --- a/gas/frags.c +++ b/gas/frags.c @@ -73,7 +73,7 @@ frag_alloc_check (const struct obstack *ob) hackery can be done in just one place. */ fragS * -frag_alloc (struct obstack *ob) +frag_alloc (struct obstack *ob, size_t extra) { fragS *ptr; int oalign; @@ -81,7 +81,7 @@ frag_alloc (struct obstack *ob) (void) obstack_alloc (ob, 0); oalign = obstack_alignment_mask (ob); obstack_alignment_mask (ob) = 0; - ptr = (fragS *) obstack_alloc (ob, SIZEOF_STRUCT_FRAG); + ptr = (fragS *) obstack_alloc (ob, extra + SIZEOF_STRUCT_FRAG); obstack_alignment_mask (ob) = oalign; memset (ptr, 0, SIZEOF_STRUCT_FRAG); totalfrags++; @@ -180,7 +180,7 @@ frag_new (size_t old_frags_var_max_size former_last_fragP = frchP->frch_last; gas_assert (former_last_fragP != 0); gas_assert (former_last_fragP == frag_now); - frag_now = frag_alloc (&frchP->frch_obstack); + frag_now = frag_alloc (&frchP->frch_obstack, 0); frag_now->fr_file = as_where (&frag_now->fr_line); diff --git a/gas/frags.h b/gas/frags.h index a1dcea0be0c..695277d7871 100644 --- a/gas/frags.h +++ b/gas/frags.h @@ -124,7 +124,7 @@ extern void frag_append_1_char (int); #define FRAG_APPEND_1_CHAR(X) frag_append_1_char (X) void frag_init (void); -fragS *frag_alloc (struct obstack *); +fragS *frag_alloc (struct obstack *, size_t); void frag_grow (size_t nchars); char *frag_more (size_t nchars); void frag_align (int alignment, int fill_character, int max); diff --git a/gas/subsegs.c b/gas/subsegs.c index 837af056485..e098ec4302a 100644 --- a/gas/subsegs.c +++ b/gas/subsegs.c @@ -127,7 +127,7 @@ subseg_set_rest (segT seg, subsegT subseg) #if __GNUC__ >= 2 obstack_alignment_mask (&newP->frch_obstack) = __alignof__ (fragS) - 1; #endif - newP->frch_frag_now = frag_alloc (&newP->frch_obstack); + newP->frch_frag_now = frag_alloc (&newP->frch_obstack, 0); newP->frch_frag_now->fr_type = rs_fill; newP->frch_cfi_data = NULL; newP->frch_ginsn_data = NULL; diff --git a/gas/write.c b/gas/write.c index e8231603961..439f6a6913a 100644 --- a/gas/write.c +++ b/gas/write.c @@ -417,7 +417,7 @@ cvt_frag_to_fill (segT sec ATTRIBUTE_UNUSED, fragS *fragP) case rs_org: case rs_space: #ifdef HANDLE_ALIGN - HANDLE_ALIGN (fragP); + HANDLE_ALIGN (sec, fragP); #endif skip_align: know (fragP->fr_next != NULL); @@ -737,11 +737,11 @@ resolve_reloc_expr_symbols (void) else if (sym != NULL && sec != NULL) { /* Convert relocs against local symbols to refer to the - corresponding section symbol plus offset instead. Keep - PC-relative relocs of the REL variety intact though to + corresponding section symbol plus offset instead. Keep + PC-relative relocs of the REL variety intact though to prevent the offset from overflowing the relocated field, - unless it has enough bits to cover the whole address - space. */ + unless it has enough bits to cover the whole address + space. */ if (S_IS_LOCAL (sym) && S_IS_DEFINED (sym) && !symbol_section_p (sym) @@ -1448,17 +1448,17 @@ compress_frag (bool use_zstd, void *ctx, const char *contents, int in_size, while (in_size > 0) { /* Reserve all the space available in the current chunk. - If none is available, start a new frag. */ + If none is available, start a new frag. */ avail_out = obstack_room (ob); if (avail_out <= 0) - { - obstack_finish (ob); - f = frag_alloc (ob); + { + obstack_finish (ob); + f = frag_alloc (ob, 0); f->fr_type = rs_fill; - (*last_newf)->fr_next = f; - *last_newf = f; - avail_out = obstack_room (ob); - } + (*last_newf)->fr_next = f; + *last_newf = f; + avail_out = obstack_room (ob); + } if (avail_out <= 0) as_fatal (_("can't extend frag")); next_out = obstack_next_free (ob); @@ -1510,16 +1510,8 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) /* Create a new frag to contain the compression header. */ struct obstack *ob = &seginfo->frchainP->frch_obstack; - fragS *first_newf = frag_alloc (ob); - if (obstack_room (ob) < header_size) - first_newf = frag_alloc (ob); - if (obstack_room (ob) < header_size) - as_fatal (ngettext ("can't extend frag %lu char", - "can't extend frag %lu chars", - (unsigned long) header_size), - (unsigned long) header_size); + fragS *first_newf = frag_alloc (ob, header_size); fragS *last_newf = first_newf; - obstack_blank_fast (ob, header_size); last_newf->fr_type = rs_fill; last_newf->fr_fix = header_size; char *header = last_newf->fr_literal; @@ -1577,7 +1569,7 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) fragS *newf; obstack_finish (ob); - newf = frag_alloc (ob); + newf = frag_alloc (ob, 0); newf->fr_type = rs_fill; last_newf->fr_next = newf; last_newf = newf; @@ -2994,9 +2986,7 @@ relax_segment (struct frag *segment_frag_root, segT segment, int pass) struct obstack *ob = &seginfo->frchainP->frch_obstack; struct frag *newf; - newf = frag_alloc (ob); - obstack_blank_fast (ob, fragP->fr_var); - obstack_finish (ob); + newf = frag_alloc (ob, fragP->fr_var); memcpy (newf, fragP, SIZEOF_STRUCT_FRAG); memcpy (newf->fr_literal, fragP->fr_literal + fragP->fr_fix,