From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26194 invoked by alias); 2 Sep 2005 15:43:08 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 25600 invoked by uid 22791); 2 Sep 2005 15:42:26 -0000 Received: from smtp104.sbc.mail.mud.yahoo.com (HELO smtp104.sbc.mail.mud.yahoo.com) (68.142.198.203) by sourceware.org (qpsmtpd/0.30-dev) with SMTP; Fri, 02 Sep 2005 15:42:26 +0000 Received: (qmail 7640 invoked from network); 2 Sep 2005 15:42:25 -0000 Received: from unknown (HELO lucon.org) (hjjean@sbcglobal.net@67.122.70.18 with login) by smtp104.sbc.mail.mud.yahoo.com with SMTP; 2 Sep 2005 15:42:24 -0000 Received: by lucon.org (Postfix, from userid 1000) id EAE29640CA; Fri, 2 Sep 2005 08:42:23 -0700 (PDT) Date: Fri, 02 Sep 2005 16:43:00 -0000 From: "H. J. Lu" To: binutils@sources.redhat.com Subject: PATCH: readelf: Handle 64bit sh_flags Message-ID: <20050902154223.GA3582@lucon.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-SW-Source: 2005-09/txt/msg00039.txt.bz2 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 * 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; }