From: "Martin Liška" <mliska@suse.cz>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, Jan Hubicka <hubicka@ucw.cz>
Subject: Strange read for simple_object_elf_find_sections for .a file
Date: Thu, 12 Mar 2020 11:36:47 +0100 [thread overview]
Message-ID: <3653c711-d7e8-a3e5-1263-326ce1c177a2@suse.cz> (raw)
In-Reply-To: <15eb771d-6d3a-b9e3-3349-cabfb123cdc6@suse.cz>
[-- Attachment #1: Type: text/plain, Size: 585 bytes --]
Hi.
I noticed a strange error during parsing of .gnu.lto_.lto section
in LTO plugin:
$ cat bss.c
int global_zero;
int global_one = 1;
int main() { return 0; }
$ gcc -flto bss.c -c
$ gcc bss.o
read version 9.0
while:
$ ar r x.a bss.o
ar: creating x.a
$ gcc x.a
read version 13617.13368
$ objdump -s -j .gnu.lto_.lto.655b2ec59df60b19 x.a
In archive x.a:
bss.o: file format elf64-x86-64
Contents of section .gnu.lto_.lto.655b2ec59df60b19:
0000 09000000 01000100 ........
which is the same as objdump of bss.o
Any idea why that happens?
Thanks,
Martin
[-- Attachment #2: 0001-Test-x.patch --]
[-- Type: text/x-patch, Size: 2733 bytes --]
From f12831ebf6ed68b569f6d0c6a9243dfa15ba3b40 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 12 Mar 2020 11:30:17 +0100
Subject: [PATCH] Test x.
---
lto-plugin/lto-plugin.c | 57 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 55 insertions(+), 2 deletions(-)
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index c307fc871bf..fbe2c6885f0 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -90,6 +90,8 @@ along with this program; see the file COPYING3. If not see
#define LTO_SECTION_PREFIX ".gnu.lto_.symtab"
#define LTO_SECTION_PREFIX_LEN (sizeof (LTO_SECTION_PREFIX) - 1)
+#define LTO_LTO_PREFIX ".gnu.lto_.lto"
+#define LTO_LTO_PREFIX_LEN (sizeof (LTO_LTO_PREFIX) - 1)
#define OFFLOAD_SECTION ".gnu.offload_lto_.opts"
#define OFFLOAD_SECTION_LEN (sizeof (OFFLOAD_SECTION) - 1)
@@ -1010,6 +1012,52 @@ process_offload_section (void *data, const char *name, off_t offset, off_t len)
return 1;
}
+/* Structure that represents LTO ELF section with information
+ about the format. */
+
+struct lto_section
+ {
+ int16_t major_version;
+ int16_t minor_version;
+ unsigned char slim_object: 1;
+ unsigned char compression: 4;
+ int32_t reserved0: 27;
+};
+
+struct lto_section lto_header;
+
+
+/* Find and parse .lto section of an object file. */
+
+static int
+process_lto_section (void *data, const char *name, off_t offset, off_t len)
+{
+ struct plugin_objfile *obj = (struct plugin_objfile *)data;
+ if (strncmp (name, LTO_LTO_PREFIX, LTO_LTO_PREFIX_LEN) == 0)
+ {
+ if (offset != lseek (obj->file->fd, offset, SEEK_SET))
+ goto err;
+
+ ssize_t got = read (obj->file->fd, <o_header,
+ sizeof (struct lto_section));
+ if (got != sizeof (struct lto_section))
+ goto err;
+
+ fprintf (stderr, "read version %d.%d\n", lto_header.major_version,
+ lto_header.minor_version);
+
+ return 0;
+ }
+
+ return 1;
+
+err:
+ if (message)
+ message (LDPL_FATAL, "%s: corrupt object file", obj->file->name);
+ obj->found = 0;
+ return 0;
+}
+
/* Callback used by gold to check if the plugin will claim FILE. Writes
the result in CLAIMED. */
@@ -1055,8 +1103,13 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
if (!obj.objfile && !err)
goto err;
- if (obj.objfile)
- errmsg = simple_object_find_sections (obj.objfile, process_symtab, &obj, &err);
+ if (obj.objfile)
+ {
+ errmsg = simple_object_find_sections (obj.objfile, process_symtab, &obj, &err);
+
+ if (!errmsg)
+ errmsg = simple_object_find_sections (obj.objfile, process_lto_section, &obj, &err);
+ }
if (!obj.objfile || errmsg)
{
--
2.25.1
next prev parent reply other threads:[~2020-03-12 10:36 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-09 9:30 [PATCH][RFC] API extension for binutils (type of symbols) Martin Liška
2020-03-09 15:36 ` H.J. Lu
2020-03-09 16:56 ` Martin Liška
2020-03-09 18:25 ` H.J. Lu
2020-03-09 20:19 ` Jan Hubicka
2020-03-10 10:05 ` Martin Liška
2020-03-10 10:49 ` Richard Biener
2020-03-10 11:09 ` Jan Hubicka
2020-03-10 11:24 ` Richard Biener
2020-03-10 12:07 ` Martin Liška
2020-03-11 9:19 ` Martin Liška
2020-03-11 10:22 ` Richard Biener
2020-03-11 10:30 ` Richard Biener
2020-03-11 12:22 ` Martin Liška
2020-03-11 12:51 ` Richard Biener
2020-03-11 13:07 ` Martin Liška
2020-03-11 13:24 ` H.J. Lu
2020-03-11 13:28 ` Martin Liška
2020-03-11 14:16 ` Alexander Monakov
2020-03-11 14:15 ` Martin Liška
2020-03-12 10:36 ` Martin Liška [this message]
2020-03-12 10:39 ` Strange read for simple_object_elf_find_sections for .a file Martin Liška
2020-03-12 12:32 ` [PATCH][RFC] API extension for binutils (type of symbols) Martin Liška
2020-03-12 12:55 ` Jan Hubicka
2020-03-12 13:10 ` Martin Liška
2020-03-12 13:15 ` Richard Biener
2020-03-12 13:24 ` Martin Liška
2020-03-12 13:31 ` Martin Liška
2020-03-16 11:12 ` H.J. Lu
2020-03-16 13:50 ` Martin Liška
2020-03-16 14:34 ` H.J. Lu
2020-03-16 14:38 ` Martin Liška
2020-03-17 23:27 ` Jan Hubicka
2020-03-18 8:52 ` Martin Liška
2020-03-18 8:53 ` [PATCH] Bump LTO bytecode version Martin Liška
2020-03-18 8:56 ` Richard Biener
2020-03-18 9:00 ` Martin Liška
2020-03-18 9:34 ` Richard Biener
2020-03-18 10:20 ` Martin Liška
2020-03-19 9:12 ` [PATCH][RFC] API extension for binutils (type of symbols) Richard Biener
2020-03-19 15:00 ` Martin Liška
2020-03-19 15:46 ` Richard Biener
2020-03-19 15:50 ` H.J. Lu
2020-03-19 16:00 ` Martin Liška
2020-03-19 16:51 ` H.J. Lu
2020-03-19 19:56 ` Richard Biener
2020-03-19 20:07 ` H.J. Lu
2020-03-09 19:45 ` Michael Matz
2020-03-10 9:39 ` Martin Liška
2020-03-10 12:20 ` Martin Liška
2020-03-10 14:26 ` Michael Matz
2020-03-26 16:54 ` Jeff Law
2020-03-27 9:10 ` Martin Liška
2020-03-27 14:21 ` Jeff Law
2020-03-27 15:21 ` Martin Liška
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=3653c711-d7e8-a3e5-1263-326ce1c177a2@suse.cz \
--to=mliska@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=richard.guenther@gmail.com \
/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).