aboutsummaryrefslogtreecommitdiff
path: root/gas
AgeCommit message (Collapse)AuthorFilesLines
2023-03-28Avoid undefined behaviour in m68hc11 md_beginAlan Modra1-17/+15
Given p = A where p is a pointer to some type and A is an array of that type, then the expression p - 1 + 1 evokes undefined behaviour according to the C standard. gcc-13 -fsanitize=address,undefined complains about this, but not where the undefined behaviour actually occurs at tc-m68hc11.c:646. Instead you get an error: "tc-m68hc11.c:708:20: runtime error: store to address 0x62600000016c with insufficient space for an object of type 'int'". Which is a lie. There most definitely is space there. Oh well, diagnostics are sometimes hard to get right. The UB is easy to avoid. PR 30279 * config/tc-m68hc11.c (md_begin): Avoid undefined pointer decrement. Remove unnecessary cast.
2023-03-27Tidy tc-ppc.c XCOFF auxent accessAlan Modra1-45/+48
It's better not to drill down into u.auxent but instead use a pointer to the combined_entry_type. That way the fix_scnlen field is available, and no one looking at the codes needs to wonder whether coffsymbol (symbol_get_bfdsym (sym))->native[i + 1] is the same auxent. * config/tc-ppc.c (ppc_frob_symbol): Tidy XCOFF auxent access. (ppc_adjust_symtab): Likewise.
2023-03-27Use stdint types in coff internal_auxentAlan Modra2-17/+17
long is a poor choice of type to store 32-bit values read from objects files by H_GET_32. H_GET_32 doesn't sign extend so tests like that in gdb/coffread.c for "negative" values won't work if long is larger than 32 bits. If long is 32-bit then code needs to be careful to not accidentally index negative array elements. (I'd rather see a segfault on an unmapped 4G array index than silently reading bogus data.) long is also a poor choice for x_sect.s_scnlen, which might have 64-bit values. It's better to use unsigned exact width types to avoid surprises. I decided to change the field names too, which makes most of this patch simply renaming. Besides that there are a few places where casts are no longer needed, and where printf format strings or tests need adjusting. include/ * coff/internal.h (union internal_auxent): Use unsigned stdint types. Rename l fields to u32 and u64 as appropriate. bfd/ * coff-bfd.c, * coff-rs6000.c, * coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c, * coffswap.h, * peXXigen.c, * xcofflink.c: Adjust to suit internal_auxent changes. binutils/ * rdcoff.c: Adjust to suit internal_auxent changes. gas/ * config/obj-coff.h, * config/tc-ppc.c: Adjust to suit internal_auxent changes. gdb/ * coffread.c, * xcoffread.c: Adjust to suit internal_auxent changes. ld/ * pe-dll.c: Adjust to suit internal_auxent changes.
2023-03-22gas: expand_irp memory leaksAlan Modra1-2/+10
* macro.c (expand_irp): Free memory on error return paths.
2023-03-21x86: Check unbalanced braces in memory referenceH.J. Lu5-1/+15
Check unbalanced braces in memory reference to avoid assembler crash caused by commit e87fb6a6d0cdfc0e9c471b7825c20c238c2cf506 Author: Jan Beulich <jbeulich@suse.com> Date: Wed Oct 5 09:16:24 2022 +0200 x86/gas: support quoted address scale factor in AT&T syntax PR gas/30248 * config/tc-i386.c (i386_att_operand): Check unbalanced braces in memory reference. * testsuite/gas/i386/i386.exp: Run pr30248. * testsuite/gas/i386/pr30248.d: New file. * testsuite/gas/i386/pr30248.err: Likewise. * testsuite/gas/i386/pr30248.s: Likewise.
2023-03-20x86: drop identifier_chars[]Jan Beulich1-22/+4
It tries to resemble what's underlying is_part_of_name(), but doesn't quite achieve that: '$' for example is unconditionally marked as part of symbol names, but was included as identifier char for Intel syntax only. Note that i386_att_operand() checks for the immediate prefix first, so the wider coverage by starts_memory_operand() is has no real effect there, but it does matter for something like mov %fs:$dollar, %eax which previously wasn't accepted (but which clearly is a memory reference - there's no point in forcing people to parenthesize the symbol name). Similarly including '%' as an identfier for Intel syntax had no real significance to the rest of the assembler. If '%' was to be valid in (unquoted) symbol names, LEX_PCT would need to be defined. Note further that this also addresses the latent issue of a sub-target defining LEX_AT or LEX_QM to zero: That would make '@' and/or '?' no valid part of symbol names, but would have included them in what is_identifier_char() considers a valid part of a name. (There's a minor related issue which is actually being eliminated: te-interix.h allows '@' only in the middle of symbol names, yet starts_memory_operand() specifically looks at the first character of [possibly] a symbol name.) In parse_real_register() there's no point also checking is_name_ender() as at this point no character is marked solely LEX_END_NAME by any sub- target. Checking is_name_beginner() is also pointless as the hash lookup will fail anyway for a zero-length name. While touching the check in parse_real_register() also drop the "allow_naked_reg" part of the condition: This has only led to inconsistent error messages.
2023-03-20x86/AT&T: restrict recognition of the "absolute branch" prefix characterJan Beulich1-2/+4
While in principle merely rejecting this for .insn would be sufficient for the purposes there, be more generic and reject it for anything that isn't going to be a branch: All elements of same-mnemonic template groups either are branches, or are not, and the few cases possibly requiring a 2nd parsing pass aren't affected either. This then also improves diagnostics for misuses like inc *%eax incl %fs:*(%eax) add *$1, %eax
2023-03-20x86: VexVVVV is now merely a booleanJan Beulich1-1/+1
With the SDM long having dropped the NDS/NDD/DDS concept of identifying encoding variants, we can finally do away with this concept as well. Of the few consumers of the attribute, only an assertion was still checking for a particular value, which we don't really need to retain. When touching lines anyway, modernize other aspects as well. This often improves similarity to adjacent lines.
2023-03-20x86: re-work build_modrm_byte()'s register assignmentJan Beulich1-287/+112
The function has accumulated a number of special cases for no real reason. Some were necessary because insn attributes (SwapSources in particular) weren't suitably utilized instead. Note that the addition of SwapSources actually increases consistency among the templates: Like others which already have the attribute, these are all insns where the VEX.VVVV-encoded register comes first (or last when looking at the SDM). Note that the vexvvvv attribute now has merely boolean meaning anymore, in line with the SDM long having dropped the NDS/NDD/DDS concept of identifying encoding variants. The fallout will be taken care of subsequently, though, to not further clutter the change here. As to the TILEZERO special case: If more instructions like this appeared, a new attribute would likely be the way to go. But as long as it's only a single insn, going from the mnemonic is cheaper.
2023-03-20Changed ld and gas BPF testsCupertino Miranda1-1/+1
Recent BPF patch removed and renamed the list of relocations based on the limitations of BPF instruction set. This patch is a correction to the tests.
2023-03-17gas: apply md_register_arithmetic also to unary '+'Jan Beulich2-11/+16
Even a unary '+' has to be considered arithmetic; at least on x86 in Intel Syntax mode otherwise bogus insn operands may be accepted. Convert this specific case to binary + (i.e. 0 + <register>). (An implication is that md_operator(,1,) would need to deal with arch- specific equivalents of unary '+' is a similar way, if such an arch- specific variant would be specified in the first place.) To avoid duplicating what make_expr_symbol() does to construct a constant-zero expression, simply make its previously local variable a file-scope static one. This way there's also no need to invoke clean_up_expression().
2023-03-17gas: expose flag_macro_alternate globallyJan Beulich5-33/+20
Yet again with the removal of gasp about 20 years ago this extra level of indirection isn't necessary anymore either. Drop macro.c's local variable and make as.c's global. While doing the conversion, switch the variable to "bool".
2023-03-17gas: use flag_mri directly in macro processingJan Beulich4-39/+23
Again with the removal of gasp about 20 years ago the extra level of indirection isn't necessary anymore. Drop macro.c's local variable and use the global flag directly.
2023-03-17gas: isolate macro_strip_at to macro.cJan Beulich3-9/+4
This removes a leftover from i960 support; with that nothing is left which would set macro_strip_at to non-zero, so the variable is converted to a #define (retaining the logic in case a new user would appear) and macro_init()'s respective parameter is dropped.
2023-03-17gas: drop function pointer parameter from macro_init()Jan Beulich3-40/+16
With the removal of gasp (about 20 years ago) the need for this kind- of-hook has disappeared. Go a step beyond merely moving the to be called function: Inline its contents right at the sole call site.
2023-03-16configure: add new target aarch64-*-nto*Clément Chigot1-0/+1
This target has its own ld emulation based on aarch64elf.em.
2023-03-16BPF relocations review / refactoringCupertino Miranda1-7/+0
- Removed not needed relocations. - Renamed relocations to match llvm and linux kernel. Relocation changes: R_BPF_INSN_64 => R_BPF_64_64 R_BPF_INSN_DISP32 => R_BPF_64_32 R_BPF_DATA_32 => R_BPF_64_ABS32 R_BPF_DATA_64 => R_BPF_64_ABS64 ChangeLog: * bfd/bpf-reloc.def: Created file with BPF_HOWTO macro entries. * bfd/reloc.c: Removed non needed relocations. * bfd/bfd-in2.h: regenerated. * bfd/libbfd.h: regenerated. * bfd/elf64-bpf.c: Changed relocations. * include/elf/bpf.h: Adapted relocation values/names. * gas/config/tc-bpf.c: Changed relocation mapping.
2023-03-14Fix assembler documentation regarding data directives.Nick Clifton2-1/+31
PR 30206 * doc/as.texi (Pseudo Ops): Document that data directives such as .byte and .int are not intended for encoding instructions.
2023-03-14gas/read.c: init more staticsAlan Modra1-62/+85
* read.c (current_name, current_label, dwarf_file, dwarf_line): Move to file scope. (pobegin): Tidy pop_override_ok. (read_a_source_file): Make last_eol an auto var. (s_reloc): Constify bfd_relocs. (read_begin): Init more variables.
2023-03-14gas .include and .incbinAlan Modra5-105/+66
This fixes a bug in .include and .incbin where given an absolute path the -I dirs would be searched for the path. * read.c (include_dir_count, include_dir_maxlen): Make them size_t. (search_and_open): New function. (s_incbin, s_include): Use search_and_open. (init_include_dir): New function. (add_include_dir): Don't set initial "." dir here. * read.h (include_dir_count, include_dir_maxlen): Update. (init_include_dir, search_and_open): Declare. * as.c (gas_early_init): Call init_include_dir. * config/tc-rx.c (rx_include): Avoid warning by using size_t. * config/tc-tic54x.c (tic54x_set_default_include): Simplify and use notes for include path. (tic54x_mlib): Use search_and_open.
2023-03-14gas/dwarf2dbg.c init more staticsAlan Modra1-11/+17
* dwarf2dbg.c (dw2_line, dw2_filename): Move to file scope and.. (dwarf2_gen_line_info): ..renamed from here. (label_num, last_used, last_used_dir_len): Move to file scope. (dwarf2_init): Init moved statics, except last_used_dir_len.
2023-03-14gas/ecoff.c: don't use zero struct copies to initAlan Modra1-18/+9
It might have made sense once upon a time, but doesn't nowadays when compilers expand memset inline. * ecoff.c (add_aux_sym_tir, allocate_scope, allocate_vlinks), (allocate_shash, allocate_thash, allocate_tag, allocate_forward), (allocate_thead, allocate_lineno_list): Use memset rather than copying zero struct.
2023-03-14gas/compress-debug.c init all of strmAlan Modra1-4/+2
* compress-debug.c (compress_init): Clear all of strm.
2023-03-10Arm64/gas: drop redundant feature prereqsJan Beulich1-11/+4
Logic exists to deal with prereqs or prereqs, and in many cases transitive prereqs are already not spelled out explicitly. Drop further ones: - FP is already a prereq to F16, - SIMD and F16 are already prereqs to COMPNUM, and - SVE2 and BFLOAT16 are already prereqs to SME.
2023-03-10Arm64/gas: add missing prereq featuresJan Beulich1-6/+6
A number of newer features are really SIMD or FP extensions, but don't have this properly specified.
2023-03-10x86: decouple broadcast type and bytes fieldsJan Beulich1-5/+6
Keep both representing exclusively what was parsed from input, to avoid the need for (potentially bogus) calculations when processing .insn.
2023-03-10x86-64: adjust REX-prefix part of SSE2AVX testJan Beulich2-46/+46
Before altering how build_modrm_byte() works, arrange for this part of the testcase to actually use distinguishable source and destination register numbers, such that incorrect propagation of, in particular, the high bit encodings (from REX to VEX) can be noticed (in turn specifically assertions [not] triggering in the respective code).
2023-03-10x86: move more disp processing out of md_assemble()Jan Beulich1-43/+46
Put it in optimize_disp() such that it can then be re-used by .insn handling. The movement makes it necessary (or at least very desirable, to avoid introducing a fragile cast) to convert to local variable to "unsigned", which in turn requires an adjustment to the pre-existing loop header. Having the caller pass in the specific template under consideration has another benefit then: We can replace the two uses of current_templates in the function as well, thus no longer looking at some merely "related" template. (This may allow further tightening, but if so that's to be the subject of another change.)
2023-03-10x86: use set_rex_vrex() also for short-form handlingJan Beulich1-21/+20
This is benign for all existing insns, but is going to be needed for handling of .insn operands. The earlier use requires moving up the function, to avoid the need for a forward declaration.
2023-03-10eh static dataAlan Modra3-21/+31
Fix another case of oss-fuzz tripping over gas static state, ie. starting over testing another input file with rubbish left uncleared in bss. size_end_sym pointed at garbage. * ehopt.c (get_cie_info): Delete forward declaration. (struct frame_data): Move to file scope. (frame): New static, packaged.. (check_eh_frame): ..eh_frame_data and debug_frame_data. (eh_begin): New function. * as.c (gas_init): Call eh_begin. * as.h (eh_begin): Declare.
2023-03-09gas: allow frag address wrapping in absolute sectionAlan Modra1-1/+2
This: .struct -1 x: .fill 1 y: results in an internal error in frag_new due to abs_section_offset wrapping from -1 to 0. Frags in the absolute section don't do much so I think we can allow the address wrap. * frags.c (frag_new): Allow address wrap in absolute section.
2023-03-03x86: use swap_2_operands() in build_vex_prefix()Jan Beulich1-17/+3
Open-coding part of what may eventually be needed is somewhat risky. Let's use the function we have, taking care of all pieces of data which may need swapping, no matter that - right now i.flags[] and i.reloc[] aren't relevant here (yet), - EVEX masking and embedded broadcast aren't applicable.
2023-03-03x86: drop redundant calculation of EVEX broadcast sizeJan Beulich1-3/+0
In commit a5748e0d8c50 ("x86/Intel: allow MASM representation of embedded broadcast") I replaced the calculation of i.broadcast.bytes in check_VecOperands() not paying attention to the immediately following call to get_broadcast_bytes() doing exactly that (again) first thing.
2023-03-03gas: default .debug section compression method adjustmentsJan Beulich1-2/+7
While commit b0c295e1b8d0 ("add --enable-default-compressed-debug- sections-algorithm configure option") adjusted flag_compress_debug's initializer, it didn't alter the default used when the command line option was specified with an (optional!) argument. This rendered help text inconsistent with actual behavior in certain configurations. As to help text - the default reported there clearly shouldn't be affected by a possible earlier --compress-debug-sections= option, so flag_compress_debug can't be used when emitting usage information.
2023-03-03x86: avoid .byte in testcases where possibleJan Beulich4-220/+152
In the course of using the upcoming .insn directive to eliminate various .byte uses in testcases I've come across these, which needlessly use more .byte than necessary even without the availability of .insn.
2023-03-02More bounds checking in macro_expandAlan Modra1-4/+4
* macro.c (macro_expand): Ensure input string buffer is not read past end.
2023-03-02Using .mri in assemblyAlan Modra1-7/+8
Changing mri mode between macro definition and use isn't good. This .macro x .endm .mri 1 x leads to a segfault. Fixed with the following patch, but I suppose what should really happen is that macros be marked as being mri mode when defined, and that determine whether the magic NARG parameter be supplied at expansion. Nobody has complained about this in 30 years so I'm not inclined to change gas behaviour to that extent. * macro.c (macro_expand): Don't segfault in mri mode if NARG formal isn't found.
2023-03-01Catch overflow in gas s_spaceAlan Modra1-11/+21
Also fix an error introduced in 1998 in reporting a zero count for negative counts. * read.c (s_space): Use unsigned multiply, and catch overflow. Correct order of tests for invalid repeat counts. Ensure ignored directives don't affect mri_pending_align.
2023-03-01gas s_fill caused internal error in frag_newAlan Modra1-10/+20
Fix an internal error after "non-constant fill count for absolute section". * read.c (s_fill): Don't create frags after errors.
2023-03-01Memory leak in gas do_repeatAlan Modra1-0/+1
* read.c (do_repeat): Free sb on error path.
2023-02-28[Aarch64] Add Binutils support for MECRichard Ball6-0/+61
This change supports MEC which is part of RME (Realm Management Extension).
2023-02-27gas/testsuite: adjust another test for case insensitive file systemsClément Chigot1-1/+1
As 1fafeaac8503eea2f61c3a35f0eef183b7e7cc65, "line.s" and "Line.s" are identical in case insensitive file systems. Thus, gas doesn't trigger an input file switch. gas/ChangeLog: * testsuite/gas/elf/dwarf-5-macro.s: Change Line.s to Line2.s.
2023-02-27Do not change the timestamp when updating the gas asconfig file.Benson Muite3-2/+9
PR 28909 * doc/local.mk (asconfig.texi): Use "cp -p" to preserve timestamps. * Makefile.in: Regenerate.
2023-02-24x86: allow to request ModR/M encodingJan Beulich5-9/+296
Several insns have a (typically shorter) non-ModR/M and a (typically longer) ModR/M encoding. In most cases the former is used by default. This isn't too dissimilar from register-only insns sometimes having two encoding forms. In those cases {load} or {store} can be used to control the encoding used. Extend this to ModR/M-less encodings which have a ModR/M counterpart (note that BSWAP hasn't). For insn reading and writing their (explicit) memory operand, both prefixes are honored; otherwise only the applicable one is. Note that for some forms of XCHG, {store} has already been performing this function, apparently as an unnoticed side effect of adding D to the template.
2023-02-24x86: MONITOR/MWAIT are not SSE3 insnsJan Beulich17-28/+140
These have their own CPUID bit and hence they should also have their own separate control.
2023-02-24x86-64: don't permit LAHF/SAHF with "generic64"Jan Beulich12-5/+111
The feature isn't universally available on 64-bit CPUs. Note that in i386-gen.c:isa_dependencies[] I'm only adding it to models where I'm certain the functionality exists. For Nocona and Core I'm uncertain in particular.
2023-02-24x86: have insns acting on segment selector values allow for consistent operandsJan Beulich7-1/+246
While MOV to/from segment register as well as selector storing insns already permit 32- and 64-bit GPR operands, selector loading insns and ARPL do not. Split templates accordingly.
2023-02-24x86: restrict insn templates accepting negative 8-bit immediatesJan Beulich5-52/+66
For shifts (but not ordinary rotates) and other cases where an immediate describes e.g. a bit count or position, allowing negative operands is at best confusing. An extreme example would be the two rotate-through-carry insns, where a negative value would _not_ mean rotating the corresponding number of bits in the other direction. To refuse such, give meaning to the combination of Imm8 and Imm8S in templates (so far these weren't used together anywhere). The issue was with smallest_imm_type() blindly setting .imm8 for signed numbers determined to fit in a byte. VPROT{B,W,D,Q} is a little special: The rotate count there is a signed quantity, so Imm8 is replaced by Imm8S. Adjust affected testcases accordingly as well. Another small adjustment to the testsuite is necessary: AAM and AAD were never sensible to use with 0xffffff90 operands. This should have been an error.
2023-02-22x86-64: LAR and LSL don't need REX.WJan Beulich2-24/+24
Just like we suppress emitting REX.W for e.g. MOV from/to segment register, there's also no need for it for LAR and LSL - these can only ever return 32-bit values and hence always zero-extend their results anyway. While there also drop the redundant Word from the first operand of the second template each - this is already implied by Reg16.
2023-02-22x86: optimize BT{,C,R,S} $imm,%regJan Beulich8-0/+115
In 64-bit mode BT can have REX.W or a data size prefix dropped in certain cases. Outside of 64-bit mode all 4 insns can have the data size prefix dropped in certain cases.