aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2018-04-30Remove long_long_align_bit gdbarch attributeTom Tromey7-36/+23
This removes the long_long_align_bit gdbarch attribute in favor of type_align. This uncovered two possible issues. First, arc-tdep.c claimed that long long alignment was 32 bits, but as discussed on the list, ARC has a maximum alignment of 32 bits, so I've added an arc_type_align function to account for this. Second, jit.c, the sole user of long_long_align_bit, was confusing "long long" with uint64_t. The relevant structure is defined in the JIT API part of the manual as: struct jit_code_entry { struct jit_code_entry *next_entry; struct jit_code_entry *prev_entry; const char *symfile_addr; uint64_t symfile_size; }; I've changed this code to use uint64_t. 2018-04-30 Tom Tromey <tom@tromey.com> * jit.c (jit_read_code_entry): Use type_align. * i386-tdep.c (i386_gdbarch_init): Don't call set_gdbarch_long_long_align_bit. * gdbarch.sh: Remove long_long_align_bit. * gdbarch.c, gdbarch.h: Rebuild. * arc-tdep.c (arc_type_align): New function. (arc_gdbarch_init): Use arc_type_align. Don't call set_gdbarch_long_long_align_bit.
2018-04-30Remove rust_type_alignmentTom Tromey2-42/+6
rust_type_alignment is not needed now that gdb has type alignment code. So, this removes it. 2018-04-30 Tom Tromey <tom@tromey.com> * rust-lang.c (rust_type_alignment): Remove. (rust_composite_type): Use type_align.
2018-04-30Expose type alignment on gdb.TypeTom Tromey8-0/+56
This adds an "alignof" attribute to gdb.Type in the Python API. 2018-04-30 Tom Tromey <tom@tromey.com> * NEWS: Mention Type.align. * python/py-type.c (typy_get_alignof): New function. (type_object_getset): Add "alignof". 2018-04-30 Tom Tromey <tom@tromey.com> * python.texi (Types In Python): Document Type.align. 2018-04-30 Tom Tromey <tom@tromey.com> * gdb.python/py-type.exp: Check align attribute. * gdb.python/py-type.c: New "aligncheck" global.
2018-04-30Handle alignof and _AlignofTom Tromey12-1/+444
This adds alignof and _Alignof to the C/C++ expression parser, and adds new tests to test the features. The tests are written to try to ensure that gdb's knowledge of alignment rules stays in sync with the compiler's. 2018-04-30 Tom Tromey <tom@tromey.com> PR exp/17095: * NEWS: Update. * std-operator.def (UNOP_ALIGNOF): New operator. * expprint.c (dump_subexp_body_standard) <case UNOP_ALIGNOF>: New. * eval.c (evaluate_subexp_standard) <case UNOP_ALIGNOF>: New. * c-lang.c (c_op_print_tab): Add alignof. * c-exp.y (ALIGNOF): New token. (exp): Add "ALIGNOF" production. (ident_tokens): Add _Alignof and alignof. 2018-04-30 Tom Tromey <tom@tromey.com> PR exp/17095: * gdb.dwarf2/dw2-align.exp: New file. * gdb.cp/align.exp: New file. * gdb.base/align.exp: New file. * lib/gdb.exp (gdb_int128_helper): New proc. (has_int128_c, has_int128_cxx): New caching procs.
2018-04-30Add initial type alignment supportTom Tromey10-5/+359
This adds some basic type alignment support to gdb. It changes struct type to store the alignment, and updates dwarf2read.c to handle DW_AT_alignment. It also adds a new gdbarch method and updates i386-tdep.c. None of this new functionality is used anywhere yet, so tests will wait until the next patch. 2018-04-30 Tom Tromey <tom@tromey.com> * i386-tdep.c (i386_type_align): New function. (i386_gdbarch_init): Update. * gdbarch.sh (type_align): New method. * gdbarch.c, gdbarch.h: Rebuild. * arch-utils.h (default_type_align): Declare. * arch-utils.c (default_type_align): New function. * gdbtypes.h (TYPE_ALIGN_BITS): New define. (struct type) <align_log2>: New field. <instance_flags>: Now a bitfield. (TYPE_RAW_ALIGN): New macro. (type_align, type_raw_align, set_type_align): Declare. * gdbtypes.c (type_align, type_raw_align, set_type_align): New functions. * dwarf2read.c (quirk_rust_enum): Set type alignment. (get_alignment, maybe_set_alignment): New functions. (read_structure_type, read_enumeration_type, read_array_type) (read_set_type, read_tag_pointer_type, read_tag_reference_type) (read_subrange_type, read_base_type): Set type alignment.
2018-04-30This patch adds support to objdump for disassembly of NFP (Netronome Flow ↵Francois H. Theron39-2458/+7302
Processor) ELF files (.nffw) as well as some basic readelf support. bfd * Makefile.am: Added NFP files to build. * archures.c: Added bfd_arch_nfp * config.bfd: Added NFP support. * configure.ac: Added NFP support. * cpu-nfp.c: New, for NFP support. * elf-bfd.h: Added elf_section_info() * elf64-nfp.c: New, for NFP support. * po/SRC-POTFILES.in: Added NFP source files. * targets.c: Added nfp_elf64_vec * bfd-in2.h: Regenerate. * Makefile.in: Regenerate. * configure: Regenerate. binutils* readelf.c: Very basic support for EM_NFP and its section types. * testsuite/binutils-all/nfp: New directory. * testsuite/binutils-all/nfp/objdump.exp: New file. Run new tests. * testsuite/binutils-all/nfp/test2_ctx8.d: New file. * testsuite/binutils-all/nfp/test2_no-pc_ctx4.d: New file. * testsuite/binutils-all/nfp/test1.d: New file. * testsuite/binutils-all/nfp/nfp6000.nffw: New file. * testsuite/binutils-all/nfp/test2_nfp6000.nffw: New file. * NEWS: Mention the new support. include * dis-asm.h: Added print_nfp_disassembler_options prototype. * elf/common.h: Added EM_NFP, officially assigned. See Google Group Generic System V Application Binary Interface. * elf/nfp.h: New, for NFP support. * opcode/nfp.h: New, for NFP support. opcodes Makefile.am: Added nfp-dis.c. configure.ac: Added bfd_nfp_arch. disassemble.h: Added print_insn_nfp prototype. disassemble.c: Added ARCH_nfp and call to print_insn_nfp nfp-dis.c: New, for NFP support. po/POTFILES.in: Added nfp-dis.c to the list. Makefile.in: Regenerate. configure: Regenerate.
2018-04-30Use bool in read_index_from_sectionSimon Marchi2-3/+7
gdb/ChangeLog: * dwarf2read.c (read_index_from_section): Use bool.
2018-04-30Automatic date update in version.inGDB Administrator1-1/+1
2018-04-29proc-events.c: fix compilation on SolarisFabian Groffen2-0/+8
This patch adds a guard around the usage of SYS_uuidsys, which is not available on (at least) Solaris 10 and OpenIndiana. gdb/ChangeLog: PR gdb/22950 * proc-events.c (init_syscall_table): Guard usage os SYS_uuidsys with #ifdef.
2018-04-29Fix race when building ada-lex.cJohn Reiser2-10/+14
Prevent a race when building ada-lex.c, and any target of rules .c:.l or .c:.y. The target should be written only at the last step, else SIGINT (^C) can leave an inconsistent state. Being .PRECIOUS makes it even worse. gdb/ChangeLog: PR build/22873 * gdb/Makefile.in: (.c:.l, .c:.y): Write the target only in the last step, and do it atomically.
2018-04-29Automatic date update in version.inGDB Administrator1-1/+1
2018-04-28Automatic date update in version.inGDB Administrator1-1/+1
2018-04-27Add libcc1 v1 compatibility to C compile featureAlexandre Oliva2-5/+28
This patch adds v1 compatibiltiy to the C compile feature. The only change in v1 concerns the handling of integer types, which permits GDB to specify the built-in name for the type. As far as I know, the C frontend is still on v0, so this patch is purely precautionary. [By default C++ compile uses the equivalent of the C frontend's int_type and float_type (aka the "v1" versions).] gdb/ChangeLog: * compile/compile-c-types.c (convert_int, convert_float): Update for C FE v1.
2018-04-27Add inclusive range support for RustTom Tromey8-23/+117
This is version 2 of the patch to add inclusive range support for Rust. I believe it addresses all review comments. Rust recently stabilized the inclusive range feature: https://github.com/rust-lang/rust/issues/28237 An inclusive range is an expression like "..= EXPR" or "EXPR ..= EXPR". It is like an ordinary range, except the upper bound is inclusive, not exclusive. This patch adds support for this feature to gdb. Regression tested on x86-64 Fedora 27. 2018-04-27 Tom Tromey <tom@tromey.com> PR rust/22545: * rust-lang.c (rust_inclusive_range_type_p): New function. (rust_range): Handle inclusive ranges. (rust_compute_range): Likewise. * rust-exp.y (struct rust_op) <inclusive>: New field. (DOTDOTEQ): New constant. (range_expr): Add "..=" productions. (operator_tokens): Add "..=" token. (ast_range): Add "inclusive" parameter. (convert_ast_to_expression) <case OP_RANGE>: Handle inclusive ranges. * parse.c (operator_length_standard) <case OP_RANGE>: Handle new bounds values. * expression.h (enum range_type) <NONE_BOUND_DEFAULT_EXCLUSIVE, LOW_BOUND_DEFAULT_EXCLUSIVE>: New constants. Update comments. * expprint.c (print_subexp_standard): Handle new bounds values. (dump_subexp_body_standard): Likewise. 2018-04-27 Tom Tromey <tom@tromey.com> PR rust/22545: * gdb.rust/simple.exp: Add inclusive range tests.
2018-04-27Enable -Wsuggest-overrideTom Tromey10-40/+67
I noticed the existence of -Wsuggest-override and so this patch enables it for gdb. It found a few spots that could use "override". Also I went ahead and removed all uses of the "OVERRIDE" macro. Using override is beneficial because it makes it harder to change a base class and then forget to change a derived class. Tested by the buildbot. ChangeLog 2018-04-27 Tom Tromey <tom@tromey.com> * configure: Rebuild. * warning.m4 (AM_GDB_WARNINGS): Add -Wsuggest-override. * dwarf2loc.c (class dwarf_evaluate_loc_desc): Use "override", not "OVERRIDE". (class symbol_needs_eval_context): Likewise. * dwarf2read.c (mock_mapped_index::symbol_name_count) (mock_mapped_index::symbol_name_at): Use "override". Remove "virtual". * dwarf2-frame.c (dwarf_expr_executor::get_addr_index): Use "override". (class dwarf_expr_executor): Use "override", not "OVERRIDE". * aarch64-tdep.c (instruction_reader::read): Use "override". (instruction_reader_test::read): Likewise. * arm-tdep.c (instruction_reader::read): Use "override". (instruction_reader_thumb::read): Likewise. gdbserver/ChangeLog 2018-04-27 Tom Tromey <tom@tromey.com> * configure: Rebuild.
2018-04-27MIPS/LD/testsuite: Update `run_dump_test' cases for non-DSO targetsMaciej W. Rozycki18-0/+41
Mark these `run_dump_test' cases across `ld-mips-elf/mips-elf.exp' that are run unconditionally and require shared library support for exclusion for targets that do not have such support, removing these failures: FAIL: MIPS BAL/JALX in PIC mode FAIL: microMIPS BAL/JALX in PIC mode FAIL: MIPS BAL/JALX in PIC mode (ignore branch ISA) FAIL: microMIPS BAL/JALX in PIC mode (ignore branch ISA) FAIL: ld-mips-elf/hash1a FAIL: ld-mips-elf/hash1b FAIL: ld-mips-elf/hash1c with `mipsel-ps2-elf' and `mips64el-ps2-elf' targets. Tests that are guarded with `linux_gnu' will have to be reviewed separately. ld/ * testsuite/ld-mips-elf/bal-jalx-pic.d: Only run for `check_shared_lib_support' targets. * testsuite/ld-mips-elf/bal-jalx-pic-n32.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-n64.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-micromips.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-micromips-n32.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-micromips-n64.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-ignore.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-n32.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-n64.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips-n32.d: Likewise. * testsuite/ld-mips-elf/bal-jalx-pic-ignore-micromips-n64.d: Likewise. * testsuite/ld-mips-elf/hash1a.d: Likewise. * testsuite/ld-mips-elf/hash1b.d: Likewise. * testsuite/ld-mips-elf/hash1c.d: Likewise. * testsuite/ld-mips-elf/relax-jalr-n32-shared.d: Likewise. * testsuite/ld-mips-elf/relax-jalr-n64-shared.d: Likewise.
2018-04-27testsuite: Support filtering targets by TCL procedure in `run_dump_test'Maciej W. Rozycki7-46/+91
Implement a more complex way of selecting targets to include or exclude with `run_dump_test' cases, by extending the syntax for the `target', `not-target', `skip' and `not-skip' options (with the binutils and GAS test suites) and the `target', `alltargets' and `notarget' options (with the LD test suite) to also accept a name of a TCL procedure instead of a target triplet glob matching expression. The result, 1 or 0, of the procedure determines whether the test is to be run or not. This mimics and expands `dg-require-effective-target' from the GCC test suite. Names of TCL procedures are supplied in square brackets `[]' as with TCL procedure calls, observing that target triplet glob matching expressions do not normally start and end with matching square brackets both at a time. Arguments for procedures are allowed if required. Having a way to specify a complex condition for a `run_dump_test' case to run has the advantage of keeping it local within the test case itself where tool options related to the check might be also present, removing the need to wrap `run_dump_test' calls into an `if' block whose only reason is to do a feature check, and ultimately lets one have the test reported as UNSUPPORTED automagically if required (not currently supported by the `run_dump_test' options used for LD). binutils/ * testsuite/lib/binutils-common.exp (match_target): New procedure. * testsuite/lib/utils-lib.exp (run_dump_test): Use it in place of `istarget' for matching with `target', `not-target', `skip' and `not-skip' options. gas/ * testsuite/lib/gas-defs.exp (run_dump_test): Use `match_target' in place of `istarget' for matching with `target', `not-target', `skip' and `not-skip' options. ld/ * testsuite/lib/ld-lib.exp (run_dump_test): Use `match_target' in place of `istarget' for matching with `target', `alltargets' and `notarget' options.
2018-04-27Revert "Enable Intel MOVDIRI, MOVDIR64B instructions."Igor Tsimbalist21-15508/+15097
This reverts commit a914a7c95895161c99533d5919b8504b37ea54a0.
2018-04-27Regenerate some files for recent ARM patchesAlan Modra5-1/+19
bfd/ * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. ld/ * po/BLD-POTFILES.in: Regenerate.
2018-04-27PR23123, PowerPC32 ifunc regressionAlan Modra3-7/+15
Two of the gcc ifunc tests fail for ppc32, due to my pr22374 fix being a little too enthusiastic in trimming PLT entries. ppc64 doesn't have the same failures because ppc64_elf_check_relocs happens to set needs_plt for any ifunc reloc. PR 23123 PR 22374 * elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Don't drop plt relocs for ifuncs. * elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Comment fixes.
2018-04-27Automatic date update in version.inGDB Administrator1-1/+1
2018-04-26Fix remote 'g' command error handling (PR remote/9665)Andrzej Kaczmarek2-19/+12
'g' command returns hex-string as response so simply checking for 'E' to determine if it failed is not enough and can trigger spurious error messages. For example, invalid behaviour can be easily triggered on Cortex-M as follows: (gdb) set $r0 = 0xe0 Sending packet: $P0=e0000000#72...Packet received: OK Packet P (set-register) is supported Sending packet: $g#67...Packet received: E0000000849A0020... Remote failure reply: E0000000849A0020... This patch fixes the problem by calling putpkt()/getpkt() directly and checking result with packet_check_result(). This works fine since Enn response has odd number of bytes while proper response has even number of bytes. Also, remote_send() is now not used anywhere so it can be removed. gdb/Changelog: 2018-04-26 Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl> PR remote/9665 * remote.c (send_g_packet): Use putpkt/getpkt/packet_check_result instead of remote_send. (remote_send): Remove.
2018-04-26Enable Intel MOVDIRI, MOVDIR64B instructions.Igor Tsimbalist21-15097/+15508
gas/ * config/tc-i386.c (cpu_arch): Add .movdir, .movdir64b. (cpu_noarch): Likewise. (process_suffix): Add check for register size. * doc/c-i386.texi: Document movdiri, movdir64b. * testsuite/gas/i386/i386.exp: Run MOVDIR{I,64B} tests. * testsuite/gas/i386/movdir-intel.d: New test. * testsuite/gas/i386/movdir.d: Likewise. * testsuite/gas/i386/movdir.s: Likewise. * testsuite/gas/i386/movdir64b-reg.s: Likewise. * testsuite/gas/i386/movdir64b-reg.l: Likewise. * testsuite/gas/i386/x86-64-movdir-intel.d: Likewise. * testsuite/gas/i386/x86-64-movdir.d: Likewise. * testsuite/gas/i386/x86-64-movdir.s: Likewise. * testsuite/gas/i386/x86-64-movdir64b-reg.s: Likewise. * testsuite/gas/i386/x86-64-movdir64b-reg.l: Likewise. opcodes/ * i386-dis.c (enum): Add PREFIX_0F38F8, PREFIX_0F38F9. (prefix_table): New instructions (see prefix above). Add Gva macro and handling in OP_G. * i386-gen.c (cpu_flag_init): Add CPU_MOVDIRI_FLAGS, CPU_MOVDIR64B_FLAGS. (cpu_flags): Likewise. (opcode_modifiers): Add AddrPrefixOpReg. (i386_opcode_modifier): Likewise. * i386-opc.h (enum): Add CpuMOVDIRI, CpuMOVDIR64B. (i386_cpu_flags): Likewise. * i386-opc.tbl: Add movidir{i,64b}. * i386-init.h: Regenerate. * i386-tbl.h: Likewise.
2018-04-26Extend the assembler so that it can automatically generate GNU Build ↵Nick Clifton15-21/+350
attribute notes if none are present in the input files. gas * as.c (flag_generate_build_notes): New variable. (show_usage): Add entry for --generate-missing-build-notes. (parse_args): Parse --generate-missing-build-notes. * as.h: Export flag_generate_build_notes. * symbols.c (save_symbol_name): Ensure that the name parameter is not NULL. * write.c (create_obj_attrs_section): Reformat. (create_note_reloc): New function - creates a relocation for a field in a GNU Build attribute note. (maybe_generate_build_notes): New function - created GNU Build attribute notes if none are present in the output file. (write_object_file): Call maybe_generate_build_notes. * configure.ac (--enable-generate-build-notes): New option. * NEWS: Announce the new feature. * doc/as.textinfo: Document the new option. * config.in: Regenerate. * configure: Regenerate. binutils* readelf.c (is_32bit_abs_reloc): Support R_PARISC_DIR32 as a 32-bit absolute reloc for the HPPA target. * testsuite/binutils-all/note-5.d: New test. * testsuite/binutils-all/note-5.s: Source file for new test. * testsuite/binutils-all/objcopy.exp: Run new test.
2018-04-26[ld/testsuite] Fix pr2404 output.Christophe Lyon3-3/+9
2018-04-26 Christophe Lyon <christophe.lyon@linaro.org> * testsuite/ld-elf/pr2404b.c (main): Adjust printf to account for new variable name. * testsuite/ld-elf/pr2404.out: Adjust expected output accordingly.
2018-04-26Fix resolving GNU ifunc bp locations when inferior runs resolverPedro Alves4-5/+27
I noticed that if you set a breakpoint on an ifunc before the ifunc is resolved, and then let the program call the ifunc, thus resolving it, GDB end up with a location for that original breakpoint that is pointing to the ifunc target, but it is left pointing to the first address of the function, instead of after its prologue. After prologue is what you get if you create a new breakpoint at that point. 1) With no debug info for the target function: 1.a) Set before resolving, and then program continued passed resolving: Num Type Disp Enb Address What 1 breakpoint keep y 0x0000000000400753 <final> 1.b) Breakpoint set after inferior resolved ifunc: Num Type Disp Enb Address What 2 breakpoint keep y 0x0000000000400757 <final+4> 2) With debug info for the target function: 1.a) Set before resolving, and then program continued passed resolving: Num Type Disp Enb Address What 1 breakpoint keep y 0x0000000000400753 in final at gdb/testsuite/gdb.base/gnu-ifunc-final.c:20 1.b) Breakpoint set after inferior resolved ifunc: Num Type Disp Enb Address What 2 breakpoint keep y 0x000000000040075a in final at gdb/testsuite/gdb.base/gnu-ifunc-final.c:21 The problem is that elf_gnu_ifunc_resolver_return_stop (called by the internal breakpoint that traps the resolver returning) does not agree with linespec.c:minsym_found. It does not skip to the function's start line (i.e., past the prologue). We can now use the find_function_start_sal overload added by the previous commmit to fix this. New tests included, which fail before the patch, and pass afterwards. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * elfread.c (elf_gnu_ifunc_resolver_return_stop): Use find_function_start_sal instead of find_pc_line. gdb/testsuite/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * gdb.base/gnu-ifunc.exp (set-break): Test that GDB resolves ifunc breakpoint locations correctly of ifunc breakpoints set while the program resolves the ifunc.
2018-04-26Extend GNU ifunc testcasesPedro Alves5-95/+366
This patch extends/rewrites the gdb.base/gnu-ifunc.exp testcase to cover the many different fixes in earlier patches. (This was actually what encovered most of the problems.) The current testcase uses an ifunc symbol with the same name as the ifunc resolver symbol and makes sure to compile the ifunc resolver without debug info. That does not model how ifuncs are implemented in gcc/ifunc nowadays. Instead, what we have is that the glibc ifunc resolvers nowadays are written in C and end up with debug info. Also, in some cases the ifunc target is written in assembly, but in other cases it's written in C. In the case of target function written in C, if the target function has debug info, when we set a break on the ifunc, we want to set it past the prologue of the target function. Currently GDB gets that wrong. To make sure we cover all the different scenarios, the testcase is tweaked to cover all the different combinations of - An ifunc resolver with the same name as the user-visible symbol vs an ifunc resolver with a different name as the user-visible symbol. - ifunc resolver compiled with and without debug info. - ifunc target function compiled with and without debug info. The testcase currently sets breakpoints on ifuncs, calls ifunc functions, steps into ifunc functions, etc. After this series, this all works and the testcase passes cleanly. While working on this, I noticed that "b gnu_ifunc" before and after the inferior resolved the ifunc would end up with a breakpoint with different locations. That's now covered by new tests inside the new "set-break" procedure. It also tests other things like making sure we can't call an ifunc without a return-type case if we don't know the type of the target. And making sure that we pass enough arguments when we do know the type. gdb/testsuite/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * gdb.base/gnu-ifunc-final.c: New file. * gdb.base/gnu-ifunc.c (final): Delete, moved to gnu-ifunc-final.c. * gdb.base/gnu-ifunc.exp (executable): Delete. (staticexecutable): Adjust. (lib_opts, exec_opts): Delete. (make_binsuffix, build, set-break): New procedures. (misc_tests): New, with tests factored out from the top level. (top level): Test different combinations of ifunc resolver name, resolver with and with debug info, and ifunc target with and without debug info. Wrap static tests with with_target_prefix.
2018-04-26PPC64: always make synthetic .text symbols for GNU ifunc symbolsPedro Alves2-6/+21
If you create an ifunc using GCC's __attribute__ ifunc, like: extern int gnu_ifunc (int arg); static int gnu_ifunc_target (int arg) { return 0; } __typeof (gnu_ifunc) *gnu_ifunc_resolver (unsigned long hwcap) { return gnu_ifunc_target; } __typeof (gnu_ifunc) gnu_ifunc __attribute__ ((ifunc ("gnu_ifunc_resolver"))); then you end up with two (function descriptor) symbols, one for the ifunc itself, and another for the resolver: (...) 12: 0000000000020060 104 FUNC GLOBAL DEFAULT 18 gnu_ifunc_resolver (...) 16: 0000000000020060 104 GNU_IFUNC GLOBAL DEFAULT 18 gnu_ifunc (...) Both ifunc and resolver symbols have the same address/value, so ppc64_elf_get_synthetic_symtab only creates a synthetic text symbol for one of them. In the case above, it ends up being created for the resolver, only: (gdb) maint print msymbols (...) [ 7] t 0x980 .frame_dummy section .text [ 8] T 0x9e4 .gnu_ifunc_resolver section .text [ 9] T 0xa58 __glink_PLTresolve section .text (...) GDB needs to know when a program stepped into an ifunc resolver, so that it can know whether to step past the resolver into the target function without the user noticing. The way GDB does it is my checking whether the current PC points to an ifunc symbol (since resolver and ifunc have the same address by design). The problem is then that ppc64_elf_get_synthetic_symtab never creates the synchetic symbol for the ifunc, so GDB stops stepping at the resolver (in a test added by the following patch): (gdb) step gnu_ifunc_resolver (hwcap=21) at gdb/testsuite/gdb.base/gnu-ifunc-lib.c:33 33 { (gdb) FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=1: final_debug=0: step After this commit, we get: [ 8] i 0x9e4 .gnu_ifunc section .text [ 9] T 0x9e4 .gnu_ifunc_resolver section .text And stepping an ifunc call takes to the final function: (gdb) step 0x00000000100009e8 in .final () (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=1: final_debug=0: step An alternative to touching bfd I considered was for GDB to check whether there's an ifunc data symbol / function descriptor that points to the current PC, whenever the program stops, but discarded it because we'd have to do a linear scan over .opd over an over to find a matching function descriptor for the current PC. At that point I considered caching that info, but quickly dismissed it as then that has no advantage (memory or performance) over just creating the synthetic ifunc text symbol in the first place. I ran the binutils and ld testsuites on PPC64 ELFv1 (machine gcc110 on the GCC compile farm), and saw no regressions. This commit is part of a GDB patch series that includes GDB tests that fail without this fix. bfd/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Don't consider ifunc and non-ifunc symbols duplicates.
2018-04-26For PPC64/ELFv1: Introduce mst_data_gnu_ifuncPedro Alves10-54/+116
Running the new tests added later in the series on PPC64 (ELFv1) revealed that the current ifunc support needs a bit of a design rework to work properly on PPC64/ELFv1, as most of the new tests fail. The ifunc support only kind of works today if the ifunc symbol and the resolver have the same name, as is currently tested by the gdb.base/gnu-ifunc.exp testcase, which is unlike how ifuncs are written nowadays. The crux of the problem is that ifunc symbols are really function descriptors, not text symbols: 44: 0000000000020060 104 FUNC GLOBAL DEFAULT 18 gnu_ifunc_resolver 54: 0000000000020060 104 GNU_IFUNC GLOBAL DEFAULT 18 gnu_ifunc But, currently GDB only knows about ifunc symbols that are text symbols. GDB's support happens to work in practice for PPC64 when the ifunc and resolver are one and only, like in the current gdb.base/gnu-ifunc.exp testcase: 15: 0000000000020060 104 GNU_IFUNC GLOBAL DEFAULT 18 gnu_ifunc because in that case, the synthetic ".gnu_ifunc" entry point text symbol that bfd creates from the actual GNU ifunc "gnu_ifunc" function (descriptor) symbol ends up with the the "is a gnu ifunc" flag set / copied over: (gdb) maint print msymbols ... [ 8] i 0x9c4 .gnu_ifunc section .text <<< mst_text_gnu_ifunc ... [29] D 0x20060 gnu_ifunc section .opd crtstuff.c <<< mst_data But, if the resolver gets a distinct symbol/name from the ifunc symbol, then we end up with this: (gdb) maint print msymbols [ 8] T 0x9e4 .gnu_ifunc_resolver section .text <<< mst_text ... [29] D 0x20060 gnu_ifunc section .opd crtstuff.c <<< mst_data [30] D 0x20060 gnu_ifunc_resolver section .opd crtstuff.c <<< mst_data I have a follow up bfd patch that turns that into: (gdb) maint print msymbols + [ 8] i 0x9e4 .gnu_ifunc section .text <<< mst_text_gnu_ifunc [ 8] T 0x9e4 .gnu_ifunc_resolver section .text <<< mst_text ... [29] D 0x20060 gnu_ifunc section .opd crtstuff.c [30] D 0x20060 gnu_ifunc_resolver section .opd crtstuff.c but that won't help everything. We still need this patch. Specifically, when we do a symbol lookup by name, like e.g., to call a function (see c-exp.y hunk), e.g., "p gnu_ifunc()", then we need to know that the found "gnu_ifunc" minimal symbol is an ifunc in order to do some special processing. But, on PPC, that lookup by name finds the function descriptor symbol, which presently is just a mst_data symbol, while at present, we look for mst_text_gnu_ifunc symbols to decide whether to do special GNU ifunc processing. In most of those places, we could try to resolve the function descriptor with gdbarch_convert_from_func_ptr_addr, and then lookup the minimal symbol at the resolved PC, see if that finds a minimal symbol of type mst_text_gnu_ifunc. If so, then we could assume that the original mst_dadta / function descriptor "gnu_ifunc" symbol was an ifunc. I tried it, and it mostly works, even if it's not the most efficient. However, there's one case that can't work with such a design -- it's that of the user calling the ifunc resolver directly to debug it, like "p gnu_ifunc_resolver(0)", expecting that to return the function pointer of the final function (which is exercised by the new tests added later). In this case, with the not-fully-working solution, we'd resolve the function descriptor, find that there's an mst_text_gnu_ifunc symbol for the resolved address, and proceed calling the function as if we tried to call "gnu_ifunc", the user-visible GNU ifunc symbol, instead of the resolver. I.e., it'd be impossible to call the resolver directly as a normal function. Introducing mst_data_gnu_ifunc eliminates the need for several gdbarch_convert_from_func_ptr_addr calls, and, fixes the "call resolver directly" use case mentioned above too. It's the cleanest approach I could think of. In sum, we make GNU ifunc function descriptor symbols get a new "mst_data_gnu_ifunc" minimal symbol type instead of the bare mst_data type. So when symbol lookup by name finds such a minimal symbol, we know we found an ifunc symbol, without resolving the entry/text symbol. If the user calls the the resolver symbol instead, like "p gnu_ifunc_resolver(0)", then we'll find the regular mst_data symbol for "gnu_ifunc_resolver", and we'll call the resolver function as just another regular function. With this, most of the GNU ifunc tests added by a later patch pass on PPC64 too. The following bfd patch fixes the remaining issues. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * breakpoint.c (set_breakpoint_location_function): Handle mst_data_gnu_ifunc. * c-exp.y (variable production): Handle mst_data_gnu_ifunc. * elfread.c (elf_symtab_read): Give data symbols with BSF_GNU_INDIRECT_FUNCTION set mst_data_gnu_ifunc type. (elf_rel_plt_read): Update comment. * linespec.c (convert_linespec_to_sals): Handle mst_data_gnu_ifunc. (minsym_found): Handle mst_data_gnu_ifunc. * minsyms.c (msymbol_is_function, minimal_symbol_reader::record) (find_solib_trampoline_target): Handle mst_data_gnu_ifunc. * parse.c (find_minsym_type_and_address): Handle mst_data_gnu_ifunc. * symmisc.c (dump_msymbols): Handle mst_data_gnu_ifunc. * symtab.c (find_gnu_ifunc): Handle mst_data_gnu_ifunc. * symtab.h (minimal_symbol_type) <mst_text_gnu_ifunc>: Update comment. <mst_data_gnu_ifunc>: New enumerator.
2018-04-26Fix stepping past GNU ifunc resolvers (introduce lookup_msym_prefer)Pedro Alves3-49/+68
When we're stepping (with "step"), we want to skip trampoline-like functions automatically, including GNU ifunc resolvers. That is done by infrun.c calling into: in_solib_dynsym_resolve_code -> svr4_in_dynsym_resolve_code -> in_gnu_ifunc_stub A problem here is that if there's a regular text symbol at the same address as the ifunc symbol, the minimal symbol lookup in in_gnu_ifunc_stub may miss the GNU ifunc symbol: (...) 41: 000000000000071a 53 FUNC GLOBAL DEFAULT 11 gnu_ifunc_resolver (...) 50: 000000000000071a 53 IFUNC GLOBAL DEFAULT 11 gnu_ifunc (...) This causes this FAIL in the tests added later in the series: (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: resolver received HWCAP set step-mode on (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: set step-mode on step 0x00007ffff7bd371a in gnu_ifunc_resolver () from build/gdb/testsuite/outputs/gdb.base/gnu-ifunc/gnu-ifunc-lib-1-0-0.so (gdb) FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=0: final_debug=0: step Above, GDB simply thought that it stepped into a regular function, so it stopped stepping, while it should have continued stepping past the resolver. The fix is to teach minimal symbol lookup to prefer GNU ifunc symbols if desired. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * minsyms.c (lookup_minimal_symbol_by_pc_section_1): Rename to ... (lookup_minimal_symbol_by_pc_section): ... this. Replace 'want_trampoline' parameter by a lookup_msym_prefer parameter. Handle it. (lookup_minimal_symbol_by_pc_section): Delete old implementation. (lookup_minimal_symbol_by_pc): Adjust. (in_gnu_ifunc_stub): Prefer GNU ifunc symbols. (lookup_solib_trampoline_symbol_by_pc): Adjust. * minsyms.h (lookup_msym_prefer): New enum. (lookup_minimal_symbol_by_pc_section): Replace 'want_trampoline' parameter by a lookup_msym_prefer parameter.
2018-04-26For PPC64: elf_gnu_ifunc_record_cache: handle plt symbols in .text sectionPedro Alves2-6/+13
elf_gnu_ifunc_record_cache doesn't ever record anything on PPC64 (tested on gcc110 on the compile farm, CentOS 7.4, ELFv1), because that expects to find PLT symbols in the .plt section, while there we get: (gdb) info symbol 'gnu_ifunc@plt' gnu_ifunc@plt in section .text ^^^^^ I guess that may be related to the comment in ppc-linux-tdep.c that says "For secure PLT, stub is in .text". In any case, this commit fixes the issue by making the function look at the symbol name instead of at the section. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * elfread.c (elf_gnu_ifunc_record_cache): Check if the symbol name ends in "@plt" instead of looking at the symbol's section.
2018-04-26Factor out minsym_found/find_function_start_sal overloadPedro Alves3-41/+37
I need to make the ifunc resolving code in elfread.c skip the target function's prologue like minsym_found does. I thought of factoring that out to a separate function, but turns out there's already a comment in find_function_start_sal that says that should agree with minsym_found... Instead of making sure the code agrees with a comment, factor out the common code to a separate function and use it from both places. Note that the current find_function_start_sal does a bit more than minsym_found's equivalent (the "We always should ..." bit), though that's probably a latent bug. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * linespec.c (minsym_found): Use find_function_start_sal CORE_ADDR overload. * symtab.c (find_function_start_sal(CORE_ADDR, obj_section *,bool)): New, factored out from ... (find_function_start_sal(symbol *, int)): ... this. Reimplement and use bool. * symtab.h (find_function_start_sal(CORE_ADDR, obj_section *,bool)): New. (find_function_start_sal(symbol *, int)): Change boolean parameter type to bool.
2018-04-26Eliminate find_pc_partial_function_gnu_ifuncPedro Alves3-34/+17
Not used anywhere any longer. If this is ever reinstated, note that this case: cache_pc_function_is_gnu_ifunc = TYPE_GNU_IFUNC (SYMBOL_TYPE (f)); was incorrect in that regular symbols never have type marked as GNU ifunc type, only minimal symbols. At some point I had some fix that checking the matching minsym here. But in the end I ended up just eliminating need for this function, so that fix was not necessary. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * blockframe.c (cache_pc_function_is_gnu_ifunc): Delete. Remove all references. (find_pc_partial_function_gnu_ifunc): Rename to ... (find_pc_partial_function): ... this, and remove references to 'is_gnu_ifunc_p'. (find_pc_partial_function): Delete old implementation. * symtab.h (find_pc_partial_function_gnu_ifunc): Delete.
2018-04-26Breakpoints, don't skip prologue of ifunc resolvers with debug infoPedro Alves2-15/+55
Without this patch, some of the tests added to gdb.base/gnu-ifunc.exp by a following patch fail like so: FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: before resolving: break gnu_ifunc FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: before resolving: info breakpoints FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: after resolving: break gnu_ifunc FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: set-break: after resolving: info breakpoints FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: before resolving: break gnu_ifunc FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: before resolving: info breakpoints FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: after resolving: break gnu_ifunc FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=1: set-break: after resolving: info breakpoints All of them trigger iff: - you have debug info for the ifunc resolver. - the resolver and the user-visible symbol have the same name. If you have an ifunc that has a resolver with the same name as the user visible symbol, debug info for the resolver masks out the ifunc minsym. When you set a breakpoint by name on the user visible symbol, GDB finds the DWARF symbol for the resolver, and thinking that it's a regular function, sets a breakpoint location past its prologue. Like so, location 1.2, before the ifunc is resolved by the inferior: (gdb) break gnu_ifunc Breakpoint 2 at 0x7ffff7bd36ea (2 locations) (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x00007ffff7bd36ea <gnu_ifunc> 1.2 y 0x00007ffff7bd36f2 in gnu_ifunc at src/gdb/testsuite/gdb.base/gnu-ifunc-lib.c:34 (gdb) And like so, location 2.2, if you set the breakpoint after the ifunc is resolved by the inferior (to "final"): (gdb) break gnu_ifunc Breakpoint 5 at 0x400757 (2 locations) (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y <MULTIPLE> 2.1 y 0x000000000040075a in final at src/gdb/testsuite/gdb.base/gnu-ifunc-resd.c:21 2.2 y 0x00007ffff7bd36f2 in gnu_ifunc at src/gdb/testsuite/gdb.base/gnu-ifunc-lib.c:34 (gdb) I don't think this is right because when users set a breakpoint at an ifunc, they don't care about debugging the resolver. Instead what you should is a single location for the ifunc in the first case, and a single location of the ifunc target in the second case. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * linespec.c (struct bound_minimal_symbol_search_key): New. (convert_linespec_to_sals): Sort minimal symbols earlier. Don't skip first line if we found a GNU ifunc minimal symbol by name. (compare_msymbols): Change parameters to work with a destructured lhs minsym. (compare_msymbols_for_qsort, compare_msymbols_for_bsearch): New functions.
2018-04-26Fix setting breakpoints on ifunc functions after they're already resolvedPedro Alves5-21/+56
This fixes setting breakpoints on ifunc functions by name after the ifunc has already been resolved. In that case, if you have debug info for the ifunc resolver, without the fix, then gdb puts a breakpoint past the prologue of the resolver, instead of setting a breakpoint at the ifunc target: break gnu_ifunc Breakpoint 4 at 0x7ffff7bd36f2: file src/gdb/testsuite/gdb.base/gnu-ifunc-lib.c, line 34. (gdb) continue Continuing. [Inferior 1 (process 13300) exited normally] (gdb) above we should have stopped at "final", but didn't because we never resolved the ifunc to the final location. If you don't have debug info for the resolver, GDB manages to resolve the ifunc target, but, it should be setting a breakpoint after the prologue of the final function, and instead what you get is that GDB sets a breakpoint on the first address of the target function. With the gnu-ifunc.exp tests added by a later patch, we get, without the fix: (gdb) break gnu_ifunc Breakpoint 4 at 0x400753 (gdb) continue Continuing. Breakpoint 4, final (arg=1) at src/gdb/testsuite/gdb.base/gnu-ifunc-final.c:20 20 { vs, fixed: (gdb) break gnu_ifunc Breakpoint 4 at 0x40075a: file src/gdb/testsuite/gdb.base/gnu-ifunc-final.c, line 21. (gdb) continue Continuing. Breakpoint 4, final (arg=2) at src/gdb/testsuite/gdb.base/gnu-ifunc-final.c:21 21 return arg + 1; (gdb) Fix the problems above by moving the ifunc target resolving to linespec.c, before we skip a function's prologue. We need to save something in the sal, so that set_breakpoint_location_function knows that it needs to create a bp_gnu_ifunc_resolver bp_location. Might as well just save a pointer to the minsym. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * breakpoint.c (set_breakpoint_location_function): Don't resolve ifunc targets here. Instead, if we have an ifunc minsym, use its address/name. (add_location_to_breakpoint): Store the minsym and the objfile in the breakpoint location. * breakpoint.h (bp_location) <msymbol, objfile>: New fields. * linespec.c (minsym_found): Resolve GNU ifunc targets here. Record the minsym in the sal. * symtab.h (symtab_and_line) <msymbol>: New field.
2018-04-26Fix elf_gnu_ifunc_resolve_by_got bugletPedro Alves2-3/+10
The next patch will add a call to elf_gnu_ifunc_resolve_by_got that trips on a latent buglet -- the function is writing to its output parameter even if the address wasn't found, confusing the caller. The function's intro comment says: /* Try to find the target resolved function entry address of a STT_GNU_IFUNC function NAME. If the address is found it is stored to *ADDR_P (if ADDR_P is not NULL) and the function returns 1. It returns 0 otherwise. So fix the function accordingly. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * elfread.c (elf_gnu_ifunc_resolve_by_got): Don't write to *ADDR_P unless we actually resolved the ifunc.
2018-04-26Calling ifunc functions when resolver has debug info, user symbol same namePedro Alves7-8/+70
If the GNU ifunc resolver has the same name as the user visible symbol, and the resolver has debug info, then the DWARF info for the resolver masks the ifunc minsym. In that scenario, if you try calling the ifunc from GDB, you call the resolver instead. With the gnu-ifunc.exp testcase added in a following patch, you'd see: (gdb) p gnu_ifunc (3) $1 = (int (*)(int)) 0x400753 <final> (gdb) FAIL: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=1: resolved_debug=0: p gnu_ifunc (3) ^^^^^^^^^^^^^^^^ That is, we called the ifunc resolver manually, which returned a pointer to the ifunc target function ("final"). The "final" symbol is the function that GDB should have called automatically, ~~~~~~~~~~~~ int final (int arg) { return arg + 1; } ~~~~~~~~~ which is what happens if you don't have debug info for the resolver: (gdb) p gnu_ifunc (3) $1 = 4 (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=0: resolver_debug=0: resolved_debug=1: p gnu_ifunc (3) ^^^^^^^^^^^^^^^^ or if the resolver's symbol has a different name from the ifunc (as is the case with modern uses of ifunc via __attribute__ ifunc, such as glibc uses): (gdb) p gnu_ifunc (3) $1 = 4 (gdb) PASS: gdb.base/gnu-ifunc.exp: resolver_attr=1: resolver_debug=1: resolved_debug=0: p gnu_ifunc (3) ^^^^^^^^^^^^^^^ in which case after this patch, you can still call the resolver directly if you want: (gdb) p gnu_ifunc_resolver (3) $1 = (int (*)(int)) 0x400753 <final> gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * c-exp.y (variable production): Prefer ifunc minsyms over regular function symbols. * symtab.c (find_gnu_ifunc): New function. * minsyms.h (lookup_msym_prefer): New enum. (lookup_minimal_symbol_by_pc_section): Replace 'want_trampoline' parameter by a lookup_msym_prefer parameter. * symtab.h (find_gnu_ifunc): New declaration.
2018-04-26Calling ifunc functions when target has no debug info but resolver hasPedro Alves9-51/+140
After the previous patch, on Fedora 27 (glibc 2.26), if you try calling strlen in the inferior, you now get: (top-gdb) p strlen ("hello") '__strlen_avx2' has unknown return type; cast the call to its declared return type This is correct, because __strlen_avx2 is written in assembly. We can improve on this though -- if the final ifunc resolved/target function has no debug info, but the ifunc _resolver_ does have debug info, we can try extracting the final function's type from the type that the resolver returns. E.g.,: typedef size_t (*strlen_t) (const char*); size_t my_strlen (const char *) { /* some implementation */ } strlen_t strlen_resolver (unsigned long hwcap) { return my_strlen; } extern size_t strlen (const char *s); __typeof (strlen) strlen __attribute__ ((ifunc ("strlen_resolver"))); In the strlen example above, the resolver returns strlen_t, which is a typedef for pointer to a function that returns size_t. "strlen_t" is the type of both the user-visible "strlen", and of the the target function that implements it. This patch teaches GDB to extract that type. This is done for actual inferior function calls (in infcall.c), and for ptype (in eval_call). By the time we get to either of these places, we've already lost the original symbol/minsym, and only have values and types to work with. Hence the changes to c-exp.y and evaluate_var_msym_value, to ensure that we propagate the ifunc minsymbol's info. The change to make ifunc symbols have no/unknown return type exposes a latent problem -- gdb.compile/compile-ifunc.exp calls a no-debug-info function, but we did not warn about it. The test is fixed by this commit too. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * blockframe.c (find_gnu_ifunc_target_type): New function. (find_function_type): New. * eval.c (evaluate_var_msym_value): For GNU ifunc types, always return a value with a memory address. (eval_call): For calls to GNU ifunc functions, try to find the type of the target function from the type that the resolver returns. * gdbtypes.c (objfile_type): Don't install a return type for ifunc symbols. * infcall.c (find_function_return_type): Delete. (find_function_addr): Add 'function_type' parameter. For calls to GNU ifunc functions, try to find the type of the target function from the type that the resolver returns, and return it via FUNCTION_TYPE. (call_function_by_hand_dummy): Adjust to use the function type returned by find_function_addr. (find_function_addr): Add 'function_type' parameter and move description here. * symtab.h (find_function_type, find_gnu_ifunc_target_type): New declarations. gdb/testsuite/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * gdb.compile/compile-ifunc.exp: Also expect "function has unknown return type" warnings.
2018-04-26Fix calling ifunc functions when resolver has debug info and different namePedro Alves2-1/+8
Currently, on Fedora 27 (glibc 2.26), if you try to call strlen in the inferior you get: (gdb) p strlen ("hello") $1 = (size_t (*)(const char *)) 0x7ffff554aac0 <__strlen_avx2> strlen is an ifunc function, and what we see above is the result of calling the ifunc resolver in the inferior. That returns a pointer to the actual target function that implements strlen on my machine. GDB should have turned around and called the resolver automatically without the user noticing. This is was caused by commit: commit bf223d3e808e6fec9ee165d3d48beb74837796de Date: Mon Aug 21 11:34:32 2017 +0100 Handle function aliases better (PR gdb/19487, errno printing) which added the find_function_alias_target call to c-exp.y, to try to find an alias with debug info for a minsym. For ifunc symbols, that finds the ifunc's resolver if it has debug info (in the example it's called "strlen_ifunc"), with the result that GDB calls that as a regular function. After this commit, we get now get: (top-gdb) p strlen ("hello") '__strlen_avx2' has unknown return type; cast the call to its declared return type Which is correct, because __strlen_avx2 is written in assembly. That'll be improved in a following patch, though. gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * c-exp.y (variable production): Skip finding an alias for ifunc symbols.
2018-04-26Fix breakpoints in ifunc after inferior resolved it (@got.plt symbol creation)Pedro Alves2-17/+44
Setting a breakpoint on an ifunc symbol after the ifunc has already been resolved by the inferior should result in creating a breakpoint location at the ifunc target. However, that's not what happens on current Fedora: (gdb) n 53 i = gnu_ifunc (1); /* break-at-call */ (gdb) 54 assert (i == 2); (gdb) b gnu_ifunc Breakpoint 2 at gnu-indirect-function resolver at 0x7ffff7bd36ee (gdb) info breakpoints Num Type Disp Enb Address What 2 STT_GNU_IFUNC resolver keep y 0x00007ffff7bd36ee <gnu_ifunc+4> The problem is that elf_gnu_ifunc_resolve_by_got never manages to resolve an ifunc target. The reason is that GDB never actually creates the internal got.plt symbols: (gdb) p 'gnu_ifunc@got.plt' No symbol "gnu_ifunc@got.plt" in current context. and this is because GDB expects that rela.plt has relocations for .plt, while it actually has relocations for .got.plt: Relocation section [10] '.rela.plt' for section [22] '.got.plt' at offset 0x570 contains 2 entries: Offset Type Value Addend Name 0x0000000000601018 X86_64_JUMP_SLOT 000000000000000000 +0 __assert_fail 0x0000000000601020 X86_64_JUMP_SLOT 000000000000000000 +0 gnu_ifunc Using an older system on the GCC compile farm (machine gcc15, an x86-64 running Debian 6.0.8, with GNU ld 2.20.1), we see that it used to be that we'd get a .rela.plt section for .plt: Relocation section [ 9] '.rela.plt' for section [11] '.plt' at offset 0x578 contains 3 entries: Offset Type Value Addend Name 0x0000000000600cc0 X86_64_JUMP_SLOT 000000000000000000 +0 __assert_fail 0x0000000000600cc8 X86_64_JUMP_SLOT 000000000000000000 +0 __libc_start_main 0x0000000000600cd0 X86_64_JUMP_SLOT 000000000000000000 +0 gnu_ifunc Those offsets did point into .got.plt, as seen with objdump -h: 20 .got.plt 00000030 0000000000600ca8 0000000000600ca8 00000ca8 2**3 CONTENTS, ALLOC, LOAD, DATA I also tested on gcc110 on the compile farm (PPC64 running CentOS 7.4.1708, with GNU ld 2.25.1), and there we see instead: Relocation section [ 9] '.rela.plt' for section [23] '.plt' at offset 0x5d0 contains 4 entries: Offset Type Value Addend Name 0x0000000010020148 PPC64_JMP_SLOT 000000000000000000 +0 __libc_start_main 0x0000000010020160 PPC64_JMP_SLOT 000000000000000000 +0 __gmon_start__ 0x0000000010020178 PPC64_JMP_SLOT 000000000000000000 +0 __assert_fail 0x0000000010020190 PPC64_JMP_SLOT 000000000000000000 +0 gnu_ifunc But note that those offsets point into .plt, not .got.plt, as seen with objdump -h: 22 .plt 00000078 0000000010020130 0000000010020130 00010130 2**3 ALLOC This commit makes us support all the different combinations above. With that addressed, we now get: (gdb) p 'gnu_ifunc@got.plt' $1 = (<text from jump slot in .got.plt, no debug info>) 0x400753 <final> And setting a breakpoint on the ifunc finds the ifunc target: (gdb) b gnu_ifunc Breakpoint 2 at 0x400753 (gdb) info breakpoints Num Type Disp Enb Address What 2 breakpoint keep y 0x0000000000400753 <final> gdb/ChangeLog: 2018-04-26 Pedro Alves <palves@redhat.com> * elfread.c (elf_rel_plt_read): Look for relocations for .got.plt too.
2018-04-26x86: fold various non-memory operand AVX512VL templatesJan Beulich5-2045/+631
There's little point carrying up to three templates per insn flavor when the sole difference is operand size and the dependency on AVX512VL being enabled. Instead the need for AVX512VL can be derived from an operand allowing for ZMMword as well as one or both or XMMword and YMMword (irrespective of whether this is a register or memory operand). Without further abstraction to deal with the different Disp8MemShift values between the templates, only a limited set (mostly ones only allowing for non-memory operands) can be folded, which is being done here. Also drop IgnoreSize wherever possible from anything that's being touched anyway.
2018-04-26x86: also optimize zeroing-masking variants of insnsJan Beulich8-73/+84
When zeroing an element of a register it doesn't matter whether the zero results from the actual operation (xor, sub, or nand) or from the zeroing-masking taking effect due to a clear mask register bit.
2018-04-26x86: properly force / avoid forcing EVEX encodingJan Beulich7-7/+76
Pseudo prefixes are supposed to be a hint only - when the specific encoding can't be used to encode an insn, silently override it. But this overriding must only happen after the respective check, to avoid forcing EVEX encoding because of something that isn't a valid register name in the given context.
2018-04-26x86: CpuXSAVE is a prereq for various other featuresJan Beulich7-31/+95
All of AVX, LWP, MPX, and PKU require XSAVE, and hence it as well as XRSTOR should be enabled when enabling these ISA extensions. Leverage these implications to shorten some of the cpu_flag_init[] entries.
2018-04-26x86: drop CpuRegMMX, CpuReg[XYZ]MM, and CpuRegMaskJan Beulich12-5231/+5322
It's not clear to me why they had been introduced - the respective comments in opcodes/i386-gen.c are certainly wrong: ymm<N> registers are very well supported (and necessary) with just AVX512F.
2018-04-26x86: don't recognize bnd<N> as registers without CpuMPXJan Beulich5-0/+29
This is just like for all other extended/optional register sets.
2018-04-26x86: x87-related adjustmentsJan Beulich10-30/+85
Neither 287 wrt 8087 nor 387 wrt 287 are proper supersets - in each case some insns get removed from the ISA (they become NOPs, but code intended for newer co-processors should not use them). Furthermore with .no87, ST should not be recognized as a register name.
2018-04-26x86: fix indentation in build_modrm_byte()Jan Beulich2-39/+43
The VEX3SOURCES code was (originally) written with just space indentation, which is not in line with general coding style as well as the style later in the function.
2018-04-26x86: move and fold common code in build_modrm_byte()Jan Beulich2-29/+18
The source and reg_slot calculations in the VEX3SOURCES only depend on the number of immediate operands.
2018-04-26x86: drop VexImmExtJan Beulich7-8082/+8086
It's only used in assertions, and hence not really needed for correct code generation.