binutils-gdb.git
6 years agoAdd selftests for range_contains and insert_into_bit_range_vector
Simon Marchi [Mon, 9 Apr 2018 19:45:39 +0000 (15:45 -0400)]
Add selftests for range_contains and insert_into_bit_range_vector

Add some selftests for these two functions.  To to make it easier to
compare sequences of ranges, add operator== and operator!= to compare
two gdb::array_view, and add operator== in struct range.

gdb/ChangeLog:

* value.c: Include "selftest.h" and "common/array-view.h".
(struct range) <operator ==>: New.
(test_ranges_contain): New.
(check_ranges_vector): New.
(test_insert_into_bit_range_vector): New.
(_initialize_values): Register selftests.
* common/array-view.h (operator==, operator!=): New.

6 years agoUse an std::vector for inline_states
Simon Marchi [Mon, 9 Apr 2018 19:40:45 +0000 (15:40 -0400)]
Use an std::vector for inline_states

This patch replaces VEC(inline_state) with std::vector<inline_state> and
adjusts the code that uses it.

gdb/ChangeLog:

* common/gdb_vecs.h (unordered_remove): Add overload that takes
an iterator.
* inline-frame.c: Include <algorithm>.
(struct inline_state): Add constructor.
(inline_state_s): Remove.
(DEF_VEC_O(inline_state_s)): Remove.
(inline_states): Change type to std::vector.
(find_inline_frame_state): Adjust to std::vector.
(allocate_inline_frame_state): Remove.
(clear_inline_frame_state): Adjust to std::vector.
(skip_inline_frames): Adjust to std::vector.

6 years agoRemove VEC(tsv_s), use std::vector instead
Simon Marchi [Mon, 9 Apr 2018 19:16:19 +0000 (15:16 -0400)]
Remove VEC(tsv_s), use std::vector instead

This patch removes VEC(tsv_s), using an std::vector instead.  I C++ified
trace_state_variable a bit in the process, using std::string for the
name.  I also thought it would be nicer to pass a const reference to
target_download_trace_state_variable, since we know it will never be
NULL.  This highlighted that the make-target-delegates script didn't
handle references well, so I adjusted this as well.  It will surely be
useful in the future.

gdb/ChangeLog:

* tracepoint.h (struct trace_state_variable): Add constructor.
<name>: Change type to std::string.
* tracepoint.c (tsv_s): Remove.
(DEF_VEC_O(tsv_s)): Remove.
(tvariables): Change to std::vector.
(create_trace_state_variable): Adjust to std::vector.
(find_trace_state_variable): Likewise.
(find_trace_state_variable_by_number): Likewise.
(delete_trace_state_variable): Likewise.
(trace_variable_command): Adjust to std::string.
(delete_trace_variable_command): Likewise.
(tvariables_info_1): Adjust to std::vector.
(save_trace_state_variables): Likewise.
(start_tracing): Likewise.
(merge_uploaded_trace_state_variables): Adjust to std::vector
and std::string.
* target.h (struct target_ops)
<to_download_trace_state_variable>: Pass reference to
trace_state_variable.
* target-debug.h (target_debug_print_const_trace_state_variable_r): New.
* target-delegates.c: Re-generate.
* mi/mi-interp.c (mi_tsv_created): Adjust to std::string.
(mi_tsv_deleted): Likewise.
* mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise.
* remote.c (remote_download_trace_state_variable): Change
pointer to reference and adjust.
* make-target-delegates (parse_argtypes): Handle references.
(write_function_header): Likewise.
(munge_type): Likewise.

6 years agoAdapt and integrate string_view tests
Simon Marchi [Mon, 9 Apr 2018 17:31:06 +0000 (13:31 -0400)]
Adapt and integrate string_view tests

The previous patch copied the string_view tests from libstdc++.  This
patch adjusts them in a similar way that the libstdc++ optional tests
are integrated in our unit test suite.

Not all tests are used, some of them require language features not
present in c++11.  For example, we can't use a string_view constructor
where the length is not explicit in a constexpr, because
std::char_traits::length is not a constexpr itself (it is in c++17
though).  Nevertheless, a good number of tests are integrated, which
covers pretty well the string_view features.

gdb/ChangeLog:

* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
string_view-selftests.c.
* unittests/basic_string_view/capacity/1.cc: Adapt to GDB
testsuite.
* unittests/basic_string_view/cons/char/1.cc: Likewise.
* unittests/basic_string_view/cons/char/2.cc: Likewise.
* unittests/basic_string_view/cons/char/3.cc: Likewise.
* unittests/basic_string_view/element_access/char/1.cc:
Likewise.
* unittests/basic_string_view/element_access/char/empty.cc:
Likewise.
* unittests/basic_string_view/element_access/char/front_back.cc:
Likewise.
* unittests/basic_string_view/inserters/char/2.cc: Likewise.
* unittests/basic_string_view/modifiers/remove_prefix/char/1.cc:
Likewise.
* unittests/basic_string_view/modifiers/remove_suffix/char/1.cc:
Likewise.
* unittests/basic_string_view/modifiers/swap/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/compare/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/compare/char/13650.cc:
Likewise.
* unittests/basic_string_view/operations/copy/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/data/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/find/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/find/char/2.cc:
Likewise.
* unittests/basic_string_view/operations/find/char/3.cc:
Likewise.
* unittests/basic_string_view/operations/find/char/4.cc:
Likewise.
* unittests/basic_string_view/operations/rfind/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/rfind/char/2.cc:
Likewise.
* unittests/basic_string_view/operations/rfind/char/3.cc:
Likewise.
* unittests/basic_string_view/operations/substr/char/1.cc:
Likewise.
* unittests/basic_string_view/operators/char/2.cc: Likewise.
* unittests/string_view-selftests.c: New file.

6 years agoCopy string_view tests from libstdc++
Simon Marchi [Mon, 9 Apr 2018 17:31:05 +0000 (13:31 -0400)]
Copy string_view tests from libstdc++

This patch copies the string_view tests from the gcc repository (commit
02a4441f002c).

  ${gcc}/libstdc++-v3/testsuite/21_strings/basic_string_view ->
    ${binutils-gdb}/gdb/unittests/basic_string_view

The local modifications are done in the following patch, so that it's
easier to review them.

gdb/ChangeLog:

* unittests/basic_string_view/capacity/1.cc: New file.
* unittests/basic_string_view/capacity/empty_neg.cc: New file.
* unittests/basic_string_view/cons/char/1.cc: New file.
* unittests/basic_string_view/cons/char/2.cc: New file.
* unittests/basic_string_view/cons/char/3.cc: New file.
* unittests/basic_string_view/cons/wchar_t/1.cc: New file.
* unittests/basic_string_view/cons/wchar_t/2.cc: New file.
* unittests/basic_string_view/cons/wchar_t/3.cc: New file.
* unittests/basic_string_view/element_access/char/1.cc: New file.
* unittests/basic_string_view/element_access/char/2.cc: New file.
* unittests/basic_string_view/element_access/char/empty.cc: New file.
* unittests/basic_string_view/element_access/char/front_back.cc: New file.
* unittests/basic_string_view/element_access/wchar_t/1.cc: New file.
* unittests/basic_string_view/element_access/wchar_t/2.cc: New file.
* unittests/basic_string_view/element_access/wchar_t/empty.cc: New file.
* unittests/basic_string_view/element_access/wchar_t/front_back.cc: New file.
* unittests/basic_string_view/include.cc: New file.
* unittests/basic_string_view/inserters/char/1.cc: New file.
* unittests/basic_string_view/inserters/char/2.cc: New file.
* unittests/basic_string_view/inserters/char/3.cc: New file.
* unittests/basic_string_view/inserters/pod/10081-out.cc: New file.
* unittests/basic_string_view/inserters/wchar_t/1.cc: New file.
* unittests/basic_string_view/inserters/wchar_t/2.cc: New file.
* unittests/basic_string_view/inserters/wchar_t/3.cc: New file.
* unittests/basic_string_view/literals/types.cc: New file.
* unittests/basic_string_view/literals/values.cc: New file.
* unittests/basic_string_view/modifiers/remove_prefix/char/1.cc: New file.
* unittests/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc: New file.
* unittests/basic_string_view/modifiers/remove_suffix/char/1.cc: New file.
* unittests/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc: New file.
* unittests/basic_string_view/modifiers/swap/char/1.cc: New file.
* unittests/basic_string_view/modifiers/swap/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/compare/char/1.cc: New file.
* unittests/basic_string_view/operations/compare/char/13650.cc: New file.
* unittests/basic_string_view/operations/compare/char/2.cc: New file.
* unittests/basic_string_view/operations/compare/char/70483.cc: New file.
* unittests/basic_string_view/operations/compare/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/compare/wchar_t/13650.cc: New file.
* unittests/basic_string_view/operations/compare/wchar_t/2.cc: New file.
* unittests/basic_string_view/operations/copy/char/1.cc: New file.
* unittests/basic_string_view/operations/copy/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/data/char/1.cc: New file.
* unittests/basic_string_view/operations/data/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/find/char/1.cc: New file.
* unittests/basic_string_view/operations/find/char/2.cc: New file.
* unittests/basic_string_view/operations/find/char/3.cc: New file.
* unittests/basic_string_view/operations/find/char/4.cc: New file.
* unittests/basic_string_view/operations/find/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/find/wchar_t/2.cc: New file.
* unittests/basic_string_view/operations/find/wchar_t/3.cc: New file.
* unittests/basic_string_view/operations/find/wchar_t/4.cc: New file.
* unittests/basic_string_view/operations/rfind/char/1.cc: New file.
* unittests/basic_string_view/operations/rfind/char/2.cc: New file.
* unittests/basic_string_view/operations/rfind/char/3.cc: New file.
* unittests/basic_string_view/operations/rfind/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/rfind/wchar_t/2.cc: New file.
* unittests/basic_string_view/operations/rfind/wchar_t/3.cc: New file.
* unittests/basic_string_view/operations/string_conversion/1.cc: New file.
* unittests/basic_string_view/operations/substr/char/1.cc: New file.
* unittests/basic_string_view/operations/substr/wchar_t/1.cc: New file.
* unittests/basic_string_view/operators/char/2.cc: New file.
* unittests/basic_string_view/operators/wchar_t/2.cc: New file.
* unittests/basic_string_view/range_access/char/1.cc: New file.
* unittests/basic_string_view/range_access/wchar_t/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/char/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc: New file.
* unittests/basic_string_view/requirements/typedefs.cc: New file.
* unittests/basic_string_view/typedefs.cc: New file.
* unittests/basic_string_view/types/1.cc: New file.

6 years agoAdd gdb::string_view
Simon Marchi [Mon, 9 Apr 2018 17:31:04 +0000 (13:31 -0400)]
Add gdb::string_view

We had a few times the need for a data structure that does essentially
what C++17's std::string_view does, which is to give an std::string-like
interface (only the read-only operations) to an arbitrary character
buffer.

This patch adapts the files copied from libstdc++ by the previous patch
to integrate them with GDB.  Here's a summary of the changes:

  * Remove things related to wstring_view, u16string_view and
  u32string_view (I don't think we need them, but we can always add them
  later).

  * Remove usages of _GLIBCXX_BEGIN_NAMESPACE_VERSION and
  _GLIBCXX_END_NAMESPACE_VERSION.

  * Put the code in the gdb namespace.  I had to add a few "std::" in
  front of std type usages.

  * Change __throw_out_of_range_fmt() for error().

  * Make gdb::string_view an alias of std::string_view when building
  with >= c++17.

  * Remove a bunch of constexpr, because they are not valid in c++11
  (e.g. they are not a single return line).

  * Use std::common_type<_Tp>::type instead of std::common_type_t<_Tp>,
  because c++11 doesn't have the later.

  * Remove the #pragma GCC system_header, since that silences some
  warnings that we might want to have if we're doing something not
  correctly.

  * Remove operator ""sv.  It would need a lot of work to make all
  supported compilers happy, and we can easily live without it.

  * Remove operator<<.  It is implemented using __ostream_insert (a
  libstdc++ internal).  Bringing it in might be possible, but I don't
  think that would be worth the effort, since we don't really use
  streams at the moment.

  * Replace internal libstdc++ asserts ( __glibcxx_assert and
  __glibcxx_requires_string_len) with gdb_assert.

  * Remove hash helpers, because they use libstdc++ internal functions.
  If we need them we always import them later.

The string_view class in cli/cli-script.c is removed and its usage
replaced with the new gdb::string_view.

gdb/ChangeLog:

* common/gdb_string_view.h: Remove libstdc++ implementation
details, adjust to gdb reality.
* common/gdb_string_view.tcc: Likewise.
* cli/cli-script.c (struct string_view): Remove.
(user_args) <m_args>: Change element type to gdb::string_view.
(user_args::insert_args): Adjust.

6 years agoCopy string_view files from libstdc++
Simon Marchi [Mon, 9 Apr 2018 17:31:04 +0000 (13:31 -0400)]
Copy string_view files from libstdc++

This patch copies the following files from libstdc++ (commit
02a4441f002c):

  ${gcc}/libstdc++-v3/include/experimental/string_view
    -> ${binutils-gdb}/gdb/common/gdb_string_view.h

  ${gcc}/libstdc++-v3/include/experimental/bits/string_view.tcc
    -> ${binutils-gdb}/gdb/common/gdb_string_view.tcc

The local modifications are done in the following patch in order to make
it easier to review them.

gdb/ChangeLog:

* common/gdb_string_view.h: New file.
* common/gdb_string_view.tcc: New file.

6 years agoUpdate ax_cv_cxx_compile_cxx.m4
Simon Marchi [Mon, 9 Apr 2018 17:31:03 +0000 (13:31 -0400)]
Update ax_cv_cxx_compile_cxx.m4

