code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-009

Bug-Reported-by:	Julien Moutinho <julm+bash@sourcephile.fr>
Bug-Reference-ID:	<20211004035906.5kiobuzkpeckmvwg@sourcephile.fr>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2021-10/msg00022.html

Bug-Description:

The bash malloc implementation of malloc_usable_size() does not follow the
specification. This can cause library functions that use it to overwrite
memory bounds checking.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/lib/malloc/malloc.c	2020-07-08 10:19:30.000000000 -0400
--- lib/malloc/malloc.c	2021-10-05 16:10:55.000000000 -0400
***************
*** 1287,1297 ****
      }

!   /* XXX - should we return 0 if ISFREE? */
!   maxbytes = binsize(p->mh_index);
!
!   /* So the usable size is the maximum number of bytes in the bin less the
!      malloc overhead */
!   maxbytes -= MOVERHEAD + MSLOP;
!   return (maxbytes);
  }

--- 1358,1367 ----
      }

!   /* return 0 if ISFREE */
!   if (p->mh_alloc == ISFREE)
!     return 0;
!
!   /* Since we use bounds checking, the usable size is the last requested size. */
!   return (p->mh_nbytes);
  }

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 8

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 9

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-010

Bug-Reported-by:	Jonas Alfredsson <jonas.alfredsson@protonmail.com>
Bug-Reference-ID:	<LjAfZaEuZncr2RaqhSSfcaiXdkuK6kdEYxshP3LApXbgMVQzggMGyWHO9knVkXicW2fP-ibsipJ_GZ-YaJRm96Rsozf6PgFmPsljRCtflls=@protonmail.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2021-05/msg00059.html

Bug-Description:

If `wait -n' is interrupted by a trapped signal other than SIGINT, it does
not completely clean up state, and that can prevent subsequent calls to
`wait -n' from working correctly.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/builtins/wait.def	2020-12-16 17:13:12.000000000 -0500
--- builtins/wait.def	2021-11-17 10:25:15.000000000 -0500
***************
*** 112,116 ****
       WORD_LIST *list;
  {
!   int status, code, opt, nflag, wflags;
    char *vname;
    SHELL_VAR *pidvar;
--- 112,117 ----
       WORD_LIST *list;
  {
!   int status, code, opt, nflag;
!   volatile int wflags;
    char *vname;
    SHELL_VAR *pidvar;
***************
*** 181,184 ****
--- 188,193 ----
        status = 128 + wait_signal_received;
        wait_sigint_cleanup ();
+       if (wflags & JWAIT_WAITING)
+ 	unset_waitlist ();
        WAIT_RETURN (status);
      }

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 9

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 10

  #endif /* _PATCHLEVEL_H_ */

repo_name: dustdfg/dragora

license: mit


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-011

Bug-Reported-by:	Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
Bug-Reference-ID:	<CAALKErFrm+yuwy=ioK+RmjCiwxTDmzeMFWqLF2BEWYtkGS5UFQ@mail.gmail.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2020-11/msg00064.html

Bug-Description:

When reading a compound assignment, and running it through the parser to
split it into words, we need to save and restore any alias we're currently
expanding.

Patch (apply with `patch -p0'):

*** ../bash-5.1-patched/parse.y	2020-11-28 12:10:06.000000000 -0500
--- parse.y	2021-10-13 11:04:27.000000000 -0400
***************
*** 6494,6501 ****

    push_stream (1);
- #if 0 /* TAG: bash-5.2 Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> 11/17/2020 */
    if (ea = expanding_alias ())
      parser_save_alias ();
- #endif
    last_read_token = WORD;		/* WORD to allow reserved words here */
    current_command_line_count = 0;
--- 6494,6499 ----
***************
*** 6532,6539 ****
    pop_stream ();

- #if 0 /* TAG: bash-5.2 */
    if (ea)
      parser_restore_alias ();
- #endif

  #if defined (HISTORY)
--- 6530,6535 ----
*** ../bash-5.1-patched/y.tab.c	2020-11-28 12:17:19.000000000 -0500
--- y.tab.c	2021-11-17 10:47:35.000000000 -0500
***************
*** 8788,8795 ****

    push_stream (1);
- #if 0 /* TAG: bash-5.2 Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> 11/17/2020 */
    if (ea = expanding_alias ())
      parser_save_alias ();
- #endif
    last_read_token = WORD;		/* WORD to allow reserved words here */
    current_command_line_count = 0;
--- 8777,8782 ----
***************
*** 8826,8833 ****
    pop_stream ();

- #if 0 /* TAG: bash-5.2 */
    if (ea)
      parser_restore_alias ();
- #endif

  #if defined (HISTORY)
--- 8813,8818 ----
*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 10

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 11

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-012

Bug-Reported-by:	Nikolay Borisov <nborisov@suse.com>
Bug-Reference-ID:	<1a715205-06ce-413b-c1c0-2f5639ce06c0@suse.com>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2020-11/msg00091.html

Bug-Description:

There is a possible race condition that arises when a child process receives
a signal trapped by the parent before it can reset the signal dispositions.
The child process is not supposed to trap the signal in this circumstance.

Patch (apply with `patch -p0'):

*** ../bash-20201118/command.h	2020-08-14 15:04:39.000000000 -0400
--- command.h	2020-11-27 15:18:02.000000000 -0500
***************
*** 125,128 ****
--- 125,129 ----
  #define SUBSHELL_COPROC	0x40	/* subshell from a coproc pipeline */
  #define SUBSHELL_RESETTRAP 0x80	/* subshell needs to reset trap strings on first call to trap */
+ #define SUBSHELL_IGNTRAP 0x100  /* subshell should reset trapped signals from trap_handler */

  /* A structure which represents a word. */

*** ../bash-20201118/execute_cmd.c	2020-11-23 14:16:48.000000000 -0500
--- execute_cmd.c	2020-11-27 16:43:25.000000000 -0500
***************
*** 1548,1551 ****
--- 1548,1554 ----
    reset_signal_handlers ();
    subshell_environment |= SUBSHELL_RESETTRAP;
+   /* Note that signal handlers have been reset, so we should no longer
+     reset the handler and resend trapped signals to ourselves. */
+   subshell_environment &= ~SUBSHELL_IGNTRAP;

    /* We are in a subshell, so forget that we are running a trap handler or
***************
*** 4321,4325 ****
  	  cmdflags |= CMD_NO_FORK;

! 	  subshell_environment = SUBSHELL_FORK;		/* XXX */
  	  if (pipe_in != NO_PIPE || pipe_out != NO_PIPE)
  	    subshell_environment |= SUBSHELL_PIPE;
--- 4324,4329 ----
  	  cmdflags |= CMD_NO_FORK;

! 	  /* We redo some of what make_child() does with SUBSHELL_IGNTRAP */
! 	  subshell_environment = SUBSHELL_FORK|SUBSHELL_IGNTRAP;	/* XXX */
  	  if (pipe_in != NO_PIPE || pipe_out != NO_PIPE)
  	    subshell_environment |= SUBSHELL_PIPE;
***************
*** 4575,4578 ****
--- 4580,4584 ----
  	  reset_signal_handlers ();
  	  subshell_environment |= SUBSHELL_RESETTRAP;
+ 	  subshell_environment &= ~SUBSHELL_IGNTRAP;

  	  if (async)
***************
*** 5515,5518 ****
--- 5521,5525 ----
        /* Cancel traps, in trap.c. */
        restore_original_signals ();
+       subshell_environment &= ~SUBSHELL_IGNTRAP;

  #if defined (JOB_CONTROL)

*** ../bash-20201118/jobs.c	2020-08-04 10:17:39.000000000 -0400
--- jobs.c	2020-11-27 16:39:56.000000000 -0500
***************
*** 2218,2221 ****
--- 2218,2223 ----
        pid_t mypid;

+       subshell_environment |= SUBSHELL_IGNTRAP;
+
        /* If this ends up being changed to modify or use `command' in the
  	 child process, go back and change callers who free `command' in
diff -rC 2 ../bash-20201118/nojobs.c nojobs.c
*** ../bash-20201118/nojobs.c	2020-07-08 10:11:25.000000000 -0400
--- nojobs.c	2020-11-27 16:38:36.000000000 -0500
***************
*** 576,579 ****
--- 576,581 ----
  #endif

+       subshell_environment |= SUBSHELL_IGNTRAP;
+
        default_tty_job_signals ();
      }

*** ../bash-20201118/sig.c	2020-11-23 13:22:17.000000000 -0500
--- sig.c	2020-11-28 10:21:43.000000000 -0500
***************
*** 56,60 ****
  #endif

! extern void initialize_siglist ();

  #if !defined (JOB_CONTROL)
--- 56,61 ----
  #endif

! extern void initialize_siglist PARAMS((void));
! extern void set_original_signal PARAMS((int, SigHandler *));

  #if !defined (JOB_CONTROL)
***************
*** 256,259 ****
--- 257,267 ----
        XHANDLER(i) = oact.sa_handler;
        XSAFLAGS(i) = oact.sa_flags;
+
+ #if 0
+       set_original_signal (XSIG(i), XHANDLER(i));	/* optimization */
+ #else
+       set_original_signal (XSIG(i), act.sa_handler);	/* optimization */
+ #endif
+
        /* Don't do anything with signals that are ignored at shell entry
  	 if the shell is not interactive. */

*** ../bash-20201118/subst.c	2020-11-16 10:33:15.000000000 -0500
--- subst.c	2020-11-27 16:07:00.000000000 -0500
***************
*** 5952,5955 ****
--- 5952,5956 ----
        /* Cancel traps, in trap.c. */
        restore_original_signals ();	/* XXX - what about special builtins? bash-4.2 */
+       subshell_environment &= ~SUBSHELL_IGNTRAP;
        QUIT;	/* catch any interrupts we got post-fork */
        setup_async_signals ();
***************
*** 6383,6386 ****
--- 6384,6388 ----
        QUIT;	/* catch any interrupts we got post-fork */
        subshell_environment |= SUBSHELL_RESETTRAP;
+       subshell_environment &= ~SUBSHELL_IGNTRAP;
      }

diff -rC 2 ../bash-20201118/trap.c trap.c
*** ../bash-20201118/trap.c	2020-11-28 12:04:07.000000000 -0500
--- trap.c	2020-11-28 10:22:10.000000000 -0500
***************
*** 482,485 ****
--- 482,511 ----
      }

