binutils-gdb.git
7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 9 May 2017 00:00:40 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAdd missing initializer to silence GCC 4.2
H.J. Lu [Mon, 8 May 2017 20:37:50 +0000 (13:37 -0700)]
Add missing initializer to silence GCC 4.2

Silence GCC 4.2:

elf64-x86-64.c: In function ‘elf_x86_64_get_synthetic_symtab’:
elf64-x86-64.c:6490: warning: missing initializer
elf64-x86-64.c:6490: warning: (near initialization for ‘plts[3].sec’)

* elf32-i386.c (elf_i386_get_synthetic_symtab): Add missing
initializer for GCC 4.2.
* lf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.

7 years agox86-64: Improve PLT generation and synthetic PLT symbols
H.J. Lu [Mon, 8 May 2017 19:24:11 +0000 (12:24 -0700)]
x86-64: Improve PLT generation and synthetic PLT symbols

On x86-64, the procedure linkage table (PLT) is used to

1. Call external function.
2. Call internal IFUNC function.  The best implementation is selected
for the target processor at run-time.
3. Act as the canonical function address.
4. Support LD_AUDIT to audit external function calls.
5. Support LD_PROFILE to profile external function calls.

PLT looks like:

PLT0:  push  GOT[1]
       jmp   *GOT[2]
       nop
PLT1:  jmp   *GOT[name1_index]
       push  name1_reloc_index
       jmp   PLT0

GOT is an array of addresses.  Initially the GOT entry of name1 is
filled with the address of the "push name1_reloc_index" instruction.
The function, name1, is called via "jmp *GOT[name1]" in the PLT entry.
Even when lazy binding is disabled by "-z now", the PLT0 entry may
still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
canonical function address.

When linker is invoked with "-z bndplt", a different PLT layout in .plt
is used:

PLT0:  push     GOT[1]
       bnd jmp  *GOT[2]
       nop
PLT1:  push     name1_reloc_index
       bnd jmp  PLT0
       nop

together with a second PLT section, .pl.bnd:

PLT1:  bnd jmp  *GOT[name1_index]
       nop

where the GOT entry of name1 is filled with the address of the push
instruction of the corresponding entry in .plt.

1. With lazy binding, when the external function, name1, is called the
first time, dynamic linker is called via PLT0 to update GOT[name1_index]
with the actual address of name1 and transfers control to name1
afterwards.
2. PLT is also used to call a local IFUNC function, name1, run-time
loader updates GOT[name1_index] when loading the module.

This patch

1. Remove PLT layout configurations from x86-64 backend_data.
2. Add generic, lay and non-lazy PLT layout configurations to x86-64
link_hash_table.  Generic PLT layout includes the PLT entry templates,
information how to update the first instruction in PLT and PLT eh_frame
informaton, which are initialized in x86-64 setup_gnu_properties, based
on "-z bndplt" and target selection.  PLT section alignment is also set
to PLT entry size for non-NaCl target.
3. Remove elf_x86_64_create_dynamic_sections.  create_dynamic_sections
isn't always called, but GOT relocations need GOT relocations.  Instead,
create all x86-64 specific dynamic sections with alignment to their entry
size  in x86-64 setup_gnu_properties, which initializes elf.dynobj, so
that x86-64 check_relocs can be simplified.
4. Rewrite elf_x86_64_get_synthetic_symtab to check PLT sections against
all dynamic relocations to support both lazy and non-lazy PLTs.

There is no change in PLT.  The only externally visible change is the
improvement of synthetic PLT symbols for .plt.got.

bfd/

* elf64-x86-64.c (PLT_ENTRY_SIZE): Renamed to ...
(LAZY_PLT_ENTRY_SIZE): This.
(NON_LAZY_PLT_ENTRY_SIZE): New.
(elf_x86_64_plt0_entry): Renamed to ...
(elf_x86_64_lazy_plt0_entry): This.
(elf_x86_64_plt_entry): Renamed to ...
(elf_x86_64_lazy_plt_entry): This.
(elf_x86_64_bnd_plt0_entry): Renamed to ...
(elf_x86_64_lazy_bnd_plt0_entry): This.
(elf_x86_64_legacy_plt_entry): Removed.
(elf_x86_64_bnd_plt_entry): Renamed to ...
(elf_x86_64_lazy_bnd_plt_entry): This.
(elf_x86_64_legacy_plt2_entry): Renamed to ...
(elf_x86_64_non_lazy_plt_entry): This.
(elf_x86_64_bnd_plt2_entry): Renamed to ...
(elf_x86_64_non_lazy_bnd_plt_entry): This.
(elf_x86_64_eh_frame_plt): Renamed to ...
(elf_x86_64_eh_frame_lazy_plt): This.
(elf_x86_64_eh_frame_bnd_plt): Renamed to ...
(elf_x86_64_eh_frame_lazy_bnd_plt): This.
(elf_x86_64_eh_frame_plt_got): Renamed to ...
(elf_x86_64_eh_frame_non_lazy_plt): This.
(elf_x86_64_lazy_plt_layout): New.
(elf_x86_64_non_lazy_plt_layout): Likewise.
(elf_x86_64_plt_layout): Likewise.
(elf_x86_64_backend_data): Remove PLT layout information.  Add
os for target system.
(GET_PLT_ENTRY_SIZE): Removed.
(elf_x86_64_lazy_plt): New.
(elf_x86_64_non_lazy_plt): Likewise.
(elf_x86_64_lazy_bnd_plt): Likewise.
(elf_x86_64_non_lazy_bnd_plt): Likewise.
(elf_x86-64_arch_bed): Updated.
(elf_x86_64_link_hash_table): Add plt, lazy_plt and non_lazy_plt.
(elf_x86_64_create_dynamic_sections): Removed.
(elf_x86_64_check_relocs): Don't check elf.dynobj.  Don't call
_bfd_elf_create_ifunc_sections nor _bfd_elf_create_got_section.
(elf_x86-64_adjust_dynamic_symbol): Updated.
(elf_x86_64_allocate_dynrelocs): Updated.  Pass 0 as PLT header
size to _bfd_elf_allocate_ifunc_dyn_relocs and don't allocate
size for PLT0 if there is no PLT0.  Get plt_entry_size from
non_lazy_plt for non-lazy PLT entries.
(elf_x86_64_size_dynamic_sections): Updated.  Get plt_entry_size
from non_lazy_plt for non-lazy PLT entries.
(elf_x86-64_relocate_section): Updated.  Properly get PLT index
if there is no PLT0.
(elf_x86_64_finish_dynamic_symbol): Updated.  Fill the first slot
in the PLT entry with generic PLT layout.  Fill the non-lazy PLT
entries with non-lazy PLT layout.  Don't fill the second and third
slots in the PLT entry if there is no PLT0.
(elf_x86_64_finish_dynamic_sections): Updated.  Don't fill PLT0
if there is no PLT0.  Set sh_entsize on the .plt.got section.
(compare_relocs): New.
(elf_x86_64_plt_type): Likewise.
(elf_x86_64_plt): Likewise.
(elf_x86_64_nacl_plt): New. Forward declaration.
(elf_x86_64_get_plt_sym_val): Removed.
(elf_x86_64_get_synthetic_symtab): Rewrite to check PLT sections
against all dynamic relocations.
(elf_x86_64_link_setup_gnu_properties): New function.
(elf_backend_create_dynamic_sections): Updated.
(elf_backend_setup_gnu_properties): New.
(elf_x86_64_nacl_plt): New.
(elf_x86_64_nacl_arch_bed): Updated.

ld/

* testsuite/ld-ifunc/ifunc-16-x86-64-now.d: New file.
* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
* testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise.
* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
* testsuite/ld-x86-64/mpx3n.dd: Likewise.
* testsuite/ld-x86-64/mpx4n.dd: Likewise.
* testsuite/ld-x86-64/plt-main-bnd-now.rd: Likewise.
* testsuite/ld-x86-64/plt2.dd: Likewise.
* testsuite/ld-x86-64/plt2.rd: Likewise.
* testsuite/ld-x86-64/plt2.s: Likewise.
* testsuite/ld-x86-64/pr20830a-now.d: Likewise.
* testsuite/ld-x86-64/pr20830b-now.d: Likewise.
* testsuite/ld-x86-64/pr21038a-now.d: Likewise.
* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
* testsuite/ld-x86-64/load1b-nacl.d: Updated.
* testsuite/ld-x86-64/load1b.d: Likewise.
* testsuite/ld-x86-64/plt-main-bnd.dd: Likewise.
* testsuite/ld-x86-64/pr20253-1h.d: Likewise.
* testsuite/ld-x86-64/pr20830a.d: Update the .plt.got section
with func@plt.
* testsuite/ld-x86-64/pr20830b.d: Likewise.
* testsuite/ld-x86-64/pr21038a.d: Likewise.
* testsuite/ld-x86-64/pr21038c.d: Likewise.
* testsuite/ld-x86-64/mpx.exp: Add some -z now tests.
* testsuite/ld-x86-64/x86-64.exp: Likewise.

7 years agoS/390: Fix ifunc missing runtime reloc
Andreas Krebbel [Mon, 8 May 2017 17:10:42 +0000 (19:10 +0200)]
S/390: Fix ifunc missing runtime reloc

This fixes a problem with a missing R_390_64 reloc against .data for a
function pointer to an ifunc function.

No regressions on s390x.

Pushed to mainline.

bfd/ChangeLog:

2017-05-08  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

* elf-s390-common.c: Don't check non_got_ref flag.
* elf32-s390.c (elf_s390_relocate_section): Likewise.
* elf64-s390.c (elf_s390_relocate_section): Likewise.

7 years agoi386: Improve PLT generation and synthetic PLT symbols
H.J. Lu [Mon, 8 May 2017 17:10:22 +0000 (10:10 -0700)]
i386: Improve PLT generation and synthetic PLT symbols

On i386, the procedure linkage table (PLT) is used to

1. Call external function.
2. Call internal IFUNC function.  The best implementation is selected
for the target processor at run-time.
3. Act as the canonical function address.
4. Support LD_AUDIT to audit external function calls.
5. Support LD_PROFILE to profile external function calls.

PLT looks like:

PLT0:  push  GOT[1]
       jmp   *GOT[2]
       nop
PLT1:  jmp   *GOT[name1_index]
       push  name1_reloc_index
       jmp   PLT0

GOT is an array of addresses.  Initially the GOT entry of name1 is
filled with the address of the "push name1_reloc_index" instruction.
The function, name1, is called via "jmp *GOT[name1]" in the PLT entry.
Even when lazy binding is disabled by "-z now", the PLT0 entry may
still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
canonical function address.

1. With lazy binding, when the external function, name1, is called the
first time, dynamic linker is called via PLT0 to update GOT[name1_index]
with the actual address of name1 and transfers control to name1
afterwards.
2. PLT is also used to call a local IFUNC function, name1, run-time
loader updates GOT[name1_index] when loading the module.

This patch

1. Remove PLT layout configurations from i386 backend_data.
2. Add generic, lay and non-lazy PLT layout configurations to i386
link_hash_table.  Generic PLT layout includes the PLT entry templates,
information how to update the first instruction in PLT and PLT eh_frame
informaton, which are initialized in i386 setup_gnu_properties, based
on PIC and target selection.  PLT section alignment is also set to PLT
entry size for non-NaCl/VxWorks target.
3. Remove elf_i386_create_dynamic_sections.  create_dynamic_sections
isn't always called, but GOT relocations need GOT relocations.  Instead,
create all i386 specific dynamic sections in i386 setup_gnu_properties,
which initializes elf.dynobj, so that i386 check_relocs can be simplified.
4. Rewrite elf_i386_get_synthetic_symtab to check PLT sections against
all dynamic relocations to support both lazy and non-lazy PLTs.

bfd/

