Commit Graph

6307 Commits

Author SHA1 Message Date
Alan Modra
ce3ab55fa7 ecoff find_nearest_line and final link leaks
Freeing ecoff_debug_info "pointers to the unswapped symbolic info"
isn't a simple matter, due to differing allocation strategies.  In
_bfd_ecoff_slurp_symbolic_info the pointers are to objalloc memory.
In the ecoff linker they are to separately malloc'd memory.  In gas we
have most (obj-elf) or all (obj-ecoff) into a single malloc'd buffer.

This patch fixes the leaks for binutils and ld, leaving the gas leaks
for another day.  The mips elf backend already had this covered, and
the ecoff backend had a pointer, raw_syments used as a flag, so most
of the patch is moving these around a little so they are accessible
for both ecoff and elf.

include/
	* coff/ecoff.h (struct ecoff_debug_info): Add alloc_syments.
bfd/
	* libecoff.h (struct ecoff_tdata): Delete raw_syments.
	* elfxx-mips.c (free_ecoff_debug): Delete.  Replace uses with
	_bfd_ecoff_free_ecoff_debug_info.
	(_bfd_mips_elf_final_link): Init debug.alloc_syments.
	* ecofflink.c (_bfd_ecoff_free_ecoff_debug_info): New function.
	* ecoff.c (_bfd_ecoff_bfd_free_cached_info): Call
	_bfd_ecoff_free_ecoff_debug_info.
	(_bfd_ecoff_slurp_symbolic_info): Replace uses of raw_syments
	with alloc_syments.
	(ecoff_final_link_debug_accumulate): Likewise.  Use
	_bfd_ecoff_free_ecoff_debug_info.
	(_bfd_ecoff_bfd_copy_private_bfd_data): Set alloc_syments for
	copied output.
	* elf64-alpha.c (elf64_alpha_read_ecoff_info): Use
	_bfd_ecoff_free_ecoff_debug_info.
	* libbfd-in.h (_bfd_ecoff_free_ecoff_debug_info): Declare.
	* libbfd.h: Regenerate.
gas/
	* config/obj-ecoff.c (ecoff_frob_file): Set alloc_syments.
	* config/obj-elf.c (elf_frob_file_after_relocs): Likewise.
2023-06-09 12:56:12 +09:30
YunQiang Su
acce83dacf MIPS: add MT ASE support for micromips32
These instructions are descripted in MD00768.

MIPS® Architecture for Programmers
Volume IV-f: The MIPS® MT Module for
the microMIPS32™ Architecture

Document Number: MD00768
Revision 1.12
July 16, 2013

https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00768-1C-microMIPS32MT-AFP-01.12.pdf
2023-06-05 11:14:46 +08:00
YunQiang Su
c0f7927b3d Revert "MIPS: add MT ASE support for micromips32"
This reverts commit 783a5f46b0.
2023-06-05 11:10:23 +08:00
YunQiang Su
783a5f46b0 MIPS: add MT ASE support for micromips32
These instructions are descripted in MD00768.

MIPS® Architecture for Programmers
Volume IV-f: The MIPS® MT Module for
the microMIPS32™ Architecture

Document Number: MD00768
Revision 1.12
July 16, 2013

https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00768-1C-microMIPS32MT-AFP-01.12.pdf
2023-06-05 11:06:10 +08:00
YunQiang Su
094025a30b MIPS: gas: alter 64 or 32 for mipsisa triples if march is implicit
When configure with triples mipsisa[32,64]rN[el,], the march value
is pinned to a fix value if not given explicitly. for example
   1) mipsisa32r6-linux-gnu -n32 xx.s will complains that:
      -march=mips32r6 is not compatible with the selected ABI
   2) mipsisa64r2el-linux-gnu -o32 generates objects with 64bit CPU:
      ELF 32-bit LSB relocatable, MIPS, MIPS64 rel2 version 1 (SYSV)
They are not good default behaviors: Let's alter the CPU info

Since we are using these triples as a regular linux distributions,
let's alter march according to ABI.
2023-06-05 11:00:14 +08:00
Jim Wilson
ec2260af61 RISC-V: PR30449, Add lga assembler macro support.
Originally discussion, https://github.com/riscv/riscv-isa-manual/pull/539

Added new load address pseudo instruction which is always expanded to GOT
access, no matter the .option rvc is set or not.

gas/
	PR 30449
	* config/tc-riscv.c (macro): Add M_LGA support.
	* testsuite/gas/riscv/la-variants.d: New.
	* testsuite/gas/riscv/la-variants.s: New.
include/
	PR 30449
	* opcode/riscv.h (M_LGA): New.
opcodes/
	PR 30449
	* riscv-opc.c (riscv_opcodes): Add lga support.
