]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
unstrip: Inline find_unalloc_section() into only caller
authorTimm Bäder <tbaeder@redhat.com>
Wed, 17 Feb 2021 08:43:46 +0000 (09:43 +0100)
committerMark Wielaard <mark@klomp.org>
Mon, 1 Mar 2021 17:07:10 +0000 (18:07 +0100)
Get rid of an unnecessary nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
src/ChangeLog
src/unstrip.c

index 9e7d6cb9b613c9a40182979514b7e841013f1d3b..f358baa26480c466d1f5ae407a65c3c3f5ce2d1d 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2021-02-17  Timm Bäder  <tbaeder@redhat.com>
 
        * unstrip.c (find_alloc_sections_prelink): Move check_match to...
index 72fabac8e8bbdf82b43ac8c616c9d412bf5fc46d..90e0283166dd50c79994ffb735f794cbff3b6b99 100644 (file)
@@ -1452,29 +1452,6 @@ more sections in stripped file than debug file -- arguments reversed?"));
        stripped_symtab = &sections[nalloc];
     }
 
-  /* Locate a matching unallocated section in SECTIONS.  */
-  inline struct section *find_unalloc_section (const GElf_Shdr *shdr,
-                                              const char *name,
-                                              const char *sig)
-    {
-      size_t l = nalloc, u = stripped_shnum - 1;
-      while (l < u)
-       {
-         size_t i = (l + u) / 2;
-         struct section *sec = &sections[i];
-         int cmp = compare_unalloc_sections (shdr, &sec->shdr,
-                                             name, sec->name,
-                                             sig, sec->sig);
-         if (cmp < 0)
-           u = i;
-         else if (cmp > 0)
-           l = i + 1;
-         else
-           return sec;
-       }
-      return NULL;
-    }
-
   Elf_Data *shstrtab = elf_getdata (elf_getscn (unstripped,
                                                unstripped_shstrndx), NULL);
   ELF_CHECK (shstrtab != NULL,
@@ -1536,9 +1513,27 @@ more sections in stripped file than debug file -- arguments reversed?"));
        }
       else
        {
-         /* Look for the section that matches.  */
-         sec = find_unalloc_section (shdr, name,
-                                     get_group_sig (unstripped, shdr));
+         /* Locate a matching unallocated section in SECTIONS.  */
+         const char *sig = get_group_sig (unstripped, shdr);
+         size_t l = nalloc, u = stripped_shnum - 1;
+         while (l < u)
+           {
+             size_t i = (l + u) / 2;
+             struct section *section = &sections[i];
+             int cmp = compare_unalloc_sections (shdr, &section->shdr,
+                                                 name, section->name,
+                                                 sig, section->sig);
+             if (cmp < 0)
+               u = i;
+             else if (cmp > 0)
+               l = i + 1;
+             else
+               {
+                 sec = section;
+                 break;
+               }
+           }
+
          if (sec == NULL)
            {
              /* An additional unallocated section is fine if not SHT_NOBITS.