* elf32-i386.c (PLT_ENTRY_SIZE): Renamed to ...
(LAZY_PLT_ENTRY_SIZE): This.
(NON_LAZY_PLT_ENTRY_SIZE): New.
(elf_i386_plt0_entry): Renamed to ...
(elf_i386_lazy_plt0_entry): This.
(elf_i386_plt_entry): Renamed to ...
(elf_i386_lazy_plt_entry): This.
(elf_i386_pic_plt0_entry): Renamed to ...
(elf_i386_pic_lazy_plt0_entry): This.
(elf_i386_pic_plt_entry): Renamed to ...
(elf_i386_pic_lazy_plt_entry): This.
(elf_i386_got_plt_entry): Renamed to ...
(elf_i386_non_lazy_plt_entry): This.
(elf_i386_pic_got_plt_entry): Renamed to ...
(elf_i386_pic_non_lazy_plt_entry): This.
(elf_i386_eh_frame_plt): Renamed to ...
(elf_i386_eh_frame_lazy_plt): This.
(elf_i386_eh_frame_plt_got): Renamed to ...
(elf_i386_eh_frame_non_lazy_plt): This.
(elf_i386_plt_layout): Renamed to ...
(elf_i386_lazy_plt_layout): This.  Remove eh_frame_plt_got and
eh_frame_plt_got_size.
(elf_i386_non_lazy_plt_layout): New.
(elf_i386_plt_layout): Likewise.
(elf_i386_non_lazy_plt): Likewise.
(GET_PLT_ENTRY_SIZE): Removed.
(elf_i386_plt): Renamed to ...
(elf_i386_lazy_plt): This.
(elf_i386_backend_data): Remove plt.  Rename is_vxworks to os.
(elf_i386_arch_bed): Updated.
(elf_i386_link_hash_table): Add plt, lazy_plt and non_lazy_plt.
(elf_i386_create_dynamic_sections): Removed.
(elf_i386_check_relocs): Don't check elf.dynobj.  Don't call
_bfd_elf_create_ifunc_sections nor _bfd_elf_create_got_section.
(elf_i386_adjust_dynamic_symbol): Updated.
(elf_i386_allocate_dynrelocs): Updated.  Pass 0 as PLT header
size to _bfd_elf_allocate_ifunc_dyn_relocs and don't allocate
size for PLT0 if there is no PLT0.
(elf_i386_size_dynamic_sections): Updated.  Check whether GOT
output section is discarded only if GOT isn't empty.
(elf_i386_relocate_section): Updated.  Properly get PLT index
if there is no PLT0.
(elf_i386_finish_dynamic_symbol): Updated.  Don't fill the
second and third slots in the PLT entry if there is no PLT0.
(elf_i386_finish_dynamic_sections): Updated.  Don't fill PLT0
if there is no PLT0.  Set sh_entsize on the .plt.got section.
(elf_i386_nacl_plt): Forward declaration.
(elf_i386_get_plt_sym_val): Removed.
(elf_i386_get_synthetic_symtab): Rewrite to check PLT sections
against all dynamic relocations.
(elf_i386_link_setup_gnu_properties): New function.
(elf_backend_create_dynamic_sections): Updated.
(elf_backend_setup_gnu_properties): New.
(elf_i386_nacl_plt): Updated.
(elf_i386_nacl_arch_bed): Likewise.
(elf_i386_vxworks_arch_bed): Likewise.

ld/

* testsuite/ld-i386/i386.exp: Add some -z now tests.
* testsuite/ld-i386/plt-pic2.dd: New file.
* testsuite/ld-i386/plt2.dd: Likewise.
* testsuite/ld-i386/plt2.rd: Likewise.
* testsuite/ld-i386/plt2.s: Likewise.
* testsuite/ld-ifunc/ifunc-16-i386-now.d: Likewise.
* testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise.
* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
* testsuite/ld-i386/pr20830.d: Update the .plt.got section
with func@plt.

7 years agoMake import libraries relocatable objects
Thomas Preud'homme [Mon, 8 May 2017 14:26:51 +0000 (15:26 +0100)]
Make import libraries relocatable objects

For ELF targets --out-implib currently generates an executable file
(e_type is ET_EXEC) despite the file being expected to be linked against
some other object file to make an executable later. It seems therefore
more sensible to make the import library a relocatable object file
(e_type set to ET_REL).

Incidentally, as dicted by requirement 8 of
"ARM v8-M Security Extensions: Requirements on Development Tools"
(document ARM-ECM-0359818) version 1.0, import libraries generated when
using --cmse-implib *must* be relocatable object file so this commit
also adds an assert there in case the type of ELF import library is
changed again in the future.

2017-05-08  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
* elflink.c (elf_output_implib): Remove executable flag from import
library bfd.
* elf32-arm.c (elf32_arm_filter_implib_symbols): Assert that the import
library is a relocatable object file.

ld/
* testsuite/ld-arm/arm-elf.exp
(Secure gateway import library generation): Check e_type field
of import library and executable produced.
* testsuite/ld-arm/cmse-implib.type: Expectations for e_type field.

7 years agoRemove some uses of MAX_REGISTER_SIZE from mips-tdep.c
Alan Hayward [Mon, 8 May 2017 08:40:07 +0000 (09:40 +0100)]
Remove some uses of MAX_REGISTER_SIZE from mips-tdep.c

gdb/
* mips-tdep.c (mips_o32_return_value): Remove unused buffer.
(print_gp_register_row): Use get_frame_register_value.

7 years agoRemove some uses of MAX_REGISTER_SIZE from mips-linux-tdep.c
Alan Hayward [Mon, 8 May 2017 08:37:26 +0000 (09:37 +0100)]
Remove some uses of MAX_REGISTER_SIZE from mips-linux-tdep.c

gdb/
* mips-linux-tdep.c (mips_supply_gregset): Use raw_supply_zeroed.
(mips_supply_fpregset): Likewise.
(mips64_supply_gregset): Likewise.

7 years agoRemove some uses of MAX_REGISTER_SIZE uses from mn10300-linux-tdep.c
Alan Hayward [Mon, 8 May 2017 08:35:45 +0000 (09:35 +0100)]
Remove some uses of MAX_REGISTER_SIZE uses from mn10300-linux-tdep.c

gdb/
* mn10300-linux-tdep.c (am33_supply_gregset_method): Use
regcache->raw_supply_zeroed.

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 8 May 2017 00:00:41 +0000 (00:00 +0000)]
Automatic date update in version.in

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

7 years agoRearrange gdb/configure.nat to make it simpler and less redundant
Sergio Durigan Junior [Wed, 3 May 2017 01:32:33 +0000 (21:32 -0400)]
Rearrange gdb/configure.nat to make it simpler and less redundant

The previous commit introduced gdb/configure.nat, but it was just a
copy-and-past (with the necessary adjustments) from the files under
gdb/config/.  We can do better than that.

Instead of using one big 'case' statement that matches the
${gdb_host_cpu} and then match each ${gdb_host}, it is possible to
remove a lof of redundancy by matching the most common ${gdb_host}'s
first, setting the common variables for each, and then proceed to
matching specific ${gdb_host}'s and ${gdb_host_cpu}'s.  In other
words, reverse the order of the 'case's and take advantage of the fact
that a lot of parameters are the same for each host.

This commit was tested on x86_64 without regressions.

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

  * configure.nat: Rearrange 'case' statements to match
host before cpu.

7 years agoIntroduce "gdb/configure.nat" (and delete "gdb/config/*/*.mh" files)
Sergio Durigan Junior [Tue, 25 Apr 2017 20:03:39 +0000 (16:03 -0400)]
Introduce "gdb/configure.nat" (and delete "gdb/config/*/*.mh" files)

Due to my ongoing work to make it possible for gdbserver to start the
inferior using the shell, I had to share the fork_inferior function
under the "nat/" directory.  In order to do that, I created a new file
and put the function there; however, this meant that I now had to
update some of the *.mh files (under "gdb/config") and add the new
file as a dependency to be built natively.  Bleh...

After talking a bit to Pedro about this, the idea came up to write a
new "gdb/configure.nat" file, a la "gdb/configure.tgt", which would
concentrate all of the native settings for each host/system.  I
decided to tackle this issue.

The patch is simple.  All of the previous Makefile variables that were
being declared inside the *.mh files are now inside "gdb/Makefile.in",
and "gdb/configure" is responsible for AC_SUBST'ing them.  The
definitions of these variables were put inside "gdb/configure.nat", so
now they're shell variables.  For excerpts of Makefile code, one must
create a file under "gdb/config/${gdb_cpu_host}" and reference it on
the "nat_extra_makefile_frag" variable.

It should now be easier to update the native dependencies of hosts in
this single file.

This has been tested on x86_64 without regressions.

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

* Makefile.in: Remove "@host_makefile_frag@".  Add variables
NAT_FILE, NATDEPFILES, NAT_CDEPS, LOADLIBES, MH_CFLAGS, XM_CLIBS,
NAT_GENERATED_FILES, HAVE_NATIVE_GCORE_HOST.  Add
"@nat_extra_makefile_frag@".
(Makefile): Remove dependency on "@frags@".
($(GNULIB_BUILDDIR)/Makefile): Likewise.
(data-directory/Makefile): Likewise.
* config/aarch64/linux.mh: Deleted; moved contents to
"gdb/configure.nat".
* config/alpha/alpha-linux.mh: Likewise.
* config/alpha/nbsd.mh: Likewise.
* config/arm/linux.mh: Likewise.
* config/arm/nbsdelf.mh: Likewise.
* config/i386/cygwin.mh: Likewise.
* config/i386/cygwin64.mh: Likewise.
* config/i386/darwin.mh: Likewise.
* config/i386/fbsd.mh: Likewise.
* config/i386/fbsd64.mh: Likewise.
* config/i386/go32.mh: Likewise.
* config/i386/i386gnu.mh: Likewise.
* config/i386/i386sol2.mh: Likewise.
* config/i386/linux.mh: Likewise.
* config/i386/linux64.mh: Likewise.
* config/i386/mingw.mh: Likewise.
* config/i386/mingw64.mh: Likewise.
* config/i386/nbsd64.mh: Likewise.
* config/i386/nbsdelf.mh: Likewise.
* config/i386/nto.mh: Likewise.
* config/i386/obsd.mh: Likewise.
* config/i386/obsd64.mh: Likewise.
* config/i386/sol2-64.mh: Likewise.
* config/ia64/linux.mh: Likewise.
* config/m32r/linux.mh: Likewise.
* config/m68k/linux.mh: Likewise.
* config/m68k/nbsdelf.mh: Likewise.
* config/m68k/obsd.mh: Likewise.
* config/m88k/obsd.mh: Likewise.
* config/mips/fbsd.mh: Likewise.
* config/mips/linux.mh: Likewise.
* config/mips/nbsd.mh: Likewise.
* config/mips/obsd64.mh: Likewise.
* config/pa/linux.mh: Likewise.
* config/pa/nbsd.mh: Likewise.
* config/pa/obsd.mh: Likewise.
* config/powerpc/aix.mh: Likewise.
* config/powerpc/fbsd.mh: Likewise.
* config/powerpc/linux.mh: Likewise.
* config/powerpc/nbsd.mh: Likewise.
* config/powerpc/obsd.mh: Likewise.
* config/powerpc/ppc64-linux.mh: Likewise.
* config/powerpc/spu-linux.mh: Likewise.
* config/s390/linux.mh: Likewise.
* config/sh/nbsd.mh: Likewise.
* config/sparc/fbsd.mh: Likewise.
* config/sparc/linux.mh: Likewise.
* config/sparc/linux64.mh: Likewise.
* config/sparc/nbsd64.mh: Likewise.
* config/sparc/nbsdelf.mh: Likewise.
* config/sparc/obsd64.mh: Likewise.
* config/sparc/sol2.mh: Likewise.
* config/tilegx/linux.mh: Likewise.
* config/vax/nbsdelf.mh: Likewise.
* config/vax/obsd.mh: Likewise.
* config/xtensa/linux.mh: Likewise.
* config/i386/i386gnu.mn: New file, with excerpts from
"config/i386/i386gnu.mh".
* configure: Regenerate.
* configure.ac: Rewrite code to use "gdb/configure.nat" instead of
*.mh files under "gdb/config".
* configure.nat: New file, with contents from the
"gdb/config/*/*.mh" files.

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

* Makefile: Remove "@host_makefile_frag@".

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 6 May 2017 00:00:53 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agobtrace: Fix memory leak in btrace_clear.
Tim Wiederhake [Fri, 5 May 2017 06:20:50 +0000 (08:20 +0200)]
btrace: Fix memory leak in btrace_clear.

7 years agogdb: Disable -Werror for -Wmaybe-uninitialized
Pedro Alves [Fri, 5 May 2017 00:03:28 +0000 (01:03 +0100)]
gdb: Disable -Werror for -Wmaybe-uninitialized

Newer GCCs are triggering false-positive -Wmaybe-uninitialized
warnings around code that uses gdb::optional:
  https://sourceware.org/ml/gdb-patches/2017-05/msg00118.html

Using std::optional wouldn't help, it triggers the same warnings:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635