+   /* This means we're in a subshell, but have not yet reset the handler for
+      trapped signals. We're not supposed to execute the trap in this situation;
+      we should restore the original signal and resend the signal to ourselves
+      to preserve the Posix "signal traps that are not being ignored shall be
+      set to the default action" semantics. */
+   if ((subshell_environment & SUBSHELL_IGNTRAP) && trap_list[sig] != (char *)IGNORE_SIG)
+     {
+       sigset_t mask;
+
+       /* Paranoia */
+       if (original_signals[sig] == IMPOSSIBLE_TRAP_HANDLER)
+ 	original_signals[sig] = SIG_DFL;
+
+       restore_signal (sig);
+
+       /* Make sure we let the signal we just caught through */
+       sigemptyset (&mask);
+       sigprocmask (SIG_SETMASK, (sigset_t *)NULL, &mask);
+       sigdelset (&mask, sig);
+       sigprocmask (SIG_SETMASK, &mask, (sigset_t *)NULL);
+
+       kill (getpid (), sig);
+
+       SIGRETURN (0);
+     }
+
    if ((sig >= NSIG) ||
        (trap_list[sig] == (char *)DEFAULT_SIG) ||

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 11

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 12

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-013

Bug-Reported-by:	Anders Kaseorg <andersk@mit.edu>
Bug-Reference-ID:	<de65540274064d7b95f17e9c46a3a6d8@oc11expo7.exchange.mit.edu>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2021-11/msg00025.html

Bug-Description:

Bash did not always perform tilde expansion following an unquoted colon on
the rhs of an assignment statement in posix mode.

Patch (apply with `patch -p0'):

*** ../bash-20211028/subst.c	2021-10-18 16:09:58.000000000 -0400
--- subst.c	2021-11-30 11:19:47.000000000 -0500
***************
*** 3826,3829 ****
--- 3826,3830 ----
    td.flags = W_ASSIGNRHS;
  #endif
+   td.flags |= (W_NOGLOB|W_TILDEEXP);
    td.word = savestring (string);
    value = call_expand_word_internal (&td, quoted, 0, (int *)NULL, (int *)NULL);

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 12

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 13

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-014

Bug-Reported-by:	platon7pronko@gmail.com
Bug-Reference-ID:
Bug-Reference-URL:	https://savannah.gnu.org/patch/?10035

Bug-Description:

Bash may produce corrupted input if a multibyte character spans a 512-byte
boundary while reading the output of a command substitution.

Patch (apply with `patch -p0'):

*** ../bash-20210217/subst.c	2021-02-03 10:32:08.000000000 -0500
--- subst.c	2021-03-01 16:47:52.000000000 -0500
***************
*** 6243,6247 ****
  	  /* punt on the hard case for now */
  	  memset (&ps, '\0', sizeof (mbstate_t));
! 	  mblen = mbrtowc (&wc, bufp-1, bufn+1, &ps);
  	  if (MB_INVALIDCH (mblen) || mblen == 0 || mblen == 1)
  	    istring[istring_index++] = c;
--- 6243,6247 ----
  	  /* punt on the hard case for now */
  	  memset (&ps, '\0', sizeof (mbstate_t));
! 	  mblen = mbrtowc (&wc, bufp-1, bufn, &ps);
  	  if (MB_INVALIDCH (mblen) || mblen == 0 || mblen == 1)
  	    istring[istring_index++] = c;

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 13

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 14

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-015

Bug-Reported-by:	Volodymyr Prodan <vovcat@gmail.com>
Bug-Reference-ID:
Bug-Reference-URL:	https://savannah.gnu.org/patch/?10076

Bug-Description:

Patch (apply with `patch -p0'):

There are some characters (e.g., cyrillic) that can't be displayed using
certain single-byte encodings (e.g., cp1251) because the negative signed
int is interpreted as EOF and not displayed.

*** ../bash-20210524/lib/readline/display.c	2021-03-16 18:12:20.000000000 -0400
--- lib/readline/display.c	2021-06-07 16:53:08.000000000 -0400
***************
*** 1599,1603 ****

    for (cur_face = FACE_NORMAL, i = 0; i < n; i++)
!     putc_face (str[i], face[i], &cur_face);
    putc_face (EOF, FACE_NORMAL, &cur_face);
  }
--- 1599,1603 ----

    for (cur_face = FACE_NORMAL, i = 0; i < n; i++)
!     putc_face ((unsigned char) str[i], face[i], &cur_face);
    putc_face (EOF, FACE_NORMAL, &cur_face);
  }

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 14

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 15

  #endif /* _PATCHLEVEL_H_ */


code:
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.1
Patch-ID:	bash51-016

Bug-Reported-by:	Vincent Menegaux <vincent.menegaux@gmail.com>
Bug-Reference-ID:
Bug-Reference-URL:	https://savannah.gnu.org/patch/?10070

Bug-Description:

Multiple `!' tokens should toggle negation of an expression in a [[
conditional command, instead of simply negating the expression.

Patch (apply with `patch -p0'):

*** ../bash-20210515/parse.y	2021-04-21 15:32:50.000000000 -0400
--- parse.y	2021-05-24 11:53:30.000000000 -0400
***************
*** 4797,4801 ****
        term = cond_term ();
        if (term)
! 	term->flags |= CMD_INVERT_RETURN;
      }
    else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[1] && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
--- 4797,4801 ----
        term = cond_term ();
        if (term)
! 	term->flags ^= CMD_INVERT_RETURN;
      }
    else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[1] && yylval.word->word[2] == 0 && test_unop (yylval.word->word))

*** ../bash-20210515/y.tab.c	2021-05-14 15:50:41.000000000 -0400
--- y.tab.c	2021-05-24 16:35:55.000000000 -0400
***************
*** 7091,7095 ****
        term = cond_term ();
        if (term)
! 	term->flags |= CMD_INVERT_RETURN;
      }
    else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[1] && yylval.word->word[2] == 0 && test_unop (yylval.word->word))
--- 7091,7095 ----
        term = cond_term ();
        if (term)
! 	term->flags ^= CMD_INVERT_RETURN;
      }
    else if (tok == WORD && yylval.word->word[0] == '-' && yylval.word->word[1] && yylval.word->word[2] == 0 && test_unop (yylval.word->word))

*** ../bash-5.1/patchlevel.h	2020-06-22 14:51:03.000000000 -0400
--- patchlevel.h	2020-10-01 11:01:28.000000000 -0400
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 15

  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */

! #define PATCHLEVEL 16

  #endif /* _PATCHLEVEL_H_ */


code:
diff -rup binutils.orig/bfd/elfnn-aarch64.c binutils-2.27/bfd/elfnn-aarch64.c
--- binutils.orig/bfd/elfnn-aarch64.c	2017-02-21 10:45:19.311956006 +0000
+++ binutils-2.27/bfd/elfnn-aarch64.c	2017-02-21 11:55:07.517922655 +0000
@@ -4947,6 +4947,7 @@ elfNN_aarch64_final_link_relocate (reloc
      it here if it is defined in a non-shared object.  */
   if (h != NULL
       && h->type == STT_GNU_IFUNC
+      && (input_section->flags & SEC_ALLOC)
       && h->def_regular)
     {
       asection *plt;


code:
--- binutils.orig/gold/fileread.cc	2019-08-06 14:22:08.669313110 +0100
+++ binutils-2.32/gold/fileread.cc	2019-08-06 14:22:28.799177543 +0100
@@ -381,6 +381,12 @@ File_read::do_read(off_t start, section_
   ssize_t bytes;
   if (this->whole_file_view_ != NULL)
     {
+      // See PR 23765 for an example of a testcase that triggers this error.
+      if (((ssize_t) start) < 0)
+	gold_fatal(_("%s: read failed, starting offset (%#llx) less than zero"),
+		   this->filename().c_str(),
+		   static_cast<long long>(start));
+
       bytes = this->size_ - start;
       if (static_cast<section_size_type>(bytes) >= size)
 	{


code:
--- binutils.orig/config/override.m4	2021-08-31 14:20:17.275574804 +0100
+++ binutils-2.37/config/override.m4	2021-08-31 14:36:37.793954247 +0100
@@ -41,7 +41,7 @@ dnl Or for updating the whole tree at on
 AC_DEFUN([_GCC_AUTOCONF_VERSION_CHECK],
 [m4_if(m4_defn([_GCC_AUTOCONF_VERSION]),
   m4_defn([m4_PACKAGE_VERSION]), [],
-  [m4_fatal([Please use exactly Autoconf ]_GCC_AUTOCONF_VERSION[ instead of ]m4_defn([m4_PACKAGE_VERSION])[.])])
+  [])
 ])
 m4_define([AC_INIT], m4_defn([AC_INIT])[
 _GCC_AUTOCONF_VERSION_CHECK


code:
diff -rup binutils.orig/configure binutils-2.30/configure
--- binutils.orig/configure	2018-09-24 17:50:06.967172922 +0100
+++ binutils-2.30/configure	2018-09-24 17:51:16.648624865 +0100
@@ -4996,49 +4996,6 @@ if test -z "$LD"; then
   fi
 fi

-# Check whether -static-libstdc++ -static-libgcc is supported.
-have_static_libs=no
-if test "$GCC" = yes; then
-  saved_LDFLAGS="$LDFLAGS"
-
-  LDFLAGS="$LDFLAGS -static-libstdc++ -static-libgcc"
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether g++ accepts -static-libstdc++ -static-libgcc" >&5
-$as_echo_n "checking whether g++ accepts -static-libstdc++ -static-libgcc... " >&6; }
-  ac_ext=cpp
-ac_cpp='$CXXCPP $CPPFLAGS'
-ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
-
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-#if (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
-#error -static-libstdc++ not implemented
-#endif
-int main() {}
-_ACEOF
-if ac_fn_cxx_try_link "$LINENO"; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }; have_static_libs=yes
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-  ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-
-  LDFLAGS="$saved_LDFLAGS"
-fi
-
-

 if test -n "$ac_tool_prefix"; then
diff -rup binutils.orig/configure.ac binutils-2.30/configure.ac
--- binutils.orig/configure.ac	2018-09-24 17:50:07.241170767 +0100
+++ binutils-2.30/configure.ac	2018-09-24 17:50:29.908992486 +0100
@@ -1288,26 +1288,6 @@ if test -z "$LD"; then
   fi
 fi

-# Check whether -static-libstdc++ -static-libgcc is supported.
-have_static_libs=no
-if test "$GCC" = yes; then
-  saved_LDFLAGS="$LDFLAGS"
-
-  LDFLAGS="$LDFLAGS -static-libstdc++ -static-libgcc"
-  AC_MSG_CHECKING([whether g++ accepts -static-libstdc++ -static-libgcc])
-  AC_LANG_PUSH(C++)
-  AC_LINK_IFELSE([AC_LANG_SOURCE([
-#if (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
-#error -static-libstdc++ not implemented
-#endif
-int main() {}])],
-    [AC_MSG_RESULT([yes]); have_static_libs=yes],
-    [AC_MSG_RESULT([no])])
-  AC_LANG_POP(C++)
-
-  LDFLAGS="$saved_LDFLAGS"
-fi
-
 ACX_PROG_GNAT
 ACX_PROG_CMP_IGNORE_INITIAL


code:
diff -rup binutils.orig/binutils/NEWS binutils-2.38/binutils/NEWS
--- binutils.orig/binutils/NEWS	2022-03-10 09:13:18.284641005 +0000
+++ binutils-2.38/binutils/NEWS	2022-03-10 09:13:26.007586352 +0000
@@ -1,5 +1,8 @@
 -*- text -*-

+* Add an option to objdump and readelf to prevent attempts to access debuginfod
+  servers when following links.
+
 Changes in 2.38:

 * elfedit: Add --output-abiversion option to update ABIVERSION.
diff -rup binutils.orig/binutils/doc/binutils.texi binutils-2.38/binutils/doc/binutils.texi
--- binutils.orig/binutils/doc/binutils.texi	2022-03-10 09:13:18.285640998 +0000
+++ binutils-2.38/binutils/doc/binutils.texi	2022-03-10 09:13:26.009586338 +0000
@@ -2246,6 +2246,8 @@ objdump [@option{-a}|@option{--archive-h
          @option{--dwarf}[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,=trace_info,=trace_abbrev,=trace_aranges,=gdb_index,=addr,=cu_index,=links]]
         [@option{-WK}|@option{--dwarf=follow-links}]
         [@option{-WN}|@option{--dwarf=no-follow-links}]
+        [@option{-wD}|@option{--dwarf=use-debuginfod}]
+        [@option{-wE}|@option{--dwarf=do-not-use-debuginfod}]
         [@option{-L}|@option{--process-links}]
         [@option{--ctf=}@var{section}]
         [@option{-G}|@option{--stabs}]
@@ -4879,6 +4881,8 @@ readelf [@option{-a}|@option{--all}]
          @option{--debug-dump}[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,=trace_info,=trace_abbrev,=trace_aranges,=gdb_index,=addr,=cu_index,=links]]
         [@option{-wK}|@option{--debug-dump=follow-links}]
         [@option{-wN}|@option{--debug-dump=no-follow-links}]
+        [@option{-wD}|@option{--debug-dump=use-debuginfod}]
+        [@option{-wE}|@option{--debug-dump=do-not-use-debuginfod}]
         [@option{-P}|@option{--process-links}]
         [@option{--dwarf-depth=@var{n}}]
         [@option{--dwarf-start=@var{n}}]
@@ -5504,7 +5508,8 @@ deduced from the input file
 @cindex separate debug files

 debuginfod is a web service that indexes ELF/DWARF debugging resources
-by build-id and serves them over HTTP.
+by build-id and serves them over HTTP.  For more information see:
+@emph{https://sourceware.org/elfutils/Debuginfod.html}

 Binutils can be built with the debuginfod client library
 @code{libdebuginfod} using the @option{--with-debuginfod} configure option.
@@ -5516,6 +5521,10 @@ separate debug files when the files are
 debuginfod is packaged with elfutils, starting with version 0.178.
 You can get the latest version from `https://sourceware.org/elfutils/'.

+The DWARF info dumping tools (@command{readelf} and @command{objdump})
+have options to control when they should access the debuginfod
+servers.  By default this access is enabled.
+
 @node Reporting Bugs
 @chapter Reporting Bugs
 @cindex bugs
Only in binutils-2.38/binutils/doc: binutils.texi.orig
diff -rup binutils.orig/binutils/doc/debug.options.texi binutils-2.38/binutils/doc/debug.options.texi
--- binutils.orig/binutils/doc/debug.options.texi	2022-03-10 09:13:18.285640998 +0000
+++ binutils-2.38/binutils/doc/debug.options.texi	2022-03-10 09:13:26.009586338 +0000
@@ -68,10 +68,27 @@ chosen when configuring the binutils via
 @option{--enable-follow-debug-links=no} options.  If these are not
 used then the default is to enable the following of debug links.

+Note - if support for the debuginfod protocol was enabled when the
+binutils were built then this option will also include an attempt to
+contact any debuginfod servers mentioned in the @var{DEBUGINFOD_URLS}
+environment variable.  This could take some time to resolve.  This
+behaviour can be disabled via the @option{=do-not-use-debuginfod} debug
+option.
+
 @item N
 @itemx =no-follow-links
 Disables the following of links to separate debug info files.

+@item D
+@itemx =use-debuginfod
+Enables contacting debuginfod servers if there is a need to follow
+debug links.  This is the default behaviour.
+
+@item E
+@itemx =do-not-use-debuginfod
+Disables contacting debuginfod servers when there is a need to follow
+debug links.
+
 @item l
 @itemx =rawline
 Displays the contents of the @samp{.debug_line} section in a raw
diff -rup binutils.orig/binutils/dwarf.c binutils-2.38/binutils/dwarf.c
--- binutils.orig/binutils/dwarf.c	2022-03-10 09:13:18.283641012 +0000
+++ binutils-2.38/binutils/dwarf.c	2022-03-10 09:13:26.010586331 +0000
@@ -109,6 +109,9 @@ int do_debug_cu_index;
 int do_wide;
 int do_debug_links;
 int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS;
+#ifdef HAVE_LIBDEBUGINFOD
+int use_debuginfod = 1;
+#endif
 bool do_checks;

 int dwarf_cutoff_level = -1;
@@ -11038,7 +11041,7 @@ debuginfod_fetch_separate_debug_info (st

   return false;
 }
-#endif
+#endif /* HAVE_LIBDEBUGINFOD  */

 static void *
 load_separate_debug_info (const char *            main_filename,
@@ -11157,9 +11160,10 @@ load_separate_debug_info (const char *
   {
     char * tmp_filename;

-    if (debuginfod_fetch_separate_debug_info (xlink,
-                                              & tmp_filename,
-                                              file))
+    if (use_debuginfod
+	&& debuginfod_fetch_separate_debug_info (xlink,
+						 & tmp_filename,
+						 file))
       {
         /* File successfully downloaded from server, replace
            debug_filename with the file's path.  */
@@ -11207,13 +11211,15 @@ load_separate_debug_info (const char *
       warn (_("tried: %s\n"), debug_filename);

 #if HAVE_LIBDEBUGINFOD
-      {
-	char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR);
-	if (urls == NULL)
-	  urls = "";
+      if (use_debuginfod)
+	{
+	  char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR);

-	warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls);
-      }
+	  if (urls == NULL)
+	    urls = "";
+
+	  warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls);
+	}
 #endif
     }

@@ -11707,6 +11713,9 @@ dwarf_select_sections_by_names (const ch
       { "aranges", & do_debug_aranges, 1 },
       { "cu_index", & do_debug_cu_index, 1 },
       { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
+#ifdef HAVE_LIBDEBUGINFOD
+      { "do-not-use-debuginfod", & use_debuginfod, 0 },
+#endif
       { "follow-links", & do_follow_links, 1 },
       { "frames", & do_debug_frames, 1 },
       { "frames-interp", & do_debug_frames_interp, 1 },
@@ -11730,6 +11739,9 @@ dwarf_select_sections_by_names (const ch
       { "trace_abbrev", & do_trace_abbrevs, 1 },
       { "trace_aranges", & do_trace_aranges, 1 },
       { "trace_info", & do_trace_info, 1 },
+#ifdef HAVE_LIBDEBUGINFOD
+      { "use-debuginfod", & use_debuginfod, 1 },
+#endif
       { NULL, NULL, 0 }
     };

@@ -11783,6 +11795,10 @@ dwarf_select_sections_by_letters (const
       case 'A':	do_debug_addr = 1; break;
       case 'a':	do_debug_abbrevs = 1; break;
       case 'c':	do_debug_cu_index = 1; break;
+#ifdef HAVE_LIBDEBUGINFOD
+      case 'D': use_debuginfod = 1; break;
+      case 'E': use_debuginfod = 0; break;
+#endif
       case 'F':	do_debug_frames_interp = 1; /* Fall through.  */
       case 'f':	do_debug_frames = 1; break;
       case 'g':	do_gdb_index = 1; break;
diff -rup binutils.orig/binutils/dwarf.h binutils-2.38/binutils/dwarf.h
--- binutils.orig/binutils/dwarf.h	2022-03-10 09:13:18.284641005 +0000
+++ binutils-2.38/binutils/dwarf.h	2022-03-10 09:13:26.010586331 +0000
@@ -224,6 +224,9 @@ extern int do_debug_cu_index;
 extern int do_wide;
 extern int do_debug_links;
 extern int do_follow_links;
+#ifdef HAVE_LIBDEBUGINFOD
+extern int use_debuginfod;
+#endif
 extern bool do_checks;

 extern int dwarf_cutoff_level;
diff -rup binutils.orig/binutils/objdump.c binutils-2.38/binutils/objdump.c
--- binutils.orig/binutils/objdump.c	2022-03-10 09:13:18.283641012 +0000
+++ binutils-2.38/binutils/objdump.c	2022-03-10 09:13:26.011586324 +0000
@@ -281,6 +281,14 @@ usage (FILE *stream, int status)
                            Do not follow links to separate debug info files\n\
                             (default)\n"));
 #endif
+#if HAVE_LIBDEBUGINFOD
+  fprintf (stream, _("\
+  -WD --dwarf=use-debuginfod\n\
+                           When following links, also query debuginfod servers (default)\n"));
+  fprintf (stream, _("\
+  -WE --dwarf=do-not-use-debuginfod\n\
+                           When following links, do not query debuginfod servers\n"));
+#endif
   fprintf (stream, _("\
   -L, --process-links      Display the contents of non-debug sections in\n\
                             separate debuginfo files.  (Implies -WK)\n"));
Only in binutils-2.38/binutils/: objdump.c.orig
diff -rup binutils.orig/binutils/readelf.c binutils-2.38/binutils/readelf.c
--- binutils.orig/binutils/readelf.c	2022-03-10 09:13:18.302640878 +0000
+++ binutils-2.38/binutils/readelf.c	2022-03-10 09:13:26.012586316 +0000
@@ -5126,6 +5126,14 @@ usage (FILE * stream)
                          Do not follow links to separate debug info files\n\
                           (default)\n"));
 #endif
+#if HAVE_LIBDEBUGINFOD
+  fprintf (stream, _("\
+  -wD --debug-dump=use-debuginfod\n\
+                         When following links, also query debuginfod servers (default)\n"));
+  fprintf (stream, _("\
+  -wE --debug-dump=do-not-use-debuginfod\n\
+                         When following links, do not query debuginfod servers\n"));
+#endif
   fprintf (stream, _("\
   --dwarf-depth=N        Do not display DIEs at depth N or greater\n"));
   fprintf (stream, _("\
Only in binutils-2.38/binutils/: readelf.c.orig
diff -rup binutils.orig/binutils/testsuite/binutils-all/debuginfod.exp binutils-2.38/binutils/testsuite/binutils-all/debuginfod.exp
--- binutils.orig/binutils/testsuite/binutils-all/debuginfod.exp	2022-03-10 09:13:18.291640956 +0000
+++ binutils-2.38/binutils/testsuite/binutils-all/debuginfod.exp	2022-03-10 09:13:26.012586316 +0000
@@ -185,8 +185,14 @@ proc test_fetch_debugaltlink { prog prog
 }

 if { [regexp ".*DEBUGINFOD.*" $conf_objdump] } {
-    test_fetch_debuglink $OBJDUMP "-W"
+    test_fetch_debuglink $OBJDUMP "-W -WD"
     test_fetch_debugaltlink $OBJDUMP "-Wk"
+
+    set test "disabling debuginfod access"
+    setup_xfail *-*-*
+    test_fetch_debuglink $OBJDUMP "-W -WE"
+    set test "debuginfod"
+
 } else {
     untested "$test (objdump not configured with debuginfod)"
 }
@@ -194,6 +200,12 @@ if { [regexp ".*DEBUGINFOD.*" $conf_objd
 if { [regexp ".*DEBUGINFOD.*" $conf_readelf] } {
     test_fetch_debuglink $READELF "-w"
     test_fetch_debugaltlink $READELF "-wk"
+
+    set test "disabling debuginfod access"
+    setup_xfail *-*-*
+    test_fetch_debuglink $READELF "-w -wE"
+    set test "debuginfod"
+
 } else {
     untested "$test (readelf not configured with debuginfod)"
 }


code:
diff -rup binutils.orig/bfd/Makefile.am binutils-2.32/bfd/Makefile.am
--- binutils.orig/bfd/Makefile.am	2019-02-08 12:22:51.395684251 +0000
+++ binutils-2.32/bfd/Makefile.am	2019-02-08 12:22:53.970664973 +0000
@@ -33,7 +33,7 @@ bfdlibdir = @bfdlibdir@
 bfdincludedir = @bfdincludedir@
 bfdlib_LTLIBRARIES = libbfd.la
 bfdinclude_HEADERS = $(BFD_H) $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
-		     $(INCDIR)/diagnostics.h $(INCDIR)/bfdlink.h
+		     $(INCDIR)/diagnostics.h $(INCDIR)/bfdlink.h $(INCDIR)/demangle.h
 else !INSTALL_LIBBFD
 # Empty these so that the respective installation directories will not be created.
 bfdlibdir =
diff -rup binutils.orig/bfd/Makefile.in binutils-2.32/bfd/Makefile.in
--- binutils.orig/bfd/Makefile.in	2019-02-08 12:21:35.291254044 +0000
+++ binutils-2.32/bfd/Makefile.in	2019-02-08 12:22:10.163992947 +0000
@@ -249,7 +249,7 @@ am__can_run_installinfo = \
   esac
 am__bfdinclude_HEADERS_DIST = $(INCDIR)/plugin-api.h bfd.h \
 	$(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
-	$(INCDIR)/diagnostics.h $(INCDIR)/bfdlink.h
+	$(INCDIR)/diagnostics.h $(INCDIR)/bfdlink.h $(INCDIR)/demangle.h
 HEADERS = $(bfdinclude_HEADERS)
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
   distclean-recursive maintainer-clean-recursive
@@ -468,7 +468,7 @@ libbfd_la_LDFLAGS = $(am__append_1) -rel
 @INSTALL_LIBBFD_FALSE@bfdinclude_HEADERS = $(am__append_2)
 @INSTALL_LIBBFD_TRUE@bfdinclude_HEADERS = $(BFD_H) \
 @INSTALL_LIBBFD_TRUE@	$(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \
-@INSTALL_LIBBFD_TRUE@	$(INCDIR)/diagnostics.h \
+@INSTALL_LIBBFD_TRUE@	$(INCDIR)/diagnostics.h $(INCDIR)/demangle.h \
 @INSTALL_LIBBFD_TRUE@	$(INCDIR)/bfdlink.h $(am__append_2)
 @INSTALL_LIBBFD_FALSE@rpath_bfdlibdir = @bfdlibdir@
 @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libbfd.la


code:
--- binutils.orig/binutils/readelf.c	2021-07-19 12:39:14.206556025 +0100
+++ binutils-2.37/binutils/readelf.c	2021-07-19 12:44:37.712728732 +0100
@@ -21873,45 +21873,52 @@ process_file (char * file_name)
   struct stat statbuf;
   char armag[SARMAG];
   bool ret = true;
+  char * name;
+  char * saved_program_name;
+
+  /* Overload program_name to include file_name.  Doing this means
+     that warning/error messages will positively identify the file
+     concerned even when multiple instances of readelf are running.  */
+  name = xmalloc (strlen (program_name) + strlen (file_name) + 3);
+  sprintf (name, "%s: %s", program_name, file_name);
+  saved_program_name = program_name;
+  program_name = name;

   if (stat (file_name, &statbuf) < 0)
     {
       if (errno == ENOENT)
-	error (_("'%s': No such file\n"), file_name);
+	error (_("No such file\n"));
       else
-	error (_("Could not locate '%s'.  System error message: %s\n"),
-	       file_name, strerror (errno));
-      return false;
+	error (_("Could not locate file.  System error message: %s\n"),
+	       strerror (errno));
+      goto done;
     }

   if (! S_ISREG (statbuf.st_mode))
     {
-      error (_("'%s' is not an ordinary file\n"), file_name);
-      return false;
+      error (_("Not an ordinary file\n"));
+      goto done;
     }

   filedata = calloc (1, sizeof * filedata);
   if (filedata == NULL)
     {
       error (_("Out of memory allocating file data structure\n"));
-      return false;
+      goto done;
     }

   filedata->file_name = file_name;
   filedata->handle = fopen (file_name, "rb");
   if (filedata->handle == NULL)
     {
-      error (_("Input file '%s' is not readable.\n"), file_name);
-      free (filedata);
-      return false;
+      error (_("Not readable\n"));
+      goto done;
     }

   if (fread (armag, SARMAG, 1, filedata->handle) != 1)
     {
-      error (_("%s: Failed to read file's magic number\n"), file_name);
-      fclose (filedata->handle);
-      free (filedata);
-      return false;
+      error (_("Failed to read file's magic number\n"));
+      goto done;
     }

   filedata->file_size = (bfd_size_type) statbuf.st_size;
@@ -21919,33 +21926,39 @@ process_file (char * file_name)

   if (memcmp (armag, ARMAG, SARMAG) == 0)
     {
-      if (! process_archive (filedata, false))
-	ret = false;
+      if (process_archive (filedata, false))
+	ret = true;
     }
   else if (memcmp (armag, ARMAGT, SARMAG) == 0)
     {
-      if ( ! process_archive (filedata, true))
-	ret = false;
+      if (process_archive (filedata, true))
+	ret = true;
     }
   else
     {
       if (do_archive_index && !check_all)
-	error (_("File %s is not an archive so its index cannot be displayed.\n"),
-	       file_name);
+	error (_("Not an archive so its index cannot be displayed.\n"));

       rewind (filedata->handle);
       filedata->archive_file_size = filedata->archive_file_offset = 0;

-      if (! process_object (filedata))
-	ret = false;
+      if (process_object (filedata))
+	ret = true;
     }

-  fclose (filedata->handle);
-  free (filedata->section_headers);
-  free (filedata->program_headers);
-  free (filedata->string_table);
-  free (filedata->dump.dump_sects);
-  free (filedata);
+ done:
+  if (filedata)
+    {
+      if (filedata->handle != NULL)
+	fclose (filedata->handle);
+      free (filedata->section_headers);
+      free (filedata->program_headers);
+      free (filedata->string_table);
+      free (filedata->dump.dump_sects);
+      free (filedata);
+    }
+  free (program_name);
+  program_name = saved_program_name;

   free (ba_cache.strtab);
   ba_cache.strtab = NULL;
--- binutils.orig/binutils/readelf.c	2021-08-10 10:15:22.088016072 +0100
+++ binutils-2.37/binutils/readelf.c	2021-08-10 10:15:55.567907891 +0100
@@ -21884,7 +21884,7 @@ process_file (char * file_name)
   Filedata * filedata = NULL;
   struct stat statbuf;
   char armag[SARMAG];
-  bool ret = true;
+  bool ret = false;
   char * name;
   char * saved_program_name;


code:
diff -rup binutils.orig/gas/symbols.c binutils-2.38/gas/symbols.c
--- binutils.orig/gas/symbols.c	2022-03-09 11:43:34.706610216 +0000
+++ binutils-2.38/gas/symbols.c	2022-03-09 11:45:57.540686508 +0000
@@ -61,8 +61,10 @@ struct symbol_flags
   /* Whether the symbol can be re-defined.  */
   unsigned int volatil : 1;

-  /* Whether the symbol is a forward reference.  */
+  /* Whether the symbol is a forward reference, and whether such has
+     been determined.  */
   unsigned int forward_ref : 1;
+  unsigned int forward_resolved : 1;

   /* This is set if the symbol is defined in an MRI common section.
      We handle such sections as single common symbols, so symbols
@@ -202,7 +204,7 @@ static void *
 symbol_entry_find (htab_t table, const char *name)
 {
   hashval_t hash = htab_hash_string (name);
-  symbol_entry_t needle = { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+  symbol_entry_t needle = { { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
 			      hash, name, 0, 0, 0 } };
   return htab_find_with_hash (table, &needle, hash);
 }
@@ -784,7 +786,9 @@ symbol_clone (symbolS *orgsymP, int repl
 symbolS *
 symbol_clone_if_forward_ref (symbolS *symbolP, int is_forward)
 {
-  if (symbolP && !symbolP->flags.local_symbol)
+  if (symbolP
+      && !symbolP->flags.local_symbol
+      && !symbolP->flags.forward_resolved)
     {
       symbolS *orig_add_symbol = symbolP->x->value.X_add_symbol;
       symbolS *orig_op_symbol = symbolP->x->value.X_op_symbol;
@@ -837,6 +841,7 @@ symbol_clone_if_forward_ref (symbolS *sy

       symbolP->x->value.X_add_symbol = add_symbol;
       symbolP->x->value.X_op_symbol = op_symbol;
+      symbolP->flags.forward_resolved = 1;
     }

   return symbolP;
diff -rup binutils.orig/gas/testsuite/gas/elf/dwarf2-18.d binutils-2.38/gas/testsuite/gas/elf/dwarf2-18.d
--- binutils.orig/gas/testsuite/gas/elf/dwarf2-18.d	2022-03-09 11:43:34.487611632 +0000
+++ binutils-2.38/gas/testsuite/gas/elf/dwarf2-18.d	2022-03-09 11:48:03.298873228 +0000
@@ -2,9 +2,8 @@
 #readelf: -x.rodata -wL
 #name: DWARF2 18
 # The am33 cr16 crx ft32 mn10 msp430 nds32 and rl78 targets do not evaluate the subtraction of symbols at assembly time.
-# The mep targets turns some view computations into complex relocations.
 # The riscv targets do not support the subtraction of symbols.
-#xfail: am3*-* cr16-* crx-* ft32*-* mep-* mn10*-* msp430-* nds32*-* riscv*-* rl78-*
+#xfail: am3*-* cr16-* crx-* ft32*-* mn10*-* msp430-* nds32*-* riscv*-* rl78-*

 Hex dump of section '\.rodata':
   0x00000000 0100 *.*
--- binutils.orig/gas/dwarf2dbg.c	2022-03-10 09:13:18.516639363 +0000
+++ binutils-2.38/gas/dwarf2dbg.c	2022-03-10 12:45:25.191933733 +0000
@@ -402,18 +402,27 @@ set_or_check_view (struct line_entry *e,
   if (viewx.X_op != O_constant || viewx.X_add_number)
     {
       expressionS incv;
+      expressionS *p_view;

       if (!p->loc.u.view)
-	{
-	  p->loc.u.view = symbol_temp_make ();
-	  gas_assert (!S_IS_DEFINED (p->loc.u.view));
-	}
+	p->loc.u.view = symbol_temp_make ();

       memset (&incv, 0, sizeof (incv));
       incv.X_unsigned = 1;
       incv.X_op = O_symbol;
       incv.X_add_symbol = p->loc.u.view;
       incv.X_add_number = 1;
+      p_view = symbol_get_value_expression (p->loc.u.view);
+      if (p_view->X_op == O_constant || p_view->X_op == O_symbol)
+	{
+	  /* If we can, constant fold increments so that a chain of
+	     expressions v + 1 + 1 ... + 1 is not created.
+	     resolve_expression isn't ideal for this purpose.  The
+	     base v might not be resolvable until later.  */
+	  incv.X_op = p_view->X_op;
+	  incv.X_add_symbol = p_view->X_add_symbol;
+	  incv.X_add_number = p_view->X_add_number + 1;
+	}

       if (viewx.X_op == O_constant)
 	{


code:
diff --git a/gold/i386.cc b/gold/i386.cc
index bf209fe9a86..31161ff091c 100644
--- a/gold/i386.cc
+++ b/gold/i386.cc
@@ -360,7 +360,11 @@ class Target_i386 : public Sized_target<32, false>
       got_(NULL), plt_(NULL), got_plt_(NULL), got_irelative_(NULL),
       got_tlsdesc_(NULL), global_offset_table_(NULL), rel_dyn_(NULL),
       rel_irelative_(NULL), copy_relocs_(elfcpp::R_386_COPY),
-      got_mod_index_offset_(-1U), tls_base_symbol_defined_(false)
+      got_mod_index_offset_(-1U), tls_base_symbol_defined_(false),
+      isa_1_used_(0), isa_1_needed_(0),
+      feature_1_(0), feature_2_used_(0), feature_2_needed_(0),
+      object_isa_1_used_(0), object_feature_1_(0),
+      object_feature_2_used_(0), seen_first_object_(false)
   { }

   // Process the relocations to determine unreferenced sections for
@@ -859,6 +863,21 @@ class Target_i386 : public Sized_target<32, false>
 				  this->rel_dyn_section(layout));
   }

+  // Record a target-specific program property in the .note.gnu.property
+  // section.
+  void
+  record_gnu_property(unsigned int, unsigned int, size_t,
+		      const unsigned char*, const Object*);
+
+  // Merge the target-specific program properties from the current object.
+  void
+  merge_gnu_properties(const Object*);
+
+  // Finalize the target-specific program properties and add them back to
+  // the layout.
+  void
+  do_finalize_gnu_properties(Layout*) const;
+
   // Information about this specific target which we pass to the
   // general Target structure.
   static const Target::Target_info i386_info;
@@ -898,6 +917,26 @@ class Target_i386 : public Sized_target<32, false>
   unsigned int got_mod_index_offset_;
   // True if the _TLS_MODULE_BASE_ symbol has been defined.
   bool tls_base_symbol_defined_;
+
+  // Target-specific program properties, from .note.gnu.property section.
+  // Each bit represents a specific feature.
+  uint32_t isa_1_used_;
+  uint32_t isa_1_needed_;
+  uint32_t feature_1_;
+  uint32_t feature_2_used_;
+  uint32_t feature_2_needed_;
+  // Target-specific properties from the current object.
+  // These bits get ORed into ISA_1_USED_ after all properties for the object
+  // have been processed. But if either is all zeroes (as when the property
+  // is absent from an object), the result should be all zeroes.
+  // (See PR ld/23486.)
+  uint32_t object_isa_1_used_;
+  // These bits get ANDed into FEATURE_1_ after all properties for the object
+  // have been processed.
+  uint32_t object_feature_1_;
+  uint32_t object_feature_2_used_;
+  // Whether we have seen our first object, for use in initializing FEATURE_1_.
+  bool seen_first_object_;
 };

 const Target::Target_info Target_i386::i386_info =
@@ -1042,6 +1081,126 @@ Target_i386::rel_irelative_section(Layout* layout)
   return this->rel_irelative_;
 }

+// Record a target-specific program property from the .note.gnu.property
+// section.
+void
+Target_i386::record_gnu_property(
+    unsigned int, unsigned int pr_type,
+    size_t pr_datasz, const unsigned char* pr_data,
+    const Object* object)
+{
+  uint32_t val = 0;
+
+  switch (pr_type)
+    {
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED:
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED:
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_USED:
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED:
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND:
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED:
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED:
+      if (pr_datasz != 4)
+	{
+	  gold_warning(_("%s: corrupt .note.gnu.property section "
+			 "(pr_datasz for property %d is not 4)"),
+		       object->name().c_str(), pr_type);
+	  return;
+	}
+      val = elfcpp::Swap<32, false>::readval(pr_data);
+      break;
+    default:
+      gold_warning(_("%s: unknown program property type 0x%x "
+		     "in .note.gnu.property section"),
+		   object->name().c_str(), pr_type);
+      break;
+    }
+
+  switch (pr_type)
+    {
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_USED:
+      this->object_isa_1_used_ |= val;
+      break;
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED:
+      this->isa_1_needed_ |= val;
+      break;
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND:
+      // If we see multiple feature props in one object, OR them together.
+      this->object_feature_1_ |= val;
+      break;
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED:
+      this->object_feature_2_used_ |= val;
+      break;
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED:
+      this->feature_2_needed_ |= val;
+      break;
+    }
+}
+
+// Merge the target-specific program properties from the current object.
+void
+Target_i386::merge_gnu_properties(const Object*)
+{
+  if (this->seen_first_object_)
+    {
+      // If any object is missing the ISA_1_USED property, we must omit
+      // it from the output file.
+      if (this->object_isa_1_used_ == 0)
+	this->isa_1_used_ = 0;
+      else if (this->isa_1_used_ != 0)
+	this->isa_1_used_ |= this->object_isa_1_used_;
+      this->feature_1_ &= this->object_feature_1_;
+      // If any object is missing the FEATURE_2_USED property, we must
+      // omit it from the output file.
+      if (this->object_feature_2_used_ == 0)
+	this->feature_2_used_ = 0;
+      else if (this->feature_2_used_ != 0)
+	this->feature_2_used_ |= this->object_feature_2_used_;
+    }
+  else
+    {
+      this->isa_1_used_ = this->object_isa_1_used_;
+      this->feature_1_ = this->object_feature_1_;
+      this->feature_2_used_ = this->object_feature_2_used_;
+      this->seen_first_object_ = true;
+    }
+  this->object_isa_1_used_ = 0;
+  this->object_feature_1_ = 0;
+  this->object_feature_2_used_ = 0;
+}
+
+static inline void
+add_property(Layout* layout, unsigned int pr_type, uint32_t val)
+{
+  unsigned char buf[4];
+  elfcpp::Swap<32, false>::writeval(buf, val);
+  layout->add_gnu_property(elfcpp::NT_GNU_PROPERTY_TYPE_0, pr_type, 4, buf);
+}
+
+// Finalize the target-specific program properties and add them back to
+// the layout.
+void
+Target_i386::do_finalize_gnu_properties(Layout* layout) const
+{
+  if (this->isa_1_used_ != 0)
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_ISA_1_USED,
+		 this->isa_1_used_);
+  if (this->isa_1_needed_ != 0)
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED,
+		 this->isa_1_needed_);
+  if (this->feature_1_ != 0)
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND,
+		 this->feature_1_);
+  if (this->feature_2_used_ != 0)
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED,
+		 this->feature_2_used_);
+  if (this->feature_2_needed_ != 0)
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED,
+		 this->feature_2_needed_);
+}
+
 // Write the first three reserved words of the .got.plt section.
 // The remainder of the section is written while writing the PLT
 // in Output_data_plt_i386::do_write.


code:
diff -rup binutils.orig/gold/layout.cc binutils-2.32/gold/layout.cc
--- binutils.orig/gold/layout.cc	2019-06-24 14:37:36.013086899 +0100
+++ binutils-2.32/gold/layout.cc	2019-06-24 14:41:40.054517479 +0100
@@ -868,6 +868,7 @@ Layout::get_output_section(const char* n
 		  && (same_name->flags() & elfcpp::SHF_TLS) == 0)
 		os = same_name;
 	    }
+#if 0 /* BZ 1722715, PR 17556.  */
 	  else if ((flags & elfcpp::SHF_TLS) == 0)
 	    {
 	      elfcpp::Elf_Xword zero_flags = 0;
@@ -878,6 +879,7 @@ Layout::get_output_section(const char* n
 	      if (p != this->section_name_map_.end())
 		os = p->second;
 	    }
+#endif
 	}

       if (os == NULL)


code:
Only in binutils-2.34/gold: autom4te.cache
diff -rup binutils.orig/gold/configure binutils-2.34/gold/configure
--- binutils.orig/gold/configure	2020-04-20 12:35:13.048297305 +0100
+++ binutils-2.34/gold/configure	2020-04-20 14:02:06.743725696 +0100
@@ -5180,7 +5180,8 @@ for targ in $target $canon_targets; do
     . ${srcdir}/configure.tgt

     if test "$targ_obj" = "UNKNOWN"; then
-      as_fn_error $? "\"unsupported target $targ\"" "$LINENO" 5
+      { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \"unsupported target $targ\"" >&5
+$as_echo "$as_me: WARNING: \"unsupported target $targ\"" >&2;}
     else
       targetobjs="$targetobjs ${targ_obj}.\$(OBJEXT)"
       if test "$targ_extra_obj" != ""; then
diff -rup binutils.orig/gold/configure.ac binutils-2.34/gold/configure.ac
--- binutils.orig/gold/configure.ac	2020-04-20 12:35:13.050297291 +0100
+++ binutils-2.34/gold/configure.ac	2020-04-20 14:01:46.435868770 +0100
@@ -181,7 +181,7 @@ for targ in $target $canon_targets; do
     . ${srcdir}/configure.tgt

     if test "$targ_obj" = "UNKNOWN"; then
-      AC_MSG_ERROR("unsupported target $targ")
+      AC_MSG_WARN("unsupported target $targ")
     else
       targetobjs="$targetobjs ${targ_obj}.\$(OBJEXT)"
       if test "$targ_extra_obj" != ""; then
--- binutils.orig/ld/configure.tgt	2020-04-20 12:35:12.465301359 +0100
+++ binutils-2.34/ld/configure.tgt	2020-04-20 14:17:52.123066333 +0100
@@ -220,7 +220,7 @@ bfin-*-linux-uclibc*)	targ_emul=elf32bfi
 			targ_extra_emuls="elf32bfin"
 			targ_extra_libpath=$targ_extra_emuls
 			;;
-bpf-*-*)		targ_emul=elf64bpf
+bpf-* | bpf-*-*)	targ_emul=elf64bpf
 			;;
 cr16-*-elf*)		targ_emul=elf32cr16
 			;;
