This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Mark, Could you take a look of the attached 0002*patch file? Only one typo in 0001*patch was fixed and I synced with latest source. I am going to clean up and split my previous patches for nested functions into smaller pieces like this to make your job a little easier. Thanks. On Tue, Sep 15, 2015 at 1:29 PM, Chih-Hung Hsieh <chh@google.com> wrote: > Prepare to compile with clang. > > Signed-off-by: Chih-Hung Hsieh <chh@google.com> > --- > src/ChangeLog | 5 ++++ > src/ld.c | 94 > ++++++++++++++++++++++++++++++----------------------------- > 2 files changed, 53 insertions(+), 46 deletions(-) > > diff --git a/src/ChangeLog b/src/ChangeLog > index 238c416..981aaeb 100644 > --- a/src/ChangeLog > +++ b/src/ChangeLog > @@ -1,3 +1,8 @@ > +2015-09-15 Chih-Hung Hsieh <chh@google.com> > + > + * ld.c (determine_output_format): Move recurisve nested > + function "try" to file scope. > + > 2015-09-09 Chih-Hung Hsieh <chh@google.com> > > * readelf.c (print_debug_exception_table): Initialize variable > before > diff --git a/src/ld.c b/src/ld.c > index 6e96ae2..b9a4f64 100644 > --- a/src/ld.c > +++ b/src/ld.c > @@ -1049,6 +1049,53 @@ parse_B_option_2 (const char *arg) > } > > > +static inline int > +try (int fd, Elf *elf) > +{ > + int result = 0; > + > + if (elf == NULL) > + return 0; > + > + if (elf_kind (elf) == ELF_K_ELF) > + { > + /* We have an ELF file. We now can find out > + what the output format should be. */ > + XElf_Ehdr_vardef(ehdr); > + > + /* Get the ELF header of the object. */ > + xelf_getehdr (elf, ehdr); > + if (ehdr != NULL) > + ld_state.ebl = > + ebl_openbackend_machine (ehdr->e_machine); > + > + result = 1; > + } > + else if (elf_kind (elf) == ELF_K_AR) > + { > + /* Try the archive members. This could > + potentially lead to wrong results if the > + archive contains files for more than one > + architecture. But this is the user's > + problem. */ > + Elf *subelf; > + Elf_Cmd cmd = ELF_C_READ_MMAP; > + > + while ((subelf = elf_begin (fd, cmd, elf)) != NULL) > + { > + cmd = elf_next (subelf); > + > + if (try (fd, subelf) != 0) > + break; > + } > + } > + > + elf_end (elf); > + > + return result; > +} > + > + > static void > determine_output_format (void) > { > @@ -1078,52 +1125,7 @@ determine_output_format (void) > int fd = open (runp->name, O_RDONLY); > if (fd != -1) > { > - int try (Elf *elf) > - { > - int result = 0; > - > - if (elf == NULL) > - return 0; > - > - if (elf_kind (elf) == ELF_K_ELF) > - { > - /* We have an ELF file. We now can find out > - what the output format should be. */ > - XElf_Ehdr_vardef(ehdr); > - > - /* Get the ELF header of the object. */ > - xelf_getehdr (elf, ehdr); > - if (ehdr != NULL) > - ld_state.ebl = > - ebl_openbackend_machine (ehdr->e_machine); > - > - result = 1; > - } > - else if (elf_kind (elf) == ELF_K_AR) > - { > - /* Try the archive members. This could > - potentially lead to wrong results if the > - archive contains files for more than one > - architecture. But this is the user's > - problem. */ > - Elf *subelf; > - Elf_Cmd cmd = ELF_C_READ_MMAP; > - > - while ((subelf = elf_begin (fd, cmd, elf)) != NULL) > - { > - cmd = elf_next (subelf); > - > - if (try (subelf) != 0) > - break; > - } > - } > - > - elf_end (elf); > - > - return result; > - } > - > - if (try (elf_begin (fd, ELF_C_READ_MMAP, NULL)) != 0) > + if (try (fd, elf_begin (fd, ELF_C_READ_MMAP, NULL)) != 0) > /* Found a file. */ > break; > } > -- > 2.6.0.rc0.131.gf624c3d > >
Prepare to compile with clang.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
---
 src/ChangeLog | 5 ++++
 src/ld.c   | 94 ++++++++++++++++++++++++++++++-----------------------------
 2 files changed, 53 insertions(+), 46 deletions(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 238c416..981aaeb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-15 Chih-Hung Hsieh <chh@google.com>
+
+Â Â Â Â * ld.c (determine_output_format): Move recurisve nested
+Â Â Â Â function "try" to file scope.
+
 2015-09-09 Chih-Hung Hsieh <chh@google.com>
    * readelf.c (print_debug_exception_table): Initialize variable before
diff --git a/src/ld.c b/src/ld.c
index 6e96ae2..b9a4f64 100644
--- a/src/ld.c
+++ b/src/ld.c
@@ -1049,6 +1049,53 @@ parse_B_option_2 (const char *arg)
 }
+static inline int
+try (int fd, Elf *elf)
+{
+Â int result = 0;
+
+Â if (elf == NULL)
+Â Â return 0;
+
+Â if (elf_kind (elf) == ELF_K_ELF)
+Â Â {
+   /* We have an ELF file. We now can find out
+    what the output format should be. */
+Â Â Â XElf_Ehdr_vardef(ehdr);
+
+   /* Get the ELF header of the object. */
+Â Â Â xelf_getehdr (elf, ehdr);
+Â Â Â if (ehdr != NULL)
+Â Â Â Â ld_state.ebl =
+Â Â Â Â Â ebl_openbackend_machine (ehdr->e_machine);
+
+Â Â Â result = 1;
+Â Â }
+Â else if (elf_kind (elf) == ELF_K_AR)
+Â Â {
+   /* Try the archive members. This could
+Â Â Â Â potentially lead to wrong results if the
+Â Â Â Â archive contains files for more than one
+    architecture. But this is the user's
+    problem. */
+Â Â Â Elf *subelf;
+Â Â Â Elf_Cmd cmd = ELF_C_READ_MMAP;
+
+Â Â Â while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
+Â Â Â Â {
+Â Â Â Â Â cmd = elf_next (subelf);
+
+Â Â Â Â Â if (try (fd, subelf) != 0)
+Â Â Â Â Â Â break;
+Â Â Â Â }
+Â Â }
+
+Â elf_end (elf);
+
+Â return result;
+}
+
+
 static void
 determine_output_format (void)
 {
@@ -1078,52 +1125,7 @@ determine_output_format (void)
     int fd = open (runp->name, O_RDONLY);
     if (fd != -1)
      {
-Â Â Â Â Â Â Â int try (Elf *elf)
-Â Â Â Â Â Â Â Â {
-Â Â Â Â Â Â Â Â Â int result = 0;
-
-Â Â Â Â Â Â Â Â Â if (elf == NULL)
-Â Â Â Â Â Â Â Â Â Â return 0;
-
-Â Â Â Â Â Â Â Â Â if (elf_kind (elf) == ELF_K_ELF)
-Â Â Â Â Â Â Â Â Â Â {
-           /* We have an ELF file. We now can find out
-            what the output format should be. */
-Â Â Â Â Â Â Â Â Â Â Â XElf_Ehdr_vardef(ehdr);
-
-           /* Get the ELF header of the object. */
-Â Â Â Â Â Â Â Â Â Â Â xelf_getehdr (elf, ehdr);
-Â Â Â Â Â Â Â Â Â Â Â if (ehdr != NULL)
-Â Â Â Â Â Â Â Â Â Â Â Â ld_state.ebl =
-Â Â Â Â Â Â Â Â Â Â Â Â Â ebl_openbackend_machine (ehdr->e_machine);
-
-Â Â Â Â Â Â Â Â Â Â Â result = 1;
-Â Â Â Â Â Â Â Â Â Â }
-Â Â Â Â Â Â Â Â Â else if (elf_kind (elf) == ELF_K_AR)
-Â Â Â Â Â Â Â Â Â Â {
-           /* Try the archive members. This could
-Â Â Â Â Â Â Â Â Â Â Â Â potentially lead to wrong results if the
-Â Â Â Â Â Â Â Â Â Â Â Â archive contains files for more than one
-            architecture. But this is the user's
-            problem. */
-Â Â Â Â Â Â Â Â Â Â Â Elf *subelf;
-Â Â Â Â Â Â Â Â Â Â Â Elf_Cmd cmd = ELF_C_READ_MMAP;
-
-Â Â Â Â Â Â Â Â Â Â Â while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
-Â Â Â Â Â Â Â Â Â Â Â Â {
-Â Â Â Â Â Â Â Â Â Â Â Â Â cmd = elf_next (subelf);
-
-Â Â Â Â Â Â Â Â Â Â Â Â Â if (try (subelf) != 0)
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
-Â Â Â Â Â Â Â Â Â Â Â Â }
-Â Â Â Â Â Â Â Â Â Â }
-
-Â Â Â Â Â Â Â Â Â elf_end (elf);
-
-Â Â Â Â Â Â Â Â Â return result;
-Â Â Â Â Â Â Â Â }
-
-Â Â Â Â Â Â Â if (try (elf_begin (fd, ELF_C_READ_MMAP, NULL)) != 0)
+Â Â Â Â Â Â Â if (try (fd, elf_begin (fd, ELF_C_READ_MMAP, NULL)) != 0)
        /* Found a file. */
        break;
      }
--
2.6.0.rc0.131.gf624c3d
Attachment:
0002-Move-recursive-nested-function-to-file-scope.patch
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |