public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] Replace libdwelf nested functions with macros.
@ 2015-10-14 17:18 Chih-Hung Hsieh
  0 siblings, 0 replies; 2+ messages in thread
From: Chih-Hung Hsieh @ 2015-10-14 17:18 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 3161 bytes --]

This patch could be abandoned and replaced by the new patch "Move nested
functions in libdwelf".



On Tue, Sep 15, 2015 at 2:26 PM, Chih-Hung Hsieh <chh@google.com> wrote:

> To be compiled without gnu99 extension.
>
> Signed-off-by: Chih-Hung Hsieh <chh@google.com>
> ---
>  libdwelf/ChangeLog                |  5 +++++
>  libdwelf/dwelf_elf_gnu_build_id.c | 42
> +++++++++++++++++++++------------------
>  2 files changed, 28 insertions(+), 19 deletions(-)
>
> diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
> index 342cb9c..1300182 100644
> --- a/libdwelf/ChangeLog
> +++ b/libdwelf/ChangeLog
> @@ -1,3 +1,8 @@
> +2015-09-14  Chih-Hung Hsieh  <chh@google.com>
> +
> +       * dwelf_elf_gnu_build_id.c (find_elf_build_id): Replace nested
> function
> +       with macro.
> +
>  2014-11-14  Mark Wielaard  <mjw@redhat.com>
>
>         * dwelf_elf_gnu_debuglink.c (dwelf_elf_gnu_debuglink): Check d_buf
> diff --git a/libdwelf/dwelf_elf_gnu_build_id.c
> b/libdwelf/dwelf_elf_gnu_build_id.c
> index 1ed501d..cb20bca 100644
> --- a/libdwelf/dwelf_elf_gnu_build_id.c
> +++ b/libdwelf/dwelf_elf_gnu_build_id.c
> @@ -42,25 +42,29 @@ find_elf_build_id (Dwfl_Module *mod, int e_type, Elf
> *elf,
>                    const void **build_id_bits, GElf_Addr *build_id_elfaddr,
>                    int *build_id_len)
>  {
> -  int check_notes (Elf_Data *data, GElf_Addr data_elfaddr)
> -  {
> -    size_t pos = 0;
> -    GElf_Nhdr nhdr;
> -    size_t name_pos;
> -    size_t desc_pos;
> -    while ((pos = gelf_getnote (data, pos, &nhdr, &name_pos, &desc_pos))
> > 0)
> -      if (nhdr.n_type == NT_GNU_BUILD_ID
> -         && nhdr.n_namesz == sizeof "GNU" && !memcmp (data->d_buf +
> name_pos,
> -                                                      "GNU", sizeof
> "GNU"))
> -       {
> -         *build_id_bits = data->d_buf + desc_pos;
> -         *build_id_elfaddr = (data_elfaddr == NO_VADDR
> -                              ? 0 : data_elfaddr + desc_pos);
> -         *build_id_len = nhdr.n_descsz;
> -         return 1;
> -       }
> -    return 0;
> -  }
> +#define check_notes(_data, _data_elfaddr) \
> +  ( { \
> +    Elf_Data *data = _data; \
> +    GElf_Addr data_elfaddr = _data_elfaddr;  \
> +    int check_result = 0; \
> +    size_t pos = 0; \
> +    GElf_Nhdr nhdr; \
> +    size_t name_pos; \
> +    size_t desc_pos; \
> +    while ((pos = gelf_getnote (data, pos, &nhdr, &name_pos, &desc_pos))
> > 0) \
> +      if (nhdr.n_type == NT_GNU_BUILD_ID \
> +         && nhdr.n_namesz == sizeof "GNU" && !memcmp (data->d_buf +
> name_pos, \
> +                                                      "GNU", sizeof
> "GNU")) \
> +       { \
> +         *build_id_bits = data->d_buf + desc_pos; \
> +         *build_id_elfaddr = (data_elfaddr == NO_VADDR \
> +                              ? 0 : data_elfaddr + desc_pos); \
> +         *build_id_len = nhdr.n_descsz; \
> +         check_result = 1; \
> +         break; \
> +       } \
> +    check_result; \
> +  } )
>
>    size_t shstrndx = SHN_UNDEF;
>    int result = 0;
> --
> 2.6.0.rc0.131.gf624c3d
>
>

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 4097 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] Replace libdwelf nested functions with macros.
@ 2015-09-15 21:26 Chih-Hung Hsieh
  0 siblings, 0 replies; 2+ messages in thread
