external/binutils.git
7 years agodarwin-nat: Add missing include
Simon Marchi [Tue, 13 Jun 2017 19:14:50 +0000 (21:14 +0200)]
darwin-nat: Add missing include

I forgot this one, which is kind of related.

The function trace_start_error_with_name has moved in commit "Share
fork_inferior et al with gdbserver", so this additional include is
needed.

Fixes:

darwin-nat.c:1735:5: error: use of undeclared identifier 'trace_start_error_with_name'
    trace_start_error_with_name ("close");

gdb/ChangeLog:

* darwin-nat.c: Include "nat/fork-inferior.h".

7 years agodarwin: Add fork-inferior.o to NATDEPFILES
Simon Marchi [Tue, 13 Jun 2017 19:14:35 +0000 (21:14 +0200)]
darwin: Add fork-inferior.o to NATDEPFILES

I happened to be build-testing on macOS and found this:

  Undefined symbols for architecture x86_64:

    "fork_inferior(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char**, void (*)(), void (*)(int), void (*)(), char const*, void (*)(char const*, char* const*, char* const*))", referenced from:

        darwin_create_inferior(target_ops*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char**, int) in darwin-nat.o

    "startup_inferior(int, int, target_waitstatus*, ptid_t*)", referenced from:

        gdb_startup_inferior(int, int) in fork-child.o

    "trace_start_error(char const*, ...)", referenced from:

        darwin_ptrace_me() in darwin-nat.o

    "trace_start_error_with_name(char const*)", referenced from:

        darwin_ptrace_me() in darwin-nat.o

  ld: symbol(s) not found for architecture x86_64

  clang: error: linker command failed with exit code 1 (use -v to see invocation)

Adding fork-inferior.o fixes it.  I factored out the Darwin bits that
are no architecture-specific in the section meant for that at the top.

I only built-tested this using Travis-CI, since I don't have access to
this platform.

gdb/ChangeLog:

* configure.nat: Factor out Darwin bits that are not
architecture-specific.  Add fork-inferior.o.

7 years agoaix: Add fork-inferior.o to NATDEPFILES
Simon Marchi [Tue, 13 Jun 2017 19:14:25 +0000 (21:14 +0200)]
aix: Add fork-inferior.o to NATDEPFILES

Trying to build on AIX gives:

ld: 0711-317 ERROR: Undefined symbol: .trace_start_error_with_name(char const*)
ld: 0711-317 ERROR: Undefined symbol: .fork_inferior(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char**, void (*)(), void (*)(int), void (*)(), char const*, void (*)(char const*, char* const*, char* const*))
ld: 0711-317 ERROR: Undefined symbol: .startup_inferior(int, int, target_waitstatus*, ptid_t*)

Including fork-inferior.o in the build should help.  I also factored out
the AIX bits that are not architecture-specific to be consistent with the other
OSes.

gdb/ChangeLog:

* configure.nat: Factor out AIX bits that are not
architecture-specific.  Add fork-inferior.o.

7 years agold: Add tests for .startof.SECNAME/.sizeof.SECNAME
H.J. Lu [Tue, 13 Jun 2017 19:03:40 +0000 (12:03 -0700)]
ld: Add tests for .startof.SECNAME/.sizeof.SECNAME

* testsuite/ld-elf/sizeof.d: Renamed to ...
* testsuite/ld-elf/sizeofa.d: This.  Updated.
* testsuite/ld-elf/startof.d: Renamed to ...
* testsuite/ld-elf/startofa.d: This.  Updated.
* testsuite/ld-elf/sizeofb.d: New file.
* testsuite/ld-elf/startofb.d: Likewise.

7 years agoAlways define referenced __start_SECNAME/__stop_SECNAME
H.J. Lu [Tue, 13 Jun 2017 15:53:22 +0000 (08:53 -0700)]
Always define referenced __start_SECNAME/__stop_SECNAME

Currently, linker will define __start_SECNAME and __stop_SECNAME symbols
only for orphaned sections.

However, during garbage collection, ELF linker marks all sections with
references to __start_SECNAME and __stop_SECNAME symbols as used even
when section SECNAME isn't an orphaned section and linker won't define
__start_SECNAME nor __stop_SECNAME.  And ELF linker stores the first
input section whose name matches __start_SECNAME or __stop_SECNAME in
u.undef.section for garbage collection.  If these symbols are provided
in linker script, u.undef.section is set to the section where they will
defined by linker script, which leads to the incorrect output.

This patch changes linker to always define referenced __start_SECNAME and
__stop_SECNAME if the input section name is the same as the output section
name, which is always true for orphaned sections, and SECNAME is a C
identifier.  Also __start_SECNAME and __stop_SECNAME symbols are marked
as hidden by ELF linker so that __start_SECNAME and __stop_SECNAME symbols
for section SECNAME in different modules are unique.  For garbage
collection, ELF linker stores the first matched input section in the
unused vtable field.

bfd/

PR ld/20022
PR ld/21557
PR ld/21562
PR ld/21571
* elf-bfd.h (elf_link_hash_entry): Add start_stop.  Change the
vtable field to a union.
(_bfd_elf_is_start_stop): Removed.
* elf32-i386.c (elf_i386_convert_load_reloc): Also check for
__start_SECNAME and __stop_SECNAME symbols.
* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Likewise.
* elflink.c (_bfd_elf_is_start_stop): Removed.
(_bfd_elf_gc_mark_rsec): Check start_stop instead of calling
_bfd_elf_is_start_stop.
(elf_gc_propagate_vtable_entries_used): Skip __start_SECNAME and
__stop_SECNAME symbols.  Updated.
(elf_gc_smash_unused_vtentry_relocs): Likewise.
(bfd_elf_gc_record_vtinherit): Likewise.
(bfd_elf_gc_record_vtentry): Likewise.

ld/

PR ld/20022
PR ld/21557
PR ld/21562
PR ld/21571
* ld.texinfo: Update __start_SECNAME/__stop_SECNAME symbols.
* ldlang.c (lang_insert_orphan): Move handling of __start_SECNAME
and __stop_SECNAME symbols to ...
(lang_set_startof): Here.  Also define __start_SECNAME and
__stop_SECNAME for -Ur.
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Mark
referenced __start_SECNAME and __stop_SECNAME symbols as hidden
and set start_stop for garbage collection.
* testsuite/ld-elf/pr21562a.d: New file.
* testsuite/ld-elf/pr21562a.s: Likewise.
* testsuite/ld-elf/pr21562a.t: Likewise.
* testsuite/ld-elf/pr21562b.d: Likewise.
* testsuite/ld-elf/pr21562b.s: Likewise.
* testsuite/ld-elf/pr21562b.t: Likewise.
* testsuite/ld-elf/pr21562c.d: Likewise.
* testsuite/ld-elf/pr21562c.t: Likewise.
* testsuite/ld-elf/pr21562d.d: Likewise.
* testsuite/ld-elf/pr21562d.t: Likewise.
* testsuite/ld-elf/pr21562e.d: Likewise.
* testsuite/ld-elf/pr21562f.d: Likewise.
* testsuite/ld-elf/pr21562g.d: Likewise.
* testsuite/ld-elf/pr21562h.d: Likewise.
* testsuite/ld-elf/pr21562i.d: Likewise.
* testsuite/ld-elf/pr21562j.d: Likewise.
* testsuite/ld-elf/pr21562k.d: Likewise.
* testsuite/ld-elf/pr21562l.d: Likewise.
* testsuite/ld-elf/pr21562m.d: Likewise.
* testsuite/ld-elf/pr21562n.d: Likewise.
* testsuite/ld-gc/pr20022.d: Likewise.
* testsuite/ld-gc/pr20022a.s: Likewise.
* testsuite/ld-gc/pr20022b.s: Likewise.
* testsuite/ld-gc/gc.exp: Run PR ld/20022 tests.
* testsuite/ld-gc/pr19161.d: Also accept local __start_SECNAME
symbol.
* testsuite/ld-gc/start.d: Likewise.
* testsuite/ld-x86-64/lea1a.d: Updated.
* testsuite/ld-x86-64/lea1b.d: Updated.
* testsuite/ld-x86-64/lea1d.d: Updated.
* testsuite/ld-x86-64/lea1e.d: Likewise.

7 years agoReplace multiple AVR scripts with a single, customizable linker script.
Georg-Johann Lay [Tue, 13 Jun 2017 15:50:26 +0000 (16:50 +0100)]
Replace multiple AVR scripts with a single, customizable linker script.

PR ld/21569
        * scripttempl/avrtiny.sc: Remove file.
* Makefile.am (eavrtiny.c): Depend on avr.sc, no more on avrtiny.sc.
* Makefile.in: Regenerate.
* emulparams/avrtiny.sh (SCRIPT_NAME): Set var to "avr".
(TEXT_ORIGIN): Remove var.
(FUSE_NAME, FUSE_LENGTH, LOCK_LENGTH, SIGNATURE_LENGTH)
(RODATA_PM_OFFSET): Set new vars.
* emulparams/avr1.sh (FUSE_NAME, EEPROM_LENGTH, FUSE_LENGTH)
(LOCK_LENGTH, SIGNATURE_LENGTH, USER_SIGNATURE_LENGTH): Set new vars.
* emulparams/avr2.sh: Same.
* emulparams/avr25.sh: Same.
* emulparams/avr3.sh: Same.
* emulparams/avr31.sh: Same.
* emulparams/avr35.sh: Same.
* emulparams/avr4.sh: Same.
* emulparams/avr5.sh: Same.
* emulparams/avr51.sh: Same.
* emulparams/avr6.sh: Same.
* emulparams/avrxmega1.sh: Same.
* emulparams/avrxmega2.sh: Same.
* emulparams/avrxmega3.sh: Same.
* emulparams/avrxmega4.sh: Same.
* emulparams/avrxmega5.sh: Same.
* emulparams/avrxmega6.sh: Same.
* emulparams/avrxmega7.sh: Same.
* scripttempl/avr.sc (__EEPROM_REGION_LENGTH__): Only define
if EEPROM_LENGTH is set.
(MEMORY) [eeprom]: Same.
(SECTIONS) [.eeprom]: Same for output section.
(__USER_SIGNATURE_REGION_LENGTH__): Only define if
USER_SIGNATURE_LENGTH is set.
(MEMORY) [user_signatures]: Same.
(SECTIONS) [.fuse]: Only define output section if FUSE_NAME = fuse.
(SECTIONS) [.config]: Only define output section if FUSE_NAME = config.

7 years agold: Add tests for -Ur
H.J. Lu [Tue, 13 Jun 2017 15:18:19 +0000 (08:18 -0700)]
ld: Add tests for -Ur

Test -Ur with __start_SECNAME, __stop_SECNAME, .startof.SECNAME and
.sizeof.SECNAME.  __start_SECNAME and __stop_SECNAME should be defined
to the start and the end of section SECNAME.  .startof.SECNAME and
.sizeof.SECNAME should be undefined.

* testsuite/ld-elf/sizeof.d: New file.
* testsuite/ld-elf/sizeof.s: Likewise.
* testsuite/ld-elf/startof.d: Likewise.
* testsuite/ld-elf/startof.s: Likewise.

7 years ago[LD][Testsuite] Add --no-dynamic-linker option to dynamic-1 rdynamic-1 test case.
Renlin Li [Tue, 13 Jun 2017 13:03:47 +0000 (14:03 +0100)]
[LD][Testsuite] Add --no-dynamic-linker option to dynamic-1 rdynamic-1 test case.

arm-none-eabi-ld supports shared libraries. However, the toolchain may be
configured to generate statically linked executable by default.

It is required to have --no-dynamic-linker option before adding dynamic symbol
to static executable.
For dynamically linked executable, the behavior won't change.

ld/ChangeLog
2017-06-13  Renlin Li  <renlin.li@arm.com>