This file provides the AX_CXX_COMPILE_STDCXX macro.  In the context of
the following patch, I wanted to build and test GDB in c++17 mode.  The
version of the macro we have in the repo does not support detecting
c++17 compilers, but the upstream version has been updated to do so.

Since we have local modifications to the file, I had to reconcile our
modifications and the updated upstream version (which was relatively
straightforward).

gdb/ChangeLog:

* ax_cxx_compile_stdcxx.m4: Sync with upstream.
* configure: Re-generate.

6 years agoRegenerate some files
Alan Modra [Mon, 9 Apr 2018 09:22:11 +0000 (18:52 +0930)]
Regenerate some files

The gold change is to pick up HJ's PR22318 AC_PLUGINS update.  The
ld change is to correct a file I generated from a modified tree.

gold/
* configure: Regenerate.
ld/
* po/BLD-POTFILES.in: Regenerate.

6 years agoApply "Convert observers to C++" edit to gdbarch.sh
Pedro Alves [Mon, 9 Apr 2018 14:34:48 +0000 (15:34 +0100)]
Apply "Convert observers to C++" edit to gdbarch.sh

Regenerating gdbarch.c results in:

  --- gdbarch.c   2018-03-26 23:18:52.905548891 +0100
  +++ new-gdbarch.c       2018-04-09 15:32:30.006712207 +0100
  @@ -44,7 +44,7 @@
   #include "reggroups.h"
   #include "osabi.h"
   #include "gdb_obstack.h"
  -#include "observable.h"
  +#include "observer.h"
   #include "regcache.h"
   #include "objfiles.h"
   #include "auxv.h"
  @@ -5457,7 +5457,7 @@
     gdb_assert (new_gdbarch != NULL);
     gdb_assert (new_gdbarch->initialized_p);
     current_inferior ()->gdbarch = new_gdbarch;
  -  gdb::observers::architecture_changed.notify (new_gdbarch);
  +  observer_notify_architecture_changed (new_gdbarch);
     registers_changed ();
   }

Clearly commit 76727919ceb5 ("Convert observers to C++") edited
gdbarch.c directly instead of gdbarch.sh.  This fixes it.

gdb/ChangeLog:
2018-04-09  Pedro Alves  <palves@redhat.com>

* gdbarch.sh: Include "observable.h" instead of "observer.h".
(set_target_gdbarch): Call
gdb::observers::architecture_changed.notify instead of
observer_notify_architecture_changed.

6 years agobinutils/testsuite: Fix a crash with STN_UNDEF in relocation
Maciej W. Rozycki [Mon, 9 Apr 2018 12:42:01 +0000 (13:42 +0100)]
binutils/testsuite: Fix a crash with STN_UNDEF in relocation

Verify that `strip' completes successfully and a correct relocation
entry is copied for a relocation encountered with the STN_UNDEF symbol
index.

binutils/
* testsuite/binutils-all/strip-15.d: New test.
* testsuite/binutils-all/strip-15rel.s: New test source.
* testsuite/binutils-all/strip-15rela.s: New test source.
* testsuite/binutils-all/strip-15mips64.s: New test source.
* testsuite/binutils-all/objcopy.exp: Run the new test.

6 years agoMIPS64/BFD: Fix a crash with STN_UNDEF in relocation
Maciej W. Rozycki [Mon, 9 Apr 2018 12:42:00 +0000 (13:42 +0100)]
MIPS64/BFD: Fix a crash with STN_UNDEF in relocation

Prevent a null BFD pointer dereference and a resulting segmentation
fault in `mips_elf64_write_rel' or `mips_elf64_write_rela':

Program received signal SIGSEGV, Segmentation fault.
0x0000000000437690 in mips_elf64_write_rela (abfd=0x71e130, sec=0x720700,
    rela_hdr=0x721ff8, count=0x7fffffffb82c, data=0x7fffffffb88c)
    at .../bfd/elf64-mips.c:4123
4123       if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
4124   && ! _bfd_elf_validate_reloc (abfd, ptr))

in the MIPS64 (n64 MIPS) ELF backend whenever the STN_UNDEF symbol index
is retrieved from the `r_sym' field of a relocation seen in input while
running `objcopy' or `strip'.  The reason for the null BFD pointer is
that internally in BFD an STN_UNDEF symbol reference resolves to an
absolute zero symbol that does not have a BFD associated.  Check the
pointer then before using it, like the generic ELF backend does in
`elf_write_relocs'.

This complements the same change made for generic ELF bundled with:

commit e35765a9a2eaff0df62757f3e6480c8ba5ab8ee8
Author: Ian Lance Taylor <ian@airs.com>
Date:   Sun Dec 15 19:59:18 1996 +0000

which (obviously due to a CVS -> GIT repository conversion inaccuracy)
seems to be one corresponding to this ChangeLog entry:

* elfcode.h (write_relocs): Handle absolute symbol.

from:

commit c86158e591edd8450f49f8cd75f82e4313d4b6d8
Author: Ian Lance Taylor <ian@airs.com>
Date:   Fri Aug 30 22:09:51 1996 +0000

("Add SH ELF support."), which also updated RELA only and not REL (which
has been since fixed with: commit 947216bf8f34 ("ELF reloc code tidy"),
<https://sourceware.org/ml/binutils/2002-11/msg00727.html>).

bfd/
* elf64-mips.c (mips_elf64_write_rel): Handle a NULL BFD pointer
in the BFD symbol referred by the relocation.
(mips_elf64_write_rela): Likewise.

6 years agobinutils/testsuite: Verify the handling of invalid `r_sym' in relocation
Maciej W. Rozycki [Mon, 9 Apr 2018 12:42:00 +0000 (13:42 +0100)]
binutils/testsuite: Verify the handling of invalid `r_sym' in relocation

Verify that `strip' terminates gracefully and a correct error message is
produced for a relocation encountered with an invalid symbol index.  No
single relocation number is valid across all targets we support, so pick
a few numbers to choose from depending on the target.

binutils/
* testsuite/binutils-all/strip-14.d: New test.
* testsuite/binutils-all/strip-14rel.s: New test source.
* testsuite/binutils-all/strip-14rela.s: New test source.
* testsuite/binutils-all/strip-14mips64.s: New test source.
* testsuite/binutils-all/objcopy.exp: Run the new test.

6 years agoMIPS64/BFD: Fix a crash with invalid `r_sym' in relocation
Maciej W. Rozycki [Mon, 9 Apr 2018 12:42:00 +0000 (13:42 +0100)]
MIPS64/BFD: Fix a crash with invalid `r_sym' in relocation

Prevent an out-of-range access and a possible segmentation fault in
`mips_elf64_slurp_one_reloc_table':

Program received signal SIGSEGV, Segmentation fault.
mips_elf64_slurp_one_reloc_table (abfd=0x71bd90, asect=0x71cf70,
    rel_hdr=<value optimized out>, reloc_count=1,
    relents=<value optimized out>, symbols=0x7218c0, dynamic=0)
    at .../bfd/elf64-mips.c:3758
3757       ps = symbols + rela.r_sym - 1;
3758       s = *ps;

in the MIPS64 (n64 MIPS) ELF backend whenever an invalid symbol index is
retrieved from the `r_sym' field of a relocation seen in input while
running `objcopy' or `strip'.  Issue an error instead, like the generic
ELF backend does, taking code from `elf_slurp_reloc_table_from_section',
except for relocation types that do not refer to a symbol.

This complements commit 1f70368c21a8 ("Stop objdump crash on corrupt
reloc table"), <https://sourceware.org/ml/binutils/2002-09/msg00332.html>,
and commit 05a487dc8c39 ("make check fails on i686-linux-gnu"),
<https://sourceware.org/ml/binutils/2002-09/msg00340.html>, where the
generic ELF backend code comes from.

bfd/
* elf64-mips.c (mips_elf64_slurp_one_reloc_table): Issue an
error for out-of-range `r_sym' values.

6 years agoInline PLT call optimization
Alan Modra [Mon, 9 Apr 2018 00:02:39 +0000 (09:32 +0930)]
Inline PLT call optimization

This patch adds the analysis part of PLT call optimization, enabling
the code added with the previous patch that actually performs the
optimization.

Gold support is not available yet.

bfd/
* elf64-ppc.c (struct _ppc64_elf_section_data): Add has_pltcall field.
(struct ppc_link_hash_table): Add can_convert_all_inline_plt.
(ppc64_elf_check_relocs): Set has_pltcall.
(ppc64_elf_adjust_dynamic_symbol): Discard some PLT entries.
(ppc64_elf_inline_plt): New function.
(ppc64_elf_size_dynamic_sections): Discard some PLT entries for locals.
* elf64-ppc.h (ppc64_elf_inline_plt): Declare.
* elf32-ppc.c (has_pltcall): Define.
(struct ppc_elf_link_hash_table): Add can_convert_all_inline_plt.
(ppc_elf_check_relocs): Set has_pltcall.
(ppc_elf_inline_plt): New function.
(ppc_elf_adjust_dynamic_symbol): Discard some PLT entries.
(ppc_elf_size_dynamic_sections): Likewise.
* elf32-ppc.h (ppc_elf_inline_plt): Declare.
ld/
* emultempl/ppc64elf.em (no_inline_plt): New var.
(ppc_before_allocation): Call ppc64_elf_inline_plt.
(enum ppc64_opt): Add OPTION_NO_INLINE_OPT.
(PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS,
PARSE_AND_LIST_ARGS_CASES): Handle --no-inline-optimize.
* emultemps/ppc32elf.em (no_inline_opt): New var.
(prelim_size_sections): New function, extracted from..
(ppc_before_allocation): ..here.  Call ppc_elf_inline_plt.
(enum ppc32_opt): Add OPTION_NO_INLINE_OPT.
(PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS,
PARSE_AND_LIST_ARGS_CASES): Handle --no-inline-optimize.

6 years agoPowerPC inline PLT call support
Alan Modra [Sun, 8 Apr 2018 23:55:10 +0000 (09:25 +0930)]
PowerPC inline PLT call support

In addition to the existing relocs we need two more to mark all
instructions in the call sequence, PLTCALL on the call itself (plus
the toc restore insn for ppc64), and PLTSEQ on others.  All
relocations in a particular sequence have the same symbol.

Example ppc64 ELFv2 assembly:
 .reloc .,R_PPC64_PLTSEQ,puts
std 2,24(1)
addis 12,2,puts@plt@ha # .reloc .,R_PPC64_PLT16_HA,puts
ld 12,puts@plt@l(12) # .reloc .,R_PPC64_PLT16_LO_DS,puts
 .reloc .,R_PPC64_PLTSEQ,puts
mtctr 12
 .reloc .,R_PPC64_PLTCALL,puts
bctrl
ld 2,24(1)

Example ppc32 -fPIC assembly:
addis 12,30,puts+32768@plt@ha # .reloc .,R_PPC_PLT16_HA,puts+0x8000
lwz 12,12,puts+32768@plt@l    # .reloc .,R_PPC_PLT16_LO,puts+0x8000
 .reloc .,R_PPC_PLTSEQ,puts+32768
mtctr 12
 .reloc .,R_PPC_PLTCALL,puts+32768
bctrl

Marking sequences like this allows the linker to convert them to nops
and a direct call if the target symbol turns out to be local.

When the call is __tls_get_addr, each relocation shown above is paired
with an R_PPC*_TLSLD or R_PPC*_TLSGD reloc to additionally mark the
sequence for possible TLS optimization.  The TLSLD or TLSGD relocs are
emitted first.

include/
* elf/ppc.h (R_PPC_PLTSEQ, R_PPC_PLTCALL): Define.
* elf/ppc64.h (R_PPC64_PLTSEQ, R_PPC64_PLTCALL): Define.
bfd/
* elf32-ppc.c (ppc_elf_howto_raw): Add PLTSEQ and PLTCALL howtos.
(is_plt_seq_reloc): New function.
(ppc_elf_check_relocs): Handle PLTSEQ and PLTCALL relocs.
(ppc_elf_tls_optimize): Handle inline plt call sequence.
(ppc_elf_relax_section): Handle PLTCALL reloc.
(ppc_elf_relocate_section): Nop out inline plt call sequence when
resolving locally.
* elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_PLTSEQ and
R_PPC64_PLTCALL entries.  Comment R_PPC64_TOCSAVE.
(has_tls_get_addr_call): Correct comment.
(is_branch_reloc): Add PLTCALL.
(is_plt_seq_reloc): New function.
(ppc64_elf_check_relocs): Handle PLT16_LO_DS reloc.  Set
has_tls_reloc for R_PPC64_TLSGD and R_PPC64_TLSLD.  Create plt
entry for R_PPC64_PLTCALL.
(ppc64_elf_tls_optimize): Handle inline plt call sequence.
(ppc_type_of_stub): Handle PLTCALL reloc.
(toc_adjusting_stub_needed): Likewise.
(ppc64_elf_relocate_section): Set "can_plt_call" for PLTCALL
reloc insn.  Nop out inline plt call sequence when resolving
locally.  Handle __tls_get_addr inline plt call optimization.
elfcpp/
* powerpc.h (R_POWERPC_PLTSEQ, R_POWERPC_PLTCALL): Define.
gold/
* powerpc.cc (Target_powerpc::Track_tls::maybe_skip_tls_get_addr_call):
Handle inline plt sequence relocs.
(Stub_table::Plt_stub_key::Plt_stub_key): Likewise.
(Target_powerpc::Scan::reloc_needs_plt_for_ifunc): Likewise.
(Target_powerpc::Relocate::relocate): Likewise.

6 years agoSupport PLT16 relocs against local symbols
Alan Modra [Sun, 8 Apr 2018 23:52:53 +0000 (09:22 +0930)]
Support PLT16 relocs against local symbols