@@ -1026,7 +1026,7 @@ z8k-*-coff)		targ_emul=z8002
 			targ_extra_ofiles=
 			;;
 *)
-  echo 2>&1 "*** ld does not support target ${targ}"
+  echo 2>&1 "*** ld does not support target '${targ}' NO REALLY"
   echo 2>&1 "*** see ld/configure.tgt for supported targets"
   exit 1

--- binutils.orig/bfd/config.bfd	2020-04-20 12:35:13.038297375 +0100
+++ binutils-2.34/bfd/config.bfd	2020-04-20 14:25:26.452869193 +0100
@@ -473,7 +473,7 @@ case "${targ}" in
     ;;

 #ifdef BFD64
-  bpf-*-none)
+  bpf-*-none | bpf-*)
     targ_defvec=bpf_elf64_le_vec
     targ_selvecs=bpf_elf64_be_vec
     targ_underscore=yes
@@ -1427,7 +1427,7 @@ case "${targ}" in
     ;;

   *)
-    echo 1>&2 "*** BFD does not support target ${targ}."
+    echo 1>&2 "*** BFD does not support target '${targ}'.  Honest."
     echo 1>&2 "*** Look in bfd/config.bfd for supported targets."
     exit 1
     ;;


code:
--- a/bfd/bfd-in.h	2012-08-02 10:56:34.561769686 +0100
+++ b/bfd/bfd-in.h	2012-08-02 11:13:27.134797755 +0100
@@ -25,11 +25,6 @@
 #ifndef __BFD_H_SEEN__
 #define __BFD_H_SEEN__

