Files
binutils-gdb/gas/config/tc-wasm32.h
Alan Modra 7ca6020a4e tidy target HANDLE_ALIGN
avr, kvx, metag, mn10300, nds32, v850, visium, and wasm32 targets
defined HANDLE_ALIGN without defining MAX_MEM_FOR_RS_ALIGN_CODE.  This
can result in a rather large chunk of memory being allocated.  Fix
that by a combination of changing the default allocation to one byte
and/or defining a target MAX_MEM_FOR_RS_ALIGN_CODE.

arm wanted to write out the entire set of nops, and limited allowed
code alignment to 64 bytes to prevent large memory allocations.
Fix that by making use of the fact that rs_align_code frags repeat
fr_var bytes at fr_literal + fr_fix to fill out the required area.
Fix metag, nds32 and kvx too, which it seems copied either arm or x86
in similarly not making use of repeating patterns.

It's worth mentioning that my tidy to kvx changed the order of nop
bundles, placing a short bundle first rather than last.

epiphany was totally broken in that uninitialised data was written out
for any alignment requiring more than three bytes of fill.

ppc created a new frag to handle a branch over a large number of nops.
This saves 4 bytes per rs_align_code frag, and most times the branch
isn't used so it is generally a win for memory usage, but I figured
the extra code complexity wasn't worth it.  So that code of mine goes.
visium copied the same scheme, so that goes too.

This leaves x86 as the only target making large allocations for
alignment frags.

	* frags.c (MAX_MEM_FOR_RS_ALIGN_CODE): Default to 1.
	* config/tc-aarch64.c (aarch64_handle_align): Remove always true
	condition.
	* config/tc-aarch64.h (MAX_MEM_FOR_RS_ALIGN_CODE): Move to be
	adjacent to HANDLE_ALIGN define.
	* config/tc-arm.c (arm_handle_align): Allow alignment of more
	than MAX_MEM_FOR_RS_ALIGN_CODE bytes.  Just write one repeat
	of nop pattern to frag.
	(arm_frag_align_code): Delete function.
	* config/tc-arm.h (MAX_MEM_ALIGNMENT_BYTES): Don't define.
	(MAX_MEM_FOR_RS_ALIGN_CODE): Set to 7.
	(md_do_align): Don't define.
	(arm_frag_align_code): Don't declare.
	* config/tc-epiphany.c (epiphany_handle_align): Correct frag
	so that nop_pattern repeats rather than random data.
	* config/tc-epiphany.h (MAX_MEM_FOR_RS_ALIGN_CODE): Define.
	* config/tc-kvx.c (kvx_make_nops): Merge into..
	(kvx_handle_align): ..here.  Put short nop bundle first,
	followed by repeated full nop bundle.
	* config/tc-kvx.h (MAX_MEM_FOR_RS_ALIGN_CODE): Define.
	* config/tc-m32c.h (HANDLE_ALIGN, MAX_MEM_FOR_RS_ALIGN_CODE):
	Don't define.
	* config/tc-metag.c (metag_handle_align): Just write one
	repeat of nop pattern to frag.
	* config/tc-metag.h (MAX_MEM_FOR_RS_ALIGN_CODE): Define.
	* config/tc-nds32.c (nds32_handle_align): Just write one
	repeat of nop pattern to frag.
	* config/tc-nds32.h (MAX_MEM_FOR_RS_ALIGN_CODE): Define.
	* config/tc-ppc.c (ppc_handle_align): Don't make a new frag
	for branch.
	* config/tc-ppc.h (MAX_MEM_FOR_RS_ALIGN_CODE): Increase to 8.
	* config/tc-visium.c (visium_handle_align): Don't make a new
	frag for branch.
	* config/tc-visium.h (MAX_MEM_FOR_RS_ALIGN_CODE): Define.
	* config/tc-wasm32.h (HANDLE_ALIGN): Don't define.
	* testsuite/gas/epiphany/nop.d,
	* testsuite/gas/epiphany/nop.s: New test.
	* testsuite/gas/epiphany/allinsn.exp: Run it.
	* testsuite/gas/kvx/nop-align.d: Adjust.
2025-05-23 08:26:08 +09:30

89 lines
3.1 KiB
C

/* This file is tc-wasm32.h.
Copyright (C) 2017-2025 Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
GAS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to the Free
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
#define TC_WASM32
#define TARGET_FORMAT "elf32-wasm32"
#define TARGET_ARCH bfd_arch_wasm32
#define TARGET_MACH 1
/* WebAssembly is strictly little-endian. */
#define TARGET_BYTES_BIG_ENDIAN 0
#define md_number_to_chars number_to_chars_littleendian
#define DIFF_EXPR_OK
/* No machine-dependent operand expressions. */
#define md_operand(x)
/* No broken word processing. */
#define WORKING_DOT_WORD
/* Force some relocations. */
#define EXTERN_FORCE_RELOC 1
extern int wasm32_force_relocation (struct fix *);
#define TC_FORCE_RELOCATION(fix) wasm32_force_relocation (fix)
#define TC_FORCE_RELOCATION_LOCAL(fix) 1
#define TC_FORCE_RELOCATION_SUB_SAME(fix,seg) wasm32_force_relocation (fix)
#define TC_FORCE_RELOCATION_SUB_ABS(fix,seg) wasm32_force_relocation (fix)
#define TC_FORCE_RELOCATION_SUB_LOCAL(fix,seg) wasm32_force_relocation (fix)
#define TC_VALIDATE_FIX_SUB(fix,seg) wasm32_force_relocation (fix)
/* This is ELF, values passed to md_apply_fix don't include the symbol
value. */
#define MD_APPLY_SYM_VALUE(FIX) 0
/* PC-relative relocations are relative to the relocation offset. */
#define MD_PCREL_FROM_SECTION(FIX, SEC) 0
#define DWARF2_LINE_MIN_INSN_LENGTH 1
/* WebAssembly uses 32-bit addresses. */
#define TC_ADDRESS_BYTES() 4
#define DWARF2_ADDR_SIZE(bfd) 4
/* Enable cfi directives. */
#define TARGET_USE_CFIPOP 1
/* The stack grows down, and there is no harm in claiming it is only
byte aligned. */
#define DWARF2_CIE_DATA_ALIGNMENT -1
/* Define the column that represents the PC. FIXME: this depends on
the ABI. */
#define DWARF2_DEFAULT_RETURN_COLUMN 36
/* Define a hook to setup initial CFI state. */
#define tc_cfi_frame_initial_instructions() do { } while (0)
#define elf_tc_final_processing()
#define md_post_relax_hook
#define md_start_line_hook()
extern bool wasm32_fix_adjustable (struct fix *);
#define tc_fix_adjustable(FIX) wasm32_fix_adjustable (FIX)
/* Type names for blocks and signatures. */
#define BLOCK_TYPE_NONE 0x40
#define BLOCK_TYPE_I32 0x7f
#define BLOCK_TYPE_I64 0x7e
#define BLOCK_TYPE_F32 0x7d
#define BLOCK_TYPE_F64 0x7c