* testsuite/ld-elf/shared.exp (build_tests): Add --no-dynamic-linker
option to rdynamic-1 and dynamic-1 tests.

7 years agoread/write_pieced_value: Merge into one function
Andreas Arnez [Tue, 13 Jun 2017 13:20:32 +0000 (15:20 +0200)]
read/write_pieced_value: Merge into one function

Since read_pieced_value and write_pieced_value share significant logic,
this patch merges them into a single function rw_pieced_value.

gdb/ChangeLog:

* dwarf2loc.c (rw_pieced_value): New.  Merge logic from...
(read_pieced_value, write_pieced_value): ...here.  Reduce to
wrappers that just call rw_pieced_value.

7 years agowrite_pieced_value: Notify memory_changed observers
Andreas Arnez [Tue, 13 Jun 2017 13:20:32 +0000 (15:20 +0200)]
write_pieced_value: Notify memory_changed observers

So far write_pieced_value uses write_memory when writing memory pieces to
the target.  However, this is a case where GDB potentially overwrites a
watchpoint value.  In such a case write_memory_with_notification should be
used instead, so that memory_changed observers get notified.

gdb/ChangeLog:

* dwarf2loc.c (write_pieced_value): When writing the data for a
memory piece, use write_memory_with_notification instead of
write_memory.

7 years agoFix bit-/byte-offset mismatch in parameter to read_value_memory
Andreas Arnez [Tue, 13 Jun 2017 13:20:31 +0000 (15:20 +0200)]
Fix bit-/byte-offset mismatch in parameter to read_value_memory

The function read_value_memory accepts a parameter embedded_offset and
expects it to represent the byte offset into the given value.  However,
the only invocation with a possibly non-zero embedded_offset happens in
read_pieced_value, where a bit offset is passed instead.

Adjust the implementation of read_value_memory to meet the caller's
expectation.  This implicitly fixes the invocation in read_pieced_value.

gdb/ChangeLog:

* valops.c (read_value_memory): Change embedded_offset to
represent a bit offset instead of a byte offset.
* value.h (read_value_memory): Adjust comment.

7 years agoread/write_pieced_value: Remove unnecessary variable copies
Andreas Arnez [Tue, 13 Jun 2017 13:20:31 +0000 (15:20 +0200)]
read/write_pieced_value: Remove unnecessary variable copies