-/* PR 14072: Ensure that config.h is included first.  */
-#if !defined PACKAGE && !defined PACKAGE_VERSION
-#error config.h must be included before this header
-#endif
-
 #ifdef __cplusplus
 extern "C" {
 #endif
--- a/bfd/bfd-in2.h	2012-08-02 10:56:34.349769680 +0100
+++ b/bfd/bfd-in2.h	2012-08-02 11:13:40.015798113 +0100
@@ -32,11 +32,6 @@
 #ifndef __BFD_H_SEEN__
 #define __BFD_H_SEEN__

-/* PR 14072: Ensure that config.h is included first.  */
-#if !defined PACKAGE && !defined PACKAGE_VERSION
-#error config.h must be included before this header
-#endif
-
 #ifdef __cplusplus
 extern "C" {
 #endif


code:
--- binutils.orig/binutils/readelf.c	2020-07-24 15:08:30.317597020 +0100
+++ binutils-2.35/binutils/readelf.c	2020-07-24 15:09:39.029155552 +0100
@@ -12069,11 +12069,13 @@ print_dynamic_symbol (Filedata *filedata
       unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);

       printf (" %-7s", get_symbol_visibility (vis));
+#if 0
       /* Check to see if any other bits in the st_other field are set.
 	 Note - displaying this information disrupts the layout of the
 	 table being generated, but for the moment this case is very rare.  */
       if (psym->st_other ^ vis)
 	printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
+#endif
     }
   printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));