2023-06-01 12:25:08 +08:00
mengqinggang
56576f4a72 LoongArch: gas: Add support for linker relaxation.
Add gas -mrelax and -mno-relax option.
Add R_LARCH_RELAX reloc for instrction if it can be relaxed.
ADD R_LARCH_ALIGN reloc for align pseudo instruction because relax.
Add ADD/SUB reloc pair for debug and exception data to calculate symbol
substraction because relax.

gas/ChangeLog:

	* config/tc-loongarch.c:
	(struct loongarch_cl_insn): New macro_id member.
	(enum options): New OPTION_RELAX and OPTION_NO_RELAX.
	(struct option): New mrelax and mno-relax.
	(md_parse_option): Likewise.
	(get_internal_label):
	(loongarch_args_parser_can_match_arg_helper): Generate relax reloc.
	(move_insn): Set fx_frag and fx_where if exist.
	(append_fixp_and_insn): Call frag_wane and frag_new for linker relax
	relocs.
	(loongarch_assemble_INSNs): New loongarch_cl_insn pointer parameter.
	(md_assemble): Fix function call.
	(fix_reloc_insn): Likewise.
	(md_apply_fix): Generate ADD/SUB reloc pair for debug and exception
	data.
	(loongarch_fix_adjustable): Delete.
	(md_convert_frag): Generate new fix.
	(loongarch_pre_output_hook): New function.
	(loongarch_make_nops): Likewise.
	(loongarch_frag_align_code): Likewise.
	(loongarch_insert_uleb128_fixes): Likewise.
	(loongarch_md_finish): Likewise.
	* config/tc-loongarch.h
	(md_allow_local_subtract): New macro define.
	(loongarch_frag_align_code): New declare.
	(md_do_align): Likewise.
	(loongarch_fix_adjustable): Delete.
	(tc_fix_adjustable): New macro define.
	(TC_FORCE_RELOCATION_SUB_SAME): Likewise.
	(TC_LINKRELAX_FIXUP): Likewise.
	(TC_FORCE_RELOCATION_LOCAL): Likewise.
	(DWARF2_USE_FIXED_ADVANCE_PC): Likewise.
	(MD_APPLY_SYM_VALUE): Likewise.
	(tc_symbol_new_hook): New extern.
	(NOP_OPCODE): Delete.
	(loongarch_pre_output_hook): New macro define.
	(md_pre_output_hook): Likewise.
	(md_finish): Likewise.
	(loongarch_md_finish): New extern.
	* testsuite/gas/all/align.d: Mark as unsupported on LoongArch.
	* testsuite/gas/all/gas.exp: Xfail loongarch*-*.
	* testsuite/gas/all/relax.d: Likewise.
	* testsuite/gas/elf/dwarf-5-irp.d: Likewise.
	* testsuite/gas/elf/dwarf-5-loc0.d: Likewise.
	* testsuite/gas/elf/dwarf-5-macro-include.d: Likewise.
	* testsuite/gas/elf/dwarf-5-macro.d: Likewise.
	* testsuite/gas/elf/dwarf2-11.d: Likewise.
	* testsuite/gas/elf/dwarf2-15.d: Likewise.
	* testsuite/gas/elf/dwarf2-16.d: Likewise.
	* testsuite/gas/elf/dwarf2-17.d: Likewise.
	* testsuite/gas/elf/dwarf2-18.d: Likewise.
	* testsuite/gas/elf/dwarf2-19.d: Likewise.
	* testsuite/gas/elf/dwarf2-5.d: Likewise.
	* testsuite/gas/elf/ehopt0.d: Likewise.
	* testsuite/gas/elf/elf.exp: Likewise.
	* testsuite/gas/elf/section11.d: Likewise.
	* testsuite/gas/lns/lns.exp: Likewise.
	* testsuite/gas/loongarch/jmp_op.d: Regenerated.
	* testsuite/gas/loongarch/li.d: Likewise.
	* testsuite/gas/loongarch/macro_op.d: Likewise.
	* testsuite/gas/loongarch/macro_op_32.d: Likewise.
	* testsuite/gas/loongarch/macro_op_large_abs.d: Likewise.
	* testsuite/gas/loongarch/macro_op_large_pc.d: Likewise.
	* testsuite/gas/loongarch/relax_align.d: New test.
	* testsuite/gas/loongarch/relax_align.s: New test.
	* testsuite/gas/loongarch/uleb128.d: New test.
	* testsuite/gas/loongarch/uleb128.s: New test.
2023-05-30 19:56:46 +08:00
Alan Modra
0b32bdabdc Don't define COFF_MAGIC
This macro was unused apart from aout/encap.h, which has been deleted.

	* config/tc-arm.h (COFF_MAGIC): Don't define.
	* config/tc-sh.h (COFF_MAGIC): Don't define.
	* config/tc-z80.h (COFF_MAGIC): Don't define.
	* config/tc-z8k.h (COFF_MAGIC): Don't define.
