Commit Graph

93313 Commits

Author SHA1 Message Date
Maciej W. Rozycki 87993319a5 WebAssembly: Correct an `index' global shadowing error for pre-4.8 GCC
Remove `-Wshadow' compilation errors:

cc1: warnings being treated as errors
.../bfd/wasm-module.c: In function 'wasm_scan_name_function_section':
.../bfd/wasm-module.c:312: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
.../bfd/wasm-module.c: In function 'wasm_register_section':
.../bfd/wasm-module.c:494: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
.../bfd/wasm-module.c: In function 'wasm_compute_custom_section_file_position':
.../bfd/wasm-module.c:523: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here

and:

cc1: warnings being treated as errors
.../opcodes/wasm32-dis.c: In function 'print_insn_wasm32':
.../opcodes/wasm32-dis.c:272: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
make[4]: *** [wasm32-dis.lo] Error 1

which for versions of GCC before 4.8 prevent support for the WebAssembly
target from being built.  See also GCC PR c/53066.

	bfd/
	* wasm-module.c (wasm_scan_name_function_section): Rename
	`index' local variable to `idx'.

	opcodes/
	* wasm32-dis.c (print_insn_wasm32): Rename `index' local
	variable to `function_index'.
2018-02-13 12:56:29 +00:00
Maciej W. Rozycki 30147392ca MIPS/GAS/testsuite: Correct duplicate `Loongson-3A tests' test name
Correct a duplicate `Loongson-3A tests' GAS test name introduced with
commit 9867540240 ("Add Loongson3A specific instructions"),
<https://sourceware.org/ml/binutils/2010-12/msg00447.html>, shared
between gas/testsuite/gas/mips/loongson-3a.d and
gas/testsuite/gas/mips/loongson-3a-2.d.

	gas/
	* testsuite/gas/mips/loongson-3a-2.d: Rename test.
2018-02-13 12:56:29 +00:00
Alan Modra 6e5e9d58c1 PR22836, "-r -s" doesn't work with -g3 using GCC 7
This fixes the case where all of a group is removed with ld -r, the
situation in the PR, and failures where part of a group is removed
that contain relocs.

bfd/
	PR 22836
	* elf.c (_bfd_elf_fixup_group_sections): Account for removed
	relocation sections.  If size reduces to just the flag word,
	remove that too and mark with SEC_EXCLUDE.
	* elflink.c (bfd_elf_final_link): Strip empty group sections.
binutils/
	* testsuite/binutils-all/group-7.s,
	* testsuite/binutils-all/group-7a.d,
	* testsuite/binutils-all/group-7b.d,
	* testsuite/binutils-all/group-7c.d: New tests.
	* testsuite/binutils-all/objcopy.exp: Run them.
ld/
	* testsuite/ld-elf/pr22836-2.d,
	* testsuite/ld-elf/pr22836-2.s: New test.
2018-02-13 22:55:49 +10:30
Alan Modra f2731e0c37 PR22829, objcopy/strip removes PT_GNU_RELRO from lld binaries
lld lays out the relro segment differently to GNU ld, not bothering to
include the first few bytes of .got.plt and padding out to a page at
the end of the segment.  This patch teaches binutils to recognize the
different (and somewhat inferior) layout as valid.

bfd/
	PR 22829
	* elf.c (assign_file_positions_for_non_load_sections): Rewrite
	PT_GNU_RELRO setup.
ld/
	* testsuite/ld-x86-64/pr14207.d: Adjust relro p_filesz.
2018-02-13 19:30:47 +10:30
Simon Marchi 387cd15b93 Fix prefix of maint set/show per-command
I noticed this:

(gdb) apropos per-command
maintenance set per-command -- Per-command statistics settings
set per-command space -- Set whether to display per-command space usage
set per-command symtab -- Set whether to display per-command symtab statistics
set per-command time -- Set whether to display per-command execution time
maintenance show per-command -- Show per-command statistics settings
show per-command space -- Show whether to display per-command space usage
show per-command symtab -- Show whether to display per-command symtab statistics
show per-command time -- Show whether to display per-command execution time

The subcommands of "maintenance set per-command" are missing the
maintenance keyword.  This is because that command is registered with
the wrong prefix.  This patch fixes that.

gdb/ChangeLog:

	* maint.c (_initialize_maint_cmds): Fix prefix of maint set/show
	per-command.