@@ -12112,7 +12114,17 @@ print_dynamic_symbol (Filedata *filedata
 		version_string);
     }

-  putchar ('\n');
+#if 1
+    {
+      unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
+
+      /* Check to see if any other bits in the st_other field are set.  */
+      if (psym->st_other ^ vis)
+	printf (" \t[%s]", get_symbol_other (filedata, psym->st_other ^ vis));
+    }
+#endif
+
+    putchar ('\n');

   if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
       && section != NULL


code:
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 3b2a4f49a9b..78a0a1dea42 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1170,6 +1170,9 @@ typedef struct bfd_section
     This is used when support for non-contiguous memory regions is enabled.  */
  struct bfd_section *already_assigned;

+  /* Explicitly specified section type, if non-zero. */
+  unsigned int type;
+
 } asection;

 /* Relax table contains information about instructions which can
@@ -1352,8 +1355,8 @@ discarded_section (const asection *sec)
   /* symbol,                    symbol_ptr_ptr,                     */ \
      (struct bfd_symbol *) SYM, &SEC.symbol,                           \
                                                                        \
-  /* map_head, map_tail, already_assigned                           */ \
-     { NULL }, { NULL }, NULL                                          \
+  /* map_head, map_tail, already_assigned, type                     */ \
+     { NULL }, { NULL }, NULL, 0                                       \
                                                                        \
     }