In read_pieced_value's main loop, the variables `dest_offset_bits' and
`source_offset_bits' are basically just copies of `offset' and
`bits_to_skip', respectively.  In write_pieced_value the copies are
reversed.  This is not very helpful when trying to keep the logic between
these functions in sync.  Since the copies are unnecessary, this patch
just removes them.

gdb/ChangeLog:

* dwarf2loc.c (read_pieced_value): Remove unnecessary variables
dest_offset_bits and source_offset_bits.
(write_pieced_value): Likewise.

7 years agoRespect piece offset for DW_OP_bit_piece
Andreas Arnez [Tue, 13 Jun 2017 13:20:31 +0000 (15:20 +0200)]
Respect piece offset for DW_OP_bit_piece

So far GDB ignores the piece offset of all kinds of DWARF bit
pieces (DW_OP_bit_piece) and treats such pieces as if the offset was zero.

This is fixed, and an appropriate test is added.

gdb/ChangeLog:

* dwarf2loc.c (read_pieced_value): Respect the piece offset, as
given by DW_OP_bit_piece.
(write_pieced_value): Likewise.

  Andreas Arnez  <arnez@linux.vnet.ibm.com>

* gdb.dwarf2/var-access.exp: Add test for composite location with
nonzero piece offsets.

7 years agoread/write_pieced_value: Improve logic for buffer allocation
Andreas Arnez [Tue, 13 Jun 2017 13:20:30 +0000 (15:20 +0200)]
read/write_pieced_value: Improve logic for buffer allocation

So far the main loop in read_pieced_value and write_pieced_value is
structured like this:

(1) Prepare a buffer and some variables we may need;

(2) depending on the DWARF piece type to be handled, use the buffer and
    the prepared variables, ignore them, or even recalculate them.

This approach reduces readability and may also lead to unnecessary copying
of data.  This patch moves the preparations to the places where sufficient
information is available and removes some of the variables involved.

gdb/ChangeLog:

* dwarf2loc.c (read_pieced_value): Move the buffer allocation and
some other preparations to the places where sufficient information
is available.
(write_pieced_value): Likewise.

7 years agoFix handling of DWARF register pieces on big-endian targets
Andreas Arnez [Tue, 13 Jun 2017 13:20:30 +0000 (15:20 +0200)]
Fix handling of DWARF register pieces on big-endian targets

For big-endian targets the logic in read/write_pieced_value tries to take
a register piece from the LSB end.  This requires offsets and sizes to be
adjusted accordingly, and that's where the current implementation has some
issues:

* The formulas for recalculating the bit- and byte-offsets into the
  register are wrong.  They just happen to yield correct results if
  everything is byte-aligned and the piece's last byte belongs to the
  given value.

* After recalculating the bit offset into the register, the number of
  bytes to be copied from the register is not recalculated.  Of course
  this does not matter if everything (particularly the piece size) is
  byte-aligned.

These issues are fixed.  The size calculation is performed with a new
helper function bits_to_bytes().

gdb/ChangeLog:

* dwarf2loc.c (bits_to_bytes): New function.
(read_pieced_value): Fix offset calculations for register pieces
on big-endian targets.
(write_pieced_value): Likewise.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/var-access.exp: Add test for non-byte-aligned
register pieces.

7 years agoread/write_pieced_value: Drop 'buffer_size' variable
Andreas Arnez [Tue, 13 Jun 2017 13:20:30 +0000 (15:20 +0200)]
read/write_pieced_value: Drop 'buffer_size' variable

When the variable 'buffer_size' in read_pieced_value and
write_pieced_value was introduced, it was needed for tracking the buffer's
allocated size.  Now that the buffer's data type has been changed to a
std::vector, the variable is no longer necessary; so remove it.

gdb/ChangeLog:

* dwarf2loc.c (read_pieced_value): Remove buffer_size variable.
(write_pieced_value): Likewise.

7 years agoAdd DWARF piece test cases for bit-field access
Andreas Arnez [Tue, 13 Jun 2017 13:20:29 +0000 (15:20 +0200)]
Add DWARF piece test cases for bit-field access

This verifies some of the previous fixes to the logic in
write_pieced_value when accessing bit-fields.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/var-access.exp: Add tests for accessing bit-fields
located in one or more DWARF pieces.

7 years agowrite_pieced_value: Transfer least significant bits into bit-field
Andreas Arnez [Tue, 13 Jun 2017 13:20:28 +0000 (15:20 +0200)]
write_pieced_value: Transfer least significant bits into bit-field

On big-endian targets, when targeting a bit-field, write_pieced_value
currently transfers the source value's *most* significant bits to the
target value, instead of its least significant bits.  This is fixed.

In particular the fix adjusts the initial value of 'offset', which can now
potentially be nonzero.  Thus the variable 'type_len' is renamed to
'max_offset', to avoid confusion.  And for consistency, the affected logic
that was mirrored in read_pieced_value is changed there in the same way.

gdb/ChangeLog:

* dwarf2loc.c (write_pieced_value): When writing to a bit-field,
transfer the source value's least significant bits, instead of its
lowest-addressed ones.  Rename type_len to max_offset.
(read_pieced_value): Mirror above changes to write_pieced_value as
applicable.

7 years agowrite_pieced_value: Fix buffer offset for memory pieces
Andreas Arnez [Tue, 13 Jun 2017 13:20:28 +0000 (15:20 +0200)]
write_pieced_value: Fix buffer offset for memory pieces

In write_pieced_value, when transferring the data to target memory via a
buffer, the bit offset within the target value is not reduced to its
sub-byte fraction before using it as a bit offset into the buffer.  This
is fixed.

gdb/ChangeLog:

* dwarf2loc.c (write_pieced_value): In DWARF_VALUE_MEMORY,
truncate full bytes from dest_offset_bits before using it as an
offset into the buffer.

7 years agowrite_pieced_value: Include transfer size in byte-wise check
Andreas Arnez [Tue, 13 Jun 2017 13:20:27 +0000 (15:20 +0200)]
write_pieced_value: Include transfer size in byte-wise check

In write_pieced_value, when checking whether the data can be transferred
byte-wise, the current logic verifies the source- and destination offsets
to be byte-aligned, but not the transfer size.  This is fixed.

gdb/ChangeLog:

* dwarf2loc.c (write_pieced_value): Include transfer size in
byte-wise check.

7 years agowrite_pieced_value: Fix copy/paste error in size calculation
Andreas Arnez [Tue, 13 Jun 2017 13:20:27 +0000 (15:20 +0200)]
write_pieced_value: Fix copy/paste error in size calculation

In write_pieced_value, the number of bytes containing a portion of the
bit-field in a given piece is calculated with the wrong starting offset;
thus the result may be off by one.  This bug was probably introduced when
copying this logic from read_pieced_value.  Fix it.

gdb/ChangeLog:

* dwarf2loc.c (write_pieced_value): Fix copy/paste error in the
calculation of this_size.

7 years agoread/write_pieced_value: Respect value parent's offset
Andreas Arnez [Tue, 13 Jun 2017 13:20:27 +0000 (15:20 +0200)]
read/write_pieced_value: Respect value parent's offset

In the case of targeting a bit-field, read_pieced_value and
write_pieced_value calculate the number of bits preceding the bit-field
without considering the relative offset of the value's parent.  This is
relevant for a structure variable like this:

  struct s {
      uint64_t foo;
      struct {
  uint32_t bar;
  uint32_t bf : 10;  /* <-- target bit-field */
      } baz;
  } s;

In this scenario, if 'val' is a GDB value representing s.baz.bf,
val->parent represents the whole s.baz structure, and the following holds:

  - value_offset (val) == sizeof s.baz.bar == 4
  - value_offset (val->parent) == sizeof s.foo == 8

The current logic would only use value_offset(val), resulting in the wrong
offset into the target value.  This is fixed.

gdb/ChangeLog:

* dwarf2loc.c (read_pieced_value): Respect parent value's offset
when targeting a bit-field.
(write_pieced_value): Likewise.

7 years agogdb/testsuite: Add "get_endianness" convenience proc
Andreas Arnez [Tue, 13 Jun 2017 13:20:26 +0000 (15:20 +0200)]
gdb/testsuite: Add "get_endianness" convenience proc

The test suite contains multiple instances of determining the target's
endianness with GDB's "show endian" command.  This patch replaces these by
an invocation of a new convenience proc 'get_endianness'.

gdb/testsuite/ChangeLog:

* lib/gdb.exp (get_endianness): New proc.
* gdb.arch/aarch64-fp.exp: Use it.
* gdb.arch/altivec-regs.exp: Likewise.
* gdb.arch/e500-regs.exp: Likewise.
* gdb.arch/vsx-regs.exp: Likewise.
* gdb.base/dump.exp: Likewise.
* gdb.base/funcargs.exp: Likewise.
* gdb.base/gnu_vector.exp: Likewise.
* gdb.dwarf2/formdata16.exp: Likewise.
* gdb.dwarf2/implptrpiece.exp: Likewise.
* gdb.dwarf2/nonvar-access.exp: Likewise.
* gdb.python/py-inferior.exp: Likewise.
* gdb.trace/unavailable-dwarf-piece.exp: Likewise.

7 years agoRemove addr_size field from struct piece_closure
Andreas Arnez [Tue, 13 Jun 2017 13:20:26 +0000 (15:20 +0200)]
Remove addr_size field from struct piece_closure

The addr_size field in the piece_closure data structure is a relic from
before introducing the typed DWARF stack.  It is obsolete now.  This patch
removes it.

gdb/ChangeLog:

* dwarf2loc.c (struct piece_closure) <addr_size>: Remove field.
(allocate_piece_closure): Drop addr_size parameter.
(dwarf2_evaluate_loc_desc_full): Adjust call to
allocate_piece_closure.

7 years agoPR gdb/21226: Take DWARF stack value pieces from LSB end
Andreas Arnez [Tue, 13 Jun 2017 13:20:26 +0000 (15:20 +0200)]
PR gdb/21226: Take DWARF stack value pieces from LSB end

When taking a DW_OP_piece or DW_OP_bit_piece from a DW_OP_stack_value, the
existing logic always takes the piece from the lowest-addressed end, which
is wrong on big-endian targets.  The DWARF standard states that the
"DW_OP_bit_piece operation describes a sequence of bits using the least
significant bits of that value", and this also matches the current logic
in GCC.  For instance, the GCC guality test case pr54970.c fails on s390x
because of this.

This fix adjusts the piece accordingly on big-endian targets.  It is
assumed that:

* DW_OP_piece shall take the piece from the LSB end as well;

* pieces reaching outside the stack value bits are considered undefined,
  and a zero value can be used instead.

gdb/ChangeLog:

PR gdb/21226
* dwarf2loc.c (read_pieced_value): Anchor stack value pieces at
the LSB end, independent of endianness.

gdb/testsuite/ChangeLog:

PR gdb/21226
* gdb.dwarf2/nonvar-access.exp: Add checks for verifying that
stack value pieces are taken from the LSB end.

7 years agowrite_pieced_value: Fix size capping logic
Andreas Arnez [Tue, 13 Jun 2017 13:20:26 +0000 (15:20 +0200)]
write_pieced_value: Fix size capping logic

A field f in a structure composed of DWARF pieces may be located in
multiple pieces, where the first and last of those may contain bits from
other fields as well.  So when writing to f, the beginning of the first
and the end of the last of those pieces may have to be skipped.  But the
logic in write_pieced_value for handling one of those pieces is flawed
when the first and last piece are the same, i.e., f is contained in a
single piece:

  < - - - - - - - - - piece_size - - - - - - - - - ->
  +-------------------------------------------------+
  | skipped_bits |   f_bits   | / / / / / / / / / / |
  +-------------------------------------------------+

The current logic determines the size of the sub-piece to operate on by
limiting the piece size to the bit size of f and then subtracting the
skipped bits:

  min (piece_size, f_bits) - skipped_bits

Instead of:

  min (piece_size - skipped_bits, f_bits)

So the resulting sub-piece size is corrupted, leading to wrong handling of
this piece in write_pieced_value.

Note that the same bug was already found in read_pieced_value and fixed
there (but not in write_pieced_value), see PR 15391.

This patch swaps the calculations, bringing them into the same (correct)
order as in read_pieced_value.

gdb/ChangeLog:

* dwarf2loc.c (write_pieced_value): Fix order of calculations for
size capping.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/var-pieces.exp: Add test case for modifying a
variable at nonzero offset.

7 years agoAdd test for modifiable DWARF locations
Andreas Arnez [Tue, 13 Jun 2017 13:20:25 +0000 (15:20 +0200)]
Add test for modifiable DWARF locations

This adds a test for read/write access to variables with various types of
DWARF locations.  It uses register- and memory locations and composite
locations with register- and memory pieces.

Since the new test calls gdb_test_no_output with commands that contain
braces, it is necessary for string_to_regexp to quote braces as well.
This was not done before.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/var-access.c: New file.
* gdb.dwarf2/var-access.exp: New test.
* lib/gdb-utils.exp (string_to_regexp): Quote braces as well.

7 years agoPrevent a call to abort when a relocatable link encounters a relocation against a...
Nick Clifton [Tue, 13 Jun 2017 13:03:16 +0000 (14:03 +0100)]
Prevent a call to abort when a relocatable link encounters a relocation against a symbol in a section removed by garbage collection.

PR ld/21524
* elflink.c (elf_link_adjust_relocs): Generate an error when
encountering a reloc against a symbol removed by garbage
collection.

7 years agoMove initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c
Yao Qi [Tue, 13 Jun 2017 08:05:04 +0000 (09:05 +0100)]
Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c

All target descriptions except mips initialization are called in -tdep.c,
instead of -nat.c, so this patch moves mips target descriptions
initialization to -tdep.c.  Secondly, I want to change the target
descriptions from pre-generated to dynamical creation, so I want to test
that these pre-generated target descriptions equal to these dynamically
created ones.  Move target descriptions initialization to -tdep.c files so
we can test them in any hosts (if they are still -nat.c, we can only test
them on mips-linux host.).

gdb:

2017-06-13  Yao Qi  <yao.qi@linaro.org>

* mips-linux-nat.c: Move include features/mips*-linux.c to
mips-linux-tdep.c.
(_initialize_mips_linux_nat): Move initialize_tdesc_mips* calls
to mips-linux-tdep.c.
* mips-linux-tdep.c: Include features/mips*-linux.c
(_initialize_mips_linux_tdep): Call initialize_tdesc_mips*
functions.
* mips-linux-tdep.h (tdesc_mips_linux): Declare.
(tdesc_mips_dsp_linux, tdesc_mips64_linux): Declare.
(tdesc_mips64_dsp_linux): Declare.

7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 13 Jun 2017 00:00:43 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAdd some 128-bit integer tests
Tom Tromey [Fri, 2 Jun 2017 12:54:06 +0000 (06:54 -0600)]
Add some 128-bit integer tests

This adds some tests for printing 128-bit integers.

2017-06-12  Tom Tromey  <tom@tromey.com>

* gdb.dwarf2/formdata16.exp: Add tests.

7 years agoRemove val_print_type_code_int
Tom Tromey [Mon, 22 May 2017 22:55:18 +0000 (16:55 -0600)]
Remove val_print_type_code_int

Now that print_scalar_formatted is more capable, there's no need for
val_print_type_code_int.  This patch removes it in favor of
val_print_scalar_formatted.

2017-06-12  Tom Tromey  <tom@tromey.com>

* valprint.h (val_print_type_code_int): Remove.
* valprint.c (generic_val_print_int): Always call
val_print_scalar_formatted.
(val_print_type_code_int): Remove.
* printcmd.c (print_scalar_formatted): Handle options->format==0.
* f-valprint.c (f_val_print): Use val_print_scalar_formatted.
* c-valprint.c (c_val_print_int): Use val_print_scalar_formatted.
* ada-valprint.c (ada_val_print_num): Use
val_print_scalar_formatted.

7 years agoSimplify print_scalar_formatted
Tom Tromey [Tue, 23 May 2017 00:43:59 +0000 (18:43 -0600)]
Simplify print_scalar_formatted

This unifies the two switches in print_scalar_formatted, removing some
now-redundant code.  Now scalar types are never converted to LONGEST,
instead printing is done using print_*_chars, operating on the byte
representation.

ChangeLog
2017-06-12  Tom Tromey  <tom@tromey.com>

* printcmd.c (print_scalar_formatted): Unify the two switches.
Don't convert scalars to LONGEST.

2017-06-12  Tom Tromey  <tom@tromey.com>

* gdb.arch/altivec-regs.exp: Expect decimal results for uint128.

7 years agoLet print_decimal_chars handle signed values
Tom Tromey [Mon, 22 May 2017 22:32:25 +0000 (16:32 -0600)]
Let print_decimal_chars handle signed values

This changes print_decimal_chars to handle signed values.

gdb/ChangeLog
2017-06-12  Tom Tromey  <tom@tromey.com>

PR exp/16225:
* valprint.h (print_decimal_chars): Update.
* valprint.c (maybe_negate_by_bytes): New function.
(print_decimal_chars): Add "is_signed" argument.
* printcmd.c (print_scalar_formatted): Update.

7 years agoDon't always zero pad in print_*_chars
Tom Tromey [Mon, 22 May 2017 09:55:58 +0000 (03:55 -0600)]
Don't always zero pad in print_*_chars

This changes print_octal_chars and print_decimal_chars to never zero
pad, and changes print_binary_chars and print_hex_chars to only
optionally zero-pad, based on a flag.

ChangeLog
2017-06-12  Tom Tromey  <tom@tromey.com>

PR exp/16225:
* valprint.h (print_binary_chars, print_hex_chars): Update.
* valprint.c (val_print_type_code_int): Update.
(print_binary_chars): Add "zero_pad" argument.
(emit_octal_digit): New function.
(print_octal_chars): Don't zero-pad.
(print_decimal_chars): Likewise.
(print_hex_chars): Add "zero_pad" argument.
* sh64-tdep.c (sh64_do_fp_register): Update.
* regcache.c (regcache::dump): Update.
* printcmd.c (print_scalar_formatted): Update.
* infcmd.c (default_print_one_register_info): Update.

2017-06-12  Tom Tromey  <tom@tromey.com>

PR exp/16225:
* gdb.reverse/i386-sse-reverse.exp: Update tests.
* gdb.arch/vsx-regs.exp: Update tests.
* gdb.arch/s390-vregs.exp (hex128): New proc.
Update test.
* gdb.arch/altivec-regs.exp: Update tests.

7 years agomips-tdep.c: Remove MAX_REGISTER_SIZE usage
Pedro Alves [Mon, 12 Jun 2017 18:04:52 +0000 (19:04 +0100)]
mips-tdep.c: Remove MAX_REGISTER_SIZE usage

mips_eabi_push_dummy_call is storing the address of a struct in a
buffer that must have the same of the confisued/set ABI register size.
Add a define for the maximum ABI size and use it to size the local
buffer.  Also rename the 'regsize' local to 'abi_regsize' for clarity.

Tested that --enable-targets=all still builds.

gdb/ChangeLog:
2017-06-12  Pedro Alves  <palves@redhat.com>
    Alan Hayward  <alan.hayward@arm.com>

* mips-tdep.c (MAX_MIPS_ABI_REGSIZE): New.
(mips_eabi_push_dummy_call): Rename local 'regsize' to
'abi_regsize'.  Rename local array 'valbuf' to 'ref_valbuf', and
use MAX_MIPS_ABI_REGSIZE instead of MAX_REGISTER_SIZE to size it.
Assert that abi_regsize bytes fit in 'ref_valbuf'.

7 years ago.gdb_index prod perf regression: mapped_symtab now vector of values
Pedro Alves [Mon, 12 Jun 2017 01:51:52 +0000 (02:51 +0100)]
.gdb_index prod perf regression: mapped_symtab now vector of values

... instead of vector of pointers

There's no real reason for having mapped_symtab::data be a vector of
heap-allocated symtab_index_entries.  symtab_index_entries is not that
large, it's movable, and it's cheap to move.  Making the vector hold
values instead improves cache locality and eliminates many roundtrips
to the heap.

Using the same test as in the previous patch, against the same gdb
inferior, timing improves ~13% further:

  ~6.0s => ~5.2s (average of 5 runs).

Note that before the .gdb_index C++ifycation patch, we were at ~5.7s.
We're now consistenly better than before.

gdb/ChangeLog
2017-06-12  Pedro Alves  <palves@redhat.com>

* dwarf2read.c (mapped_symtab::data): Now a vector of
symtab_index_entry instead of vector of
std::unique_ptr<symtab_index_entry>.  All users adjusted to check
whether an element's name is NULL instead of checking whether the
element itself is NULL.
(find_slot): Change return type.  Adjust.
(hash_expand, , add_index_entry, uniquify_cu_indices)
(write_hash_table): Adjust.

7 years ago.gdb_index prod perf regression: Estimate size of psyms_seen
Pedro Alves [Mon, 12 Jun 2017 01:40:18 +0000 (02:40 +0100)]
.gdb_index prod perf regression: Estimate size of psyms_seen

Using the same test as the previous patch, perf shows GDB spending
over 7% in "free".  A substantial number of those calls comes from
insertions in the psyms_seen unordered_set causing lots of rehashing
and recreating buckets.  Fix this by computing an estimate of the size
of the set upfront.

Using the same test as in the previous patch, against the same gdb
inferior, timing improves ~8% further:

  ~6.5s => ~6.0s (average of 5 runs).

gdb/ChangeLog:
2017-06-12  Pedro Alves  <palves@redhat.com>

* dwarf2read.c (recursively_count_psymbols): New function.
(write_psymtabs_to_index): Call it to compute number of psyms and
pass estimate size of psyms_seen to unordered_set's ctor.

7 years ago.gdb_index prod perf regression: find before insert in unordered_map
Pedro Alves [Sun, 11 Jun 2017 23:49:51 +0000 (00:49 +0100)]
.gdb_index prod perf regression: find before insert in unordered_map

"perf" shows the unordered_map::emplace call in write_hash_table a bit
high up on profiles.  Fix this using the find + insert idiom instead
of going straight to insert.

I tried doing the same to the other unordered_maps::emplace calls in
the file, but saw no performance improvement, so left them be.

With a '-g3 -O2' build of gdb, and:

  $ cat save-index.cmd
  set $i = 0
  while $i < 100
    save gdb-index .
    set $i = $i + 1
  end
  $ time ./gdb -data-directory=data-directory -nx --batch -q -x save-index.cmd  ./gdb.pristine

I get an improvement of ~7%:

  ~7.0s => ~6.5s (average of 5 runs).

gdb/ChangeLog:
2017-06-12  Pedro Alves  <palves@redhat.com>

* dwarf2read.c (write_hash_table): Check if key already exists
before emplacing.

7 years agoCode cleanup: dwarf2read.c: Add data_buf::append_uint
Pedro Alves [Sat, 10 Jun 2017 15:51:14 +0000 (16:51 +0100)]
Code cleanup: dwarf2read.c: Add data_buf::append_uint

This avoids having to specify the integer size twice in the same line.

gdb/ChangeLog:
2017-06-12  Pedro Alves  <palves@redhat.com>

* dwarf2read.c (data_buf::append_space): Rename to...
(data_buf::grow): ... this, and make private.  Adjust all callers.
(data_buf::append_uint): New method.
(add_address_entry, write_one_signatured_type)
(write_psymtabs_to_index): Use it.

7 years agoCode cleanup: dwarf2read.c: Eliminate ::file_write
Pedro Alves [Fri, 9 Jun 2017 23:53:00 +0000 (00:53 +0100)]
Code cleanup: dwarf2read.c: Eliminate ::file_write

There's no real need for all this indirection.

gdb/ChangeLog:
2017-06-12  Pedro Alves  <palves@redhat.com>

* dwarf2read.c (file_write(FILE *, const void *, size_t)): Delete.
(file_write (FILE *, const std::vector<Elem>&)): Delete.
(data_buf::file_write): Call ::fwrite directly.

7 years agoCode cleanup: dwarf2read.c:uniquify_cu_indices: Use std::unique
Pedro Alves [Sun, 11 Jun 2017 23:43:55 +0000 (00:43 +0100)]
Code cleanup: dwarf2read.c:uniquify_cu_indices: Use std::unique

gdb/ChangeLog:
2017-06-12  Pedro Alves  <palves@redhat.com>

* dwarf2read.c (uniquify_cu_indices): Use std::unique and
std::vector::erase.

7 years agoCode cleanup: C++ify .gdb_index producer
Jan Kratochvil [Mon, 12 Jun 2017 15:29:53 +0000 (16:29 +0100)]
Code cleanup: C++ify .gdb_index producer

gdb/ChangeLog
2017-06-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

Code cleanup: C++ify .gdb_index producer.
* dwarf2read.c: Include <unordered_set> and <unordered_map>.
(MAYBE_SWAP) [WORDS_BIGENDIAN]: Cast to offset_type.
(struct strtab_entry, hash_strtab_entry, eq_strtab_entry)
(create_strtab, add_string): Remove.
(file_write, data_buf): New.
(struct symtab_index_entry): Use std::vector for cu_indices.
(struct mapped_symtab): Use std::vector for data.
(hash_symtab_entry, eq_symtab_entry, delete_symtab_entry)
(create_symbol_hash_table, create_mapped_symtab, cleanup_mapped_symtab):
Remove.
(find_slot): Change return type.  Update it to the new data structures.
(hash_expand, add_index_entry): Update it to the new data structures.
(offset_type_compare): Remove.
(uniquify_cu_indices): Update it to the new data structures.
(c_str_view, c_str_view_hasher, vector_hasher): New.
(add_indices_to_cpool): Remove.
(write_hash_table): Update it to the new data structures.
(struct psymtab_cu_index_map, hash_psymtab_cu_index)
(eq_psymtab_cu_index): Remove.
(psym_index_map): New typedef.
(struct addrmap_index_data): Change addr_obstack pointer to data_buf
reference and std::unordered_map for cu_index_htab.
(add_address_entry, add_address_entry_worker, write_address_map)
(write_psymbols): Update it to the new data structures.
(write_obstack): Remove.
(struct signatured_type_index_data): Change types_list to a data_buf
reference and psyms_seen to a std::unordered_set reference.
(write_one_signatured_type, recursively_write_psymbols)
(write_psymtabs_to_index): Update it to the new data structures.

7 years agoELF: Pass bfd_link_info to merge_gnu_properties
H.J. Lu [Mon, 12 Jun 2017 14:37:15 +0000 (07:37 -0700)]
ELF: Pass bfd_link_info to merge_gnu_properties

Pass struct bfd_link_info * to merge_gnu_properties to give backend
control of how GNU properties are merged based on linker command line
options.

* elf-bfd.h (elf_backend_data): Add struct bfd_link_info *
to merge_gnu_properties.
* elf-properties.c (elf_merge_gnu_properties): Add struct
bfd_link_info * and pass it to merge_gnu_properties.
(elf_merge_gnu_property_list): Add struct bfd_link_info *
and pass it to elf_merge_gnu_properties.
(_bfd_elf_link_setup_gnu_properties): Pass info to
elf_merge_gnu_property_list.
* elf32-i386.c (elf_i386_merge_gnu_properties): Add struct
bfd_link_info *.
* elf64-x86-64.c (elf_x86_64_merge_gnu_properties): Likewise.

7 years agoS/390: Return with an error for broken tls rewrites
Andreas Krebbel [Fri, 9 Jun 2017 09:19:01 +0000 (11:19 +0200)]
S/390: Return with an error for broken tls rewrites

bfd/ChangeLog:

2017-06-12  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

* elf32-s390.c (elf_s390_relocate_section): Return false in case
the rewriting fails.
* elf64-s390.c (elf_s390_relocate_section): Likewise.

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 12 Jun 2017 00:00:38 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoIntroduce "set debug separate-debug-file"
Simon Marchi [Sun, 11 Jun 2017 21:16:01 +0000 (23:16 +0200)]
Introduce "set debug separate-debug-file"

I helped someone figure out why their separate debug info (debug
link-based) was not found by gdb.  It turns out that the debug file was
not named properly.  It made me realize that it is quite difficult to
diagnose this kind of problems.  This patch adds some debug output to
show where GDB looks for those files, so that it should be (more)
obvious to find what's wrong.

Here's an example of the result, first with an example of unsuccessful lookup,
and then a successful one.

  (gdb) set debug separate-debug-file on
  (gdb) file /usr/bin/gnome-calculator
  Reading symbols from /usr/bin/gnome-calculator...
  Looking for separate debug info (build-id) for /usr/bin/gnome-calculator
    Trying /usr/local/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug

  Looking for separate debug info (debug link) for /usr/bin/gnome-calculator
    Trying /usr/bin/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
    Trying /usr/bin/.debug/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
    Trying /usr/local/lib/debug//usr/bin/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
  (no debugging symbols found)...done.
  (gdb) set debug-file-directory /usr/lib/debug
  (gdb) file /usr/bin/gnome-calculator
  Reading symbols from /usr/bin/gnome-calculator...
  Looking for separate debug info by build-id for /usr/bin/gnome-calculator
    Trying /usr/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug
  Reading symbols from /usr/lib/debug/.build-id/0d/5c5e8c86dbe4f4f95f7a13de04f91d377f3c6a.debug...done.
  done.

Note: here, the debug link happens to be named like the build-id, but it
doesn't have to be this way.  It puzzled me for a minute.

gdb/ChangeLog:

* NEWS (Changes since GDB 8.0): Announce {set,show} debug
separate-debug-file commands.
* symfile.h (separate_debug_file_debug): New global.
* symfile.c (separate_debug_file_debug): New global.
(separate_debug_file_exists, find_separate_debug_file): Add
debug output.
(_initialize_symfile): Add "set debug separate-debug-file"
command.
* build-id.c (build_id_to_debug_bfd,
find_separate_debug_file_by_buildid): Add debug output.

gdb/doc/ChangeLog:

* gdb.texinfo (Optional Messages about Internal Happenings):
Document {set,show} debug separate-debug-file commands.

7 years agoPR 21564, Section start in binary output file incorrect
Alan Modra [Sun, 11 Jun 2017 04:04:13 +0000 (13:34 +0930)]
PR 21564, Section start in binary output file incorrect

PR 21564
* binary.c (binary_set_section_contents): Scale lma by octets
per byte to set filepos.

7 years agoAutomatic date update in version.in
GDB Administrator [Sun, 11 Jun 2017 00:00:44 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 10 Jun 2017 00:00:43 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agogdbarch: Remove displaced_step_free_closure
Simon Marchi [Fri, 9 Jun 2017 22:24:05 +0000 (00:24 +0200)]
gdbarch: Remove displaced_step_free_closure

The displaced_step_free_closure gdbarch hook allows architectures to
free data they might have allocated to complete a displaced step.
However, all architectures using that hook use the
simple_displaced_step_free_closure provided in arch-utils.{c,h}, which
does a simple xfree.  We can remove it and do an xfree directly instead
of calling the hook.

gdb/ChangeLog:

* gdbarch.sh (displaced_step_free_closure): Remove.
* gdbarch.h, gdbarch.c: Re-generate.
* aarch64-linux-tdep.c (aarch64_linux_init_abi): Don't set
displaced_step_free_closure.
* amd64-linux-tdep.c (amd64_linux_init_abi_common): Likewise.
* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
* i386-linux-tdep.c (i386_linux_init_abi): Likewise.
* rs6000-aix-tdep.c (rs6000_aix_init_osabi): Likewise.
* rs6000-tdep.c (rs6000_gdbarch_init): Likewise.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* arch-utils.h (simple_displaced_step_free_closure): Remove.
* arch-utils.c (simple_displaced_step_free_closure): Remove.
* infrun.c (displaced_step_clear): Call xfree instead of
gdbarch_displaced_step_free_closure.

7 years agoInclude <signal.h> on gdbserver/fork-child.c (and fix regressions)
Sergio Durigan Junior [Fri, 9 Jun 2017 22:16:19 +0000 (18:16 -0400)]
Include <signal.h> on gdbserver/fork-child.c (and fix regressions)

Hi,

This is another obvious patch that fixes a thinko from my previous
startup-with-shell series.  We should conditionally include <signal.h>
on gdb/gdbserver/fork-child.c because gdbserver will be putting the
inferior's terminal on the correct mode after the call to
fork_inferior, and for that it needs to ignore SIGTTOU.

This patch fixes a bunch of regressions happening on AArch64 that were
reported by Yao.

gdb/gdbserver/ChangeLog:
2017-06-09  Sergio Durigan Junior  <sergiodj@redhat.com>

* fork-child.c: Conditionally include <signal.h>.

7 years agox86-64: Add some x32 ELF property tests
H.J. Lu [Fri, 9 Jun 2017 17:43:43 +0000 (10:43 -0700)]
x86-64: Add some x32 ELF property tests

* testsuite/ld-x86-64/property-x86-3-x32.d: New file.
* testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-4b-x32.d: Likewise.
* testsuite/ld-x86-64/property-x86-3.d: Also pass
-defsym __64_bit__=1 to asssembler.
* testsuite/ld-x86-64/property-x86-4a.d: Likewise.
* testsuite/ld-x86-64/property-x86-4b.d: Likewise.
* testsuite/ld-x86-64/property-x86-3.s: Align to 4 bytes if
__64_bit__ isn't defined.
* testsuite/ld-x86-64/property-x86-4a.s: Likewise.
* testsuite/ld-x86-64/property-x86-4b.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run property-x86-3-x32,
property-x86-4a-x32 and property-x86-4b-x32.

7 years agoRevert "[AArch64] Allow COPY relocation elimination"
Jiong Wang [Fri, 9 Jun 2017 11:02:05 +0000 (12:02 +0100)]
Revert "[AArch64] Allow COPY relocation elimination"

This reverts commit bc327528fd2ccdc6c29ab6ae608085dddbad5cc8.

This patch can only be committed after PC-relative relocation types
support on copy relocation elimination is also completed.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 9 Jun 2017 00:00:44 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoFix possible bug when no args have been provided to the executable
Sergio Durigan Junior [Thu, 8 Jun 2017 20:58:25 +0000 (16:58 -0400)]
Fix possible bug when no args have been provided to the executable

Hi,

This bug is related to:

  <https://sourceware.org/ml/gdb-patches/2017-06/msg00216.html>

On stringify_argv, we have to check if args[0] is not NULL before
stringifying anything, otherwise we might do the wrong thing when
trimming the "ret" string in the end.  args[0] will be NULL when no
arguments are passed to the inferior that will be started.

Checked in as obvious.

gdb/ChangeLog:
2017-06-08  Sergio Durigan Junior  <sergiodj@redhat.com>

* common/common-utils.c (stringify_argv): Check for "arg[0] !=
NULL".

7 years ago[ARC] Corrected conditions for dynamic sections creation.
Cupertino Miranda [Tue, 23 May 2017 11:36:33 +0000 (13:36 +0200)]
[ARC] Corrected conditions for dynamic sections creation.

Fixed conditions to create the dynamic sections.
Previously there would be times where the dynamic sections would not be created
although they were actually required for linking to work.

Issue found through OpenADK build, more precisely the ublicb testsuite package.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

elf32-arc.c (elf_arc_check_relocs): Fixed conditions to generate
dynamic sections.

7 years ago[ARC] Fixed condition to generate TEXTREL.
Cupertino Miranda [Wed, 5 Apr 2017 21:22:07 +0000 (23:22 +0200)]
[ARC] Fixed condition to generate TEXTREL.

TEXTREL was being generated even when relocatable .o files had the .rela.text
section. Now it is limitted only to dynamic object files that still have them.
Nevertheless, our target aborts in those cases due to architecture limitations
where icache is not coherent with dcache, and to force this coherence expensive
kernel level support would be needed.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

* elf32-arc.c (elf_arc_size_dynamic_sections): Changed condition to
require TEXTREL.

7 years ago[ARC] Fixed TLS for IE model.
Cupertino Miranda [Thu, 29 Dec 2016 16:10:01 +0000 (17:10 +0100)]
[ARC] Fixed TLS for IE model.

In the case of static relocation, the GOT entries are fixed at link time
and are set by the linker.
In order to compute the right TLS offset it is necessary to add TCB_SIZE
to the offset, just in case the dynamic linker is not expected to be
executed (static linked case).
This problem does appear in dynamic linked applications, as the dynamic
linker is adding this TCB_SIZE by operating the TCB block structure.

Problem revealed in GLIBC with static linking.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

arc-got.h (relocate_fix_got_relocs_for_got_info): Added TCB_SIZE to
patched section contents for TLS IE reloc.
elf32-arc.c: Remove TCB_SIZE preprocessor macro.

Rebase to 0006

7 years ago[ARC] Add RELOC_FOR_GLOBAL_SYMBOL in ARC target code.
Cupertino Miranda [Wed, 30 Nov 2016 19:23:21 +0000 (20:23 +0100)]
[ARC] Add RELOC_FOR_GLOBAL_SYMBOL in ARC target code.

This miss was identified in the context of openssh building for ARC.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

elf32-arc.c (elf_arc_relocate_section): Added "call" to
RELOC_FOR_GLOBAL_SYMBOL macro.

7 years ago[ARC] ARC_PC32 dynamic reloc incorrectly generated.
Cupertino Miranda [Wed, 30 Nov 2016 13:07:20 +0000 (14:07 +0100)]
[ARC] ARC_PC32 dynamic reloc incorrectly generated.

Fixed issue related to the generation of ARC_PC32 dynamic relocs when symbol
is dynamic but still defined in a non shared object.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

elf32-arc.c (elf_arc_relocate_section): Small refactor and condition
changes.

7 years ago[ARC] Don't convert _DYNAMIC@ to _GLOBAL_OFFSET_TABLE_
Vineet Gupta [Mon, 30 May 2016 09:49:22 +0000 (15:19 +0530)]
[ARC] Don't convert _DYNAMIC@ to _GLOBAL_OFFSET_TABLE_

Historically the arc abi demanded that a GOT[0] should be referencible as
[pc+_DYNAMIC@gotpc].  Hence we convert a _DYNAMIC@gotpc to a GOTPC reference to
_GLOBAL_OFFSET_TABLE_.

This is no longer the case and uClibc and upcomming GNU libc don't expect this
to happen.

gas/ChangeLog:

    Vineet Gupta  <vgupta@synopsys.com>
    Cupertino Miranda  <cmiranda@synopsys.com>

* config/tc-arc.c (md_undefined_symbol): Changed.
* config/tc-arc.h (DYNAMIC_STRUCT_NAME): Removed.

7 years ago[ARC] Reassign the symbol got information to actual symbol when indirect.
Cupertino Miranda [Mon, 24 Oct 2016 20:19:48 +0000 (22:19 +0200)]
[ARC] Reassign the symbol got information to actual symbol when indirect.

GOT information would not be reassign to symbol when it became a indect
symbol.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

* elf32-arc.c (elf_arc_relocate_section): Fixed reassign of indirect
symbols.

7 years ago[ARC] Disable warning on absolute relocs when symbol is local.
Cupertino Miranda [Mon, 24 Oct 2016 10:52:04 +0000 (12:52 +0200)]
[ARC] Disable warning on absolute relocs when symbol is local.

R_ARC_32 and R_ARC_32_ME cannot be generated as dynamic relocs.
However, a warning message and check_relocs was aborting when this type of
reloc was being resolved to a local symbol.
This is wrong as local symbols are resolvable at link time.

bfd/ChangeLog:

    Cupertino Miranda  <cmiranda@synopsys.com>

* elf32-arc.c (elf_arc_check_relocs): Added condition to disable
warning and "Bad value" for local symbols ARC_32 or ARC_32_ME relocs.

7 years ago[ARC] Avoid creating dynamic relocs when static linked is requested.
Cupertino Miranda [Wed, 7 Dec 2016 13:22:54 +0000 (14:22 +0100)]
[ARC] Avoid creating dynamic relocs when static linked is requested.

bfd/Changelog:

    Cupertino Miranda  <cmiranda@synopsys.com>

* elf32-arc.c (ADD_RELA): Changed to only work when dynamic object is
created.

7 years agoAdd MN10300_MAX_REGISTER_SIZE
Alan Hayward [Thu, 8 Jun 2017 15:05:24 +0000 (16:05 +0100)]
Add MN10300_MAX_REGISTER_SIZE

gdb/
* mn10300-tdep.c (MN10300_MAX_REGISTER_SIZE): Add.
(mn10300_extract_return_value): Use MN10300_MAX_REGISTER_SIZE.
(mn10300_push_dummy_call): Likewise.

7 years agoUpdate ff4ca5ac6a2e8 to the correct version.
Alan Hayward [Thu, 8 Jun 2017 14:57:12 +0000 (15:57 +0100)]
Update ff4ca5ac6a2e8 to the correct version.

gdb/
* mi/mi-main.c (register_changed_p): Use value_contents_eq.

7 years ago[bfd][arm] Don't assert on suspicious build attributes in input file
Richard Earnshaw [Thu, 8 Jun 2017 14:11:44 +0000 (15:11 +0100)]
[bfd][arm] Don't assert on suspicious build attributes in input file

It's generally a bad idea to use assertions to validate our idea of
what an input file looks like.  We need to be as liberal as possible
in what we accept with respect to standards and conservative with what
we produce.

Currently, if gcc is used to produce an assembler file which contains
only data, but the FPU is set to fpv4-sp-d16 and mfloat-abi=hard, then
the following attributes will be set in the output:

        .cpu arm7tdmi
        .eabi_attribute 27, 1   @ Tag_ABI_HardFP_use
        .eabi_attribute 28, 1   @ Tag_ABI_VFP_args
        .eabi_attribute 20, 1   @ Tag_ABI_FP_denormal
        .eabi_attribute 21, 1   @ Tag_ABI_FP_exceptions
        .eabi_attribute 23, 3   @ Tag_ABI_FP_number_model
        .eabi_attribute 24, 1   @ Tag_ABI_align8_needed
        .eabi_attribute 25, 1   @ Tag_ABI_align8_preserved
        .eabi_attribute 26, 2   @ Tag_ABI_enum_size
        .eabi_attribute 30, 6   @ Tag_ABI_optimization_goals
        .eabi_attribute 34, 0   @ Tag_CPU_unaligned_access
        .eabi_attribute 18, 4   @ Tag_ABI_PCS_wchar_t

There is then no .fpu directive to cause Tag_FP_arch to be set,
because there are no functions containing code in the object file.  If
this object file is assembled by hand, but without -mfpu on the
invocation of the assembler, then the build attributes produced will
trigger an assertion during linking.

Thinking about the build attributes, the combination of a
single-precision only implementation of no floating-point architecture
is still no floating-point architecture.  Hence the assertion on the
input BFD in the linker makes no real sense.

We should, however, be more conservative in what we generate, so I've
left the assertion on the output bfd in place; I don't think we can
trigger it with this change since we never merge the problematic tags
from a perversely generated input file.

* elf32-arm.c (elf32_arm_merge_eabi_attributes): Remove assertion
that the input bfd has Tag_FP_ARCH non-zero if Tag_ABI_HardFP_use
is non-zero.  Add clarifying comments.

7 years agoRemove MAX_REGISTER_SIZE from mi/mi-main.c
Alan Hayward [Thu, 8 Jun 2017 13:02:59 +0000 (14:02 +0100)]
Remove MAX_REGISTER_SIZE from mi/mi-main.c

gdb/
* mi/mi-main.c (register_changed_p): Use cooked_read_value.

7 years agox86: Dump local IFUNC functions in the map file
H.J. Lu [Thu, 8 Jun 2017 04:18:01 +0000 (21:18 -0700)]
x86: Dump local IFUNC functions in the map file

Dump local IFUNC functions in the map file when generating IRELATIVE
relocations if -Map is used.

bfd/

* elf32-i386.c (elf_i386_check_relocs): Set local IFUNC symbol
name.  Use local IFUNC symbol name string to report unsupported
non-PIC call to IFUNC function.
(elf_i386_relocate_section): Dump local IFUNC name with minfo
when generating R_386_IRELATIVE relocation.
(elf_i386_finish_dynamic_symbol): Likewise.
* elf_x86_64_check_relocs (elf_x86_64_check_relocs): Set local
IFUNC symbol name.
(elf_x86_64_relocate_section): Dump local IFUNC name with minfo
when generating R_X86_64_IRELATIVE relocation.
(elf_x86_64_finish_dynamic_symbol): Likewise.

ld/

* testsuite/ld-ifunc/ifunc-1-local-x86.d: Pass
"-Map tmpdir/ifunc-1-local-x86.map" to ld and check
ifunc-1-local-x86.map.
* testsuite/ld-ifunc/ifunc-1-x86.d: Pass
"-Map tmpdir/ifunc-1-x86.map" to ld and check ifunc-1-x86.map.
* testsuite/ld-ifunc/ifunc-1-local-x86.map: New file.
* testsuite/ld-ifunc/ifunc-1-x86.map: Likewise.

7 years agocl
H.J. Lu [Thu, 8 Jun 2017 10:48:04 +0000 (03:48 -0700)]
cl

7 years ago[AArch64] Allow COPY relocation elimination
Jiong Wang [Wed, 7 Jun 2017 11:05:39 +0000 (12:05 +0100)]
[AArch64] Allow COPY relocation elimination

  As discussed at the PR, this patch tries to avoid COPY relocation generation
and propagate the original relocation into runtime if it was relocating on
writable section.  The ELIMINATE_COPY_RELOCS has been set to true and it's
underlying infrastructure has been improved so that the COPY reloc elimination
at least working on absoluate relocations (ABS64) after this patch.

bfd/
        PR ld/21532
        * elfnn-aarch64.c (ELIMINATE_COPY_RELOCS): Set to 1.
        (elfNN_aarch64_final_link_relocate): Also propagate relocations to
        runtime for copy relocation elimination cases.
        (alias_readonly_dynrelocs): New function.
        (elfNN_aarch64_adjust_dynamic_symbol): Keep the dynamic relocs instead
        of generating copy relocation if it is not against read-only sections.
        (elfNN_aarch64_check_relocs): Likewise.

ld/
        * testsuite/ld-aarch64/copy-reloc-eliminate.d: New test.
        * testsuite/ld-aarch64/copy-reloc-exe-eliminate.s: New test source file.
        * testsuite/ld-aarch64/aarch64-elf.exp: Run new testcase.

7 years ago2017-06-07 Eric Christopher <echristo@gmail.com>
Eric Christopher [Thu, 8 Jun 2017 00:49:35 +0000 (17:49 -0700)]
2017-06-07  Eric Christopher  <echristo@gmail.com>

* aarch64.cc (maybe_apply_stub): Add debug logging for looking
up stubs to undefined symbols and early return rather than
fail to look them up.
(scan_reloc_for_stub): Add debug logging for no stub creation
for undefined symbols.

7 years agoAutomatic date update in version.in
GDB Administrator [Thu, 8 Jun 2017 00:00:39 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoImplement proper "startup-with-shell" support on gdbserver
Sergio Durigan Junior [Fri, 23 Dec 2016 03:14:02 +0000 (22:14 -0500)]
Implement proper "startup-with-shell" support on gdbserver

This patch implements the proper support for the "startup-with-shell"
feature on gdbserver.  A new packet is added, QStartupWithShell, and
it is sent on initialization.  If the host sends a
"QStartupWithShell:1", it means the inferior shall be started using a
shell.  If the host sends a "QStartupWithShell:0", it means the
inferior shall be started without using a shell.  Any other value is
considered an error.

There is no way to remotely set the shell that will be used by the
target to start the inferior.  In order to do that, the user must
start gdbserver while providing a shell via the $SHELL environment
variable.  The same is true for the host side.

The "set startup-with-shell" setting from the host side is used to
decide whether to start the remote inferior using a shell.  This same
setting is also used to decide whether to use a shell to start the
host inferior; this means that it is not really possible to start the
inferior using different mechanisms on target and host.

A documentation patch is included, along with a new testcase for the
feature.

gdb/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* NEWS (Changes since GDB 8.0): Announce that GDBserver is now
able to start inferiors using a shell.
(New remote packets): Announce new packet "QStartupWithShell".
* remote.c: Add PACKET_QStartupWithShell.
(extended_remote_create_inferior): Handle new
PACKET_QStartupWithShell.
(remote_protocol_features) <QStartupWithShell>: New entry for
PACKET_QStartupWithShell.
(_initialize_remote): Call "add_packet_config_cmd" for
QStartupShell.

gdb/gdbserver/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* server.c (handle_general_set): Handle new packet
"QStartupWithShell".
(handle_query): Add "QStartupWithShell" to the list of supported
packets.
(gdbserver_usage): Add help text explaining the
new "--startup-with-shell" and "--no-startup-with-shell" CLI
options.
(captured_main): Recognize and act upon the presence of the new
CLI options.

gdb/testsuite/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* gdb.base/startup-with-shell.c: New file.
* gdb.base/startup-with-shell.exp: Likewise.

gdb/doc/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* gdb.texinfo (Starting) <startup-with-shell>: Add @anchor.
(Connecting) <Remote Packet>: Add "startup-with-shell"
and "QStartupWithShell" to the table.
(Remote Protocol) <QStartupWithShell>: New item, explaining the
packet.

7 years agoShare fork_inferior et al with gdbserver
Sergio Durigan Junior [Fri, 23 Dec 2016 02:11:11 +0000 (21:11 -0500)]
Share fork_inferior et al with gdbserver

This is the most important (and the biggest, sorry) patch of the
series.  It moves fork_inferior from gdb/fork-child.c to
nat/fork-inferior.c and makes all the necessary adjustments to both
GDB and gdbserver to make sure everything works OK.

There is no "most important change" with this patch; all changes are
made in a progressive way, making sure that gdbserver had the
necessary features while not breaking GDB at the same time.

I decided to go ahead and implement a partial support for starting the
inferior with a shell on gdbserver, although the full feature comes in
the next patch.  The user won't have the option to disable the
startup-with-shell, and also won't be able to change which shell
gdbserver will use (other than setting the $SHELL environment
variable, that is).

Everything is working as expected, and no regressions were present
during the tests.

gdb/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>
    Pedro Alves  <palves@redhat.com>

* Makefile.in (HFILES_NO_SRCDIR): Add "common/common-inferior.h"
and "nat/fork-inferior.h".
* common/common-inferior.h: New file, with contents from
"gdb/inferior.h".
* commom/common-utils.c: Include "common-utils.h".
(stringify_argv): New function.
* common/common-utils.h (stringify_argv): New prototype.
* configure.nat: Add "fork-inferior.o" as a dependency for
"*linux*", "fbsd*" and "nbsd*" hosts.
* corefile.c (get_exec_file): Update comment.
* darwin-nat.c (darwin_ptrace_him): Call "gdb_startup_inferior"
instead of "startup_inferior".
(darwin_create_inferior): Call "add_thread_silent" after
"fork_inferior".
* fork-child.c: Cleanup unnecessary includes.
(SHELL_FILE): Move to "common/common-fork-child.c".
(environ): Likewise.
(exec_wrapper): Initialize.
(get_exec_wrapper): New function.
(breakup_args): Move to "common/common-fork-child.c"; rename to
"breakup_args_for_exec".
(escape_bang_in_quoted_argument): Move to
"common/common-fork-child.c".
(saved_ui): New variable.
(prefork_hook): New function.
(postfork_hook): Likewise.
(postfork_child_hook): Likewise.
(gdb_startup_inferior): Likewise.
(fork_inferior): Move to "common/common-fork-child.c".  Update
function to support gdbserver.
(startup_inferior): Likewise.
* gdbcore.h (get_exec_file): Remove declaration.
* gnu-nat.c (gnu_create_inferior): Call "gdb_startup_inferior"
instead of "startup_inferior".  Call "add_thread_silent" after
"fork_inferior".
* inf-ptrace.c: Include "nat/fork-inferior.h" and "utils.h".
(inf_ptrace_create_inferior): Call "gdb_startup_inferior"
instead of "startup_inferior".  Call "add_thread_silent" after
"fork_inferior".
* inferior.h: Include "common-inferior.h".
(trace_start_error): Move to "common/common-utils.h".
(trace_start_error_with_name): Likewise.
(fork_inferior): Move prototype to "nat/fork-inferior.h".
(startup_inferior): Likewise.
(gdb_startup_inferior): New prototype.
* nat/fork-inferior.c: New file, with contents from "fork-child.c".
* nat/fork-inferior.h: New file.
* procfs.c (procfs_init_inferior): Call "gdb_startup_inferior"
instead of "startup_inferior".  Call "add_thread_silent" after
"fork_inferior".
* target.h (target_terminal_init): Move prototype to
"target/target.h".
(target_terminal_inferior): Likewise.
(target_terminal_ours): Likewise.
* target/target.h (target_terminal_init): New prototype, moved
from "target.h".
(target_terminal_inferior): Likewise.
(target_terminal_ours): Likewise.
* utils.c (gdb_flush_out_err): New function.

gdb/gdbserver/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>
    Pedro Alves  <palves@redhat.com>

* Makefile.in (SFILES): Add "nat/fork-inferior.o".
* configure: Regenerate.
* configure.srv (srv_linux_obj): Add "fork-child.o" and
"fork-inferior.o".
(i[34567]86-*-lynxos*): Likewise.
(spu*-*-*): Likewise.
* fork-child.c: New file.
* linux-low.c: Include "common-inferior.h", "nat/fork-inferior.h"
and "environ.h".
(linux_ptrace_fun): New function.
(linux_create_inferior): Adjust function prototype to reflect
change on "target.h".  Adjust function code to use
"fork_inferior".
(linux_request_interrupt): Delete "signal_pid".
* lynx-low.c: Include "common-inferior.h" and "nat/fork-inferior.h".
(lynx_ptrace_fun): New function.
(lynx_create_inferior): Adjust function prototype to reflect
change on "target.h".  Adjust function code to use
"fork_inferior".
* nto-low.c (nto_create_inferior): Adjust function prototype and
code to reflect change on "target.h".  Update comments.
* server.c: Include "common-inferior.h", "nat/fork-inferior.h",
"common-terminal.h" and "environ.h".
(terminal_fd): Moved to fork-child.c.
(old_foreground_pgrp): Likewise.
(restore_old_foreground_pgrp): Likewise.
(last_status): Make it global.
(last_ptid): Likewise.
(our_environ): New variable.
(startup_with_shell): Likewise.
(program_name): Likewise.
(program_argv): Rename to...
(program_args): ...this.
(wrapper_argv): New variable.
(start_inferior): Delete function.
(get_exec_wrapper): New function.
(get_exec_file): Likewise.
(get_environ): Likewise.
(prefork_hook): Likewise.
(post_fork_inferior): Likewise.
(postfork_hook): Likewise.
(postfork_child_hook): Likewise.
(handle_v_run): Update code to deal with arguments coming from the
remote host.  Update calls from "start_inferior" to
"create_inferior".
(captured_main): Likewise.  Initialize environment variable.  Call
"have_job_control".
* server.h (post_fork_inferior): New prototype.
(get_environ): Likewise.
(last_status): Declare.
(last_ptid): Likewise.
(signal_pid): Likewise.
* spu-low.c: Include "common-inferior.h" and "nat/fork-inferior.h".
(spu_ptrace_fun): New function.
(spu_create_inferior): Adjust function prototype to reflect change
on "target.h".  Adjust function code to use "fork_inferior".
* target.c (target_terminal_init): New function.
(target_terminal_inferior): Likewise.
(target_terminal_ours): Likewise.
* target.h: Include <vector>.
(struct target_ops) <create_inferior>: Update prototype.
(create_inferior): Update macro.
* utils.c (gdb_flush_out_err): New function.
* win32-low.c (win32_create_inferior): Adjust function prototype
and code to reflect change on "target.h".

gdb/testsuite/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* gdb.server/non-existing-program.exp: Update regex in order to
reflect the fact that gdbserver is now using fork_inferior (with a
shell) to startup the inferior.

7 years agoShare parts of gdb/gdbthread.h with gdbserver
Sergio Durigan Junior [Thu, 22 Dec 2016 18:30:42 +0000 (13:30 -0500)]
Share parts of gdb/gdbthread.h with gdbserver

GDB and gdbserver now share 'switch_to_thread' because of
fork_inferior.  To make things clear, I created a new file name
common/common-gdbthread.h, and left the implementation specific to
each part.

gdb/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* Makefile.in (HFILES_NO_SRCDIR): Add "common/common-gdbthread.h".
* common/common-gdbthread.h: New file, with parts from
"gdb/gdbthread.h".
* gdbthread.h: Include "common-gdbthread.h".
(switch_to_thread): Moved to "common/common-gdbthread.h".

gdb/gdbserver/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* inferiors.c (switch_to_thread): New function.

7 years agoMove parts of inferior job control to common/
Sergio Durigan Junior [Thu, 22 Dec 2016 17:41:16 +0000 (12:41 -0500)]
Move parts of inferior job control to common/

This commit moves a few bits responsible for dealing with inferior job
control from GDB to common/, which makes them available to gdbserver.
This is necessary for the upcoming patches that will share
fork_inferior et al between GDB and gdbserver.

We move some parts of gdb/terminal.h to gdb/common/common-terminal.h,
especifically the code that checks terminal features and that are used
to set job_control accordingly.

After sharing parts of gdb/terminal.h, we also to share the two
functions on gdb/inflow.c that are going to be needed by the
fork_inferior rework.  They are 'gdb_setpgid' and the new
'have_job_control'.  I've also taken the opportunity to give a more
meaningful name to "inflow.c" on common/.  Now it is called
"job-control.c" (thanks Pedro for the suggestion).

gdb/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* Makefile.in (SFILES): Add "common/job-control.c".
(HFILES_NO_SRCDIR): Add "common/job-control.h".
(COMMON_OBS): Add "job-control.o".
* common/job-control.c: New file, with contents from
"gdb/inflow.c".
* common/job-control.h: New file, with contents from "terminal.h".
* fork-child.c: Include "job-control.h".
* inflow.c: Include "job-control.h".
(gdb_setpgid): Move to "common/common-inflow.c".
(_initialize_inflow): Move setting of "job_control" to
"handle_job_control".
* terminal.h (job_control): Moved to "common/common-terminal.h".
(gdb_setpgid): Likewise.
* top.c: Include "job_control.h".
* utils.c: Likewise.
(job_control): Moved to "job-control.c".

gdb/gdbserver/ChangeLog:
2017-06-07  Sergio Durigan Junior  <sergiodj@redhat.com>

* Makefile.in (SFILE): Add "common/job-control.c".
(OBS): Add "job-control.o".

7 years agoIntroduce compiled_regex, eliminate make_regfree_cleanup
Pedro Alves [Wed, 7 Jun 2017 13:21:40 +0000 (14:21 +0100)]
Introduce compiled_regex, eliminate make_regfree_cleanup

This patch replaces compile_rx_or_error and make_regfree_cleanup with
a class that wraps a regex_t.

gdb/ChangeLog:
2017-06-07  Pedro Alves  <palves@redhat.com>

* Makefile.in (SFILES): Add gdb_regex.c.
(COMMON_OBS): Add gdb_regex.o.
* ada-lang.c (ada_add_standard_exceptions)
(ada_add_exceptions_from_frame, name_matches_regex)
(ada_add_global_exceptions, ada_exceptions_list_1): Change regex
parameter type to compiled_regex.  Adjust.
(ada_exceptions_list): Use compiled_regex.
* break-catch-throw.c (exception_catchpoint::pattern): Now a
std::unique_ptr<compiled_regex>.
(exception_catchpoint::~exception_catchpoint): Remove regfree
call.
(check_status_exception_catchpoint): Adjust to use compiled_regex.
(handle_gnu_v3_exceptions): Adjust to use compiled_regex.
* breakpoint.c (solib_catchpoint::compiled): Now a
std::unique_ptr<compiled_regex>.
(solib_catchpoint::~solib_catchpoint): Remove regfree call.
(check_status_catch_solib): Adjust to use compiled_regex.
(add_solib_catchpoint): Adjust to use compiled_regex.
* cli/cli-cmds.c (apropos_command): Use compiled_regex.
* cli/cli-decode.c (apropos_cmd): Change regex parameter to
compiled_regex reference.  Adjust to use it.
* cli/cli-decode.h: Remove struct re_pattern_buffer forward
declaration.  Include "gdb_regex.h".
(apropos_cmd): Change regex parameter to compiled_regex reference.
* gdb_regex.c: New file.
* gdb_regex.h (make_regfree_cleanup, get_regcomp_error): Delete
declarations.
(class compiled_regex): New.
* linux-tdep.c: Include "common/gdb_optional.h".
(struct mapping_regexes): New, factored out from
mapping_is_anonymous_p, and adjusted to use compiled_regex.
(mapping_is_anonymous_p): Use mapping_regexes wrapped in a
gdb::optional and remove cleanups.  Adjust to compiled_regex.
* probe.c: Include "common/gdb_optional.h".
(collect_probes): Use compiled_regex and gdb::optional and remove
cleanups.
* skip.c: Include "common/gdb_optional.h".
(skiplist_entry::compiled_function_regexp): Now a
gdb::optional<compiled_regex>.
(skiplist_entry::compiled_function_regexp_is_valid): Delete field.
(free_skiplist_entry): Remove regfree call.
(compile_skip_regexp, skip_rfunction_p): Adjust to use
compiled_regex and gdb::optional.
* symtab.c: Include "common/gdb_optional.h".
(search_symbols): Use compiled_regex and gdb::optional.
* utils.c (do_regfree_cleanup, make_regfree_cleanup)
(get_regcomp_error, compile_rx_or_error): Delete.  Some bits moved
to gdb_regex.c.

7 years agoAdd support for AArch64 system register names IP0, IP1, FP and LR.
Michael Collison [Wed, 7 Jun 2017 12:34:34 +0000 (13:34 +0100)]
Add support for AArch64 system register names IP0, IP1, FP and LR.

* config/tc-aarch64.c (reg_entry_reg_names): Add IP0,
IP1, FP, and LR as register aliases of register 16, 17, 29
and 30 respectively.
* testsuite/gas/aarch64/diagnostic.l: Remove diagnostic
prohibiting register 'lr' which is now an alias.
* testsuite/gas/aarch64/diagnostic.s: Remove instruction
utilizing register 'lr' which is now an alias.

7 years agoRemove MAX_REGISTER_SIZE from regcache.c
Alan Hayward [Wed, 7 Jun 2017 09:16:46 +0000 (10:16 +0100)]
Remove MAX_REGISTER_SIZE from regcache.c

gdb/
* regcache.c (regcache::save): Avoid buffer use.
(regcache::dump): Likewise.

7 years agoRemove MAX_REGISTER_SIZE from sh(64)-tdep.c
Alan Hayward [Wed, 7 Jun 2017 09:06:10 +0000 (10:06 +0100)]
Remove MAX_REGISTER_SIZE from sh(64)-tdep.c

gdb/
* sh-tdep.c (sh_pseudo_register_read): Remove
MAX_REGISTER_SIZE.
(sh_pseudo_register_write): Likewise.
* sh64-tdep.c (sh64_pseudo_register_read): Likewise.
(sh64_pseudo_register_write): Likewise.

7 years agoRemove MAX_REGISTER_SIZE from aarch64-tdep.c
Alan Hayward [Wed, 7 Jun 2017 08:57:55 +0000 (09:57 +0100)]
Remove MAX_REGISTER_SIZE from aarch64-tdep.c

gdb/
* aarch64-tdep.c (aarch64_store_return_value): Use
V_REGISTER_SIZE.
(aarch64_pseudo_read_value): Likewise.
(aarch64_pseudo_write): Likewise.

7 years agoFix a number of pr21529 testcase failures
Alan Modra [Wed, 7 Jun 2017 05:52:58 +0000 (15:22 +0930)]
Fix a number of pr21529 testcase failures

Various targets fail this testcase due to ld not supporting binary output.

* testsuite/ld-unique/pr21529.d: xfail aarch64, arm, hppa, ia64,
nds32, and score.  Match any output.

7 years agoAutomatic date update in version.in
GDB Administrator [Wed, 7 Jun 2017 00:00:40 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agobfd: support section groups with preceding SHF_GROUP sections
Jose E. Marchesi [Tue, 6 Jun 2017 18:19:06 +0000 (11:19 -0700)]
bfd: support section groups with preceding SHF_GROUP sections

GAS always places section groups (SHT_GROUP) before the rest of the
sections in the output file.  However, other assemblers may place
section groups after the group members.

This patch fixes handlign such situations, and removes some duplicated
logic.

bfd/ChangeLog:

2017-06-06  Jose E. Marchesi  <jose.marchesi@oracle.com>

* elf.c (setup_group): Make sure BFD sections are created for all
group sections in the input file when processing SHF_GROUP
sections.
(bfd_section_from_shdr): Avoid duplicating logic already
implemented in `setup_group'.

