From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: Re: [PATCH 1/2] Add is_executable to Dwfl_Module.
Date: Thu, 11 Sep 2014 21:00:49 +0200 [thread overview]
Message-ID: <20140911190049.GA1901@host2.jankratochvil.net> (raw)
In-Reply-To: 1410380142.27502.36.camel@bordewijk.wildebeest.org
[-- Attachment #1: Type: text/plain, Size: 3033 bytes --]
On Wed, 10 Sep 2014 22:15:42 +0200, Mark Wielaard wrote:
> So I propose a cleanup like the attached first.
While I find that as an improvement in general IMO on top of your patch the
changes could be done a bit differently.
Patricularly I at least miss there that 'e_ident'.
Jan
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 572f15b..be6950d 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -163,11 +163,11 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
/* Extract the information we need from the file header. */
unsigned char ei_class;
unsigned char ei_data;
- uint16_t e_type;
union
{
Elf32_Ehdr e32;
Elf64_Ehdr e64;
+ Elf_Ehdr e;
} ehdr;
GElf_Off phoff;
uint_fast16_t phnum;
@@ -186,15 +186,14 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
.d_size = sizeof ehdr,
.d_version = EV_CURRENT,
};
- ei_class = ((const unsigned char *) buffer)[EI_CLASS];
- ei_data = ((const unsigned char *) buffer)[EI_DATA];
+ ei_class = ((const Elf_Ehdr *) buffer)->e_ident[EI_CLASS];
+ ei_data = ((const Elf_Ehdr *) buffer)->e_ident[EI_DATA];
switch (ei_class)
{
case ELFCLASS32:
xlatefrom.d_size = sizeof (Elf32_Ehdr);
if (elf32_xlatetom (&xlateto, &xlatefrom, ei_data) == NULL)
return finish ();
- e_type = ehdr.e32.e_type;
phoff = ehdr.e32.e_phoff;
phnum = ehdr.e32.e_phnum;
phentsize = ehdr.e32.e_phentsize;
@@ -207,7 +206,6 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
xlatefrom.d_size = sizeof (Elf64_Ehdr);
if (elf64_xlatetom (&xlateto, &xlatefrom, ei_data) == NULL)
return finish ();
- e_type = ehdr.e64.e_type;
phoff = ehdr.e64.e_phoff;
phnum = ehdr.e64.e_phnum;
phentsize = ehdr.e64.e_phentsize;
@@ -609,7 +607,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
/* We'll use the name passed in or a stupid default if not DT_SONAME. */
if (name == NULL)
- name = e_type == ET_EXEC ? "[exe]" : execlike ? "[pie]" : "[dso]";
+ name = ehdr.e.e_type == ET_EXEC ? "[exe]" : execlike ? "[pie]" : "[dso]";
void *soname = NULL;
size_t soname_size = 0;
diff --git a/libelf/elf.h b/libelf/elf.h
index 40e87b2..47e7bc7 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -67,6 +67,14 @@ typedef Elf64_Half Elf64_Versym;
typedef struct
{
unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
+ uint16_t e_type; /* Object file type */
+ uint16_t e_machine; /* Architecture */
+ uint32_t e_version; /* Object file version */
+} Elf_Ehdr;
+
+typedef struct
+{
+ unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
Elf32_Half e_type; /* Object file type */
Elf32_Half e_machine; /* Architecture */
Elf32_Word e_version; /* Object file version */
next reply other threads:[~2014-09-11 19:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-11 19:00 Jan Kratochvil [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-09-22 17:28 Roland McGrath
2014-09-18 14:59 Jan Kratochvil
2014-09-18 14:56 Mark Wielaard
2014-09-10 20:15 Mark Wielaard
2014-09-10 18:56 Mark Wielaard
2014-09-10 7:21 Jan Kratochvil
2014-09-09 21:55 Roland McGrath
2014-09-09 21:51 Jan Kratochvil
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=20140911190049.GA1901@host2.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=elfutils-devel@lists.fedorahosted.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).