2018-02-13 00:33:04 -05:00
GDB Administrator 0f3f3a55b5 Automatic date update in version.in 2018-02-13 00:00:35 +00:00
Andrew Burgess b303c6f688 gdb: Remove cleanup from dw2_do_instantiate_symtab
When running the test gdb.dwarf2/dw2-bad-parameter-type.exp under
valgrind, I see the following issue reported (on x86-64 Fedora):

  (gdb) ptype f
  ==5203== Invalid read of size 1
  ==5203==    at 0x6931FE: process_die_scope::~process_die_scope() (dwarf2read.c:10642)
  ==5203==    by 0x66818F: process_die(die_info*, dwarf2_cu*) (dwarf2read.c:10664)
  ==5203==    by 0x66A01F: read_file_scope(die_info*, dwarf2_cu*) (dwarf2read.c:11650)
  ==5203==    by 0x667F2D: process_die(die_info*, dwarf2_cu*) (dwarf2read.c:10672)
  ==5203==    by 0x6677B6: process_full_comp_unit(dwarf2_per_cu_data*, language) (dwarf2read.c:10445)
  ==5203==    by 0x66657A: process_queue(dwarf2_per_objfile*) (dwarf2read.c:9945)
  ==5203==    by 0x6559B4: dw2_do_instantiate_symtab(dwarf2_per_cu_data*) (dwarf2read.c:3163)
  ==5203==    by 0x66683D: psymtab_to_symtab_1(partial_symtab*) (dwarf2read.c:10034)
  ==5203==    by 0x66622A: dwarf2_read_symtab(partial_symtab*, objfile*) (dwarf2read.c:9811)
  ==5203==    by 0x787984: psymtab_to_symtab(objfile*, partial_symtab*) (psymtab.c:792)
  ==5203==    by 0x786E3E: psym_lookup_symbol(objfile*, int, char const*, domain_enum_tag) (psymtab.c:522)
  ==5203==    by 0x804BD0: lookup_symbol_via_quick_fns(objfile*, int, char const*, domain_enum_tag) (symtab.c:2383)
  ==5203==  Address 0x147ed063 is 291 bytes inside a block of size 4,064 free'd
  ==5203==    at 0x4C2CD5A: free (vg_replace_malloc.c:530)
  ==5203==    by 0x444415: void xfree<void>(void*) (common-utils.h:60)
  ==5203==    by 0x9DA8C2: call_freefun (obstack.c:103)
  ==5203==    by 0x9DAD35: _obstack_free (obstack.c:280)
  ==5203==    by 0x44464C: auto_obstack::~auto_obstack() (gdb_obstack.h:73)
  ==5203==    by 0x68AFB0: dwarf2_cu::~dwarf2_cu() (dwarf2read.c:25080)
  ==5203==    by 0x68B204: free_one_cached_comp_unit(dwarf2_per_cu_data*) (dwarf2read.c:25174)
  ==5203==    by 0x66668C: dwarf2_release_queue(void*) (dwarf2read.c:9982)
  ==5203==    by 0x563A4C: do_my_cleanups(cleanup**, cleanup*) (cleanups.c:154)
  ==5203==    by 0x563AA7: do_cleanups(cleanup*) (cleanups.c:176)
  ==5203==    by 0x5646CE: throw_exception_cxx(gdb_exception) (common-exceptions.c:289)
  ==5203==    by 0x5647B7: throw_exception(gdb_exception) (common-exceptions.c:317)
  ==5203==  Block was alloc'd at
  ==5203==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
  ==5203==    by 0x564BE8: xmalloc (common-utils.c:44)
  ==5203==    by 0x9DA872: call_chunkfun (obstack.c:94)
  ==5203==    by 0x9DA935: _obstack_begin_worker (obstack.c:141)
  ==5203==    by 0x9DAA3C: _obstack_begin (obstack.c:164)
  ==5203==    by 0x4445E0: auto_obstack::auto_obstack() (gdb_obstack.h:70)
  ==5203==    by 0x68AE07: dwarf2_cu::dwarf2_cu(dwarf2_per_cu_data*) (dwarf2read.c:25073)
  ==5203==    by 0x661A8A: init_cutu_and_read_dies(dwarf2_per_cu_data*, abbrev_table*, int, int, void (*)(die_reader_specs const*, unsigned char const*, die_info*, int, void*), void*) (dwarf2read.c:7869)
  ==5203==    by 0x666A29: load_full_comp_unit(dwarf2_per_cu_data*, language) (dwarf2read.c:10108)
  ==5203==    by 0x655847: load_cu(dwarf2_per_cu_data*) (dwarf2read.c:3120)
  ==5203==    by 0x655928: dw2_do_instantiate_symtab(dwarf2_per_cu_data*) (dwarf2read.c:3148)
  ==5203==    by 0x66683D: psymtab_to_symtab_1(partial_symtab*) (dwarf2read.c:10034)

There's actually a series of three issues reported, but it turns out
they're all related, so we can consider on the first one.