7 years agoRemove declaration of set_register_cache from regdef.h
Yao Qi [Tue, 6 Jun 2017 15:42:45 +0000 (16:42 +0100)]
Remove declaration of set_register_cache from regdef.h

Function set_register_cache was removed by 3aee891821f538cfb4e0a08a26196c70127f1474
([GDBserver] Multi-process + multi-arch), so this patch removes the
declaration too.

gdb:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

* regformats/regdef.h (set_register_cache): Remove the
declaration.

7 years agoRemove a MAX_REGISTER_SIZE from frame.c
Alan Hayward [Tue, 6 Jun 2017 15:34:20 +0000 (16:34 +0100)]
Remove a MAX_REGISTER_SIZE from frame.c

gdb/
* frame.c (frame_unwind_register_signed): Use
frame_unwind_register_value.

7 years agoFix double free when running gdb.linespec/ls-errs.exp (PR breakpoints/21553)
Pedro Alves [Tue, 6 Jun 2017 14:53:59 +0000 (15:53 +0100)]
Fix double free when running gdb.linespec/ls-errs.exp (PR breakpoints/21553)

The problem is that b->extra_string is free'ed twice: Once in the
breakpoint's dtor, and another time via make_cleanup (xfree).

This patch gets rid of the cleanups, fixing the problem.

