/* elfedit.c -- Update the ELF header of an ELF format file
- Copyright (C) 2010-2020 Free Software Foundation, Inc.
+ Copyright (C) 2010-2021 Free Software Foundation, Inc.
This file is part of GNU Binutils.
\f
#include "config.h"
#include "sysdep.h"
+#include "libiberty.h"
#include <assert.h>
#if __GNUC__ >= 2
x86_feature = GNU_PROPERTY_X86_FEATURE_1_IBT;
else if (strcasecmp (feature, "shstk") == 0)
x86_feature = GNU_PROPERTY_X86_FEATURE_1_SHSTK;
+ else if (strcasecmp (feature, "lam_u48") == 0)
+ x86_feature = GNU_PROPERTY_X86_FEATURE_1_LAM_U48;
+ else if (strcasecmp (feature, "lam_u57") == 0)
+ x86_feature = GNU_PROPERTY_X86_FEATURE_1_LAM_U57;
else
{
error (_("Unknown x86 feature: %s\n"), feature);
static int
process_archive (const char * file_name, FILE * file,
- bfd_boolean is_thin_archive)
+ bool is_thin_archive)
{
struct archive_info arch;
struct archive_info nested_arch;
size_t got;
int ret;
+ struct stat statbuf;
/* The ARCH structure is used to hold information about this archive. */
arch.file_name = NULL;
nested_arch.sym_table = NULL;
nested_arch.longnames = NULL;
- if (setup_archive (&arch, file_name, file, is_thin_archive, FALSE) != 0)
+ if (fstat (fileno (file), &statbuf) < 0
+ || setup_archive (&arch, file_name, file, statbuf.st_size,
+ is_thin_archive, false) != 0)
{
ret = 1;
goto out;
if (qualified_name == NULL)
{
error (_("%s: bad archive file name\n"), file_name);
+ free (name);
ret = 1;
break;
}
FILE *member_file;
char *member_file_name = adjust_relative_path (file_name,
name, namelen);
+ free (name);
if (member_file_name == NULL)
{
+ free (qualified_name);
ret = 1;
break;
}
error (_("Input file '%s' is not readable\n"),
member_file_name);
free (member_file_name);
+ free (qualified_name);
ret = 1;
break;
}
}
else if (is_thin_archive)
{
+ free (name);
+
/* This is a proxy for a member of a nested archive. */
archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
{
error (_("%s: failed to seek to archive member\n"),
nested_arch.file_name);
+ free (qualified_name);
ret = 1;
break;
}
}
else
{
+ free (name);
archive_file_offset = arch.next_arhdr_offset;
arch.next_arhdr_offset += archive_file_size;
return 1;
}
+#if defined (_WIN32) && !defined (__CYGWIN__)
+ else if (statbuf_p->st_size == 0)
+ {
+ /* MS-Windows 'stat' reports the null device as a regular file;
+ fix that. */
+ int fd = open (file_name, O_RDONLY | O_BINARY);
+ if (isatty (fd))
+ {
+ statbuf_p->st_mode &= ~S_IFREG;
+ statbuf_p->st_mode |= S_IFCHR;
+ }
+ }
+#endif
+
if (! S_ISREG (statbuf_p->st_mode))
{
error (_("'%s' is not an ordinary file\n"), file_name);
}
if (memcmp (armag, ARMAG, SARMAG) == 0)
- ret = process_archive (file_name, file, FALSE);
+ ret = process_archive (file_name, file, false);
else if (memcmp (armag, ARMAGT, SARMAG) == 0)
- ret = process_archive (file_name, file, TRUE);
+ ret = process_archive (file_name, file, true);
else
{
rewind (file);
ATTRIBUTE_NORETURN static void
usage (FILE *stream, int exit_status)
{
+ unsigned int i;
+ char *osabi = concat (osabis[0].name, NULL);
+
+ for (i = 1; i < ARRAY_SIZE (osabis); i++)
+ osabi = reconcat (osabi, osabi, "|", osabis[i].name, NULL);
+
fprintf (stream, _("Usage: %s <option(s)> elffile(s)\n"),
program_name);
fprintf (stream, _(" Update the ELF header of ELF files\n"));
fprintf (stream, _(" The options are:\n"));
fprintf (stream, _("\
- --input-mach <machine> Set input machine type to <machine>\n\
- --output-mach <machine> Set output machine type to <machine>\n\
- --input-type <type> Set input file type to <type>\n\
- --output-type <type> Set output file type to <type>\n\
- --input-osabi <osabi> Set input OSABI to <osabi>\n\
- --output-osabi <osabi> Set output OSABI to <osabi>\n"));
+ --input-mach [none|i386|iamcu|l1om|k1om|x86_64]\n\
+ Set input machine type\n\
+ --output-mach [none|i386|iamcu|l1om|k1om|x86_64]\n\
+ Set output machine type\n\
+ --input-type [none|rel|exec|dyn]\n\
+ Set input file type\n\
+ --output-type [none|rel|exec|dyn]\n\
+ Set output file type\n\
+ --input-osabi [%s]\n\
+ Set input OSABI\n\
+ --output-osabi [%s]\n\
+ Set output OSABI\n"),
+ osabi, osabi);
#ifdef HAVE_MMAP
fprintf (stream, _("\
- --enable-x86-feature <feature>\n\
- Enable x86 feature <feature>\n\
- --disable-x86-feature <feature>\n\
- Disable x86 feature <feature>\n"));
+ --enable-x86-feature [ibt|shstk|lam_u48|lam_u57]\n\
+ Enable x86 feature\n\
+ --disable-x86-feature [ibt|shstk|lam_u48|lam_u57]\n\
+ Disable x86 feature\n"));
#endif
fprintf (stream, _("\
-h --help Display this information\n\
program_name);
if (REPORT_BUGS_TO[0] && exit_status == 0)
fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
+ free (osabi);
exit (exit_status);
}
{
int c, status;
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
+#ifdef HAVE_LC_MESSAGES
setlocale (LC_MESSAGES, "");
#endif
-#if defined (HAVE_SETLOCALE)
setlocale (LC_CTYPE, "");
-#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);