2023-05-30 12:51:39 +09:30
Jan Beulich
590a0fed02 x86-64: improve gas diagnostic when no 32-bit target is configured
Make this similar to --64 and --x32: Check whether a suitable target
exists.
2023-05-26 10:14:13 +02:00
Jan Beulich
778415f597 x86: figure braces aren't really part of mnemonics
Instead they're separators for pseudo-prefixes. Don't insert them in
mnemonic_chars[], handling them explicitly in parse_insn() instead. Note
that this eliminates the need for another separator after a pseudo-
prefix. While maybe not overly interesting for a following real
mnemonic, I view this as quite desirable between multiple successive
pseudo-prefixes (bringing things in line with the other use of figure
braces in AVX512's zeroing-masking).

Drop the unused is_mnemonic_char() at this occasion.
2023-05-26 09:42:03 +02:00
Jan Beulich
d2b1a14de3 x86: de-duplicate operand_special_chars[] wrt extra_symbol_chars[]
Having to add characters to both arrays can easily lead to oversights.
Consuming extra_symbol_chars[] when populating operand_chars[] also
allows to drop two special cases in md_begin().

Constify operand_special_chars[] at this occasion.
2023-05-26 09:41:41 +02:00
Jan Beulich
a4f8c177b4 x86/Intel: address quoted-symbol related FIXMEs
If in a "word ptr <address>" or alike construct the "ptr" part is
double-quoted, it shouldn't be recognized as the specific keyword we're
looking for (just like we don't recognize double-quoted operator or
register names anymore). Be careful though to tell closing from opening
double-quotes, as a quoted symbol may follow right afterwards.
2023-05-23 09:01:31 +02:00
Jan Beulich
6acf913090 x86: don't recognize quoted symbol names as registers or operators
The concept of quoted symbols names was introduced pretty late. Utilize
it to allow access to symbols with names matching that of a register (or,
in Intel syntax, also an identifier-like operator).

This is primarily to aid gcc when generating Intel syntax output; see
their bug target/53929.
2023-05-23 09:00:44 +02:00
Zhang, Jun
c88ed92f0c Support Intel FRED LKGS
gas/ChangeLog:

	* NEWS: Support Intel FRED LKGS.
	* config/tc-i386.c: Add fred lkgs
	* doc/c-i386.texi: Document .fred, .lkgs.
	* testsuite/gas/i386/i386.exp: Add FRED LKGS tests
	* testsuite/gas/i386/x86-64-fred-intel.d: Ditto.
	* testsuite/gas/i386/x86-64-fred.d: Ditto.
	* testsuite/gas/i386/x86-64-fred.s: Ditto.
	* testsuite/gas/i386/x86-64-lkgs-intel.d: Ditto.
	* testsuite/gas/i386/x86-64-lkgs-inval.l: Ditto.
	* testsuite/gas/i386/x86-64-lkgs-inval.s: Ditto.
	* testsuite/gas/i386/x86-64-lkgs.d: Ditto.
	* testsuite/gas/i386/x86-64-lkgs.s: Ditto.

opcodes/ChangeLog:

	* i386-dis.c: New entry for fred, lkgs.
	* i386-gen.c: Add CPU_FRED CPU_LKGS.
	* i386-init.h : Regenerated.
	* i386-mnem.h : Regenerated.
	* i386-opc.h: Add fred, lkgs.
	* i386-opc.tbl: Add FRED, LKGS instructions.
	* i386-tbl.h: Regenerated.
2023-05-23 14:43:23 +08:00
liuhongt
cbf25f4705 Revert "Support Intel FRED LKGS"
This reverts commit e5a497fe38.
2023-05-23 14:42:20 +08:00
Zhang, Jun
e5a497fe38 Support Intel FRED LKGS
gas/ChangeLog:

        * NEWS: Support Intel FRED LKGS.
        * config/tc-i386.c: Add fred lkgs
        * doc/c-i386.texi: Document .fred, .lkgs.
        * testsuite/gas/i386/i386.exp: Add FRED LKGS tests
        * testsuite/gas/i386/x86-64-fred-intel.d: Ditto.
        * testsuite/gas/i386/x86-64-fred.d: Ditto.
        * testsuite/gas/i386/x86-64-fred.s: Ditto.
        * testsuite/gas/i386/x86-64-lkgs-intel.d: Ditto.
        * testsuite/gas/i386/x86-64-lkgs-inval.l: Ditto.
        * testsuite/gas/i386/x86-64-lkgs-inval.s: Ditto.
        * testsuite/gas/i386/x86-64-lkgs.d: Ditto.
        * testsuite/gas/i386/x86-64-lkgs.s: Ditto.

opcodes/ChangeLog:

        * i386-dis.c: New entry for fred, lkgs.
        * i386-gen.c: Add CPU_FRED CPU_LKGS.
        * i386-init.h : Regenerated.
        * i386-mnem.h : Regenerated.
        * i386-opc.h: Add fred, lkgs.
        * i386-opc.tbl: Add FRED, LKGS instructions.
        * i386-tbl.h: Regenerated.
2023-05-23 13:50:40 +08:00
Kuan-Lin Chen
f1cd8b94e7 RISC-V: Support subtraction of .uleb128.
96d6e190e9

There are some known limitations for now,

* Do not shrink the length of the uleb128 value, even if the value is reduced
after relaxations.  Also reports error if the length grows up.

* The R_RISCV_SET_ULEB128 needs to be paired with and be placed before the
R_RISCV_SUB_ULEB128.

bfd/
	* bfd-in2.h: Regenerated.
	* elfnn-riscv.c (perform_relocation): Perform R_RISCV_SUB_ULEB128 and
	R_RISCV_SET_ULEB128 relocations.  Do not shrink the length of the
	uleb128 value, and report error if the length grows up.  Called the
	generic functions, _bfd_read_unsigned_leb128 and _bfd_write_unsigned_leb128,
	to encode the uleb128 into the section contents.
	(riscv_elf_relocate_section): Make sure that the R_RISCV_SET_ULEB128
	must be paired with and be placed before the R_RISCV_SUB_ULEB128.
	* elfxx-riscv.c (howto_table): Added R_RISCV_SUB_ULEB128 and
	R_RISCV_SET_ULEB128.
	(riscv_reloc_map): Likewise.
	(riscv_elf_ignore_reloc): New function.
	* libbfd.h: Regenerated.
	* reloc.c (BFD_RELOC_RISCV_SET_ULEB128, BFD_RELOC_RISCV_SUB_ULEB128):
	New relocations to support .uleb128 subtraction.
gas/
	* config/tc-riscv.c (md_apply_fix): Added BFD_RELOC_RISCV_SET_ULEB128
	and BFD_RELOC_RISCV_SUB_ULEB128.
	(s_riscv_leb128): Updated to allow uleb128 subtraction.
	(riscv_insert_uleb128_fixes): New function, scan uleb128 subtraction
	expressions and insert fixups for them.
	(riscv_md_finish): Called riscv_insert_uleb128_fixes for all sections.
include/
	* elf/riscv.h ((R_RISCV_SET_ULEB128, (R_RISCV_SUB_ULEB128): Defined.
ld/
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
	* testsuite/ld-riscv-elf/uleb128*: New testcase for uleb128 subtraction.
binutils/
	* testsuite/binutils-all/nm.exp: Updated since RISCV supports .uleb128.
2023-05-19 16:24:10 +08:00
Jan Beulich
1e66f4c55f x86: permit all relational operators in insn operands
Oddly enough == and != were not permitted, because of '=' not having
been listed in operand_special_chars[].
2023-05-19 09:19:10 +02:00
Jan Beulich
5cc007751c x86: further adjust extend-to-32bit-address conditions
While a442cac508 ("ix86: wrap constants") helped address a number of
inconsistencies between BFD64 and !BFD64 builds, it has also resulted in
certain bogus uses of constants to no longer be warned about. Leverage
the md_optimize_expr() hook to adjust when to actually truncate
expressions to 32 bits - any involvement of binary expressions (which
would be evaluated in 32 bits only when !BFD64) signals the need for
doing so. Plain constants (or ones merely subject to unary operators)
should remain un-truncated - they would be handled as bignums when
!BFD64, and hence are okay to permit.

To compensate
- slightly extend optimize_imm() (to be honest I never understood why
  the code being added - or something similar - wasn't there in the
  first place),
- adjust expectations of the disp-imm-32 testcase (there are now
  warnings, as there should be for any code which won't build [warning-
  free] when !BFD64, and Disp8/Imm8 are no longer used in the warned
  about cases).
2023-05-19 09:18:09 +02:00
Jan Beulich
6f5ee7a3e9 gas: invoke md_optimize_expr() also for unary expressions
Give backends a chance to see these, just as they can see binary ones.
Most of those which use this hook already cope with NULL being passed
for the left operand (typically because of checking the operator first).
Adjust the two which don't.

Take the opportunity and also document the hook.
2023-05-19 09:16:29 +02:00
Jan Beulich
df81d460b2 x86: tighten extend-to-32bit-address conditions
In a442cac508 ("ix86: wrap constants") I made the truncation condition
too relaxed: Any indication of a mode that's possible with BFD64 only
should avoid the truncation. Therefore, like in the other two cases of
calls to extend_to_32bit_address(), also check whether we're generating
a 64-bit object.
2023-05-19 09:14:40 +02:00
Alan Modra
4cb88cfae8 PR11601, Solaris assembler compatibility doesn't work
Well, it doesn't work on x86 or ppc, which both have # starting
comments anywhere on a line.  I think it is therefore only useful on
sparc.

	PR 11601
	* config/obj-elf.c (obj_elf_section_word): Only compile for sparc.
	(obj_elf_section): Only support solaris .section directive on
	sparc.
	* doc/as.texi (Section): Mention that solaris .section
	directive is only supported for sparc.
2023-05-18 09:33:14 +09:30
Alan Modra
249d1bad51 PR28955 mips gas segfault
Testing for NULL in pic_need_relax fixes the other call to this
function in md_estimate_size_before_relax.

	PR 28955
	* config/tc-mips.c (mips_frob_file): Move NULL sym test to..
	(pic_need_relax): ..here.
2023-05-13 20:47:31 +09:30
Jan Beulich
f847749a74 x86: slightly simplify i386_parse_name()
With the switch to parse_real_register() (commit 4faaa10f3f) "bad_reg"
cannot come back anymore. Drop the respective check.
2023-05-12 08:56:07 +02:00
Jan Beulich
d50c498a1b gas: equates of registers
There are two problems: symbol_equated_p() doesn't recognize equates of
registers, and S_CAN_BE_REDEFINED() goes by section rather than by
expression type. Both together undermine .eqv and .equiv clearly meaning
to guard the involved symbols against re-definition (both ways).

To compensate pseudo_set() now using O_symbol and S_CAN_BE_REDEFINED()
now checking for O_register,
- for targets creating register symbols through symbol_{new,create}() ->
  symbol_init() -> S_SET_VALUE() (alpha, arc, dlx, ia64, m68k, mips,
  mmix, tic4x, tic54x, plus anything using cgen or itbl-ops), have
  symbol_init() set their expressions to O_register,
- x86'es parse_register() also can't go by section anymore when
  trying to "look through" equates; probably symbol_equated_p() should
  have been used there from the beginning, if only that had worked for
  equates of registers,
- various targets need to "look through" equates when parsing insn
  operands (which also helps transitive forward equates); perhaps even
  more ought to, but many don't look to consider the possibility of
  register equates in the first place.

This was uncovered by code reported in PR gas/30274 (duplicating
PR gas/30272), except that there .eqv was used when really .equ was
meant. Therefore that bug report is addressed here only in so far as
gas wouldn't crash anymore; the code there still won't assemble
successfully, just that now the issues there are properly diagnosed.
2023-05-12 08:55:48 +02:00
Jan Beulich
654dfab066 RISC-V: tighten post-relocation-operator separator expectation
As per the spec merely a blank isn't okay as a separator, the operand
to the relocation function ought to be parenthesized. Enforcing this
then also eliminates an inconsistency in that

	lui	t0, %hi sym
	lui	t0, %hi 0x1000

were accepted, but

	lui	t0, %hi +sym
	lui	t0, %hi -0x1000

were not.
2023-05-04 10:24:36 +02:00
Ilya Leoshkevich
c981907770 gas: fix building tc-bpf.c on s390x
char is unsigned on s390x, so there are a lot of warnings like:

    gas/config/tc-bpf.c: In function 'get_token':
    gas/config/tc-bpf.c:900:14: error: comparison is always false due to limited range of data type [-Werror=type-limits]
      900 |       if (ch == EOF || len > MAX_TOKEN_SZ)
          |              ^~

Change its type to int, like in the other similar code.

There is also:

    gas/config/tc-bpf.c:735:30: error: 'bpf_endianness' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      735 |    dst, be ? size[endianness - BPF_BE16] : size[endianness - BPF_LE16]);
          |                   ~~~~~~~~~~~^~~~~~~~~~

-Wmaybe-uninitialized doesn't seem to understand the FSM; just
initialize bpf_endianness to silence it.  Add an assertion to
build_bpf_endianness() in order to catch potential bugs.
2023-05-04 08:37:50 +02:00
Alan Modra
a07223191b Remove unused args from bfd_make_debug_symbol
The ptr and size args are unused.  Make the function look the same as
bfd_make_empty_symbol.
2023-05-03 15:53:29 +09:30
Jan Beulich
6b50f5f4cb x86/Intel: reduce ELF/PE conditional scope in x86_cons()
All the Intel syntax related state adjustments apply independent of
target or object format.
2023-04-28 08:20:15 +02:00
Guillermo E. Martinez
ff5a51b377 gas: support for the BPF pseudo-c assembly syntax
This patch adds support to the GNU assembler for an alternative
assembly syntax used in BPF.  This syntax is C-like and very
unconventional for an assembly language, but it is generated by
clang/llvm and is also used in inline asm templates in kernel code, so
we ought to support it.

After this patch, the assembler is able to parse instructions in both
supported syntax: the normal assembly-like syntax and the pseudo-C
syntax.  Instruction formats can be mixed in the source program: the
assembler recognizes the right syntax to use.

gas/ChangeLog:

2023-04-20  Guillermo E. Martinez  <guillermo.e.martinez@oracle.com>

	PR gas/29728
	* config/tc-bpf.h (TC_EQUAL_IN_INSN): Define.
	* config/tc-bpf.c (LEX_IS_SYMBOL_COMPONENT): Define.
	(LEX_IS_WHITESPACE): Likewise.
	(LEX_IS_NEWLINE): Likewise.
	(LEX_IS_ARITHM_OP): Likewise.
	(LEX_IS_STAR): Likewise.
	(LEX_IS_CLSE_BR): Likewise.
	(LEX_IS_OPEN_BR): Likewise.
	(LEX_IS_EQUAL): Likewise.
	(LEX_IS_EXCLA): Likewise.
	(ST_EOI): Likewise.
	(MAX_TOKEN_SZ): Likewise.
	(init_pseudoc_lex): New function.
	(md_begin): Call init_pseudoc_lex.
	(valid_expr): New function.
	(build_bpf_non_generic_load): Likewise.
	(build_bpf_atomic_insn): Likewise.
	(build_bpf_jmp_insn): Likewise.
	(build_bpf_arithm_insn): Likewise.
	(build_bpf_endianness): Likewise.
	(build_bpf_load_store_insn): Likewise.
	(look_for_reserved_word): Likewise.
	(is_register): Likewise.
	(is_cast): Likewise.
	(get_token): Likewise.
	(bpf_pseudoc_to_normal_syntax): Likewise.
	(md_assemble): Try pseudo-C syntax if an instruction cannot be
	parsed.
2023-04-26 19:27:41 +02:00
Jan Beulich
7a29ee2903 RISC-V: adjust logic to avoid register name symbols
Special casing GPR names in my_getSmallExpression() leads to a number of
inconsistencies. Generalize this by utilizing the md_parse_name() hook,
limited to when instruction operands are being parsed (really: probed).
Then both the GPR lookup there and the yet more ad hoc workaround for
PR/gas 29940 can be removed (including its extension needed for making
the compressed form JAL work again).
2023-04-25 11:19:18 +02:00
Jan Beulich
b33e94cfa4 RISC-V: don't recognize bogus relocations
With my_getSmallExpression() consistently and silently failing on
relocation operators not fitting an insn, it is no longer necessary to
hand it percent_op_itype[] "just in case" (i.e. to avoid errors when a
subsequent parsing attempt for another operand combination might
succeed). This also eliminates the latent problem of percent_op_itype[]
and percent_op_stype[] growing a non-identical set of recognized
relocation operators.
2023-04-25 11:17:19 +02:00
Jan Beulich
a5e756e63e RISC-V: avoid redundant and misleading/wrong error messages
The use of a wrong (for the insn) relocation operator (or a future one
which simply isn't recognized by older gas yet) doesn't render the (rest
of the) expression "bad". Furthermore alongside the error from
expression() in most cases the parser would emit another error then
anyway. Suppress the call to my_getExpression() in such a case,
arranging for a guaranteed subsequent error message by marking the
expression "illegal".
2023-04-25 11:16:44 +02:00
Jan Beulich
408ab0161d RISC-V: drop "percent_op" parameter from my_getOpcodeExpression()
Both callers check for no relocations, so there's no point parsing for
some. Have the function pass percent_op_null into
my_getSmallExpression(). Note that there's no point passing
percent_op_itype: Elsewhere, especially when processing compressed alias
insns ahead of non-alias ones, this has the effect of avoiding "bad
expression" errors when another parsing pass may follow (and succeed).
Here, however, all alternative forms of an insn type will again start
with the same O4 or O2, so avoiding errors earlier on doesn't really
help. Plus constructs with a relocation specifier (as percent_op_itype
would permit) can't be specified anyway, as the scrubber eats the
whitespace between .insn's type and the O4 or O2 expression when that
starts with % or ( - i.e. these will be seen as e.g. "i%lo(x)", and
riscv_ip() looks only for whitespace when finding the end of a mnemonic.
2023-04-25 11:16:07 +02:00
Jan Beulich
85bd4bfb7f RISC-V: minor effort reduction in relocation specifier parsing
The sole caller of parse_relocation() has already checked for the %
prefix, so there's no need to check for it again in the strncasecmp()
and there's also no reason to make the involved string literals longer
than necessary.
2023-04-25 11:15:25 +02:00
YunQiang Su
af98929731 MIPS: fix loongson3 llsc workaround
-mfix-looongson3-llsc may add sync instructions not needed on some
asm code with lots of debug info.

	PR: 30153
	* gas/config/tc-mips.c(fix_loongson3_llsc): clear logistic.
2023-04-23 14:50:18 +08:00
Jan Beulich
4f0813127b x86: parse_register() must not alter the parsed string
This reverts the code change done by 100f993c53 ("x86: Check
unbalanced braces in memory reference"), which wrongly identified
e87fb6a6d0 ("x86/gas: support quoted address scale factor in AT&T
syntax") as the root cause of PR gas/30248. (The testcase is left in
place, no matter that it's at best marginally useful in that shape.)

The problem instead is that parse_register() alters the string handed to
it, thus breaking valid assumptions in subsequent parsing code. Since
the function's behavior is a result of get_symbol_name()'s, make a copy
of the incoming string before invoking that function.

Like for parse_real_register() follow the model of strtol() et al: input
string is const-qualified to signal that the string isn't altered, but
the returned "end" pointer is not const-qualified, requiring const to be
cast away (which generally is a bad idea, but the alternative would
again be more convoluted code).
2023-04-19 11:43:26 +02:00
Jan Beulich
74e05e01e2 x86: parse_real_register() does not alter the parsed string
Follow the model of strtol() et al - input string is const-qualified to
signal that the string isn't altered, but the returned "end" pointer is
not const-qualified, requiring const to be cast away (which generally is
a bad idea, but the alternative would be more convoluted code).
2023-04-19 11:42:51 +02:00
mengqinggang
a02676b77d Symbols with GOT relocatios do not fix adjustbale
gas
    * config/tc-loongarch.c (loongarch_fix_adjustable): Symbols with GOT relocatios do not fix adjustbale.
    * testsuite/gas/loongarch/macro_op_large_abs.d: Regenerated.
    * testsuite/gas/loongarch/macro_op_large_pc.d: Regenerated.
  ld
     * testsuite/ld-loongarch-elf/macro_op.d: Regenerated. -
2023-04-18 11:49:21 +01:00
Haochen Jiang
d100d8c1f3 Support Intel AMX-COMPLEX
gas/ChangeLog:

	* NEWS: Support Intel AMX-COMPLEX.
	* config/tc-i386.c: Add amx_complex.
	* doc/c-i386.texi: Document .amx_complex.
	* testsuite/gas/i386/i386.exp: Run AMX-COMPLEX tests.
	* testsuite/gas/i386/amx-complex-inval.l: New test.
	* testsuite/gas/i386/amx-complex-inval.s: Ditto.
	* testsuite/gas/i386/x86-64-amx-complex-bad.d: Ditto.
	* testsuite/gas/i386/x86-64-amx-complex-bad.s: Ditto.
	* testsuite/gas/i386/x86-64-amx-complex-intel.d: Ditto.
	* testsuite/gas/i386/x86-64-amx-complex.d: Ditto.
	* testsuite/gas/i386/x86-64-amx-complex.s: Ditto.

opcodes/ChangeLog:

	* i386-dis.c (MOD_VEX_0F386C_X86_64_W_0): New.
	(PREFIX_VEX_0F386C_X86_64_W_0_M_1_L_0): Ditto.
	(X86_64_VEX_0F386C): Ditto.
	(VEX_LEN_0F386C_X86_64_W_0_M_1): Ditto.
	(VEX_W_0F386C_X86_64): Ditto.
	(mod_table): Add MOD_VEX_0F386C_X86_64_W_0.
	(prefix_table): Add PREFIX_VEX_0F386C_X86_64_W_0_M_1_L_0.
	(x86_64_table): Add X86_64_VEX_0F386C.
	(vex_len_table): Add VEX_LEN_0F386C_X86_64_W_0_M_1.
	(vex_w_table): Add VEX_W_0F386C_X86_64.
	* i386-gen.c (cpu_flag_init): Add CPU_AMX_COMPLEX_FLAGS and
	CPU_ANY_AMX_COMPLEX_FLAGS.
	* i386-init.h: Regenerated.
	* i386-mnem.h: Ditto.
	* i386-opc.h (CpuAMX_COMPLEX): New.
	(i386_cpu_flags): Add cpuamx_complex.
	* i386-opc.tbl: Add AMX-COMPLEX instructions.
	* i386-tbl.h: Regenerated.
2023-04-07 05:47:01 +00:00
Alan Modra
f679aaa4c8 ubsan: aarch64 parse_vector_reg_list
tc-aarch64.c:1473:27: runtime error: left shift of 7 by 30 places
cannot be represented in type 'int'.

	* config/tc-aarch64.c (parse_vector_reg_list): Avoid UB left
	shift.
2023-04-03 07:43:14 +09:30
Tsukasa OI
54bca63b5c RISC-V: Allocate "various" operand type
This commit intends to move operands that require very special handling or
operand types that are so minor (e.g. only useful on a few instructions)
under "W".  I also intend this "W" to be "temporary" operand storage until
we can find good two character (or less) operand type.

In this commit, prefetch offset operand "f" for 'Zicbop' extension is moved
to "Wif" because of its special handling (and allocating single character
"f" for this operand type seemed too much).

Current expected allocation guideline is as follows:

1.  'W'
2.  The most closely related single-letter extension in lowercase
    (strongly recommended but not mandatory)
3.  Identify operand type

The author currently plans to allocate following three-character operand
types (for operands including instructions from unratified extensions).

1.  "Wif" ('Zicbop': fetch offset)
2.  "Wfv" (unratified 'Zfa': value operand from FLI.[HSDQ] instructions)
3.  "Wfm" / "WfM"
    'Zfh', 'F', 'D', 'Q': rounding modes "m" with special handling
                          solely for widening conversion instructions.

gas/ChangeLog:

	* config/tc-riscv.c (validate_riscv_insn, riscv_ip): Move from
	"f" to "Wif".

opcodes/ChangeLog:

	* riscv-dis.c (print_insn_args): Move from "f" to "Wif".
	* riscv-opc.c (riscv_opcodes): Reflect new operand type.
2023-03-31 10:25:44 +02:00
Jan Beulich
c032bc4fe7 x86: handle immediate operands for .insn
Since we have no insn suffix and it's also not realistic to infer
immediate size from the size of other (typically register) operands
(like optimize_imm() does), and since we also don't have a template
telling us permitted size(s), a new syntax construct is introduced to
allow size (and signedness) specification. In the absence of such, the
size is inferred from significant bits (which obviously may yield
inconsistent results at least for effectively negative values, depending
on whether BFD64 is enabled), and only if supplied expressions can be
evaluated at parsing time. Being explicit is generally recommended to
users.

Size specification is permitted at bit granularity, but of course the
eventually emitted immediate values will be padded up to 8-, 16-, 32-,
or 64-bit fields.
2023-03-31 08:22:28 +02:00
Jan Beulich
e3bf0aade2 x86: allow for multiple immediates in output_disp()
.insn isn't going to have a constraint of only a single immediate when,
in particular, RIP-relative addressing is used.
2023-03-31 08:21:56 +02:00
Jan Beulich
f7377a91b5 x86: handle EVEX Disp8 for .insn
In particular the scaling factor cannot always be determined from pre-
existing operand attributes. Introduce a new {:d<N>} vector operand
syntax extension, restricted to .insn only, to allow specifying this in
(at least) otherwise ambiguous cases.
2023-03-31 08:21:30 +02:00
Jan Beulich
0ff3b7d0c7 x86: process instruction operands for .insn
Deal with register and memory operands; immediate operands will follow
later, as will the handling of EVEX embedded broadcast and EVEX Disp8
scaling.

Note that because we can't really know how to encode their use, %cr8 and
up cannot be used with .insn outside of 64-bit mode. Users would need to
specify an explicit LOCK prefix in combination with %cr0 etc.
2023-03-31 08:21:05 +02:00
Jan Beulich
393fbe8d81 x86: parse special opcode modifiers for .insn
So called "short form" encoding is specified by a trailing "+r", whereas
a possible extension opcode is specified by the usual "/<digit>". Take
these off the expression before handing it to get_absolute_expression().

Note that on targets where / starts a comment, --divide needs passing to
gas in order to make use of the extension opcode functionality.
2023-03-31 08:20:22 +02:00
Jan Beulich
d0c2e3ec82 x86: parse VEX and alike specifiers for .insn
All encoding spaces can be used this way; there's a certain risk that
the bits presently reserved could be used for other purposes down the
road, but people using .insn are expected to know what they're doing
anyway. Plus this way there's at least _some_ way to have those bits
set.

For now this will only allow operand-less insns to be encoded this way.
2023-03-31 08:19:58 +02:00
Jan Beulich
edd6763868 x86: introduce .insn directive
For starters this deals with only very basic constructs.
2023-03-31 08:18:58 +02:00
Richard Sandiford
8ff429203d aarch64: Add the RPRFM instruction
This patch adds the RPRFM (range prefetch) instruction.
It was introduced as part of SME2, but it belongs to the
prefetch hint space and so doesn't require any specific
ISA flags.

The aarch64_rprfmop_array initialiser (deliberately) only
fills in the leading non-null elements.
2023-03-30 11:09:18 +01:00