diff --git a/bfd/elf.c b/bfd/elf.c
index a67415e76e1..82b53be99f9 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3280,7 +3280,9 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg)

   /* If the section type is unspecified, we set it based on
      asect->flags.  */
-  if ((asect->flags & SEC_GROUP) != 0)
+  if (asect->type != 0)
+    sh_type = asect->type;
+  else if ((asect->flags & SEC_GROUP) != 0)
     sh_type = SHT_GROUP;
   else
     sh_type = bfd_elf_get_default_section_type (asect->flags);
diff --git a/bfd/section.c b/bfd/section.c
index 899438a1c5e..2de7dbf661a 100644
--- a/bfd/section.c
+++ b/bfd/section.c
@@ -737,8 +737,8 @@ CODE_FRAGMENT
 .  {* symbol,                    symbol_ptr_ptr,                     *}	\
 .     (struct bfd_symbol *) SYM, &SEC.symbol,				\
 .									\
-.  {* map_head, map_tail, already_assigned                           *}	\
-.     { NULL }, { NULL }, NULL						\
+.  {* map_head, map_tail, already_assigned, type                     *}	\
+.     { NULL }, { NULL }, NULL, 0						\
 .									\
 .    }
 .
diff --git a/ld/NEWS b/ld/NEWS
index dbb402d1f8a..a498abaf0f9 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,8 @@
 -*- text -*-