Necessary if gcc is to use PLT16 relocs to implement -mlongcall, and
there isn't a good technical reason why local symbols should be
excluded from PLT16 support.  Non-ifunc local symbol PLT entries go in
a separate section to other PLT entries.  In a fixed position
executable they won't need to be relocated, and in a PIE or shared
library I chose to not implement lazy relocation.

bfd/
* elf64-ppc.c (LOCAL_PLT_ENTRY_SIZE): Define.
(struct ppc_stub_hash_entry): Add symtype field.
(PLT_KEEP): Define.
(struct ppc_link_hash_table): Add pltlocal and relpltlocal.
(create_linkage_sections): Create pltlocal and relpltlocal.
(ppc64_elf_check_relocs): Allow PLT relocs on local symbols.
Set PLT_KEEP.
(ppc64_elf_adjust_dynamic_symbol): Keep PLT entries for inline calls.
(allocate_dynrelocs): Allocate pltlocal and relpltlocal.
(ppc64_elf_size_dynamic_sections): Size pltlocal and relpltlocal.
Keep PLT entries for inline calls against locals.
(ppc_build_one_stub): Use pltlocal as appropriate.
(ppc_size_one_stub): Likewise.
(ppc64_elf_size_stubs): Set symtype.
(build_global_entry_stubs_and_plt): Init pltlocal and write
relpltlocal for globals.
(write_plt_relocs_for_local_syms): Likewise for local syms.
(ppc64_elf_relocate_section): Support PLT for local syms.
* elf32-ppc.c (PLT_KEEP): Define.
(struct ppc_elf_link_hash_table): Add pltlocal and relpltlocal.
(ppc_elf_create_glink): Create pltlocal and relpltlocal.
(ppc_elf_check_relocs): Allow PLT relocs on local symbols.
Set PLT_KEEP.  Adjust update_local_sym_info call.
(ppc_elf_adjust_dynamic_symbol): Keep PLT entries for inline calls.
(allocate_dynrelocs): Allocate pltlocal and relpltlocal.
(ppc_elf_size_dynamic_sections): Size pltlocal and relpltlocal.
(ppc_elf_relocate_section): Support PLT16 relocs for local syms.
(write_global_sym_plt): Init pltlocal and write relpltlocal.
(ppc_finish_symbols): Likewise for locals.
ld/
* emulparams/elf32ppc.sh (OTHER_RELRO_SECTIONS_2): Add .branch_lt.
(OTHER_GOT_RELOC_SECTIONS): Add .rela.branch_lt.
* testsuite/ld-powerpc/elfv2so.d: Update for symbol/stub reordering.
* testsuite/ld-powerpc/relbrlt.d: Likewise.
* testsuite/ld-powerpc/relbrlt.s: Likewise.
* testsuite/ld-powerpc/tlsso.r: Likewise.
* testsuite/ld-powerpc/tlstocso.r: Likewise.
gold/
* powerpc.cc (Target_powerpc::lplt_): New variable.
(Target_powerpc::lplt_section): Associated accessor.
(Target_powerpc::plt_off): Handle local non-ifunc symbols.
(Target_powerpc::make_lplt_section): New function.
(Target_powerpc::make_local_plt_entry): New function.
(Powerpc_relobj::do_relocate_sections): Write out lplt.
(Output_data_plt_powerpc::first_plt_entry_offset): Zero for lplt.
(Output_data_plt_powerpc::add_local_entry): New function.
(Output_data_plt_powerpc::do_write): Ignore lplt.
(Target_powerpc::make_iplt_section): Make lplt first.
(Target_powerpc::make_brlt_section): Make .branch_lt relro.
(Target_powerpc::Scan::local): Handle PLT16 relocs.

6 years agoRearrange PLT reloc output on powerpc
Alan Modra [Sun, 8 Apr 2018 23:51:59 +0000 (09:21 +0930)]
Rearrange PLT reloc output on powerpc

The current scheme where we output PLT relocs for global symbols in
finish_dynamic_symbol, and PLT relocs for local symbols when
outputting stubs does not work if PLT entries are to be used for
inline PLT sequences against non-dynamic globals or local symbols.

bfd/
* elf64-ppc.c (ppc_build_one_stub): Move output of PLT relocs
for local symbols to..
(write_plt_relocs_for_local_syms): ..here.  New function.
(ppc64_elf_finish_dynamic_symbol): Move output of PLT relocs for
global symbols to..
(build_global_entry_stubs_and_plt): ..here.  Rename from
build_global_entry_stubs.
(ppc64_elf_build_stubs): Always call build_global_entry_stubs_and_plt.
Call write_plt_relocs_for_local_syms.
* elf32-ppc.c (get_sym_h): New function.
(ppc_elf_relax_section): Use get_sym_h.
(ppc_elf_relocate_section): Move output of PLT relocs and glink
stubs for local symbols to..
(ppc_finish_symbols): ..here.  New function.
(ppc_elf_finish_dynamic_symbol): Move output of PLT relocs for
global syms to..
(write_global_sym_plt): ..here.  New function.
* elf32-ppc.h (ppc_elf_modify_segment_map): Delete attribute.
(ppc_finish_symbols): Declare.
ld/
* ppc32elf.em (ppc_finish): Call ppc_finish_symbols.

6 years agoPowerPC PLT16 relocations
Alan Modra [Sun, 8 Apr 2018 23:51:10 +0000 (09:21 +0930)]
PowerPC PLT16 relocations

The PowerPC64 ELFv2 ABI and the PowerPC SysV ABI support a number of
relocations that can be used to create and access a PLT entry.
However, the relocs are not well defined.  The PLT16 family of relocs
talk about "the section offset or address of the procedure linkage
table entry".  It's plain that we do need a relative address when PIC
as otherwise we'd have dynamic text relocations, but "section offset"
doesn't specify which section.  The most obvious one, ".plt", isn't
that useful because there is no readily available way of addressing
the start of the ".plt" section.  Much more useful would be "the
GOT/TOC-pointer relative offset of the procedure linkage table entry",
and I suppose you could argue that is a "section offset" of sorts.
For PowerPC64 it is better to use the same TOC-pointer relative
addressing even when non-PIC, since ".plt" may be located outside the
range of a 32-bit address.  However, for ppc32 we do want an absolute
address when non-PIC as a GOT pointer may not be set up.  Also, for
ppc32 PIC we have a similar situation to R_PPC_PLTREL24 in that the
GOT pointer is set to a location in the .got2 section and we need to
specify the .got2 offset in the PLT16 reloc addend.

This patch supports PLT16 relocations using these semantics.  This is
not an ABI change for ppc32 since the relocations were not previously
supported by GNU ld, but is for ppc64 where some of the PLT16 relocs
were supported.  I'm not particularly concerned since the old ppc64
PLT16 reloc semantics made them almost completely useless.

bfd/
* elf32-ppc.c (ppc_elf_check_relocs): Handle PLT16 relocs.
(ppc_elf_relocate_section): Likewise.
* elf64-ppc.c (ppc64_elf_check_relocs): Handle PLT16_LO_DS.
(ppc64_elf_relocate_section): Likewise.  Correct PLT16
resolution to plt entry relative to toc pointer.
gold/
* powerpc.cc (Target_powerpc::plt_off): New functions.
(is_plt16_reloc): New function.
(Stub_table::plt_off): Use Target_powerpc::plt_off.
(Stub_table::plt_call_size): Use plt_off.
(Stub_table::do_write): Likewise.
(Target_powerpc::Scan::get_reference_flags): Return RELATIVE_REF
for PLT16 relocations.
(Target_powerpc::Scan::reloc_needs_plt_for_ifunc): Return true
for PLT16 relocations.
(Target_powerpc::Scan::global): Make a PLT entry for PLT16 relocations.
(Target_powerpc::Relocate::relocate): Support PLT16 relocations.
(Powerpc_scan_relocatable_reloc::global_strategy): Return RELOC_SPECIAL
for ppc32 plt16 relocs.

6 years agoPowerPC indirect calls to __tls_get_addr
Alan Modra [Sun, 8 Apr 2018 23:41:44 +0000 (09:11 +0930)]
PowerPC indirect calls to __tls_get_addr

It is possible to construct indirect calls to __tls_get_addr in
assembly that confuse TLS optimization.  (PowerPC gcc doesn't support
such calls, ignoring -mlongcall for __tls_get_addr.)  This patch fixes
the problem by requiring a TLSLD or TLSGD marker reloc before any insn
in an indirect call to __tls_get_addr will be optimized.  They also
need additional marker relocs defined in a later patch, so don't
expect the optimization to work just yet.  The point here is to
prevent mis-optimization of indirect calls without any marker relocs.

The presense of a marker reloc is tracked by a new bit in the tls_mask
field of ppc_link_hash_entry and the corresponding lgot_masks unsigned
char array for local symbols.  Since the field is only 8 bits, we've
run out of space.  However, tracking TLS use for variables, and
tracking IFUNC for functions are independent, and bits can be reused.
TLS_TLS is always set for TLS usage, so can be used to select the
meaning of the other bits.  This patch does that even for elf32-ppc.c
which hasn't yet run out of space in the field.

* elf64-ppc.c (TLS_TLS, TLS_GD, TLS_LD, TLS_TPREL, TLS_DTPREL,
TLS_TPRELGD, TLS_EXPLICIT):  Renumber.  Test TLS_TLS throughout
file when other TLS flags are tested in a mask.
(TLS_MARK, NON_GOT): Define.
(PLT_IFUNC): Redefine, and test TLS_TLS throughout file as well.
(update_local_sym_info): Don't create got entry when NON_GOT.
(ppc64_elf_check_relocs): Pass NON_GOT with PLT_IFUNC.
Set TLS_MARK.
(get_tls_mask): Do toc lookup if tls_mask is just TLS_MARK.
(ppc64_elf_relocate_section): Likewise.
(ppc64_elf_tls_optimize): Don't attempt to optimize indirect
__tls_get_addr calls lacking a marker reloc.
* elf32-ppc.c (TLS_TLS, TLS_GD, TLS_LD, TLS_TPREL, TLS_DTPREL,
TLS_TPRELGD): Renumber.  Update comment.
(TLS_MARK, NON_GOT): Define.
(PLT_IFUNC): Redefine, and test TLS_TLS throughout file as well.
(update_local_sym_info): Don't create got entry when NON_GOT.
(ppc_elf_check_relocs): Pass NON_GOT with PLT_IFUNC.
Set TLS_MARK.
(ppc_elf_tls_optimize): Don't attempt to optimize indirect
__tls_get_addr calls lacking a marker reloc.

