From: "Maciej W. Rozycki" <macro@imgtec.com>
To: <binutils@sourceware.org>
Subject: [committed v2] MIPS/readelf: With `-A' also dump GOT in static binaries
Date: Wed, 26 Apr 2017 12:35:00 -0000 [thread overview]
Message-ID: <alpine.DEB.2.00.1704242002530.25796@tp.orcam.me.uk> (raw)
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.
---
Changes in v2:
- If GOT[0] is non-zero in a static binary, then assume no reserved
entries are present.
binutils-mips-readelf-arch-static-got.diff
Index: binutils/binutils/readelf.c
===================================================================
--- binutils.orig/binutils/readelf.c 2017-04-24 19:58:23.206368293 +0100
+++ binutils/binutils/readelf.c 2017-04-24 20:15:58.135427885 +0100
@@ -15007,8 +15007,93 @@ 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");
+
+ /* In a dynamic binary GOT[0] is reserved for the dynamic
+ loader to store the lazy resolver pointer, however in
+ a static binary it may well have been omitted and GOT
+ reduced to a table of addresses.
+ 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) == 0)
+ {
+ 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. */
reply other threads:[~2017-04-26 12:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=alpine.DEB.2.00.1704242002530.25796@tp.orcam.me.uk \
--to=macro@imgtec.com \
--cc=binutils@sourceware.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).