+* TYPE=<type> is now supported in an output section description to set the
+  section type value.
+
 Changes in 2.38:

 * Add -z pack-relative-relocs/-z no pack-relative-relocs to x86 ELF
diff --git a/ld/ld.texi b/ld/ld.texi
index fc75e9b3625..d57e9221410 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -5483,13 +5483,23 @@ loaded into memory when the program is run.
 @item READONLY
 The section should be marked as read-only.
 @item DSECT
-@itemx COPY
-@itemx INFO
-@itemx OVERLAY
+@item COPY
+@item INFO
+@item OVERLAY
 These type names are supported for backward compatibility, and are
 rarely used.  They all have the same effect: the section should be
 marked as not allocatable, so that no memory is allocated for the
 section when the program is run.
+@item TYPE = @var{type}
+Set the section type to the integer @var{type}. When generating an ELF
+output file, type names @code{SHT_PROGBITS}, @code{SHT_STRTAB},
+@code{SHT_NOTE}, @code {SHT_NOBITS}, @code{SHT_INIT_ARRAY},
+@code{SHT_FINI_ARRAY}, and @code{SHT_PREINIT_ARRAY} are also allowed
+for @var{type}.  It is the user's responsibility to ensure that any
+special requirements of the section type are met.
+@item READONLY ( TYPE = @var{type} )
+This form of the syntax combines the @var{READONLY} type with the
+type specified by @var{type}.
 @end table

 @kindex NOLOAD
diff --git a/ld/ldgram.y b/ld/ldgram.y
index 11c2f219c05..3a904e39482 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -47,6 +47,7 @@
 #endif

 static enum section_type sectype;
+static etree_type *sectype_value;
 static lang_memory_region_type *region;

 static bool ldgram_had_keep = false;
@@ -139,6 +140,7 @@ static int error_index;
 %token LD_FEATURE
 %token NOLOAD DSECT COPY INFO OVERLAY
 %token READONLY
+%token TYPE
 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
 %token <integer> NEXT
 %token SIZEOF ALIGNOF ADDR LOADADDR MAX_K MIN_K
@@ -1058,9 +1060,8 @@ section:	NAME
 			{
 			  ldlex_popstate ();
 			  ldlex_wild ();
-			  lang_enter_output_section_statement($1, $3, sectype,
-							      $5, $7, $4,
-							      $8, $6);
+			  lang_enter_output_section_statement ($1, $3, sectype,
+					sectype_value, $5, $7, $4, $8, $6);
 			}
 		'{'
 		statement_list_opt
@@ -1130,8 +1131,10 @@ type:
 	|  COPY    { sectype = noalloc_section; }
 	|  INFO    { sectype = noalloc_section; }
 	|  OVERLAY { sectype = noalloc_section; }
+        |  READONLY '(' TYPE '=' exp ')' { sectype = typed_readonly_section; sectype_value = $5; }
 	|  READONLY { sectype = readonly_section; }