From: Chih-Hung Hsieh @ 2015-09-15 21:26 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 2545 bytes --]

To be compiled without gnu99 extension.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
---
 libdwelf/ChangeLog                |  5 +++++
 libdwelf/dwelf_elf_gnu_build_id.c | 42 +++++++++++++++++++++------------------
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
index 342cb9c..1300182 100644
--- a/libdwelf/ChangeLog
+++ b/libdwelf/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-14  Chih-Hung Hsieh  <chh@google.com>
+
+	* dwelf_elf_gnu_build_id.c (find_elf_build_id): Replace nested function
+	with macro.
+
 2014-11-14  Mark Wielaard  <mjw@redhat.com>
 
 	* dwelf_elf_gnu_debuglink.c (dwelf_elf_gnu_debuglink): Check d_buf
diff --git a/libdwelf/dwelf_elf_gnu_build_id.c b/libdwelf/dwelf_elf_gnu_build_id.c
index 1ed501d..cb20bca 100644
--- a/libdwelf/dwelf_elf_gnu_build_id.c
+++ b/libdwelf/dwelf_elf_gnu_build_id.c
@@ -42,25 +42,29 @@ find_elf_build_id (Dwfl_Module *mod, int e_type, Elf *elf,
 		   const void **build_id_bits, GElf_Addr *build_id_elfaddr,
 		   int *build_id_len)
 {
-  int check_notes (Elf_Data *data, GElf_Addr data_elfaddr)
-  {
-    size_t pos = 0;
-    GElf_Nhdr nhdr;
-    size_t name_pos;
-    size_t desc_pos;
-    while ((pos = gelf_getnote (data, pos, &nhdr, &name_pos, &desc_pos)) > 0)
-      if (nhdr.n_type == NT_GNU_BUILD_ID
-	  && nhdr.n_namesz == sizeof "GNU" && !memcmp (data->d_buf + name_pos,
-						       "GNU", sizeof "GNU"))
-	{
-	  *build_id_bits = data->d_buf + desc_pos;
-	  *build_id_elfaddr = (data_elfaddr == NO_VADDR
-			       ? 0 : data_elfaddr + desc_pos);
-	  *build_id_len = nhdr.n_descsz;
-	  return 1;
-	}
-    return 0;
-  }
+#define check_notes(_data, _data_elfaddr) \
+  ( { \
+    Elf_Data *data = _data; \
+    GElf_Addr data_elfaddr = _data_elfaddr;  \
+    int check_result = 0; \
+    size_t pos = 0; \
+    GElf_Nhdr nhdr; \
+    size_t name_pos; \
+    size_t desc_pos; \
+    while ((pos = gelf_getnote (data, pos, &nhdr, &name_pos, &desc_pos)) > 0) \
+      if (nhdr.n_type == NT_GNU_BUILD_ID \
+	  && nhdr.n_namesz == sizeof "GNU" && !memcmp (data->d_buf + name_pos, \
+						       "GNU", sizeof "GNU")) \
+	{ \
+	  *build_id_bits = data->d_buf + desc_pos; \
+	  *build_id_elfaddr = (data_elfaddr == NO_VADDR \
+			       ? 0 : data_elfaddr + desc_pos); \
+	  *build_id_len = nhdr.n_descsz; \
+	  check_result = 1; \
+	  break; \
+	} \
+    check_result; \
+  } )
 
   size_t shstrndx = SHN_UNDEF;
   int result = 0;
-- 
2.6.0.rc0.131.gf624c3d


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-14 17:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 17:18 [PATCH] Replace libdwelf nested functions with macros Chih-Hung Hsieh
  -- strict thread matches above, loose matches on Subject: below --
2015-09-15 21:26 Chih-Hung Hsieh

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).