Tested on x86_64 GNU/Linux.

gdb/ChangeLog:
2017-06-06  Pedro Alves  <palves@redhat.com>

PR breakpoints/21553
* breakpoint.c (create_breakpoints_sal_default)
(init_breakpoint_sal, create_breakpoint_sal): Use
gdb::unique_xmalloc_ptr for string parameters.
(create_breakpoint): Constify 'extra_string' and 'cond_string'
parameters.  Replace cleanups with gdb::unique_xmalloc_ptr.
(base_breakpoint_create_breakpoints_sal)
(bkpt_create_breakpoints_sal, tracepoint_create_breakpoints_sal)
(strace_marker_create_breakpoints_sal)
(create_breakpoints_sal_default): Use gdb::unique_xmalloc_ptr for
string parameters.
* breakpoint.h (breakpoint_ops::create_breakpoints_sal): Use
gdb::unique_xmalloc_ptr for string parameters.
(create_breakpoint): Constify 'extra_string' and 'cond_string'
parameters.

7 years agoRemove uses of MAX_REGISTER_SIZE from alpha-tdep.c
Alan Hayward [Tue, 6 Jun 2017 14:45:08 +0000 (15:45 +0100)]
Remove uses of MAX_REGISTER_SIZE from alpha-tdep.c

gdb/
* alpha-tdep.c (alpha_register_to_value): Use
get_frame_register_value.
(alpha_value_to_register): Use ALPHA_REGISTER_SIZE.