Initializing the variables to quiet the warning would defeat the
purpose of gdb::optional.  Making the optional ctor memset its storage
would be a pessimization.  Wrapping gdb::optional's internals with
"#pragma GCC diagnostic push/ignored/pop" doesn't work, we'd have to
wrap uses of gdb::optional instead, which I think would get unwieldy
and ugly as we start using gdb::optional more and more.

The -Wmaybe-uninitialized warning is documented as producing false
positives (unlike -Wuninialized), so until we find a better
workaround, disable -Werror for this warning.  You'll still see the
warning when building gdb, but it won't cause a build failure.

Tested by building with gcc 4.8.5, 5.3.1, and gcc trunk (20170428).

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

* warning.m4 (build_warnings): Add -Wno-error=maybe-uninitialized.
* configure: Regenerate.

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

* configure: Regenerate.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 5 May 2017 00:00:37 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoFix gdb.python/py-record-btrace-threads.exp with Python 3
Pedro Alves [Thu, 4 May 2017 15:02:36 +0000 (16:02 +0100)]
Fix gdb.python/py-record-btrace-threads.exp with Python 3

Fix several instances of:

 ...
 python print not f1calls
   File "<string>", line 1
     print not f1calls
     ^
 SyntaxError: Missing parentheses in call to 'print'
 Error while executing Python code.
 (gdb) FAIL: gdb.python/py-record-btrace-threads.exp: thread=1: checking thread 1: python print not f1calls
 ...

gdb/testsuite/ChangeLog:
2017-05-04  Pedro Alves  <palves@redhat.com>

* gdb.python/py-record-btrace-threads.exp (check_insn_for_thread):
Add parens to print call for Python 3.

7 years agoRAII-fy make_cleanup_restore_current_thread & friends
Pedro Alves [Thu, 4 May 2017 11:46:44 +0000 (12:46 +0100)]
RAII-fy make_cleanup_restore_current_thread & friends

After all the make_cleanup_restore_current_thread fixing, I thought
I'd convert that and its relatives (which are all cleanups) to RAII
classes.

scoped_restore_current_pspace_and_thread was put in a separate file to
avoid a circular dependency.

Tested on x86-64 Fedora 23, native and gdbserver.

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

* Makefile.in (SFILES): Add progspace-and-thread.c.
(HFILES_NO_SRCDIR): Add progspace-and-thread.h.
(COMMON_OBS): Add progspace-and-thread.o.
* breakpoint.c: Include "progspace-and-thread.h".
(update_inserted_breakpoint_locations)
(insert_breakpoint_locations, create_longjmp_master_breakpoint):
Use scoped_restore_current_pspace_and_thread.
(create_std_terminate_master_breakpoint): Use
scoped_restore_current_program_space.
(remove_breakpoint): Use scoped_restore_current_pspace_and_thread.
(print_breakpoint_location): Use
scoped_restore_current_program_space.
(bp_loc_is_permanent): Use
scoped_restore_current_pspace_and_thread.
(resolve_sal_pc): Use scoped_restore_current_pspace_and_thread.
(download_tracepoint_locations): Use
scoped_restore_current_pspace_and_thread.
(breakpoint_re_set): Use scoped_restore_current_pspace_and_thread.
* exec.c (exec_close_1): Use scoped_restore_current_program_space.
(enum step_over_calls_kind): Moved from inferior.h.
(class scoped_restore_current_thread): New class.
* gdbthread.h (make_cleanup_restore_current_thread): Delete
declaration.
(scoped_restore_current_thread): New class.
* infcmd.c: Include "common/gdb_optional.h".
(continue_1, proceed_after_attach): Use
scoped_restore_current_thread.
(notice_new_inferior): Use scoped_restore_current_thread.
* inferior.c: Include "progspace-and-thread.h".
(restore_inferior, save_current_inferior): Delete.
(add_inferior_command, clone_inferior_command): Use
scoped_restore_current_pspace_and_thread.
* inferior.h (scoped_restore_current_inferior): New class.
* infrun.c: Include "progspace-and-thread.h" and
"common/gdb_optional.h".
(follow_fork_inferior): Use
scoped_restore_current_pspace_and_thread.
(scoped_restore_exited_inferior): New class.
(handle_vfork_child_exec_or_exit): Use
scoped_restore_exited_inferior,
scoped_restore_current_pspace_and_thread,
scoped_restore_current_thread and scoped_restore.
(fetch_inferior_event): Use scoped_restore_current_thread.
* linespec.c (decode_line_full, decode_line_1): Use
scoped_restore_current_program_space.
* mi/mi-main.c: Include "progspace-and-thread.h".
(exec_continue): Use scoped_restore_current_thread.
(mi_cmd_exec_run): Use scoped_restore_current_pspace_and_thread.
(mi_cmd_trace_frame_collected): Use scoped_restore_current_thread.
* proc-service.c (ps_pglobal_lookup): Use
scoped_restore_current_program_space.
* progspace-and-thread.c: New file.
* progspace-and-thread.h: New file.
* progspace.c (release_program_space, clone_program_space): Use
scoped_restore_current_program_space.
(restore_program_space, save_current_program_space)
(save_current_space_and_thread): Delete.
(switch_to_program_space_and_thread): Moved to
progspace-and-thread.c.
* progspace.h (save_current_program_space)
(save_current_space_and_thread): Delete declarations.
(scoped_restore_current_program_space): New class.
* remote.c (remote_btrace_maybe_reopen): Use
scoped_restore_current_thread.
* symtab.c: Include "progspace-and-thread.h".
(skip_prologue_sal): Use scoped_restore_current_pspace_and_thread.
* thread.c (print_thread_info_1): Use
scoped_restore_current_thread.
(struct current_thread_cleanup): Delete.
(do_restore_current_thread_cleanup)
(restore_current_thread_cleanup_dtor): Rename/convert both to ...
(scoped_restore_current_thread::~scoped_restore_current_thread):
... this new dtor.
(make_cleanup_restore_current_thread): Rename/convert to ...
(scoped_restore_current_thread::scoped_restore_current_thread):
... this new ctor.
(thread_apply_all_command): Use scoped_restore_current_thread.
(thread_apply_command): Use scoped_restore_current_thread.
* tracepoint.c (tdump_command): Use scoped_restore_current_thread.
* varobj.c (value_of_root_1): Use scoped_restore_current_thread.

7 years agomake_cleanup_restore_current_thread: Look up thread earlier
Pedro Alves [Thu, 4 May 2017 13:43:34 +0000 (14:43 +0100)]
make_cleanup_restore_current_thread: Look up thread earlier

The unconditional is_stopped call already asserts that the thread exists.

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

* thread.c (make_cleanup_restore_current_thread): Move
find_thread_ptid call before the is_stopped call.  Assert that the
thread is found.  Replace is_stopped call by checking the thread's
state directly.  Remove unnecessary NULL-thread check.

7 years agoFix get_core_register_section leak, introduce thread_section_name
Pedro Alves [Thu, 4 May 2017 14:14:37 +0000 (15:14 +0100)]
Fix get_core_register_section leak, introduce thread_section_name

This plugs a leak introduced in the previous change to
get_core_register_section, which removed an xfree call that is
actually necessary because the 'section_name' local is static.

From [1] it looks like the reason the variable was made static to
begin with, was just "laziness" to avoid having to think about freeing
it on every function return path:

 https://sourceware.org/ml/gdb-patches/2005-03/msg00237.html

The easiest to fix that nowadays is to use a std::string.

I don't see a need to xstrdup the section name in the single-threaded
case though, and also there's more than one place that computes a
multi-threaded section name in the same way.  So put the section name
computation in a wrapper class with state.

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

* corelow.c (thread_section_name): New class.
(get_core_register_section, get_core_siginfo): Use it.

7 years agoRISC-V: Fix disassemble for c.li, c.andi and c.addiw
Kito Cheng [Wed, 5 Apr 2017 12:58:28 +0000 (20:58 +0800)]
RISC-V: Fix disassemble for c.li, c.andi and c.addiw

ChangeLog

2017-05-03  Kito Cheng  <kito.cheng@gmail.com>

        * riscv-dis.c (print_insn_args): Handle 'Co' operands.

7 years agoRemove some superfluous code in corelow.c
Andreas Arnez [Thu, 4 May 2017 09:06:10 +0000 (11:06 +0200)]
Remove some superfluous code in corelow.c

In corelow.c I stumbled upon an extra semicolon and an xfree of a NULL
pointer.  Remove them.

gdb/ChangeLog:

* corelow.c (sniff_core_bfd): Remove extra semicolon.
(get_core_register_section): Remove xfree of NULL pointer.

7 years agoFix PR21404 - assertion fail when calculating symbol size
Senthil Kumar Selvaraj [Mon, 24 Apr 2017 09:47:14 +0000 (15:17 +0530)]
Fix PR21404 - assertion fail when calculating symbol size

Fix a host of problems related to adjustment of
symbol values and sizes when relaxing for avr.

1. Adjust symbol size first before adjusting symbol
value. Otherwise, a symbol whose value just got adjusted to the
relaxed address also ends up getting resized. See pr21404-1.s.

2. Reduce symbol sizes only if their span is below an
alignment boundary. Otherwise, the size gets decremented once when the
actual instruction is relaxed and padding bytes are added, and again
when the padding bytes are deleted (if padding ends up being unnecessary).
pr21404-2.s addresses that, and this bug is really the root cause of PR21404.

3. Adjust all symbol values before an alignment boundary.
Previous code did not adjust symbol values if they fell in the
would-be padded area, resulting in incorrect symbol values in some
cases (see pr21404-3.s).

4. Increase symbol sizes if alignment directives require so.
As pr21404-4.s shows
.global nonzero_sym
L1:
    jmp  L1
nonzero_sym:
    nop
    nop
    .p2align 2
.size nonzero_sym, .-nonzero_sym

The two nops satisfy the 4 byte alignment at assembly time and
therefore the size of nonzero_sym is 4. Relaxation shortens
the 4 byte jmp to a 2 byte rjmp, and to satisfy 4 byte alignment
the code places 2 extra padding bytes after the nops, increasing
nonzero_sym's size by 2. This wasn't handled before.

If the assembly code does not have any align directives, then the
boundary is the section size, and symbol values and sizes == boundary
should also get adjusted. To handle that case, add a did_pad variable
and use that to determine whether it should use < boundary or <= boundary.

Also get rid of reloc_toaddr, which is now redundant.  toaddr is now not
adjusted to handle the above case - the newly added
did_pad variable does the job.

pr21404-{5,6,7,8} are the same testcases written for local symbols, as
the code handles them slightly differently.