The invalid read is triggered from a destructor which is being invoked
as part of a stack unwind after throwing an error.  At the time the
error is thrown, the stack looks like this:

    #0  0x00000000009f4ecd in __cxa_throw ()
    #1  0x0000000000564761 in throw_exception_cxx (exception=...) at ../../src/gdb/common/common-exceptions.c:303
    #2  0x00000000005647b8 in throw_exception (exception=...) at ../../src/gdb/common/common-exceptions.c:317
    #3  0x00000000005648ff in throw_it(return_reason, errors, const char *, typedef __va_list_tag __va_list_tag *) (reason=RETURN_ERROR,
        error=GENERIC_ERROR, fmt=0xb33020 "Dwarf Error: Cannot find DIE at 0x%x referenced from DIE at 0x%x [in module %s]",
        ap=0x7fff387f2d68) at ../../src/gdb/common/common-exceptions.c:373
    #4  0x0000000000564929 in throw_verror (error=GENERIC_ERROR,
        fmt=0xb33020 "Dwarf Error: Cannot find DIE at 0x%x referenced from DIE at 0x%x [in module %s]", ap=0x7fff387f2d68)
        at ../../src/gdb/common/common-exceptions.c:379
    #5  0x0000000000867be4 in verror (string=0xb33020 "Dwarf Error: Cannot find DIE at 0x%x referenced from DIE at 0x%x [in module %s]",
        args=0x7fff387f2d68) at ../../src/gdb/utils.c:251
    #6  0x000000000056879d in error (fmt=0xb33020 "Dwarf Error: Cannot find DIE at 0x%x referenced from DIE at 0x%x [in module %s]")
        at ../../src/gdb/common/errors.c:43
    #7  0x0000000000686875 in follow_die_ref (src_die=0x30bc8a0, attr=0x30bc8c8, ref_cu=0x7fff387f2ed0) at ../../src/gdb/dwarf2read.c:22969
    #8  0x00000000006844cd in lookup_die_type (die=0x30bc8a0, attr=0x30bc8c8, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:21976
    #9  0x0000000000683f27 in die_type (die=0x30bc8a0, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:21832
    #10 0x0000000000679b39 in read_subroutine_type (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:17343
    #11 0x00000000006845fb in read_type_die_1 (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:22035
    #12 0x0000000000684576 in read_type_die (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:22010
    #13 0x000000000067003f in read_func_scope (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:13822
    #14 0x0000000000667f5e in process_die (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:10679
    #15 0x000000000066a020 in read_file_scope (die=0x30bc720, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:11650
    #16 0x0000000000667f2e in process_die (die=0x30bc720, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:10672
    #17 0x00000000006677b7 in process_full_comp_unit (per_cu=0x3089b80, pretend_language=language_minimal)
        at ../../src/gdb/dwarf2read.c:10445
    #18 0x000000000066657b in process_queue (dwarf2_per_objfile=0x30897d0) at ../../src/gdb/dwarf2read.c:9945
    #19 0x00000000006559b5 in dw2_do_instantiate_symtab (per_cu=0x3089b80) at ../../src/gdb/dwarf2read.c:3163
    #20 0x000000000066683e in psymtab_to_symtab_1 (pst=0x3089bd0) at ../../src/gdb/dwarf2read.c:10034
    #21 0x000000000066622b in dwarf2_read_symtab (self=0x3089bd0, objfile=0x3073f40) at ../../src/gdb/dwarf2read.c:9811
    #22 0x0000000000787985 in psymtab_to_symtab (objfile=0x3073f40, pst=0x3089bd0) at ../../src/gdb/psymtab.c:792
    #23 0x0000000000786e3f in psym_lookup_symbol (objfile=0x3073f40, block_index=1, name=0x30b2e30 "f", domain=VAR_DOMAIN)
        at ../../src/gdb/psymtab.c:522
    #24 0x0000000000804bd1 in lookup_symbol_via_quick_fns (objfile=0x3073f40, block_index=1, name=0x30b2e30 "f", domain=VAR_DOMAIN)
        at ../../src/gdb/symtab.c:2383
    #25 0x0000000000804fe4 in lookup_symbol_in_objfile (objfile=0x3073f40, block_index=1, name=0x30b2e30 "f", domain=VAR_DOMAIN)
        at ../../src/gdb/symtab.c:2558
    #26 0x0000000000805125 in lookup_static_symbol (name=0x30b2e30 "f", domain=VAR_DOMAIN) at ../../src/gdb/symtab.c:2595
    #27 0x0000000000804357 in lookup_symbol_aux (name=0x30b2e30 "f", match_type=symbol_name_match_type::FULL, block=0x0,
        domain=VAR_DOMAIN, language=language_c, is_a_field_of_this=0x0) at ../../src/gdb/symtab.c:2105
    #28 0x0000000000803ad9 in lookup_symbol_in_language (name=0x30b2e30 "f", block=0x0, domain=VAR_DOMAIN, lang=language_c,
        is_a_field_of_this=0x0) at ../../src/gdb/symtab.c:1887
    #29 0x0000000000803b53 in lookup_symbol (name=0x30b2e30 "f", block=0x0, domain=VAR_DOMAIN, is_a_field_of_this=0x0)
        at ../../src/gdb/symtab.c:1899
    #30 0x000000000053b246 in classify_name (par_state=0x7fff387f6090, block=0x0, is_quoted_name=false, is_after_structop=false)
        at ../../src/gdb/c-exp.y:2879
    #31 0x000000000053b7e9 in c_yylex () at ../../src/gdb/c-exp.y:3083
    #32 0x000000000053414a in c_yyparse () at c-exp.c:1903
    #33 0x000000000053c2e7 in c_parse (par_state=0x7fff387f6090) at ../../src/gdb/c-exp.y:3255
    #34 0x0000000000774a02 in parse_exp_in_context_1 (stringptr=0x7fff387f61c0, pc=0, block=0x0, comma=0, void_context_p=0, out_subexp=0x0)
        at ../../src/gdb/parse.c:1213
    #35 0x000000000077476a in parse_exp_in_context (stringptr=0x7fff387f61c0, pc=0, block=0x0, comma=0, void_context_p=0, out_subexp=0x0)
        at ../../src/gdb/parse.c:1115
    #36 0x0000000000774714 in parse_exp_1 (stringptr=0x7fff387f61c0, pc=0, block=0x0, comma=0) at ../../src/gdb/parse.c:1106
    #37 0x0000000000774c53 in parse_expression (string=0x27ff996 "f") at ../../src/gdb/parse.c:1253
    #38 0x0000000000861dc4 in whatis_exp (exp=0x27ff996 "f", show=1) at ../../src/gdb/typeprint.c:472
    #39 0x00000000008620d8 in ptype_command (type_name=0x27ff996 "f", from_tty=1) at ../../src/gdb/typeprint.c:561
    #40 0x000000000047430b in do_const_cfunc (c=0x3012010, args=0x27ff996 "f", from_tty=1) at ../../src/gdb/cli/cli-decode.c:106
    #41 0x000000000047715e in cmd_func (cmd=0x3012010, args=0x27ff996 "f", from_tty=1) at ../../src/gdb/cli/cli-decode.c:1886
    #42 0x00000000008431bb in execute_command (p=0x27ff996 "f", from_tty=1) at ../../src/gdb/top.c:630
    #43 0x00000000006bf946 in command_handler (command=0x27ff990 "ptype f") at ../../src/gdb/event-top.c:583
    #44 0x00000000006bfd12 in command_line_handler (rl=0x30bb3a0 "\240\305\v\003") at ../../src/gdb/event-top.c:774