7 years agoHandle printing information about PE format files which have 0 as the value of the...
Daniel Bonniot de Ruisselet [Tue, 6 Jun 2017 14:06:02 +0000 (15:06 +0100)]
Handle printing information about PE format files which have 0 as the value of the HInt Table in the import tables structure.

PR binutils/21546
* peXXigen.c (pe_print_idata): Use the address of the first thunk
if the hint address is zero.

7 years ago[Patch, ARM] Relax the restrictions on REG_SP under Thumb mode on ARMv8-A
Jiong Wang [Thu, 25 May 2017 09:40:07 +0000 (10:40 +0100)]
[Patch, ARM] Relax the restrictions on REG_SP under Thumb mode on ARMv8-A

  For Thumb mode, since ARMv8-A, REG_SP is allowed in most of the places in
Rd/Rt/Rt2 etc while it was disallowed before ARMv8-A, and was rejected through
the "reject_bad_reg" macro and several scattered checks.

  This patch only rejects REG_SP in "reject_bad_reg" and several related places
for legacy architectures before ARMv8-A. I have checked those affected instructions
, all of them qualify such relaxations.

  Testcases adjusted accordingly.
    * ld-sp-warn.d was written without .arch and without -march options passed.
      By default it assumes all architectures, so I deleted the REG_SP warning
      on ldrsb as it's supported on ARMv8-A.  There are actually quite a few
      seperate tests on other architectures, for example ld-sp-warn-v7.l etc.,
      so there the test for ldrsb on legacy architectures are still covered.
    * sp-pc-validations-bad-t has been extended to armv8-a.
    * strex-bad-t.d restricted on armv7-a.
    * Some new tests for REG_SP used as Rd/Rt etc added in sp-usage-thumb2-relax*.

