import gcc-toolset-10-binutils-2.35-11.el8

This commit is contained in:
CentOS Sources 2022-04-06 13:49:28 +00:00 committed by Stepan Oksanichenko
parent 6278ad9592
commit c5cf600872
7 changed files with 10658 additions and 1 deletions

View File

@ -0,0 +1,778 @@
diff -rup binutils.orig/bfd/bfd-in2.h binutils-2.35.1/bfd/bfd-in2.h
--- binutils.orig/bfd/bfd-in2.h 2021-01-29 11:14:51.848568548 +0000
+++ binutils-2.35.1/bfd/bfd-in2.h 2021-01-29 11:15:33.431322133 +0000
@@ -583,6 +583,8 @@ bfd *bfd_openr (const char *filename, co
bfd *bfd_fdopenr (const char *filename, const char *target, int fd);
+bfd *bfd_fdopenw (const char *filename, const char *target, int fd);
+
bfd *bfd_openstreamr (const char * filename, const char * target,
void * stream);
diff -rup binutils.orig/bfd/opncls.c binutils-2.35.1/bfd/opncls.c
--- binutils.orig/bfd/opncls.c 2021-01-29 11:14:51.846568560 +0000
+++ binutils-2.35.1/bfd/opncls.c 2021-01-29 11:15:33.431322133 +0000
@@ -395,6 +395,39 @@ bfd_fdopenr (const char *filename, const
/*
FUNCTION
+ bfd_fdopenw
+
+SYNOPSIS
+ bfd *bfd_fdopenw (const char *filename, const char *target, int fd);
+
+DESCRIPTION
+ <<bfd_fdopenw>> is exactly like <<bfd_fdopenr>> with the exception that
+ the resulting BFD is suitable for output.
+*/
+
+bfd *
+bfd_fdopenw (const char *filename, const char *target, int fd)
+{
+ bfd *out = bfd_fdopenr (filename, target, fd);
+
+ if (out != NULL)
+ {
+ if (!bfd_write_p (out))
+ {
+ close (fd);
+ _bfd_delete_bfd (out);
+ out = NULL;
+ bfd_set_error (bfd_error_invalid_operation);
+ }
+ else
+ out->direction = write_direction;
+ }
+
+ return out;
+}
+
+/*
+FUNCTION
bfd_openstreamr
SYNOPSIS
diff -rup binutils.orig/binutils/ar.c binutils-2.35.1/binutils/ar.c
--- binutils.orig/binutils/ar.c 2021-01-29 11:14:51.344571539 +0000
+++ binutils-2.35.1/binutils/ar.c 2021-01-29 11:15:56.174187367 +0000
@@ -25,6 +25,7 @@
#include "sysdep.h"
#include "bfd.h"
+#include "libbfd.h"
#include "libiberty.h"
#include "progress.h"
#include "getopt.h"
@@ -1195,20 +1196,26 @@ write_archive (bfd *iarch)
bfd *obfd;
char *old_name, *new_name;
bfd *contents_head = iarch->archive_next;
+ int ofd = -1;
+ struct stat target_stat;
+ bfd_boolean skip_stat = FALSE;
old_name = (char *) xmalloc (strlen (bfd_get_filename (iarch)) + 1);
strcpy (old_name, bfd_get_filename (iarch));
- new_name = make_tempname (old_name);
+ new_name = make_tempname (old_name, &ofd);
if (new_name == NULL)
bfd_fatal (_("could not create temporary file whilst writing archive"));
output_filename = new_name;
- obfd = bfd_openw (new_name, bfd_get_target (iarch));
+ obfd = bfd_fdopenw (new_name, bfd_get_target (iarch), ofd);
if (obfd == NULL)
- bfd_fatal (old_name);
+ {
+ close (ofd);
+ bfd_fatal (old_name);
+ }
output_bfd = obfd;
@@ -1237,6 +1244,14 @@ write_archive (bfd *iarch)
if (!bfd_set_archive_head (obfd, contents_head))
bfd_fatal (old_name);
+#if !defined (_WIN32) || defined (__CYGWIN32__)
+ ofd = dup (ofd);
+ if (iarch == NULL || iarch->iostream == NULL)
+ skip_stat = TRUE;
+ else if (ofd == -1 || fstat (fileno (iarch->iostream), &target_stat) != 0)
+ bfd_fatal (old_name);
+#endif
+
if (!bfd_close (obfd))
bfd_fatal (old_name);
@@ -1246,7 +1261,7 @@ write_archive (bfd *iarch)
/* We don't care if this fails; we might be creating the archive. */
bfd_close (iarch);
- if (smart_rename (new_name, old_name, 0) != 0)
+ if (smart_rename (new_name, old_name, ofd, skip_stat ? NULL : &target_stat, 0) != 0)
xexit (1);
free (old_name);
free (new_name);
diff -rup binutils.orig/binutils/arsup.c binutils-2.35.1/binutils/arsup.c
--- binutils.orig/binutils/arsup.c 2021-01-29 11:14:51.350571503 +0000
+++ binutils-2.35.1/binutils/arsup.c 2021-01-29 11:15:56.174187367 +0000
@@ -345,13 +345,25 @@ ar_save (void)
else
{
char *ofilename = xstrdup (bfd_get_filename (obfd));
+ bfd_boolean skip_stat = FALSE;
+ struct stat target_stat;
+ int ofd = -1;
if (deterministic > 0)
obfd->flags |= BFD_DETERMINISTIC_OUTPUT;
+#if !defined (_WIN32) || defined (__CYGWIN32__)
+ /* It's OK to fail; at worst it will result in SMART_RENAME using a slow
+ copy fallback to write the output. */
+ ofd = dup (fileno (obfd->iostream));
+ if (lstat (real_name, &target_stat) != 0)
+ skip_stat = TRUE;
+#endif
+
bfd_close (obfd);
- smart_rename (ofilename, real_name, 0);
+ smart_rename (ofilename, real_name, ofd,
+ skip_stat ? NULL : &target_stat, 0);
obfd = 0;
free (ofilename);
}
diff -rup binutils.orig/binutils/bucomm.c binutils-2.35.1/binutils/bucomm.c
--- binutils.orig/binutils/bucomm.c 2021-01-29 11:14:51.422571073 +0000
+++ binutils-2.35.1/binutils/bucomm.c 2021-01-29 11:15:33.431322133 +0000
@@ -532,7 +532,7 @@ template_in_dir (const char *path)
as FILENAME. */
char *
-make_tempname (const char *filename)
+make_tempname (const char *filename, int *ofd)
{
char *tmpname = template_in_dir (filename);
int fd;
@@ -550,7 +550,7 @@ make_tempname (const char *filename)
free (tmpname);
return NULL;
}
- close (fd);
+ *ofd = fd;
return tmpname;
}
diff -rup binutils.orig/binutils/bucomm.h binutils-2.35.1/binutils/bucomm.h
--- binutils.orig/binutils/bucomm.h 2021-01-29 11:14:51.350571503 +0000
+++ binutils-2.35.1/binutils/bucomm.h 2021-01-29 11:15:56.174187367 +0000
@@ -51,7 +51,7 @@ int display_info (void);
void print_arelt_descr (FILE *, bfd *, bfd_boolean, bfd_boolean);
-char *make_tempname (const char *);
+char *make_tempname (const char *, int *);
char *make_tempdir (const char *);
bfd_vma parse_vma (const char *, const char *);
@@ -71,7 +71,8 @@ extern void print_version (const char *)
/* In rename.c. */
extern void set_times (const char *, const struct stat *);
-extern int smart_rename (const char *, const char *, int);
+extern int smart_rename (const char *, const char *, int, struct stat *, int);
+
/* In libiberty. */
void *xmalloc (size_t);
diff -rup binutils.orig/binutils/objcopy.c binutils-2.35.1/binutils/objcopy.c
--- binutils.orig/binutils/objcopy.c 2021-01-29 11:14:51.342571551 +0000
+++ binutils-2.35.1/binutils/objcopy.c 2021-01-29 11:15:56.175187361 +0000
@@ -20,6 +20,7 @@
#include "sysdep.h"
#include "bfd.h"
+#include "libbfd.h"
#include "progress.h"
#include "getopt.h"
#include "libiberty.h"
@@ -3711,9 +3712,9 @@ set_long_section_mode (bfd *output_bfd,
/* The top-level control. */
static void
-copy_file (const char *input_filename, const char *output_filename,
- const char *input_target, const char *output_target,
- const bfd_arch_info_type *input_arch)
+copy_file (const char *input_filename, const char *output_filename, int ofd,
+ struct stat *in_stat, const char *input_target,
+ const char *output_target, const bfd_arch_info_type *input_arch)
{
bfd *ibfd;
char **obj_matching;
@@ -3732,7 +3733,7 @@ copy_file (const char *input_filename, c
/* To allow us to do "strip *" without dying on the first
non-object file, failures are nonfatal. */
ibfd = bfd_openr (input_filename, input_target);
- if (ibfd == NULL)
+ if (ibfd == NULL || fstat (fileno (ibfd->iostream), in_stat) != 0)
{
bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
status = 1;
@@ -3786,9 +3787,14 @@ copy_file (const char *input_filename, c
else
force_output_target = TRUE;
- obfd = bfd_openw (output_filename, output_target);
+ if (ofd >= 0)
+ obfd = bfd_fdopenw (output_filename, output_target, ofd);
+ else
+ obfd = bfd_openw (output_filename, output_target);
+
if (obfd == NULL)
{
+ close (ofd);
bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
status = 1;
return;
@@ -3816,13 +3822,19 @@ copy_file (const char *input_filename, c
if (output_target == NULL)
output_target = bfd_get_target (ibfd);
- obfd = bfd_openw (output_filename, output_target);
+ if (ofd >= 0)
+ obfd = bfd_fdopenw (output_filename, output_target, ofd);
+ else
+ obfd = bfd_openw (output_filename, output_target);
+
if (obfd == NULL)
{
+ close (ofd);
bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
status = 1;
return;
}
+
/* This is a no-op on non-Coff targets. */
set_long_section_mode (obfd, ibfd, long_section_names);
@@ -4786,6 +4798,8 @@ strip_main (int argc, char *argv[])
int hold_status = status;
struct stat statbuf;
char *tmpname;
+ int tmpfd = -1;
+ int copyfd = -1;
if (get_file_size (argv[i]) < 1)
{
@@ -4793,18 +4807,18 @@ strip_main (int argc, char *argv[])
continue;
}
- if (preserve_dates)
- /* No need to check the return value of stat().
- It has already been checked in get_file_size(). */
- stat (argv[i], &statbuf);
-
if (output_file == NULL
|| filename_cmp (argv[i], output_file) == 0)
- tmpname = make_tempname (argv[i]);
+ tmpname = make_tempname (argv[i], &tmpfd);
else
tmpname = output_file;
- if (tmpname == NULL)
+ if (tmpname == NULL
+#if !defined (_WIN32) || defined (__CYGWIN32__)
+ /* Retain a copy of TMPFD since we will need it for SMART_RENAME. */
+ || (tmpfd >= 0 && (copyfd = dup (tmpfd)) == -1)
+#endif
+ )
{
bfd_nonfatal_message (argv[i], NULL, NULL,
_("could not create temporary file to hold stripped copy"));
@@ -4813,7 +4827,8 @@ strip_main (int argc, char *argv[])
}
status = 0;
- copy_file (argv[i], tmpname, input_target, output_target, NULL);
+ copy_file (argv[i], tmpname, tmpfd, &statbuf, input_target,
+ output_target, NULL);
if (status == 0)
{
if (preserve_dates)
@@ -4821,12 +4836,18 @@ strip_main (int argc, char *argv[])
if (output_file != tmpname)
status = (smart_rename (tmpname,
output_file ? output_file : argv[i],
- preserve_dates) != 0);
+ copyfd, &statbuf, preserve_dates) != 0);
if (status == 0)
status = hold_status;
}
else
- unlink_if_ordinary (tmpname);
+ {
+#if !defined (_WIN32) || defined (__CYGWIN32__)
+ if (copyfd >= 0)
+ close (copyfd);
+#endif
+ unlink_if_ordinary (tmpname);
+ }
if (output_file != tmpname)
free (tmpname);
}
@@ -5033,7 +5054,8 @@ copy_main (int argc, char *argv[])
bfd_boolean formats_info = FALSE;
bfd_boolean use_globalize = FALSE;
bfd_boolean use_keep_global = FALSE;
- int c;
+ int c, tmpfd = -1;
+ int copyfd = -1;
struct stat statbuf;
const bfd_arch_info_type *input_arch = NULL;
@@ -5870,34 +5892,43 @@ copy_main (int argc, char *argv[])
convert_efi_target (efi);
}
- if (preserve_dates)
- if (stat (input_filename, & statbuf) < 0)
- fatal (_("warning: could not locate '%s'. System error message: %s"),
- input_filename, strerror (errno));
-
/* If there is no destination file, or the source and destination files
are the same, then create a temp and rename the result into the input. */
if (output_filename == NULL
|| filename_cmp (input_filename, output_filename) == 0)
- tmpname = make_tempname (input_filename);
+ tmpname = make_tempname (input_filename, &tmpfd);
else
tmpname = output_filename;
- if (tmpname == NULL)
- fatal (_("warning: could not create temporary file whilst copying '%s', (error: %s)"),
- input_filename, strerror (errno));
+ if (tmpname == NULL
+#if !defined (_WIN32) || defined (__CYGWIN32__)
+ /* Retain a copy of TMPFD since we will need it for SMART_RENAME. */
+ || (tmpfd >= 0 && (copyfd = dup (tmpfd)) == -1)
+#endif
+ )
+ {
+ fatal (_("warning: could not create temporary file whilst copying '%s', (error: %s)"),
+ input_filename, strerror (errno));
+ }
- copy_file (input_filename, tmpname, input_target, output_target, input_arch);
+ copy_file (input_filename, tmpname, tmpfd, &statbuf, input_target,
+ output_target, input_arch);
if (status == 0)
{
if (preserve_dates)
set_times (tmpname, &statbuf);
if (tmpname != output_filename)
- status = (smart_rename (tmpname, input_filename,
+ status = (smart_rename (tmpname, input_filename, copyfd, &statbuf,
preserve_dates) != 0);
}
else
- unlink_if_ordinary (tmpname);
+ {
+#if !defined (_WIN32) || defined (__CYGWIN32__)
+ if (copyfd >= 0)
+ close (copyfd);
+#endif
+ unlink_if_ordinary (tmpname);
+ }
if (tmpname != output_filename)
free (tmpname);
diff -rup binutils.orig/binutils/rename.c binutils-2.35.1/binutils/rename.c
--- binutils.orig/binutils/rename.c 2021-01-29 11:14:51.422571073 +0000
+++ binutils-2.35.1/binutils/rename.c 2021-01-29 11:15:56.175187361 +0000
@@ -131,17 +131,55 @@ set_times (const char *destination, cons
#endif
#endif
-/* Rename FROM to TO, copying if TO is a link.
- Return 0 if ok, -1 if error. */
+#if !defined (_WIN32) || defined (__CYGWIN32__)
+/* Try to preserve the permission bits and ownership of an existing file when
+ rename overwrites it. FD is the file being renamed and TARGET_STAT has the
+ status of the file that was overwritten. */
+static void
+try_preserve_permissions (int fd, struct stat *target_stat)
+{
+ struct stat from_stat;
+ int ret = 0;
+
+ if (fstat (fd, &from_stat) != 0)
+ return;
+
+ int from_mode = from_stat.st_mode & 0777;
+ int to_mode = target_stat->st_mode & 0777;
+
+ /* Fix up permissions before we potentially lose ownership with fchown.
+ Clear the setxid bits because in case the fchown below fails then we don't
+ want to end up with a sxid file owned by the invoking user. If the user
+ hasn't changed or if fchown succeeded, we add back the sxid bits at the
+ end. */
+ if (from_mode != to_mode)
+ fchmod (fd, to_mode);
+
+ /* Fix up ownership, this will clear the setxid bits. */
+ if (from_stat.st_uid != target_stat->st_uid
+ || from_stat.st_gid != target_stat->st_gid)
+ ret = fchown (fd, target_stat->st_uid, target_stat->st_gid);
+
+ /* Fix up the sxid bits if either the fchown wasn't needed or it
+ succeeded. */
+ if (ret == 0)
+ fchmod (fd, target_stat->st_mode & 07777);
+}
+#endif
+
+/* Rename FROM to TO, copying if TO is either a link or is not a regular file.
+ FD is an open file descriptor pointing to FROM that we can use to safely fix
+ up permissions of the file after renaming. TARGET_STAT has the file status
+ that is used to fix up permissions and timestamps after rename. Return 0 if
+ ok, -1 if error and FD is closed before returning. */
int
-smart_rename (const char *from, const char *to, int preserve_dates ATTRIBUTE_UNUSED)
+smart_rename (const char *from, const char *to, int fd ATTRIBUTE_UNUSED,
+ struct stat *target_stat ATTRIBUTE_UNUSED,
+ int preserve_dates ATTRIBUTE_UNUSED)
{
- bfd_boolean exists;
- struct stat s;
int ret = 0;
-
- exists = lstat (to, &s) == 0;
+ bfd_boolean exists = target_stat != NULL;
#if defined (_WIN32) && !defined (__CYGWIN32__)
/* Win32, unlike unix, will not erase `to' in `rename(from, to)' but
@@ -158,36 +196,35 @@ smart_rename (const char *from, const ch
unlink (from);
}
#else
- /* Use rename only if TO is not a symbolic link and has
- only one hard link, and we have permission to write to it. */
+ /* Avoid a full copy and use rename if we can fix up permissions of the
+ file after renaming, i.e.:
+
+ - TO is not a symbolic link
+ - TO is a regular file with only one hard link
+ - We have permission to write to TO
+ - FD is available to safely fix up permissions to be the same as the file
+ we overwrote with the rename.
+
+ Note though that the actual file on disk that TARGET_STAT describes may
+ have changed and we're only trying to preserve the status we know about.
+ At no point do we try to interact with the new file changes, so there can
+ only be two outcomes, i.e. either the external file change survives
+ without knowledge of our change (if it happens after the rename syscall)
+ or our rename and permissions fixup survive without any knowledge of the
+ external change. */
if (! exists
- || (!S_ISLNK (s.st_mode)
- && S_ISREG (s.st_mode)
- && (s.st_mode & S_IWUSR)
- && s.st_nlink == 1)
+ || (fd >= 0
+ && !S_ISLNK (target_stat->st_mode)
+ && S_ISREG (target_stat->st_mode)
+ && (target_stat->st_mode & S_IWUSR)
+ && target_stat->st_nlink == 1)
)
{
ret = rename (from, to);
if (ret == 0)
{
if (exists)
- {
- /* Try to preserve the permission bits and ownership of
- TO. First get the mode right except for the setuid
- bit. Then change the ownership. Then fix the setuid
- bit. We do the chmod before the chown because if the
- chown succeeds, and we are a normal user, we won't be
- able to do the chmod afterward. We don't bother to
- fix the setuid bit first because that might introduce
- a fleeting security problem, and because the chown
- will clear the setuid bit anyhow. We only fix the
- setuid bit if the chown succeeds, because we don't
- want to introduce an unexpected setuid file owned by
- the user running objcopy. */
- chmod (to, s.st_mode & 0777);
- if (chown (to, s.st_uid, s.st_gid) >= 0)
- chmod (to, s.st_mode & 07777);
- }
+ try_preserve_permissions (fd, target_stat);
}
else
{
@@ -203,9 +240,11 @@ smart_rename (const char *from, const ch
non_fatal (_("unable to copy file '%s'; reason: %s"), to, strerror (errno));
if (preserve_dates)
- set_times (to, &s);
+ set_times (to, target_stat);
unlink (from);
}
+ if (fd >= 0)
+ close (fd);
#endif /* _WIN32 && !__CYGWIN32__ */
return ret;
diff -rup binutils.orig/binutils/ar.c binutils-2.35.1/binutils/ar.c
--- binutils.orig/binutils/ar.c 2021-02-02 13:01:42.257734944 +0000
+++ binutils-2.35.1/binutils/ar.c 2021-02-02 13:11:13.340958352 +0000
@@ -25,7 +25,6 @@
#include "sysdep.h"
#include "bfd.h"
-#include "libbfd.h"
#include "libiberty.h"
#include "progress.h"
#include "getopt.h"
@@ -1082,7 +1081,7 @@ open_output_file (bfd * abfd)
output_filename, base);
output_filename = base;
}
-
+
if (output_dir)
{
size_t len = strlen (output_dir);
@@ -1099,7 +1098,7 @@ open_output_file (bfd * abfd)
if (verbose)
printf ("x - %s\n", output_filename);
-
+
FILE * ostream = fopen (output_filename, FOPEN_WB);
if (ostream == NULL)
{
@@ -1198,10 +1197,8 @@ write_archive (bfd *iarch)
bfd *contents_head = iarch->archive_next;
int ofd = -1;
struct stat target_stat;
- bfd_boolean skip_stat = FALSE;
- old_name = (char *) xmalloc (strlen (bfd_get_filename (iarch)) + 1);
- strcpy (old_name, bfd_get_filename (iarch));
+ old_name = xstrdup (bfd_get_filename (iarch));
new_name = make_tempname (old_name, &ofd);
if (new_name == NULL)
@@ -1246,11 +1243,9 @@ write_archive (bfd *iarch)
#if !defined (_WIN32) || defined (__CYGWIN32__)
ofd = dup (ofd);
- if (iarch == NULL || iarch->iostream == NULL)
- skip_stat = TRUE;
- else if (ofd == -1 || fstat (fileno (iarch->iostream), &target_stat) != 0)
- bfd_fatal (old_name);
#endif
+ if (ofd == -1 || bfd_stat (iarch, &target_stat) != 0)
+ bfd_fatal (old_name);
if (!bfd_close (obfd))
bfd_fatal (old_name);
@@ -1261,7 +1256,7 @@ write_archive (bfd *iarch)
/* We don't care if this fails; we might be creating the archive. */
bfd_close (iarch);
- if (smart_rename (new_name, old_name, ofd, skip_stat ? NULL : &target_stat, 0) != 0)
+ if (smart_rename (new_name, old_name, ofd, &target_stat, 0) != 0)
xexit (1);
free (old_name);
free (new_name);
Only in binutils-2.35.1/binutils/: ar.c.orig
Only in binutils-2.35.1/binutils/: ar.c.rej
diff -rup binutils.orig/binutils/arsup.c binutils-2.35.1/binutils/arsup.c
--- binutils.orig/binutils/arsup.c 2021-02-02 13:01:42.208735269 +0000
+++ binutils-2.35.1/binutils/arsup.c 2021-02-02 13:11:55.725678308 +0000
@@ -42,6 +42,8 @@ extern int deterministic;
static bfd *obfd;
static char *real_name;
+static char *temp_name;
+static int real_ofd;
static FILE *outfile;
static void
@@ -149,27 +151,24 @@ maybequit (void)
void
ar_open (char *name, int t)
{
- char *tname;
- const char *bname = lbasename (name);
- real_name = name;
-
- /* Prepend tmp- to the beginning, to avoid file-name clashes after
- truncation on filesystems with limited namespaces (DOS). */
- if (asprintf (&tname, "%.*stmp-%s", (int) (bname - name), name, bname) == -1)
+ real_name = xstrdup (name);
+ temp_name = make_tempname (real_name, &real_ofd);
+
+ if (temp_name == NULL)
{
- fprintf (stderr, _("%s: Can't allocate memory for temp name (%s)\n"),
+ fprintf (stderr, _("%s: Can't open temporary file (%s)\n"),
program_name, strerror(errno));
maybequit ();
return;
}
- obfd = bfd_openw (tname, NULL);
+ obfd = bfd_fdopenw (temp_name, NULL, real_ofd);
if (!obfd)
{
fprintf (stderr,
_("%s: Can't open output archive %s\n"),
- program_name, tname);
+ program_name, temp_name);
maybequit ();
}
@@ -344,10 +343,9 @@ ar_save (void)
}
else
{
- char *ofilename = xstrdup (bfd_get_filename (obfd));
bfd_boolean skip_stat = FALSE;
struct stat target_stat;
- int ofd = -1;
+ int ofd = real_ofd;
if (deterministic > 0)
obfd->flags |= BFD_DETERMINISTIC_OUTPUT;
@@ -355,17 +353,18 @@ ar_save (void)
#if !defined (_WIN32) || defined (__CYGWIN32__)
/* It's OK to fail; at worst it will result in SMART_RENAME using a slow
copy fallback to write the output. */
- ofd = dup (fileno (obfd->iostream));
- if (lstat (real_name, &target_stat) != 0)
- skip_stat = TRUE;
+ ofd = dup (ofd);
#endif
-
bfd_close (obfd);
- smart_rename (ofilename, real_name, ofd,
+ if (ofd == -1 || fstat (ofd, &target_stat) != 0)
+ skip_stat = TRUE;
+
+ smart_rename (temp_name, real_name, ofd,
skip_stat ? NULL : &target_stat, 0);
obfd = 0;
- free (ofilename);
+ free (temp_name);
+ free (real_name);
}
}
Only in binutils-2.35.1/binutils/: arsup.c.orig
Only in binutils-2.35.1/binutils/: arsup.c.rej
diff -rup binutils.orig/binutils/objcopy.c binutils-2.35.1/binutils/objcopy.c
--- binutils.orig/binutils/objcopy.c 2021-02-02 13:01:42.214735229 +0000
+++ binutils-2.35.1/binutils/objcopy.c 2021-02-02 13:13:27.613071192 +0000
@@ -20,7 +20,6 @@
#include "sysdep.h"
#include "bfd.h"
-#include "libbfd.h"
#include "progress.h"
#include "getopt.h"
#include "libiberty.h"
@@ -3733,7 +3732,7 @@ copy_file (const char *input_filename, c
/* To allow us to do "strip *" without dying on the first
non-object file, failures are nonfatal. */
ibfd = bfd_openr (input_filename, input_target);
- if (ibfd == NULL || fstat (fileno (ibfd->iostream), in_stat) != 0)
+ if (ibfd == NULL || bfd_stat (ibfd, in_stat) != 0)
{
bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
status = 1;
Only in binutils-2.35.1/binutils/: objcopy.c.orig
Only in binutils-2.35.1/binutils/: objcopy.c.rej
--- binutils.orig/binutils/arsup.c 2021-02-04 10:42:03.265729780 +0000
+++ binutils-2.35.1/binutils/arsup.c 2021-02-04 10:45:48.439166658 +0000
@@ -357,8 +357,21 @@ ar_save (void)
#endif
bfd_close (obfd);
- if (ofd == -1 || fstat (ofd, &target_stat) != 0)
- skip_stat = TRUE;
+ if (lstat (real_name, &target_stat) != 0)
+ {
+ /* The temp file created in ar_open has mode 0600 as per mkstemp.
+ Create the real empty output file here so smart_rename will
+ update the mode according to the process umask. */
+ obfd = bfd_openw (real_name, NULL);
+ if (obfd == NULL
+ || bfd_stat (obfd, &target_stat) != 0)
+ skip_stat = TRUE;
+ if (obfd != NULL)
+ {
+ bfd_set_format (obfd, bfd_archive);
+ bfd_close (obfd);
+ }
+ }
smart_rename (temp_name, real_name, ofd,
skip_stat ? NULL : &target_stat, 0);
--- binutils.orig/binutils/rename.c 2021-02-08 11:02:58.767933783 +0000
+++ binutils-2.35.1/binutils/rename.c 2021-02-08 11:20:37.539179363 +0000
@@ -179,7 +179,10 @@ smart_rename (const char *from, const ch
int preserve_dates ATTRIBUTE_UNUSED)
{
int ret = 0;
- bfd_boolean exists = target_stat != NULL;
+ struct stat to_stat;
+ bfd_boolean exists;
+
+ exists = lstat (to, &to_stat) == 0;
#if defined (_WIN32) && !defined (__CYGWIN32__)
/* Win32, unlike unix, will not erase `to' in `rename(from, to)' but
@@ -214,16 +217,16 @@ smart_rename (const char *from, const ch
external change. */
if (! exists
|| (fd >= 0
- && !S_ISLNK (target_stat->st_mode)
- && S_ISREG (target_stat->st_mode)
- && (target_stat->st_mode & S_IWUSR)
- && target_stat->st_nlink == 1)
+ && !S_ISLNK (to_stat.st_mode)
+ && S_ISREG (to_stat.st_mode)
+ && (to_stat.st_mode & S_IWUSR)
+ && to_stat.st_nlink == 1)
)
{
ret = rename (from, to);
if (ret == 0)
{
- if (exists)
+ if (exists && target_stat != NULL)
try_preserve_permissions (fd, target_stat);
}
else
@@ -239,7 +242,7 @@ smart_rename (const char *from, const ch
if (ret != 0)
non_fatal (_("unable to copy file '%s'; reason: %s"), to, strerror (errno));
- if (preserve_dates)
+ if (preserve_dates && target_stat != NULL)
set_times (to, target_stat);
unlink (from);
}

View File

@ -0,0 +1,144 @@
diff -rup binutils.orig/gas/testsuite/gas/ppc/power4_32.d binutils-2.35/gas/testsuite/gas/ppc/power4_32.d
--- binutils.orig/gas/testsuite/gas/ppc/power4_32.d 2022-01-25 13:39:48.063563099 +0000
+++ binutils-2.35/gas/testsuite/gas/ppc/power4_32.d 2022-01-25 13:48:30.857981751 +0000
@@ -41,7 +41,7 @@ Disassembly of section \.text:
7c: (7c 01 17 ec|ec 17 01 7c) dcbz r1,r2
80: (7c 23 27 ec|ec 27 23 7c) dcbzl r3,r4
84: (7c 05 37 ec|ec 37 05 7c) dcbz r5,r6
- 88: (7c 05 32 2c|2c 32 05 7c) dcbt r5,r6
- 8c: (7c 05 32 2c|2c 32 05 7c) dcbt r5,r6
- 90: (7d 05 32 2c|2c 32 05 7d) dcbt r5,r6,8
+ 88: (7c 05 32 2c|2c 32 05 7c) dcbtct r5,r6
+ 8c: (7c 05 32 2c|2c 32 05 7c) dcbtct r5,r6
+ 90: (7d 05 32 2c|2c 32 05 7d) dcbtds r5,r6
#pass
diff -rup binutils.orig/opcodes/ppc-opc.c binutils-2.35/opcodes/ppc-opc.c
--- binutils.orig/opcodes/ppc-opc.c 2022-01-25 13:39:47.650565929 +0000
+++ binutils-2.35/opcodes/ppc-opc.c 2022-01-25 13:47:09.056542122 +0000
@@ -2205,6 +2205,74 @@ extract_sxl (uint64_t insn,
return 1;
return (insn >> 11) & 0x1;
}
+
+/* The list of embedded processors that use the embedded operand ordering
+ for the 3 operand dcbt and dcbtst instructions. */
+#define DCBT_EO (PPC_OPCODE_E500 | PPC_OPCODE_E500MC | PPC_OPCODE_476 \
+ | PPC_OPCODE_A2)
+
+/* ISA 2.03 and later specify extended mnemonics dcbtct, dcbtds, and
+ dcbtstct, dcbtstds with a note saying these should be used in new
+ programs rather than the base mnemonics "so that it can be coded
+ with TH as the last operand for all categories". For that reason
+ the extended mnemonics are enabled in the assembler for the
+ embedded processors, but not for the disassembler so as to display
+ the embedded dcbt or dcbtst expected form with TH first for
+ embedded programmers. */
+
+static uint64_t
+insert_thct (uint64_t insn,
+ int64_t value,
+ ppc_cpu_t dialect ATTRIBUTE_UNUSED,
+ const char **errmsg)
+{
+ if ((uint64_t) value > 7)
+ *errmsg = _("invalid TH value");
+ return insn | ((value & 7) << 21);
+}
+
+static int64_t
+extract_thct (uint64_t insn,
+ ppc_cpu_t dialect,
+ int *invalid)
+{
+ /* Missing optional operands have a value of 0. */
+ if (*invalid < 0)
+ return 0;
+
+ int64_t value = (insn >> 21) & 0x1f;
+ if (value > 7 || (dialect & DCBT_EO) != 0)
+ *invalid = 1;
+
+ return value;
+}
+
+static uint64_t
+insert_thds (uint64_t insn,
+ int64_t value,
+ ppc_cpu_t dialect ATTRIBUTE_UNUSED,
+ const char **errmsg)
+{
+ if (value < 8 || value > 15)
+ *errmsg = _("invalid TH value");
+ return insn | ((value & 0x1f) << 21);
+}
+
+static int64_t
+extract_thds (uint64_t insn,
+ ppc_cpu_t dialect,
+ int *invalid)
+{
+ /* Missing optional operands have a value of 8. */
+ if (*invalid < 0)
+ return 8;
+
+ int64_t value = (insn >> 21) & 0x1f;
+ if (value < 8 || value > 15 || (dialect & DCBT_EO) != 0)
+ *invalid = 1;
+
+ return value;
+}
/* The operands table.
@@ -2402,10 +2470,18 @@ const struct powerpc_operand powerpc_ope
#define MO CT
{ 0x1f, 21, NULL, NULL, PPC_OPERAND_OPTIONAL },
+ /* The TH field in dcbtct. */
+#define THCT CT + 1
+ { 0x1f, 21, insert_thct, extract_thct, PPC_OPERAND_OPTIONAL },
+
+ /* The TH field in dcbtds. */
+#define THDS THCT + 1
+ { 0x1f, 21, insert_thds, extract_thds, PPC_OPERAND_OPTIONAL },
+
/* The D field in a D form instruction. This is a displacement off
a register, and implies that the next operand is a register in
parentheses. */
-#define D CT + 1
+#define D THDS + 1
{ 0xffff, 0, NULL, NULL, PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED },
/* The D8 field in a D form instruction. This is a displacement off
@@ -4211,12 +4287,6 @@ const unsigned int num_powerpc_operands
#define PPCHTM PPC_OPCODE_POWER8
#define E200Z4 PPC_OPCODE_E200Z4
#define PPCLSP PPC_OPCODE_LSP
-/* The list of embedded processors that use the embedded operand ordering
- for the 3 operand dcbt and dcbtst instructions. */
-#define DCBT_EO (PPC_OPCODE_E500 | PPC_OPCODE_E500MC | PPC_OPCODE_476 \
- | PPC_OPCODE_A2)
-
-
/* The opcode table.
@@ -6592,6 +6662,8 @@ const struct powerpc_opcode powerpc_opco
{"mtvsrwz", X(31,243), XX1RB_MASK, PPCVSX2, 0, {XT6, RA}},
{"dcbtstt", XRT(31,246,0x10), XRT_MASK, POWER7, 0, {RA0, RB}},
+{"dcbtstct", X(31,246), X_MASK, POWER4, 0, {RA0, RB, THCT}},
+{"dcbtstds", X(31,246), X_MASK, POWER4, 0, {RA0, RB, THDS}},
{"dcbtst", X(31,246), X_MASK, POWER4, DCBT_EO, {RA0, RB, CT}},
{"dcbtst", X(31,246), X_MASK, DCBT_EO, 0, {CT, RA0, RB}},
{"dcbtst", X(31,246), X_MASK, PPC, POWER4|DCBT_EO, {RA0, RB}},
@@ -6643,6 +6715,9 @@ const struct powerpc_opcode powerpc_opco
{"lscbx.", XRC(31,277,1), X_MASK, M601, 0, {RT, RA, RB}},
{"dcbtt", XRT(31,278,0x10), XRT_MASK, POWER7, 0, {RA0, RB}},
+{"dcbna", XRT(31,278,0x11), XRT_MASK, POWER10, 0, {RA0, RB}},
+{"dcbtct", X(31,278), X_MASK, POWER4, 0, {RA0, RB, THCT}},
+{"dcbtds", X(31,278), X_MASK, POWER4, 0, {RA0, RB, THDS}},
{"dcbt", X(31,278), X_MASK, POWER4, DCBT_EO, {RA0, RB, CT}},
{"dcbt", X(31,278), X_MASK, DCBT_EO, 0, {CT, RA0, RB}},
{"dcbt", X(31,278), X_MASK, PPC, POWER4|DCBT_EO, {RA0, RB}},

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,107 @@
diff -rup binutils.orig/gas/config/tc-ppc.c binutils-2.35/gas/config/tc-ppc.c
--- binutils.orig/gas/config/tc-ppc.c 2022-02-03 11:10:42.835719394 +0000
+++ binutils-2.35/gas/config/tc-ppc.c 2022-02-03 11:13:04.298724661 +0000
@@ -1738,12 +1738,12 @@ ppc_setup_opcodes (void)
if ((ppc_cpu & op->flags) != 0
&& !(ppc_cpu & op->deprecated))
- str_hash_insert (ppc_hash, op->name, (void *) op);
+ str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
}
if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
for (op = powerpc_opcodes; op < op_end; op++)
- str_hash_insert (ppc_hash, op->name, (void *) op);
+ str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
op_end = prefix_opcodes + prefix_num_opcodes;
for (op = prefix_opcodes; op < op_end; op++)
@@ -1772,12 +1772,12 @@ ppc_setup_opcodes (void)
if ((ppc_cpu & op->flags) != 0
&& !(ppc_cpu & op->deprecated))
- str_hash_insert (ppc_hash, op->name, (void *) op);
+ str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
}
if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
for (op = prefix_opcodes; op < op_end; op++)
- str_hash_insert (ppc_hash, op->name, (void *) op);
+ str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
op_end = vle_opcodes + vle_num_opcodes;
for (op = vle_opcodes; op < op_end; op++)
@@ -1807,7 +1807,7 @@ ppc_setup_opcodes (void)
if ((ppc_cpu & op->flags) != 0
&& !(ppc_cpu & op->deprecated))
- str_hash_insert (ppc_hash, op->name, (void *) op);
+ str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
}
/* SPE2 instructions */
@@ -1841,11 +1841,11 @@ ppc_setup_opcodes (void)
}
if ((ppc_cpu & op->flags) != 0 && !(ppc_cpu & op->deprecated))
- str_hash_insert (ppc_hash, op->name, (void *) op);
+ str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
}
for (op = spe2_opcodes; op < op_end; op++)
- str_hash_insert (ppc_hash, op->name, (void *) op);
+ str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
}
/* Insert the macros into a hash table. */
diff -rup binutils.orig/gas/hash.c binutils-2.35/gas/hash.c
--- binutils.orig/gas/hash.c 2022-02-03 11:10:42.827719448 +0000
+++ binutils-2.35/gas/hash.c 2022-02-03 11:12:00.506175797 +0000
@@ -32,6 +32,24 @@ htab_insert (htab_t htab, PTR element)
*slot = element;
}
+void **
+htab_insert_or_replace (htab_t htab, void *element, int replace)
+{
+ void **slot = htab_find_slot (htab, element, INSERT);
+ if (*slot != NULL)
+ {
+ if (replace)
+ {
+ if (htab->del_f)
+ (*htab->del_f) (*slot);
+ *slot = element;
+ }
+ return slot;
+ }
+ *slot = element;
+ return NULL;
+}
+
/* Print statistics about a hash table. */
void
diff -rup binutils.orig/gas/hash.h binutils-2.35/gas/hash.h
--- binutils.orig/gas/hash.h 2022-02-03 11:10:42.830719428 +0000
+++ binutils-2.35/gas/hash.h 2022-02-03 11:12:25.002002561 +0000
@@ -103,6 +103,19 @@ str_hash_insert (htab_t table, const cha
htab_insert (table, string_tuple_alloc (key, value));
}
+extern void ** htab_insert_or_replace (htab_t, void *, int);
+
+static inline void **
+str_hash_insert_or_replace (htab_t table, const char *key, void *value, int replace)
+{
+ string_tuple_t *elt = string_tuple_alloc (key, value);
+ void **slot = htab_insert_or_replace (table, elt, replace);
+ if (slot && !replace)
+ free (elt);
+ return slot;
+}
+
+
static inline htab_t
str_htab_create (void)
{

View File

@ -0,0 +1,62 @@
diff -rup binutils.orig/bfd/elf-bfd.h binutils-2.35/bfd/elf-bfd.h
--- binutils.orig/bfd/elf-bfd.h 2021-06-23 15:00:33.913477324 +0100
+++ binutils-2.35/bfd/elf-bfd.h 2021-06-23 15:03:42.300235019 +0100
@@ -1748,6 +1748,11 @@ struct bfd_elf_section_data
/* Link from a text section to its .eh_frame_entry section. */
asection *eh_frame_entry;
+ /* TRUE if the section has secondary reloc sections associated with it.
+ FIXME: In the future it might be better to change this into a list
+ of secondary reloc sections, making lookup easier and faster. */
+ bfd_boolean has_secondary_relocs;
+
/* A pointer used for various section optimizations. */
void *sec_info;
};
diff -rup binutils.orig/bfd/elf.c binutils-2.35/bfd/elf.c
--- binutils.orig/bfd/elf.c 2021-06-23 15:00:33.902477396 +0100
+++ binutils-2.35/bfd/elf.c 2021-06-23 15:02:36.269672347 +0100
@@ -12672,6 +12672,7 @@ _bfd_elf_copy_special_section_fields (co
{
asection * isec;
asection * osec;
+ struct bfd_elf_section_data * esd;
if (isection == NULL)
return FALSE;
@@ -12687,8 +12688,9 @@ _bfd_elf_copy_special_section_fields (co
if (osec == NULL)
return FALSE;
- BFD_ASSERT (elf_section_data (osec)->sec_info == NULL);
- elf_section_data (osec)->sec_info = elf_section_data (isec)->sec_info;
+ esd = elf_section_data (osec);
+ BFD_ASSERT (esd->sec_info == NULL);
+ esd->sec_info = elf_section_data (isec)->sec_info;
osection->sh_type = SHT_RELA;
osection->sh_link = elf_onesymtab (obfd);
if (osection->sh_link == 0)
@@ -12731,6 +12733,10 @@ _bfd_elf_copy_special_section_fields (co
osection->sh_info =
elf_section_data (isection->bfd_section->output_section)->this_idx;
+ esd = elf_section_data (isection->bfd_section->output_section);
+ BFD_ASSERT (esd != NULL);
+ osection->sh_info = esd->this_idx;
+ esd->has_secondary_relocs = TRUE;
#if DEBUG_SECONDARY_RELOCS
fprintf (stderr, "update header of %s, sh_link = %u, sh_info = %u\n",
osec->name, osection->sh_link, osection->sh_info);
diff -rup binutils.orig/bfd/elfcode.h binutils-2.35/bfd/elfcode.h
--- binutils.orig/bfd/elfcode.h 2021-06-23 15:00:33.910477344 +0100
+++ binutils-2.35/bfd/elfcode.h 2021-06-23 15:04:32.506902070 +0100
@@ -987,7 +987,8 @@ elf_write_relocs (bfd *abfd, asection *s
(*swap_out) (abfd, &src_rela, dst_rela);
}
- if (!bed->write_secondary_relocs (abfd, sec))
+ if (elf_section_data (sec)->has_secondary_relocs
+ && !bed->write_secondary_relocs (abfd, sec))
{
*failedp = TRUE;
return;

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
Summary: A GNU collection of binary utilities
Name: %{?scl_prefix}%{?cross}binutils%{?_with_debug:-debug}
Version: 2.35
Release: 6%{?dist}
Release: 11%{?dist}
License: GPLv3+
URL: https://sourceware.org/binutils
@ -267,6 +267,29 @@ Patch31: binutils-aarch64-plt-sh_entsize.patch
Patch32: binutils-add-sym-cache-to-elf-link-hash.patch
Patch33: binutils-elf-add-objects.patch
# Purpose: Remove a vulnerability in the smart_rename function.
# Lifetime: Fixed in 2.36
Patch34: binutils-CVE-2021-20197.patch
# Purpose: Remove a quadratic performance penalty processing files.
# Lifetime: Fixed in 2.35.2
Patch35: binutils-secondary-relocs-speed.patch
# Purpose: Remove a quadratic performance penalty processing files.
# Lifetime: Fixed in 2.35.2
Patch36: binutils-gas-speedups.patch
# Purpose: Add options to control the display of multibyte characters. CVE 2021-42574
# Lifetime: Fixed in 2.38 (maybe)
Patch37: binutils.unicode.patch
# Purpose: Fix the assembly of the three-operand variant of the DCBT insn.
# Lifetime: Fixed in 2.36.1
Patch38: binutils-PPC-dcbt.patch
# Purpose: Fix the assembly of the three-operand variant of the DCBT insn (again).
# Lifetime: Fixed in 2.36.1
Patch39: binutils-ppc-hash-insert.patch
#----------------------------------------------------------------------------
@ -904,6 +927,24 @@ exit 0
#----------------------------------------------------------------------------
%changelog
* Thu Feb 03 2022 Nick Clifton <nickc@redhat.com> - 2.35-11
- Fix the assembly of the three-operand variant of the DCBT insn. (#2044523)
* Tue Jan 25 2022 Nick Clifton <nickc@redhat.com> - 2.35-10
- Fix the assembly of the three-operand variant of the DCBT insn. (#2044523)
* Mon Nov 29 2021 Nick Clifton <nickc@redhat.com> - 2.35-9
- Add ability to control the display of unicode characters. (#2009178)
- Backport some more speed up patches. (#1978174)
- Remove a quadratic performance penalty processing files. (#1978174)
- Extend vulnerability fix again. (#1925779)
* Mon Feb 08 2021 Nick Clifton <nickc@redhat.com> - 2.35-8
- Extend vulnerability fix again. (#1925779)
* Mon Feb 01 2021 Nick Clifton <nickc@redhat.com> - 2.35-7
- Fix a vulnerability in the smart_rename function used by some binutils tools. (#1920641)
* Fri Jan 15 2021 Nick Clifton <nickc@redhat.com> - 2.35-6
- NVR bump to allow rebuild with new tag.