public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: tbaeder@redhat.com
To: elfutils-devel@sourceware.org
Subject: [PATCH 1/4] strip: Replace nested check_preserved function with loop
Date: Fri,  8 Jan 2021 09:04:46 +0100	[thread overview]
Message-ID: <20210108080449.2201310-2-tbaeder@redhat.com> (raw)
In-Reply-To: <20210108080449.2201310-1-tbaeder@redhat.com>

From: Timm Bäder <tbaeder@redhat.com>

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
 src/strip.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/strip.c b/src/strip.c
index 7ce14ab8..c971b6c2 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1535,25 +1535,30 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 		 files by setting the .debug_data pointer to the original
 		 file's .data pointer.  Below, we'll copy the section
 		 contents.  */
+	      size_t shdr_indices[2] = { shdr_info[cnt].shdr.sh_link, 0 };
+	      int n = 1;
 
-	      inline void check_preserved (size_t i)
-	      {
-		if (i != 0 && i < shnum + 2 && shdr_info[i].idx != 0
-		    && shdr_info[i].debug_data == NULL)
-		  {
-		    if (shdr_info[i].data == NULL)
-		      shdr_info[i].data = elf_getdata (shdr_info[i].scn, NULL);
-		    if (shdr_info[i].data == NULL)
-		      INTERNAL_ERROR (fname);
+	      if (SH_INFO_LINK_P (&shdr_info[cnt].shdr))
+		{
+		  shdr_indices[1] = shdr_info[cnt].shdr.sh_info;
+		  n++;
+		}
 
-		    shdr_info[i].debug_data = shdr_info[i].data;
-		    changes |= i < cnt;
-		  }
-	      }
+	      for (int j = 0; j < n; j++)
+		{
+		  size_t i = shdr_indices[j];
+		  if (i != 0 && i < shnum + 2 && shdr_info[i].idx != 0
+		      && shdr_info[i].debug_data == NULL)
+		    {
+		      if (shdr_info[i].data == NULL)
+			shdr_info[i].data = elf_getdata (shdr_info[i].scn, NULL);
+		      if (shdr_info[i].data == NULL)
+			INTERNAL_ERROR (fname);
 
-	      check_preserved (shdr_info[cnt].shdr.sh_link);
-	      if (SH_INFO_LINK_P (&shdr_info[cnt].shdr))
-		check_preserved (shdr_info[cnt].shdr.sh_info);
+		      shdr_info[i].debug_data = shdr_info[i].data;
+		      changes |= i < cnt;
+		    }
+		}
 	    }
 	}
     }
-- 
2.26.2


  reply	other threads:[~2021-01-08  8:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08  8:04 Remove nested functions from src/strip.c tbaeder
2021-01-08  8:04 ` tbaeder [this message]
2021-01-28 12:17   ` [PATCH 1/4] strip: Replace nested check_preserved function with loop Mark Wielaard
2021-01-08  8:04 ` [PATCH 2/4] strip: Pull relocate() info file scope tbaeder
2021-01-28 12:50   ` Mark Wielaard
2021-01-08  8:04 ` [PATCH 3/4] strip: Pull update_section_size() into " tbaeder
2021-01-28 12:59   ` Mark Wielaard
2021-01-08  8:04 ` [PATCH 4/4] strip: Remove no_symtab_updates() function tbaeder
2021-01-28 13:29   ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210108080449.2201310-2-tbaeder@redhat.com \
    --to=tbaeder@redhat.com \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).