The problem is that in `process_die` (frames 14 and 16) we create a
`process_die_scope` object, that takes a copy of the `struct
dwarf2_cu *` passed into the frame.  The destructor of the
`process_die_scope` dereferences the stored pointer.  This wouldn't be
an issue, except...

... in dw2_do_instantiate_symtab (frame 19) a clean up was registered that
clears the dwarf2_queue in case of an error.  Part of this clean up
involves deleting the `struct dwarf2_cu`s referenced from the queue..

The problem then, is that cleanups are processed at the site of the
throw, while, class destructors are invoked as we unwind their frame.
The result is that we process the frame 19 cleanup (and delete the
struct dwarf2_cu) before we process the destructors in frames 14 and 16.
When we do get back to frames 14 and 16 the objects being references
have already been deleted.

The solution is to remove the cleanup from dw2_do_instantiate_symtab, and
instead use a destructor to release the dwarf2_queue instead.  With this
patch in place, the valgrind errors are now resolved.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_release_queue): Delete function, move body
	into...
	(class dwarf2_queue_guard): ...the destructor of this new class.
	(dw2_do_instantiate_symtab): Create instance of the new class
	dwarf2_queue_guard, remove cleanup.
2018-02-12 21:43:45 +00:00
Maciej W. Rozycki 12a43565ad MIPS/GAS/test: Fix an n32 `.reginfo' size test failure
Correct a commit 2d6dda7161 ("MIPS/BFD: Correctly report unsupported
`.reginfo' section size") issue and avoid a GAS test failure:

regexp_diff match failure
regexp "^.*: Incorrect `\.reginfo' section size; expected 24, got 28$"
line   "../as-new: dump.o: Incorrect `.reginfo' section size; expected 24, got 32"
FAIL: MIPS assembled .reginfo section size (n32)

