This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: readelf: Handle 64bit sh_flags
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Fri, 2 Sep 2005 08:42:23 -0700
- Subject: PATCH: readelf: Handle 64bit sh_flags
Some compiler may generate sh_flags==0xffffffffc0000003 in 64bit ELF
object file. The current readelf outputs:
[ 9] .ctors
PROGBITS 0000000000000000 00000000000008ab 0
0000000000000008 0000000000000000 0 8
[ffffffffc00WRITE, ALLOC, PROC (40000000), PROC (80000000),
UNKNOWN (100000000, UNKNOWN (200000000, UNKNOWN (400000000, UNKNOWN
(800000000, UNKNOWN (100000000, UNKNOWN (200000000, UNKNOWN (400000000,
UNKNOWN (800000000, UNKNOWN (100000000, UNKNOWN (200000000, UNKNOWN
(400000000, UNKNOWN (800000000, UNKNOWN (100000000, UNKNOWN (200000000,
UNKNOWN (400000000, UNKNOWN (800000000, UNKNOWN (100000000, UNKNOWN
(200000000, UNKNOWN (400000000, UNKNOWN (800000000, UNKNOWN (100000000,
UNKNOWN (200000000, UNKNOWN (400000000, UNKNOWN (800000000, UNKNOWN
(100000000, UNKNOWN (200000000, UNKNOWN (400000000, UNKNOWN (800000000,
UNKNOWN (100000000, UNKNOWN (200000000, UNKNOWN (400000000, UNKNOWN
(800000000
Also it doesn't provide anything useful to display OS/PROC/unknown
field one bit at a time. This patch changes it to
[ 9] .ctors
PROGBITS 0000000000000000 00000000000008ab 0
0000000000000008 0000000000000000 0 8
[ffffffffc0000003]: WRITE, ALLOC, PROC (00000000c0000000),
UNKNOWN (ffffffff00000000)
H.J.
----
2005-09-02 H.J. Lu <hongjiu.lu@intel.com>
* readelf.c (get_elf_section_flags): Handle 64bit sh_flags.
--- binutils/readelf.c.flag 2005-09-02 06:59:00.000000000 -0700
+++ binutils/readelf.c 2005-09-02 08:27:45.000000000 -0700
@@ -3799,7 +3799,11 @@ get_elf_section_flags (bfd_vma sh_flags)
{
static char buff[1024];
char *p = buff;
- int index, size = sizeof (buff) - (8 + 4 + 1);
+ int field_size = is_32bit_elf ? 8 : 16;
+ int index, size = sizeof (buff) - (field_size + 4 + 1);
+ bfd_vma os_flags = 0;
+ bfd_vma proc_flags = 0;
+ bfd_vma unknown_flags = 0;
const struct
{
const char *str;
@@ -3821,8 +3825,9 @@ get_elf_section_flags (bfd_vma sh_flags)
if (do_section_details)
{
- sprintf (buff, "[%8.8lx]: ", (unsigned long) sh_flags);
- p += 8 + 4;
+ sprintf (buff, "[%*.*lx]: ",
+ field_size, field_size, (unsigned long) sh_flags);
+ p += field_size + 4;
}
while (sh_flags)
@@ -3852,38 +3857,26 @@ get_elf_section_flags (bfd_vma sh_flags)
break;
}
- if (p != buff + 8 + 4)
- {
- if (size < 10 + 2)
- abort ();
- size -= 2;
- *p++ = ',';
- *p++ = ' ';
- }
-
if (index != -1)
{
+ if (p != buff + field_size + 4)
+ {
+ if (size < (10 + 2))
+ abort ();
+ size -= 2;
+ *p++ = ',';
+ *p++ = ' ';
+ }
+
size -= flags [index].len;
p = stpcpy (p, flags [index].str);
}
else if (flag & SHF_MASKOS)
- {
- size -= 5 + 8;
- sprintf (p, "OS (%8.8lx)", (unsigned long) flag);
- p += 5 + 8;
- }
+ os_flags |= flag;
else if (flag & SHF_MASKPROC)
- {
- size -= 7 + 8;
- sprintf (p, "PROC (%8.8lx)", (unsigned long) flag);
- p += 7 + 8;
- }
+ proc_flags |= flag;
else
- {
- size -= 10 + 8;
- sprintf (p, "UNKNOWN (%8.8lx)", (unsigned long) flag);
- p += 10 + 8;
- }
+ unknown_flags |= flag;
}
else
{
@@ -3922,6 +3915,55 @@ get_elf_section_flags (bfd_vma sh_flags)
}
}
+ if (do_section_details)
+ {
+ if (os_flags)
+ {
+ size -= 5 + field_size;
+ if (p != buff + field_size + 4)
+ {
+ if (size < (2 + 1))
+ abort ();
+ size -= 2;
+ *p++ = ',';
+ *p++ = ' ';
+ }
+ sprintf (p, "OS (%*.*lx)", field_size, field_size,
+ (unsigned long) os_flags);
+ p += 5 + field_size;
+ }
+ if (proc_flags)
+ {
+ size -= 7 + field_size;
+ if (p != buff + field_size + 4)
+ {
+ if (size < (2 + 1))
+ abort ();
+ size -= 2;
+ *p++ = ',';
+ *p++ = ' ';
+ }
+ sprintf (p, "PROC (%*.*lx)", field_size, field_size,
+ (unsigned long) proc_flags);
+ p += 7 + field_size;
+ }
+ if (unknown_flags)
+ {
+ size -= 10 + field_size;
+ if (p != buff + field_size + 4)
+ {
+ if (size < (2 + 1))
+ abort ();
+ size -= 2;
+ *p++ = ',';
+ *p++ = ' ';
+ }
+ sprintf (p, "UNKNOWN (%*.*lx)", field_size, field_size,
+ (unsigned long) unknown_flags);
+ p += 10 + field_size;
+ }
+ }
+
*p = '\0';
return buff;
}