Submitted By: Armin K. Date: 2016-04-28 Initial Package Version: 2.26 Upstream Status: Committed Origin: Upstream Description: Various fixes for issues identified upstream --- a/bfd/archive.c 2016-01-25 09:51:06.000000000 +0100 +++ b/bfd/archive.c 2016-04-27 17:07:04.277213979 +0200 @@ -802,7 +802,7 @@ Note that last_file->origin can be odd in the case of BSD-4.4-style element with a long odd size. */ filestart += filestart % 2; - if (filestart <= last_file->proxy_origin) + if (filestart < last_file->proxy_origin) { /* Prevent looping. See PR19256. */ bfd_set_error (bfd_error_malformed_archive); --- a/bfd/dwarf2.c 2016-01-25 09:51:06.000000000 +0100 +++ b/bfd/dwarf2.c 2016-04-27 17:07:04.353217017 +0200 @@ -3706,8 +3706,10 @@ fail more quickly. */ return FALSE; + /* Set BFD_DECOMPRESS to decompress debug sections. */ if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL - || ! bfd_check_format (debug_bfd, bfd_object) + || !(debug_bfd->flags |= BFD_DECOMPRESS, + bfd_check_format (debug_bfd, bfd_object)) || (msec = find_debug_info (debug_bfd, debug_sections, NULL)) == NULL || !bfd_generic_link_read_symbols (debug_bfd)) --- a/bfd/elf32-i386.c 2016-01-25 09:51:06.000000000 +0100 +++ b/bfd/elf32-i386.c 2016-04-27 17:07:04.415219496 +0200 @@ -1830,7 +1830,8 @@ && (sec->flags & SEC_ALLOC) != 0 && (r_type != R_386_PC32 || (h != NULL - && (! SYMBOLIC_BIND (info, h) + && (! (bfd_link_pie (info) + || SYMBOLIC_BIND (info, h)) || h->root.type == bfd_link_hash_defweak || !h->def_regular)))) || (ELIMINATE_COPY_RELOCS @@ -2490,12 +2491,14 @@ } else { + eh->plt_got.offset = (bfd_vma) -1; h->plt.offset = (bfd_vma) -1; h->needs_plt = 0; } } else { + eh->plt_got.offset = (bfd_vma) -1; h->plt.offset = (bfd_vma) -1; h->needs_plt = 0; } @@ -4016,10 +4019,12 @@ /* It is relative to .got.plt section. */ if (h->got.offset != (bfd_vma) -1) - /* Use GOT entry. */ + /* Use GOT entry. Mask off the least significant bit in + GOT offset which may be set by R_386_GOT32 processing + below. */ relocation = (htab->elf.sgot->output_section->vma + htab->elf.sgot->output_offset - + h->got.offset - offplt); + + (h->got.offset & ~1) - offplt); else /* Use GOTPLT entry. */ relocation = (h->plt.offset / plt_entry_size - 1 + 3) * 4; @@ -4285,8 +4290,8 @@ else if (h != NULL && h->dynindx != -1 && (r_type == R_386_PC32 - || !bfd_link_pic (info) - || !SYMBOLIC_BIND (info, h) + || !(bfd_link_executable (info) + || SYMBOLIC_BIND (info, h)) || !h->def_regular)) outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); else @@ -5355,19 +5360,23 @@ bfd *abfd = info->output_bfd; const struct elf_backend_data *bed = get_elf_backend_data (abfd); struct elf_link_hash_table *htab = elf_hash_table (info); - unsigned long r_symndx = ELF32_R_SYM (rela->r_info); - Elf_Internal_Sym sym; - if (htab->dynsym == NULL - || !bed->s->swap_symbol_in (abfd, - (htab->dynsym->contents - + r_symndx * sizeof (Elf32_External_Sym)), - 0, &sym)) - abort (); + if (htab->dynsym != NULL + && htab->dynsym->contents != NULL) + { + /* Check relocation against STT_GNU_IFUNC symbol if there are + dynamic symbols. */ + unsigned long r_symndx = ELF32_R_SYM (rela->r_info); + Elf_Internal_Sym sym; + if (!bed->s->swap_symbol_in (abfd, + (htab->dynsym->contents + + r_symndx * sizeof (Elf32_External_Sym)), + 0, &sym)) + abort (); - /* Check relocation against STT_GNU_IFUNC symbol. */ - if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) - return reloc_class_ifunc; + if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) + return reloc_class_ifunc; + } switch (ELF32_R_TYPE (rela->r_info)) { --- a/bfd/elf64-x86-64.c 2016-01-25 09:51:06.000000000 +0100 +++ b/bfd/elf64-x86-64.c 2016-04-27 17:07:04.416219536 +0200 @@ -2029,7 +2029,8 @@ && (sec->flags & SEC_ALLOC) != 0 && (! IS_X86_64_PCREL_TYPE (r_type) || (h != NULL - && (! SYMBOLIC_BIND (info, h) + && (! (bfd_link_pie (info) + || SYMBOLIC_BIND (info, h)) || h->root.type == bfd_link_hash_defweak || !h->def_regular)))) || (ELIMINATE_COPY_RELOCS @@ -2723,12 +2724,14 @@ } else { + eh->plt_got.offset = (bfd_vma) -1; h->plt.offset = (bfd_vma) -1; h->needs_plt = 0; } } else { + eh->plt_got.offset = (bfd_vma) -1; h->plt.offset = (bfd_vma) -1; h->needs_plt = 0; } @@ -3190,35 +3193,43 @@ } else { - asection *asect; - bfd_size_type size; + bfd_signed_vma distance; /* At this point, we don't know the load addresses of TSEC section nor SEC section. We estimate the distrance between - SEC and TSEC. */ - size = 0; - for (asect = sec->output_section; - asect != NULL && asect != tsec->output_section; - asect = asect->next) - { - asection *i; - for (i = asect->output_section->map_head.s; - i != NULL; - i = i->map_head.s) - { - size = align_power (size, i->alignment_power); - size += i->size; + SEC and TSEC. We store the estimated distances in the + compressed_size field of the output section, which is only + used to decompress the compressed input section. */ + if (sec->output_section->compressed_size == 0) + { + asection *asect; + bfd_size_type size = 0; + for (asect = link_info->output_bfd->sections; + asect != NULL; + asect = asect->next) + { + asection *i; + for (i = asect->map_head.s; + i != NULL; + i = i->map_head.s) + { + size = align_power (size, i->alignment_power); + size += i->size; + } + asect->compressed_size = size; } } /* Don't convert GOTPCREL relocations if TSEC isn't placed after SEC. */ - if (asect == NULL) + distance = (tsec->output_section->compressed_size + - sec->output_section->compressed_size); + if (distance < 0) continue; /* Take PT_GNU_RELRO segment into account by adding maxpagesize. */ - if ((toff + size + maxpagesize - roff + 0x80000000) + if ((toff + distance + maxpagesize - roff + 0x80000000) > 0xffffffff) continue; } @@ -4631,8 +4642,8 @@ else if (h != NULL && h->dynindx != -1 && (IS_X86_64_PCREL_TYPE (r_type) - || ! bfd_link_pic (info) - || ! SYMBOLIC_BIND (info, h) + || !(bfd_link_executable (info) + || SYMBOLIC_BIND (info, h)) || ! h->def_regular)) { outrel.r_info = htab->r_info (h->dynindx, r_type); @@ -5728,19 +5739,23 @@ bfd *abfd = info->output_bfd; const struct elf_backend_data *bed = get_elf_backend_data (abfd); struct elf_x86_64_link_hash_table *htab = elf_x86_64_hash_table (info); - unsigned long r_symndx = htab->r_sym (rela->r_info); - Elf_Internal_Sym sym; - if (htab->elf.dynsym == NULL - || !bed->s->swap_symbol_in (abfd, - (htab->elf.dynsym->contents - + r_symndx * bed->s->sizeof_sym), - 0, &sym)) - abort (); + if (htab->elf.dynsym != NULL + && htab->elf.dynsym->contents != NULL) + { + /* Check relocation against STT_GNU_IFUNC symbol if there are + dynamic symbols. */ + unsigned long r_symndx = htab->r_sym (rela->r_info); + Elf_Internal_Sym sym; + if (!bed->s->swap_symbol_in (abfd, + (htab->elf.dynsym->contents + + r_symndx * bed->s->sizeof_sym), + 0, &sym)) + abort (); - /* Check relocation against STT_GNU_IFUNC symbol. */ - if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) - return reloc_class_ifunc; + if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) + return reloc_class_ifunc; + } switch ((int) ELF32_R_TYPE (rela->r_info)) { --- a/bfd/elflink.c 2016-01-25 09:51:06.000000000 +0100 +++ b/bfd/elflink.c 2016-04-27 17:07:04.281214139 +0200 @@ -555,6 +555,19 @@ if (h == NULL) return provide; + if (h->versioned == unknown) + { + /* Set versioned if symbol version is unknown. */ + char *version = strrchr (name, ELF_VER_CHR); + if (version) + { + if (version > name && version[-1] != ELF_VER_CHR) + h->versioned = versioned_hidden; + else + h->versioned = versioned; + } + } + switch (h->root.type) { case bfd_link_hash_defined: @@ -1472,13 +1485,16 @@ represent variables; this can cause confusion in principle, but any such confusion would seem to indicate an erroneous program or shared library. We also permit a common symbol in a regular - object to override a weak symbol in a shared object. */ + object to override a weak symbol in a shared object. A common + symbol in executable also overrides a symbol in a shared object. */ if (newdyn && newdef && (olddef || (h->root.type == bfd_link_hash_common - && (newweak || newfunc)))) + && (newweak + || newfunc + || (!olddyn && bfd_link_executable (info)))))) { *override = TRUE; newdef = FALSE; @@ -4562,8 +4578,10 @@ break; } - /* Don't add DT_NEEDED for references from the dummy bfd. */ + /* Don't add DT_NEEDED for references from the dummy bfd nor + for unmatched symbol. */ if (!add_needed + && matched && definition && ((dynsym && h->ref_regular_nonweak --- a/binutils/Makefile.am 2015-11-13 09:27:40.000000000 +0100 +++ b/binutils/Makefile.am 2016-04-27 17:07:04.353217017 +0200 @@ -192,6 +192,7 @@ EXPECT=$(EXPECT); export EXPECT; \ runtest=$(RUNTEST); \ if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \ + CC="$(CC)" CC_FOR_BUILD="$(CC_FOR_BUILD)" \ CC_FOR_TARGET="$(CC_FOR_TARGET)" CFLAGS_FOR_TARGET="$(CFLAGS)" \ $$runtest --tool $(DEJATOOL) --srcdir $${srcdir}/testsuite \ $(RUNTESTFLAGS); \ --- a/binutils/Makefile.in 2015-11-13 09:27:40.000000000 +0100 +++ b/binutils/Makefile.in 2016-04-27 17:07:04.353217017 +0200 @@ -1290,6 +1290,7 @@ EXPECT=$(EXPECT); export EXPECT; \ runtest=$(RUNTEST); \ if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \ + CC="$(CC)" CC_FOR_BUILD="$(CC_FOR_BUILD)" \ CC_FOR_TARGET="$(CC_FOR_TARGET)" CFLAGS_FOR_TARGET="$(CFLAGS)" \ $$runtest --tool $(DEJATOOL) --srcdir $${srcdir}/testsuite \ $(RUNTESTFLAGS); \ --- a/gas/config/tc-i386.c 2016-01-25 09:51:06.000000000 +0100 +++ b/gas/config/tc-i386.c 2016-04-27 17:07:04.495222695 +0200 @@ -552,6 +552,10 @@ specified explicitly. */ static int omit_lock_prefix = 0; +/* 1 if the assembler should generate relax relocations. */ +static int generate_relax_relocations + = DEFAULT_GENERATE_X86_RELAX_RELOCATIONS; + static enum check_kind { check_none = 0, @@ -1871,6 +1875,9 @@ if (r->reg_flags & RegRex) nr += 8; + if (r->reg_flags & RegVRex) + nr += 16; + return nr; } @@ -4557,7 +4564,9 @@ && i.op[op].disps->X_op == O_constant) { offsetT value = i.op[op].disps->X_add_number; - int vec_disp8_ok = fits_in_vec_disp8 (value); + int vec_disp8_ok + = (i.disp_encoding != disp_encoding_32bit + && fits_in_vec_disp8 (value)); if (t->operand_types [op].bitfield.vec_disp8) { if (vec_disp8_ok) @@ -7241,9 +7250,14 @@ /* Check for "call/jmp *mem", "mov mem, %reg", "test %reg, mem" and "binop mem, %reg" where binop is one of adc, add, and, cmp, or, sbb, sub, xor - instructions. */ - if ((i.rm.mode == 2 - || (i.rm.mode == 0 && i.rm.regmem == 5)) + instructions. Always generate R_386_GOT32X for + "sym*GOT" operand in 32-bit mode. */ + if ((generate_relax_relocations + || (!object_64bit + && i.rm.mode == 0 + && i.rm.regmem == 5)) + && (i.rm.mode == 2 + || (i.rm.mode == 0 && i.rm.regmem == 5)) && ((i.operands == 1 && i.tm.base_opcode == 0xff && (i.rm.reg == 2 || i.rm.reg == 4)) @@ -9616,6 +9630,7 @@ #define OPTION_MSHARED (OPTION_MD_BASE + 21) #define OPTION_MAMD64 (OPTION_MD_BASE + 22) #define OPTION_MINTEL64 (OPTION_MD_BASE + 23) +#define OPTION_MRELAX_RELOCATIONS (OPTION_MD_BASE + 24) struct option md_longopts[] = { @@ -9647,6 +9662,7 @@ {"mbig-obj", no_argument, NULL, OPTION_MBIG_OBJ}, #endif {"momit-lock-prefix", required_argument, NULL, OPTION_OMIT_LOCK_PREFIX}, + {"mrelax-relocations", required_argument, NULL, OPTION_MRELAX_RELOCATIONS}, {"mevexrcig", required_argument, NULL, OPTION_MEVEXRCIG}, {"mamd64", no_argument, NULL, OPTION_MAMD64}, {"mintel64", no_argument, NULL, OPTION_MINTEL64}, @@ -9966,6 +9982,15 @@ as_fatal (_("invalid -momit-lock-prefix= option: `%s'"), arg); break; + case OPTION_MRELAX_RELOCATIONS: + if (strcasecmp (arg, "yes") == 0) + generate_relax_relocations = 1; + else if (strcasecmp (arg, "no") == 0) + generate_relax_relocations = 0; + else + as_fatal (_("invalid -mrelax-relocations= option: `%s'"), arg); + break; + case OPTION_MAMD64: cpu_arch_flags.bitfield.cpuamd64 = 1; cpu_arch_flags.bitfield.cpuintel64 = 0; @@ -10146,6 +10171,9 @@ -momit-lock-prefix=[no|yes]\n\ strip all lock prefixes\n")); fprintf (stream, _("\ + -mrelax-relocations=[no|yes]\n\ + generate relax relocations\n")); + fprintf (stream, _("\ -mamd64 accept only AMD64 ISA\n")); fprintf (stream, _("\ -mintel64 accept only Intel64 ISA\n")); --- a/gas/config.in 2015-11-13 09:27:41.000000000 +0100 +++ b/gas/config.in 2016-04-27 17:07:03.840196514 +0200 @@ -39,6 +39,9 @@ /* Define if you want compressed debug sections by default. */ #undef DEFAULT_FLAG_COMPRESS_DEBUG +/* Define to 1 if you want to generate x86 relax relocations by default. */ +#undef DEFAULT_GENERATE_X86_RELAX_RELOCATIONS + /* Supported emulations. */ #undef EMULATIONS --- a/gas/configure 2016-01-25 09:54:08.000000000 +0100 +++ b/gas/configure 2016-04-27 17:07:03.843196634 +0200 @@ -765,6 +765,7 @@ enable_targets enable_checking enable_compressed_debug_sections +enable_x86_relax_relocations enable_werror enable_build_warnings enable_nls @@ -1415,6 +1416,8 @@ --enable-checking enable run-time checks --enable-compressed-debug-sections={all,gas,none} compress debug sections by default] + --enable-x86-relax-relocations + generate x86 relax relocations by default --enable-werror treat compile warnings as errors --enable-build-warnings enable build-time compiler warnings --disable-nls do not use Native Language Support @@ -10972,7 +10975,7 @@ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10975 "configure" +#line 10978 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11078,7 +11081,7 @@ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11081 "configure" +#line 11084 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11680,6 +11683,17 @@ esac fi +# PR gas/19520 +# Decide if x86 assembler should generate relax relocations. +ac_default_x86_relax_relocations=unset +# Provide a configure time option to override our default. +# Check whether --enable-x86_relax_relocations was given. +if test "${enable_x86_relax_relocations+set}" = set; then : + enableval=$enable_x86_relax_relocations; case "${enableval}" in + no) ac_default_x86_relax_relocations=0 ;; +esac +fi + using_cgen=no @@ -12085,6 +12099,17 @@ ;; + i386-*-solaris2 \ + | x86_64-*-solaris2 \ + | i386-*-solaris2.[0-9] \ + | i386-*-solaris2.1[01] \ + | x86_64-*-solaris2.1[01]) + if test ${this_target} = $target \ + && test ${ac_default_x86_relax_relocations} = unset; then + ac_default_x86_relax_relocations=0 + fi + ;; + i860-*-*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: GAS support for ${generic_target} is preliminary and a work in progress" >&5 $as_echo "$as_me: WARNING: GAS support for ${generic_target} is preliminary and a work in progress" >&2;} @@ -12505,7 +12530,16 @@ done -if test x$ac_default_compressed_debug_sections == xyes ; then +if test ${ac_default_x86_relax_relocations} = unset; then + ac_default_x86_relax_relocations=1 +fi + +cat >>confdefs.h <<_ACEOF +#define DEFAULT_GENERATE_X86_RELAX_RELOCATIONS $ac_default_x86_relax_relocations +_ACEOF + + +if test x$ac_default_compressed_debug_sections = xyes ; then $as_echo "#define DEFAULT_FLAG_COMPRESS_DEBUG 1" >>confdefs.h --- a/gas/configure.ac 2016-01-25 09:51:06.000000000 +0100 +++ b/gas/configure.ac 2016-04-27 17:07:03.843196634 +0200 @@ -77,6 +77,17 @@ *) ac_default_compressed_debug_sections=unset ;; esac])dnl +# PR gas/19520 +# Decide if x86 assembler should generate relax relocations. +ac_default_x86_relax_relocations=unset +# Provide a configure time option to override our default. +AC_ARG_ENABLE(x86_relax_relocations, + AS_HELP_STRING([--enable-x86-relax-relocations], + [generate x86 relax relocations by default]), +[case "${enableval}" in + no) ac_default_x86_relax_relocations=0 ;; +esac])dnl + using_cgen=no AM_BINUTILS_WARNINGS @@ -168,6 +179,17 @@ AC_DEFINE(STRICTCOFF, 1, [Using strict COFF?]) ;; + i386-*-solaris2 \ + | x86_64-*-solaris2 \ + | i386-*-solaris2.[[0-9]] \ + | i386-*-solaris2.1[[01]] \ + | x86_64-*-solaris2.1[[01]]) + if test ${this_target} = $target \ + && test ${ac_default_x86_relax_relocations} = unset; then + ac_default_x86_relax_relocations=0 + fi + ;; + i860-*-*) AC_MSG_WARN(GAS support for ${generic_target} is preliminary and a work in progress) ;; @@ -549,7 +571,14 @@ done -if test x$ac_default_compressed_debug_sections == xyes ; then +if test ${ac_default_x86_relax_relocations} = unset; then + ac_default_x86_relax_relocations=1 +fi +AC_DEFINE_UNQUOTED(DEFAULT_GENERATE_X86_RELAX_RELOCATIONS, + $ac_default_x86_relax_relocations, + [Define to 1 if you want to generate x86 relax relocations by default.]) + +if test x$ac_default_compressed_debug_sections = xyes ; then AC_DEFINE(DEFAULT_FLAG_COMPRESS_DEBUG, 1, [Define if you want compressed debug sections by default.]) fi --- a/ld/configure 2016-01-25 09:54:11.000000000 +0100 +++ b/ld/configure 2016-04-27 17:07:03.826195955 +0200 @@ -17134,7 +17134,7 @@ fi done -if test x$ac_default_compressed_debug_sections == xyes ; then +if test x$ac_default_compressed_debug_sections = xyes ; then $as_echo "#define DEFAULT_FLAG_COMPRESS_DEBUG 1" >>confdefs.h --- a/ld/configure.ac 2015-11-13 09:27:42.000000000 +0100 +++ b/ld/configure.ac 2016-04-27 17:07:03.826195955 +0200 @@ -384,7 +384,7 @@ fi done -if test x$ac_default_compressed_debug_sections == xyes ; then +if test x$ac_default_compressed_debug_sections = xyes ; then AC_DEFINE(DEFAULT_FLAG_COMPRESS_DEBUG, 1, [Define if you want compressed debug sections by default.]) fi --- a/ld/emultempl/elf32.em 2015-11-13 09:27:42.000000000 +0100 +++ b/ld/emultempl/elf32.em 2016-04-27 17:07:04.274213859 +0200 @@ -1946,25 +1946,32 @@ return os; } + flags = s->flags; + if (!bfd_link_relocatable (&link_info)) + { + nexts = s; + while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts)) + != NULL) + if (nexts->output_section == NULL + && (nexts->flags & SEC_EXCLUDE) == 0 + && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 + && (nexts->owner->flags & DYNAMIC) == 0 + && nexts->owner->usrdata != NULL + && !(((lang_input_statement_type *) nexts->owner->usrdata) + ->flags.just_syms) + && _bfd_elf_match_sections_by_type (nexts->owner, nexts, + s->owner, s)) + flags = (((flags ^ SEC_READONLY) + | (nexts->flags ^ SEC_READONLY)) + ^ SEC_READONLY); + } + /* Decide which segment the section should go in based on the section name and section flags. We put loadable .note sections right after the .interp section, so that the PT_NOTE segment is stored right after the program headers where the OS can read it in the first page. */ - flags = s->flags; - nexts = s; - while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts)) != NULL) - if (nexts->output_section == NULL - && (nexts->flags & SEC_EXCLUDE) == 0 - && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 - && (nexts->owner->flags & DYNAMIC) == 0 - && nexts->owner->usrdata != NULL - && !(((lang_input_statement_type *) nexts->owner->usrdata) - ->flags.just_syms) - && _bfd_elf_match_sections_by_type (nexts->owner, nexts, s->owner, s)) - flags = (((flags ^ SEC_READONLY) | (nexts->flags ^ SEC_READONLY)) - ^ SEC_READONLY); place = NULL; if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0) place = &hold[orphan_nonalloc]; --- a/ld/emultempl/mmo.em 2015-11-13 09:27:42.000000000 +0100 +++ b/ld/emultempl/mmo.em 2016-04-27 17:07:04.274213859 +0200 @@ -107,22 +107,28 @@ return os; } + flags = s->flags; + if (!bfd_link_relocatable (&link_info)) + { + nexts = s; + while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts)) + != NULL) + if (nexts->output_section == NULL + && (nexts->flags & SEC_EXCLUDE) == 0 + && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 + && (nexts->owner->flags & DYNAMIC) == 0 + && nexts->owner->usrdata != NULL + && !(((lang_input_statement_type *) nexts->owner->usrdata) + ->flags.just_syms)) + flags = (((flags ^ SEC_READONLY) | (nexts->flags ^ SEC_READONLY)) + ^ SEC_READONLY); + } + /* Check for matching section type flags for sections we care about. A section without contents can have SEC_LOAD == 0, but we still want it attached to a sane section so the symbols appear as expected. */ - flags = s->flags; - nexts = s; - while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts)) != NULL) - if (nexts->output_section == NULL - && (nexts->flags & SEC_EXCLUDE) == 0 - && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 - && (nexts->owner->flags & DYNAMIC) == 0 - && nexts->owner->usrdata != NULL - && !(((lang_input_statement_type *) nexts->owner->usrdata) - ->flags.just_syms)) - flags = (((flags ^ SEC_READONLY) | (nexts->flags ^ SEC_READONLY)) - ^ SEC_READONLY); + if ((flags & (SEC_ALLOC | SEC_READONLY)) != SEC_READONLY) for (i = 0; i < sizeof (holds) / sizeof (holds[0]); i++) if ((flags & holds[i].nonzero_flags) != 0) --- a/ld/emultempl/pe.em 2015-11-13 09:27:42.000000000 +0100 +++ b/ld/emultempl/pe.em 2016-04-27 17:07:04.275213899 +0200 @@ -2225,21 +2225,27 @@ orphan_init_done = 1; } + flags = s->flags; + if (!bfd_link_relocatable (&link_info)) + { + nexts = s; + while ((nexts = bfd_get_next_section_by_name (nexts->owner, + nexts))) + if (nexts->output_section == NULL + && (nexts->flags & SEC_EXCLUDE) == 0 + && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 + && (nexts->owner->flags & DYNAMIC) == 0 + && nexts->owner->usrdata != NULL + && !(((lang_input_statement_type *) nexts->owner->usrdata) + ->flags.just_syms)) + flags = (((flags ^ SEC_READONLY) + | (nexts->flags ^ SEC_READONLY)) + ^ SEC_READONLY); + } + /* Try to put the new output section in a reasonable place based on the section name and section flags. */ - flags = s->flags; - nexts = s; - while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))) - if (nexts->output_section == NULL - && (nexts->flags & SEC_EXCLUDE) == 0 - && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 - && (nexts->owner->flags & DYNAMIC) == 0 - && nexts->owner->usrdata != NULL - && !(((lang_input_statement_type *) nexts->owner->usrdata) - ->flags.just_syms)) - flags = (((flags ^ SEC_READONLY) | (nexts->flags ^ SEC_READONLY)) - ^ SEC_READONLY); place = NULL; if ((flags & SEC_ALLOC) == 0) ; --- a/ld/emultempl/pep.em 2015-11-13 09:27:42.000000000 +0100 +++ b/ld/emultempl/pep.em 2016-04-27 17:07:04.275213899 +0200 @@ -1996,21 +1996,27 @@ orphan_init_done = 1; } + flags = s->flags; + if (!bfd_link_relocatable (&link_info)) + { + nexts = s; + while ((nexts = bfd_get_next_section_by_name (nexts->owner, + nexts))) + if (nexts->output_section == NULL + && (nexts->flags & SEC_EXCLUDE) == 0 + && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 + && (nexts->owner->flags & DYNAMIC) == 0 + && nexts->owner->usrdata != NULL + && !(((lang_input_statement_type *) nexts->owner->usrdata) + ->flags.just_syms)) + flags = (((flags ^ SEC_READONLY) + | (nexts->flags ^ SEC_READONLY)) + ^ SEC_READONLY); + } + /* Try to put the new output section in a reasonable place based on the section name and section flags. */ - flags = s->flags; - nexts = s; - while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))) - if (nexts->output_section == NULL - && (nexts->flags & SEC_EXCLUDE) == 0 - && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0 - && (nexts->owner->flags & DYNAMIC) == 0 - && nexts->owner->usrdata != NULL - && !(((lang_input_statement_type *) nexts->owner->usrdata) - ->flags.just_syms)) - flags = (((flags ^ SEC_READONLY) | (nexts->flags ^ SEC_READONLY)) - ^ SEC_READONLY); place = NULL; if ((flags & SEC_ALLOC) == 0) ; --- a/ld/lexsup.c 2015-11-13 09:27:42.000000000 +0100 +++ b/ld/lexsup.c 2016-04-27 17:07:03.881198152 +0200 @@ -1586,15 +1586,14 @@ /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data, --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and --dynamic-list FILE. -Bsymbolic and -Bsymbolic-functions are - for shared libraries. -Bsymbolic overrides all others and vice - versa. */ + for PIC outputs. -Bsymbolic overrides all others and vice versa. */ switch (command_line.symbolic) { case symbolic_unset: break; case symbolic: - /* -Bsymbolic is for shared library only. */ - if (bfd_link_dll (&link_info)) + /* -Bsymbolic is for PIC output only. */ + if (bfd_link_pic (&link_info)) { link_info.symbolic = TRUE; /* Should we free the unused memory? */ @@ -1603,8 +1602,8 @@ } break; case symbolic_functions: - /* -Bsymbolic-functions is for shared library only. */ - if (bfd_link_dll (&link_info)) + /* -Bsymbolic-functions is for PIC output only. */ + if (bfd_link_pic (&link_info)) command_line.dynamic_list = dynamic_list_data; break; } --- a/ld/testsuite/ld-plugin/lto.exp 2015-11-13 09:27:42.000000000 +0100 +++ b/ld/testsuite/ld-plugin/lto.exp 2016-04-27 17:13:14.710567525 +0200 @@ -400,9 +400,20 @@ || [istarget "x86_64-*-linux*"] || [istarget "amd64-*-linux*"]) } { set testname "PR ld/12365" - set exec_output [run_host_cmd "$CC" "-O2 -flto -flto-partition=none -fuse-linker-plugin tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"] + set exec_output [run_host_cmd "$CC" "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"] if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } { + # Linker should catch the reference to undefined `my_bcopy' + # error caused by a GCC bug. pass $testname + } elseif { [ string match "" $exec_output ] } { + global READELF + set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"] + if { [ regexp "my_bcopy" $exec_output ] } { + # Verify that there is no `my_bcopy' symbol in executable. + fail $testname + } { + pass $testname + } } { fail $testname } --- a/opcodes/i386-dis.c 2016-01-25 09:51:06.000000000 +0100 +++ b/opcodes/i386-dis.c 2016-04-27 17:07:03.926199949 +0200 @@ -13644,7 +13644,7 @@ if (op_index[i] != -1 && op_riprel[i]) { (*info->fprintf_func) (info->stream, " # "); - (*info->print_address_func) ((bfd_vma) (start_pc + codep - start_codep + (*info->print_address_func) ((bfd_vma) (start_pc + (codep - start_codep) + op_address[op_index[i]]), info); break; } @@ -16158,7 +16158,7 @@ the displacement is added! */ mask = 0xffff; if ((prefixes & PREFIX_DATA) == 0) - segment = ((start_pc + codep - start_codep) + segment = ((start_pc + (codep - start_codep)) & ~((bfd_vma) 0xffff)); } if (address_mode != mode_64bit