on MIPS targets other than bare-metal ones.  The reason for this failure
is section padding to alignment, done in `size_seg'.  For n32 `.reginfo'
the section alignment is set to 3, and therefore the section is padded
to a multiple of 8, except for bare-metal targets, for which padding is
unconditionally disabled in `md_section_align'.

Use `--no-pad-sections' then to disable padding for all targets, so that
the size of `.reginfo' is always the same, matching the message pattern.

	gas/
	* testsuite/gas/mips/reginfo-2-n32.d: Add `--no-pad-sections' to
	`as' flags.
2018-02-12 16:04:05 +00:00
Henry Wong d2159fdc0f MIPS: Fix encoding for MIPSr6 sigrie instruction.
The instruction encoding for the MIPS r6 sigrie instruction seems to be
incorrect.  It's currently 0x4170xxxx (which overlaps with ei, di, evp,
and dvp), but should be 0x0417xxxx.  See ISA reference[1][2].

References:

[1] "MIPS Architecture for Programmers Volume II-A: The MIPS32
    Instruction Set Manual", Imagination Technologies, Inc., Document
    Number: MD00086, Revision 6.06, December 15, 2016, Table A.4 "MIPS32
    REGIMM Encoding of rt Field", p. 452

[2] "MIPS Architecture For Programmers Volume II-A: The MIPS64
    Instruction Set Reference Manual", Imagination Technologies, Inc.,
    Document Number: MD00087, Revision 6.06, December 15, 2016, Table
    A.4 "MIPS64 REGIMM Encoding of rt Field", p. 581

	opcodes/
	* mips-opc.c (mips_builtin_opcodes): Correct "sigrie" encoding.

	gas/
	* testsuite/gas/mips/r6.d: Update for "sigrie" encoding fix.
	* testsuite/gas/mips/r6-n32.d: Likewise.
	* testsuite/gas/mips/r6-n64.d: Likewise.
2018-02-12 14:50:42 +00:00
Zebediah Figura 830db0485e Add support for reading msdos MZ executables.
See email thread starting here:  https://www.sourceware.org/ml/binutils/2018-01/msg00001.html

include	* coff/msdos.h: New header.
	* coff/pe.h: Move common defines to msdos.h.
	* coff/powerpc.h: Likewise.

bfd	* i386msdos.c (msdos_mkobject); New function.
	(msdos_object_p): New function.
	(i386_msdos_vec): Use msdos_object_p as the check_format
	function.
	* peicode.h: Rename external_PEI_DOS_hdr, DOSMAGIC, and
	NT_SIGNATURE to external_DOS_hdr, IMAGE_DOS_SIGNATURE, and
	IMAGE_NT_SIGNATURE.
	* peXXigen.c: Likewise.
	* coff-ia64.c: Likewise.
2018-02-12 13:15:56 +00:00
Nick Clifton 7e784da543 Update Russian translation for the gas/ sub-directory. 2018-02-12 12:10:50 +00:00
Nick Clifton 0b8683b7eb Fix compile time warning: bfd/elf32-arc.c:1537]: (warning) Redundant assignment of 'rel->r_offset' to itself.
* elf32-arc.c (elf_arc_relocate_section):  Remove redundant
	assignment.
2018-02-12 11:57:41 +00:00
Nick Clifton 6444b19b24 oops - actually remove the assignment this time: bfd/elf32-nds32.c:9693]: (warning) Redundant assignment of 'irel->r_addend' to itself. 2018-02-12 11:54:48 +00:00
Nick Clifton 94fe5757db Fix compile time warning: bfd/elf32-nds32.c:9693]: (warning) Redundant assignment of 'irel->r_addend' to itself.
* elf32-nds32.c (nds32_elf_relax_longjump3): Remove redundant
	assignment.
2018-02-12 11:51:56 +00:00
GDB Administrator 7eb84119d8 Automatic date update in version.in 2018-02-12 00:00:35 +00:00
GDB Administrator e5bc5e207b Automatic date update in version.in 2018-02-11 00:01:01 +00:00
Eric Botcazou d805612e38 Fix commit date. 2018-02-10 02:37:32 +01:00
Eric Botcazou a8735c82b8 Fix GOT relocation overflow on SPARC.
There are 2 failures left in the linker testsuite on SPARC64/Linux and
they are caused by 2 different issues leading to the same end effect:
the overflow of the relocation section for the GOT, i.e. the linker
generates too many dynamic relocations for the GOT wrt the size of the
relocation section, leading to memory corruption and missing relocations
in the final binary.

The first issue was introduced by:
  https://sourceware.org/ml/binutils/2017-06/msg00368.html
which makes the linker generate more R_SPARC_RELATIVE relocations for
the GOT without adjusting the size of the relocation section.  This is
fixed by (1) preventively adjusting this size in allocate_dynrelocs and
(2) generating R_SPARC_NONE if needed when R_SPARC_GOTDATA_OP is relaxed.

The second issue is that we generate a GOT relocation for an undefined
weak symbol with non-default visibility in a PIC binary without accounting
for that  in the size of the relocation section.  Since the address of the
symbol should resolve to 0 at run time, it is fixed by not generating the
relocation at all, i.e. leaving the GOT entry zeroed.

bfd/
	* elfxx-sparc.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Reorder conditions.
	(sparc_elf_append_rela): Assert that there is enough room in section.
	(_bfd_sparc_elf_copy_indirect_symbol): Fix formatting.
	(_bfd_sparc_elf_adjust_dynamic_symbol): Minor tweak.
	(allocate_dynrelocs): Remove outdated comments and reorder conditions.
	For a symbol subject to a GOT relocation, reserve a slot in the
	relocation section if the symbol isn't dynamic and we are in PIC mode.
	(_bfd_sparc_elf_relocate_section) <R_SPARC_GOTDATA_OP>: If relocation
	is relaxed and a slot was reserved, generate a R_SPARC_NONE relocation.
	<R_SPARC_GOTDATA_OP_HIX22>: Adjust comments.
	<R_SPARC_PC10>: Reorder conditions.  Remove always-false assertion.
	(_bfd_sparc_elf_finish_dynamic_symbol): Rename local_undefweak into
	resolved_to_zero.  Do not generate a dynamic GOT relocation for an
	undefined weak symbol with non-default visibility.  Remove superfluous
	'else' and fix formatting.
2018-02-10 02:30:25 +01:00
GDB Administrator 5d0fb5ffdf Automatic date update in version.in 2018-02-10 00:00:34 +00:00
H.J. Lu 3b4c384407 x86: Add is_solaris to elf_x86_target_os
Add is_solaris to elf_x86_target_os since Solaris is quite different.

	* elf32-i386.c (elf_i386_get_synthetic_symtab): Also handle
	is_solaris.
	(i386_elf32_sol2_vec): Don't declare.
	(elf_i386_link_setup_gnu_properties): Also handle is_solaris.
	Don't set need_global_offset_table.
	(elf_i386_solaris_arch_bed): New.
	(elf_backend_arch_data): Set to elf_i386_solaris_arch_bed for
	Solaris.
	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Check
	target_os != is_nacl instead of target_os == is_normal.
	(x86_64_elf64_sol2_vec): Don't declare.
	(elf_x86_64_link_setup_gnu_properties): Check target_os !=
	is_nacl instead of target_os == is_normal.  Don't set
	need_global_offset_table.
	(elf_x86_64_solaris_arch_bed): New.
	(elf_backend_arch_data): Set to elf_x86_64_solaris_arch_bed for
	Solaris.
	* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Keep
	_GLOBAL_OFFSET_TABLE_ for Solaris.
	(_bfd_x86_elf_link_setup_gnu_properties): Don't copy
	need_global_offset_table.
	* elfxx-x86.h (elf_x86_target_os): Add is_solaris.
	(elf_x86_link_hash_table): Remove need_global_offset_table.
	(elf_x86_init_table): Likewise.
2018-02-09 08:45:07 -08:00
Tom Tromey 9c3630e983 Don't reference past the end of the vector
An earlier change made find_source_lines read:

    end = &data[size];

However, since 'size' is the size of the vector, this seems fishy.
More obviously ok is to compute the end of the data directly:

    end = data.data () + size;

2018-02-09  Tom Tromey  <tom@tromey.com>

	* source.c (find_source_lines): Don't reference past the end of
	the vector.
2018-02-09 06:46:11 -07:00
Markus Metzger c4e1263132 btrace: reword error messages
Reword some btrace error messages to align with the format discussed in
https://sourceware.org/ml/gdb-patches/2018-02/msg00135.html.

gdb/
	* remote.c (remote_btrace_maybe_reopen): Change error message.
	* btrace.c (btrace_enable): Likewise.
	(parse_xml_btrace): Likewise.
	(parse_xml_btrace_conf): Likewise.

testsuite/
	* lib/gdb.exp (skip_btrace_pt_tests): Update expected error message.
	Fix test name.
2018-02-09 14:03:22 +01:00
Markus Metzger 88711fbfea btrace: check perf_event_paranoid
One recurring error on Debian systems is that the default perf_event_paranoid
setting disables the perf_event interface for user-space.

Check the current level and point the user to the file.

gdb/
	* nat/linux-btrace.c (diagnose_perf_event_open_fail): New.
	(linux_enable_pt, linux_enable_bts): Call
	diagnose_perf_event_open_fail.
2018-02-09 14:03:21 +01:00
Markus Metzger 17ad2a4f46 btrace: improve enable error messages
Improve the error message when GDB fails to start recording branch trace.

This patch also removes a zero buffer size check for PT to align with BTS.  The
buffer size can not be configured to be zero.

gdb/
	* nat/linux-btrace.c (perf_event_pt_event_type): Improve error message.
	Remove parameter and change return type.  Update callers.  Move it.
	(linux_enable_bts, linux_enable_pt): Improve error message.
	(linux_enable_pt): Remove zero buffer size check.
	(linux_enable_btrace): Improve error messages.  Remove NULL return
	check.
2018-02-09 14:03:20 +01:00
Markus Metzger de6242d307 btrace, gdbserver: remove the to_supports_btrace target method
Remove the to_supports_btrace target method and instead rely on detecting errors
when trying to enable recording.  This will also provide a suitable error
message explaining why recording is not possible.

For remote debugging, gdbserver will now always advertise branch tracing related
packets.  When talking to an older GDB, this will cause GDB to try to enable
branch tracing and gdbserver to report a suitable error message every time.

An older gdbserver will not advertise branch tracing related packets if the
one-time check failed, so a newer GDB with this patch will fail to enable branch
tracing at remote_enable_btrace() rather than at btrace_enable().  The error
message is the same in both cases so there should be no user-visible change.

gdb/
	* btrace.c (btrace_enable): Remove target_supports_btrace call.
	* nat/linux-btrace.c (perf_event_pt_event_type): Move.
	(kernel_supports_bts, kernel_supports_pt, linux_supports_bts)
	(linux_supports_pt, linux_supports_btrace): Remove.
	(linux_enable_bts): Call cpu_supports_bts.
	* nat/linux-btrace.h (linux_supports_btrace): Remove.
	* remote.c (remote_supports_btrace): Remove.
	(init_remote_ops): Remove remote_supports_btrace.
	* target-delegates.c: Regenerated.
	* target.c (target_supports_btrace): Remove.
	* target.h (target_ops) <to_supports_btrace>: Remove
	(target_supports_btrace): Remove.
	* x86-linux-nat.c (x86_linux_create_target): Remove
	linux_supports_btrace.

gdbserver/
	* linux-low.c (linux_target_ops): Remove linux_supports_btrace.
	* nto-low.c (nto_target_ops): Remove NULL for supports_btrace.
	* spu-low.c (spu_target_ops): Likewise.
	* win32-low.c (win32_target_ops): Likewise.
	* server.c (supported_btrace_packets): Report packets unconditionally.
	* target.h (target_ops) <supports_btrace>: Remove.
	(target_supports_btrace): Remove.
2018-02-09 14:03:20 +01:00
Markus Metzger 9ee23a853c btrace, gdbserver: use exceptions to convey btrace enable/disable errors
Change error reporting to use exceptions and be prepared to catch them in
gdbserver.  We use the exception message in our error reply to GDB.

This may remove some detail from the error message in the native case since
errno is no longer printed.  Later patches will improve that.

We're still using error strings on the RSP level.  This patch does not affect
the interoperability of older/newer GDB/gdbserver.

gdbserver/
	* server.c (handle_btrace_enable_bts, handle_btrace_enable_pt)
	(handle_btrace_disable): Change return type to void.  Use exceptions
	to report errors.
	(handle_btrace_general_set): Catch exception and copy message to
	return message.

gdb/
	* nat/linux-btrace.c (linux_enable_btrace): Throw exception if enabling
	btrace failed.
	* x86-linux-nat.c (x86_linux_enable_btrace): Catch btrace enabling
	exception and use message in own exception.
2018-02-09 14:03:19 +01:00
Markus Metzger 5c3284c1ec btrace: prepare for throwing exceptions when enabling btrace
We indicate success or failure for enabling branch tracing via the pointer
return value.  Depending on the type of error, errno may provide additional
information.

Prepare for using exceptions with more descriptive error messages by using smart
pointers and objects with automatic destruction to hold intermediate results.

gdb/
	* nat/linux-btrace.c: Include scoped_fd.h and scoped_mmap.h.
	(perf_event_pt_event_type): Use gdb_file_up.
	(linux_enable_bts, linux_enable_pt): Use gdb::unique_xmalloc_ptr,
	scoped_fd, and scoped_mmap.
2018-02-09 14:03:19 +01:00
Markus Metzger 84696f37ae common: add scoped_mmap
Add a simple helper to automatically unmap a memory mapping.

gdb/
	* common/scoped_mmap.h: New.
	* unittests/scoped_mmap-selftest.c: New.
	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/scoped_mmap-selftest.c.
2018-02-09 14:03:19 +01:00
Markus Metzger ea4a088812 common: add scoped_fd
Add a simple helper to automatically close a file descriptor.

gdb/
	* common/scoped_fd.h: New.
	* unittests/scoped_fd-selftest.c: New.
	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/scoped_fd-selftest.c.
2018-02-09 14:03:18 +01:00
Tom Tromey 869e8290ea Use gdb::unique_xmalloc_ptr in auto_load_section_scripts
This changes auto_load_section_scripts to use gdb::unique_xmalloc_ptr,
allowing the removal of a cleanup.

2018-02-09  Tom Tromey  <tom@tromey.com>

	* auto-load.c (auto_load_section_scripts): Use
	gdb::unique_xmalloc_ptr.
2018-02-09 05:53:22 -07:00
Tom Tromey a37a2ae708 Use std::string in execute_script_contents
This changes execute_script_contents to use a std::string, allowing
the removal of a cleanup.

2018-02-09  Tom Tromey  <tom@tromey.com>

	* auto-load.c (execute_script_contents): Use std::string.
2018-02-09 05:53:21 -07:00
Joel Brobecker 4e72534799 gdb/NEWS: Clarify the news entry for "rbreak" in GDB 8.1
gdb/ChangeLog:

        * NEWS <Changes in GDB 8.1>: Clarify that "rbreak" is a new
        Python function, rather than a new command.
2018-02-09 16:04:38 +04:00
H.J. Lu 15b23f3612 x86: Set need_global_offset_table with info->output_bfd->xvec
* elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
	Remove prototype.
	(i386_elf32_sol2_vec): Declared.
	(elf_i386_link_setup_gnu_properties): Set
	need_global_offset_table with info->output_bfd->xvec.
	* elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
	Remove prototype.
	(x86_64_elf64_sol2_vec): Declared.
	(elf_x86_64_link_setup_gnu_properties): Set
	need_global_offset_table with info->output_bfd->xvec.
2018-02-08 16:30:55 -08:00
GDB Administrator 4d6945e70a Automatic date update in version.in 2018-02-09 00:00:25 +00:00
H.J. Lu dc11dea212 x86: Keep the unused _GLOBAL_OFFSET_TABLE_ for Solaris
Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it isn't used.
This patch detects Solaris target and keeps _GLOBAL_OFFSET_TABLE_ for
Solaris.

	* elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
	New prototype.
	(elf_i386_link_setup_gnu_properties): Set need_global_offset_table
	for Solaris.
	* elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
	New prototype.
	(elf_x86_64_link_setup_gnu_properties): Set
	need_global_offset_table for Solaris.
	* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Keep the
	unused _GLOBAL_OFFSET_TABLE_ for Solaris.
	(_bfd_x86_elf_link_setup_gnu_properties): Copy
	need_global_offset_table.
	* elfxx-x86.h (elf_x86_link_hash_table): Add
	need_global_offset_table.
	(elf_x86_init_table): Likewise.
2018-02-08 13:52:22 -08:00
Jim Wilson 3f48fe4a95 RISC-V: Add comment for previous change.
bfd/
	* elfnn-riscv.c (riscv_elf_relocate_section): Add comment for previous
	change.
2018-02-08 13:15:10 -08:00
Tom Tromey 9a897d43f0 Remove cleanups from solib.c
This removes a couple of cleanups from solib.c, replacing one with
std::string and another with unique_xmalloc_ptr.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* solib.c (solib_find_1): Use std::string.
	(solib_bfd_fopen): Use unique_xmalloc_ptr.
2018-02-08 11:46:57 -07:00
Tom Tromey 58ef3771fb Use unique_xmalloc_ptr in build_id_to_debug_bfd
This changes build_id_to_debug_bfd to use a unique_xmalloc_ptr,
removing a cleanup.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* build-id.c (build_id_to_debug_bfd): Use unique_xmalloc_ptr.
2018-02-08 11:46:57 -07:00
Tom Tromey a9abc43451 Use gdb::def_vector in find_source_lines
This replaces an explicit malloc and a cleanup with a gdb::def_vector.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* source.c (find_source_lines): Use gdb::def_vector.
2018-02-08 11:46:57 -07:00
Tom Tromey 84f27c6fcb Remove cleanups from macro_define_command
This removes cleanups from macro_define_command, by introducing a new
struct temporary_macro_definition that cleans up after itself.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* macrocmd.c (struct temporary_macro_definition): New.
	(macro_define_command): Use temporary_macro_definition.  Remove
	cleanups.
	(free_macro_definition_ptr): Remove.
2018-02-08 11:46:56 -07:00
Tom Tromey 0354904bda Use std::string in maybe_expand
This patch changes maybe_expand to use std::string rather than an
explicit malloc and a cleanup.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* macroexp.c (maybe_expand): Use std::string.
2018-02-08 11:46:56 -07:00
Tom Tromey 1739cf248f Class-ify macro_buffer
This patch changes macro_buffer to be a bit more of a C++ class,
adding constructors, a destructor, and some members.  Then this is
used to remove various cleanups in macroexp.c.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* macroexp.c (struct macro_buffer): Add initializers for some
	members.
	(init_buffer, init_shared_buffer, free_buffer)
	(free_buffer_return_text): Remove.
	(macro_buffer): New constructors.
	(~macro_buffer): New destructor.
	(macro_buffer::set_shared): New method.
	(macro_buffer::resize_buffer, macro_buffer::appendc)
	(macro_buffer::appendmem): Now methods, not free functions.
	(set_token, append_tokens_without_splicing, stringify)
	(macro_stringify): Update.
	(gather_arguments): Change return type.  Remove argc_p argument,
	add args_ptr argument.  Use std::vector.
	(substitute_args): Remove argc argument.  Accept std::vector.
	(expand): Update.  Use std::vector.
	(scan, macro_expand, macro_expand_next): Update.
2018-02-08 11:46:56 -07:00
Tom Tromey f6c2623eb8 Return unique_xmalloc_ptr from macro scope functions
This changes the macro scope functions (sal_macro_scope,
user_macro_scope, and default_macro_scope) to return a
unique_xmalloc_ptr, then fixes up the users.  This allowed for the
removal of several cleanups.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* symtab.c (default_collect_symbol_completion_matches_break_on):
	Use unique_xmalloc_ptr.
	* macroscope.h: (sal_macro_scope, user_macro_scope)
	(default_macro_scope): Return unique_xmalloc_ptr.
	* macroscope.c (sal_macro_scope, user_macro_scope)
	(default_macro_scope): Return unique_xmalloc_ptr.
	* macroexp.h (macro_expand, macro_expand_once): Return
	unique_xmalloc_ptr.
	* macroexp.c (macro_expand, macro_expand_once): Return
	unique_xmalloc_ptr.
	* macrocmd.c (macro_expand_command, macro_expand_once_command)
	(info_macro_command, info_macros_command): Use
	unique_xmalloc_ptr.
	* compile/compile-c-support.c (write_macro_definitions): Use
	unique_xmalloc_ptr.
	* c-exp.y (c_parse): Use unique_xmalloc_ptr.
2018-02-08 11:46:55 -07:00
Tom Tromey 8ce47547b3 Remove make_cleanup_restore_current_thread from gdbserver
This removes make_cleanup_restore_current_thread from gdbserver,
replacing it with a use of scoped_restore.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* linux-low.c (install_software_single_step_breakpoints): Use
	make_scoped_restore.
	* inferiors.c (make_cleanup_restore_current_thread): Remove.
	(do_restore_current_thread_cleanup): Remove.
	* gdbthread.h (make_cleanup_restore_current_thread): Don't
	declare.
2018-02-08 11:46:55 -07:00
Tom Tromey 45dd3607e2 Remove a cleanup from gdbserver
This removes a cleanup from gdbserver's set_raw_breakpoint_at,
replacing it with unique_xmalloc_ptr.

2018-02-08  Tom Tromey  <tom@tromey.com>

	* mem-break.c (set_raw_breakpoint_at): Use
	gdb::unique_xmalloc_ptr.
2018-02-08 11:46:55 -07:00
Nick Clifton 8de3a6e2af Speed up readelf and objdump by not looking for DWO links unless the user has requested that they be displayed/followed.
PR 22802
	* dwarf.c (load_separate_debug_file): Return early if the user is
	not interested in debug links.
2018-02-08 12:29:07 +00:00
Nick Clifton ef135d4314 Fix a seg-fault in the ELF note parser when a note with an excessively large alignment is encountered.
PR 22788
	* elf.c (elf_parse_notes): Reject notes with excessuively large
	alignments.
2018-02-08 10:28:25 +00:00
Alan Modra a9479dc051 PR22819, powerpc gas "instruction address is not a multiple of 4"
Checks for insn alignment were hopelessly confused when misaligned
data starts a new frag.  The real-world testcase happened to run out
of frag space in the middle of emitting a trace-back table via
something like:
	.byte 0		/* VERSION=0 */
 	.byte 9		/* LANG=C++ */
	.byte 34	/* Bits on: has_tboff, fp_present */
	.byte 64	/* Bits on: name_present */
	.byte 128	/* Bits on: stores_bc, FP_SAVED=0 */
	.byte 0		/* Bits on: GP_SAVED=0 */
	.byte 2		/* FIXEDPARMS=2 */
	.byte 1		/* FLOATPARMS=0, parmsonstk */
	.long 0
	.long 768	/* tb_offset: 0x300 */
	.hword 45	/* Function name length: 45 */
 	.long 0x334e5a5f
	.long 0x31766f70
	.long 0x65744932
	.long 0x69746172
	.long 0x7a5f6e6f
	.long 0x64504533
	.long 0x5f534e50
	.long 0x72463431
	.long 0x61746361
	.long 0x74535f6c
	.long 0x74637572
	.byte 0x45
	.byte 0
The trigger being those misaligned .long's output for the function
name.  A most horrible way to output a string, especially considering
endian issues..

	PR 22819
	* config/tc-ppc.c (md_assemble): Rewrite insn alignment checking.
	(ppc_frag_check): Likewise.
	* testsuite/gas/ppc/misalign.d,
	* testsuite/gas/ppc/misalign.l,
	* testsuite/gas/ppc/misalign.s: New test.
	* testsuite/gas/ppc/misalign2.d,
	* testsuite/gas/ppc/misalign2.s: New test.
	* testsuite/gas/ppc/ppc.exp: Run them.
2018-02-08 13:56:29 +10:30
GDB Administrator 02ecce62be Automatic date update in version.in 2018-02-08 00:00:32 +00:00
Simon Marchi c2e0e465f9 Fix type of values representing optimized out static members
As reported here:

  https://sourceware.org/ml/gdb/2018-02/msg00019.html

the type of values representing static members that are optimized out is
wrong.  It currently assigns the type of the containing class rather
than the type of the field.  This patch fixes that.

I found a place in m-static.exp already dealing with optimized out
static members, so I just added some gdb_test there.

gdb/ChangeLog:

	* value.c (value_static_field): Assign field type instead of
	containing type when returning an optimized out value.

gdb/testsuite/ChangeLog:

	* gdb.cp/m-static.exp: Check type of optimized out static
	member.
2018-02-07 08:49:56 -05:00