-	;
+	|  TYPE '=' exp { sectype = type_section; sectype_value = $3; }
+        ;

 atype:
 		'(' type ')'
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 474784c874a..1733f8e65c4 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -1891,8 +1891,8 @@ lang_insert_orphan (asection *s,
     address = exp_intop (0);

   os_tail = (lang_output_section_statement_type **) lang_os_list.tail;
-  os = lang_enter_output_section_statement (secname, address, normal_section,
-					    NULL, NULL, NULL, constraint, 0);
+  os = lang_enter_output_section_statement (
+      secname, address, normal_section, 0, NULL, NULL, NULL, constraint, 0);

   if (add_child == NULL)
     add_child = &os->children;
@@ -2635,10 +2635,12 @@ lang_add_section (lang_statement_list_type *ptr,
     case normal_section:
     case overlay_section:
     case first_overlay_section:
+    case type_section:
       break;
     case noalloc_section:
       flags &= ~SEC_ALLOC;
       break;
+    case typed_readonly_section:
     case readonly_section:
       flags |= SEC_READONLY;
       break;
@@ -4209,6 +4211,7 @@ map_input_to_output_sections
     {
       lang_output_section_statement_type *tos;
       flagword flags;
+      unsigned int type = 0;

       switch (s->header.type)
 	{
@@ -4264,6 +4267,42 @@ map_input_to_output_sections
 	    case readonly_section:
 	      flags |= SEC_READONLY;
 	      break;
+	    case typed_readonly_section:
+	      flags |= SEC_READONLY;
+	      /* Fall through.  */
+	    case type_section:
+	      if (os->sectype_value->type.node_class == etree_name
+		  && os->sectype_value->type.node_code == NAME)
+		{
+		  const char *name = os->sectype_value->name.name;
+		  if (strcmp (name, "SHT_PROGBITS") == 0)
+		    type = SHT_PROGBITS;
+		  else if (strcmp (name, "SHT_STRTAB") == 0)
+		    type = SHT_STRTAB;
+		  else if (strcmp (name, "SHT_NOTE") == 0)
+		    type = SHT_NOTE;
+		  else if (strcmp (name, "SHT_NOBITS") == 0)
+		    type = SHT_NOBITS;
+		  else if (strcmp (name, "SHT_INIT_ARRAY") == 0)
+		    type = SHT_INIT_ARRAY;
+		  else if (strcmp (name, "SHT_FINI_ARRAY") == 0)
+		    type = SHT_FINI_ARRAY;
+		  else if (strcmp (name, "SHT_PREINIT_ARRAY") == 0)
+		    type = SHT_PREINIT_ARRAY;
+		  else
+		    einfo (_ ("%F%P: invalid type for output section `%s'\n"),
+			   os->name);
+		}
+	     else
+	       {
+		 exp_fold_tree_no_dot (os->sectype_value);
+		 if (expld.result.valid_p)
+		   type = expld.result.value;
+		 else
+		   einfo (_ ("%F%P: invalid type for output section `%s'\n"),
+			  os->name);
+	       }
+	      break;
 	    case noload_section:
 	      if (bfd_get_flavour (link_info.output_bfd)
 		  == bfd_target_elf_flavour)
@@ -4276,6 +4315,7 @@ map_input_to_output_sections
 	    init_os (os, flags | SEC_READONLY);
 	  else
 	    os->bfd_section->flags |= flags;
+	  os->bfd_section->type = type;
 	  break;
 	case lang_input_section_enum:
 	  break;
@@ -7506,6 +7546,7 @@ lang_output_section_statement_type *
 lang_enter_output_section_statement (const char *output_section_statement_name,
 				     etree_type *address_exp,
 				     enum section_type sectype,
+				     etree_type *sectype_value,
 				     etree_type *align,
 				     etree_type *subalign,
 				     etree_type *ebase,
@@ -7523,10 +7564,12 @@ lang_enter_output_section_statement (const char *output_section_statement_name,
       os->addr_tree = address_exp;
     }
   os->sectype = sectype;
-  if (sectype != noload_section)
-    os->flags = SEC_NO_FLAGS;
-  else
+  if (sectype == type_section || sectype == typed_readonly_section)
+    os->sectype_value = sectype_value;
+  else if (sectype == noload_section)
     os->flags = SEC_NEVER_LOAD;
+  else
+    os->flags = SEC_NO_FLAGS;
   os->block_value = 1;

   /* Make next things chain into subchain of this.  */
@@ -8842,7 +8885,7 @@ lang_enter_overlay_section (const char *name)
   etree_type *size;

   lang_enter_output_section_statement (name, overlay_vma, overlay_section,
-				       0, overlay_subalign, 0, 0, 0);
+				       0, 0, overlay_subalign, 0, 0, 0);

   /* If this is the first section, then base the VMA of future
      sections on this one.  This will work correctly even if `.' is
diff --git a/ld/ldlang.h b/ld/ldlang.h
index 0d057c9bee9..95f6e468b30 100644
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -122,7 +122,9 @@ enum section_type
   overlay_section,
   noload_section,
   noalloc_section,
-  readonly_section
+  type_section,
+  readonly_section,
+  typed_readonly_section
 };

 /* This structure holds a list of program headers describing
@@ -166,6 +168,7 @@ typedef struct lang_output_section_statement_struct
   int constraint;
   flagword flags;
   enum section_type sectype;
+  etree_type *sectype_value;
   unsigned int processed_vma : 1;
   unsigned int processed_lma : 1;
   unsigned int all_input_readonly : 1;
@@ -545,7 +548,7 @@ extern void lang_add_output
   (const char *, int from_script);
 extern lang_output_section_statement_type *lang_enter_output_section_statement
   (const char *, etree_type *, enum section_type, etree_type *, etree_type *,
-   etree_type *, int, int);
+   etree_type *, etree_type *, int, int);
 extern void lang_final
   (void);
 extern void lang_relax_sections
diff --git a/ld/ldlex.l b/ld/ldlex.l
index 78db16e3a48..c38b46b9336 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -323,6 +323,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 <EXPRESSION>"DSECT"			{ RTOKEN(DSECT); }
 <EXPRESSION>"COPY"			{ RTOKEN(COPY); }
 <EXPRESSION>"INFO"			{ RTOKEN(INFO); }
+<EXPRESSION>"TYPE"			{ RTOKEN(TYPE); }
 <SCRIPT,EXPRESSION>"ONLY_IF_RO"		{ RTOKEN(ONLY_IF_RO); }
 <SCRIPT,EXPRESSION>"ONLY_IF_RW"		{ RTOKEN(ONLY_IF_RW); }
 <SCRIPT,EXPRESSION>"SPECIAL"		{ RTOKEN(SPECIAL); }
diff --git a/ld/mri.c b/ld/mri.c
index b428ab0d0bf..5749870ef1e 100644
--- a/ld/mri.c
+++ b/ld/mri.c
@@ -210,8 +210,8 @@ mri_draw_tree (void)
 	    base = p->vma ? p->vma : exp_nameop (NAME, ".");

 	  lang_enter_output_section_statement (p->name, base,
-					       p->ok_to_load ? normal_section : noload_section,
-					       align, subalign, NULL, 0, 0);
+	    p->ok_to_load ? normal_section : noload_section, 0,
+	    align, subalign, NULL, 0, 0);
 	  base = 0;
 	  tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
 	  tmp->next = NULL;
diff --git a/ld/testsuite/ld-scripts/output-section-types.d b/ld/testsuite/ld-scripts/output-section-types.d
index ab124fa4dd7..2ecacaba57d 100644
--- a/ld/testsuite/ld-scripts/output-section-types.d
+++ b/ld/testsuite/ld-scripts/output-section-types.d
@@ -1,13 +1,17 @@
 #ld: -Toutput-section-types.t
 #source: align2a.s
-#objdump: -h
+#readelf: -S --wide
 #target: [is_elf_format]

 #...
-  . \.rom.*
-[ 	]+ALLOC, READONLY
-  . \.ro.*
-[ 	]+CONTENTS, ALLOC, LOAD, READONLY, DATA
-  . \.over.*
-[ 	]+CONTENTS, READONLY
+.* .rom          +NOBITS        +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +00 +A +0 +0 +[1248]
+.* .ro           +PROGBITS      +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +00 +A +0 +0 +[1248]
+.* .over         +PROGBITS      +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +00  + +0 +0 +[1248]
+.* progbits      +PROGBITS      +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +00 +A +0 +0 +[1248]
+.* strtab        +STRTAB        +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +00 +A +0 +0 +[1248]
+.* note          +NOTE          +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +00 +A +0 +0 +[1248]
+.* init_array    +INIT_ARRAY    +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +0[48] +A +0 +0 +[1248]
+.* fini_array    +FINI_ARRAY    +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +0[48] +A +0 +0 +[1248]
+.* preinit_array +PREINIT_ARRAY +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +0[48] +A +0 +0 +[1248]
+.* .ro.note      +NOTE          +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +00 +A +0 +0 +[1248]
 #pass
diff --git a/ld/testsuite/ld-scripts/output-section-types.t b/ld/testsuite/ld-scripts/output-section-types.t
index d8fdfda1a03..18fc5c11980 100644
--- a/ld/testsuite/ld-scripts/output-section-types.t
+++ b/ld/testsuite/ld-scripts/output-section-types.t
@@ -2,6 +2,13 @@ SECTIONS {
   .rom  (NOLOAD)   : { LONG(1234); }
   .ro   (READONLY) : { LONG(5678); }
   .over (OVERLAY)  : { LONG(0123); }
+  progbits (TYPE=SHT_PROGBITS) : { BYTE(1) }
+  strtab (TYPE = SHT_STRTAB) : { BYTE(0) }
+  note (TYPE =SHT_NOTE) : { BYTE(8) }
+  init_array (TYPE= 14) : { QUAD(14) }
+  fini_array ( TYPE=SHT_FINI_ARRAY) : { QUAD(15) }
+  preinit_array (TYPE=SHT_PREINIT_ARRAY ) : { QUAD(16) }
+  .ro.note   (READONLY (TYPE=SHT_NOTE)) : { LONG(5678); }
   /DISCARD/        : { *(*) }

 }


code:
--- binutils.orig/bfd/elf.c	2018-10-19 11:42:10.107277490 +0100
+++ binutils-2.31.1/bfd/elf.c	2018-10-19 11:44:33.607105801 +0100
@@ -830,7 +830,13 @@ setup_group (bfd *abfd, Elf_Internal_Shd
 	}
     }

-  if (elf_group_name (newsect) == NULL)
+  if (elf_group_name (newsect) == NULL
+      /* OS specific sections might be in a group (eg ARM's ARM_EXIDX section)
+	 but they will not have been added to the group because they do not
+	 have contents that the ELF code in the BFD library knows how to
+	 process.  This is OK though - we rely upon the target backends to
+	 handle these sections for us.  */
+      && hdr->sh_type < SHT_LOOS)
     {
       /* xgettext:c-format */
       _bfd_error_handler (_("%pB: no group info for section '%pA'"),
@@ -936,7 +942,8 @@ _bfd_elf_setup_sections (bfd *abfd)
 	  else if (idx->shdr->bfd_section)
 	    elf_sec_group (idx->shdr->bfd_section) = shdr->bfd_section;
 	  else if (idx->shdr->sh_type != SHT_RELA
-		   && idx->shdr->sh_type != SHT_REL)
+		   && idx->shdr->sh_type != SHT_REL
+		   && idx->shdr->sh_type < SHT_LOOS)
 	    {
 	      /* There are some unknown sections in the group.  */
 	      _bfd_error_handler