gas/
* config/tc-arm.c (reject_bad_reg): Allow REG_SP on ARMv8-A.
(parse_operands): Allow REG_SP for OP_oRRnpcsp and OP_RRnpcsp on
ARMv8-A.
(do_co_reg): Allow REG_SP for Rd on ARMv8-A.
(do_t_add_sub): Likewise.
(do_t_mov_cmp): Likewise.
(do_t_tb): Likewise.
* testsuite/gas/arm/ld-sp-warn.l: Delete the warning on REG_SP as Rt for
ldrsb.
* testsuite/gas/arm/sp-pc-validations-bad-t-v8a.d: New test.
* testsuite/gas/arm/sp-pc-validations-bad-t-v8a.l: New test.
* testsuite/gas/arm/sp-pc-validations-bad-t.d: Specifies -march=armv7-a.
* testsuite/gas/arm/sp-pc-validations-bad-t.s: Remove ".arch armv7-a".
* testsuite/gas/arm/sp-usage-thumb2-relax-on-v7.d: New test.
* testsuite/gas/arm/sp-usage-thumb2-relax-on-v7.l: New test.
* testsuite/gas/arm/sp-usage-thumb2-relax-on-v8.d: New test.
* testsuite/gas/arm/sp-usage-thumb2-relax.s: New test.
* testsuite/gas/arm/strex-bad-t.d: Specifies -march=armv7-a.