6 years agoAutomatic date update in version.in
GDB Administrator [Mon, 9 Apr 2018 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoAutomatic date update in version.in
GDB Administrator [Sun, 8 Apr 2018 00:01:11 +0000 (00:01 +0000)]
Automatic date update in version.in

6 years agoFix gdb.mi/mi-stack.exp when gcc generates a stack protector
Simon Marchi [Sat, 7 Apr 2018 18:08:56 +0000 (14:08 -0400)]
Fix gdb.mi/mi-stack.exp when gcc generates a stack protector

I see some failures in the gdb.mi/mi-stack.exp test.  The test runs to
the callee4 function:

  int callee4 (void)
  {
    int A=1;
    int B=2;
    int C;
    int D[3] = {0, 1, 2};

    C = A + B;
    return 0;
  }

and expects to be stopped at the A=1 line.  However, when gcc generates
some stack protection code, it will stop at the { instead, as shown by
this disassembly (after I did "break callee4" and "run"):

  (gdb) disassemble /s
  Dump of assembler code for function callee4:
  /home/simark/src/binutils-gdb/gdb/testsuite/gdb.mi/mi-stack.c:
  26 {
     0x00005555555546ca <+0>: push   %rbp
     0x00005555555546cb <+1>: mov    %rsp,%rbp
     0x00005555555546ce <+4>: sub    $0x20,%rsp
  => 0x00005555555546d2 <+8>: mov    %fs:0x28,%rax
     0x00005555555546db <+17>: mov    %rax,-0x8(%rbp)
     0x00005555555546df <+21>: xor    %eax,%eax

  27   int A=1; /* callee4 begin */
     0x00005555555546e1 <+23>: movl   $0x1,-0x20(%rbp)

  28   int B=2;
     0x00005555555546e8 <+30>: movl   $0x2,-0x1c(%rbp)

The rest of the test relies on execution stopping on the A=1, so many things
fail after that.  This patch uses mi_continue_to_line instead, to stop at the
A=1 line precisely.

gdb/testsuite/ChangeLog:

* gdb.mi/mi-stack.exp (test_stack_frame_listing): Use
mi_continue_to_line.
* gdb.mi/mi-stack.c (callee4): Add comment.

6 years agoFix indentation in gdb.mi/mi-stack.exp
Simon Marchi [Sat, 16 Dec 2017 14:56:50 +0000 (09:56 -0500)]
Fix indentation in gdb.mi/mi-stack.exp

This patch fixes the indentation in gdb.mi/mi-stack.exp, which is a bit
inconsistent.

gdb/testsuite/ChangeLog:

* gdb.mi/mi-stack.exp: Fix indentation.

6 years agoReplace make_cleanup_restore_current_traceframe with RAII class
Simon Marchi [Sat, 7 Apr 2018 18:03:12 +0000 (14:03 -0400)]
Replace make_cleanup_restore_current_traceframe with RAII class

I put the constructor in tracepoint.c because it needs to read
traceframe_number, and I prefer to do that than to expose
traceframe_number.

gdb/ChangeLog:

* tracepoint.c (struct current_traceframe_cleanup): Remove.
(do_restore_current_traceframe_cleanup): Remove.
(restore_current_traceframe_cleanup_dtor): Remove.
(make_cleanup_restore_current_traceframe): Remove.
(scoped_restore_current_traceframe::scoped_restore_current_traceframe):
New.
* tracepoint.h (struct scoped_restore_current_traceframe): New.
* infrun.c (fetch_inferior_event): Use
scoped_restore_current_traceframe.

6 years agoMake dwarf2_per_objfile::all_type_units an std::vector
Simon Marchi [Sat, 7 Apr 2018 17:53:44 +0000 (13:53 -0400)]
Make dwarf2_per_objfile::all_type_units an std::vector

Make all_type_units an std::vector, remove
n_type_units/n_allocated_type_units and some manual memory management.

gdb/ChangeLog:

* dwarf2read.h (struct dwarf2_per_objfile) <n_type_units>:
Remove.
<n_allocated_type_units>: Remove.
<all_type_units>: Change to std::vector.
* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
to std::vector change.
(dwarf2_per_objfile::get_cutu): Likewise.
(dwarf2_per_objfile::get_tu): Likewise.
(create_signatured_type_table_from_index): Likewise.
(create_signatured_type_table_from_debug_names): Likewise.
(dw2_symtab_iter_next): Likewise.
(dw2_print_stats): Likewise.
(dw2_expand_all_symtabs): Likewise.
(dw2_expand_marked_cus): Likewise.
(dw2_debug_names_iterator::next): Likewise.
(dwarf2_initialize_objfile): Likewise.
(add_signatured_type_cu_to_table): Likewise.
(create_all_type_units): Likewise.
(add_type_unit): Likewise.
(struct tu_abbrev_offset): Add constructor.
(build_type_psymtabs_1): Adjust to std::vector change.
(print_tu_stats): Likewise.
* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
(write_debug_names): Likewise.

6 years agoMake dwarf2_per_objfile::all_comp_units an std::vector
Simon Marchi [Sat, 7 Apr 2018 17:53:43 +0000 (13:53 -0400)]
Make dwarf2_per_objfile::all_comp_units an std::vector

Make all_comp_units an std::vector, remove n_comp_units and some manual
memory management.

gdb/ChangeLog:

* dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise.
Make an std::vector.
<n_comp_units>: Remove.
* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
to std::vector change.
(dwarf2_per_objfile::get_cutu): Likewise.
(dwarf2_per_objfile::get_cu): Likewise.
(create_cus_from_index): Likewise.
(create_addrmap_from_index): Likewise.
(create_addrmap_from_aranges): Likewise.
(dwarf2_read_index): Likewise.
(dw2_find_last_source_symtab): Likewise.
(dw2_map_symtabs_matching_filename): Likewise.
(dw2_symtab_iter_next): Likewise.
(dw2_print_stats): Likewise.
(dw2_expand_all_symtabs): Likewise.
(dw2_expand_symtabs_with_fullname): Likewise.
(dw2_expand_marked_cus): Likewise.
(dw2_map_symbol_filenames): Likewise.
(create_cus_from_debug_names): Likewise.
(dwarf2_read_debug_names): Likewise.
(dw2_debug_names_iterator::next): Likewise.
(dwarf2_initialize_objfile): Likewise.
(set_partial_user): Likewise.
(dwarf2_build_psymtabs_hard): Likewise.
(read_comp_units_from_section): Remove arguments, adjust to
std::vector change.
(create_all_comp_units): Adjust to std::vector and
read_comp_units_from_section changes.
(dwarf2_find_containing_comp_unit): Adjust to std::vector
change.
* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
(psyms_seen_size): Likewise.
(write_gdbindex): Likewise.
(write_debug_names): Likewise.

6 years agoRemove some usages of get_dwarf2_per_objfile
Simon Marchi [Sat, 7 Apr 2018 17:53:42 +0000 (13:53 -0400)]
Remove some usages of get_dwarf2_per_objfile

This patch removes some usages of get_dwarf2_per_objfile, where we can
get hold of the dwarf2_per_objfile object in a simpler way.  For
example, it's simpler (and slightly less work) to pass
dwarf2_per_objfile and get the objfile from it than to pass the objfile
and call get_dwarf2_per_objfile.

Ideally, get_dwarf2_per_objfile should only be used in the entry points
of the dwarf2 code, where we receive an objfile.

gdb/ChangeLog:

* dwarf2read.c (create_cus_from_index_list): Replace objfile arg
with dwarf2_per_objfile.
(create_cus_from_index): Likewise.
(create_signatured_type_table_from_index): Likewise.
(dwarf2_read_index): Likewise.
(dwarf2_initialize_objfile): Likewise.
(dwarf2_fetch_die_loc_sect_off):  Get dwarf2_per_objfile from
per_cu rather than get_dwarf2_per_objfile.

6 years agoReplace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile
Simon Marchi [Sat, 7 Apr 2018 17:53:40 +0000 (13:53 -0400)]
Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile

Those two functions look like good candidates to become methods of
dwarf2_per_objfile.  I did that, and added get_tu as well.  When
replacing usages of dw2_get_cutu, I changed some instances to get_cutu
and others to get_cu, when appropriate (when we know we want a CU and
not a TU).

gdb/ChangeLog:

* dwarf2read.h (struct signatured_type): Forward declare.
(struct dwarf2_per_objfile) <get_cutu, get_cu, get_tu>:
New methods.
* dwarf2read.c (dwarf2_per_objfile::get_cutu): Rename from...
(dw2_get_cutu): ...this.
(dwarf2_per_objfile::get_cu): Rename from...
(dw2_get_cu): ...this.
(dwarf2_per_objfile::get_tu): New.
(create_addrmap_from_index): Adjust.
(create_addrmap_from_aranges): Adjust.
(dw2_find_last_source_symtab): Adjust.
(dw2_map_symtabs_matching_filename): Adjust.
(dw2_symtab_iter_next): Adjust.
(dw2_print_stats): Adjust.
(dw2_expand_all_symtabs): Adjust.
(dw2_expand_symtabs_with_fullname): Adjust.
(dw2_expand_marked_cus): Adjust.
(dw_expand_symtabs_matching_file_matcher): Adjust.
(dw2_map_symbol_filenames): Adjust.
(dw2_debug_names_iterator::next): Adjust.
(dwarf2_initialize_objfile): Adjust.
(set_partial_user): Adjust.
(dwarf2_build_psymtabs_hard): Adjust.

6 years agoRemove some unused variables in dwarf2read.c
Simon Marchi [Sat, 7 Apr 2018 17:53:39 +0000 (13:53 -0400)]
Remove some unused variables in dwarf2read.c

Most of them are obvious.  The ones in dwarf2_record_block_ranges are
less obvious, because it is a bit suspicious to have that many
variables unused.  But after inspection, it seems like it dates from
commit 5f46c5a54825 ("Code cleanup: Split dwarf2_ranges_read to a
callback"), where dwarf2_record_block_ranges was made to use
dwarf2_ranges_process, which contains the same functionality.

gdb/ChangeLog:

* dwarf2read.c (create_signatured_type_table_from_debug_names):
Remove unused variables.
(dw2_map_symtabs_matching_filename): Likewise.
(dwarf2_record_block_ranges): Likewise.
(dwarf2_read_addr_index): Likewise.
(follow_die_offset): Likewise.

6 years agoDefer breakpoint reset when cloning progspace for fork child
Simon Marchi [Sat, 7 Apr 2018 17:51:59 +0000 (13:51 -0400)]
Defer breakpoint reset when cloning progspace for fork child

Using this simple test:

  static void
  break_here ()
  {
  }

  int
  main (int argc, char *argv[])
  {
    fork ();
    break_here();
    return 0;
  }

compiled as a PIE:

  $ gcc test.c -g3 -O0 -o test -pie

and running this:

  $ ./gdb -nx -q --data-directory=data-directory ./test -ex "b break_here" -ex "set detach-on-fork off" -ex r

gives:

  Warning:
  Cannot insert breakpoint 1.
  Cannot access memory at address 0x64a

Note that GDB might get stopped by SIGTTOU because of this issue:

  https://sourceware.org/bugzilla/show_bug.cgi?id=23020

In that case, just use "fg" to continue.

This issue happens only with position-independent executables.  Adding
the main objfile for the new inferior (the fork child) causes GDB to try
to reset the breakpoints.  However, that new objfile has not been
relocated yet.  So the breakpoint on "break_here" resolves to an
unrelocated address, from which we are trying to read/write to set a
breakpoint.  Passing SYMFILE_DEFER_BP_RESET avoids that problem.  The
executable is relocated just after, in the follow_fork_inferior
function.

The buildbot seems happy with this patch.  I don't think it's necessary
to add a new test.  Just changing this made many tests go from FAIL to
PASS on my machine, where gcc produces PIE executables by default.  If
anything, I think we would need to add a board file that produces
position-independent executables, so that we can run all the tests with
PIE, even on machines where that is not the default.

gdb/ChangeLog:

* progspace.c (clone_program_space): Pass SYMFILE_DEFER_BP_RESET
to symbol_file_add_main.

6 years agoImplement write_async_safe for mi_console_file (PR 22299)
Simon Marchi [Sat, 7 Apr 2018 17:48:05 +0000 (13:48 -0400)]
Implement write_async_safe for mi_console_file (PR 22299)

Enabling "set debug lin-lwp 1" with the MI interpreter doesn't work.
When the sigchld_handler function wants to print a debug output
("sigchld\n"), it uses ui_file_write_async_safe.  This ends up in the
default implementation of ui_file::write_async_safe, which aborts GDB.

This patch implements the write_async_safe method for mi_console_file.
The "normal" MI output is line buffered, which means the output
accumulates in m_buffer until a \n is written, at which point it's
flushed in m_raw.  The implementation of write_async_safe provided by
this patch bypasses this buffer and writes directly to m_raw.  There are
two reasons for this:

(1) Appending to m_buffer (therefore to an std::string) is probably not
    async-safe, as it may allocate memory.
(2) We may have a partial output already in m_buffer, so that would lead
    to some nested MI output, not so great.

There is probably still a chance to have bad MI output, if
sigchld_handler is invoked in the middle of mi_console_file's flush, and
the line being flushed is only partially sent to m_raw.  The solution
would probably be to block signals during flushing.  Since this is only
used for debug output, I don't know if it's worth the effort to do that.

To implement write_async_safe, I needed to use the fputstrn_unfiltered,
which does the necessary escaping (e.g. replace \n with \\n).  I started
by adding printchar's callback parameters to fputstrn_unfiltered, to be
able to pass async-safe versions of them.  It's not easy to provide an
async-safe version of do_fprintf, but it turns out that we can easily
replace printchar's callbacks with a single do_fputc quite easily.  The
async-safe version of do_fputc simply calls the underlying ui_file's
write_async_safe method.

gdb/ChangeLog:

PR mi/22299
* mi/mi-console.c (do_fputc_async_safe): New.
(mi_console_file::write_async_safe): New.
(mi_console_file::flush): Adjust calls to fputstrn_unfiltered.
* mi/mi-console.h (class mi_console_file) <write_async_safe>:
New.
* ui-file.c (ui_file::putstrn): Adjust call to
fputstrn_unfiltered.
* utils.c (printchar): Replace do_fputs and do_fprintf
parameters by do_fputc.
(fputstr_filtered): Adjust call to printchar.
(fputstr_unfiltered): Likewise.
(fputstrn_filtered): Likewise.
(fputstrn_unfiltered): Add do_fputc parameter, pass to
printchar.
* utils.h (do_fputc_ftype): New typedef.
(fputstrn_unfiltered): Add do_fputc parameter.

6 years agoRemove stale file i386-avx.dat
Simon Marchi [Sat, 7 Apr 2018 17:37:17 +0000 (13:37 -0400)]
Remove stale file i386-avx.dat

I noticed that regformats/i386/i386-avx.dat did not get re-generated
when doing "make" in the features directory.  I think it's a leftover
from commit

  f5a29eb0a663 ("Clean up x86 non-linux GDBserver target descriptions")

I build-tested gdbserver with amd64 and i386.

gdb/ChangeLog:

* regformats/i386/i386-avx.dat: Remove.

6 years agoFix generation of x86-64 gdbarch with osabi none (PR 22979)
Simon Marchi [Sat, 7 Apr 2018 17:24:58 +0000 (13:24 -0400)]
Fix generation of x86-64 gdbarch with osabi none (PR 22979)

When a 64-bits (x86-64) gdbarch is created, it is first born as a
32-bits gdbarch in i386_gdbarch_init.  The call gdbarch_init_osabi will
call the handler register for the selected (arch, osabi) pair, such as
amd64_linux_init_abi.  The various amd64 handlers call amd64_init_abi,
which turns the gdbarch into a 64-bits one.

When selecting the i386:x86-64 architecture with no osabi, no such
handler is ever called, so the gdbarch stays (wrongfully) a 32-bits one.

My first idea was to manually call amd64_init_abi & al in
i386_gdbarch_init when the osabi is GDB_OSABI_NONE.  However, this
doesn't work in a build of GDB where i386 is included as a target but
not amd64.  My next option (implemented in this patch), is to allow
registering handlers for GDB_OSABI_NONE.  I added two such handlers in
amd64-tdep.c, so now it works the same as for the "normal" osabis.  It
required re-ordering things in gdbarch_init_osabi to allow running
handlers for GDB_OSABI_NONE.

Without this patch applied (but with the previous one*) :

  (gdb) set osabi none
  (gdb) set architecture i386:x86-64
  The target architecture is assumed to be i386:x86-64
  (gdb) p sizeof(void*)
  $1 = 4

and now:

  (gdb) set osabi none
  (gdb) set architecture i386:x86-64
  The target architecture is assumed to be i386:x86-64
  (gdb) p sizeof(void*)
  $1 = 8

* Before the previous patch, which fixed "set osabi none", this bug was
  hidden because we didn't actually try to generate a gdbarch for no
  osabi, it would always fall back on Linux.  Generating the gdbarch for
  amd64/linux did work.

gdb/ChangeLog:

PR gdb/22979
* amd64-tdep.c (amd64_none_init_abi): New function.
(amd64_x32_none_init_abi): New function.
(_initialize_amd64_tdep): Register handlers for x86-64 and
x64_32 with GDB_OSABI_NONE.
* osabi.c (gdbarch_init_osabi): Allow running handlers for the
GDB_OSABI_NONE osabi.

gdb/testsuite/ChangeLog:

PR gdb/22979
* gdb.arch/amd64-osabi.exp: New file.

6 years agoMake "set osabi none" really work (PR 22980)
Simon Marchi [Sat, 7 Apr 2018 17:23:28 +0000 (13:23 -0400)]
Make "set osabi none" really work (PR 22980)

I was looking for a way to reproduce easily PR 22979 by doing this:

  (gdb) set architecture i386:x86-64
  (gdb) set osabi none

However, I noticed that even though I did "set osabi none", the gdbarch
gdb created was for Linux:

  (gdb) set debug arch 1
  (gdb) set architecture i386:x86-64
  ...
  (gdb) set osabi none
  gdbarch_find_by_info: info.bfd_arch_info i386:x86-64
  gdbarch_find_by_info: info.byte_order 1 (little)
  gdbarch_find_by_info: info.osabi 4 (GNU/Linux)  <--- Wrong?
  gdbarch_find_by_info: info.abfd 0x0
  gdbarch_find_by_info: info.tdep_info 0x0
  gdbarch_find_by_info: Previous architecture 0x1e6fd30 (i386:x86-64)
  selected
  gdbarch_update_p: Architecture 0x1e6fd30 (i386:x86-64) unchanged

This is because the value GDB_OSABI_UNKNOWN has an unclear role,
sometimes meaning "no osabi" and sometimes "please selected
automatically".  Doing "set osabi none" sets the requested osabi to
GDB_OSABI_UNKNOWN, in which case gdbarch_info_fill overrides it with a
value from the target description, or the built-in default osabi.  This
means that it's impossible to force GDB not to use an osabi with "set
osabi".  Since my GDB's built-in default osabi is Linux, it always falls
back to GDB_OSABI_LINUX.

To fix it, I introduced GDB_OSABI_NONE, which really means "I don't want
any osabi".  GDB_OSABI_UNKNOWN can then be used only for "not set yet,
please auto-detect".  GDB_OSABI_UNINITIALIZED now seems unnecessary
since it overlaps with GDB_OSABI_UNKNOWN, so I think it can be removed
and gdbarch_info::osabi can be initialized to GDB_OSABI_UNKNOWN.

gdb/ChangeLog:

PR gdb/22980
* defs.h (enum gdb_osabi): Remove GDB_OSABI_UNINITIALIZED, add
GDB_OSABI_NONE.
* arch-utils.c (gdbarch_info_init): Don't set info->osabi.
* osabi.c (gdb_osabi_names): Add "unknown" entry.

gdb/testsuite/ChangeLog:

PR gdb/22980
* gdb.base/osabi.exp: New file.

6 years agoMake target_read_alloc & al return vectors
Simon Marchi [Sat, 7 Apr 2018 17:19:12 +0000 (13:19 -0400)]
Make target_read_alloc & al return vectors

This patch started by changing target_read_alloc_1 to return a
byte_vector, to avoid manual memory management (in target_read_alloc_1
and in the callers).  To communicate failures to the callers, it
actually returns a gdb::optional<gdb::byte_vector>.

Adjusting target_read_stralloc was a bit more tricky, since it wants to
return a buffer of char, and not gdb_byte.  Since you can't just cast a
gdb::byte_vector into a gdb::def_vector<char>, I made
target_read_alloc_1 templated, so both versions (that return vectors of
gdb_byte and char) are generated.  Since target_read_stralloc now
returns a gdb::char_vector instead of a gdb::unique_xmalloc_ptr<char>, a
few callers need to be adjusted.

gdb/ChangeLog:

* common/byte-vector.h (char_vector): New type.
* target.h (target_read_alloc): Return
gdb::optional<byte_vector>.
(target_read_stralloc): Return gdb::optional<char_vector>.
(target_get_osdata): Return gdb::optional<char_vector>.
* target.c (target_read_alloc_1): Templatize.  Replacement
manual memory management with vector.
(target_read_alloc): Change return type, adjust.
(target_read_stralloc): Change return type, adjust.
(target_get_osdata): Change return type, adjust.
* auxv.c (struct auxv_info) <length>: Remove.
<data>: Change type to gdb::optional<byte_vector>.
(auxv_inferior_data_cleanup): Free auxv_info with delete.
(get_auxv_inferior_data): Allocate auxv_info with new, adjust.
(target_auxv_search): Adjust.
(fprint_target_auxv): Adjust.
* avr-tdep.c (avr_io_reg_read_command): Adjust.
* linux-tdep.c (linux_spu_make_corefile_notes): Adjust.
(linux_make_corefile_notes): Adjust.
* osdata.c (get_osdata): Adjust.
* remote.c (remote_get_threads_with_qxfer): Adjust.
(remote_memory_map): Adjust.
(remote_traceframe_info): Adjust.
(btrace_read_config): Adjust.
(remote_read_btrace): Adjust.
(remote_pid_to_exec_file): Adjust.
* solib-aix.c (solib_aix_get_library_list): Adjust.
* solib-dsbt.c (decode_loadmap): Don't free buf.
(dsbt_get_initial_loadmaps): Adjust.
* solib-svr4.c (svr4_current_sos_via_xfer_libraries): Adjust.
* solib-target.c (solib_target_current_sos): Adjust.
* tracepoint.c (sdata_make_value): Adjust.
* xml-support.c (xinclude_start_include): Adjust.
(xml_fetch_content_from_file): Adjust.
* xml-support.h (xml_fetch_another): Change return type.
(xml_fetch_content_from_file): Change return type.
* xml-syscall.c (xml_init_syscalls_info): Adjust.
* xml-tdesc.c (file_read_description_xml): Adjust.
(fetch_available_features_from_target): Change return type.
(target_fetch_description_xml): Adjust.
(target_read_description_xml): Adjust.

6 years agoFurther improve warnings for relocations referring to discarded sections.
Cary Coutant [Fri, 6 Apr 2018 23:06:16 +0000 (16:06 -0700)]
Further improve warnings for relocations referring to discarded sections.

Relocations referring to discarded sections are now treated as errors
instead of warnings.

Also with this patch, we will now print the section group signature and the
object file with the prevailing definition of that group along with the
name of the symbol that the relocation is referring to. This additional
information should be much more useful to anyone trying to track down
the source of such errors.

To do so, we now map each discarded section to the Kept_section info in
the Layout class, and defer the logic that maps a discarded section to
its counterpart in the kept group. This gives us the information we need
to identify the signature symbol given the discarded section, and the
name of the object file that provided the prevailing (i.e., first)
definition of that group.

gold/
* object.cc (Sized_relobj_file::include_section_group): Store
reference to Kept_section info for discarded comdat sections
regardless of size.  Move size checking to map_to_kept_section.
(Sized_relobj_file::include_linkonce_section): Likewise.
(Sized_relobj_file::map_to_kept_section): Add section name parameter.
Insert size checking logic from above functions.
(Sized_relobj_file::find_kept_section_object): New method.
(Sized_relobj_file::get_symbol_name): New method.
* object.h (Sized_relobj_file::map_to_kept_section): Add section_name
parameter.  Adjust all callers.
(Sized_relobj_file::find_kept_section_object): New method.
(Sized_relobj_file::get_symbol_name): New method.
(Sized_relobj_file::Kept_comdat_section): Replace object and shndx
fields with sh_size, kept_section, symndx, and is_comdat fields.
(Sized_relobj_file::set_kept_comdat_section): Replace kept_object
and kept_shndx parameters with is_comdat, symndx, sh_size, and
kept_section.
(Sized_relobj_file::get_kept_comdat_section): Likewise.
* target-reloc.h (enum Comdat_behavior): Change CB_WARNING to CB_ERROR.
Adjust all references.
(issue_undefined_symbol_error): New function template.
(relocate_section): Pass section name to map_to_kept_section.
Move discarded section code to new function above.
* aarch64.cc (Target_aarch64::scan_reloc_section_for_stubs): Move
declaration for gsym out one level.  Call issue_discarded_error.
* arm.cc (Target_arm::scan_reloc_section_for_stubs): Likewise.
* powerpc.cc (Relocate_comdat_behavior): Change CB_WARNING to CB_ERROR.

6 years agoAutomatic date update in version.in
GDB Administrator [Sat, 7 Apr 2018 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoChange value::contents to be a unique_xmalloc_ptr
Tom Tromey [Wed, 4 Apr 2018 22:34:33 +0000 (16:34 -0600)]
Change value::contents to be a unique_xmalloc_ptr

This changes value::contents to be a unique_xmalloc_ptr, removing a
small bit of manual memory management.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.c (~value): Update.
(struct value) <contents>: Now unique_xmalloc_ptr.
(value_contents_bits_eq, allocate_value_contents)
(value_contents_raw, value_contents_all_raw)
(value_contents_for_printing, value_contents_for_printing_const)
(set_value_enclosing_type): Update.

6 years agoRemove range_s VEC
Tom Tromey [Wed, 4 Apr 2018 22:32:14 +0000 (16:32 -0600)]
Remove range_s VEC

This changes the "optimized_out" and "unavailable" VECs in struct
value to be std::vectors, and then fixes up all the uses.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.c (range_s): Remove typedef, VEC.
(struct range): Add operator<.
(range_lessthan): Remove.
(ranges_contain): Change type.
(~value): Update.
(struct value) <unavailable, optimized_out>: Now std::vector.
(value_entirely_available)
(value_entirely_covered_by_range_vector)
(value_entirely_unavailable, value_entirely_optimized_out):
Update.
(insert_into_bit_range_vector): Change argument type.
(find_first_range_overlap): Likewise.
(struct ranges_and_idx, value_contents_bits_eq)
(require_not_optimized_out, require_available): Update.
(ranges_copy_adjusted): Change argument types.
(value_optimized_out, value_copy, value_fetch_lazy): Update.

6 years agoChange value::parent to a value_ref_ptr
Tom Tromey [Wed, 4 Apr 2018 22:08:42 +0000 (16:08 -0600)]
Change value::parent to a value_ref_ptr

This changes value::parent to a value_ref_ptr.  This removes a bit of
manual reference count management.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.c (~value): Update.
(struct value) <parent>: Now a value_ref_ptr.
(value_parent, set_value_parent, value_address, value_copy):
Update.

6 years agoUse new and delete for values
Tom Tromey [Wed, 4 Apr 2018 21:57:51 +0000 (15:57 -0600)]
Use new and delete for values

This adds a constructor and destructor to struct value, and then
changes value.c to use "new" and "delete".

While doing this I noticed a memory leak -- value_decref was not
freeing value::optimized_out.  This patch fixes this leak.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.c (struct value): Add constructor, destructor, and member
initializers.
(allocate_value_lazy, value_decref): Update.

6 years agoRemove value::next and value::released
Tom Tromey [Wed, 4 Apr 2018 03:52:31 +0000 (21:52 -0600)]
Remove value::next and value::released

This patch converts all_values to simply hold a list of references to
values.  Now, there's no need to have a value record whether or not it
is released -- there is only a single reference-counting mechanism for
values.  So, this also removes value::next, value::released, and
value_next.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.c (struct value) <released, next>: Remove.
(all_values): Now a std::vector.
(allocate_value_lazy): Update.
(value_next): Remove.
(value_mark, value_free_to_mark, release_value)
(value_release_to_mark): Update.

6 years agoRemove free_value_chain
Tom Tromey [Wed, 4 Apr 2018 02:20:01 +0000 (20:20 -0600)]
Remove free_value_chain

This patch changes value_release_to_mark and fetch_subexp_value to
return a std::vector of value references, rather than relying on the
"next" field that is contained in a struct value.  This makes it
simpler to reason about the returned values, and also allows for the
removal of free_value_chain.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.h (fetch_subexp_value, value_release_to_mark): Update.
(free_value_chain): Remove.
* value.c (free_value_chain): Remove.
(value_release_to_mark): Return a std::vector.
* ppc-linux-nat.c (num_memory_accesses): Change "chain" to a
std::vector.
(check_condition): Update.
* eval.c (fetch_subexp_value): Change "val_chain" to a
std::vector.
* breakpoint.c (update_watchpoint): Update.
(can_use_hardware_watchpoint): Change "vals" to a std::vector.

6 years agoRemove free_all_values
Tom Tromey [Wed, 4 Apr 2018 00:31:01 +0000 (18:31 -0600)]
Remove free_all_values

free_all_values is unused, so this removes it.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.h (free_all_values): Remove.
* value.c (free_all_values): Remove.

6 years agoChange value history to use value_ref_ptr
Tom Tromey [Wed, 4 Apr 2018 00:23:30 +0000 (18:23 -0600)]
Change value history to use value_ref_ptr

This simplifies the value history implementation by replacing the
current data structure with a std::vector, and by making the value
history simply hold a reference to each value.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.c (VALUE_HISTORY_CHUNK, struct value_history_chunk)
(value_history_chain, value_history_count): Remove.
(value_history): New global.
(record_latest_value, access_value_history, show_values)
(preserve_values): Update.

6 years agoChange varobj to use value_ref_ptr
Tom Tromey [Wed, 4 Apr 2018 00:15:13 +0000 (18:15 -0600)]
Change varobj to use value_ref_ptr

This changes varobj to use value_ref_ptr, allowing the removal of some
manual reference count management.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* varobj.h (struct varobj) <value>: Now a value_ref_ptr.
* varobj.c (varobj_set_display_format, varobj_set_value)
(install_default_visualizer, construct_visualizer)
(install_new_value, ~varobj, varobj_get_value_type)
(my_value_of_variable, varobj_editable_p): Update.
* c-varobj.c (c_describe_child, c_value_of_variable)
(cplus_number_of_children, cplus_describe_child): Update.
* ada-varobj.c (ada_number_of_children, ada_name_of_child)
(ada_path_expr_of_child, ada_value_of_child, ada_type_of_child)
(ada_value_of_variable, ada_value_is_changeable_p): Update.

6 years agoChange last_examine_value to value_ref_ptr
Tom Tromey [Wed, 4 Apr 2018 00:03:32 +0000 (18:03 -0600)]
Change last_examine_value to value_ref_ptr

This patch removes some manual reference count manipulation by
changing last_examine_value to be a value_ref_ptr and then updating
the users.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* printcmd.c (last_examine_address): Change type to
value_ref_ptr.
(do_examine, x_command): Update.

6 years agoChange breakpoints to use value_ref_ptr
Tom Tromey [Tue, 3 Apr 2018 23:58:58 +0000 (17:58 -0600)]
Change breakpoints to use value_ref_ptr

Now that value_ref_ptr exists, it is possible to simplify breakpoint
and bpstat memory management by using a value_ref_ptr rather than
manually handling the reference counts.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* value.c (release_value): Update.
* breakpoint.h (struct watchpoint) <val>: Now a value_ref_ptr.
(struct bpstats) <val>: Now a value_ref_ptr.
* breakpoint.c (update_watchpoint, breakpoint_init_inferior)
(~bpstats, bpstats, bpstat_clear_actions, watchpoint_check)
(~watchpoint, print_it_watchpoint, watch_command_1)
(invalidate_bp_value_on_memory_change): Update.

6 years agoIntroduce a gdb_ref_ptr specialization for struct value
Tom Tromey [Tue, 3 Apr 2018 23:45:21 +0000 (17:45 -0600)]
Introduce a gdb_ref_ptr specialization for struct value

struct value is internally reference counted and so, while it also has
some ownership rules unique to it, it makes sense to use a gdb_ref_ptr
when managing it automatically.

This patch removes the existing unique_ptr specialization in favor of
a reference-counted pointer.  It also introduces two other
clarifications:

1. Rename value_free to value_decref, which I think is more in line
   with what the function actually does; and

2. Change release_value to return a gdb_ref_ptr.  This change allows
   us to remove the confusing release_value_or_incref function,
   primarily by making it much simpler to reason about the result of
   release_value.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

* varobj.c (varobj_clear_saved_item)
(update_dynamic_varobj_children, install_new_value, ~varobj):
Update.
* value.h (value_incref): Move declaration earlier.
(value_decref): Rename from value_free.
(struct value_ref_policy): New.
(value_ref_ptr): New typedef.
(struct value_deleter): Remove.
(gdb_value_up): Remove typedef.
(release_value): Change return type.
(release_value_or_incref): Remove.
* value.c (set_value_parent): Update.
(value_incref): Change return type.
(value_decref): Rename from value_free.
(value_free_to_mark, free_all_values, free_value_chain): Update.
(release_value): Return value_ref_ptr.
(release_value_or_incref): Remove.
(record_latest_value, set_internalvar, clear_internalvar):
Update.
* stack.c (info_frame_command): Don't call value_free.
* python/py-value.c (valpy_dealloc, valpy_new)
(value_to_value_object): Update.
* printcmd.c (do_examine): Update.
* opencl-lang.c (lval_func_free_closure): Update.
* mi/mi-main.c (register_changed_p): Don't call value_free.
* mep-tdep.c (mep_frame_prev_register): Don't call value_free.
* m88k-tdep.c (m88k_frame_prev_register): Don't call value_free.
* m68hc11-tdep.c (m68hc11_frame_prev_register): Don't call
value_free.
* guile/scm-value.c (vlscm_free_value_smob)
(vlscm_scm_from_value): Update.
* frame.c (frame_register_unwind, frame_unwind_register_signed)
(frame_unwind_register_unsigned, get_frame_register_bytes)
(put_frame_register_bytes): Don't call value_free.
* findvar.c (address_from_register): Don't call value_free.
* dwarf2read.c (dwarf2_compute_name): Don't call value_free.
* dwarf2loc.c (entry_data_value_free_closure)
(value_of_dwarf_reg_entry, free_pieced_value_closure)
(dwarf2_evaluate_loc_desc_full): Update.
* breakpoint.c (update_watchpoint, breakpoint_init_inferior)
(~bpstats, bpstats, bpstat_clear_actions, watchpoint_check)
(~watchpoint, watch_command_1)
(invalidate_bp_value_on_memory_change): Update.
* alpha-tdep.c (alpha_register_to_value): Don't call value_free.

6 years agoAdd -Wno-error=deprecated-register to gdb build flags
Simon Marchi [Fri, 6 Apr 2018 20:11:51 +0000 (16:11 -0400)]
Add -Wno-error=deprecated-register to gdb build flags

As shown in PR 23022, building with clang-6 and Python 2 trips on the
fact that the Python 2 headers use the "register" keyword:

/usr/include/python2.7/unicodeobject.h:534:5: error: 'register' storage class specifier is deprecated and incompatible with C++17 [-Werror,-Wdeprecated-register]
    register PyObject *obj,     /* Object */
    ^~~~~~~~~

This patch adds -Wno-error=deprecated-register to our flags, so that we can
still see this class of warnings, but they don't cause a build failure.

gdb/ChangeLog:

PR gdb/23022
* warning.m4: Add -Wno-error=deprecated-register.
* configure: Re-generate.

6 years agoDisplay all DWARF 5 language names
Tom Tromey [Thu, 5 Apr 2018 16:52:29 +0000 (10:52 -0600)]
Display all DWARF 5 language names

I happened to notice that objdump was not printing "Rust" when showing
the DW_AT_language for a CU:

    <10>   DW_AT_language    : 28 (Unknown: 1c)

This patch adds all the new language constants from DWARF 5 to
binutils/dwarf.c.

2018-04-06  Tom Tromey  <tom@tromey.com>

* dwarf.c (read_and_display_attr_value): Add missing DW_LANG
constants from DWARF 5.

6 years agox86-64: Don't mask out R_X86_64_converted_reloc_bit
H.J. Lu [Fri, 6 Apr 2018 12:06:08 +0000 (05:06 -0700)]
x86-64: Don't mask out R_X86_64_converted_reloc_bit

R_X86_64_converted_reloc_bit is set in elf_x86_64_convert_load_reloc
which is called from elf_x86_64_check_relocs.  Since it is used only
internally by linker, there is no need to mask it out in
elf_x86_64_info_to_howto.

* elf64-x86-64.c (elf_x86_64_info_to_howto): Don't mask out
R_X86_64_converted_reloc_bit.

6 years agoAutomatic date update in version.in
GDB Administrator [Fri, 6 Apr 2018 00:00:46 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoUse dlsym to check if libdl is needed for plugin
H.J. Lu [Thu, 5 Apr 2018 22:31:41 +0000 (15:31 -0700)]
Use dlsym to check if libdl is needed for plugin

config/plugins.m4 has

 if test "$plugins" = "yes"; then
    AC_SEARCH_LIBS([dlopen], [dl])
  fi

Plugin uses dlsym, but libasan.so only intercepts dlopen, not dlsym:

[hjl@gnu-tools-1 binutils-text]$ nm -D /lib64/libasan.so.4| grep " dl"
0000000000038580 W dlclose
                 U dl_iterate_phdr
000000000004dc50 W dlopen
                 U dlsym
                 U dlvsym
[hjl@gnu-tools-1 binutils-text]$

Testing dlopen for libdl leads to false negative when -fsanitize=address
is used.  It results in link failure:

../bfd/.libs/libbfd.a(plugin.o): undefined reference to symbol 'dlsym@@GLIBC_2.16'

dlsym should be used to check if libdl is needed for plugin.

bfd/

PR gas/22318
* configure: Regenerated.

binutils/

PR gas/22318
* configure: Regenerated.

gas/

PR gas/22318
* configure: Regenerated.

gprof/

PR gas/22318
* configure: Regenerated.

ld/

PR gas/22318
* configure: Regenerated.

6 years agoconfig: Sync with GCC
H.J. Lu [Thu, 5 Apr 2018 22:22:13 +0000 (15:22 -0700)]
config: Sync with GCC

Sync with GCC
2018-04-05  H.J. Lu  <hongjiu.lu@intel.com>

PR gas/22318
* plugins.m4 (AC_PLUGINS): Use dlsym to check if libdl is needed.

2018-02-14  Igor Tsimbalist  <igor.v.tsimbalist@intel.com>

PR target/84148
* cet.m4: Check if target support multi-byte NOPS (SSE).

6 years agoImprove warnings for relocations referring to discarded sections.
Cary Coutant [Thu, 5 Apr 2018 21:51:37 +0000 (14:51 -0700)]
Improve warnings for relocations referring to discarded sections.

gold/
* target-reloc.h (relocate_section): Add local symbol index or global
symbol name to warning about relocation that refers to discarded
section.

6 years agoMIPS/binutils/testsuite: Fix `.dc.l' typo in `strip-13mips64.s'
Maciej W. Rozycki [Thu, 5 Apr 2018 21:35:25 +0000 (14:35 -0700)]
MIPS/binutils/testsuite: Fix `.dc.l' typo in `strip-13mips64.s'

Fix a typo: `.dc.w' -> `.dc.l' in `strip-13mips64.s', correcting a bug
from commit 2f8ceb38991e ("binutils/testsuite: Support REL and MIPS64
reloc formats with `strip-13'").  For relocation format correctness only
as there is no observable change in test results due to the lack of
connection between the second relocation entry affected and the examined
error message produced.

binutils/
* testsuite/binutils-all/strip-13mips64.s: Use `.dc.l' rather
than `.dc.w' in second relocation.

6 years agoRevert previous patch and apply revised patch.
Cary Coutant [Thu, 5 Apr 2018 16:41:42 +0000 (09:41 -0700)]
Revert previous patch and apply revised patch.

Revert:

2018-04-05  James Cowgill  <james.cowgill@mips.com>

PR gold/22770
* mips.cc (Mips_got_info::record_got_page_entry): Fetch existing
page entries for the object's GOT.

Apply:

PR gold/22770
* mips.cc (Mips_got_info::record_got_page_entry): Don't insert
Got_page_entry for object's GOT.
(Mips_got_info::add_got_page_entries): Add all pages from from's GOT.
Rename to add_got_page_count.
(Got_page_entry): Remove num_pages.

6 years agoMIPS: Fix GOT page counter in multi-got links
James Cowgill [Thu, 5 Apr 2018 15:47:53 +0000 (08:47 -0700)]
MIPS: Fix GOT page counter in multi-got links

The record_got_page_entry function records and updates the maximum
number of GOT page entries which may be required by an object. In the
case where an existing GOT page entry was expanded, only the entry
belonging to output GOT would have its page count updated. This leaves
the entry belonging to the object GOT with the num_pages count of 1 it
was originally initialized with. Later on when GOTs are being merged in a
multi-got link, this causes the value of entry->num_pages in
add_got_page_entries to always be 1 and underestimates the number of pages
required for the new entry. This in turn leads to an assertion failure in
get_got_page_offset where we run out of pages.

Fix by obtaining the object's GOT entry unconditionally and not just
the first time it gets created. Now that entry2 is always valid, remove
the useless NULL checks.

gold/
PR gold/22770
* mips.cc (Mips_got_info::record_got_page_entry): Fetch existing
page entries for the object's GOT.

6 years agoStop the IA64 linker from removing unwind tables when garbage collecting.
Nick Clifton [Thu, 5 Apr 2018 13:44:05 +0000 (14:44 +0100)]
Stop the IA64 linker from removing unwind tables when garbage collecting.

PR 23030
* emulparams/elf64_ia64.sh (OTHER_READONLY_SECTIONS): Make sure
that the .IA_64.unwind_info and .IA_64.unwind sections are not
subject to garbage collection.

6 years agoRemove unnecessary include from linespec.h
Tom Tromey [Sat, 31 Mar 2018 18:55:32 +0000 (12:55 -0600)]
Remove unnecessary include from linespec.h

linespec.h was inculding vec.h, but doesn't expose any VECs.
So, this include can be removed.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* linespec.h: Remove include of "vec.h".

6 years agoRemove typep and VEC(typep) from linespec.c
Tom Tromey [Sat, 31 Mar 2018 18:52:57 +0000 (12:52 -0600)]
Remove typep and VEC(typep) from linespec.c

This removes VEC(typep) from linespec.c in favor of std::vector.  It
also removes the "typep" typedef.  This change allowed the removal of
some cleanups.

I believe the previous cleanup code in find_superclass_methods could
result in a memory leak, so this patch is an improvement in that way
as well.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* linespec.c (typep): Remove typedef.
(find_methods, find_superclass_methods): Take a std::vector.
(find_method): Use std::vector.

6 years agoMore use of std::vector in linespec.c
Tom Tromey [Sat, 31 Mar 2018 18:43:56 +0000 (12:43 -0600)]
More use of std::vector in linespec.c

This changes some spots in linespec.c to take a std::vector.  This
patch spilled out to objc-lang.c a bit as well.  This change allows
for the removal of some cleanups.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* utils.c (compare_strings): Remove.
* utils.h (compare_strings): Remove.
* objc-lang.h (find_imps): Update.
* objc-lang.c (find_methods): Take a std::vector.
(uniquify_strings, find_imps): Likewise.
* linespec.c (find_methods): Take a std::vector.
(decode_objc): Use std::vector.
(add_all_symbol_names_from_pspace, find_superclass_methods): Take
a std::vector.
(find_method, find_function_symbols): Use std::vector.

6 years agoChange streq to return bool
Tom Tromey [Sun, 1 Apr 2018 15:33:13 +0000 (09:33 -0600)]
Change streq to return bool

I wanted to use streq with std::unique in another (upcoming) patch in
this seres, so I changed it to return bool.  To my surprise, this lead
to regressions.  The cause turned out to be that streq was used as an
htab callback -- by casting it to the correct function type.  This
sort of cast is invalid, so this patch adds a variant which is
directly suitable for use by htab.  (Note that I did not add an
overload, as I could not get that to work with template deduction in
the other patch.)

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* completer.c (completion_tracker::completion_tracker): Remove
cast.
(completion_tracker::discard_completions): Likewise.
* breakpoint.c (ambiguous_names_p): Remove cast.
* ada-lang.c (_initialize_ada_language): Remove cast.
* utils.h (streq): Update.
(streq_hash): Add new declaration.
* utils.c (streq): Return bool.
(streq_hash): New function.

6 years agoRemove a string copy from event_location_to_sals
Tom Tromey [Sat, 31 Mar 2018 18:21:10 +0000 (12:21 -0600)]
Remove a string copy from event_location_to_sals

The use of "const" showed that a string copy in event_location_to_sals
was unnecessary.  This patch removes it.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* linespec.c (event_location_to_sals) <case ADDRESS_LOCATION>:
Remove a string copy.

6 years agoHave filter_results take a std::vector
Tom Tromey [Sat, 31 Mar 2018 18:16:54 +0000 (12:16 -0600)]
Have filter_results take a std::vector

This chagnes filter_results to take a std::vector, allowing the
removal of some cleanups in its callers.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* linespec.c (filter_results): Use std::vector.
(decode_line_2, decode_line_full): Update.

6 years agoReturn std::string from canonical_to_fullform
Tom Tromey [Sat, 31 Mar 2018 17:01:55 +0000 (11:01 -0600)]
Return std::string from canonical_to_fullform

This changes canonical_to_fullform to return a std::string, and
changes decode_line_2 to use std::vector.  This allows for the removal
of some cleanups.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* linespec.c (canonical_to_fullform): Return std::string.
(filter_results): Update.
(struct decode_line_2_item): Add constructor.
<fullform, displayform>: Now std::string.
(decode_line_2_compare_items): Now a std::sort comparator.
(decode_line_2): Update.

6 years agoMake copy_token_string return unique_xmalloc_ptr
Tom Tromey [Sat, 11 Nov 2017 18:09:52 +0000 (11:09 -0700)]
Make copy_token_string return unique_xmalloc_ptr

This changes copy_token_string to return a unique_xmalloc_ptr, which
allows the removal of some cleanups.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* linespec.c (copy_token_string): Return a unique_xmalloc_ptr.
(unexpected_linespec_error): Update.
(linespec_parse_basic, parse_linespec): Update.

6 years agoFix some indentation in linespec.c
Tom Tromey [Sat, 31 Mar 2018 16:54:25 +0000 (10:54 -0600)]
Fix some indentation in linespec.c

This removes some leftover comments and fixes the indentation in a
couple of spots in linespec.c.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* linespec.c (linespec_parse_basic): Reindent.

6 years agoRemove some cleanups from search_minsyms_for_name
Tom Tromey [Sat, 31 Mar 2018 16:32:00 +0000 (10:32 -0600)]
Remove some cleanups from search_minsyms_for_name

This changes struct collect_minsyms to use a std::vector, which
enables the removal of a cleanup from search_minsyms_for_name.  This
also changes iterate_over_minimal_symbols to take a
gdb::function_view, which makes a function in linespec.c more
type-safe.

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

* minsyms.h (iterate_over_minimal_symbols): Update.
* minsyms.c (iterate_over_minimal_symbols): Take a
gdb::function_view.
* linespec.c (struct collect_minsyms): Remove.
(compare_msyms): Now a std::sort comparator.
(add_minsym): Add parameters.
(search_minsyms_for_name): Update.  Use std::vector.

6 years agobinutils/testsuite: Tighten the error message check with `strip-13'
Maciej W. Rozycki [Thu, 5 Apr 2018 12:08:35 +0000 (13:08 +0100)]
binutils/testsuite: Tighten the error message check with `strip-13'

Avoid false positives and actually verify both that an `unsupported
relocation type 0x8f' message is produced and that no other message is,
except for the final `bad value', in the `strip-13' test.  This ensures
that it is a relocation processing error and not a different issue that
has caused `strip' to terminate unsuccessfully, and that the number
representing the unsupported relocation has not been clobbered.

binutils/
* testsuite/binutils-all/strip-13.d: Also expect `unsupported
relocation type 0x8f' error message.

6 years agobinutils/testsuite: Support REL and MIPS64 reloc formats with `strip-13'
Maciej W. Rozycki [Thu, 5 Apr 2018 12:08:35 +0000 (13:08 +0100)]
binutils/testsuite: Support REL and MIPS64 reloc formats with `strip-13'

Add source variants for the `strip-13' test that produce relocations in
the REL and MIPS64 formats, fixing a failure for the `mips64el-openbsd'
target.  This also corrects output for `i*86-*', `i960-*', `m6812-*' and
`m68hc12-*', o32 `mips*-*', and `score*-*' targets, which however does
not show up as a test result change due to lax error message matching
causing `bad value' previously produced by `strip' as a result of input
file rejection to be accepted as a test pass.

For `m6811-*' aka `m68hc11-*' targets this causes a phantom regression,
because they use 16-bit addressing and therefore `.dc.a' emits 16-bit
quantities causing relocation data constructed in assembly not to be as
expected.  Previously input was rejected by `strip' with a `bad value'
message and now it is accepted, however due to the relocation data error
the relocation number is not one of the unsupported ones and the tool
completes successfully, which scores as a test failure.

Disable the test case for `m6811-*' and `m68hc11-*' targets then, as it
is a test case bug rather than a problem with the relevant backend.  A
separate change to the test case is required to correct this problem, at
which point the test case can be enabled for the affected targets.

binutils/
* testsuite/binutils-all/strip-13.s: Rename to...
* testsuite/binutils-all/strip-13rela.s: ... this.
* testsuite/binutils-all/strip-13rel.s: New test source.
* testsuite/binutils-all/strip-13mips64.s: New test source.
* testsuite/binutils-all/strip-13.d: Remove `arm-*', `d10v-*',
`dlx-*' and `xgate-*' from `not-target' list.  Add `m6811-*' and
`m68hc11-*' to `not-target' list.
* testsuite/binutils-all/objcopy.exp: Switch between sources for
`strip-13'.

6 years agobinutils/testsuite: Enable `strip-13' test for `hppa*-*'
Maciej W. Rozycki [Thu, 5 Apr 2018 12:08:35 +0000 (13:08 +0100)]
binutils/testsuite: Enable `strip-13' test for `hppa*-*'

Based on relocations defined in include/elf/*.h files we have relocation
numbers: 143, 159, 214 and 215 currently not used by any of our ELF
targets.  Use 143 then instead of 241 to enable the `strip-13' test for
`hppa*-*' targets.  It has a side effect with some targets of verifying
that unused relocations whose numbers are below the respective R_*_max
value are handled correctly.

binutils/
* testsuite/binutils-all/strip-13.s: Use 143 (0x8f) rather than
241 (0xf1) for the relocation number and RELA addend.
* testsuite/binutils-all/strip-13.d: Remove `hppa*-*' from the
`not-target' list.

6 years agoAutomatic date update in version.in
GDB Administrator [Thu, 5 Apr 2018 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years ago[GOLD] Make powerpc64 .branch_lt relro
Alan Modra [Wed, 4 Apr 2018 07:40:36 +0000 (17:10 +0930)]
[GOLD] Make powerpc64 .branch_lt relro

Better security beats better placement for code optimization.

* powerpc.cc (Target_powerpc::make_brlt_section): Make .branch_lt relro.

6 years agoelf-hppa.h warning fix
Alan Modra [Wed, 4 Apr 2018 02:30:22 +0000 (12:00 +0930)]
elf-hppa.h warning fix

* elf-hppa.h (elf_hppa_info_to_howto): Init howto to NULL.
(elf_hppa_info_to_howto_rel): Likewise.

6 years ago * binutils/MAINTAINERS: Update e-mail address.
John David Anglin [Wed, 4 Apr 2018 22:29:17 +0000 (18:29 -0400)]
* binutils/MAINTAINERS: Update e-mail address.

6 years agoi386: Clear vex instead of vex.evex
H.J. Lu [Wed, 4 Apr 2018 11:36:44 +0000 (04:36 -0700)]
i386: Clear vex instead of vex.evex

"vex" has many fields to control how to decode an instruction.  Clear
all fields in "vex" before decoding an instruction to avoid using values
left from the previous instruction.

gas/

PR binutils/23025
* testsuite/gas/i386/prefix.s: Add tests for vcvtpd2dq with
VEX and EVEX prefixes.
* testsuite/gas/i386/prefix.d: Updated.

opcodes/

PR binutils/23025
* i386-dis.c (get_valid_dis386): Don't set vex.prefix nor vex.w
to 0.
(print_insn): Clear vex instead of vex.evex.

6 years agoAdd blurb about linker changes for Cygwin and Mingw targets.
Eric Botcazou [Wed, 4 Apr 2018 10:18:09 +0000 (12:18 +0200)]
Add blurb about linker changes for Cygwin and Mingw targets.

6 years agoSpeed up direct linking with DLLs on Windows (2/2).
Eric Botcazou [Wed, 4 Apr 2018 10:13:05 +0000 (12:13 +0200)]
Speed up direct linking with DLLs on Windows (2/2).

This patch deals with the generation of the import library on the fly.

The implementation is inefficient because the linker makes a lot of
calls to realloc and memmove when importing the symbols in order to
maintain a sorted list of symbols.

This is fixable by relying on the fact that, for every linked DLL,
the list of symbols it exports is already sorted so you can import
them en masse once you have found the insertion point.

ld/
* deffile.h (def_file_add_import_from): Declare.
(def_file_add_import_at): Likewise.
* deffilep.y (fill_in_import): New function extracted from...
(def_file_add_import): ...here.  Call it.
(def_file_add_import_from): New function.
(def_file_add_import_at): Likewise.
* pe-dll.c (pe_implied_import_dll): Use an optimized version of the
insertion loop for imported symbols if possible.

6 years agoSpeed up direct linking with DLLs on Windows (1/2).
Eric Botcazou [Wed, 4 Apr 2018 10:07:50 +0000 (12:07 +0200)]
Speed up direct linking with DLLs on Windows (1/2).

This patch deals with the auto-import feature.  There are 2 versions
of this feature: the original one, which was piggybacked on the OS
loader with an optional help from the runtime (--enable-auto-import
--enable-runtime-pseudo-reloc-v1) and is still the one mostly
documented in the sources and manual; the enhanced one by Kai Tietz,
which is entirely piggybacked on the runtime (--enable-auto-import
--enable-runtime-pseudo-reloc-v2) and is the default for Mingw and
Cygwin nowadays.

The implementation is inefficient because of pe[p]_find_data_imports:
for every undefined symbol, the function walks the entire set of
relocations for all the input files and does a direct name comparison
for each of them.

This is easily fixable by using a hash-based map for v1 and a simple
hash table for v2.  This patch leaves v1 alone and only changes v2.
It also factors out pe[p]_find_data_imports into a common function,
removes old cruft left and right, and attempts to better separate
the implementations of v1 and v2 in the code.

ld/
* emultempl/pe.em (U_SIZE): Delete.
(pe_data_import_dll): Likewise.
(make_import_fixup): Return void, take 4th parameter and pass it down
in call to pe_create_import_fixup.
(pe_find_data_imports): Move to...
(gld_${EMULATION_NAME}_after_open): Run the stdcall fixup pass after
the auto-import pass and add a guard before running the latter.
* emultempl/pep.em (U_SIZE): Delete.
(pep_data_import_dll): Likewise.
(make_import_fixup): Return void, take 4th parameter and pass it down
in call to pe_create_import_fixup.
(pep_find_data_imports): Move to...
(gld_${EMULATION_NAME}_after_open): Run the stdcall fixup pass after
the auto-import pass and add a guard before running the latter.
* pe-dll.c (runtime_pseudp_reloc_v2_init): Change type to bfd_boolean.
(pe_walk_relocs_of_symbol): Rename into...
(pe_walk_relocs): ...this.  Add 2 more parameters,4th parameter to the
callback prototype and pass 4th parameter in calls to the callback.
If the import hash table is present, invoke the callback on the reloc
if the symbol name is in the table.
(pe_find_data_imports): ...here.  Take 2 parameters.  Build an import
hash table for the pseudo-relocation support version 2.  When it is
built, walk the relocations only once at the end; when it is not, do
not build a fixup when the symbol isn't part of an import table.
Issue the associated warning only after a first fixup is built.
(tmp_seq2): Delete.
(make_singleton_name_imp): Likewise.
(make_import_fixup_mark): Return const char * and a stable string.
(make_import_fixup_entry): Do not deal with the pseudo-relocation
support version 2.
(make_runtime_pseudo_reloc): Factor out code and fix formatting.
(pe_create_import_fixup): Add 5th parameter.  Clearly separate the
pseudo-relocation support version 2 from the rest.  Fix formatting.
* pe-dll.h (pe_walk_relocs_of_symbol): Delete.
(pe_find_data_imports): Declare.
(pe_create_import_fixup): Add 5th parameter.
* pep-dll.c (pe_data_import_dll): Delete.
(pe_find_data_imports): Define.
(pe_walk_relocs_of_symbol): Delete.
* pep-dll.h (pep_walk_relocs_of_symbol): Delete.
(pep_find_data_imports): Declare.
(pep_create_import_fixup): Add 5th parameter.
* ld.texinfo (--enable-auto-import): Adjust to new implementation.

6 years agoUpdate Spanish translations for ld/ opcodes/ and gold/ sub-directories
Nick Clifton [Wed, 4 Apr 2018 08:00:18 +0000 (09:00 +0100)]
Update Spanish translations for ld/ opcodes/ and gold/ sub-directories

6 years agoRetire Jason Eckhardt as i860 maintainer.
Nick Clifton [Wed, 4 Apr 2018 07:35:19 +0000 (08:35 +0100)]
Retire Jason Eckhardt as i860 maintainer.

* MAINTAINERS: Move Jason Eckhardt to past maintainers section.

6 years agoPR binutils/22875: HPPA/ELF: Also fail with relocation placeholders
Maciej W. Rozycki [Wed, 4 Apr 2018 01:00:49 +0000 (02:00 +0100)]
PR binutils/22875: HPPA/ELF: Also fail with relocation placeholders

Do not consider R_PARISC_UNIMPLEMENTED placeholder relocation entries of
the `elf_hppa_howto_table' table valid in `info_to_howto' HPPA handlers.
Instead issue an unsupported relocation type error and return a NULL
howto as with relocations whose number is R_PARISC_UNIMPLEMENTED or
beyond.

bfd/
* elf-hppa.h (elf_hppa_info_to_howto): Also return
unsuccessfully for unimplemented relocations.
(elf_hppa_info_to_howto_rel): Likewise.

6 years agoPR binutils/22875: i860/ELF: Report unsupported relocation types
Maciej W. Rozycki [Wed, 4 Apr 2018 01:00:49 +0000 (02:00 +0100)]
PR binutils/22875: i860/ELF: Report unsupported relocation types

Complement commit f3185997ac09 ("PR 22875: Stop strip corrupting unknown
relocs"), <https://sourceware.org/ml/binutils/2018-02/msg00445.html>,
and also set the `bfd_error_bad_value' error and report an unsupported
relocation type if a howto lookup fails with the i860 backend, fixing a
confusing `no error' error message and removing a binutils test failure:

failed with: <.../binutils/strip-new: tmpdir/bintest.o: no error>, expected: <.* bad value>
.../binutils/strip-new: tmpdir/bintest.o: no error
FAIL: binutils-all/strip-13

with the `i860-stardent-elf' target.

bfd/
* elf32-i860.c (lookup_howto): Add `abfd' parameter.  Set the
`bfd_error_bad_value' error and call `_bfd_error_handler' on a
howto lookup failure.
(elf32_i860_reloc_type_lookup): Adjust `lookup_howto' call
accordingly.
(elf32_i860_info_to_howto_rela): Likewise.
(elf32_i860_relocate_splitn): Likewise.
(elf32_i860_relocate_pc16): Likewise.
(elf32_i860_relocate_pc26): Likewise.
(elf32_i860_relocate_section): Likewise.

6 years agoPR binutils/22875: Visium/ELF: Prevent an out-of-bounds howto table access
Maciej W. Rozycki [Wed, 4 Apr 2018 01:00:49 +0000 (02:00 +0100)]
PR binutils/22875: Visium/ELF: Prevent an out-of-bounds howto table access

Prevent an out-of-bounds `visium_elf_howto_table' table access in
`visium_info_to_howto_rela' by using the size of the table rather than
R_VISIUM_max to determine the number of entries in the contiguous
regular Visium relocation range defined and described in the table.

bfd/
* elf32-visium.c (visium_info_to_howto_rela): Correct the range
check for `visium_elf_howto_table' table access.

6 years agoPR binutils/22875: IQ2000/ELF: Prevent an out-of-bounds howto table access
Maciej W. Rozycki [Wed, 4 Apr 2018 01:00:49 +0000 (02:00 +0100)]
PR binutils/22875: IQ2000/ELF: Prevent an out-of-bounds howto table access

Prevent an out-of-bounds `iq2000_elf_howto_table' table access in
`iq2000_info_to_howto_rela' by using the size of the table rather than
R_IQ2000_max to determine the number of entries in the contiguous
regular IQ2000 relocation range defined and described in the table.

bfd/
* elf32-iq2000.c (iq2000_info_to_howto_rela): Correct the range
check for `iq2000_elf_howto_table' table access.

6 years agoPR binutils/22875: FRV/ELF: Prevent an out-of-bounds howto table access
Maciej W. Rozycki [Wed, 4 Apr 2018 01:00:48 +0000 (02:00 +0100)]
PR binutils/22875: FRV/ELF: Prevent an out-of-bounds howto table access

Prevent an out-of-bounds `elf32_frv_howto_table' table access in
`frv_info_to_howto_rela' by using the size of the table rather than
R_FRV_max to determine the number of entries in the contiguous regular
FRV relocation range defined and described in the table.

bfd/
* elf32-frv.c (frv_info_to_howto_rela): Correct the range check
for `elf32_frv_howto_table' table access.

6 years agoPR binutils/22875: MIPS/ELF: Also fail with relocation placeholders
Maciej W. Rozycki [Wed, 4 Apr 2018 01:00:48 +0000 (02:00 +0100)]
PR binutils/22875: MIPS/ELF: Also fail with relocation placeholders

Do not consider placeholder EMPTY_HOWTO relocation entries valid in
`rtype_to_howto' MIPS handlers.  Instead issue an unsupported relocation
type error and return a NULL howto as with relocations outside the three
ISA-specific min-max ranges.

bfd/
* elf32-mips.c (mips_elf32_rtype_to_howto): Also return
unsuccessfully for placeholder howtos.
* elf64-mips.c (mips_elf64_rtype_to_howto): Likewise.
* elfn32-mips.c (mips_elf_n32_rtype_to_howto): Likewise.

6 years agoAutomatic date update in version.in
GDB Administrator [Wed, 4 Apr 2018 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoChange read_alphacoff_dynamic_symtab to use gdb::byte_vector
Tom Tromey [Sat, 11 Nov 2017 02:52:33 +0000 (19:52 -0700)]
Change read_alphacoff_dynamic_symtab to use gdb::byte_vector

This changes read_alphacoff_dynamic_symtab to use gdb::byte_vector.
This allows for the removal of some cleanups.

Tested by the buildbot; though I don't know whether this code path is
ever actually run.

gdb/ChangeLog
2018-04-03  Tom Tromey  <tom@tromey.com>

* mipsread.c (read_alphacoff_dynamic_symtab): Use
gdb::byte_vector.

6 years agoMIPS/LD/testsuite: Correct LD emulations for `mips*-*-kfreebsd*-gnu'
Maciej W. Rozycki [Tue, 3 Apr 2018 08:16:44 +0000 (01:16 -0700)]
MIPS/LD/testsuite: Correct LD emulations for `mips*-*-kfreebsd*-gnu'

Complement commit 86b24e15c45b ("MIPS/LD/testsuite: Correct
comm-data.exp test ABI/emul/endian arrangement") and set LD emulations
correctly for `mips*-*-kfreebsd*-gnu' targets in comm-data.exp, removing
test suite failures:

FAIL: MIPS o32/copyreloc common symbol override test (auxiliary shared object build)
FAIL: MIPS o32/copyreloc common symbol override test
FAIL: MIPS o32/nocopyreloc common symbol override test (auxiliary shared object build)
FAIL: MIPS o32/nocopyreloc common symbol override test

ld/
* testsuite/ld-mips-elf/comm-data.exp: Correct support for
`mips*-*-kfreebsd*-gnu' targets.

6 years agoFix problem where mixed section types can cause internal error during a -r link.
Cary Coutant [Mon, 2 Apr 2018 23:12:10 +0000 (16:12 -0700)]
Fix problem where mixed section types can cause internal error during a -r link.

During a -r (or --emit-relocs) link, if two sections had the same name but
different section types, gold would put relocations for both sections into
the same relocation section even though the data sections remained separate.

For .eh_frame sections, when one section is PROGBITS and another is
X86_64_UNWIND, we really should be using the UNWIND section type and
combining the sections anyway.  For other sections, we should be
creating one relocation section for each output data section.

gold/
PR gold/23016
* incremental.cc (can_incremental_update): Check for unwind section
type.
* layout.h (Layout::layout): Add sh_type parameter.
* layout.cc (Layout::layout): Likewise.
(Layout::layout_reloc): Create new output reloc section if data
section does not already have one.
(Layout::layout_eh_frame): Check for unwind section type.
(Layout::make_eh_frame_section): Use unwind section type for .eh_frame
and .eh_frame_hdr.
* object.h (Sized_relobj_file::Shdr_write): New typedef.
(Sized_relobj_file::layout_section): Add sh_type parameter.
(Sized_relobj_file::Deferred_layout::Deferred_layout): Add sh_type
parameter.
* object.cc (Sized_relobj_file::check_eh_frame_flags): Check for
unwind section type.
(Sized_relobj_file::layout_section): Add sh_type parameter; pass it
to Layout::layout.
(Sized_relobj_file::do_layout): Make local copy of sh_type.
Force .eh_frame sections to unwind section type.
Pass sh_type to layout_section.
(Sized_relobj_file<size, big_endian>::do_layout_deferred_sections):
Pass sh_type to layout_section.
* output.cc (Output_section::Output_section): Initialize reloc_section_.
* output.h (Output_section::reloc_section): New method.
(Output_section::set_reloc_section): New method.
(Output_section::reloc_section_): New data member.
* target.h (Target::unwind_section_type): New method.
(Target::Target_info::unwind_section_type): New data member.

* aarch64.cc (aarch64_info): Add unwind_section_type.
* arm.cc (arm_info, arm_nacl_info): Likewise.
* i386.cc (i386_info, i386_nacl_info, iamcu_info): Likewise.
* mips.cc (mips_info, mips_nacl_info): Likewise.
* powerpc.cc (powerpc_info): Likewise.
* s390.cc (s390_info): Likewise.
* sparc.cc (sparc_info): Likewise.
* tilegx.cc (tilegx_info): Likewise.
* x86_64.cc (x86_64_info, x86_64_nacl_info): Likewise.

* testsuite/Makefile.am (pr23016_1, pr23016_2): New test cases.
* testsuite/Makefile.in: Regenerate.
* testsuite/testfile.cc: Add unwind_section_type.
* testsuite/pr23016_1.sh: New test script.
* testsuite/pr23016_1a.s: New source file.
* testsuite/pr23016_1b.s: New source file.
* testsuite/pr23016_2.sh: New test script.
* testsuite/pr23016_2a.s: New source file.
* testsuite/pr23016_2b.s: New source file.

6 years agoAutomatic date update in version.in
GDB Administrator [Tue, 3 Apr 2018 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in

6 years agoAdd myself as a write-after-approval GDB maintainer.
Weimin Pan [Mon, 2 Apr 2018 21:23:59 +0000 (16:23 -0500)]
Add myself as a write-after-approval GDB maintainer.

6 years agoFix merge issues in gdb/ChangeLog and gdb/testsuite/ChangeLog...
Joel Brobecker [Mon, 2 Apr 2018 18:34:11 +0000 (11:34 -0700)]
Fix merge issues in gdb/ChangeLog and gdb/testsuite/ChangeLog...

... introduced by the previous commit to these files.
Also adjust the date in the new ChangeLog entries (out of date).

6 years agoFix infinite recursion when printing static member with typedef
Weimin Pan [Wed, 28 Mar 2018 19:23:48 +0000 (13:23 -0600)]
Fix infinite recursion when printing static member with typedef

The original problem was fixed (see related PR 22242). But using a typedef
as the declared type for a static member variable, as commented in this PR,
is still causing gdb to get into infinite loop when printing the static
member's value. This problem can be reproduced as follows:

% cat t.cc
class A {
    typedef A type;
public:
    bool operator==(const type& other) { return true; }

    static const type INSTANCE;
};

const A A::INSTANCE;

int main() {
    A a;
    if (a == A::INSTANCE) {
        return -1;
    }
    return 0;
}
% g++ -g t.cc
% gdb -ex "start" -ex "p a" a.out

The fix is rather trivial - in cp_print_static_field(), should call
check_typedef() to get the static member's real type and use it to
check whether it's a struct or an array.

As Simon suggested, I've added a new test case to the testsuite
and am passing the original type, not the real type, as argument
to both cp_print_value_fields() and val_print().

Re-tested on both aarch64-linux-gnu and amd64-linux-gnu. No regressions.

6 years agogdb/ChangeLog: Fix filenames in a couple of entries
Joel Brobecker [Mon, 26 Mar 2018 16:09:56 +0000 (09:09 -0700)]
gdb/ChangeLog: Fix filenames in a couple of entries

6 years agoChange rs6000_ptrace_ldinfo to return a byte_vector
Tom Tromey [Fri, 10 Nov 2017 20:52:37 +0000 (13:52 -0700)]
Change rs6000_ptrace_ldinfo to return a byte_vector

This changes rs6000_ptrace_ldinfo to return a byte_vector.  I think
this points out an existing double-free in
rs6000_xfer_shared_libraries.

Tested by the buildbot.

gdb/ChangeLog
2018-04-01  Tom Tromey  <tom@tromey.com>

* rs6000-nat.c (rs6000_ptrace_ldinfo): Return a byte_vector.
(rs6000_xfer_shared_libraries): Update.