diff options
author | Andrew Hsieh <andrewhsieh@google.com> | 2014-12-09 17:57:18 +0800 |
---|---|---|
committer | Andrew Hsieh <andrewhsieh@google.com> | 2014-12-09 19:50:14 +0800 |
commit | 5e8c1cf25beccac1d22d10dc866912394f42771b (patch) | |
tree | ee16b70f804484dc8e434e647e699ab50da2620f /binutils-2.25/ld/emultempl | |
parent | 8eebd7953384e6662ca926b003f2cdda8ccd3ee5 (diff) | |
download | toolchain_binutils-5e8c1cf25beccac1d22d10dc866912394f42771b.zip toolchain_binutils-5e8c1cf25beccac1d22d10dc866912394f42771b.tar.gz toolchain_binutils-5e8c1cf25beccac1d22d10dc866912394f42771b.tar.bz2 |
[2.25] sync to a30720e3e633f275250e26f85ccae5dbdddfb6c6
local patches will be re-applied later
commit a30720e3e633f275250e26f85ccae5dbdddfb6c6
Author: Alan Modra <amodra@gmail.com>
Date: Wed Nov 19 10:30:16 2014 +1030
daily update
Change-Id: Ieb2a3f4dd2ecb289ac5305ff08d428b2847494ab
Diffstat (limited to 'binutils-2.25/ld/emultempl')
53 files changed, 1762 insertions, 455 deletions
diff --git a/binutils-2.25/ld/emultempl/README b/binutils-2.25/ld/emultempl/README index c3c7472..f81ce08 100644 --- a/binutils-2.25/ld/emultempl/README +++ b/binutils-2.25/ld/emultempl/README @@ -2,7 +2,7 @@ The files in this directory are sourced by genscripts.sh, after setting some variables to substitute in, to produce C source files that contain jump tables for each emulation. -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2012-2014 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright diff --git a/binutils-2.25/ld/emultempl/aarch64elf.em b/binutils-2.25/ld/emultempl/aarch64elf.em index b3279bf..42e8056 100644 --- a/binutils-2.25/ld/emultempl/aarch64elf.em +++ b/binutils-2.25/ld/emultempl/aarch64elf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2009-2012 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # Contributed by ARM Ltd. # # This file is part of the GNU Binutils. @@ -30,6 +30,7 @@ fragment <<EOF static int no_enum_size_warning = 0; static int no_wchar_size_warning = 0; static int pic_veneer = 0; +static int fix_erratum_835769 = 0; static void gld${EMULATION_NAME}_before_parse (void) @@ -159,7 +160,6 @@ elf${ELFSIZE}_aarch64_add_stub_section (const char *stub_sec_name, asection *stub_sec; flagword flags; asection *output_section; - const char *secname; lang_output_section_statement_type *os; struct hook_stub_info info; @@ -173,8 +173,7 @@ elf${ELFSIZE}_aarch64_add_stub_section (const char *stub_sec_name, bfd_set_section_alignment (stub_file->the_bfd, stub_sec, 3); output_section = input_section->output_section; - secname = bfd_get_section_name (output_section->owner, output_section); - os = lang_output_section_find (secname); + os = lang_output_section_get (output_section); info.input_section = input_section; lang_list_init (&info.add); @@ -221,20 +220,27 @@ build_section_lists (lang_statement_union_type *statement) static void gld${EMULATION_NAME}_after_allocation (void) { + int ret; + /* bfd_elf32_discard_info just plays with debugging sections, ie. doesn't affect any code, so we can delay resizing the sections. It's likely we'll resize everything in the process of adding stubs. */ - if (bfd_elf_discard_info (link_info.output_bfd, & link_info)) + ret = bfd_elf_discard_info (link_info.output_bfd, & link_info); + if (ret < 0) + { + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + return; + } + else if (ret > 0) need_laying_out = 1; /* If generating a relocatable output file, then we don't have to examine the relocs. */ if (stub_file != NULL && !link_info.relocatable) { - int ret = elf${ELFSIZE}_aarch64_setup_section_lists (link_info.output_bfd, - & link_info); - + ret = elf${ELFSIZE}_aarch64_setup_section_lists (link_info.output_bfd, + &link_info); if (ret != 0) { if (ret < 0) @@ -297,7 +303,7 @@ aarch64_elf_create_output_section_statements (void) bfd_elf${ELFSIZE}_aarch64_set_options (link_info.output_bfd, &link_info, no_enum_size_warning, no_wchar_size_warning, - pic_veneer); + pic_veneer, fix_erratum_835769); stub_file = lang_add_input_file ("linker stubs", lang_input_file_is_fake_enum, @@ -346,6 +352,7 @@ PARSE_AND_LIST_PROLOGUE=' #define OPTION_PIC_VENEER 310 #define OPTION_STUBGROUP_SIZE 311 #define OPTION_NO_WCHAR_SIZE_WARNING 312 +#define OPTION_FIX_ERRATUM_835769 313 ' PARSE_AND_LIST_SHORTOPTS=p @@ -356,6 +363,7 @@ PARSE_AND_LIST_LONGOPTS=' { "pic-veneer", no_argument, NULL, OPTION_PIC_VENEER}, { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE }, { "no-wchar-size-warning", no_argument, NULL, OPTION_NO_WCHAR_SIZE_WARNING}, + { "fix-cortex-a53-835769", no_argument, NULL, OPTION_FIX_ERRATUM_835769}, ' PARSE_AND_LIST_OPTIONS=' @@ -373,6 +381,7 @@ PARSE_AND_LIST_OPTIONS=' after each stub section. Values of +/-1 indicate\n\ the linker should choose suitable defaults.\n" )); + fprintf (file, _(" --fix-cortex-a53-835769 Fix erratum 835769\n")); ' PARSE_AND_LIST_ARGS_CASES=' @@ -392,6 +401,10 @@ PARSE_AND_LIST_ARGS_CASES=' pic_veneer = 1; break; + case OPTION_FIX_ERRATUM_835769: + fix_erratum_835769 = 1; + break; + case OPTION_STUBGROUP_SIZE: { const char *end; diff --git a/binutils-2.25/ld/emultempl/aix.em b/binutils-2.25/ld/emultempl/aix.em index aa72ce6..56985cf 100644 --- a/binutils-2.25/ld/emultempl/aix.em +++ b/binutils-2.25/ld/emultempl/aix.em @@ -9,7 +9,7 @@ fragment <<EOF /* This file is is generated by a shell script. DO NOT EDIT! */ /* AIX emulation code for ${EMULATION_NAME} - Copyright 1991-2013 Free Software Foundation, Inc. + Copyright (C) 1991-2014 Free Software Foundation, Inc. Written by Steve Chamberlain <sac@cygnus.com> AIX support by Ian Lance Taylor <ian@cygnus.com> AIX 64 bit support by Tom Rix <trix@redhat.com> @@ -854,7 +854,7 @@ gld${EMULATION_NAME}_before_allocation (void) /* Remove this section from the list of the output section. This assumes we know what the script looks like. */ is = NULL; - os = lang_output_section_find (sec->output_section->name); + os = lang_output_section_get (sec->output_section); if (os == NULL) einfo ("%P%F: can't find output section %s\n", sec->output_section->name); @@ -1399,7 +1399,7 @@ static char * gld${EMULATION_NAME}_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -1509,7 +1509,13 @@ gld${EMULATION_NAME}_open_dynamic_archive (const char *arch, if (!entry->flags.maybe_archive) return FALSE; - path = concat (search->name, "/lib", entry->filename, arch, ".a", NULL); + if (entry->flags.full_name_provided) + path = concat (search->name, "/", entry->filename, + (const char *) NULL); + else + path = concat (search->name, "/lib", entry->filename, arch, ".a", + (const char *) NULL); + if (!ldfile_try_open_bfd (path, entry)) { free (path); @@ -1547,6 +1553,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = { NULL, /* list_options */ NULL, /* recognized_file */ NULL, /* find potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/alphaelf.em b/binutils-2.25/ld/emultempl/alphaelf.em index 21064ad..a36fc7d 100644 --- a/binutils-2.25/ld/emultempl/alphaelf.em +++ b/binutils-2.25/ld/emultempl/alphaelf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2003, 2004, 2005, 2007, 2008, 2009 -# Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -73,6 +72,7 @@ alpha_after_open (void) static void alpha_after_parse (void) { + link_info.relax_pass = 2; if (limit_32bit && !link_info.shared && !link_info.relocatable) lang_section_start (".interp", exp_binop ('+', diff --git a/binutils-2.25/ld/emultempl/armcoff.em b/binutils-2.25/ld/emultempl/armcoff.em index 20bff14..de10a6c 100644 --- a/binutils-2.25/ld/emultempl/armcoff.em +++ b/binutils-2.25/ld/emultempl/armcoff.em @@ -4,8 +4,7 @@ fragment <<EOF /* This file is is generated by a shell script. DO NOT EDIT! */ /* emulate the original gld for the given ${EMULATION_NAME} - Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 1991-2014 Free Software Foundation, Inc. Written by Steve Chamberlain steve@cygnus.com This file is part of the GNU Binutils. @@ -205,7 +204,7 @@ static char * gld${EMULATION_NAME}_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -280,6 +279,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = gld${EMULATION_NAME}_list_options, NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/armelf.em b/binutils-2.25/ld/emultempl/armelf.em index eee6af1..1dde019 100644 --- a/binutils-2.25/ld/emultempl/armelf.em +++ b/binutils-2.25/ld/emultempl/armelf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 1991-2013 Free Software Foundation, Inc. +# Copyright (C) 1991-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -28,10 +28,10 @@ fragment <<EOF #include "ldctor.h" #include "elf/arm.h" -static char *thumb_entry_symbol = NULL; +static char * thumb_entry_symbol = NULL; static int byteswap_code = 0; static int target1_is_rel = 0${TARGET1_IS_REL}; -static char *target2_type = "${TARGET2_TYPE}"; +static char * target2_type = "${TARGET2_TYPE}"; static int fix_v4bx = 0; static int use_blx = 0; static bfd_arm_vfp11_fix vfp11_denorm_fix = BFD_ARM_VFP11_FIX_DEFAULT; @@ -189,7 +189,6 @@ elf32_arm_add_stub_section (const char * stub_sec_name, asection *stub_sec; flagword flags; asection *output_section; - const char *secname; lang_output_section_statement_type *os; struct hook_stub_info info; @@ -203,8 +202,7 @@ elf32_arm_add_stub_section (const char * stub_sec_name, bfd_set_section_alignment (stub_file->the_bfd, stub_sec, alignment_power); output_section = input_section->output_section; - secname = bfd_get_section_name (output_section->owner, output_section); - os = lang_output_section_find (secname); + os = lang_output_section_get (output_section); info.input_section = input_section; lang_list_init (&info.add); @@ -273,6 +271,8 @@ compare_output_sec_vma (const void *a, const void *b) static void gld${EMULATION_NAME}_after_allocation (void) { + int ret; + if (!link_info.relocatable) { /* Build a sorted list of input text sections, then use that to process @@ -327,15 +327,20 @@ gld${EMULATION_NAME}_after_allocation (void) ie. doesn't affect any code, so we can delay resizing the sections. It's likely we'll resize everything in the process of adding stubs. */ - if (bfd_elf_discard_info (link_info.output_bfd, & link_info)) + ret = bfd_elf_discard_info (link_info.output_bfd, & link_info); + if (ret < 0) + { + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + return; + } + else if (ret > 0) need_laying_out = 1; /* If generating a relocatable output file, then we don't have to examine the relocs. */ if (stub_file != NULL && !link_info.relocatable) { - int ret = elf32_arm_setup_section_lists (link_info.output_bfd, & link_info); - + ret = elf32_arm_setup_section_lists (link_info.output_bfd, &link_info); if (ret != 0) { if (ret < 0) @@ -526,13 +531,14 @@ PARSE_AND_LIST_PROLOGUE=' #define OPTION_NO_ENUM_SIZE_WARNING 309 #define OPTION_PIC_VENEER 310 #define OPTION_FIX_V4BX_INTERWORKING 311 -#define OPTION_STUBGROUP_SIZE 312 +#define OPTION_STUBGROUP_SIZE 312 #define OPTION_NO_WCHAR_SIZE_WARNING 313 #define OPTION_FIX_CORTEX_A8 314 #define OPTION_NO_FIX_CORTEX_A8 315 -#define OPTION_NO_MERGE_EXIDX_ENTRIES 316 +#define OPTION_NO_MERGE_EXIDX_ENTRIES 316 #define OPTION_FIX_ARM1176 317 #define OPTION_NO_FIX_ARM1176 318 +#define OPTION_LONG_PLT 319 ' PARSE_AND_LIST_SHORTOPTS=p @@ -557,6 +563,7 @@ PARSE_AND_LIST_LONGOPTS=' { "no-merge-exidx-entries", no_argument, NULL, OPTION_NO_MERGE_EXIDX_ENTRIES }, { "fix-arm1176", no_argument, NULL, OPTION_FIX_ARM1176 }, { "no-fix-arm1176", no_argument, NULL, OPTION_NO_FIX_ARM1176 }, + { "long-plt", no_argument, NULL, OPTION_LONG_PLT }, ' PARSE_AND_LIST_OPTIONS=' @@ -574,6 +581,8 @@ PARSE_AND_LIST_OPTIONS=' fprintf (file, _(" --no-wchar-size-warning Don'\''t warn about objects with incompatible\n" " wchar_t sizes\n")); fprintf (file, _(" --pic-veneer Always generate PIC interworking veneers\n")); + fprintf (file, _(" --long-plt Generate long .plt entries\n" + " to handle large .plt/.got displacements\n")); fprintf (file, _("\ --stub-group-size=N Maximum size of a group of input sections that\n\ can be handled by one stub section. A negative\n\ @@ -677,6 +686,10 @@ PARSE_AND_LIST_ARGS_CASES=' case OPTION_NO_FIX_ARM1176: fix_arm1176 = 0; break; + + case OPTION_LONG_PLT: + bfd_elf32_arm_use_long_plt (); + break; ' # We have our own before_allocation etc. functions, but they call diff --git a/binutils-2.25/ld/emultempl/avrelf.em b/binutils-2.25/ld/emultempl/avrelf.em index 90894a1..170dc3e 100644 --- a/binutils-2.25/ld/emultempl/avrelf.em +++ b/binutils-2.25/ld/emultempl/avrelf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2006, 2007, 2008, 2009 -# Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/beos.em b/binutils-2.25/ld/emultempl/beos.em index f59e000..732abfd 100644 --- a/binutils-2.25/ld/emultempl/beos.em +++ b/binutils-2.25/ld/emultempl/beos.em @@ -7,8 +7,7 @@ else fi fragment <<EOF /* This file is part of GLD, the Gnu Linker. - Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1995-2014 Free Software Foundation, Inc. This file is part of the GNU Binutils. @@ -778,6 +777,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = NULL, /* list options */ NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/bfin.em b/binutils-2.25/ld/emultempl/bfin.em index ca57ac1..1439da2 100644 --- a/binutils-2.25/ld/emultempl/bfin.em +++ b/binutils-2.25/ld/emultempl/bfin.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2010 Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/cr16elf.em b/binutils-2.25/ld/emultempl/cr16elf.em index f76b95e..02f5220 100644 --- a/binutils-2.25/ld/emultempl/cr16elf.em +++ b/binutils-2.25/ld/emultempl/cr16elf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2007, 2008, 2009 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # Contributed by M R Swami Reddy <MR.Swami.Reddy@nsc.com> # # This file is part of the GNU Binutils. @@ -47,7 +47,7 @@ cr16_elf_after_open (void) input file with a nonzero .data section. The BFD backend will fill in these sections with magic numbers which can be used to relocate the data section at run time. */ - for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) + for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) { asection *datasec; @@ -139,7 +139,7 @@ cr16elf_before_allocation (void) /* If we are generating embedded relocs, call a special BFD backend routine to do the work. */ - for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) + for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) { asection *datasec, *relsec; char *errmsg; diff --git a/binutils-2.25/ld/emultempl/crxelf.em b/binutils-2.25/ld/emultempl/crxelf.em index c6d5a8d..da59429 100644 --- a/binutils-2.25/ld/emultempl/crxelf.em +++ b/binutils-2.25/ld/emultempl/crxelf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2004, 2005, 2007, 2009 -# Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/elf-generic.em b/binutils-2.25/ld/emultempl/elf-generic.em index 2c850f1..32c102d 100644 --- a/binutils-2.25/ld/emultempl/elf-generic.em +++ b/binutils-2.25/ld/emultempl/elf-generic.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/elf32.em b/binutils-2.25/ld/emultempl/elf32.em index 682f5e5..137446f 100644 --- a/binutils-2.25/ld/emultempl/elf32.em +++ b/binutils-2.25/ld/emultempl/elf32.em @@ -12,9 +12,7 @@ fragment <<EOF /* This file is is generated by a shell script. DO NOT EDIT! */ /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME} - Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 - Free Software Foundation, Inc. + Copyright (C) 1991-2014 Free Software Foundation, Inc. Written by Steve Chamberlain <sac@cygnus.com> ELF support by Ian Lance Taylor <ian@cygnus.com> @@ -40,11 +38,9 @@ fragment <<EOF #include "sysdep.h" #include "bfd.h" #include "libiberty.h" -#include "filenames.h" #include "safe-ctype.h" +#include "filenames.h" #include "getopt.h" -#include "md5.h" -#include "sha1.h" #include <fcntl.h> #include "bfdlink.h" @@ -56,6 +52,7 @@ fragment <<EOF #include "ldlang.h" #include "ldfile.h" #include "ldemul.h" +#include "ldbuildid.h" #include <ldgram.h> #include "elf/common.h" #include "elf-bfd.h" @@ -897,53 +894,20 @@ id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED) { const char *style = emit_note_gnu_build_id; bfd_size_type size; + bfd_size_type build_id_size; size = offsetof (Elf_External_Note, name[sizeof "GNU"]); size = (size + 3) & -(bfd_size_type) 4; - if (!strcmp (style, "md5") || !strcmp (style, "uuid")) - size += 128 / 8; - else if (!strcmp (style, "sha1")) - size += 160 / 8; - else if (!strncmp (style, "0x", 2)) - { - /* ID is in string form (hex). Convert to bits. */ - const char *id = style + 2; - do - { - if (ISXDIGIT (id[0]) && ISXDIGIT (id[1])) - { - ++size; - id += 2; - } - else if (*id == '-' || *id == ':') - ++id; - else - { - size = 0; - break; - } - } while (*id != '\0'); - } + build_id_size = compute_build_id_size (style); + if (build_id_size) + size += build_id_size; else size = 0; return size; } -static unsigned char -read_hex (const char xdigit) -{ - if (ISDIGIT (xdigit)) - return xdigit - '0'; - if (ISUPPER (xdigit)) - return xdigit - 'A' + 0xa; - if (ISLOWER (xdigit)) - return xdigit - 'a' + 0xa; - abort (); - return 0; -} - static bfd_boolean write_build_id (bfd *abfd) { @@ -956,7 +920,6 @@ write_build_id (bfd *abfd) bfd_size_type size; file_ptr position; Elf_External_Note *e_note; - typedef void (*sum_fn) (const void *, size_t, void *); style = t->o->build_id.style; asec = t->o->build_id.sec; @@ -988,55 +951,7 @@ write_build_id (bfd *abfd) bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type); memcpy (e_note->name, "GNU", sizeof "GNU"); - if (strcmp (style, "md5") == 0) - { - struct md5_ctx ctx; - - md5_init_ctx (&ctx); - if (!bed->s->checksum_contents (abfd, (sum_fn) &md5_process_bytes, &ctx)) - return FALSE; - md5_finish_ctx (&ctx, id_bits); - } - else if (strcmp (style, "sha1") == 0) - { - struct sha1_ctx ctx; - - sha1_init_ctx (&ctx); - if (!bed->s->checksum_contents (abfd, (sum_fn) &sha1_process_bytes, &ctx)) - return FALSE; - sha1_finish_ctx (&ctx, id_bits); - } - else if (strcmp (style, "uuid") == 0) - { - int n; - int fd = open ("/dev/urandom", O_RDONLY); - if (fd < 0) - return FALSE; - n = read (fd, id_bits, size); - close (fd); - if (n < (int) size) - return FALSE; - } - else if (strncmp (style, "0x", 2) == 0) - { - /* ID is in string form (hex). Convert to bits. */ - const char *id = style + 2; - size_t n = 0; - do - { - if (ISXDIGIT (id[0]) && ISXDIGIT (id[1])) - { - id_bits[n] = read_hex (*id++) << 4; - id_bits[n++] |= read_hex (*id++); - } - else if (*id == '-' || *id == ':') - ++id; - else - abort (); /* Should have been validated earlier. */ - } while (*id != '\0'); - } - else - abort (); /* Should have been validated earlier. */ + generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size); position = i_shdr->sh_offset + asec->output_offset; size = asec->size; @@ -1099,7 +1014,7 @@ gld${EMULATION_NAME}_after_open (void) /* Find an ELF input. */ for (abfd = link_info.input_bfds; - abfd != (bfd *) NULL; abfd = abfd->link_next) + abfd != (bfd *) NULL; abfd = abfd->link.next) if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) break; @@ -1114,7 +1029,20 @@ gld${EMULATION_NAME}_after_open (void) } if (link_info.relocatable) - return; + { + if (link_info.execstack == ! link_info.noexecstack) + /* PR ld/16744: If "-z [no]execstack" has been specified on the + command line and we are perfoming a relocatable link then no + PT_GNU_STACK segment will be created and so the + linkinfo.[no]execstack values set in _handle_option() will have no + effect. Instead we create a .note.GNU-stack section in much the + same way as the assembler does with its --[no]execstack option. */ + (void) bfd_make_section_with_flags (link_info.input_bfds, + ".note.GNU-stack", + SEC_READONLY | (link_info.execstack ? SEC_CODE : 0)); + + return; + } if (link_info.eh_frame_hdr && !link_info.traditional_format) @@ -1123,7 +1051,7 @@ gld${EMULATION_NAME}_after_open (void) bfd_boolean warn_eh_frame = FALSE; asection *s; - for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next) + for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next) { if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) elfbfd = abfd; @@ -1480,6 +1408,8 @@ gld${EMULATION_NAME}_before_allocation (void) const char *rpath; asection *sinterp; bfd *abfd; + struct elf_link_hash_entry *ehdr_start = NULL; + struct bfd_link_hash_entry ehdr_start_save = ehdr_start_save; if (is_elf_hash_table (link_info.hash)) { @@ -1487,10 +1417,35 @@ gld${EMULATION_NAME}_before_allocation (void) /* Make __ehdr_start hidden if it has been referenced, to prevent the symbol from being dynamic. */ - if (!bfd_elf_record_link_assignment (link_info.output_bfd, &link_info, - "__ehdr_start", TRUE, TRUE)) - einfo ("%P%F: failed to record assignment to %s: %E\n", - "__ehdr_start"); + if (!link_info.relocatable) + { + struct elf_link_hash_entry *h + = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start", + FALSE, FALSE, TRUE); + + /* Only adjust the export class if the symbol was referenced + and not defined, otherwise leave it alone. */ + if (h != NULL + && (h->root.type == bfd_link_hash_new + || h->root.type == bfd_link_hash_undefined + || h->root.type == bfd_link_hash_undefweak + || h->root.type == bfd_link_hash_common)) + { + _bfd_elf_link_hash_hide_symbol (&link_info, h, TRUE); + if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL) + h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN; + /* Don't leave the symbol undefined. Undefined hidden + symbols typically won't have dynamic relocations, but + we most likely will need dynamic relocations for + __ehdr_start if we are building a PIE or shared + library. */ + ehdr_start = h; + ehdr_start_save = h->root; + h->root.type = bfd_link_hash_defined; + h->root.u.def.section = bfd_abs_section_ptr; + h->root.u.def.value = 0; + } + } /* If we are going to make any variable assignments, we need to let the ELF backend know about them in case the variables are @@ -1504,7 +1459,7 @@ gld${EMULATION_NAME}_before_allocation (void) if (rpath == NULL) rpath = (const char *) getenv ("LD_RUN_PATH"); - for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next) + for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next) if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) { const char *audit_libs = elf_dt_audit (abfd); @@ -1605,6 +1560,14 @@ ${ELF_INTERPRETER_SET_DEFAULT} if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info)) einfo ("%P%F: failed to set dynamic section sizes: %E\n"); + + if (ehdr_start != NULL) + { + /* If we twiddled __ehdr_start to defined earlier, put it back + as it was. */ + ehdr_start->root.type = ehdr_start_save.type; + ehdr_start->root.u = ehdr_start_save.u; + } } EOF @@ -1623,42 +1586,46 @@ gld${EMULATION_NAME}_open_dynamic_archive { const char *filename; char *string; + size_t len; + bfd_boolean opened = FALSE; if (! entry->flags.maybe_archive) return FALSE; filename = entry->filename; + len = strlen (search->name) + strlen (filename); + if (entry->flags.full_name_provided) + { + len += sizeof "/"; + string = (char *) xmalloc (len); + sprintf (string, "%s/%s", search->name, filename); + } + else + { + size_t xlen = 0; - /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION - is defined, but it does not seem worth the headache to optimize - away those two bytes of space. */ - string = (char *) xmalloc (strlen (search->name) - + strlen (filename) - + strlen (arch) + len += strlen (arch) + sizeof "/lib.so"; #ifdef EXTRA_SHLIB_EXTENSION - + strlen (EXTRA_SHLIB_EXTENSION) + xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3 + ? strlen (EXTRA_SHLIB_EXTENSION) - 3 + : 0); #endif - + sizeof "/lib.so"); - - sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); - + string = (char *) xmalloc (len + xlen); + sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); #ifdef EXTRA_SHLIB_EXTENSION - /* Try the .so extension first. If that fails build a new filename - using EXTRA_SHLIB_EXTENSION. */ - if (! ldfile_try_open_bfd (string, entry)) - { - sprintf (string, "%s/lib%s%s%s", search->name, - filename, arch, EXTRA_SHLIB_EXTENSION); + /* Try the .so extension first. If that fails build a new filename + using EXTRA_SHLIB_EXTENSION. */ + opened = ldfile_try_open_bfd (string, entry); + if (!opened) + strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION); #endif + } - if (! ldfile_try_open_bfd (string, entry)) + if (!opened && !ldfile_try_open_bfd (string, entry)) { free (string); return FALSE; } -#ifdef EXTRA_SHLIB_EXTENSION - } -#endif entry->filename = string; @@ -1683,7 +1650,8 @@ gld${EMULATION_NAME}_open_dynamic_archive /* Rather than duplicating the logic above. Just use the filename we recorded earlier. */ - filename = lbasename (entry->filename); + if (!entry->flags.full_name_provided) + filename = lbasename (entry->filename); bfd_elf_set_dt_needed_name (entry->the_bfd, filename); } @@ -1777,6 +1745,9 @@ gld${EMULATION_NAME}_place_orphan (asection *s, { ".rodata", SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA, 0, 0, 0, 0 }, + { ".tdata", + SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL, + 0, 0, 0, 0 }, { ".data", SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA, 0, 0, 0, 0 }, @@ -1800,6 +1771,7 @@ gld${EMULATION_NAME}_place_orphan (asection *s, { orphan_text = 0, orphan_rodata, + orphan_tdata, orphan_data, orphan_bss, orphan_rel, @@ -1927,6 +1899,8 @@ gld${EMULATION_NAME}_place_orphan (asection *s, place = &hold[orphan_bss]; else if ((s->flags & SEC_SMALL_DATA) != 0) place = &hold[orphan_sdata]; + else if ((s->flags & SEC_THREAD_LOCAL) != 0) + place = &hold[orphan_tdata]; else if ((s->flags & SEC_READONLY) == 0) place = &hold[orphan_data]; else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL)) @@ -1968,9 +1942,12 @@ fragment <<EOF static void gld${EMULATION_NAME}_after_allocation (void) { - bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd, - &link_info); - gld${EMULATION_NAME}_map_segments (need_layout); + int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info); + + if (need_layout < 0) + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + else + gld${EMULATION_NAME}_map_segments (need_layout); } EOF fi @@ -1982,7 +1959,7 @@ static char * gld${EMULATION_NAME}_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -2300,6 +2277,14 @@ fragment <<EOF link_info.execstack = FALSE; } EOF + +if test x"$BNDPLT" = xyes; then +fragment <<EOF + else if (strcmp (optarg, "bndplt") == 0) + link_info.bndplt = TRUE; +EOF +fi + if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then fragment <<EOF else if (strcmp (optarg, "global") == 0) @@ -2479,6 +2464,13 @@ fragment <<EOF EOF fi +if test x"$BNDPLT" = xyes; then +fragment <<EOF + fprintf (file, _("\ + -z bndplt Always generate BND prefix in PLT entries\n")); +EOF +fi + if test -n "$PARSE_AND_LIST_OPTIONS" ; then fragment <<EOF $PARSE_AND_LIST_OPTIONS @@ -2524,6 +2516,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options}, ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols}, ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL}, - ${LDEMUL_NEW_VERS_PATTERN-NULL} + ${LDEMUL_NEW_VERS_PATTERN-NULL}, + ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL} }; EOF diff --git a/binutils-2.25/ld/emultempl/epiphanyelf_4x4.em b/binutils-2.25/ld/emultempl/epiphanyelf_4x4.em index 9f913ea..650604a 100644 --- a/binutils-2.25/ld/emultempl/epiphanyelf_4x4.em +++ b/binutils-2.25/ld/emultempl/epiphanyelf_4x4.em @@ -1,7 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, -# 2004, 2005, 2007, 2008 -# Free Software Foundation, Inc. +# Copyright (C) 1991-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/genelf.em b/binutils-2.25/ld/emultempl/genelf.em index ce416eb..5c5e1cb 100644 --- a/binutils-2.25/ld/emultempl/genelf.em +++ b/binutils-2.25/ld/emultempl/genelf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -38,7 +38,7 @@ gld${EMULATION_NAME}_after_open (void) after_open_default (); if (link_info.relocatable) - for (ibfd = link_info.input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = link_info.input_bfds; ibfd != NULL; ibfd = ibfd->link.next) if ((syms = bfd_get_outsymbols (ibfd)) != NULL && bfd_get_flavour (ibfd) == bfd_target_elf_flavour) for (sec = ibfd->sections; sec != NULL; sec = sec->next) diff --git a/binutils-2.25/ld/emultempl/generic.em b/binutils-2.25/ld/emultempl/generic.em index dce2bff..111b1c1 100644 --- a/binutils-2.25/ld/emultempl/generic.em +++ b/binutils-2.25/ld/emultempl/generic.em @@ -4,8 +4,7 @@ fragment <<EOF /* This file is is generated by a shell script. DO NOT EDIT! */ /* emulate the original gld for the given ${EMULATION_NAME} - Copyright 1991, 1992, 1994, 1996, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2007 Free Software Foundation, Inc. + Copyright (C) 1991-2014 Free Software Foundation, Inc. Written by Steve Chamberlain steve@cygnus.com This file is part of the GNU Binutils. @@ -81,7 +80,7 @@ static char * gld${EMULATION_NAME}_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -156,6 +155,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = ${LDEMUL_LIST_OPTIONS-NULL}, ${LDEMUL_RECOGNIZED_FILE-NULL}, ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL}, - ${LDEMUL_NEW_VERS_PATTERN-NULL} + ${LDEMUL_NEW_VERS_PATTERN-NULL}, + ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL} }; EOF diff --git a/binutils-2.25/ld/emultempl/gld960.em b/binutils-2.25/ld/emultempl/gld960.em index 4ba3eec..5632f31 100644 --- a/binutils-2.25/ld/emultempl/gld960.em +++ b/binutils-2.25/ld/emultempl/gld960.em @@ -1,8 +1,7 @@ # This shell script emits a C file. -*- C -*- # It does some substitutions. fragment <<EOF -/* Copyright 1991, 1992, 1994, 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008 - Free Software Foundation, Inc. +/* Copyright (C) 1991-2014 Free Software Foundation, Inc. This file is part of the GNU Binutils. @@ -74,7 +73,7 @@ static char * gld960_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -149,6 +148,7 @@ struct ld_emulation_xfer_struct ld_gld960_emulation = NULL, /* list options */ NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/gld960c.em b/binutils-2.25/ld/emultempl/gld960c.em index 1999ea8..dd69c79 100644 --- a/binutils-2.25/ld/emultempl/gld960c.em +++ b/binutils-2.25/ld/emultempl/gld960c.em @@ -1,8 +1,7 @@ # This shell script emits a C file. -*- C -*- # It does some substitutions. fragment <<EOF -/* Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2007 Free Software Foundation, Inc. +/* Copyright (C) 1991-2014 Free Software Foundation, Inc. This file is part of the GNU Binutils. @@ -87,7 +86,7 @@ static char * gld960_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -162,6 +161,7 @@ struct ld_emulation_xfer_struct ld_gld960coff_emulation = NULL, /* list options */ NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/hppaelf.em b/binutils-2.25/ld/emultempl/hppaelf.em index 65c1ea5..6955796 100644 --- a/binutils-2.25/ld/emultempl/hppaelf.em +++ b/binutils-2.25/ld/emultempl/hppaelf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 1991, 1993, 1994, 1997, 1999, 2000, 2001, 2002, 2003, 2004, -# 2005, 2006, 2007, 2008, 2009, 2012 Free Software Foundation, Inc. +# Copyright (C) 1991-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -178,7 +177,6 @@ hppaelf_add_stub_section (const char *stub_sec_name, asection *input_section) asection *stub_sec; flagword flags; asection *output_section; - const char *secname; lang_output_section_statement_type *os; struct hook_stub_info info; @@ -190,8 +188,7 @@ hppaelf_add_stub_section (const char *stub_sec_name, asection *input_section) goto err_ret; output_section = input_section->output_section; - secname = bfd_get_section_name (output_section->owner, output_section); - os = lang_output_section_find (secname); + os = lang_output_section_get (output_section); info.input_section = input_section; lang_list_init (&info.add); @@ -245,20 +242,26 @@ build_section_lists (lang_statement_union_type *statement) static void gld${EMULATION_NAME}_after_allocation (void) { + int ret; + /* bfd_elf_discard_info just plays with data and debugging sections, ie. doesn't affect code size, so we can delay resizing the sections. It's likely we'll resize everything in the process of adding stubs. */ - if (bfd_elf_discard_info (link_info.output_bfd, &link_info)) + ret = bfd_elf_discard_info (link_info.output_bfd, &link_info); + if (ret < 0) + { + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + return; + } + else if (ret > 0) need_laying_out = 1; /* If generating a relocatable output file, then we don't have to examine the relocs. */ if (stub_file != NULL && !link_info.relocatable) { - int ret = elf32_hppa_setup_section_lists (link_info.output_bfd, - &link_info); - + ret = elf32_hppa_setup_section_lists (link_info.output_bfd, &link_info); if (ret != 0) { if (ret < 0) diff --git a/binutils-2.25/ld/emultempl/ia64elf.em b/binutils-2.25/ld/emultempl/ia64elf.em index 88d5748..b14cb3d 100644 --- a/binutils-2.25/ld/emultempl/ia64elf.em +++ b/binutils-2.25/ld/emultempl/ia64elf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2003, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/irix.em b/binutils-2.25/ld/emultempl/irix.em index 41b8ce4..502d4a5 100644 --- a/binutils-2.25/ld/emultempl/irix.em +++ b/binutils-2.25/ld/emultempl/irix.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/linux.em b/binutils-2.25/ld/emultempl/linux.em index 61c7df4..bbc5946 100644 --- a/binutils-2.25/ld/emultempl/linux.em +++ b/binutils-2.25/ld/emultempl/linux.em @@ -9,8 +9,7 @@ fragment <<EOF /* This file is is generated by a shell script. DO NOT EDIT! */ /* Linux a.out emulation code for ${EMULATION_NAME} - Copyright 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, - 2003, 2004, 2005, 2007, 2008, 2012 Free Software Foundation, Inc. + Copyright (C) 1991-2014 Free Software Foundation, Inc. Written by Steve Chamberlain <sac@cygnus.com> Linux support by Eric Youngdale <ericy@cais.cais.com> @@ -62,7 +61,7 @@ gld${EMULATION_NAME}_open_dynamic_archive { char *string; - if (! entry->flags.maybe_archive) + if (! entry->flags.maybe_archive || entry->flags.full_name_provided) return FALSE; string = (char *) xmalloc (strlen (search->name) @@ -131,7 +130,7 @@ static char * gld${EMULATION_NAME}_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -206,6 +205,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = NULL, /* list options */ NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/lnk960.em b/binutils-2.25/ld/emultempl/lnk960.em index e556d43..6364f6d 100644 --- a/binutils-2.25/ld/emultempl/lnk960.em +++ b/binutils-2.25/ld/emultempl/lnk960.em @@ -2,8 +2,7 @@ # It does some substitutions. fragment <<EOF /* intel coff loader emulation specific stuff - Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003, - 2005, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 1991-2014 Free Software Foundation, Inc. Written by Steve Chamberlain steve@cygnus.com This file is part of the GNU Binutils. @@ -268,7 +267,7 @@ static char * lnk960_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -343,6 +342,7 @@ struct ld_emulation_xfer_struct ld_lnk960_emulation = NULL, /* list options */ NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/m68hc1xelf.em b/binutils-2.25/ld/emultempl/m68hc1xelf.em index 594b193..b357897 100644 --- a/binutils-2.25/ld/emultempl/m68hc1xelf.em +++ b/binutils-2.25/ld/emultempl/m68hc1xelf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 1991, 1993, 1994, 1997, 1999, 2000, 2001, 2002, 2003, 2005, 2007, -# 2008, 2009 Free Software Foundation, Inc. +# Copyright (C) 1991-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -250,7 +249,6 @@ m68hc11elf_add_stub_section (const char *stub_sec_name, asection *stub_sec; flagword flags; asection *output_section; - const char *secname; lang_output_section_statement_type *os; struct hook_stub_info info; @@ -262,8 +260,7 @@ m68hc11elf_add_stub_section (const char *stub_sec_name, goto err_ret; output_section = tramp_section->output_section; - secname = bfd_get_section_name (output_section->owner, output_section); - os = lang_output_section_find (secname); + os = lang_output_section_get (output_section); /* Try to put the new section at the same place as an existing .tramp section. Such .tramp section exists in most cases and diff --git a/binutils-2.25/ld/emultempl/m68kcoff.em b/binutils-2.25/ld/emultempl/m68kcoff.em index f68866c..1a95d7c 100644 --- a/binutils-2.25/ld/emultempl/m68kcoff.em +++ b/binutils-2.25/ld/emultempl/m68kcoff.em @@ -4,8 +4,7 @@ fragment <<EOF /* This file is is generated by a shell script. DO NOT EDIT! */ /* Handle embedded relocs for m68k. - Copyright 2000, 2002, 2003, 2004, 2005, 2007, 2008 - Free Software Foundation, Inc. + Copyright (C) 2000-2014 Free Software Foundation, Inc. Written by Michael Sokolov <msokolov@ivan.Harhan.ORG>, based on generic.em by Steve Chamberlain <steve@cygnus.com>, embedded relocs code based on mipsecoff.em by Ian Lance Taylor <ian@cygnus.com> (now removed). @@ -68,7 +67,7 @@ gld${EMULATION_NAME}_after_open (void) || link_info.relocatable) return; - for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) + for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) { asection *datasec; @@ -134,7 +133,7 @@ gld${EMULATION_NAME}_after_allocation (void) || link_info.relocatable) return; - for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) + for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) { asection *datasec, *relsec; char *errmsg; @@ -165,7 +164,7 @@ static char * gld${EMULATION_NAME}_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -240,6 +239,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = NULL, /* list options */ NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/m68kelf.em b/binutils-2.25/ld/emultempl/m68kelf.em index 48a50bc..c5cfe77 100644 --- a/binutils-2.25/ld/emultempl/m68kelf.em +++ b/binutils-2.25/ld/emultempl/m68kelf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2000, 2001, 2003, 2005, 2007, 2008, 2009 -# Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # Written by Michael Sokolov <msokolov@ivan.Harhan.ORG>, based on armelf.em # # This file is part of the GNU Binutils. @@ -76,7 +75,7 @@ m68k_elf_after_open (void) input file with a nonzero .data section. The BFD backend will fill in these sections with magic numbers which can be used to relocate the data section at run time. */ - for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) + for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) { asection *datasec; @@ -154,7 +153,7 @@ m68k_elf_after_allocation (void) /* If we are generating embedded relocs, call a special BFD backend routine to do the work. */ - for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next) + for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) { asection *datasec, *relsec; char *errmsg; diff --git a/binutils-2.25/ld/emultempl/metagelf.em b/binutils-2.25/ld/emultempl/metagelf.em index 21e3e94..97739dc 100644 --- a/binutils-2.25/ld/emultempl/metagelf.em +++ b/binutils-2.25/ld/emultempl/metagelf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2013 Free Software Foundation, Inc. +# Copyright (C) 2013-2014 Free Software Foundation, Inc. # # This file is part of GNU Binutils. # @@ -45,9 +45,9 @@ static bfd_signed_vma group_size = 1; static void metagelf_create_output_section_statements (void) { - extern const bfd_target bfd_elf32_metag_vec; + extern const bfd_target metag_elf32_vec; - if (link_info.output_bfd->xvec != &bfd_elf32_metag_vec) + if (link_info.output_bfd->xvec != &metag_elf32_vec) return; stub_file = lang_add_input_file ("linker stubs", @@ -154,7 +154,6 @@ metagelf_add_stub_section (const char *stub_sec_name, asection *input_section) asection *stub_sec; flagword flags; asection *output_section; - const char *secname; lang_output_section_statement_type *os; struct hook_stub_info info; @@ -166,8 +165,7 @@ metagelf_add_stub_section (const char *stub_sec_name, asection *input_section) goto err_ret; output_section = input_section->output_section; - secname = bfd_get_section_name (output_section->owner, output_section); - os = lang_output_section_find (secname); + os = lang_output_section_get (output_section); info.input_section = input_section; lang_list_init (&info.add); @@ -221,20 +219,26 @@ build_section_lists (lang_statement_union_type *statement) static void gld${EMULATION_NAME}_after_allocation (void) { + int ret; + /* bfd_elf_discard_info just plays with data and debugging sections, ie. doesn't affect code size, so we can delay resizing the sections. It's likely we'll resize everything in the process of adding stubs. */ - if (bfd_elf_discard_info (link_info.output_bfd, &link_info)) + ret = bfd_elf_discard_info (link_info.output_bfd, &link_info); + if (ret < 0) + { + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + return; + } + else if (ret > 0) need_laying_out = 1; /* If generating a relocatable output file, then we don't have to examine the relocs. */ if (stub_file != NULL && !link_info.relocatable) { - int ret = elf_metag_setup_section_lists (link_info.output_bfd, - &link_info); - + ret = elf_metag_setup_section_lists (link_info.output_bfd, &link_info); if (ret != 0) { if (ret < 0) diff --git a/binutils-2.25/ld/emultempl/mipself.em b/binutils-2.25/ld/emultempl/mipself.em index 3c6ec9f..b6e17ce 100644 --- a/binutils-2.25/ld/emultempl/mipself.em +++ b/binutils-2.25/ld/emultempl/mipself.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2004, 2006, 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -136,7 +136,6 @@ mips_add_stub_section (const char *stub_sec_name, asection *input_section, { asection *stub_sec; flagword flags; - const char *secname; lang_output_section_statement_type *os; struct hook_stub_info info; @@ -176,9 +175,7 @@ mips_add_stub_section (const char *stub_sec_name, asection *input_section, if (!bfd_set_section_flags (stub_bfd, stub_sec, flags)) goto err_ret; - /* Create an output section statement. */ - secname = bfd_get_section_name (output_section->owner, output_section); - os = lang_output_section_find (secname); + os = lang_output_section_get (output_section); /* Initialize a statement list that contains only the new statement. */ lang_list_init (&info.add); diff --git a/binutils-2.25/ld/emultempl/mmix-elfnmmo.em b/binutils-2.25/ld/emultempl/mmix-elfnmmo.em index 0059792..5ef5e5e 100644 --- a/binutils-2.25/ld/emultempl/mmix-elfnmmo.em +++ b/binutils-2.25/ld/emultempl/mmix-elfnmmo.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 -# Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -102,7 +101,7 @@ mmix_after_allocation (void) This section is only present when there are register symbols. */ sec = bfd_get_section_by_name (link_info.output_bfd, MMIX_REG_SECTION_NAME); if (sec != NULL) - bfd_set_section_vma (abfd, sec, 0); + bfd_set_section_vma (sec->owner, sec, 0); if (!_bfd_mmix_after_linker_allocation (link_info.output_bfd, &link_info)) { diff --git a/binutils-2.25/ld/emultempl/mmixelf.em b/binutils-2.25/ld/emultempl/mmixelf.em index 89c60c9..566eeb0 100644 --- a/binutils-2.25/ld/emultempl/mmixelf.em +++ b/binutils-2.25/ld/emultempl/mmixelf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2001, 2002, 2003, 2005, 2007, 2012 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/mmo.em b/binutils-2.25/ld/emultempl/mmo.em index b895a9a..f7deaaa 100644 --- a/binutils-2.25/ld/emultempl/mmo.em +++ b/binutils-2.25/ld/emultempl/mmo.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 -# Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/nds32elf.em b/binutils-2.25/ld/emultempl/nds32elf.em new file mode 100644 index 0000000..592471e --- /dev/null +++ b/binutils-2.25/ld/emultempl/nds32elf.em @@ -0,0 +1,386 @@ +# This shell script emits a C file. -*- C -*- +# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Contributed by Andes Technology Corporation. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +fragment <<EOF + +#include "libbfd.h" +#include "elf-bfd.h" +#include "elf/nds32.h" +#include "bfd_stdint.h" +#include "elf32-nds32.h" + +static int relax_fp_as_gp = 1; /* --mrelax-omit-fp */ +static int eliminate_gc_relocs = 0; /* --meliminate-gc-relocs */ +static FILE *sym_ld_script = NULL; /* --mgen-symbol-ld-script=<file> */ +/* Disable if linking a dynamically linked executable. */ +static int load_store_relax = 1; +static int target_optimize = 0; /* Switch optimization. */ +static int relax_status = 0; /* Finished optimization. */ +static int relax_round = 0; /* Going optimization. */ +static FILE *ex9_export_file = NULL; /* --mexport-ex9=<file> */ +static FILE *ex9_import_file = NULL; /* --mimport-ex9=<file> */ +static int update_ex9_table = 0; /* --mupdate-ex9. */ +static int ex9_limit = 511; +static bfd_boolean ex9_loop_aware = FALSE; /* Ignore ex9 if inside a loop. */ +static bfd_boolean ifc_loop_aware = FALSE; /* Ignore ifc if inside a loop. */ + +/* Save the target options into output bfd to avoid using to many global + variables. Do this after the output has been created, but before + inputs are read. */ +static void +nds32_elf_create_output_section_statements (void) +{ + if (strstr (bfd_get_target (link_info.output_bfd), "nds32") == NULL) + { + /* Check the output target is nds32. */ + einfo ("%F%X%P: error: Cannot change output format whilst " + "linking NDS32 binaries.\n"); + return; + } + + bfd_elf32_nds32_set_target_option (&link_info, relax_fp_as_gp, + eliminate_gc_relocs, + sym_ld_script, + load_store_relax, + target_optimize, relax_status, relax_round, + ex9_export_file, ex9_import_file, + update_ex9_table, ex9_limit, + ex9_loop_aware, ifc_loop_aware); +} + +static void +nds32_elf_after_parse (void) +{ + if (link_info.relocatable) + DISABLE_RELAXATION; + + if (!RELAXATION_ENABLED) + { + target_optimize = target_optimize & (!NDS32_RELAX_JUMP_IFC_ON); + target_optimize = target_optimize & (!NDS32_RELAX_EX9_ON); + relax_fp_as_gp = 0; + } + + if (ex9_import_file != NULL) + { + ex9_export_file = NULL; + target_optimize = target_optimize & (!NDS32_RELAX_EX9_ON); + } + else + update_ex9_table = 0; + + if (link_info.shared) + { + target_optimize = target_optimize & (!NDS32_RELAX_JUMP_IFC_ON); + target_optimize = target_optimize & (!NDS32_RELAX_EX9_ON); + } + + after_parse_default (); +} + +static void +nds32_elf_after_open (void) +{ + unsigned int arch_ver = (unsigned int)-1; + unsigned int abi_ver = (unsigned int)-1; + bfd *abfd; + + /* For now, make sure all object files are of the same architecture. + We may try to merge object files with different architecture together. */ + for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) + { + if (arch_ver == (unsigned int)-1 && E_N1_ARCH != (elf_elfheader (abfd)->e_flags & EF_NDS_ARCH)) + arch_ver = elf_elfheader (abfd)->e_flags & EF_NDS_ARCH ; + + if (abi_ver == (unsigned int)-1) + { + /* Initialize ABI version, if not ABI0. + (OS uses empty file to create empty ELF with ABI0). */ + if ((elf_elfheader (abfd)->e_flags & EF_NDS_ABI) != 0) + abi_ver = elf_elfheader (abfd)->e_flags & EF_NDS_ABI ; + } + else if ((elf_elfheader (abfd)->e_flags & EF_NDS_ABI) != 0 + && abi_ver != (elf_elfheader (abfd)->e_flags & EF_NDS_ABI)) + { + /* Incompatible objects. */ + einfo (_("%F%B: ABI version of object files mismatched\n"), abfd); + } + +#if defined NDS32_EX9_EXT + /* Append .ex9.itable section in the last input object file. */ + if (abfd->link_next == NULL && (target_optimize & NDS32_RELAX_EX9_ON)) + { + asection *itable; + struct bfd_link_hash_entry *h; + itable = bfd_make_section_with_flags (abfd, ".ex9.itable", + SEC_CODE | SEC_ALLOC | SEC_LOAD + | SEC_HAS_CONTENTS | SEC_READONLY + | SEC_IN_MEMORY | SEC_KEEP); + if (itable) + { + itable->gc_mark = 1; + itable->alignment_power = 2; + itable->size = 0x1000; + itable->contents = bfd_zalloc (abfd, itable->size); + + /* Add a symbol in the head of ex9.itable to objdump clearly. */ + h = bfd_link_hash_lookup (link_info.hash, "_EX9_BASE_", + FALSE, FALSE, FALSE); + _bfd_generic_link_add_one_symbol + (&link_info, link_info.output_bfd, "_EX9_BASE_", + BSF_GLOBAL | BSF_WEAK, itable, 0, (const char *) NULL, FALSE, + get_elf_backend_data (link_info.output_bfd)->collect, &h); + } + } +#endif + } + + /* Check object files if the target is dynamic linked executable + or shared object. */ + if (elf_hash_table (&link_info)->dynamic_sections_created + || link_info.shared || link_info.pie) + { + for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next) + { + if (!(elf_elfheader (abfd)->e_flags & E_NDS32_HAS_PIC)) + { + /* Non-PIC object file is used. */ + if (link_info.shared || link_info.pie) + { + /* For PIE or shared object, all input must be PIC. */ + einfo (_("%B: must use -fpic to compile this file " + "for shared object or PIE\n"), abfd); + } + else + { + /* Dynamic linked executable with SDA and non-PIC. + Turn off load/store relaxtion. */ + /* TODO: This may support in the future. */ + load_store_relax = 0 ; + relax_fp_as_gp = 0; + } + } + } + /* Turn off relax when building shared object or PIE + until we can support their relaxation. */ + } + + /* Call the standard elf routine. */ + gld${EMULATION_NAME}_after_open (); +} + +static void +nds32_elf_after_allocation (void) +{ + if (target_optimize & NDS32_RELAX_EX9_ON + || (ex9_import_file != NULL && update_ex9_table == 1)) + { + /* Initialize ex9 hash table. */ + if (!nds32_elf_ex9_init ()) + return; + } + + /* Call default after allocation callback. + 1. This is where relaxation is done. + 2. It calls gld${EMULATION_NAME}_map_segments to build ELF segment table. + 3. Any relaxation requires relax being done must be called after it. */ + gld${EMULATION_NAME}_after_allocation (); +} + +EOF +# Define some shell vars to insert bits of code into the standard elf +# parse_args and list_options functions. +# +PARSE_AND_LIST_PROLOGUE=' +#define OPTION_BASELINE 301 +#define OPTION_ELIM_GC_RELOCS (OPTION_BASELINE + 1) +#define OPTION_FP_AS_GP (OPTION_BASELINE + 2) +#define OPTION_NO_FP_AS_GP (OPTION_BASELINE + 3) +#define OPTION_REDUCE_FP_UPDATE (OPTION_BASELINE + 4) +#define OPTION_NO_REDUCE_FP_UPDATE (OPTION_BASELINE + 5) +#define OPTION_EXPORT_SYMBOLS (OPTION_BASELINE + 6) + +/* These are only available to ex9. */ +#if defined NDS32_EX9_EXT +#define OPTION_EX9_BASELINE 320 +#define OPTION_EX9_TABLE (OPTION_EX9_BASELINE + 1) +#define OPTION_NO_EX9_TABLE (OPTION_EX9_BASELINE + 2) +#define OPTION_EXPORT_EX9 (OPTION_EX9_BASELINE + 3) +#define OPTION_IMPORT_EX9 (OPTION_EX9_BASELINE + 4) +#define OPTION_UPDATE_EX9 (OPTION_EX9_BASELINE + 5) +#define OPTION_EX9_LIMIT (OPTION_EX9_BASELINE + 6) +#define OPTION_EX9_LOOP (OPTION_EX9_BASELINE + 7) +#endif + +/* These are only available to link-time ifc. */ +#if defined NDS32_IFC_EXT +#define OPTION_IFC_BASELINE 340 +#define OPTION_JUMP_IFC (OPTION_IFC_BASELINE + 1) +#define OPTION_NO_JUMP_IFC (OPTION_IFC_BASELINE + 2) +#define OPTION_IFC_LOOP (OPTION_IFC_BASELINE + 3) +#endif +' +PARSE_AND_LIST_LONGOPTS=' + { "mfp-as-gp", no_argument, NULL, OPTION_FP_AS_GP}, + { "mno-fp-as-gp", no_argument, NULL, OPTION_NO_FP_AS_GP}, + { "mexport-symbols", required_argument, NULL, OPTION_EXPORT_SYMBOLS}, + /* These are deprecated options. Remove them in the future. */ + { "mrelax-reduce-fp-update", no_argument, NULL, OPTION_REDUCE_FP_UPDATE}, + { "mrelax-no-reduce-fp-update", no_argument, NULL, OPTION_NO_REDUCE_FP_UPDATE}, + { "mbaseline", required_argument, NULL, OPTION_BASELINE}, + { "meliminate-gc-relocs", no_argument, NULL, OPTION_ELIM_GC_RELOCS}, + { "mrelax-omit-fp", no_argument, NULL, OPTION_FP_AS_GP}, + { "mrelax-no-omit-fp", no_argument, NULL, OPTION_NO_FP_AS_GP}, + { "mgen-symbol-ld-script", required_argument, NULL, OPTION_EXPORT_SYMBOLS}, + /* These are specific optioins for ex9-ext support. */ +#if defined NDS32_EX9_EXT + { "mex9", no_argument, NULL, OPTION_EX9_TABLE}, + { "mno-ex9", no_argument, NULL, OPTION_NO_EX9_TABLE}, + { "mexport-ex9", required_argument, NULL, OPTION_EXPORT_EX9}, + { "mimport-ex9", required_argument, NULL, OPTION_IMPORT_EX9}, + { "mupdate-ex9", no_argument, NULL, OPTION_UPDATE_EX9}, + { "mex9-limit", required_argument, NULL, OPTION_EX9_LIMIT}, + { "mex9-loop-aware", no_argument, NULL, OPTION_EX9_LOOP}, +#endif + /* These are specific optioins for ifc-ext support. */ +#if defined NDS32_IFC_EXT + { "mifc", no_argument, NULL, OPTION_JUMP_IFC}, + { "mno-ifc", no_argument, NULL, OPTION_NO_JUMP_IFC}, + { "mifc-loop-aware", no_argument, NULL, OPTION_IFC_LOOP}, +#endif +' +PARSE_AND_LIST_OPTIONS=' + fprintf (file, _("\ + --m[no-]fp-as-gp Disable/enable fp-as-gp relaxation\n\ + --mexport-symbols=FILE Exporting symbols in linker script\n\ +")); + +#if defined NDS32_EX9_EXT + fprintf (file, _("\ + --m[no-]ex9 Disable/enable link-time EX9 relaxation\n\ + --mexport-ex9=FILE Export EX9 table after linking\n\ + --mimport-ex9=FILE Import Ex9 table for EX9 relaxation\n\ + --mupdate-ex9 Update existing EX9 table\n\ + --mex9-limit=NUM Maximum number of entries in ex9 table\n\ + --mex9-loop-aware Avoid generate EX9 instruction inside loop\n\ +")); +#endif + +#if defined NDS32_IFC_EXT + fprintf (file, _("\ + --m[no-]ifc Disable/enable link-time IFC optimization\n\ + --mifc-loop-aware Avoid generate IFC instruction inside loop\n\ +")); +#endif +' +PARSE_AND_LIST_ARGS_CASES=' + case OPTION_BASELINE: + einfo ("%P: --mbaseline is not used anymore.\n"); + break; + case OPTION_ELIM_GC_RELOCS: + eliminate_gc_relocs = 1; + break; + case OPTION_FP_AS_GP: + case OPTION_NO_FP_AS_GP: + relax_fp_as_gp = (optc == OPTION_FP_AS_GP); + break; + case OPTION_REDUCE_FP_UPDATE: + case OPTION_NO_REDUCE_FP_UPDATE: + einfo ("%P: --relax-[no-]reduce-fp-updat is not used anymore.\n"); + break; + case OPTION_EXPORT_SYMBOLS: + if (!optarg) + einfo (_("Missing file for --mexport-symbols.\n"), optarg); + + if(strcmp (optarg, "-") == 0) + sym_ld_script = stdout; + else + { + sym_ld_script = fopen (optarg, FOPEN_WT); + if(sym_ld_script == NULL) + einfo (_("%P%F: cannot open map file %s: %E.\n"), optarg); + } + break; +#if defined NDS32_EX9_EXT + case OPTION_EX9_TABLE: + target_optimize = target_optimize | NDS32_RELAX_EX9_ON; + break; + case OPTION_NO_EX9_TABLE: + target_optimize = target_optimize & (!NDS32_RELAX_EX9_ON); + break; + case OPTION_EXPORT_EX9: + if (!optarg) + einfo (_("Missing file for --mexport-ex9=<file>.\n")); + + if(strcmp (optarg, "-") == 0) + ex9_export_file = stdout; + else + { + ex9_export_file = fopen (optarg, "wb"); + if(ex9_export_file == NULL) + einfo (_("ERROR %P%F: cannot open ex9 export file %s.\n"), optarg); + } + break; + case OPTION_IMPORT_EX9: + if (!optarg) + einfo (_("Missing file for --mimport-ex9=<file>.\n")); + + ex9_import_file = fopen (optarg, "rb+"); + if(ex9_import_file == NULL) + einfo (_("ERROR %P%F: cannot open ex9 import file %s.\n"), optarg); + break; + case OPTION_UPDATE_EX9: + update_ex9_table = 1; + break; + case OPTION_EX9_LIMIT: + if (optarg) + { + ex9_limit = atoi (optarg); + if (ex9_limit > 511 || ex9_limit < 1) + { + einfo (_("ERROR: the range of ex9_limit must between 1 and 511\n")); + exit (1); + } + } + break; + case OPTION_EX9_LOOP: + target_optimize = target_optimize | NDS32_RELAX_EX9_ON; + ex9_loop_aware = 1; + break; +#endif +#if defined NDS32_IFC_EXT + case OPTION_JUMP_IFC: + target_optimize = target_optimize | NDS32_RELAX_JUMP_IFC_ON; + break; + case OPTION_NO_JUMP_IFC: + target_optimize = target_optimize & (!NDS32_RELAX_JUMP_IFC_ON); + break; + case OPTION_IFC_LOOP: + target_optimize = target_optimize | NDS32_RELAX_JUMP_IFC_ON; + ifc_loop_aware = 1; + break; +#endif +' +LDEMUL_AFTER_OPEN=nds32_elf_after_open +LDEMUL_AFTER_PARSE=nds32_elf_after_parse +LDEMUL_AFTER_ALLOCATION=nds32_elf_after_allocation +LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=nds32_elf_create_output_section_statements diff --git a/binutils-2.25/ld/emultempl/needrelax.em b/binutils-2.25/ld/emultempl/needrelax.em index 7f90224..a89f122 100644 --- a/binutils-2.25/ld/emultempl/needrelax.em +++ b/binutils-2.25/ld/emultempl/needrelax.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2001, 2002, 2003, 2005, 2007 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/netbsd.em b/binutils-2.25/ld/emultempl/netbsd.em index 99b48b0..82478b2 100644 --- a/binutils-2.25/ld/emultempl/netbsd.em +++ b/binutils-2.25/ld/emultempl/netbsd.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2007 Free Software Foundation, Inc. +# Copyright (C) 2007-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/nios2elf.em b/binutils-2.25/ld/emultempl/nios2elf.em new file mode 100644 index 0000000..bdf54a3 --- /dev/null +++ b/binutils-2.25/ld/emultempl/nios2elf.em @@ -0,0 +1,323 @@ +# This shell script emits a C file. -*- C -*- +# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# +# This file is part of GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +# This file is sourced from elf32.em, and defines extra Nios II ELF +# specific routines. Taken from metagelf.em. +# +fragment <<EOF + +#include "ldctor.h" +#include "elf32-nios2.h" + + +/* Fake input file for stubs. */ +static lang_input_statement_type *stub_file; + +/* Whether we need to call nios2_layout_sections_again. */ +static int need_laying_out = 0; + + +/* This is called before the input files are opened. We create a new + fake input file to hold the stub sections. */ + +static void +nios2elf_create_output_section_statements (void) +{ + extern const bfd_target nios2_elf32_le_vec, nios2_elf32_be_vec; + + if (link_info.output_bfd->xvec != &nios2_elf32_le_vec + && link_info.output_bfd->xvec != &nios2_elf32_be_vec) + return; + + /* If --no-relax was not explicitly specified by the user, enable + relaxation. If it's not enabled (either explicitly or by default), + we're done, as we won't need to create any stubs. */ + if (!link_info.relocatable && RELAXATION_DISABLED_BY_DEFAULT) + ENABLE_RELAXATION; + if (!RELAXATION_ENABLED) + return; + + stub_file = lang_add_input_file ("linker stubs", + lang_input_file_is_fake_enum, + NULL); + stub_file->the_bfd = bfd_create ("linker stubs", link_info.output_bfd); + if (stub_file->the_bfd == NULL + || ! bfd_set_arch_mach (stub_file->the_bfd, + bfd_get_arch (link_info.output_bfd), + bfd_get_mach (link_info.output_bfd))) + { + einfo ("%X%P: can not create BFD %E\n"); + return; + } + + stub_file->the_bfd->flags |= BFD_LINKER_CREATED; + ldlang_add_file (stub_file); +} + + +struct hook_stub_info +{ + lang_statement_list_type add; + asection *input_section; +}; + +/* Traverse the linker tree to find the spot where the stub goes. */ + +static bfd_boolean +hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp, + bfd_boolean afterp) +{ + lang_statement_union_type *l; + bfd_boolean ret; + + for (; (l = *lp) != NULL; lp = &l->header.next) + { + switch (l->header.type) + { + case lang_constructors_statement_enum: + ret = hook_in_stub (info, &constructor_list.head, afterp); + if (ret) + return ret; + break; + + case lang_output_section_statement_enum: + ret = hook_in_stub (info, + &l->output_section_statement.children.head, + afterp); + if (ret) + return ret; + break; + + case lang_wild_statement_enum: + ret = hook_in_stub (info, &l->wild_statement.children.head, afterp); + if (ret) + return ret; + break; + + case lang_group_statement_enum: + ret = hook_in_stub (info, &l->group_statement.children.head, afterp); + if (ret) + return ret; + break; + + case lang_input_section_enum: + if (l->input_section.section == info->input_section) + { + /* We've found our section. Insert the stub immediately + before or after its associated input section. */ + if (afterp) + { + *(info->add.tail) = l->header.next; + l->header.next = info->add.head; + } + else + { + *lp = info->add.head; + *(info->add.tail) = l; + } + return TRUE; + } + break; + + case lang_data_statement_enum: + case lang_reloc_statement_enum: + case lang_object_symbols_statement_enum: + case lang_output_statement_enum: + case lang_target_statement_enum: + case lang_input_statement_enum: + case lang_assignment_statement_enum: + case lang_padding_statement_enum: + case lang_address_statement_enum: + case lang_fill_statement_enum: + break; + + default: + FAIL (); + break; + } + } + return FALSE; +} + +/* Call-back for elf32_nios2_size_stubs. */ + +/* Create a new stub section, and arrange for it to be linked + immediately before or after INPUT_SECTION, according to AFTERP. */ + +static asection * +nios2elf_add_stub_section (const char *stub_sec_name, asection *input_section, + bfd_boolean afterp) +{ + asection *stub_sec; + flagword flags; + asection *output_section; + const char *secname; + lang_output_section_statement_type *os; + struct hook_stub_info info; + + flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE + | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP); + stub_sec = bfd_make_section_anyway_with_flags (stub_file->the_bfd, + stub_sec_name, flags); + if (stub_sec == NULL) + goto err_ret; + + output_section = input_section->output_section; + secname = bfd_get_section_name (output_section->owner, output_section); + os = lang_output_section_find (secname); + + info.input_section = input_section; + lang_list_init (&info.add); + lang_add_section (&info.add, stub_sec, NULL, os); + + if (info.add.head == NULL) + goto err_ret; + + if (hook_in_stub (&info, &os->children.head, afterp)) + return stub_sec; + + err_ret: + einfo ("%X%P: can not make stub section: %E\n"); + return NULL; +} + + +/* Another call-back for elf32_nios2_size_stubs. */ + +static void +nios2elf_layout_sections_again (void) +{ + /* If we have changed sizes of the stub sections, then we need + to recalculate all the section offsets. This may mean we need to + add even more stubs. */ + gld${EMULATION_NAME}_map_segments (TRUE); + need_laying_out = -1; +} + + +static void +build_section_lists (lang_statement_union_type *statement) +{ + if (statement->header.type == lang_input_section_enum) + { + asection *i = statement->input_section.section; + + if (i->sec_info_type != SEC_INFO_TYPE_JUST_SYMS + && (i->flags & SEC_EXCLUDE) == 0 + && i->output_section != NULL + && i->output_section->owner == link_info.output_bfd) + { + nios2_elf32_next_input_section (&link_info, i); + } + } +} + + +/* For Nios II we use this opportunity to build linker stubs. */ + +static void +gld${EMULATION_NAME}_after_allocation (void) +{ + int ret; + + /* bfd_elf_discard_info just plays with data and debugging sections, + ie. doesn't affect code size, so we can delay resizing the + sections. It's likely we'll resize everything in the process of + adding stubs. */ + ret = bfd_elf_discard_info (link_info.output_bfd, &link_info); + if (ret < 0) + { + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + return; + } + else if (ret > 0) + need_laying_out = 1; + + /* If generating a relocatable output file, then we don't + have to examine the relocs. */ + if (stub_file != NULL && !link_info.relocatable && RELAXATION_ENABLED) + { + ret = nios2_elf32_setup_section_lists (link_info.output_bfd, &link_info); + if (ret != 0) + { + if (ret < 0) + { + einfo ("%X%P: can not size stub section: %E\n"); + return; + } + + lang_for_each_statement (build_section_lists); + + /* Call into the BFD backend to do the real work. */ + if (! nios2_elf32_size_stubs (link_info.output_bfd, + stub_file->the_bfd, + &link_info, + &nios2elf_add_stub_section, + &nios2elf_layout_sections_again)) + { + einfo ("%X%P: can not size stub section: %E\n"); + return; + } + } + } + + if (need_laying_out != -1) + gld${EMULATION_NAME}_map_segments (need_laying_out); + + if (!link_info.relocatable && RELAXATION_ENABLED) + { + /* Now build the linker stubs. */ + if (stub_file != NULL && stub_file->the_bfd->sections != NULL) + { + if (! nios2_elf32_build_stubs (&link_info)) + einfo ("%X%P: can not build stubs: %E\n"); + } + } +} + + +/* Avoid processing the fake stub_file in vercheck, stat_needed and + check_needed routines. */ + +static void (*real_func) (lang_input_statement_type *); + +static void nios2_for_each_input_file_wrapper (lang_input_statement_type *l) +{ + if (l != stub_file) + (*real_func) (l); +} + +static void +nios2_lang_for_each_input_file (void (*func) (lang_input_statement_type *)) +{ + real_func = func; + lang_for_each_input_file (&nios2_for_each_input_file_wrapper); +} + +#define lang_for_each_input_file nios2_lang_for_each_input_file + +EOF + + +# Put these extra nios2elf routines in ld_${EMULATION_NAME}_emulation +# +LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation +LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=nios2elf_create_output_section_statements diff --git a/binutils-2.25/ld/emultempl/pe.em b/binutils-2.25/ld/emultempl/pe.em index 4df7753..979cc8b 100644 --- a/binutils-2.25/ld/emultempl/pe.em +++ b/binutils-2.25/ld/emultempl/pe.em @@ -8,7 +8,7 @@ fi rm -f e${EMULATION_NAME}.c (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-) fragment <<EOF -/* Copyright 1995-2013 Free Software Foundation, Inc. +/* Copyright (C) 1995-2014 Free Software Foundation, Inc. This file is part of the GNU Binutils. @@ -66,6 +66,7 @@ fragment <<EOF #include "ldlex.h" #include "ldmisc.h" #include "ldctor.h" +#include "ldbuildid.h" #include "coff/internal.h" /* FIXME: See bfd/peXXigen.c for why we include an architecture specific @@ -73,9 +74,10 @@ fragment <<EOF #include "coff/i386.h" #include "coff/pe.h" -/* FIXME: This is a BFD internal header file, and we should not be +/* FIXME: These are BFD internal header files, and we should not be using it here. */ #include "../bfd/libcoff.h" +#include "../bfd/libpei.h" #include "deffile.h" #include "pe-dll.h" @@ -130,12 +132,15 @@ static int support_old_code = 0; static char * thumb_entry_symbol = NULL; static lang_assignment_statement_type *image_base_statement = 0; static unsigned short pe_dll_characteristics = 0; +static bfd_boolean insert_timestamp = TRUE; +static const char *emit_build_id; #ifdef DLL_SUPPORT static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable. */ static char *pe_out_def_filename = NULL; static char *pe_implib_filename = NULL; static int pe_enable_auto_image_base = 0; +static unsigned long pe_auto_image_base = 0x61500000; static char *pe_dll_search_prefix = NULL; #endif @@ -239,8 +244,7 @@ fragment <<EOF (OPTION_EXCLUDE_LIBS + 1) #define OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC \ (OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC + 1) -#define OPTION_LARGE_ADDRESS_AWARE \ - (OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC + 1) +#define OPTION_LARGE_ADDRESS_AWARE (OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC + 1) #define OPTION_DISABLE_LARGE_ADDRESS_AWARE \ (OPTION_LARGE_ADDRESS_AWARE + 1) #define OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1 \ @@ -251,15 +255,13 @@ fragment <<EOF (OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2 + 1) #define OPTION_USE_NUL_PREFIXED_IMPORT_TABLES \ (OPTION_EXCLUDE_MODULES_FOR_IMPLIB + 1) -#define OPTION_NO_LEADING_UNDERSCORE \ - (OPTION_USE_NUL_PREFIXED_IMPORT_TABLES + 1) -#define OPTION_LEADING_UNDERSCORE \ - (OPTION_NO_LEADING_UNDERSCORE + 1) +#define OPTION_NO_LEADING_UNDERSCORE (OPTION_USE_NUL_PREFIXED_IMPORT_TABLES + 1) +#define OPTION_LEADING_UNDERSCORE (OPTION_NO_LEADING_UNDERSCORE + 1) #define OPTION_ENABLE_LONG_SECTION_NAMES \ (OPTION_LEADING_UNDERSCORE + 1) #define OPTION_DISABLE_LONG_SECTION_NAMES \ (OPTION_ENABLE_LONG_SECTION_NAMES + 1) -/* DLLCharacteristics flags */ +/* DLLCharacteristics flags. */ #define OPTION_DYNAMIC_BASE (OPTION_DISABLE_LONG_SECTION_NAMES + 1) #define OPTION_FORCE_INTEGRITY (OPTION_DYNAMIC_BASE + 1) #define OPTION_NX_COMPAT (OPTION_FORCE_INTEGRITY + 1) @@ -268,6 +270,10 @@ fragment <<EOF #define OPTION_NO_BIND (OPTION_NO_SEH + 1) #define OPTION_WDM_DRIVER (OPTION_NO_BIND + 1) #define OPTION_TERMINAL_SERVER_AWARE (OPTION_WDM_DRIVER + 1) +/* Determinism. */ +#define OPTION_INSERT_TIMESTAMP (OPTION_TERMINAL_SERVER_AWARE + 1) +#define OPTION_NO_INSERT_TIMESTAMP (OPTION_INSERT_TIMESTAMP + 1) +#define OPTION_BUILD_ID (OPTION_NO_INSERT_TIMESTAMP + 1) static void gld${EMULATION_NAME}_add_options @@ -301,6 +307,8 @@ gld${EMULATION_NAME}_add_options OPTION_USE_NUL_PREFIXED_IMPORT_TABLES}, {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE}, {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE}, + {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP}, + {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP}, #ifdef DLL_SUPPORT /* getopt allows abbreviations, so we do this to stop it from treating -o as an abbreviation for this option. */ @@ -321,7 +329,7 @@ gld${EMULATION_NAME}_add_options treating -c as an abbreviation for these --compat-implib. */ {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT}, {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT}, - {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE}, + {"enable-auto-image-base", optional_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE}, {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE}, {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX}, {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES}, @@ -345,6 +353,7 @@ gld${EMULATION_NAME}_add_options {"no-bind", no_argument, NULL, OPTION_NO_BIND}, {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER}, {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE}, + {"build-id", optional_argument, NULL, OPTION_BUILD_ID}, {NULL, no_argument, NULL, 0} }; @@ -384,7 +393,7 @@ typedef struct #define U_SIZE(CSTR) \ (sizeof (CSTR) + (is_underscoring () == 0 ? 0 : 1)) -#define D(field,symbol,def,usc) {&pe.field,sizeof(pe.field), def, symbol, 0, usc} +#define D(field,symbol,def,usc) {&pe.field, sizeof (pe.field), def, symbol, 0, usc} static definfo init[] = { @@ -438,6 +447,8 @@ gld_${EMULATION_NAME}_list_options (FILE *file) fprintf (file, _(" --support-old-code Support interworking with old code\n")); fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n")); fprintf (file, _(" --thumb-entry=<symbol> Set the entry point to be Thumb <symbol>\n")); + fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero (default).\n")); + fprintf (file, _(" This makes binaries non-deterministic\n")); #ifdef DLL_SUPPORT fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n")); fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n")); @@ -452,11 +463,12 @@ gld_${EMULATION_NAME}_list_options (FILE *file) fprintf (file, _(" --kill-at Remove @nn from exported symbols\n")); fprintf (file, _(" --out-implib <file> Generate import library\n")); fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n")); - fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n")); + fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports\n")); fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\ create __imp_<SYMBOL> as well.\n")); - fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\ - unless user specifies one\n")); + fprintf (file, _(" --enable-auto-image-base[=<address>] Automatically choose image base for DLLs\n\ + (optionally starting with address) unless\n\ + specifically set with --image-base\n")); fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n")); fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\ an importlib, use <string><basename>.dll\n\ @@ -490,6 +502,7 @@ gld_${EMULATION_NAME}_list_options (FILE *file) fprintf (file, _(" --no-bind Do not bind this image\n")); fprintf (file, _(" --wdmdriver Driver uses the WDM model\n")); fprintf (file, _(" --tsaware Image is Terminal Server aware\n")); + fprintf (file, _(" --build-id[=STYLE] Generate build ID\n")); } @@ -684,6 +697,7 @@ set_pe_stack_heap (char *resname, char *comname) einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg); } +#define DEFAULT_BUILD_ID_STYLE "md5" static bfd_boolean gld${EMULATION_NAME}_handle_option (int optc) @@ -754,6 +768,12 @@ gld${EMULATION_NAME}_handle_option (int optc) case OPTION_LEADING_UNDERSCORE: pe_leading_underscore = 1; break; + case OPTION_INSERT_TIMESTAMP: + insert_timestamp = TRUE; + break; + case OPTION_NO_INSERT_TIMESTAMP: + insert_timestamp = FALSE; + break; #ifdef DLL_SUPPORT case OPTION_OUT_DEF: pe_out_def_filename = xstrdup (optarg); @@ -796,6 +816,12 @@ gld${EMULATION_NAME}_handle_option (int optc) break; case OPTION_ENABLE_AUTO_IMAGE_BASE: pe_enable_auto_image_base = 1; + if (optarg && *optarg) + { + char *end; + pe_auto_image_base = strtoul (optarg, &end, 0); + /* XXX should check that we actually parsed something */ + } break; case OPTION_DISABLE_AUTO_IMAGE_BASE: pe_enable_auto_image_base = 0; @@ -866,6 +892,17 @@ gld${EMULATION_NAME}_handle_option (int optc) case OPTION_TERMINAL_SERVER_AWARE: pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE; break; + case OPTION_BUILD_ID: + if (emit_build_id != NULL) + { + free ((char *) emit_build_id); + emit_build_id = NULL; + } + if (optarg == NULL) + optarg = DEFAULT_BUILD_ID_STYLE; + if (strcmp (optarg, "none")) + emit_build_id = xstrdup (optarg); + break; } /* Set DLLCharacteristics bits */ @@ -905,7 +942,7 @@ static unsigned long compute_dll_image_base (const char *ofile) { unsigned long hash = strhash (ofile); - return 0x61300000 + ((hash << 16) & 0x0FFC0000); + return pe_auto_image_base + ((hash << 16) & 0x0FFC0000); } #endif @@ -1221,6 +1258,169 @@ debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj) *found = 1; } +static bfd_boolean +pecoff_checksum_contents (bfd *abfd, + void (*process) (const void *, size_t, void *), + void *arg) +{ + file_ptr filepos = (file_ptr) 0; + + while (1) + { + unsigned char b; + int status; + + if (bfd_seek (abfd, filepos, SEEK_SET) != 0) + return 0; + + status = bfd_bread (&b, (bfd_size_type) 1, abfd); + if (status < 1) + { + break; + } + + (*process) (&b, 1, arg); + filepos += 1; + } + + return TRUE; +} + +static bfd_boolean +write_build_id (bfd *abfd) +{ + struct pe_tdata *t = pe_data (abfd); + asection *asec; + struct bfd_link_order *link_order = NULL; + unsigned char *contents; + bfd_size_type size; + bfd_size_type build_id_size; + unsigned char *build_id; + + /* Find the section the .buildid output section has been merged info. */ + for (asec = abfd->sections; asec != NULL; asec = asec->next) + { + struct bfd_link_order *l = NULL; + for (l = asec->map_head.link_order; l != NULL; l = l->next) + { + if ((l->type == bfd_indirect_link_order)) + { + if (l->u.indirect.section == t->build_id.sec) + { + link_order = l; + break; + } + } + } + + if (link_order) + break; + } + + if (!link_order) + { + einfo (_("%P: warning: .buildid section discarded," + " --build-id ignored.\n")); + return TRUE; + } + + if (t->build_id.sec->contents == NULL) + t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size); + contents = t->build_id.sec->contents; + size = t->build_id.sec->size; + + build_id_size = compute_build_id_size (t->build_id.style); + build_id = xmalloc (build_id_size); + generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size); + + bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase; + + /* Construct a debug directory entry which points to an immediately following CodeView record. */ + struct internal_IMAGE_DEBUG_DIRECTORY idd; + idd.Characteristics = 0; + idd.TimeDateStamp = 0; + idd.MajorVersion = 0; + idd.MinorVersion = 0; + idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW; + idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1; + idd.AddressOfRawData = asec->vma - ib + link_order->offset + + sizeof (struct external_IMAGE_DEBUG_DIRECTORY); + idd.PointerToRawData = asec->filepos + link_order->offset + + sizeof (struct external_IMAGE_DEBUG_DIRECTORY); + + struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents; + _bfd_XXi_swap_debugdir_out (abfd, &idd, ext); + + /* Write the debug directory entry. */ + if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0) + return 0; + + if ((bfd_bwrite (contents, size, abfd) != size)) + return 0; + + /* Construct the CodeView record. */ + CODEVIEW_INFO cvinfo; + cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE; + cvinfo.Age = 1; + + /* Zero pad or truncate the generated build_id to fit in the CodeView record. */ + memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH); + memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH) + ? CV_INFO_SIGNATURE_LENGTH : build_id_size); + + free (build_id); + + /* Write the codeview record. */ + if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo) == 0) + return 0; + + /* Record the location of the debug directory in the data directory. */ + pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress + = asec->vma - ib + link_order->offset; + pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size + = sizeof (struct external_IMAGE_DEBUG_DIRECTORY); + + return TRUE; +} + +/* Make .buildid section, and set up coff_tdata->build_id. */ +static bfd_boolean +setup_build_id (bfd *ibfd) +{ + asection *s; + flagword flags; + + if (!validate_build_id_style (emit_build_id)) + { + einfo ("%P: warning: unrecognized --build-id style ignored.\n"); + return FALSE; + } + + flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY + | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA); + s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags); + if (s != NULL) + { + struct pe_tdata *t = pe_data (link_info.output_bfd); + t->build_id.after_write_object_contents = &write_build_id; + t->build_id.style = emit_build_id; + t->build_id.sec = s; + + /* Section is a fixed size: + One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW, + pointing at a CV_INFO_PDB70 record containing the build-id, with a + null byte for PdbFileName. */ + s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY) + + sizeof (CV_INFO_PDB70) + 1; + + return TRUE; + } + + einfo ("%P: warning: Cannot create .buildid section," + " --build-id ignored.\n"); + return FALSE; +} + static void gld_${EMULATION_NAME}_after_open (void) { @@ -1238,11 +1438,31 @@ gld_${EMULATION_NAME}_after_open (void) printf ("-%s\n", sym->root.string); bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL); - for (a = link_info.input_bfds; a; a = a->link_next) + for (a = link_info.input_bfds; a; a = a->link.next) printf ("*%s\n",a->filename); } #endif + if (emit_build_id != NULL) + { + bfd *abfd; + + /* Find a COFF input. */ + for (abfd = link_info.input_bfds; + abfd != (bfd *) NULL; abfd = abfd->link.next) + if (bfd_get_flavour (abfd) == bfd_target_coff_flavour) + break; + + /* If there are no COFF input files do not try to + add a build-id section. */ + if (abfd == NULL + || !setup_build_id (abfd)) + { + free ((char *) emit_build_id); + emit_build_id = NULL; + } + } + /* Pass the wacky PE command line options into the output bfd. FIXME: This should be done via a function, rather than by including an internal BFD header. */ @@ -1255,6 +1475,7 @@ gld_${EMULATION_NAME}_after_open (void) pe_data (link_info.output_bfd)->pe_opthdr = pe; pe_data (link_info.output_bfd)->dll = init[DLLOFF].value; pe_data (link_info.output_bfd)->real_flags |= real_flags; + pe_data (link_info.output_bfd)->insert_timestamp = insert_timestamp; /* At this point we must decide whether to use long section names in the output or not. If the user hasn't explicitly specified @@ -1264,17 +1485,23 @@ gld_${EMULATION_NAME}_after_open (void) find it, so enable it in that case. */ if (pe_use_coff_long_section_names < 0 && link_info.strip == strip_none) { - /* Iterate over all sections of all input BFDs, checking - for any that begin 'debug_' and are long names. */ - LANG_FOR_EACH_INPUT_STATEMENT (is) + if (link_info.relocatable) + pe_use_coff_long_section_names = 1; + else { - int found_debug = 0; - bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug); - if (found_debug) - { - pe_use_coff_long_section_names = 1; - break; - } + /* Iterate over all sections of all input BFDs, checking + for any that begin 'debug_' and are long names. */ + LANG_FOR_EACH_INPUT_STATEMENT (is) + { + int found_debug = 0; + + bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug); + if (found_debug) + { + pe_use_coff_long_section_names = 1; + break; + } + } } } @@ -2101,7 +2328,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive unsigned int i; - if (! entry->flags.maybe_archive) + if (! entry->flags.maybe_archive || entry->flags.full_name_provided) return FALSE; filename = entry->filename; @@ -2227,6 +2454,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = gld_${EMULATION_NAME}_list_options, gld_${EMULATION_NAME}_recognized_file, gld_${EMULATION_NAME}_find_potential_libraries, - NULL /* new_vers_pattern. */ + NULL, /* new_vers_pattern. */ + NULL /* extra_map_file_text. */ }; EOF diff --git a/binutils-2.25/ld/emultempl/pep.em b/binutils-2.25/ld/emultempl/pep.em index 3e8b65e..b24a608 100644 --- a/binutils-2.25/ld/emultempl/pep.em +++ b/binutils-2.25/ld/emultempl/pep.em @@ -18,8 +18,7 @@ esac rm -f e${EMULATION_NAME}.c (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-) fragment <<EOF -/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 - Free Software Foundation, Inc. +/* Copyright (C) 2006-2014 Free Software Foundation, Inc. Written by Kai Tietz, OneVision Software GmbH&CoKg. This file is part of the GNU Binutils. @@ -65,6 +64,7 @@ fragment <<EOF #include "ldlex.h" #include "ldmisc.h" #include "ldctor.h" +#include "ldbuildid.h" #include "coff/internal.h" /* FIXME: See bfd/peXXigen.c for why we include an architecture specific @@ -72,9 +72,10 @@ fragment <<EOF #include "coff/x86_64.h" #include "coff/pe.h" -/* FIXME: This is a BFD internal header file, and we should not be +/* FIXME: These are BFD internal header files, and we should not be using it here. */ #include "../bfd/libcoff.h" +#include "../bfd/libpei.h" #undef AOUTSZ #define AOUTSZ PEPAOUTSZ @@ -146,6 +147,8 @@ static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE; static int support_old_code = 0; static lang_assignment_statement_type *image_base_statement = 0; static unsigned short pe_dll_characteristics = 0; +static bfd_boolean insert_timestamp = TRUE; +static const char *emit_build_id; #ifdef DLL_SUPPORT static int pep_enable_stdcall_fixup = 1; /* 0=disable 1=enable (default). */ @@ -234,6 +237,7 @@ enum options OPTION_LEADING_UNDERSCORE, OPTION_ENABLE_LONG_SECTION_NAMES, OPTION_DISABLE_LONG_SECTION_NAMES, + OPTION_HIGH_ENTROPY_VA, OPTION_DYNAMIC_BASE, OPTION_FORCE_INTEGRITY, OPTION_NX_COMPAT, @@ -241,7 +245,10 @@ enum options OPTION_NO_SEH, OPTION_NO_BIND, OPTION_WDM_DRIVER, - OPTION_TERMINAL_SERVER_AWARE + OPTION_INSERT_TIMESTAMP, + OPTION_NO_INSERT_TIMESTAMP, + OPTION_TERMINAL_SERVER_AWARE, + OPTION_BUILD_ID }; static void @@ -308,6 +315,7 @@ gld${EMULATION_NAME}_add_options #endif {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES}, {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES}, + {"high-entropy-va", no_argument, NULL, OPTION_HIGH_ENTROPY_VA}, {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE}, {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY}, {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT}, @@ -316,6 +324,9 @@ gld${EMULATION_NAME}_add_options {"no-bind", no_argument, NULL, OPTION_NO_BIND}, {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER}, {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE}, + {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP}, + {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP}, + {"build-id", optional_argument, NULL, OPTION_BUILD_ID}, {NULL, no_argument, NULL, 0} }; @@ -353,7 +364,7 @@ typedef struct #define U_SIZE(CSTR) \ (sizeof (CSTR) + (is_underscoring () == 0 ? 0 : 1)) -#define D(field,symbol,def,usc) {&pep.field,sizeof(pep.field), def, symbol,0, usc} +#define D(field,symbol,def,usc) {&pep.field, sizeof (pep.field), def, symbol, 0, usc} static definfo init[] = { @@ -402,6 +413,8 @@ gld_${EMULATION_NAME}_list_options (FILE *file) fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n")); fprintf (file, _(" --support-old-code Support interworking with old code\n")); fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n")); + fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero. (default)\n")); + fprintf (file, _(" This makes binaries non-deterministic\n")); #ifdef DLL_SUPPORT fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n")); fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n")); @@ -439,6 +452,8 @@ gld_${EMULATION_NAME}_list_options (FILE *file) executable image files\n")); fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\ in object files\n")); + fprintf (file, _(" --high-entropy-va Image is compatible with 64-bit address space\n\ + layout randomization (ASLR)\n")); fprintf (file, _(" --dynamicbase Image base address may be relocated using\n\ address space layout randomization (ASLR)\n")); fprintf (file, _(" --forceinteg Code integrity checks are enforced\n")); @@ -449,6 +464,7 @@ gld_${EMULATION_NAME}_list_options (FILE *file) fprintf (file, _(" --no-bind Do not bind this image\n")); fprintf (file, _(" --wdmdriver Driver uses the WDM model\n")); fprintf (file, _(" --tsaware Image is Terminal Server aware\n")); + fprintf (file, _(" --build-id[=STYLE] Generate build ID\n")); #endif } @@ -639,6 +655,7 @@ set_pep_stack_heap (char *resname, char *comname) einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg); } +#define DEFAULT_BUILD_ID_STYLE "md5" static bfd_boolean gld${EMULATION_NAME}_handle_option (int optc) @@ -707,6 +724,12 @@ gld${EMULATION_NAME}_handle_option (int optc) case OPTION_LEADING_UNDERSCORE: pep_leading_underscore = 1; break; + case OPTION_INSERT_TIMESTAMP: + insert_timestamp = TRUE; + break; + case OPTION_NO_INSERT_TIMESTAMP: + insert_timestamp = FALSE; + break; #ifdef DLL_SUPPORT case OPTION_OUT_DEF: pep_out_def_filename = xstrdup (optarg); @@ -785,6 +808,9 @@ gld${EMULATION_NAME}_handle_option (int optc) pep_use_coff_long_section_names = 0; break; /* Get DLLCharacteristics bits */ + case OPTION_HIGH_ENTROPY_VA: + pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA; + break; case OPTION_DYNAMIC_BASE: pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE; break; @@ -809,6 +835,17 @@ gld${EMULATION_NAME}_handle_option (int optc) case OPTION_TERMINAL_SERVER_AWARE: pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE; break; + case OPTION_BUILD_ID: + if (emit_build_id != NULL) + { + free ((char *) emit_build_id); + emit_build_id = NULL; + } + if (optarg == NULL) + optarg = DEFAULT_BUILD_ID_STYLE; + if (strcmp (optarg, "none")) + emit_build_id = xstrdup (optarg); + break; } /* Set DLLCharacteristics bits */ @@ -1180,10 +1217,174 @@ static void debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj) { int *found = (int *) obj; + if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0) *found = 1; } +static bfd_boolean +pecoff_checksum_contents (bfd *abfd, + void (*process) (const void *, size_t, void *), + void *arg) +{ + file_ptr filepos = (file_ptr) 0; + + while (1) + { + unsigned char b; + int status; + + if (bfd_seek (abfd, filepos, SEEK_SET) != 0) + return 0; + + status = bfd_bread (&b, (bfd_size_type) 1, abfd); + if (status < 1) + { + break; + } + + (*process) (&b, 1, arg); + filepos += 1; + } + + return TRUE; +} + +static bfd_boolean +write_build_id (bfd *abfd) +{ + struct pe_tdata *t = pe_data (abfd); + asection *asec; + struct bfd_link_order *link_order = NULL; + unsigned char *contents; + bfd_size_type size; + bfd_size_type build_id_size; + unsigned char *build_id; + + /* Find the section the .buildid output section has been merged info. */ + for (asec = abfd->sections; asec != NULL; asec = asec->next) + { + struct bfd_link_order *l = NULL; + for (l = asec->map_head.link_order; l != NULL; l = l->next) + { + if ((l->type == bfd_indirect_link_order)) + { + if (l->u.indirect.section == t->build_id.sec) + { + link_order = l; + break; + } + } + } + + if (link_order) + break; + } + + if (!link_order) + { + einfo (_("%P: warning: .buildid section discarded," + " --build-id ignored.\n")); + return TRUE; + } + + if (t->build_id.sec->contents == NULL) + t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size); + contents = t->build_id.sec->contents; + size = t->build_id.sec->size; + + build_id_size = compute_build_id_size (t->build_id.style); + build_id = xmalloc (build_id_size); + generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size); + + bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase; + + /* Construct a debug directory entry which points to an immediately following CodeView record. */ + struct internal_IMAGE_DEBUG_DIRECTORY idd; + idd.Characteristics = 0; + idd.TimeDateStamp = 0; + idd.MajorVersion = 0; + idd.MinorVersion = 0; + idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW; + idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1; + idd.AddressOfRawData = asec->vma - ib + link_order->offset + + sizeof (struct external_IMAGE_DEBUG_DIRECTORY); + idd.PointerToRawData = asec->filepos + link_order->offset + + sizeof (struct external_IMAGE_DEBUG_DIRECTORY); + + struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents; + _bfd_XXi_swap_debugdir_out (abfd, &idd, ext); + + /* Write the debug directory enttry */ + if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0) + return 0; + + if ((bfd_bwrite (contents, size, abfd) != size)) + return 0; + + /* Construct the CodeView record. */ + CODEVIEW_INFO cvinfo; + cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE; + cvinfo.Age = 1; + + /* Zero pad or truncate the generated build_id to fit in the CodeView record. */ + memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH); + memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH) + ? CV_INFO_SIGNATURE_LENGTH : build_id_size); + + free (build_id); + + /* Write the codeview record. */ + if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo) == 0) + return 0; + + /* Record the location of the debug directory in the data directory. */ + pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress + = asec->vma - ib + link_order->offset; + pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size + = sizeof (struct external_IMAGE_DEBUG_DIRECTORY); + + return TRUE; +} + +/* Make .buildid section, and set up coff_tdata->build_id. */ +static bfd_boolean +setup_build_id (bfd *ibfd) +{ + asection *s; + flagword flags; + + if (!validate_build_id_style (emit_build_id)) + { + einfo ("%P: warning: unrecognized --build-id style ignored.\n"); + return FALSE; + } + + flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY + | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA); + s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags); + if (s != NULL) + { + struct pe_tdata *t = pe_data (link_info.output_bfd); + t->build_id.after_write_object_contents = &write_build_id; + t->build_id.style = emit_build_id; + t->build_id.sec = s; + + /* Section is a fixed size: + One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW, + pointing at a CV_INFO_PDB70 record containing the build-id, with a + null byte for PdbFileName. */ + s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY) + + sizeof (CV_INFO_PDB70) + 1; + + return TRUE; + } + + einfo ("%P: warning: Cannot create .buildid section," + " --build-id ignored.\n"); + return FALSE; +} + static void gld_${EMULATION_NAME}_after_open (void) { @@ -1202,11 +1403,31 @@ gld_${EMULATION_NAME}_after_open (void) printf ("-%s\n", sym->root.string); bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL); - for (a = link_info.input_bfds; a; a = a->link_next) + for (a = link_info.input_bfds; a; a = a->link.next) printf ("*%s\n",a->filename); } #endif + if (emit_build_id != NULL) + { + bfd *abfd; + + /* Find a COFF input. */ + for (abfd = link_info.input_bfds; + abfd != (bfd *) NULL; abfd = abfd->link.next) + if (bfd_get_flavour (abfd) == bfd_target_coff_flavour) + break; + + /* If there are no COFF input files do not try to + add a build-id section. */ + if (abfd == NULL + || !setup_build_id (abfd)) + { + free ((char *) emit_build_id); + emit_build_id = NULL; + } + } + /* Pass the wacky PE command line options into the output bfd. FIXME: This should be done via a function, rather than by including an internal BFD header. */ @@ -1219,6 +1440,7 @@ gld_${EMULATION_NAME}_after_open (void) pe_data (link_info.output_bfd)->pe_opthdr = pep; pe_data (link_info.output_bfd)->dll = init[DLLOFF].value; pe_data (link_info.output_bfd)->real_flags |= real_flags; + pe_data (link_info.output_bfd)->insert_timestamp = insert_timestamp; /* At this point we must decide whether to use long section names in the output or not. If the user hasn't explicitly specified @@ -1228,17 +1450,23 @@ gld_${EMULATION_NAME}_after_open (void) find it, so enable it in that case. */ if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none) { - /* Iterate over all sections of all input BFDs, checking - for any that begin 'debug_' and are long names. */ - LANG_FOR_EACH_INPUT_STATEMENT (is) + if (link_info.relocatable) + pep_use_coff_long_section_names = 1; + else { - int found_debug = 0; - bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug); - if (found_debug) - { - pep_use_coff_long_section_names = 1; - break; - } + /* Iterate over all sections of all input BFDs, checking + for any that begin 'debug_' and are long names. */ + LANG_FOR_EACH_INPUT_STATEMENT (is) + { + int found_debug = 0; + + bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug); + if (found_debug) + { + pep_use_coff_long_section_names = 1; + break; + } + } } } @@ -1871,7 +2099,7 @@ gld_${EMULATION_NAME}_open_dynamic_archive unsigned int i; - if (! entry->flags.maybe_archive) + if (! entry->flags.maybe_archive || entry->flags.full_name_provided) return FALSE; filename = entry->filename; @@ -1997,6 +2225,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = gld_${EMULATION_NAME}_list_options, gld_${EMULATION_NAME}_recognized_file, gld_${EMULATION_NAME}_find_potential_libraries, - NULL /* new_vers_pattern. */ + NULL, /* new_vers_pattern. */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/ppc32elf.em b/binutils-2.25/ld/emultempl/ppc32elf.em index 6843770..0e2af12 100644 --- a/binutils-2.25/ld/emultempl/ppc32elf.em +++ b/binutils-2.25/ld/emultempl/ppc32elf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2003, 2005, 2007, 2008, 2009, 2010, 2011, 2012 -# Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -28,6 +27,7 @@ fragment <<EOF #include "libbfd.h" #include "elf32-ppc.h" #include "ldlex.h" +#include "ldlang.h" #define is_ppc_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ @@ -35,15 +35,30 @@ fragment <<EOF /* Whether to run tls optimization. */ static int notlsopt = 0; -static int no_tls_get_addr_opt = 0; -/* Whether to emit symbols for stubs. */ -static int emit_stub_syms = -1; - -/* Chooses the correct place for .plt and .got. */ -static enum ppc_elf_plt_type plt_style = PLT_UNSET; +/* Choose the correct place for .got. */ static int old_got = 0; +static bfd_vma pagesize = 0; + +static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0 }; + +static void +ppc_after_open_output (void) +{ + if (params.emit_stub_syms < 0) + params.emit_stub_syms = link_info.emitrelocations || link_info.shared; + if (pagesize == 0) + pagesize = config.commonpagesize; + params.pagesize_p2 = bfd_log2 (pagesize); + ppc_elf_link_params (&link_info, ¶ms); +} + +EOF + +# No --secure-plt, --bss-plt, or --sdata-got for vxworks. +if test -z "$VXWORKS_BASE_EM_FILE" ; then + fragment <<EOF static void ppc_after_open (void) { @@ -57,10 +72,7 @@ ppc_after_open (void) lang_output_section_statement_type *plt_os[2]; lang_output_section_statement_type *got_os[2]; - if (emit_stub_syms < 0) - emit_stub_syms = link_info.emitrelocations || link_info.shared; - new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info, - plt_style, emit_stub_syms); + new_plt = ppc_elf_select_plt_layout (link_info.output_bfd, &link_info); if (new_plt < 0) einfo ("%X%P: select_plt_layout problem %E\n"); @@ -102,13 +114,15 @@ ppc_after_open (void) gld${EMULATION_NAME}_after_open (); } +EOF +fi +fragment <<EOF static void ppc_before_allocation (void) { if (is_ppc_elf (link_info.output_bfd)) { - if (ppc_elf_tls_setup (link_info.output_bfd, &link_info, - no_tls_get_addr_opt) + if (ppc_elf_tls_setup (link_info.output_bfd, &link_info) && !notlsopt) { if (!ppc_elf_tls_optimize (link_info.output_bfd, &link_info)) @@ -121,9 +135,14 @@ ppc_before_allocation (void) gld${EMULATION_NAME}_before_allocation (); + ppc_elf_maybe_strip_sdata_syms (&link_info); + + if (RELAXATION_ENABLED) + params.branch_trampolines = 1; + /* Turn on relaxation if executable sections have addresses that might make branches overflow. */ - if (RELAXATION_DISABLED_BY_DEFAULT) + else if (!RELAXATION_DISABLED_BY_USER) { bfd_vma low = (bfd_vma) -1; bfd_vma high = 0; @@ -150,8 +169,50 @@ ppc_before_allocation (void) high = o->vma + o->rawsize - 1; } if (high > low && high - low > (1 << 25) - 1) - ENABLE_RELAXATION; + params.branch_trampolines = 1; } + + if (params.ppc476_workaround || params.branch_trampolines) + ENABLE_RELAXATION; +} + +/* Replaces default zero fill padding in executable sections with + "ba 0" instructions. This works around the ppc476 icache bug if we + have a function pointer tail call near the end of a page, some + small amount of padding, then the function called at the beginning + of the next page. If the "ba 0" is ever executed we should hit a + segv, so it's almost as good as an illegal instruction (zero). */ + +static void +no_zero_padding (lang_statement_union_type *l) +{ + if (l->header.type == lang_padding_statement_enum + && l->padding_statement.size != 0 + && l->padding_statement.output_section != NULL + && (l->padding_statement.output_section->flags & SEC_CODE) != 0 + && l->padding_statement.fill->size == 0) + { + struct _ppc_fill_type + { + size_t size; + unsigned char data[4]; + }; + static struct _ppc_fill_type fill_be = { 4, {0x48, 0, 0, 2} }; + static struct _ppc_fill_type fill_le = { 4, {2, 0, 0, 0x48} }; + + if (bfd_big_endian (link_info.output_bfd)) + l->padding_statement.fill = (struct _fill_type *) &fill_be; + else + l->padding_statement.fill = (struct _fill_type *) &fill_le; + } +} + +static void +ppc_finish (void) +{ + if (params.ppc476_workaround) + lang_for_each_statement (no_zero_padding); + finish_default (); } EOF @@ -186,16 +247,24 @@ PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}' #define OPTION_OLD_GOT (OPTION_OLD_PLT + 1) #define OPTION_STUBSYMS (OPTION_OLD_GOT + 1) #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1) +#define OPTION_PPC476_WORKAROUND (OPTION_NO_STUBSYMS + 1) +#define OPTION_NO_PPC476_WORKAROUND (OPTION_PPC476_WORKAROUND + 1) ' PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS }, { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS }, { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT }, - { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT }, + { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },' +if test -z "$VXWORKS_BASE_EM_FILE" ; then + PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' { "secure-plt", no_argument, NULL, OPTION_NEW_PLT }, { "bss-plt", no_argument, NULL, OPTION_OLD_PLT }, - { "sdata-got", no_argument, NULL, OPTION_OLD_GOT }, + { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },' +fi +PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' + { "ppc476-workaround", optional_argument, NULL, OPTION_PPC476_WORKAROUND }, + { "no-ppc476-workaround", no_argument, NULL, OPTION_NO_PPC476_WORKAROUND }, ' PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}' @@ -203,20 +272,27 @@ PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}' --emit-stub-syms Label linker stubs with a symbol.\n\ --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\ --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\ - --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n\ + --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n' +if test -z "$VXWORKS_BASE_EM_FILE" ; then + PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\ --secure-plt Use new-style PLT if possible.\n\ --bss-plt Force old-style BSS PLT.\n\ - --sdata-got Force GOT location just before .sdata.\n" + --sdata-got Force GOT location just before .sdata.\n' +fi +PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\ + --ppc476-workaround [=pagesize]\n\ + Avoid a cache bug on ppc476.\n\ + --no-ppc476-workaround Disable workaround.\n" )); ' PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' case OPTION_STUBSYMS: - emit_stub_syms = 1; + params.emit_stub_syms = 1; break; case OPTION_NO_STUBSYMS: - emit_stub_syms = 0; + params.emit_stub_syms = 0; break; case OPTION_NO_TLS_OPT: @@ -224,15 +300,15 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' break; case OPTION_NO_TLS_GET_ADDR_OPT: - no_tls_get_addr_opt = 1; + params.no_tls_get_addr_opt = 1; break; case OPTION_NEW_PLT: - plt_style = PLT_NEW; + params.plt_style = PLT_NEW; break; case OPTION_OLD_PLT: - plt_style = PLT_OLD; + params.plt_style = PLT_OLD; break; case OPTION_OLD_GOT: @@ -241,11 +317,32 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' case OPTION_TRADITIONAL_FORMAT: notlsopt = 1; - no_tls_get_addr_opt = 1; + params.no_tls_get_addr_opt = 1; return FALSE; + + case OPTION_PPC476_WORKAROUND: + params.ppc476_workaround = 1; + if (optarg != NULL) + { + char *end; + pagesize = strtoul (optarg, &end, 0); + if (*end + || (pagesize < 4096 && pagesize != 0) + || pagesize != (pagesize & -pagesize)) + einfo (_("%P%F: invalid pagesize `%s'\''\n"), optarg); + } + break; + + case OPTION_NO_PPC476_WORKAROUND: + params.ppc476_workaround = 0; + break; ' # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation # -LDEMUL_AFTER_OPEN=ppc_after_open +LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_after_open_output +if test -z "$VXWORKS_BASE_EM_FILE" ; then + LDEMUL_AFTER_OPEN=ppc_after_open +fi LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation +LDEMUL_FINISH=ppc_finish diff --git a/binutils-2.25/ld/emultempl/ppc64elf.em b/binutils-2.25/ld/emultempl/ppc64elf.em index f2085d7..59ea786 100644 --- a/binutils-2.25/ld/emultempl/ppc64elf.em +++ b/binutils-2.25/ld/emultempl/ppc64elf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 -# Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -30,25 +29,29 @@ fragment <<EOF #include "elf-bfd.h" #include "elf64-ppc.h" #include "ldlex.h" +#include "elf/ppc64.h" + +static asection *ppc_add_stub_section (const char *, asection *); +static void ppc_layout_sections_again (void); + +static struct ppc64_elf_params params = { NULL, + &ppc_add_stub_section, + &ppc_layout_sections_again, + 1, 0, 0, + ${DEFAULT_PLT_STATIC_CHAIN-0}, -1, 0, + 0, -1, -1}; /* Fake input file for stubs. */ static lang_input_statement_type *stub_file; -static int stub_added = 0; /* Whether we need to call ppc_layout_sections_again. */ static int need_laying_out = 0; -/* Maximum size of a group of input sections that can be handled by - one stub section. A value of +/-1 indicates the bfd back-end - should use a suitable default size. */ -static bfd_signed_vma group_size = 1; - /* Whether to add ".foo" entries for each "foo" in a version script. */ static int dotsyms = 1; /* Whether to run tls optimization. */ static int no_tls_opt = 0; -static int no_tls_get_addr_opt = 0; /* Whether to run opd optimization. */ static int no_opd_opt = 0; @@ -56,30 +59,14 @@ static int no_opd_opt = 0; /* Whether to run toc optimization. */ static int no_toc_opt = 0; -/* Whether to allow multiple toc sections. */ -static int no_multi_toc = 0; - /* Whether to sort input toc and got sections. */ static int no_toc_sort = 0; -/* Set if PLT call stubs should load r11. */ -static int plt_static_chain = ${DEFAULT_PLT_STATIC_CHAIN-0}; - -/* Set if PLT call stubs need to be thread safe on power7+. */ -static int plt_thread_safe = -1; - /* Set if individual PLT call stubs should be aligned. */ static int plt_stub_align = 0; -/* Whether to emit symbols for stubs. */ -static int emit_stub_syms = -1; - static asection *toc_section = 0; -/* Whether to canonicalize .opd so that there are no overlapping - .opd entries. */ -static int non_overlapping_opd = 0; - /* This is called before the input files are opened. We create a new fake input file to hold the stub sections. */ @@ -107,7 +94,10 @@ ppc_create_output_section_statements (void) stub_file->the_bfd->flags |= BFD_LINKER_CREATED; ldlang_add_file (stub_file); - if (!ppc64_elf_init_stub_bfd (stub_file->the_bfd, &link_info)) + params.stub_bfd = stub_file->the_bfd; + if (params.save_restore_funcs < 0) + params.save_restore_funcs = !link_info.relocatable; + if (!ppc64_elf_init_stub_bfd (&link_info, ¶ms)) einfo ("%F%P: can not init BFD: %E\n"); } @@ -256,10 +246,10 @@ ppc_before_allocation (void) if (stub_file != NULL) { if (!no_opd_opt - && !ppc64_elf_edit_opd (&link_info, non_overlapping_opd)) + && !ppc64_elf_edit_opd (&link_info)) einfo ("%X%P: can not edit %s: %E\n", "opd"); - if (ppc64_elf_tls_setup (&link_info, no_tls_get_addr_opt, &no_multi_toc) + if (ppc64_elf_tls_setup (&link_info) && !no_tls_opt) { /* Size the sections. This is premature, but we want to know the @@ -378,7 +368,6 @@ ppc_add_stub_section (const char *stub_sec_name, asection *input_section) asection *stub_sec; flagword flags; asection *output_section; - const char *secname; lang_output_section_statement_type *os; struct hook_stub_info info; @@ -392,8 +381,7 @@ ppc_add_stub_section (const char *stub_sec_name, asection *input_section) goto err_ret; output_section = input_section->output_section; - secname = bfd_get_section_name (output_section->owner, output_section); - os = lang_output_section_find (secname); + os = lang_output_section_get (output_section); info.input_section = input_section; lang_list_init (&info.add); @@ -402,7 +390,6 @@ ppc_add_stub_section (const char *stub_sec_name, asection *input_section) if (info.add.head == NULL) goto err_ret; - stub_added = 1; if (hook_in_stub (&info, &os->children.head)) return stub_sec; @@ -471,27 +458,20 @@ build_section_lists (lang_statement_union_type *statement) static void gld${EMULATION_NAME}_after_allocation (void) { - /* bfd_elf_discard_info just plays with data and debugging sections, - ie. doesn't affect code size, so we can delay resizing the - sections. It's likely we'll resize everything in the process of - adding stubs. */ - if (bfd_elf_discard_info (link_info.output_bfd, &link_info)) - need_laying_out = 1; + int ret; /* If generating a relocatable output file, then we don't have any stubs. */ if (stub_file != NULL && !link_info.relocatable) { - int ret = ppc64_elf_setup_section_lists (&link_info, - &ppc_add_stub_section, - &ppc_layout_sections_again); + ret = ppc64_elf_setup_section_lists (&link_info); if (ret < 0) einfo ("%X%P: can not size stub section: %E\n"); - else if (ret > 0) + else { ppc64_elf_start_multitoc_partition (&link_info); - if (!no_multi_toc) + if (!params.no_multi_toc) { toc_section = bfd_get_section_by_name (link_info.output_bfd, ".got"); @@ -500,7 +480,7 @@ gld${EMULATION_NAME}_after_allocation (void) } if (ppc64_elf_layout_multitoc (&link_info) - && !no_multi_toc + && !params.no_multi_toc && toc_section != NULL) lang_for_each_statement (build_toc_list); @@ -512,13 +492,24 @@ gld${EMULATION_NAME}_after_allocation (void) einfo ("%P: .init/.fini fragments use differing TOC pointers\n"); /* Call into the BFD backend to do the real work. */ - if (!ppc64_elf_size_stubs (&link_info, group_size, - plt_static_chain, plt_thread_safe, - plt_stub_align)) + if (!ppc64_elf_size_stubs (&link_info)) einfo ("%X%P: can not size stub section: %E\n"); } } + /* We can't parse and merge .eh_frame until the glink .eh_frame has + been generated. Otherwise the glink .eh_frame CIE won't be + merged with other CIEs, and worse, the glink .eh_frame FDEs won't + be listed in .eh_frame_hdr. */ + ret = bfd_elf_discard_info (link_info.output_bfd, &link_info); + if (ret < 0) + { + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + return; + } + else if (ret > 0) + need_laying_out = 1; + if (need_laying_out != -1) { gld${EMULATION_NAME}_map_segments (need_laying_out); @@ -534,34 +525,34 @@ gld${EMULATION_NAME}_after_allocation (void) static void gld${EMULATION_NAME}_finish (void) { + char *msg = NULL; + char *line, *endline; + /* e_entry on PowerPC64 points to the function descriptor for _start. If _start is missing, default to the first function descriptor in the .opd section. */ - entry_section = ".opd"; - - if (stub_added) + if (stub_file != NULL + && (elf_elfheader (link_info.output_bfd)->e_flags & EF_PPC64_ABI) == 1) + entry_section = ".opd"; + + if (params.emit_stub_syms < 0) + params.emit_stub_syms = 1; + if (stub_file != NULL + && !link_info.relocatable + && !ppc64_elf_build_stubs (&link_info, config.stats ? &msg : NULL)) + einfo ("%X%P: can not build stubs: %E\n"); + + fflush (stdout); + for (line = msg; line != NULL; line = endline) { - char *msg = NULL; - char *line, *endline; - - if (emit_stub_syms < 0) - emit_stub_syms = 1; - if (!ppc64_elf_build_stubs (emit_stub_syms, &link_info, - config.stats ? &msg : NULL)) - einfo ("%X%P: can not build stubs: %E\n"); - - fflush (stdout); - for (line = msg; line != NULL; line = endline) - { - endline = strchr (line, '\n'); - if (endline != NULL) - *endline++ = '\0'; - fprintf (stderr, "%s: %s\n", program_name, line); - } - fflush (stderr); - if (msg != NULL) - free (msg); + endline = strchr (line, '\n'); + if (endline != NULL) + *endline++ = '\0'; + fprintf (stderr, "%s: %s\n", program_name, line); } + fflush (stderr); + if (msg != NULL) + free (msg); ppc64_elf_restore_symbols (&link_info); finish_default (); @@ -664,7 +655,9 @@ PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}' #define OPTION_NO_PLT_ALIGN (OPTION_PLT_ALIGN + 1) #define OPTION_STUBSYMS (OPTION_NO_PLT_ALIGN + 1) #define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1) -#define OPTION_DOTSYMS (OPTION_NO_STUBSYMS + 1) +#define OPTION_SAVRES (OPTION_NO_STUBSYMS + 1) +#define OPTION_NO_SAVRES (OPTION_SAVRES + 1) +#define OPTION_DOTSYMS (OPTION_NO_SAVRES + 1) #define OPTION_NO_DOTSYMS (OPTION_DOTSYMS + 1) #define OPTION_NO_TLS_OPT (OPTION_NO_DOTSYMS + 1) #define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1) @@ -687,6 +680,8 @@ PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS }, { "dotsyms", no_argument, NULL, OPTION_DOTSYMS }, { "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS }, + { "save-restore-funcs", no_argument, NULL, OPTION_SAVRES }, + { "no-save-restore-funcs", no_argument, NULL, OPTION_NO_SAVRES }, { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT }, { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT }, { "no-opd-optimize", no_argument, NULL, OPTION_NO_OPD_OPT }, @@ -741,6 +736,14 @@ PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}' --no-dotsyms Don'\''t do anything special in version scripts.\n" )); fprintf (file, _("\ + --save-restore-funcs Provide register save and restore routines used\n\ + by gcc -Os code. Defaults to on for normal\n\ + final link, off for ld -r.\n" + )); + fprintf (file, _("\ + --no-save-restore-funcs Don'\''t provide these routines.\n" + )); + fprintf (file, _("\ --no-tls-optimize Don'\''t try to optimize TLS accesses.\n" )); fprintf (file, _("\ @@ -768,26 +771,26 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' case OPTION_STUBGROUP_SIZE: { const char *end; - group_size = bfd_scan_vma (optarg, &end, 0); + params.group_size = bfd_scan_vma (optarg, &end, 0); if (*end) einfo (_("%P%F: invalid number `%s'\''\n"), optarg); } break; case OPTION_PLT_STATIC_CHAIN: - plt_static_chain = 1; + params.plt_static_chain = 1; break; case OPTION_NO_PLT_STATIC_CHAIN: - plt_static_chain = 0; + params.plt_static_chain = 0; break; case OPTION_PLT_THREAD_SAFE: - plt_thread_safe = 1; + params.plt_thread_safe = 1; break; case OPTION_NO_PLT_THREAD_SAFE: - plt_thread_safe = 0; + params.plt_thread_safe = 0; break; case OPTION_PLT_ALIGN: @@ -808,11 +811,11 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' break; case OPTION_STUBSYMS: - emit_stub_syms = 1; + params.emit_stub_syms = 1; break; case OPTION_NO_STUBSYMS: - emit_stub_syms = 0; + params.emit_stub_syms = 0; break; case OPTION_DOTSYMS: @@ -823,12 +826,20 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' dotsyms = 0; break; + case OPTION_SAVRES: + params.save_restore_funcs = 1; + break; + + case OPTION_NO_SAVRES: + params.save_restore_funcs = 0; + break; + case OPTION_NO_TLS_OPT: no_tls_opt = 1; break; case OPTION_NO_TLS_GET_ADDR_OPT: - no_tls_get_addr_opt = 1; + params.no_tls_get_addr_opt = 1; break; case OPTION_NO_OPD_OPT: @@ -840,7 +851,7 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' break; case OPTION_NO_MULTI_TOC: - no_multi_toc = 1; + params.no_multi_toc = 1; break; case OPTION_NO_TOC_SORT: @@ -848,17 +859,17 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' break; case OPTION_NON_OVERLAPPING_OPD: - non_overlapping_opd = 1; + params.non_overlapping_opd = 1; break; case OPTION_TRADITIONAL_FORMAT: no_tls_opt = 1; - no_tls_get_addr_opt = 1; + params.no_tls_get_addr_opt = 1; no_opd_opt = 1; no_toc_opt = 1; - no_multi_toc = 1; + params.no_multi_toc = 1; no_toc_sort = 1; - plt_static_chain = 1; + params.plt_static_chain = 1; return FALSE; ' diff --git a/binutils-2.25/ld/emultempl/rxelf.em b/binutils-2.25/ld/emultempl/rxelf.em index f27e8e6..6386abd 100644 --- a/binutils-2.25/ld/emultempl/rxelf.em +++ b/binutils-2.25/ld/emultempl/rxelf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2009, 2011 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -25,6 +25,8 @@ test -z "$TARGET2_TYPE" && TARGET2_TYPE="rel" fragment <<EOF +#include "elf32-rx.h" + static bfd_boolean no_flag_mismatch_warnings = TRUE; static bfd_boolean ignore_lma = TRUE; @@ -86,3 +88,5 @@ PARSE_AND_LIST_ARGS_CASES=' ' LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=rx_elf_create_output_section_statements + +LDEMUL_EXTRA_MAP_FILE_TEXT=rx_additional_link_map_text diff --git a/binutils-2.25/ld/emultempl/scoreelf.em b/binutils-2.25/ld/emultempl/scoreelf.em index 8556b40..fa3c0f7 100644 --- a/binutils-2.25/ld/emultempl/scoreelf.em +++ b/binutils-2.25/ld/emultempl/scoreelf.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2006, 2007, 2008, 2009, 2012 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # Contributed by: # Brain.lin (brain.lin@sunplusct.com) # Mei Ligang (ligang@sunnorth.com.cn) diff --git a/binutils-2.25/ld/emultempl/sh64elf.em b/binutils-2.25/ld/emultempl/sh64elf.em index 17f9dde..c49fbe8 100644 --- a/binutils-2.25/ld/emultempl/sh64elf.em +++ b/binutils-2.25/ld/emultempl/sh64elf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 -# Free Software Foundation, Inc. +# Copyright (C) 2000-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -249,6 +248,9 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void) gld${EMULATION_NAME}_after_allocation (); + /* Needed, since we create link_orders here. */ + lang_clear_os_map (); + cranges = bfd_get_section_by_name (link_info.output_bfd, SH64_CRANGES_SECTION_NAME); diff --git a/binutils-2.25/ld/emultempl/solaris2.em b/binutils-2.25/ld/emultempl/solaris2.em index 2c24467..6aff0ba 100644 --- a/binutils-2.25/ld/emultempl/solaris2.em +++ b/binutils-2.25/ld/emultempl/solaris2.em @@ -9,7 +9,7 @@ fragment <<EOF /* This file is generated by a shell script. DO NOT EDIT! */ /* Solaris 2 emulation code for ${EMULATION_NAME} - Copyright 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2014 Free Software Foundation, Inc. Written by Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> This file is part of the GNU Binutils. diff --git a/binutils-2.25/ld/emultempl/spu_ovl.S b/binutils-2.25/ld/emultempl/spu_ovl.S index 509397a..03fecc6 100644 --- a/binutils-2.25/ld/emultempl/spu_ovl.S +++ b/binutils-2.25/ld/emultempl/spu_ovl.S @@ -1,6 +1,6 @@ /* Overlay manager for SPU. - Copyright 2006, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2006-2014 Free Software Foundation, Inc. This file is part of the GNU Binutils. diff --git a/binutils-2.25/ld/emultempl/spuelf.em b/binutils-2.25/ld/emultempl/spuelf.em index e14fa26..1b4d72f 100644 --- a/binutils-2.25/ld/emultempl/spuelf.em +++ b/binutils-2.25/ld/emultempl/spuelf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 -# Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -90,9 +89,9 @@ static const struct _ovl_stream icache_mgr_stream = { static int is_spu_target (void) { - extern const bfd_target bfd_elf32_spu_vec; + extern const bfd_target spu_elf32_vec; - return link_info.output_bfd->xvec == &bfd_elf32_spu_vec; + return link_info.output_bfd->xvec == &spu_elf32_vec; } /* Create our note section. */ @@ -138,8 +137,9 @@ spu_place_special_section (asection *s, asection *o, const char *output_name) lang_output_section_statement_type *os; if (o != NULL) - output_name = o->name; - os = lang_output_section_find (output_name); + os = lang_output_section_get (o); + else + os = lang_output_section_find (output_name); if (os == NULL) { os = gld${EMULATION_NAME}_place_orphan (s, output_name, 0); @@ -447,7 +447,7 @@ EOF if grep -q 'ld_elf.*ppc.*_emulation' ldemul-list.h; then fragment <<EOF -#include <errno.h> +#include "safe-ctype.h" #include "filenames.h" #include "libiberty.h" diff --git a/binutils-2.25/ld/emultempl/sunos.em b/binutils-2.25/ld/emultempl/sunos.em index af11027..e57e1f0 100644 --- a/binutils-2.25/ld/emultempl/sunos.em +++ b/binutils-2.25/ld/emultempl/sunos.em @@ -9,9 +9,7 @@ fragment <<EOF /* This file is is generated by a shell script. DO NOT EDIT! */ /* SunOS emulation code for ${EMULATION_NAME} - Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2012 - Free Software Foundation, Inc. + Copyright (C) 1991-2014 Free Software Foundation, Inc. Written by Steve Chamberlain <sac@cygnus.com> SunOS shared library support by Ian Lance Taylor <ian@cygnus.com> @@ -960,7 +958,7 @@ static char * gld${EMULATION_NAME}_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -1035,6 +1033,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = NULL, /* list options */ NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/tic6xdsbt.em b/binutils-2.25/ld/emultempl/tic6xdsbt.em index 01923b3..ff591f1 100644 --- a/binutils-2.25/ld/emultempl/tic6xdsbt.em +++ b/binutils-2.25/ld/emultempl/tic6xdsbt.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2011, 2012 Free Software Foundation, Inc. +# Copyright (C) 2011-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -36,19 +36,19 @@ static int merge_exidx_entries = -1; static int is_tic6x_target (void) { - extern const bfd_target bfd_elf32_tic6x_le_vec; - extern const bfd_target bfd_elf32_tic6x_be_vec; - extern const bfd_target bfd_elf32_tic6x_linux_le_vec; - extern const bfd_target bfd_elf32_tic6x_linux_be_vec; - extern const bfd_target bfd_elf32_tic6x_elf_le_vec; - extern const bfd_target bfd_elf32_tic6x_elf_be_vec; - - return (link_info.output_bfd->xvec == &bfd_elf32_tic6x_le_vec - || link_info.output_bfd->xvec == &bfd_elf32_tic6x_be_vec - || link_info.output_bfd->xvec == &bfd_elf32_tic6x_linux_le_vec - || link_info.output_bfd->xvec == &bfd_elf32_tic6x_linux_be_vec - || link_info.output_bfd->xvec == &bfd_elf32_tic6x_elf_le_vec - || link_info.output_bfd->xvec == &bfd_elf32_tic6x_elf_be_vec); + extern const bfd_target tic6x_elf32_le_vec; + extern const bfd_target tic6x_elf32_be_vec; + extern const bfd_target tic6x_elf32_linux_le_vec; + extern const bfd_target tic6x_elf32_linux_be_vec; + extern const bfd_target tic6x_elf32_c6000_le_vec; + extern const bfd_target tic6x_elf32_c6000_be_vec; + + return (link_info.output_bfd->xvec == &tic6x_elf32_le_vec + || link_info.output_bfd->xvec == &tic6x_elf32_be_vec + || link_info.output_bfd->xvec == &tic6x_elf32_linux_le_vec + || link_info.output_bfd->xvec == &tic6x_elf32_linux_be_vec + || link_info.output_bfd->xvec == &tic6x_elf32_c6000_le_vec + || link_info.output_bfd->xvec == &tic6x_elf32_c6000_be_vec); } /* Pass params to backend. */ @@ -95,6 +95,7 @@ static void gld${EMULATION_NAME}_after_allocation (void) { int layout_changed = 0; + int ret; if (!link_info.relocatable) { @@ -149,7 +150,13 @@ gld${EMULATION_NAME}_after_allocation (void) /* bfd_elf32_discard_info just plays with debugging sections, ie. doesn't affect any code, so we can delay resizing the sections. */ - if (bfd_elf_discard_info (link_info.output_bfd, & link_info)) + ret = bfd_elf_discard_info (link_info.output_bfd, & link_info); + if (ret < 0) + { + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + return; + } + else if (ret > 0) layout_changed = 1; gld${EMULATION_NAME}_map_segments (layout_changed); diff --git a/binutils-2.25/ld/emultempl/ticoff.em b/binutils-2.25/ld/emultempl/ticoff.em index dff1d70..c403d56 100644 --- a/binutils-2.25/ld/emultempl/ticoff.em +++ b/binutils-2.25/ld/emultempl/ticoff.em @@ -3,8 +3,7 @@ (echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-) fragment <<EOF /* This file is part of GLD, the Gnu Linker. - Copyright 1999, 2000, 2002, 2003, 2004, 2005, 2007 - Free Software Foundation, Inc. + Copyright (C) 1999-2014 Free Software Foundation, Inc. This file is part of the GNU Binutils. @@ -106,7 +105,7 @@ gld_${EMULATION_NAME}_before_parse(void) static char * gld_${EMULATION_NAME}_get_script (int *isfile) EOF -if test -n "$COMPILE_IN" +if test x"$COMPILE_IN" = xyes then # Scripts compiled in. @@ -181,6 +180,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = gld_${EMULATION_NAME}_list_options, NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/vanilla.em b/binutils-2.25/ld/emultempl/vanilla.em index 4a83dfd..f8ade99 100644 --- a/binutils-2.25/ld/emultempl/vanilla.em +++ b/binutils-2.25/ld/emultempl/vanilla.em @@ -2,8 +2,7 @@ # It does some substitutions. fragment <<EOF /* A vanilla emulation with no defaults - Copyright 1991, 1992, 1994, 2000, 2001, 2002, 2003, 2005, 2007, 2008 - Free Software Foundation, Inc. + Copyright (C) 1991-2014 Free Software Foundation, Inc. Written by Steve Chamberlain steve@cygnus.com This file is part of the GNU Binutils. @@ -82,6 +81,7 @@ struct ld_emulation_xfer_struct ld_vanilla_emulation = NULL, /* list options */ NULL, /* recognized file */ NULL, /* find_potential_libraries */ - NULL /* new_vers_pattern */ + NULL, /* new_vers_pattern */ + NULL /* extra_map_file_text */ }; EOF diff --git a/binutils-2.25/ld/emultempl/vms.em b/binutils-2.25/ld/emultempl/vms.em index 30c1a16..40be66d 100644 --- a/binutils-2.25/ld/emultempl/vms.em +++ b/binutils-2.25/ld/emultempl/vms.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2010, 2012 -# Free Software Foundation, Inc. +# Copyright (C) 2010-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -58,7 +57,7 @@ gld${EMULATION_NAME}_open_dynamic_archive (const char *arch ATTRIBUTE_UNUSED, { char *string; - if (! entry->flags.maybe_archive) + if (! entry->flags.maybe_archive || entry->flags.full_name_provided) return FALSE; string = (char *) xmalloc (strlen (search->name) @@ -208,9 +207,12 @@ gld${EMULATION_NAME}_before_allocation (void) static void gld${EMULATION_NAME}_after_allocation (void) { - bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd, - &link_info); - gld${EMULATION_NAME}_map_segments (need_layout); + int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info); + + if (need_layout < 0) + einfo ("%X%P: .eh_frame/.stab edit: %E\n"); + else + gld${EMULATION_NAME}_map_segments (need_layout); } static void diff --git a/binutils-2.25/ld/emultempl/vxworks.em b/binutils-2.25/ld/emultempl/vxworks.em index 7a21ac3..4bdc088 100644 --- a/binutils-2.25/ld/emultempl/vxworks.em +++ b/binutils-2.25/ld/emultempl/vxworks.em @@ -1,5 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2006, 2007, 2008, 2010 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # diff --git a/binutils-2.25/ld/emultempl/xtensaelf.em b/binutils-2.25/ld/emultempl/xtensaelf.em index 1e6eb07..948d18d 100644 --- a/binutils-2.25/ld/emultempl/xtensaelf.em +++ b/binutils-2.25/ld/emultempl/xtensaelf.em @@ -1,6 +1,5 @@ # This shell script emits a C file. -*- C -*- -# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 -# Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # # This file is part of the GNU Binutils. # @@ -1311,7 +1310,7 @@ is_inconsistent_linkonce_section (asection *sec) for Tensilica's XCC compiler. */ name = sec_name + linkonce_len; if (CONST_STRNEQ (name, "prop.")) - name = strchr (name + 5, '.') + 1; + name = strchr (name + 5, '.') ? strchr (name + 5, '.') + 1 : name + 5; else if (name[1] == '.' && (name[0] == 'p' || name[0] == 'e' || name[0] == 'h')) name += 2; diff --git a/binutils-2.25/ld/emultempl/z80.em b/binutils-2.25/ld/emultempl/z80.em index eeb3213..9411f5b 100644 --- a/binutils-2.25/ld/emultempl/z80.em +++ b/binutils-2.25/ld/emultempl/z80.em @@ -1,7 +1,7 @@ # This shell script emits C code -*- C -*- # to keep track of the machine type of Z80 object files # It does some substitutions. -# Copyright 2005, 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 2005-2014 Free Software Foundation, Inc. # This file is part of the GNU Binutils. # # This program is free software; you can redistribute it and/or modify |