7 years agoFix memory leaks in the sysinfo program.
Simon Marchi [Tue, 6 Jun 2017 13:52:31 +0000 (14:52 +0100)]
Fix memory leaks in the sysinfo program.

* sysinfo.y: Free memory allocated by token NAME.

7 years agoFix AArch64 in the same way as other targets updated in 8170f7693bc0a9442c0aa28019792...
James Clarke [Tue, 6 Jun 2017 13:30:47 +0000 (14:30 +0100)]
Fix AArch64 in the same way as other targets updated in 8170f7693bc0a9442c0aa280197925db92d48ca6.

PR ld/19579
* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Check
ELF_COMMON_DEF_P for common symbols.

7 years agoAdd IA64_MAX_FP_REGISTER_SIZE
Alan Hayward [Tue, 6 Jun 2017 12:50:07 +0000 (13:50 +0100)]
Add IA64_MAX_FP_REGISTER_SIZE

gdb/
* ia64-tdep.c (IA64_MAX_FP_REGISTER_SIZE) Add.
(ia64_register_to_value): Use IA64_MAX_FP_REGISTER_SIZE.
(ia64_value_to_register): Likewise.
(ia64_extract_return_value): Likewise.
(ia64_store_return_value): Likewise.
(ia64_push_dummy_call): Likewise.

7 years agold: Fix spelling mistake in comment.
Andrew Burgess [Tue, 6 Jun 2017 09:15:27 +0000 (10:15 +0100)]
ld: Fix spelling mistake in comment.

ld/ChangeLog:

* ld.h (struct args_type): Fix typo in comment.

7 years agold: Allow section groups to be resolved as part of a relocatable link
Andrew Burgess [Wed, 22 Mar 2017 17:27:49 +0000 (17:27 +0000)]
ld: Allow section groups to be resolved as part of a relocatable link

This commit adds a new linker feature: the ability to resolve section
groups as part of a relocatable link.

Currently section groups are automatically resolved when performing a
final link, and are carried through when performing a relocatable link.
By carried through this means that one copy of each section group (from
all the copies that might be found in all the input files) is placed
into the output file.  Sections that are part of a section group will
not match input section specifiers within a linker script and are
forcibly kept as separate sections.

There is a slight resemblance between section groups and common
section.  Like section groups, common sections are carried through when
performing a relocatable link, and resolved (allocated actual space)
only at final link time.

However, with common sections there is an ability to force the linker to
allocate space for the common sections when performing a relocatable
link, there's currently no such ability for section groups.

This commit adds such a mechanism.  This new facility can be accessed in
two ways, first there's a command line switch --force-group-allocation,
second, there's a new linker script command FORCE_GROUP_ALLOCATION.  If
one of these is used when performing a relocatable link then the linker
will resolve the section groups as though it were performing a final
link, the section group will be deleted, and the members of the group
will be placed like normal input sections.  If there are multiple copies
of the group (from multiple input files) then only one copy of the group
members will be placed, the duplicate copies will be discarded.

Unlike common sections that have the --no-define-common command line
flag, and INHIBIT_COMMON_ALLOCATION linker script command there is no
way to prevent group resolution during a final link, this is because the
ELF gABI specifically prohibits the presence of SHT_GROUP sections in a
fully linked executable.  However, the code as written should make
adding such a feature trivial, setting the new resolve_section_groups
flag to false during a final link should work as you'd expect.

bfd/ChangeLog:

* elf.c (_bfd_elf_make_section_from_shdr): Don't initially mark
SEC_GROUP sections as SEC_EXCLUDE.
(bfd_elf_set_group_contents): Replace use of abort with an assert.
(assign_section_numbers): Use resolve_section_groups flag instead
of relocatable link type.
(_bfd_elf_init_private_section_data): Use resolve_section_groups
flag instead of checking the final_link flag for part of the
checks in here.  Fix white space as a result.
* elflink.c (elf_link_input_bfd): Use resolve_section_groups flag
instead of relocatable link type.
(bfd_elf_final_link): Likewise.

include/ChangeLog:

* bfdlink.h (struct bfd_link_info): Add new resolve_section_groups
flag.

ld/ChangeLog:

* ld.h (struct args_type): Add force_group_allocation field.
* ldgram.y: Add support for FORCE_GROUP_ALLOCATION.
* ldlex.h: Likewise.
* ldlex.l: Likewise.
* lexsup.c: Likewise.
* ldlang.c (unique_section_p): Check resolve_section_groups flag
not the relaxable link flag.
(lang_add_section): Discard section groups when we're resolving
groups.  Clear the SEC_LINK_ONCE flag if we're resolving section
groups.
* ldmain.c (main): Initialise resolve_section_groups flag in
link_info based on command line flags.
* testsuite/ld-elf/group11.d: New file.
* testsuite/ld-elf/group12.d: New file.
* testsuite/ld-elf/group12.ld: New file.
* NEWS: Mention new features.
* ld.texinfo (Options): Document --force-group-allocation.
(Miscellaneous Commands): Document FORCE_GROUP_ALLOCATION.

7 years agobfd: remove unused local variables in elf32-score, elf32-score7 and elfxx-mips
Jose E. Marchesi [Tue, 6 Jun 2017 07:33:20 +0000 (00:33 -0700)]
bfd: remove unused local variables in elf32-score, elf32-score7 and elfxx-mips

bfd/ChangeLog:

2017-06-06  Jose E. Marchesi  <jose.marchesi@oracle.com>

* elfxx-mips.c (_bfd_mips_elf_relocate_section): Remove unused
variable `bed'.
* elf32-score.c (score_elf_final_link_relocate): Likewise.
(s3_bfd_score_elf_check_relocs): Likewise.
* elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise.
(score_elf_final_link_relocate): Likewise.
(s7_bfd_score_elf_check_relocs): Likewise.

7 years agobfd: remove unused local variable in elflink.c:init_reloc_cookie_rels
Jose E. Marchesi [Tue, 6 Jun 2017 07:01:58 +0000 (00:01 -0700)]
bfd: remove unused local variable in elflink.c:init_reloc_cookie_rels

bfd/ChangeLog:

2017-06-06  Jose E. Marchesi  <jose.marchesi@oracle.com>

* elflink.c (init_reloc_cookie_rels): Remove unused variable
`bed'.

7 years agoELF/BFD: Hold the number of internal static relocs in `->reloc_count'
Maciej W. Rozycki [Tue, 6 Jun 2017 00:24:06 +0000 (01:24 +0100)]
ELF/BFD: Hold the number of internal static relocs in `->reloc_count'

Correct a commit e5713223cbc1 ("MIPS/BFD: For n64 hold the number of
internal relocs in `->reloc_count'") regression and change internal
relocation handling in the generic ELF BFD linker code such that, except
in the presence of R_SPARC_OLO10 relocations, a section's `reloc_count'
holds the number of internal rather than external relocations, making
the handling more consistent between GAS, which sets `->reloc_count'
with a call to `bfd_set_reloc', and LD, which sets `->reloc_count' as it
reads input sections.

The handling of dynamic relocations remains unchanged and they continue
holding the number of external relocations in `->reloc_count'; they are
also not converted to the internal form except in `elf_link_sort_relocs'
(which does not handle the general, i.e. non-n64-MIPS case of composed
relocations correctly as per the ELF gABI, though it does not seem to
matter for the targets we currently support).

The n64 MIPS backend is the only one with `int_rels_per_ext_rel' set to
non-one, and consequently the change is trivial for all the remaining
backends and targets.

bfd/
* elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): Subtract `count'
from `reloc_count' rather than decrementing it.
* elf.c (bfd_section_from_shdr): Multiply the adjustment to
`reloc_count' by `int_rels_per_ext_rel'.
* elf32-score.c (score_elf_final_link_relocate): Do not multiply
`reloc_count' by `int_rels_per_ext_rel' for last relocation
entry determination.
(s3_bfd_score_elf_check_relocs): Likewise.
* elf32-score7.c (score_elf_final_link_relocate): Likewise.
(s7_bfd_score_elf_relocate_section): Likewise.
(s7_bfd_score_elf_check_relocs): Likewise.
* elf64-mips.c (mips_elf64_get_reloc_upper_bound): Remove
prototype and function.
(mips_elf64_slurp_one_reloc_table): Do not update `reloc_count'.
(mips_elf64_slurp_reloc_table): Assert that `reloc_count' is
triple rather than once the sum of REL and RELA relocation entry
counts.
(bfd_elf64_get_reloc_upper_bound): Remove macro.
* elflink.c (_bfd_elf_link_read_relocs): Do not multiply
`reloc_count' by `int_rels_per_ext_rel' for internal relocation
storage allocation size determination.
(elf_link_input_bfd): Multiply `.ctors' and `.dtors' section's
size by `int_rels_per_ext_rel'.  Do not multiply `reloc_count'
by `int_rels_per_ext_rel' for last relocation entry
determination.
(bfd_elf_final_link): Do not multiply `reloc_count' by
`int_rels_per_ext_rel' for internal relocation storage
allocation size determination.
(init_reloc_cookie_rels): Do not multiply `reloc_count' by
`int_rels_per_ext_rel' for last relocation entry determination.
(elf_gc_smash_unused_vtentry_relocs): Likewise.
* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
(_bfd_mips_elf_relocate_section): Likewise.