7 years agoAutomatic date update in version.in
GDB Administrator [Thu, 4 May 2017 00:00:55 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoMIPS16/GAS: Relax 32-bit non-PIC PC-relative synthetic instructions
Maciej W. Rozycki [Wed, 3 May 2017 19:43:10 +0000 (20:43 +0100)]
MIPS16/GAS: Relax 32-bit non-PIC PC-relative synthetic instructions

Implement the relaxation of MIPS16 PC-relative synthetic LA, DLA, LW and
LD instructions to an equivalent sequence of instructions produced where
the address operand requested is out of range, absolute or requires
linker relocation, for ABIs that use 32-bit addressing and non-PIC code.

The sequence generated uses the register specified for the destination
operand as a temporary and begins with LI to load the high 16-bit part
of the address, then continues with SLL by 16 bits to move that part
into place and finally completes with a suitable operation corresponding
to the synthetic instruction used, one of: 2-argument ADDIU, 2-argument
DADDIU, absolute LW, and absolute LD respectively, providing the low
16-bit part of the address.  All instructions use the extended encoding.
As a special exception accept absolute addresses for relaxation even in
PIC code.

For example:

la $2, 0x12345678

produces code as:

li $2, 0x1234
sll $2, $2, 16
addiu $2, 0x5678

would.

Where linker relocation is required emit an R_MIPS16_HI16 relocation on
the initial LI instruction and an R_MIPS16_LO16 relocation on the final
operation.

For example (where `foo' is not local):

lw $3, foo

produces code as:

li $3, %hi(foo)
sll $3, $3, 16
lw $3, %lo(foo)($3)

would.

Emit assembly warnings as appropriate where this new relaxation triggers
in the `nomacro' mode or for an instruction manually placed in a branch
delay slot in the `noreorder' mode.  Refrain from relaxation where an
explicit instruction size suffix has been used and in the `noautoextend'
mode.

gas/
* config/tc-mips.c (RELAX_MIPS16_ENCODE): Add `pic', `sym32' and
`nomacro' flags.
(RELAX_MIPS16_PIC, RELAX_MIPS16_SYM32, RELAX_MIPS16_NOMACRO):
New macros.
(RELAX_MIPS16_USER_SMALL, RELAX_MIPS16_USER_EXT)
(RELAX_MIPS16_DSLOT, RELAX_MIPS16_JAL_DSLOT)
(RELAX_MIPS16_EXTENDED, RELAX_MIPS16_MARK_EXTENDED)
(RELAX_MIPS16_CLEAR_EXTENDED, RELAX_MIPS16_ALWAYS_EXTENDED)
(RELAX_MIPS16_MARK_ALWAYS_EXTENDED)
(RELAX_MIPS16_CLEAR_ALWAYS_EXTENDED): Shift bits.
(RELAX_MIPS16_MACRO, RELAX_MIPS16_MARK_MACRO)
(RELAX_MIPS16_CLEAR_MACRO): New macros.
(append_insn): Pass `mips_pic', HAVE_32BIT_SYMBOLS and
`mips_opts.warn_about_macros' settings to RELAX_MIPS16_ENCODE.
(mips16_macro_frag): New function.
(md_estimate_size_before_relax): Handle HI16/LO16 relaxation.
(mips_relax_frag): Likewise.
(md_convert_frag): Likewise.

* testsuite/gas/mips/mips16@relax-swap3.d: Remove error output,
add dump patterns.
* testsuite/gas/mips/mips16e@relax-swap3.d: New test
subarchitecture.
* testsuite/gas/mips/micromips@relax-swap3.d: Remove trailing
NOP padding.
* testsuite/gas/mips/mips16-pcrel-reloc-2.d: Remove error
output, add dump patterns.
* testsuite/gas/mips/mips16-pcrel-reloc-3.d: Remove error
output, add dump patterns.
* testsuite/gas/mips/mips16-pcrel-reloc-6.d: Remove error
output, add dump patterns.
* testsuite/gas/mips/mips16-pcrel-reloc-7.d: Remove error
output, add dump patterns.
* testsuite/gas/mips/mips16-pcrel-addend-2.d: Remove error
output, add dump patterns.
* testsuite/gas/mips/mips16-pcrel-addend-3.d: Remove error
output, add dump patterns.
* testsuite/gas/mips/mips16-pcrel-absolute.d: Remove error
output, add dump patterns.
* testsuite/gas/mips/mips16-pcrel-absolute-1.d: Remove error
output, add dump patterns.
* testsuite/gas/mips/mips16@relax-swap3.l: Remove file.
* testsuite/gas/mips/mips16-pcrel-reloc-2.l: Remove file.
* testsuite/gas/mips/mips16-pcrel-reloc-3.l: Remove file.
* testsuite/gas/mips/mips16-pcrel-reloc-6.l: Remove file.
* testsuite/gas/mips/mips16-pcrel-reloc-7.l: Remove file.
* testsuite/gas/mips/mips16-pcrel-addend-2.l: Remove file.
* testsuite/gas/mips/mips16-pcrel-addend-3.l: Remove file.
* testsuite/gas/mips/mips16-pcrel-absolute.l: Remove file.
* testsuite/gas/mips/mips16-pcrel-absolute-1.l: Remove file.
* testsuite/gas/mips/relax-swap3.s: Adjust trailing padding.

* testsuite/gas/mips/mips16-pcrel-0.d: New test.
* testsuite/gas/mips/mips16-pcrel-1.d: New test.
* testsuite/gas/mips/mips16-pcrel-2.d: New test.
* testsuite/gas/mips/mips16-pcrel-3.d: New test.
* testsuite/gas/mips/mips16-pcrel-4.d: New test.
* testsuite/gas/mips/mips16-pcrel-5.d: New test.
* testsuite/gas/mips/mips16-pcrel-pic-0.d: New test.
* testsuite/gas/mips/mips16-pcrel-pic-1.d: New test.
* testsuite/gas/mips/mips16-pcrel-n32-0.d: New test.
* testsuite/gas/mips/mips16-pcrel-n32-1.d: New test.
* testsuite/gas/mips/mips16-pcrel-n64-sym32-0.d: New test.
* testsuite/gas/mips/mips16-pcrel-n64-sym32-1.d: New test.
* testsuite/gas/mips/mips16-pcrel-n64-0.d: New test.
* testsuite/gas/mips/mips16-pcrel-n64-1.d: New test.
* testsuite/gas/mips/mips16-pcrel-delay-0.d: New test.
* testsuite/gas/mips/mips16-pcrel-delay-1.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-4.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-5.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-6.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-7.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-8.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-9.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-pic-8.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-pic-9.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-n32-8.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-n32-9.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-n64-sym32-8.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-n64-sym32-9.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-n64-8.d: New test.
* testsuite/gas/mips/mips16-pcrel-addend-n64-9.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-2.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-3.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-4.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-5.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-6.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-7.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-pic-4.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-pic-6.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-n32-4.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-n32-6.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-n64-4.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-n64-6.d: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-n64-sym32-4.d: New
test.
* testsuite/gas/mips/mips16-pcrel-absolute-n64-sym32-6.d: New
test.
* testsuite/gas/mips/mips16-pcrel-absolute-pic-n32-4.d: New
test.
* testsuite/gas/mips/mips16-pcrel-absolute-pic-n32-6.d: New
test.
* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-4.d: New
test.
* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-6.d: New
test.
* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-sym32-4.d:
New test.
* testsuite/gas/mips/mips16-pcrel-absolute-pic-n64-sym32-6.d:
New test.
* testsuite/gas/mips/mips16-pcrel-0.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-1.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-2.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-3.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-4.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-5.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-delay-0.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-delay-1.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-addend-8.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-addend-9.l: New stderr output.
* testsuite/gas/mips/mips16-pcrel-absolute-4.l: New stderr
output.
* testsuite/gas/mips/mips16-pcrel-absolute-6.l: New stderr
output.
* testsuite/gas/mips/mips16-pcrel-0.s: New test source.
* testsuite/gas/mips/mips16-pcrel-1.s: New test source.
* testsuite/gas/mips/mips16-pcrel-2.s: New test source.
* testsuite/gas/mips/mips16-pcrel-3.s: New test source.
* testsuite/gas/mips/mips16-pcrel-4.s: New test source.
* testsuite/gas/mips/mips16-pcrel-5.s: New test source.
* testsuite/gas/mips/mips16-pcrel-delay-0.s: New test source.
* testsuite/gas/mips/mips16-pcrel-delay-1.s: New test source.
* testsuite/gas/mips/mips16-pcrel-addend-4.s: New test source.
* testsuite/gas/mips/mips16-pcrel-addend-5.s: New test source.
* testsuite/gas/mips/mips16-pcrel-addend-6.s: New test source.
* testsuite/gas/mips/mips16-pcrel-addend-7.s: New test source.
* testsuite/gas/mips/mips16-pcrel-addend-8.s: New test source.
* testsuite/gas/mips/mips16-pcrel-addend-9.s: New test source.
* testsuite/gas/mips/mips16-pcrel-absolute-2.s: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-3.s: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-4.s: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-5.s: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-6.s: New test.
* testsuite/gas/mips/mips16-pcrel-absolute-7.s: New test.
* testsuite/gas/mips/mips.exp: Run the new tests.

ld/
* testsuite/ld-mips-elf/mips16-pcrel-0.d: New test.
* testsuite/ld-mips-elf/mips16-pcrel-1.d: New test.
* testsuite/ld-mips-elf/mips16-pcrel-addend-2.d: New test.
* testsuite/ld-mips-elf/mips16-pcrel-addend-6.d: New test.
* testsuite/ld-mips-elf/mips16-pcrel-n32-0.d: New test.
* testsuite/ld-mips-elf/mips16-pcrel-n32-1.d: New test.
* testsuite/ld-mips-elf/mips16-pcrel-n64-sym32-0.d: New test.
* testsuite/ld-mips-elf/mips16-pcrel-n64-sym32-1.d: New test.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.

7 years agoMake sure malloc is linked into gdb.cp/oranking.cc.
Keith Seitz [Wed, 3 May 2017 19:41:09 +0000 (12:41 -0700)]
Make sure malloc is linked into gdb.cp/oranking.cc.

On some platforms, e.g., arm-eabi-none, we need to make certain that
malloc is linked into the program because the test suite uses function
calls requiring malloc:

(gdb) p foo101("abc")
evaluation of this expression requires the program to have a function "malloc".

gdb/testsuite/ChangeLog

* gdb.cp/oranking.cc (dummy): New function to grab malloc.
(main): Call it.

7 years agoAdjust testsuite/ld-elf/pr21384.d
H.J. Lu [Wed, 3 May 2017 14:40:51 +0000 (07:40 -0700)]
Adjust testsuite/ld-elf/pr21384.d

Adjust testsuite/ld-elf/pr21384.d to accommodate additional dynamic
symbols on some targets.

* testsuite/ld-elf/pr21384.d: Adjusted to accommodate
additional dynamic symbols on some targets.

7 years agoRemove MAX_REGISTER_SIZE from frv-linux-tdep.c
Alan Hayward [Wed, 3 May 2017 13:51:40 +0000 (14:51 +0100)]
Remove MAX_REGISTER_SIZE from frv-linux-tdep.c

gdb/
* frv-linux-tdep.c (frv_linux_supply_gregset): Use raw_supply_zeroed.
* regcache.c (regcache::raw_supply_zeroed): New function.
* regcache.h (regcache::raw_supply_zeroed): New declaration.

7 years agogdbarch.sh: Remove commented out TARGET_CHAR_BIT definition
Simon Marchi [Wed, 3 May 2017 13:21:27 +0000 (09:21 -0400)]
gdbarch.sh: Remove commented out TARGET_CHAR_BIT definition

As Pedro commented on the patch "Change field separator in gdbarch.sh",
this commented out definition is probably not useful and should be
removed.  It has been commented out for basically forever, and it
probably serves the same intent as addressable_memory_unit_size.

gdb/ChangeLog:

* gdbarch.sh: Remove commented out definition of
TARGET_CHAR_BIT.
* gdbarch.h: Re-generate.

7 years agoRegenerate gdb/{,gdbserver/}configure (for commit be628ab814f1c90e185d7482d27aa8a991a...
Sergio Durigan Junior [Wed, 3 May 2017 13:13:15 +0000 (09:13 -0400)]
Regenerate gdb/{,gdbserver/}configure (for commit be628ab814f1c90e185d7482d27aa8a991ab5837)

On commit be628ab814f1c90e185d7482d27aa8a991ab5837, both
common/common.m4 was modified in order to check for the presence of
'termios.h', 'termio.h' and 'sgtty.h'.  However, I forgot to
regenerate both gdb/configure and gdb/gdbserver/configure.  This
commit does that.

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

* configure: Regenerate.

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

* configure: Regenerate.

7 years agoPrevent a seg-fault in the assembler when provided with a bogus input source file.
Nick Clifton [Wed, 3 May 2017 08:52:01 +0000 (09:52 +0100)]
Prevent a seg-fault in the assembler when provided with a bogus input source file.

PR gas/20941
* symbols.c (snapshot_symbol): Handle the case where
resolve_expression returns a local symbol.

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

7 years agoMIPS16/GAS: Fix absolute references with PC-relative synthetic instructions
Maciej W. Rozycki [Tue, 2 May 2017 23:05:15 +0000 (00:05 +0100)]
MIPS16/GAS: Fix absolute references with PC-relative synthetic instructions

Complement commit 88a7ef168927 ("MIPS16/GAS: Restore unsupported
relocation diagnostics") and also propagate constant expressions, either
already reduced from absolute symbol references or created from literals
in the first place, used as a PC-relative operand with the MIPS16 LA,
LW, DLA and LD synthetic instructions to relaxation, matching the way
forward absolute symbol references have been handled as from the commit
referred and letting relaxation produce any necessary relocations, if
possible, for the absolute value requested to be reproduced at the run
time.

Call `symbol_append' for any expression symbol created for the purpose
of MIPS16 relaxation as with constant expressions now propagated from
earlier on such symbols may make it through and have R_MIPS16_PC16_S1
relocations emitted against, and therefore need to appear in the symbol
table produced.

gas/
* config/tc-mips.c (append_insn): Call `symbol_append' for any
expression symbol created for MIPS16 relaxation.
(match_mips16_insn): Don't encode a constant value as an
immediate with a PC-relative operand.

* testsuite/gas/mips/mips16-pcrel-absolute-1.d: New test.
* testsuite/gas/mips/mips16-branch-absolute-1.d: New test.
* testsuite/gas/mips/mips16-branch-absolute-2.d: New test.
* testsuite/gas/mips/mips16-branch-absolute-addend-1.d: New
test.
* testsuite/gas/mips/mips16-branch-absolute-n32-1.d: New test.
* testsuite/gas/mips/mips16-branch-absolute-n32-2.d: New test.
* testsuite/gas/mips/mips16-branch-absolute-addend-n32-1.d: New
test.
* testsuite/gas/mips/mips16-branch-absolute-n64-1.d: New test.
* testsuite/gas/mips/mips16-branch-absolute-n64-2.d: New test.
* testsuite/gas/mips/mips16-branch-absolute-addend-n64-1.d: New
test.
* testsuite/gas/mips/mips16-pcrel-absolute-1.l: New stderr
output.
* testsuite/gas/mips/mips16-pcrel-absolute-1.s: New test source.
* testsuite/gas/mips/mips16-branch-absolute-1.s: New test
source.
* testsuite/gas/mips/mips16-branch-absolute-2.s: New test
source.
* testsuite/gas/mips/mips16-branch-absolute-addend-1.s: New test
source.
* testsuite/gas/mips/mips.exp: Run the new tests.

ld/
* testsuite/ld-mips-elf/mips16-branch-absolute-1.d: New test.
* testsuite/ld-mips-elf/mips16-branch-absolute-2.d: New test.
* testsuite/ld-mips-elf/mips16-branch-absolute-addend-1.d: New
test.
* testsuite/ld-mips-elf/mips16-branch-absolute-n32-1.d: New
test.
* testsuite/ld-mips-elf/mips16-branch-absolute-n32-2.d: New
test.
* testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32-1.d:
New test.
* testsuite/ld-mips-elf/mips16-branch-absolute-n64-1.d: New
test.
* testsuite/ld-mips-elf/mips16-branch-absolute-n64-2.d: New
test.
* testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64-1.d:
New test.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.

7 years agox86: Add -Wl,--no-as-needed to some TLS tests
H.J. Lu [Tue, 2 May 2017 23:00:49 +0000 (16:00 -0700)]
x86: Add -Wl,--no-as-needed to some TLS tests

* testsuite/ld-i386/tls.exp: Add -Wl,--no-as-needed to
"TLS without PLT (1)" and "TLS without PLT (3)".
* testsuite/ld-x86-64/tls.exp: Add -Wl,--no-as-needed to
to "TLS without PLT (3)".

7 years agoRISC-V: Change CALL macro to use ra as the temporary address register
Michael Clark [Thu, 27 Apr 2017 04:08:46 +0000 (16:08 +1200)]
RISC-V: Change CALL macro to use ra as the temporary address register

e.g.

    1:  auipc ra, %pcrel_hi(symbol)
        jalr  ra, %pcrel_lo(1b)(ra)

The use of ra instead of t1 for address construction provides an
opportunity for a microarchitecture to elide the write of the
destination address, and instead read the target address as an
immediate spread across the fused auipc+jalr pair. The link
register ra in the jalr overwrites the target address temporary.

2017-05-01  Michael Clark  <michaeljclark@mac.com>

* riscv-opc.c (riscv_opcodes) <call>: Use RA not T1 as a temporary
register.

7 years agoRISC-V: Allow 32-bit BFD to handle 64-bit objects
Palmer Dabbelt [Mon, 1 May 2017 17:26:32 +0000 (10:26 -0700)]
RISC-V: Allow 32-bit BFD to handle 64-bit objects

We've been telling people that the riscv32-* and riscv64-* toolchains
are exactly the same, but it turns out we were lying: the riscv32-* BFD
doesn't handle 64-bit objects.  This fixes that difference, so the ports
are actually the same.

bfd/ChangeLog

2017-05-01  Palmer Dabbelt  <palmer@dabbelt.com>

        * config.bfd (riscv32-*): Enable rv64.

7 years agoAdd a test for PR ld/21384
H.J. Lu [Tue, 2 May 2017 20:54:22 +0000 (13:54 -0700)]
Add a test for PR ld/21384

PR ld/21384
* testsuite/ld-elf/pr21384.d: New file.
* testsuite/ld-elf/pr21384.dl: Likewise.
* testsuite/ld-elf/pr21384.ld: Likewise.
* testsuite/ld-elf/pr21384.s: Likewise.

7 years agoCast relcount to unsigned long when comparing with sec->reloc_count
H.J. Lu [Tue, 2 May 2017 19:16:26 +0000 (12:16 -0700)]
Cast relcount to unsigned long when comparing with sec->reloc_count

The type of relcount is long and the type of sec->reloc_count is
unsigned int.  On 32-bit hosts, GCC issues an error:

objcopy.c:2144:20: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
       if (relcount > sec->reloc_count)

Cast relcount to unsigned long to silence GCC.

* objcopy.c (merge_gnu_build_notes): Cast relcount to unsigned
long when comparing with sec->reloc_count.

7 years agosolib-target: Remove local variables
Simon Marchi [Tue, 2 May 2017 18:25:43 +0000 (14:25 -0400)]
solib-target: Remove local variables

Now that we use std::vector, these local variables are not very useful.
They're not much shorter than the expressions they stand for.

gdb/ChangeLog:

* solib-target.c (solib_target_relocate_section_addresses):
Remove num_section_bases, num_bases, segment_bases variables.

7 years agoRemove definition of VEC (CORE_ADDR)
Simon Marchi [Tue, 2 May 2017 17:30:09 +0000 (13:30 -0400)]
Remove definition of VEC (CORE_ADDR)

gdb/ChangeLog:

* common/gdb_vecs.h (DEF_VEC_I (CORE_ADDR)): Remove.

7 years agoUse std::vector in lm_info_target
Simon Marchi [Tue, 2 May 2017 17:30:08 +0000 (13:30 -0400)]
Use std::vector in lm_info_target

Replace the two VEC fields with std::vector.

gdb/ChangeLog:

* solib-target.c: Include <vector>
(struct lm_info_target) <~lm_info_target>: Remove.
<segment_bases, section_bases>: Change type to
std::vector<CORE_ADDR>.
(library_list_start_segment, library_list_start_section,
library_list_end_library,
solib_target_relocate_section_addresses): Adjust.

7 years agoChange return type of gdbarch_software_single_step to vector<CORE_ADDR>
Simon Marchi [Tue, 2 May 2017 17:30:07 +0000 (13:30 -0400)]
Change return type of gdbarch_software_single_step to vector<CORE_ADDR>

This is a relatively straightforward patch that changes
gdbarch_software_single_step so it returns an std::vector<CORE_ADDR>
instead of a VEC (CORE_ADDR).

gdb/ChangeLog:

* gdbarch.sh (software_single_step): Change return type to
std::vector<CORE_ADDR>.
* gdbarch.c, gdbarch.h: Re-generate.
* arch/arm-get-next-pcs.c (thumb_deal_with_atomic_sequence_raw):
Adjust.
(arm_deal_with_atomic_sequence_raw): Adjust.
(thumb_get_next_pcs_raw): Adjust.
(arm_get_next_pcs_raw): Adjust.
(arm_get_next_pcs): Adjust.
* arch/arm-get-next-pcs.h (arm_get_next_pcs): Adjust.
* aarch64-tdep.c (aarch64_software_single_step): Adjust.
* alpha-tdep.c (alpha_deal_with_atomic_sequence): Adjust.
(alpha_software_single_step): Adjust.
* alpha-tdep.h (alpha_software_single_step): Adjust.
* arm-linux-tdep.c (arm_linux_software_single_step): Adjust.
* arm-tdep.c (arm_software_single_step): Adjust.
(arm_breakpoint_kind_from_current_state): Adjust.
* arm-tdep.h (arm_software_single_step): Adjust.
* breakpoint.c (insert_single_step_breakpoint): Adjust.
* cris-tdep.c (cris_software_single_step): Adjust.
* mips-tdep.c (mips_deal_with_atomic_sequence): Adjust.
(micromips_deal_with_atomic_sequence): Adjust.
(deal_with_atomic_sequence): Adjust.
(mips_software_single_step): Adjust.
* mips-tdep.h (mips_software_single_step): Adjust.
* moxie-tdep.c (moxie_software_single_step): Adjust.
* nios2-tdep.c (nios2_software_single_step): Adjust.
* ppc-tdep.h (ppc_deal_with_atomic_sequence): Adjust.
* rs6000-aix-tdep.c (rs6000_software_single_step): Adjust.
* rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust.
* s390-linux-tdep.c (s390_software_single_step): Adjust.
* sparc-tdep.c (sparc_software_single_step): Adjust.
* spu-tdep.c (spu_software_single_step): Adjust.
* tic6x-tdep.c (tic6x_software_single_step): Adjust.

gdb/gdbserver/ChangeLog:

* linux-arm-low.c (arm_gdbserver_get_next_pcs): Adjust to
software_single_step change of return type to
std::vector<CORE_ADDR>.
* linux-low.c (install_software_single_step_breakpoints):
Likewise.
* linux-low.h (install_software_single_step_breakpoints):
Likewise.

7 years agoChange field separator in gdbarch.sh
Simon Marchi [Tue, 2 May 2017 17:30:07 +0000 (13:30 -0400)]
Change field separator in gdbarch.sh

The fields in the description of the gdbarch interface are separated
using colons.  That becomes a problem if we want to use things like
std::vector in it. This patch changes the field separator to use
semicolons instead.

I think there's very little chance we'll ever want to use a semicolon in
one of the fields, but if you think another character would be more
appropriate, let me know.

gdb/ChangeLog:

* gdbarch.sh: Use semi-colon as field separator instead of colon.
* gdbarch.h: Re-generate.

7 years agoDon't merge notes when the relocs associated with them cannot be reliably deleted.
Nick Clifton [Tue, 2 May 2017 15:54:53 +0000 (16:54 +0100)]
Don't merge notes when the relocs associated with them cannot be reliably deleted.

* objcopy.c (merge_gnu_build_notes): Disable merge if there are
more internal relocs than external relocs.

7 years agoPR 21384, --dynamic-list regression with f02cb058
Alan Modra [Tue, 2 May 2017 12:26:43 +0000 (21:56 +0930)]
PR 21384, --dynamic-list regression with f02cb058

The commit to "Always descend into output section statements in
lang_do_assignments" meant that linker script symbols were not
bfd_link_hash_new when ld called bfd_elf_record_link_assignment.
This patch corrects that problem by testing h->non_elf instead.

PR 21384
* elflink.c (bfd_elf_link_mark_dynamic_symbol): Test h->non_elf
rather than h->root.type == bfd_link_hash_new.
(bfd_elf_record_link_assignment): Similarly, call
bfd_elf_link_mark_dynamic_symbol when h->non_elf.

7 years agoMIPS16/opcodes: Keep the LSB of PC-relative offsets in disassembly
Maciej W. Rozycki [Tue, 2 May 2017 10:53:30 +0000 (11:53 +0100)]
MIPS16/opcodes: Keep the LSB of PC-relative offsets in disassembly

Correct the disassembly of the PC-relative immediate argument of the
MIPS16 synthetic LA, LW, DLA and LD instructions and do not mask the
LSB, which in this case is a part of the data address rather than the
ISA bit and has to be fully presented.

opcodes/
* mips-dis.c (print_insn_arg): Only clear the ISA bit for jumps
and branches and not synthetic data instructions.

binutils/
* testsuite/binutils-all/mips/mips16-undecoded.d: Adjust the
disassembly of PC-relative LA and LW synthetic instructions.

7 years agoPrevent memory exhaustion from a corrupt PE binary with an overlarge number of relocs.
Nick Clifton [Tue, 2 May 2017 10:54:53 +0000 (11:54 +0100)]
Prevent memory exhaustion from a corrupt PE binary with an overlarge number of relocs.

PR 21440
* objdump.c (dump_relocs_in_section): Check for an excessive
number of relocs before attempting to dump them.

7 years agoPython: Introduce gdb.Instruction class
Tim Wiederhake [Tue, 2 May 2017 09:35:54 +0000 (11:35 +0200)]
Python: Introduce gdb.Instruction class

This adds a generic instruction class to Python and has gdb.RecordInstruction
inherit from it.

7 years agoPython: Move and rename gdb.BtraceFunction
Tim Wiederhake [Tue, 2 May 2017 09:35:54 +0000 (11:35 +0200)]
Python: Move and rename gdb.BtraceFunction

Remove gdb.BtraceFunctionCall and replace by gdb.FunctionSegment.  Additionally,
rename prev_segment and next_segment to prev and next.

7 years agoPython: Move and rename gdb.BtraceInstruction
Tim Wiederhake [Tue, 2 May 2017 09:35:54 +0000 (11:35 +0200)]
Python: Move and rename gdb.BtraceInstruction

Remove gdb.BtraceInstruction and replace by gdb.RecordInstruction.

7 years agoPython: Introduce gdb.RecordGap class
Tim Wiederhake [Tue, 2 May 2017 09:35:54 +0000 (11:35 +0200)]
Python: Introduce gdb.RecordGap class

As discussed here: https://sourceware.org/ml/gdb-patches/2017-04/msg00157.html

A gap is not an instruction and it should not pretend to be one.
gdb.Record.instruction_history is now a list of gdb.RecordInstruction and
gdb.RecordGap objects.  This allows the user to deal with Gaps in the record
in a more sane way.

7 years agoPython: Remove ptid from gdb.Record interface
Tim Wiederhake [Tue, 2 May 2017 09:35:54 +0000 (11:35 +0200)]
Python: Remove ptid from gdb.Record interface

As discussed here: https://sourceware.org/ml/gdb-patches/2017-04/msg00166.html

7 years agoPython: Use correct ptid in btrace recording
Tim Wiederhake [Tue, 2 May 2017 09:35:54 +0000 (11:35 +0200)]
Python: Use correct ptid in btrace recording

The user would always get the instruction_history and function_call_history
objects of the current thread, not the thread for which the gdb.Record object
was created.

The attached testcase fails without this patch and passes with the patch.

7 years agoPython: Fix indentation in py-record-btrace.c
Tim Wiederhake [Tue, 2 May 2017 09:35:54 +0000 (11:35 +0200)]
Python: Fix indentation in py-record-btrace.c

7 years agoFix value in comment of disassembled ARM type A opcodes.
Bernd Edlinger [Tue, 2 May 2017 09:28:09 +0000 (10:28 +0100)]
Fix value in comment of disassembled ARM type A opcodes.

* arm-dis.c (print_insn_thumb32): Fix value_in_comment.

7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 2 May 2017 00:00:39 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agox86: Run GNU2 TLS tests with working GNU2 TLS support
H.J. Lu [Mon, 1 May 2017 18:02:55 +0000 (11:02 -0700)]
x86: Run GNU2 TLS tests with working GNU2 TLS support

Check if GNU2 TLS really works before running GNU2 TLS tests.

* testsuite/ld-i386/tls.exp: Run GNU2 TLS tests only if there
is working GNU2 TLS support.
* testsuite/ld-x86-64/tls.exp: Likewise.
* testsuite/lib/ld-lib.exp (check_gnu2_tls_available): New proc.

7 years agogdb/MAINTAINERS: Move Daniel J and Mark to the Past Maintainers section.
Joel Brobecker [Mon, 1 May 2017 16:59:15 +0000 (09:59 -0700)]
gdb/MAINTAINERS: Move Daniel J and Mark to the Past Maintainers section.

gdb/ChangeLog:

        * MAINTAINERS: Move Daniel Jacobowitz and Mark Kettenis to
        the past maintainers section.

7 years agomerge_gnu_build_notes reloc deletion
Alan Modra [Mon, 1 May 2017 04:41:27 +0000 (14:11 +0930)]
merge_gnu_build_notes reloc deletion

If moving relocs, the next reloc to look at is at the same location.

* objcopy.c (merge_gnu_build_notes): Correct code deleting
relocs.

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 1 May 2017 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAutomatic date update in version.in
GDB Administrator [Sun, 30 Apr 2017 00:00:31 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoPR21432, buffer overflow in perform_relocation
Alan Modra [Sat, 29 Apr 2017 05:18:16 +0000 (14:48 +0930)]
PR21432, buffer overflow in perform_relocation

The existing reloc offset range tests didn't catch small negative
offsets less than the size of the reloc field.

PR 21432
* reloc.c (reloc_offset_in_range): New function.
(bfd_perform_relocation, bfd_install_relocation): Use it.
(_bfd_final_link_relocate): Likewise.

7 years agoMake environ.exp run on all platforms (and create info-program.exp)
Sergio Durigan Junior [Fri, 31 Mar 2017 17:24:36 +0000 (13:24 -0400)]
Make environ.exp run on all platforms (and create info-program.exp)

This has been on my TODO list for a while.  There's a really old bug
about this (PR testsuite/8595), and there was no reason for
environ.exp to be specific for hppa* targets.  So this patch removes
this constraint, modernizes the testcase, and cleans up some things.
Most of the tests remained, and some were rewritten (especially the
one that checks if "show environment" works, which is something kind
of hard to do).

As a bonus, I'm adding a separated info-program.exp file containing
all the tests related to "info program" that were present on
environ.exp.

Tested locally, everything still passes.

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

PR testsuite/8595
* gdb.base/environ.exp: Make test available in all architectures.
Move bits related to "info program" testing to
gdb.base/info-program.exp.  Rewrite tests to use the two new
procedures mentione below.
(test_set_show_env_var) New procedure.
(test_set_show_env_var_equal): Likewise.
* gdb.base/info-program.exp: New file.

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 29 Apr 2017 00:00:38 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoRemove cleanup in get_return_value
Yao Qi [Fri, 28 Apr 2017 21:48:42 +0000 (22:48 +0100)]
Remove cleanup in get_return_value

With regcache ctor, we can use it to create local object in
get_return_value (), so that the cleanup can be removed.

gdb:

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

* infcmd.c (get_return_value): Use regcache ctor, and remove
cleanup.

7 years agoUse tag dispatch regcache ctor in regcache_dup
Yao Qi [Fri, 28 Apr 2017 21:48:42 +0000 (22:48 +0100)]
Use tag dispatch regcache ctor in regcache_dup

This patch adds a tag dispatch ctor to create read-only regcache from
a write-through regcache, also this patch deletes copy ctor and
assignment operator.

gdb:

2017-04-28  Yao Qi  <yao.qi@linaro.org>
    Pedro Alves  <palves@redhat.com>

* regcache.c (regcache::regcache): New tag dispatch ctor.
(do_cooked_read): Moved above.
(regcache_dup): Use the tag dispatch ctor..
* regcache.h (regcache): Declare ctor, delete copy ctor and
assignment operator, remove friend regcache_dup.

7 years agoSimplify regcache_dup
Yao Qi [Fri, 28 Apr 2017 21:48:42 +0000 (22:48 +0100)]
Simplify regcache_dup

regcache_dup, in fact, is to create a readonly regcache from a
non-readonly regcache.  This patch adds an assert that src is not
readonly.

gdb:

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

* regcache.c (regcache_dup): Assert !src->m_readonly_p and
call method save instead of regcache_cpy.
* regcache.h (struct regcache): Make regcache_dup a friend.

7 years agoClass-fy regcache
Yao Qi [Fri, 28 Apr 2017 21:48:42 +0000 (22:48 +0100)]
Class-fy regcache

This patch moves regcache declaration to regcache.h, and converts
regcache apis to member functions, for example, regcache_invalidate
is changed to regcache::invalidate.

This patch also add "m_" prefix to these private fields.

gdb:

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

* regcache.c (struct regcache): Move to regcache.h
(regcache::arch): New method.
(regcache_get_ptid): Update.
(get_regcache_arch): Call arch method.
(get_regcache_aspace): Call method aspace.
(register_buffer): Change it to method.
(regcache_save): Change it to regcache::save.
(regcache_restore): Likewise.
(regcache_cpy_no_passthrough): Remove the declaration.
(regcache_cpy): Call methods restore and cpy_no_passthrough.
(regcache_cpy_no_passthrough): Change it to method
cpy_no_passthrough.
(regcache_register_status): Change it to method
get_register_status.
(regcache_invalidate): Change it to method invalidate.
(regcache_thread_ptid_changed): Use methods ptid and set_ptid.
(regcache_raw_update): Change it to method raw_update.
(regcache_raw_read): Likewise.
(regcache_raw_read_signed): Likewise.
(regcache_raw_read_unsigned): Likewise.
(regcache_raw_write_signed): Likewise.
(regcache_raw_write_unsigned): Likewise.
(regcache_cooked_read): Likewise.
(regcache_cooked_read_value): Likewise.
(regcache_cooked_read_signed): Likewise.
(regcache_cooked_read_unsigned): Likewise.
(regcache_cooked_write_signed): Likewise.
(regcache_cooked_write_unsigned): Likewise.
(regcache_raw_set_cached_value): Likewise.
(regcache_raw_write): Likewise.
(regcache_cooked_write): Likewise.
(regcache_xfer_part): Likewise.
(regcache_raw_read_part): Likewise.
(regcache_raw_write_part): Likewise.
(regcache_cooked_read_part): Likewise.
(regcache_cooked_write_part): Likewise.
(regcache_raw_supply): Likewise.
(regcache_raw_collect): Likewise.
(regcache_transfer_regset): Likewise.
(regcache_supply_regset): Likewise.
(regcache_collect_regset): Likewise.
(regcache_debug_print_register): Likewise.
(enum regcache_dump_what): Move it to regcache.h.
(regcache_dump): Change it to method dump.
* regcache.h (enum regcache_dump_what): New.
(class regcache): New.
* target.c (target_fetch_registers): Call method
debug_print_register.
(target_store_registers): Likewise.

7 years agoClass-ify lm_info_windows
Simon Marchi [Fri, 28 Apr 2017 21:16:18 +0000 (17:16 -0400)]
Class-ify lm_info_windows

This patch makes lm_info_windows a "real" class.  It initializes the field
and replaces XCNEW/xfree with new/delete.

gdb/ChangeLog:

* windows-nat.c (struct lm_info_windows): Initialize field.
(windows_make_so): Allocate lm_info_windows with new.
(windows_free_so): Free lm_info_windows with delete.

7 years agoClass-ify lm_info_darwin
Simon Marchi [Fri, 28 Apr 2017 21:16:18 +0000 (17:16 -0400)]
Class-ify lm_info_darwin

This patch makes lm_info_darwin a "real" class.  It initializes the
field and replaces XCNEW/xfree with new/delete.

gdb/ChangeLog:

* solib-darwin.c (struct lm_info_darwin): Initialize field.
(darwin_current_sos): Allocate lm_info_darwin with new, remove
cleanup.
(darwin_free_so): Free lm_info_darwin with delete.

7 years agoClass-ify lm_info_svr4
Simon Marchi [Fri, 28 Apr 2017 21:16:17 +0000 (17:16 -0400)]
Class-ify lm_info_svr4

This patch makes lm_info_svr4 a "real" class.  It initializes fields,
uses bool and replaces XCNEW/xfree with new/delete.

The memcpy in svr4_copy_library_list is replaced by a usage of the
default copy constructor.

gdb/ChangeLog:

* solib-svr4.h (struct lm_info_svr4): Initialize fields.
<l_addr_p>: Change type to bool.
* solib-svr4.c (lm_info_read): Allocate lm_info_svr4 with new.
(svr4_free_so): Free lm_info_svr4 with delete.
(svr4_copy_library_list): Replace memcpy with call to copy
constructor.
(library_list_start_library, svr4_default_sos): Allocate
lm_info_svr4 with new.

7 years agoClass-ify lm_info_target
Simon Marchi [Fri, 28 Apr 2017 21:16:16 +0000 (17:16 -0400)]
Class-ify lm_info_target

This patch makes lm_info_target a "real" class.  It adds a destructor,
uses std::string, initializes the fields and replaces XCNEW/xfree with
new/delete.

gdb/ChangeLog:

* solib-target.c (struct lm_info_target): Add destructor,
initialize fields.
<name>: Change type to std::string.
(library_list_start_library): Allocate lm_info_target with new.
(solib_target_free_library_list): Free lm_info_target with
delete.
(solib_target_current_sos): Adapt to std::string.
(solib_target_free_so): Free lm_info_target with delete.

7 years agoClass-ify lm_info_frv
Simon Marchi [Fri, 28 Apr 2017 21:16:16 +0000 (17:16 -0400)]
Class-ify lm_info_frv

This patches makes lm_info_frv a "real" class.  It adds a destructor,
initializes the fields and replaces XCNEW/xfree with new/delete.

gdb/ChangeLog:

* solib-frv.c (struct lm_info_frv): Add destructor, initialize
fields.
(frv_current_sos): Allocate lm_info_frv with new.
(frv_relocate_main_executable): Free lm_info_frv with delete,
allocate with new.
(frv_clear_solib, frv_free_so): Free lm_info_frv with delete.

7 years agoFix indentation of lm_info_frv
Simon Marchi [Fri, 28 Apr 2017 21:16:15 +0000 (17:16 -0400)]
Fix indentation of lm_info_frv

This patch fixes the indentation of lm_info_frv, so that the real
changes of the following patch are not lost in the reformatting.

gdb/ChangeLog:

* solib-frv.c (struct lm_info_frv): Fix indentation.

7 years agoClass-ify lm_info_dsbt
Simon Marchi [Fri, 28 Apr 2017 21:16:14 +0000 (17:16 -0400)]
Class-ify lm_info_dsbt

This patches makes lm_info_dsbt a "real" class.  It introduces a
destructor, initializes the field and replaces XCNEW/xfree with
new/delete.

gdb/ChangeLog:

* solib-dsbt.c (struct lm_info_dsbt): Add destructor, initialize
map field.
(dsbt_current_sos): Allocate lm_info_dsbt with new.
(dsbt_relocate_main_executable): Free lm_info_dsbt with delete
and allocate with new.
(dsbt_clear_solib, dsbt_free_so): Free lm_info_dsbt with delete.

7 years agoClass-ify lm_info_aix
Simon Marchi [Fri, 28 Apr 2017 21:16:14 +0000 (17:16 -0400)]
Class-ify lm_info_aix

This patch makes lm_info_aix a "real" class.  It uses std::string,
initializes fields in-class and replaces XCNEW/xfree with new/delete.
The solib_aix_new_lm_info can be replaced by using the default copy
constructor.

gdb/ChangeLog:

* solib-aix.c (struct lm_info_aix): Initialize fields in-class.
<filename, member_name>: Change type to std::string.
(solib_aix_new_lm_info, solib_aix_xfree_lm_info): Remove.
(library_list_start_library): Allocate lm_info_aix with new.
(solib_aix_free_library_list, solib_aix_free_so): Free with delete.
(solib_aix_current_sos): Adapt to std::string, copy lm_info_aix
with copy constructor.

7 years agoMake various lm_info implementations inherit from a base class
Simon Marchi [Fri, 28 Apr 2017 21:16:13 +0000 (17:16 -0400)]
Make various lm_info implementations inherit from a base class

The lm_info structure is used to store target specific information about
mapped libraries.  It is currently defined as an opaque type in solist.h
and a pointer to it is included in solist, the target-agnostic object
representing a loaded shared library.  Multiple targets define their own
implementation of lm_info.

In anticipation of using C++ stuff (e.g. vector) in the lm_info objects,
we first need to avoid different definitions of classes with the same
name (which violates the one definition rule).  This patch does it by
having a base class (lm_info_base) from which all the specific lm_info
derive.  Each implementation is renamed to something that makes sense
(e.g. lm_info_aix for AIX).  The next logical step would probably be to
derive directly from so_list, it's not really obvious, so I'll keep that
for another day.

One special case is the Neutrino (nto) support.  It uses SVR4-style
libraries, but overrides some methods.  To do that, it needed to have
its own copy of SVR4's lm_info structure in nto-tdep.c, because it was
just not possible to put it in solib-svr4.h and include that file.  Over
time, that copy got out of sync, which is still the case today.  I can
only assume that the lm_addr function in nto-tdep.c is broken right now.
The first field of the old lm_info was a pointer (gdb_byte *), whereas
in the new lm_info it's an address in the inferior (CORE_ADDR).  Trying
to use that field today probably results in a crash.  With this
refactor, it's now possible to put lm_info_svr4 in solib-svr4.h and just
include it.  I have adapted the code in nto-tdep.c to that it builds,
but it's probably not correct.  Since I don't have the knowledge nor
setup to try this on Neutrino, somebody else would have to fix it.  But
I am confident that I am not making things worse than they already are.

gdb/ChangeLog:

* solist.h (struct lm_info): Remove.
(struct lm_info_base): New class.
(struct so_list) <lm_info>: Change type to lm_info_base *.
* nto-tdep.c (struct lm_info): Remove.
(lm_addr): Adjust.
* solib-aix.c (struct lm_info): Rename to ...
(struct lm_info_aix): ... this.  Extend lm_info_base.
(lm_info_p): Rename to ...
(lm_info_aix_p): ... this, and adjust.
(solib_aix_new_lm_info, solib_aix_xfree_lm_info,
solib_aix_parse_libraries, library_list_start_library,
solib_aix_free_library_list, solib_aix_parse_libraries,
solib_aix_get_library_list,
solib_aix_relocate_section_addresses, solib_aix_free_so,
solib_aix_get_section_offsets,
solib_aix_solib_create_inferior_hook, solib_aix_current_sos):
Adjust.
(struct solib_aix_inferior_data) <library_list>: Adjust.
* solib-darwin.c (struct lm_info): Rename to ...
(struct lm_info_darwin): ... this.  Extend lm_info_base.
(darwin_current_sos, darwin_relocate_section_addresses): Adjust.
* solib-dsbt.c (struct lm_info): Rename to ...
(struct lm_info_dsbt): ... this.  Extend lm_info_base.
(struct dsbt_info) <main_executable_lm_info): Adjust.
(dsbt_current_sos, dsbt_relocate_main_executable, dsbt_free_so,
dsbt_relocate_section_addresses): Adjust.
* solib-frv.c (struct lm_info): Rename to ...
(struct lm_info_frv): ... this.  Extend lm_info_base.
(main_executable_lm_info): Adjust.
(frv_current_sos, frv_relocate_main_executable, frv_free_so,
frv_relocate_section_addresses, frv_fdpic_find_global_pointer,
find_canonical_descriptor_in_load_object,
frv_fdpic_find_canonical_descriptor): Adjust.
* solib-svr4.c (struct lm_info): Move to solib-svr4.h, renamed
to lm_info_svr4.
(lm_info_read, lm_addr_check, svr4_keep_data_in_core,
svr4_clear_so, svr4_copy_library_list,
library_list_start_library, svr4_default_sos, svr4_read_so_list,
svr4_current_sos, svr4_fetch_objfile_link_map,
solist_update_incremental): Adjust.
* solib-svr4.h (struct lm_info_svr4): Move here from
solib-svr4.c.
* solib-target.c (struct lm_info): Rename to ...
(struct lm_info_target): ... this.  Extend lm_info_base.
(lm_info_p): Rename to ...
(lm_info_target_p): ... this.
(solib_target_parse_libraries, library_list_start_segment,
library_list_start_section, library_list_start_library,
library_list_end_library, solib_target_free_library_list,
solib_target_current_sos, solib_target_free_so,
solib_target_relocate_section_addresses): Adjust.
* windows-nat.c (struct lm_info): Rename to ...
(struct lm_info_windows): ... this.  Extend lm_info_base.
(windows_make_so, handle_load_dll, handle_unload_dll,
windows_xfer_shared_libraries): Adjust.

7 years agoStandardize darwin's lm_info
Simon Marchi [Fri, 28 Apr 2017 21:16:12 +0000 (17:16 -0400)]
Standardize darwin's lm_info

Darwin's lm_info structure is used a little bit differently than the
other solib implementations.  The other implementations first allocate
an so_list object, then instanciate their specific lm_info structure,
and assign it to so_list::lm_info.

The Darwin implementation allocates both at the same time
(darwin_so_list).  This patch changes it to be like the others, so that
we'll be able to do some generalizations later.

gdb/ChangeLog:

* solib-darwin.c (struct darwin_so_list): Remove.
(darwin_current_sos): Allocate an so_list object instead of a
darwin_so_list, separately allocate an lm_info object.
(darwin_free_so): Free lm_info.

7 years agox86: Add run-time tests for -mtls-dialect=gnu2
H.J. Lu [Fri, 28 Apr 2017 19:42:05 +0000 (12:42 -0700)]
x86: Add run-time tests for -mtls-dialect=gnu2

* testsuite/config/default.exp (GNU2_CFLAGS): New.  Set
to -mtls-dialect=gnu2 if target compiler supports it.
* testsuite/ld-i386/tls.exp: Run -mtls-dialect=gnu2 tests.
* testsuite/ld-x86-64/tls.exp: Likewise.
* testsuite/ld-i386/tlsdesc1a.c: New file.
* testsuite/ld-i386/tlsdesc1b.c: Likewise.
* testsuite/ld-x86-64/tlsdesc1a.c: Likewise.
* testsuite/ld-x86-64/tlsdesc1b.c: Likewise.

7 years agoELF: Add run-time tests for -z now
H.J. Lu [Fri, 28 Apr 2017 19:29:29 +0000 (12:29 -0700)]
ELF: Add run-time tests for -z now

* testsuite/ld-elf/shared.exp: Add run-time tests for -z now.
* testsuite/ld-i386/tls.exp: Likewise.
* testsuite/ld-ifunc/ifunc.exp: Likewise.
* testsuite/ld-x86-64/tls.exp: Likewise.

7 years agoConsistently use fprintf_filtered when displaying MIPS registers.
John Baldwin [Fri, 28 Apr 2017 16:34:52 +0000 (09:34 -0700)]
Consistently use fprintf_filtered when displaying MIPS registers.

One line was using printf_filtered instead of fprintf_filtered
to the requested file.

gdb/ChangeLog:

* mips-tdep.c (print_gp_register_row): Replace printf_filtered
with fprintf_filtered.

7 years agox86: Check plt_got before using .plt.got
H.J. Lu [Fri, 28 Apr 2017 14:26:45 +0000 (07:26 -0700)]
x86: Check plt_got before using .plt.got

Since the GOT procedure linkage table is supported only if plt_got
isn't NULL, we need to check plt_got before using it.

* elf32-i386.c (elf_i386_allocate_dynrelocs): Check plt_got
before using .plt.got.
* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Likewise.

7 years agoAdd constructor and destructor to regcache
Yao Qi [Fri, 28 Apr 2017 13:43:13 +0000 (14:43 +0100)]
Add constructor and destructor to regcache

This patch adds ctor and dtor to regcache.

gdb:

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

* regcache.c (regcache::regcache): New function.
(regcache::~regcache): New function.
(regcache_xmalloc_1): Remove.
(regcache_xmalloc): Call new regcache.
(regcache_xfree): Call delete regcache.
(get_thread_arch_aspace_regcache): Call new regcache.

7 years agoFix off by one error when checking for empty note names.
Nick Clifton [Fri, 28 Apr 2017 11:09:14 +0000 (12:09 +0100)]
Fix off by one error when checking for empty note names.

PR binutils/21439
* readelf.c (print_gnu_build_attribute_name): Allow for an empty
name field.

7 years agoFix heap-buffer address violation when reading version data from a corrupt binary.
Nick Clifton [Fri, 28 Apr 2017 10:21:53 +0000 (11:21 +0100)]
Fix heap-buffer address violation when reading version data from a corrupt binary.

PR binutils/21437
* readelf.c (process_version_sections): Check for underflow when
computing the start address of the auxillary version data.

7 years agoFix heap-buffer overflow bugs caused when dumping debug information from a corrupt...
Nick Clifton [Fri, 28 Apr 2017 09:28:04 +0000 (10:28 +0100)]
Fix heap-buffer overflow bugs caused when dumping debug information from a corrupt binary.

PR binutils/21438
* dwarf.c (process_extended_line_op): Do not assume that the
string extracted from the section is NUL terminated.
(fetch_indirect_string): If the string retrieved from the section
is not NUL terminated, return an error message.
(fetch_indirect_line_string): Likewise.
(fetch_indexed_string): Likewise.

7 years agoUse ptid method lwp in mips_linux_new_thread
Yao Qi [Fri, 28 Apr 2017 08:50:51 +0000 (09:50 +0100)]
Use ptid method lwp in mips_linux_new_thread

gdb:

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

* mips-linux-nat.c (mips_linux_new_thread): Use ptid method
lwp instead of ptid_get_lwp.

7 years ago[MIPS] Use lwpid from lwp_info instead of inferior_ptid
Yao Qi [Fri, 28 Apr 2017 08:33:16 +0000 (09:33 +0100)]
[MIPS] Use lwpid from lwp_info instead of inferior_ptid

RAJESH reported that GDB gets "Couldn't write debug register: No such
process." on mips64 when GDB attaches to a multi threaded application.

Looks GDB nows PTRACE_GET_WATCH_REGS for inferior_ptid but
PTRACE_SET_WATCH_REGS for lwp->ptid, they may be different.

gdb:

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

* mips-linux-nat.c (mips_linux_new_thread): Get lwpid from
lwp_info instead of getting from inferior_ptid.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 28 Apr 2017 00:00:34 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoFix overload resolution involving rvalue references and cv qualifiers.
Keith Seitz [Thu, 27 Apr 2017 22:55:26 +0000 (15:55 -0700)]
Fix overload resolution involving rvalue references and cv qualifiers.

The following patch fixes several outstanding overload resolution problems
with rvalue references and cv qualifiers in the test suite. The tests for
these problems typically passed with one compiler version and failed with
another. This behavior occurs because of the ordering of the overloaded
functions in the debug info. So the first best match "won out" over the
a subsequent better match.

One of the bugs addressed by this patch is the failure of rank_one_type to
account for type equality of two overloads based on CV qualifiers.  This was
leading directly to problems evaluating rvalue reference overload quality,
but it is also highlighted in gdb.cp/oranking.exp, where two test KFAIL as
a result of this shortcoming.

I found the overload resolution code committed with the rvalue reference
patch (f9aeb8d49) needlessly over-complicated, and I have greatly simplified
it. This fixes some KFAILing tests in gdb.exp/rvalue-ref-overload.exp.

gdb/ChangeLog

* gdbtypes.c (LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS)
DIFFERENT_REFERENCE_TYPE_BADNESS): Remove.
(CV_CONVERSION_BADNESS): Define.
(rank_one_type): Remove overly restrictive rvalue reference
rank checks.
Add cv-qualifier checks and subranks for type equality.
* gdbtypes.h (REFERENCE_CONVERSION_RVALUE,
REFERENCE_CONVERSION_CONST_LVALUE, CV_CONVERSION_BADNESS,
CV_CONVERSION_CONST, CV_CONVERSION_VOLATILE): Declare.

gdb/testsuite/ChangeLog

* gdb.cp/oranking.cc (test15): New function.
(main): Call test15 and declare additional variables for testing.
* gdb.cp/oranking.exp: Remove kfail status for "p foo4(&a)" and
"p foo101('abc')" tests.
* gdb.cp/rvalue-ref-overloads.exp: Remove kfail status for
"lvalue reference overload" test.
* gdb.cp/rvalue-ref-params.exp: Remove kfail status for
"print value of f1 on Child&& in f2" test.

7 years agox86-64: Use "=" instead of "+=" to update 0
H.J. Lu [Thu, 27 Apr 2017 22:24:08 +0000 (15:24 -0700)]
x86-64: Use "=" instead of "+=" to update 0

Use

  if (htab->elf.splt->size == 0)
    htab->elf.splt->size = GET_PLT_ENTRY_SIZE (output_bfd);

instead of

  if (htab->elf.splt->size == 0)
    htab->elf.splt->size += GET_PLT_ENTRY_SIZE (output_bfd);

* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Use "="
instead of "+=" to update 0.

7 years agoAdd missing incref when creating Inferior Python object
Simon Marchi [Thu, 27 Apr 2017 21:03:20 +0000 (17:03 -0400)]
Add missing incref when creating Inferior Python object

The test py-inferior.exp fails when using a debug build of Python 3.6.  I don't
see it failing with my system's default Python, but it might be related to the
different memory allocation scheme used when doing a build with pydebug.

The issue is that we are missing a Py_INCREF in
inferior_to_inferior_object.  The PyObject_New function initializes the
object with a refcount of 1.  If we assume that this refcount
corresponds to the reference we are returning, then we are missing an
incref for the reference in the inferior data.

The counterpart for the incref that corresponds to the reference in the
inferior data is in py_free_inferior, in the form the gdbpy_ref instance.

Here's how I can get it to crash (with some debug output):

  $ ./gdb -nx -ex "set debug python 1"
  (gdb) add-inferior
  Added inferior 2
  (gdb) python infs = gdb.inferiors()
  Creating Python Inferior object inf = 1
  Creating Python Inferior object inf = 2
  (gdb) remove-inferiors 2
  py_free_inferior inf = 2
  infpy_dealloc inf = <unknown>
  (gdb) python infs = None
  Fatal Python error: Objects/tupleobject.c:243 object at 0x7f9cf1a568d8 has negative ref count -1

  Current thread 0x00007f9cf1b68780 (most recent call first):
    File "<string>", line 1 in <module>
  [1]    408 abort (core dumped)  ./gdb -nx -ex "set debug python 1"

After having created the inferiors object, their refcount is 1 (which
comes from PyObject_New), but it should be two.  The gdb inferior object
has a reference and the "infs" list has a reference.

When invoking remove-inferiors, py_free_inferior gets called.  It does
the decref that corresponds to the reference that the gdb inferior
object kept.  At this moment, the refcount drops to 0 and the object
gets deallocated, even though the "infs" list still has a reference.
When we set "infs" to None, Python tries to decref the already zero
refcount and the assert triggers.

With this patch, it looks better:

  (gdb) add-inferior
  Added inferior 2
  (gdb) python infs = gdb.inferiors()
  Creating Python Inferior object inf = 1
  Creating Python Inferior object inf = 2
  (gdb) remove-inferiors 2
  py_free_inferior inf = 2
  (gdb) python infs = None
  infpy_dealloc inf = <unknown>

gdb/ChangeLog:

* python/py-inferior.c (inferior_to_inferior_object): Increment reference
count when creating the object.

7 years agox86: Create dynamic sections in create_dynamic_sections
H.J. Lu [Thu, 27 Apr 2017 20:55:31 +0000 (13:55 -0700)]
x86: Create dynamic sections in create_dynamic_sections

This patch creates dynamic sections in i386/x86-64 create_dynamic_sections
instead of creating them on demend.  Linker will strip them if they are
empty.  It changes order in x86-64 .eh_frame section.  The extra DW_CFA_nop
paddings is due to

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

bfd/

* elf32-i386.c (elf_i386_create_dynamic_sections): Create the
.plt.got section here.
(elf_i386_check_relocs): Don't create the .plt.got section.
* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Create
the .plt.got and .plt.bnd sections here.
(elf_x86_64_check_relocs): Don't create the .plt.got nor
.plt.bnd sections.

ld/

* testsuite/ld-x86-64/pr21038a.d: Update DW_CFA_nop paddings
in .eh_frame section.
* testsuite/ld-x86-64/pr21038c.d: Update .eh_frame order.

7 years agoRemove has_bnd_reloc from elf_x86_64_link_hash_entry
H.J. Lu [Thu, 27 Apr 2017 16:32:35 +0000 (09:32 -0700)]
Remove has_bnd_reloc from elf_x86_64_link_hash_entry

has_bnd_reloc was added to elf_x86_64_link_hash_entry track BND
relocations by

commit 0ff2b86e7c14177ec7f9e1257f8e697814794017
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Nov 20 09:01:04 2013 -0800

    Create the second PLT for BND relocations

Since BND relocations have been deprecated by

commit d258b828287a863376af60a1ef7ceafbccc83d93
Author: Igor Zamyatin <igor.zamyatin@intel.com>
Date:   Tue Nov 18 10:52:36 2014 +0300

    Add -z bndplt to generate BND prefix in PLT entries

This patch removes has_bnd_reloc from elf_x86_64_link_hash_entry and
checks bndplt instead of has_bnd_reloc.

* elf64-x86-64.c (elf_x86_64_link_hash_entry): Remove
has_bnd_reloc.
(elf_x86_64_link_hash_newfunc): Don't clear has_bnd_reloc.
(elf_x86_64_copy_indirect_symbol): Don't copy has_bnd_reloc.
(elf_x86_64_check_relocs): Don't set has_bnd_reloc.
(elf_x86_64_finish_dynamic_symbol): Check bndplt instead of
has_bnd_reloc.

Remove has_bnd_reloc

7 years agoChange _bfd_elf_link_setup_gnu_properties to bfd *
H.J. Lu [Thu, 27 Apr 2017 16:07:23 +0000 (09:07 -0700)]
Change _bfd_elf_link_setup_gnu_properties to bfd *

Change setup_gnu_properties to return the first relocatable ELF input
with GNU properties so that a backend can make decision based on GNU
properties.

* elf-bfd.h (elf_backend_data): Change setup_gnu_properties
to return bfd *.
(_bfd_elf_link_setup_gnu_properties): Return bfd *.
* elf-properties.c (_bfd_elf_link_setup_gnu_properties): Return
the first relocatable ELF input with GNU properties.

7 years agoi386: Simplify VxWorks for non-PIC
H.J. Lu [Thu, 27 Apr 2017 15:55:36 +0000 (08:55 -0700)]
i386: Simplify VxWorks for non-PIC

Change

  if (PIC)
    {
      #1
    }
  else
    {
      #2
      if (VxWorks)
        {
          #3
        }
    }
  #4
  if (VxWorks && !PIC)
    {
      #5
    }

to

  #4
  if (PIC)
    {
      #1
    }
  else
    {
      #2
      if (VxWorks)
        {
          #3
          #5
        }
    }

* elf32-i386.c (elf_i386_finish_dynamic_sections): Simplify
VxWorks for non-PIC.

7 years agoRead corrrect auxiliary entry in AIX
Ulrich Weigand [Thu, 27 Apr 2017 13:57:08 +0000 (15:57 +0200)]
Read corrrect auxiliary entry in AIX

Fix handling of XCOFF function auxiliary entries, in particular when
the xlc -qfuncsect or gcc -ffunction-sections compiler option is used
in AIX.  Also handle C_WEAKEXT storage class.

gdb/
2016-10-21  Sangamesh Mallayya  <sangamesh.swamy@in.ibm.com>
    Ulrich Weigand  <uweigand@de.ibm.com>

* xcoffread.c (read_xcoff_symtab): Read correct function auxiliary
entry if xlc -qfuncsect or gcc -ffunction-sections compiler option
is used in AIX.
(read_xcoff_symtab): Handle C_WEAKEXT storage class.
(process_xcoff_symbol): Likewise.
(scan_xcoff_symtab): Likewise.

Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
7 years agoMIPS16/GAS: Factor out duplicate symbol value conversion code
Maciej W. Rozycki [Thu, 27 Apr 2017 01:25:33 +0000 (02:25 +0100)]
MIPS16/GAS: Factor out duplicate symbol value conversion code

Factor out and consolidate duplicate section-relative to PC-relative
symbol value conversion in `mips16_extended_frag' and `md_convert_frag'
used for MIPS16 relaxation, observing that the final calculation in the
latter function implies `stretch == 0'.  Sanitize the formatting of code
moved.

gas/
* config/tc-mips.c (mips16_pcrel_val): New function, factored
out from...
(mips16_extended_frag): ... here.
(md_convert_frag): Use `mips16_pcrel_val' rather than repeated
code in MIPS16 relaxation, with `stretch' hardcoded to 0.

7 years agoMIPS16/GAS: Rename the LONG_BRANCH relaxation flag
Maciej W. Rozycki [Thu, 27 Apr 2017 01:13:21 +0000 (02:13 +0100)]
MIPS16/GAS: Rename the LONG_BRANCH relaxation flag

Following commit 177b4a6ad004 ("infinite loop in mips16 assembler
relaxation"), <https://sourceware.org/ml/binutils/2002-03/msg00345.html>
the LONG_BRANCH flag used in MIPS16 relaxation has lost its use for
branches.  Complement commit 88a7ef168927 ("MIPS16/GAS: Restore
unsupported relocation diagnostics") then, which has removed the remains
of code deactivated by the former commit, and rename the flag to
ALWAYS_EXTENDED, more accurately reflecting its current use to select
the extended form of PC-relative ADDIU, DADDIU, LD and LW instructions.

gas/
* config/tc-mips.c (RELAX_MIPS16_LONG_BRANCH): Rename to...
(RELAX_MIPS16_ALWAYS_EXTENDED): ... this.
(RELAX_MIPS16_MARK_LONG_BRANCH): Rename to...
(RELAX_MIPS16_MARK_ALWAYS_EXTENDED): ... this.
(RELAX_MIPS16_CLEAR_LONG_BRANCH): Rename to...
(RELAX_MIPS16_CLEAR_ALWAYS_EXTENDED): ... this.
(mips16_extended_frag): Adjust accordingly.