aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2025-03-10Further tidies to bed->p_align codeAlan Modra1-12/+11
align_pagesize was used for two things, reducing p->p_align from maxpagesize to the bed->p_align value (section alignment permitting), and increasing p->p_align above maxpagesize if section alignment required that. This patch untangles those two, making align_pagesize only do the former. p->p_align is set directly for the latter. I've made that change to p->p_align only when D_PAGED to keep things consistent with other early assignments to p->p_align. p->p_align is set later according to section alignment when not D_PAGED. I've also moved the place where align_pagesize adjusts p->p_align to be with other code setting p->p_align. That seemed better to me than leaving it until the last possible moment. Note that it isn't necessary to have this adjustment done inside a test for a PT_LOAD header, since we never set align_pagesize non-zero outside a PT_LOAD test. * elf.c (assign_file_positions_for_load_sections): Clear align_pagesize whenever we have a section alignment more than bed->p_align. Set p->p_align rather than align_pagesize when section alignment exceeds maxpagesize. Assign p->p_align from align_pagesize earlier.
2025-03-10Tidy code handling bed->p_align a little.Alan Modra1-19/+18
No functional changes here, just preparation for the next patch. * elf.c (assign_file_positions_for_load_sections): Replace p_align_p and p_align with align_pagesize. Revise comments on code handling bed->p_align.
2025-03-10ld: Cleanup sframe_decoder_init_func_bfdinfo use of reloc cookieJens Remus1-9/+8
The loop did set cookie->rel to the i-th relocation twice. At the beginning using the loop counter. At the end by incrementing. One approach is sufficient. Change cookie to pointer-to-const, replace cookie->rel by rel, initialize before the loop and increment at the end, and merge the two assertions (for cookie->rel) into one. While at it change sec to pointer-to-const. bfd/ * elf-sframe.c (sframe_decoder_init_func_bfdinfo): Cleanup use of relocation cookie. Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-03-10gas: Use SFrame header and FDE field sizes when generating .sframeJens Remus1-16/+13
The use of SFRAME_RELOC_SIZE in generation of SFrame stack trace information from CFI directives erroneously suggested that this could be used to configure a different relocation size. But in practice it is tied to the SFrame field sizes it is used for and therefore cannot be changed. Replace the uses of SFRAME_RELOC_SIZE by the size of the respective SFrame header and FDE fields when emitting SFrame information. While at it enhance some comments. gas/ * gen-sframe.c (SFRAME_RELOC_SIZE): Delete. (sizeof_member): Define. (output_sframe_funcdesc): Use size of SFrame FDE fields instead of SFRAME_RELOC_SIZE. (output_sframe_internal): Use size of SFrame header fields instead of SFRAME_RELOC_SIZE. Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-03-10Automatic date update in version.inGDB Administrator1-1/+1
2025-03-09RISC-V: PR32772, fixed segfault caused by the accidental removal of `h != NULL'Nelson Chu1-1/+1
bfd/ PR 32772 * elfnn-riscv.c (riscv_elf_relocate_section): Fixed segfault caused by the accidental removal of `h != NULL' when handling a call to an undefined weak function.
2025-03-09Fix segfault if target_fileio_read_alloc failsBrandon Belew1-5/+5
Check for target_fileio_read_alloc failure in linux_fill_prpsinfo before dereferencing buffer. This fixes a segfault in the 'gcore' command when attached to certain remote targets. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32441 Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-03-09Automatic date update in version.inGDB Administrator1-1/+1
2025-03-08bfd_elf_parse_attr_section_v1 buffer overflowAlan Modra1-7/+3
This function has a misleading parameter "contents", which usually means an entire section contents is passed. However in this case the actual sections contents plus one is passed, leading to miscalculating the end of the buffer. * elf-attrs.c (bfd_elf_parse_attr_section_v1): Delete hdr and contents param. Add p and p_end as params. (_bfd_elf_parse_attributes): Adjust to suit.
2025-03-08gprof: Compile tst-gmon.c with -O2 -fno-omit-frame-pointerH.J. Lu4-11/+13
Compile tst-gmon.c with -O2 -fno-omit-frame-pointer to ensure proper call graph generation. PR gprof/32768 * configure.ac: Compile tst-gmon.c with -fno-omit-frame-pointer. * configure: Regenerated. * testsuite/Makefile.am (GPROF_FLAGS): Add -O2 -fno-omit-frame-pointer. (AM_CFLAGS): Removed. (COMPILE): Append $(GPROF_FLAGS). (LINK): Likewise. * testsuite/Makefile.in: Regenerated. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-03-08[gdb/testsuite] Fix gdb.base/step-over-syscall.exp with -m32 for AMDTom de Vries1-1/+1
When running test-case gdb.base/step-over-syscall.exp with target board unix/-m32 on an AMD processor, I run into: ... (gdb) x/2i $pc^M => 0xf7fc9575 <__kernel_vsyscall+5>: syscall^M 0xf7fc9577 <__kernel_vsyscall+7>: int $0x80^M (gdb) PASS: $exp: fork: displaced=off: pc before/after syscall instruction stepi^M [Detaching after fork from child process 65650]^M 0xf7fc9579 in __kernel_vsyscall ()^M 1: x/i $pc^M => 0xf7fc9579 <__kernel_vsyscall+9>: pop %ebp^M (gdb) $exp: fork: displaced=off: stepi fork insn print /x $pc^M $2 = 0xf7fc9579^M (gdb) PASS: gdb.base/step-over-syscall.exp: fork: displaced=off: pc after stepi FAIL: $exp: fork: displaced=off: pc after stepi matches insn addr after syscall ... The problem is that the syscall returns at the "pop %ebp" insn, while the test-case expects it to return at the "int $0x80" insn. This is similar to the problem I fixed in commit 14852123287 ("[gdb/testsuite] Fix gdb.base/step-over-syscall.exp with -m32"), just that the syscall sequence used there used the "sysenter" insn instead of the "syscall" insn. Fix this by extending the fix for commit 14852123287 to also handle the "syscall" insn. Tested on x86_64-linux, both using an AMD and Intel processor. PR testsuite/32439 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32439
2025-03-07gdb/dwarf: call other cutu_reader constructor in ensure_lang and ↵Simon Marchi2-13/+14
dw2_get_file_names PR 32742 shows this failing: $ make check TESTS="gdb.ada/access_to_unbounded_array.exp" RUNTESTFLAGS="--target_board=fission" Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.ada/access_to_unbounded_array.exp ... FAIL: gdb.ada/access_to_unbounded_array.exp: scenario=all: gdb_breakpoint: set breakpoint at foo.adb:23 (GDB internal error) Or, interactively: $ ./gdb -q -nx --data-directory=data-directory testsuite/outputs/gdb.ada/access_to_unbounded_array/foo-all -ex 'b foo.adb:23' -batch /home/simark/src/binutils-gdb/gdb/dwarf2/read.c:19567: internal-error: set_lang: Assertion `old_value == language_unknown || old_value == language_minimal || old_value == lang' failed. The symptom is that for a given dwarf2_per_cu, the language gets set twice. First, set to `language_ada`, and then, to `language_minimal`. It's unexpected for the language of a CU to get changed like this. The CU at offset 0x0 in the main file looks like: 0x00000000: Compile Unit: length = 0x00000030, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000034) 0x0000000b: DW_TAG_compile_unit DW_AT_low_pc [DW_FORM_addr] (0x000000000000339a) DW_AT_high_pc [DW_FORM_data8] (0x0000000000000432) DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000) DW_AT_GNU_dwo_name [DW_FORM_strp] ("b~foo.dwo") DW_AT_comp_dir [DW_FORM_strp] ("/home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.ada/access_to_unbounded_array") DW_AT_GNU_pubnames [DW_FORM_flag_present] (true) DW_AT_GNU_addr_base [DW_FORM_sec_offset] (0x00000000) DW_AT_GNU_dwo_id [DW_FORM_data8] (0x277aee54e7bd47f7) This refers to the DWO file b~foo.dwo, whose top-level DIE is: .debug_info.dwo contents: 0x00000000: Compile Unit: length = 0x00000b63, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000b67) 0x0000000b: DW_TAG_compile_unit DW_AT_producer [DW_FORM_GNU_str_index] ("GNU Ada 14.2.1 20250207 -fgnat-encodings=minimal -gdwarf-4 -fdebug-types-section -fuse-ld=gold -gnatA -gnatWb -gnatiw -gdwarf-4 -gsplit-dwarf -ggnu-pubnames -gnatws -mtune=generic -march=x86-64") DW_AT_language [DW_FORM_data1] (DW_LANG_Ada95) DW_AT_name [DW_FORM_GNU_str_index] ("/home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.ada/access_to_unbounded_array/b~foo.adb") DW_AT_comp_dir [DW_FORM_GNU_str_index] ("/home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.ada/access_to_unbounded_array") DW_AT_GNU_dwo_id [DW_FORM_data8] (0xdbeffefab180a2cb) The thing to note is that the language attribute is only present in the DIE in the DWO file, not on the DIE in the main file. The first time the language gets set is here: #0 dwarf2_per_cu::set_lang (this=0x50f0000044b0, lang=language_ada, dw_lang=DW_LANG_Ada95) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:20788 #1 0x0000555561666af6 in cutu_reader::prepare_one_comp_unit (this=0x7ffff10bf2b0, cu=0x51700008e000, pretend_language=language_minimal) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:21029 #2 0x000055556159f740 in cutu_reader::cutu_reader (this=0x7ffff10bf2b0, this_cu=0x50f0000044b0, per_objfile=0x516000066080, abbrev_table=0x510000004640, existing_cu=0x0, skip_partial=false, pretend_language=language_minimal, cache=0x7ffff11b95e0) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:3371 #3 0x00005555615a547a in process_psymtab_comp_unit (this_cu=0x50f0000044b0, per_objfile=0x516000066080, storage=0x7ffff11b95e0) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:3799 #4 0x00005555615a9292 in cooked_index_worker_debug_info::process_cus (this=0x51700008dc80, task_number=0, first=std::unique_ptr<dwarf2_per_cu> = {...}, end=std::unique_ptr<dwarf2_per_cu> = {...}) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:4122 In this code path (particularly this specific cutu_reader constructir), the work is done to find and read the DWO file. So the language is properly identifier as language_ada, all good so far. The second time the language gets set is: #0 dwarf2_per_cu::set_lang (this=0x50f0000044b0, lang=language_minimal, dw_lang=0) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:20788 #1 0x0000555561666af6 in cutu_reader::prepare_one_comp_unit (this=0x7ffff0f42730, cu=0x517000091b80, pretend_language=language_minimal) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:21029 #2 0x00005555615a1822 in cutu_reader::cutu_reader (this=0x7ffff0f42730, this_cu=0x50f0000044b0, per_objfile=0x516000066080, pretend_language=language_minimal, parent_cu=0x0, dwo_file=0x0) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:3464 #3 0x000055556158c850 in dw2_get_file_names (this_cu=0x50f0000044b0, per_objfile=0x516000066080) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:1956 #4 0x000055556158f4f5 in dw_expand_symtabs_matching_file_matcher (per_objfile=0x516000066080, file_matcher=...) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:2157 #5 0x00005555616329e2 in cooked_index_functions::expand_symtabs_matching (this=0x50200002ab50, objfile=0x516000065780, file_matcher=..., lookup_name=0x0, symbol_matcher=..., expansion_notify=..., search_flags=..., domain=..., lang_matcher=...) at /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:15912 #6 0x0000555562ca8a14 in objfile::map_symtabs_matching_filename (this=0x516000065780, name=0x50200002ad90 "break pck.adb", real_path=0x0, callback=...) at /home/smarchi/src/binutils-gdb/gdb/symfile-debug.c:207 #7 0x0000555562d68775 in iterate_over_symtabs (pspace=0x513000005600, name=0x50200002ad90 "break pck.adb", callback=...) at /home/smarchi/src/binutils-gdb/gdb/symtab.c:727 Here, we use the other cutu_reader constructor, the one that does not look up the DWO file for the passed CU. If a DWO file exists for this CU, the caller is expected to pass it as a parameter. That cutu_reader constructor also ends up setting the language of the CU. But because it didn't read the DWO file, it didn't figure out the language is language_ada, so it tries to set the language to the default, language_minimal. A question is: why do we end up trying to set the CU's language is this context. This is completely unrelated to what we're trying to do, that is get the file names from the line table. Setting the language is a side-effect of just constructing a cutu_reader, which we need to look up attributes in dw2_get_file_names_reader. There are probably some cleanups to be done here, to avoid doing useless work like looking up and setting the CU's language when all we need is an object to help reading the DIEs and attributes. But that is future work. The same cutu_reader constructor is used in `dwarf2_per_cu::ensure_lang`. Since this is the version of cutu_reader that does not look up the DWO file, it will conclude that the language is language_minimal and set that as the CU's language. In other words, `dwarf2_per_cu::ensure_lang` will get the language wrong, pretty ironic. Fix this by using the other cutu_reader constructor in those two spots. Pass `per_objfile->get_cu (this_cu)`, as the `existing_cu` parameter. I think this is necessary, because that constructor has an assert to check that if `existing_cu` is nullptr, then there must not be an existing `dwarf2_cu` in the per_objfile. To avoid getting things wrong like this, I think that the second cutu_reader constructor should be reserved for the spots that do pass a non-nullptr dwo_file. The only spot at the moment in create_cus_hash_table, where we read multiple units from the same DWO file. In this context, I guess it makes sense for efficiency to get the dwo_file once and pass it down to cutu_reader. For that constructor, make the parameters non-optional, add "non-nullptr" asserts, and update the code to assume the passed values are not nullptr. What I don't know is if this change is problematic thread-wise, if the functions I have modified to use the other cutu_reader constructor can be called concurrently in worker threads. If so, I think it would be problematic. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32742 Change-Id: I980d16875b9a43ab90e251504714d0d41165c7c8 Approved-By: Tom Tromey <tom@tromey.com>
2025-03-07Avoid excessive CU expansion on failed matchesTom Tromey2-22/+66
PR symtab/31010 points out that something like "ptype INT" will expand all CUs in a typical program. The OP further points out that the original patch for PR symtab/30520: https://sourceware.org/pipermail/gdb-patches/2024-January/205924.html ... did solve the problem, but the patch changed after (my) review and reintroduced the bug. In cooked_index_functions::expand_symtabs_matching, the final component of a split name is compared with the entry's name using the usual method of calling get_symbol_name_matcher. This code iterates over languages and tries to split the original name according to each style. But, the Ada splitter uses the decoded name -- "int". This causes every C or C++ CU to be expanded. Clearly this is wrong. And, it seems to me that looping over languages and trying to guess the splitting style for the input text is probably bad. However, fixing the problem is not so easy (again due to Ada). I've filed a follow-up bug, PR symtab/32733, for this. Meanwhile, this patch changes the code to be closer to the originally-submitted patch. This works because the comparison is now done between the full name and the "lookup_name_without_params" object, which is a less adulterated variant of the original input. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31010 Tested-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-07Use wild matching for lookup_name_info::match_anyTom Tromey1-1/+1
Currently, lookup_name_info::match_any symbol_name_match_type::FULL. However, this seems wrong. Consider the expand_symtabs_matching implementation of the cooked index: it compares name components, and then if all the components match, it checks: if ((match_type == symbol_name_match_type::FULL || (lang != language_ada && match_type == symbol_name_match_type::EXPRESSION))) { if (parent != nullptr) continue; That is, if the component-matching loop did not finish, and a full match is requested, then fail to match. This handles cases where the index is asked to look up "b::c" but finds "a::b::c". However, match_any should match, well, any. So, it seems to me that checking any parent matches is irrelevant -- and therefore this should use wild matching.
2025-03-08Automatic date update in version.inGDB Administrator1-1/+1
2025-03-07Handle ">>" in cp-name-parser.yTom Tromey2-0/+24
I noticed that a certain name didn't work correctly when trying to remove the parameters. I put this into lookup_name_info-selftests.c. I tracked this down to the fact that cp-name-parser.y doesn't handle ">>" to end templates. This patch fixes this in a simple way -- accepting the "RSH" token where appropriate and then un-pushing a ">".
2025-03-07Minor cleanups to cpname_stateTom Tromey1-9/+11
This changes cpname_state to have a constructor and some inline initializers.
2025-03-07gdb/dwarf: move cooked_indexer to cooked-indexer.{h,c}Simon Marchi5-825/+914
Move the cooked_indexer class declaration to a new cooked-indexer.h file, and the implementation to cooked-indexer.c. Change-Id: Ibff3b06045b2af65fa9516097acf732d7c2d9414 Approved-By: Tom Tromey <tom@tromey.com>
2025-03-07gdb/dwarf: move cooked_index_storage to cooked-index-storage.{h,c}Simon Marchi5-137/+194
cooked_index_storage is currently declared in `cooked-index.h` and implemented in `read.c`. Move all that to new `cooked-index-storage.{h,c}` files. Change-Id: I2a07eb446d8a07b15c5664dfe01e3a820cdd45be Approved-By: Tom Tromey <tom@tromey.com>
2025-03-07gdb/dwarf: move cutu_reader to read.hSimon Marchi2-146/+148
In order to move some things outside of read.c, cutu_reader needs to be in a header file. Change-Id: Ib26d7949c55867848d109332caf2efb1a6e72923 Approved-By: Tom Tromey <tom@tromey.com>
2025-03-07AVR: gas/32704 - Improve code generation for __gcc_isr.Georg-Johann Lay1-54/+122
The prologue generated by __gcc_isr can be improved in situations where: * ZERO_REG is needed, and * SREG is not clobbered by the ISR, and * avr-gcc provides a GPR >= R16 with the Done chunk, and * Code generation is for ordinary AVRs (not AVRrc). For example, the prologue for volatile char var; __attribute__((signal)) void __vector_1 (void) { var = 1; var = 0; } may be 00000000 <__vector_1>: 0: 8f 93 push r24 2: 1f 92 push r1 4: 80 e0 ldi r24, 0 6: 18 2e mov r1, r24 instead of the code as currently generated by GAS: 00000000 <__vector_1>: 0: 1f 92 push r1 2: 1f b6 in r1, SREG 4: 1f 92 push r1 6: 11 24 clr r1 8: 8f 93 push r24 which consumes more stack, time and code than needed. gas/ PR gas/32704 PR gas/21683 * config/tc-avr.c (avr_isr): bool-ize. (avr_emit_insn): Emit "mov" code as MOV R1,<reg>. (avr_isr_stack_t): New typedef. (avr_emit_push, avr_emit_pop): New static functions. (avr_patch_gccisr_frag): Overhaul prologue and epilogue generation.
2025-03-07Fix imm20 range check in MSP430 port of gasNick Clifton7-11/+45
2025-03-07gas: don't permit "repeat" expressions with .cfi_{escape,fde_data}Jan Beulich1-8/+14
Repeat counts greater than 1 will emit data directly into the current (sub-)section. That's wrong with .cfi_*, which defer data emission until much later: N-1 instances of the specified data would not end up in .eh_frame (or whatever the section that CFI data was specified to go into). Simply disallow "repeat" expressions in such cases.
2025-03-07gas/listing: drop forward declarationsJan Beulich1-11/+0
These aren't needed (anymore); all static functions are defined before their first use.
2025-03-07gas: centralize declaration of listing_tailJan Beulich4-6/+3
Besides it being somewhat off to have three decls scattered across the code base, it is generally bad practice for the definition of a symbol to not also observe its declaration (making sure the two won't go out of sync).
2025-03-07objdump: permit disassembling multiple individual functionsJan Beulich4-14/+63
Compilers may split functions, e.g. into a "hot" and "cold" part, or they may emit special case instantiations (e.g. as a result of IPA). It can be helpful to be able to disassemble all of the parts or clones in one go. Permit using "--disassemble=" multiple times.
2025-03-07objdump: properly disassemble successive functions of the same nameJan Beulich6-4/+76
... when only their symbol was requested for disassembly. Addressing the respective FIXME is as easy as coverting the "else" there to an if() with the opposite condition, thus accounting for the disabling the original if() may have effected.
2025-03-07Fix missing int argument warningJan-Benedict Glaw1-1/+1
This warning (per -Werror) breaks the build using a recent GCC with recent userland. Approved-By: Tom Tromey <tom@tromey.com>
2025-03-07[gdb/tdep] Support REX2 and EVEX prefixTom de Vries1-1/+109
The following amd64 insn: ... 0: 67 d5 44 8d 3d 00 00 00 00 lea 0x0(%eip),%r31d ... uses the REX2 prefix [1], which is currently not supported in amd64_get_insn_details. Add the missing support in amd64_get_insn_details, as well as a corresponding unit test. Likewise for an amd64 insn using an EVEX prefix [2]: ... 0: 62 f1 7c 48 28 05 00 fc ff ff vmovaps -0x400(%rip),%zmm0 ... Tested on x86_64-linux. PR tdep/32725 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32725 [1] https://en.wikipedia.org/wiki/VEX_prefix [2] https://en.wikipedia.org/wiki/EVEX_prefix
2025-03-07[gdb/tdep] Fix vmovdqu decodingTom de Vries1-6/+77
PR tdep/31952 reports that displaced stepping over an instruction pointer relative insn "vmovdqu 0x20(%rip),%ymm1" gives the wrong results. This is caused by misclassification of the insn in amd64_get_insn_details, which results in details.modrm_offset == -1, while the instruction in fact does have a modrm byte. The instruction is encoded as follows: ... 400557: c5 fe 6f 0d 20 00 00 00 vmovdqu 0x20(%rip),%ymm1 ... where: - "0xc5 0xfe" is the vex2 prefix, - "0x6f" is the opcode, - "0x0d" is the modrm byte, and - "0x20 0x00 0x00 0x00" is a 32-bit displacement. The problem is related to details.opcode_len, which is 1. While it is true that the length of the opcode in the insn (0x6f) is 1 byte, the vex2 prefix implies that we're encoding an 2-byte opcode beginnning with 0x0f [1]. Consequently, we should be using the twobyte_has_modrm map rather than the onebyte_has_modrm map. Fix this in amd64_get_insn_details, and add a selftest to check this. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31952 [1] https://en.wikipedia.org/wiki/VEX_prefix
2025-03-07[gdb/tdep] Make amd64_get_insn_details more regularTom de Vries1-4/+7
In amd64_get_insn_details, I found this code with a comment explaining why enc_prefix_offset is not set: ... else if (vex2_prefix_p (*insn)) { /* Don't record the offset in this case because this prefix has no REX.B equivalent. */ insn += 2; } ... which I didn't understand until I looked at the only use of enc_prefix_offset, in fixup_riprel: ... /* REX.B should be unset (VEX.!B set) as we were using rip-relative addressing, but ensure it's unset (set for VEX) anyway, tmp_regno is not r8-r15. */ if (insn_details->enc_prefix_offset != -1) { gdb_byte *pfx = &dsc->insn_buf[insn_details->enc_prefix_offset]; if (rex_prefix_p (pfx[0])) pfx[0] &= ~REX_B; else if (vex3_prefix_p (pfx[0])) pfx[1] |= VEX3_NOT_B; else gdb_assert_not_reached ("unhandled prefix"); } ... Fix this by: - setting enc_prefix_offset for the vex2 case in amd64_get_insn_details, making the function more regular and easier to understand, and - handling the vex2 case in the "enc_prefix_offset != -1" clause in fixup_riprel. Tested on x86_64-linux.
2025-03-07[gdb/tdep] Add vzeroupper and vzeroall in amd64-insn-decode selftestTom de Vries1-0/+34
After I posted a tentative patch for PR31952, Alexander Monakov pointed out that the patch broke instruction decoding for instructions vzeroall and vzeroupper. Add selftests for these two instructions in amd64-insn-decode, both using vex2 and vex3 prefixes. Tested on x86_64-linux.
2025-03-07[gdb/tdep] Add vex2_to_vex3Tom de Vries1-0/+40
I noticed here [1] that the vex2 prefix is essentially a special case of the vex3 prefix, meaning it's possible to rewrite any insn with a vex2 prefix into an equivalent one with a vex3 prefix. Add function vex2_to_vex3 that does precisely that, in the selftests namespace. Add a selftest that exercises this function. Tested on x86_64-linux. [1] https://en.wikipedia.org/wiki/VEX_prefix
2025-03-07[gdb/tdep] Factor out part of fixup_riprelTom de Vries1-22/+37
Factor out the part of fixup_riprel that patches the insn, and use it in a unit test. Tested on x86_64-linux.
2025-03-07[gdb/tdep] Fix rip-relative insn handling in amd64_get_used_input_int_regTom de Vries1-1/+12
I wanted to add a unit test for an an rip-relative amd64 insn, so I did: ... $ gcc -fPIE hello.c ... and used an rip-relative insn from main: ... 4005db: 48 8d 3d 1e 00 00 00 lea 0x1e(%rip),%rdi ... While writing the unit test, I found that amd64_get_used_input_int_reg returns rbp as input register. Fix this by using rip_relative_p in amd64_get_used_input_int_reg to handle this case. Tested on x86_64-linux.
2025-03-07[gdb/tdep] Factor out rip_relative_pTom de Vries1-2/+14
Factor out rip_relative_p, and rewrite it to use MODRM_MOD_FIELD and MODRM_RM_FIELD. No functional changes. Tested on x86_64-linux.
2025-03-07[gdb/tdep] Add amd64-insn-decode selftestTom de Vries1-8/+63
Add a selftest that checks the results of amd64_get_insn_details and related functions for two basic instructions. Add a parameter assumptions to amd64_get_used_input_int_regs, to make sure that this selftest: ... /* INSN: add %eax,(%rcx). */ ... SELF_CHECK (amd64_get_used_input_int_regs (&details, false) == ((1 << EAX_REG_NUM) | (1 << ECX_REG_NUM))); ... passes because it found the "%eax" in the insn, rather than passing because of this assumption: ... /* Assume RAX is used. If not, we'd have to detect opcodes that implicitly use RAX. */ used_regs_mask |= 1 << EAX_REG_NUM; ... Tested on x86_64-linux.
2025-03-07[gdb/tdep] Factor out amd64_get_used_input_int_regsTom de Vries1-6/+17
The function amd64_get_unused_input_int_reg consists of two parts: - finding the used int registers in an insn, and - picking an unused int register. Factor out the first part as new function amd64_get_used_input_int_regs. No functional changes. Tested on x86_64-linux.
2025-03-07[gdb/tdep] Refactor amd64_get_unused_input_int_reg, part 3Tom de Vries1-21/+22
While reading amd64_get_unused_input_int_reg, I noticed that it avoids picking RSP, which has to do with how the result of the only call to it is going to be used. Likewise for picking a register in the RAX ... RDI range. Fix this by: - adding an allowed_regs_mask parameter to amd64_get_unused_input_int_reg, and - properly documenting the value of the corresponding argument in fixup_riprel. No functional changes. Tested on x86_64-linux.
2025-03-07[gdb/tdep] Refactor amd64_get_unused_input_int_reg, part 2Tom de Vries1-2/+2
I noticed that amd64_get_unused_input_int_reg uses a signed int for a bit mask: ... /* 1 bit for each reg */ int used_regs_mask = 0; ... There's an assert: ... gdb_assert (used_regs_mask < 256); ... which is meant to assert on register numbers >= 8, but if for instance sizeof (used_regs_mask) == 4 and used_regs_mask == (1 << 31), then that is not caught because of the signedness. We could fix this by changing the type to unsigned int, but that only guarantees 16 bits in the reg mask. Intel CPUs with the APX extension support 32 int registers. The implementation of amd64_get_unused_input_int_reg doesn't support analyzing registers with register number >= 8 yet, but now that we're changing the type, it seems like a good idea to anticipate this. Fix this by using uint32_t. Likewise, update the loop over the reg mask: ... for (i = 0; i < 8; ++i) { if (! (used_regs_mask & (1 << i))) return i; ... to handle any used_regs_mask value rather than just those for register number < 8. Tested on x86_64-linux.
2025-03-07[gdb/tdep] Refactor amd64_get_unused_input_int_reg, part 1Tom de Vries1-10/+19
While reading amd64_get_unused_input_int_reg, I noticed that it first asserts, then throws an internal_error if no unused register can be found. Looking at the documentation of gdbarch_displaced_step_copy_insn, it seems that a failure can be indicated less abruptly, by returning a nullptr. Fix this by: - returning -1 in case of failure to find an unused register in amd64_get_unused_input_int_reg, and - propagating this to amd64_displaced_step_copy_insn. Tested on x86_64-linux.
2025-03-07gas: leave expression symbols alone when processing equatesJan Beulich6-5/+46
PR gas/32721 In this bogus piece of code distilled from fuzzing and slightly edited: A=%eax|%! Y=A Z=A or $6,Z the first of the equates with A on the rhs changes A's section (due to the use of S_GET_VALUE()), from expression to register, thus yielding Y in the expression section (and X_op being O_symbol), but Z in the register section (and X_op being O_register with X_add_value being -1). There shouldn't be random O_register expressions, though, for targets setting md_register_arithmetic to false. Plus both Y and Z would better be exchangeable. In pseudo_set() wire handling of O_symbol expressions referencing a symbol in the expression section to that of other stuff ending up in this section. Also avoid bogus O_register expressions to be created, for targets setting md_register_arithmetic to false: S_GET_VALUE() would resolve any arithmetic, which must not happen for such targets. To be on the safe side for such targets, also amend resolve_register(). Correct another earlier oversight there too (affecting at least Z80), by using the new expr_copy() helper there as well. Undo 46b9f07dfe79 ("PR 32721, internal error in tc-i386.c:parse_register"), albeit without losing the simplification it did.
2025-03-07v850: improve linker scripts for relocatable linkingJan Beulich2-14/+14
Quite a few constructs where unconditional when they should take $RELOCATING into account. The original observation was that output of "ld -r" had .text start at 0x00100000.
2025-03-07gas: fold is_end_of_line[] into lex_type[]Jan Beulich6-73/+46
... by way of introducing LEX_EOL and LEX_EOS. As a prereq convert the remaining open-coded accesses. The Alpha change is actually a functional one: The array slot for '!' having been set to 1 is very unlikely to have been correct. 1 means "end of line", when surely "end of statement" was always meant.
2025-03-07include: drop bout.hJan Beulich1-192/+0
gas'es obj-bout.c was dropped about 20 years ago, while bfd's bout.c was dropped almost 7 years ago. Time for the unused header to go away, too.
2025-03-07rl78: drop redundant statement separator checkJan Beulich1-2/+1
With the switch to the use of is_end_of_stmt() in 2dd0370c433d ("rl78: use is_whitespace()") the open-coded checking against line_separator_chars[] can be dropped.
2025-03-07Z8k: use is_end_of_stmt()Jan Beulich1-5/+5
... instead of open-coding it.
2025-03-07x86: use is_end_of_stmt()Jan Beulich2-7/+7
... instead of open-coding it.
2025-03-07VAX: use is_end_of_stmt()Jan Beulich1-2/+2
... instead of open-coding it. This also fixes two array underrun issues, when plain char is a signed type.
2025-03-07TILEPro: use is_end_of_stmt()Jan Beulich1-4/+4
... instead of open-coding it. Also convert a variable to plain char (allowing to drop two casts), which is how it's actually used.