From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58726 invoked by alias); 11 Apr 2017 23:08:52 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 58690 invoked by uid 89); 11 Apr 2017 23:08:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=reserved X-HELO: mailapp01.imgtec.com Received: from mailapp01.imgtec.com (HELO mailapp01.imgtec.com) (195.59.15.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Apr 2017 23:08:49 +0000 Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id B53C3BEC72FE8 for ; Wed, 12 Apr 2017 00:08:43 +0100 (IST) Received: from [10.20.78.80] (10.20.78.80) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server id 14.3.294.0; Wed, 12 Apr 2017 00:08:47 +0100 Date: Tue, 11 Apr 2017 23:08:00 -0000 From: "Maciej W. Rozycki" To: Subject: [PATCH] MIPS/readelf: With `-A' also dump GOT in static binaries Message-ID: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-SW-Source: 2017-04/txt/msg00126.txt.bz2 A static, non-relocated global offset table will be embedded in static binaries produced from objects containing any kind of GOT relocations, generally PIC code. All symbols will have been resolved in static link in such binaries making all GOT entries local and their values final as there is no run-time load processing further performed. Dump such GOT with `readelf -A' like already done with regular GOT, to make it easier to examine static code that uses accesses via the GOT pointer. There will be no dynamic segment or section in a static binary to get the GOT pointer (DT_PLTGOT) from, so use section headers to find a `.got' section instead. binutils/ * readelf.c (process_mips_specific): Add static GOT support. --- I will commit this change shortly, once the two outstanding `readelf' clean-ups recently posted have been committed that this change is conceptually consistent with. Maciej binutils-mips-readelf-arch-static-got.diff Index: binutils/binutils/readelf.c =================================================================== --- binutils.orig/binutils/readelf.c 2017-04-10 23:37:14.563833225 +0100 +++ binutils/binutils/readelf.c 2017-04-10 23:40:11.957781646 +0100 @@ -15001,8 +15001,82 @@ process_mips_specific (FILE * file) /* We have a lot of special sections. Thanks SGI! */ if (dynamic_section == NULL) - /* No information available. */ - return res; + { + /* No dynamic information available. See if there is static GOT. */ + sect = find_section (".got"); + if (sect != NULL) + { + unsigned char *data_end; + unsigned char *data; + bfd_vma ent, end; + int addr_size; + + pltgot = sect->sh_addr; + + ent = pltgot; + addr_size = (is_32bit_elf ? 4 : 8); + end = pltgot + sect->sh_size; + + data = (unsigned char *) get_data (NULL, file, sect->sh_offset, + end - pltgot, 1, + _("Global Offset Table data")); + /* PR 12855: Null data is handled gracefully throughout. */ + data_end = data + (end - pltgot); + + printf (_("\nStatic GOT:\n")); + printf (_(" Canonical gp value: ")); + print_vma (ent + 0x7ff0, LONG_HEX); + printf ("\n\n"); + + printf (_(" Reserved entries:\n")); + printf (_(" %*s %10s %*s\n"), + addr_size * 2, _("Address"), _("Access"), + addr_size * 2, _("Value")); + ent = print_mips_got_entry (data, pltgot, ent, data_end); + printf ("\n"); + if (ent == (bfd_vma) -1) + goto sgot_print_fail; + + /* Check for the MSB of GOT[1] being set, identifying a GNU + object. This entry will be used by some runtime loaders, + to store the module pointer. Otherwise this is an ordinary + local entry. + PR 21344: Check for the entry being fully available before + fetching it. */ + if (data + && data + ent - pltgot + addr_size <= data_end + && (byte_get (data + ent - pltgot, addr_size) + >> (addr_size * 8 - 1)) != 0) + { + ent = print_mips_got_entry (data, pltgot, ent, data_end); + printf ("\n"); + if (ent == (bfd_vma) -1) + goto sgot_print_fail; + } + printf ("\n"); + + if (ent < end) + { + printf (_(" Local entries:\n")); + printf (" %*s %10s %*s\n", + addr_size * 2, _("Address"), _("Access"), + addr_size * 2, _("Value")); + while (ent < end) + { + ent = print_mips_got_entry (data, pltgot, ent, data_end); + printf ("\n"); + if (ent == (bfd_vma) -1) + goto sgot_print_fail; + } + printf ("\n"); + } + + sgot_print_fail: + if (data) + free (data); + } + return res; + } for (entry = dynamic_section; /* PR 17531 file: 012-50589-0.004. */