summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2021-02-17 09:43:47 +0100
committerMark Wielaard <mark@klomp.org>2021-03-01 18:07:20 +0100
commit93a6c36c8540f073d487d9be97bcfabb591cda2c (patch)
treec92a5d958426ec47480bc44da61788e57a88bd65
parent39c67b8f6c0dcee999eb8e73f8e07a41efb78c2b (diff)
downloadelfutils-93a6c36c8540f073d487d9be97bcfabb591cda2c.tar.gz
unstrip: Pull warn() into file scope
Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
-rw-r--r--src/ChangeLog6
-rw-r--r--src/unstrip.c35
2 files changed, 26 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f358baa2..9e0ebd89 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
2021-02-17 Timm Bäder <tbaeder@redhat.com>
+ * unstrip.c (handle_explicit_files): Move warn function...
+ (warn): ...here as top-level static function taking stripped,
+ unstripped files and force flag as extra arguments.
+
+2021-02-17 Timm Bäder <tbaeder@redhat.com>
+
* unstrip.c (copy_elided_sections): Inline find_unalloc_section
function into calling location. The sec pointer is set to NULL
before the if-else statement and only set when match is found.
diff --git a/src/unstrip.c b/src/unstrip.c
index 90e02831..612b7cbf 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -2225,22 +2225,23 @@ open_file (const char *file, bool writable)
return fd;
}
+/* Warn, and exit if not forced to continue, if some ELF header
+ sanity check for the stripped and unstripped files failed. */
+static void
+warn (const char *msg, bool force,
+ const char *stripped_file, const char *unstripped_file)
+{
+ error (force ? 0 : EXIT_FAILURE, 0, "%s'%s' and '%s' %s%s.",
+ force ? _("WARNING: ") : "",
+ stripped_file, unstripped_file, msg,
+ force ? "" : _(", use --force"));
+}
+
/* Handle a pair of files we need to open by name. */
static void
handle_explicit_files (const char *output_file, bool create_dirs, bool force,
const char *stripped_file, const char *unstripped_file)
{
-
- /* Warn, and exit if not forced to continue, if some ELF header
- sanity check for the stripped and unstripped files failed. */
- void warn (const char *msg)
- {
- error (force ? 0 : EXIT_FAILURE, 0, "%s'%s' and '%s' %s%s.",
- force ? _("WARNING: ") : "",
- stripped_file, unstripped_file, msg,
- force ? "" : _(", use --force"));
- }
-
int stripped_fd = open_file (stripped_file, false);
Elf *stripped = elf_begin (stripped_fd, ELF_C_READ, NULL);
GElf_Ehdr stripped_ehdr;
@@ -2261,16 +2262,20 @@ handle_explicit_files (const char *output_file, bool create_dirs, bool force,
if (memcmp (stripped_ehdr.e_ident,
unstripped_ehdr.e_ident, EI_NIDENT) != 0)
- warn (_("ELF header identification (e_ident) different"));
+ warn (_("ELF header identification (e_ident) different"), force,
+ stripped_file, unstripped_file);
if (stripped_ehdr.e_type != unstripped_ehdr.e_type)
- warn (_("ELF header type (e_type) different"));
+ warn (_("ELF header type (e_type) different"), force,
+ stripped_file, unstripped_file);
if (stripped_ehdr.e_machine != unstripped_ehdr.e_machine)
- warn (_("ELF header machine type (e_machine) different"));
+ warn (_("ELF header machine type (e_machine) different"), force,
+ stripped_file, unstripped_file);
if (stripped_ehdr.e_phnum < unstripped_ehdr.e_phnum)
- warn (_("stripped program header (e_phnum) smaller than unstripped"));
+ warn (_("stripped program header (e_phnum) smaller than unstripped"),
+ force, stripped_file, unstripped_file);
}
handle_file (output_file, create_dirs, stripped, &stripped_ehdr, unstripped);