summaryrefslogtreecommitdiffstats
path: root/lto-plugin
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-03-19 16:56:27 +0100
committerMartin Liska <mliska@suse.cz>2020-03-19 16:56:27 +0100
commitc8429c2aba80f845939ffa6b2cfe8a0be1b50078 (patch)
tree24fdc75d0c796217da6680c0dd3e9abddb1238ca /lto-plugin
parentUpdate include/plugin-api.h. (diff)
downloadgcc-c8429c2aba80f845939ffa6b2cfe8a0be1b50078.tar.gz
gcc-c8429c2aba80f845939ffa6b2cfe8a0be1b50078.tar.bz2
gcc-c8429c2aba80f845939ffa6b2cfe8a0be1b50078.tar.xz
API extension for binutils (type of symbols).
* lto-section-in.c: Add ext_symtab. * lto-streamer-out.c (write_symbol_extension_info): New. (produce_symtab_extension): New. (produce_asm_for_decls): Stream also produce_symtab_extension. * lto-streamer.h (enum lto_section_type): New section. * lto-symtab.h (enum gcc_plugin_symbol_type): New. (enum gcc_plugin_symbol_section_kind): Likewise. * lto-plugin.c (LTO_SECTION_PREFIX): Rename to ... (LTO_SYMTAB_PREFIX): ... this. (LTO_SECTION_PREFIX_LEN): Rename to ... (LTO_SYMTAB_PREFIX_LEN): ... this. (LTO_SYMTAB_EXT_PREFIX): New. (LTO_SYMTAB_EXT_PREFIX_LEN): New. (LTO_LTO_PREFIX): New. (LTO_LTO_PREFIX_LEN): New. (parse_table_entry): Fill up unused to zero. (parse_table_entry_extension): New. (parse_symtab_extension): New. (finish_conflict_resolution): Change type for resolution. (process_symtab): Use new macro name. (process_symtab_extension): New. (claim_file_handler): Parse also process_symtab_extension. (onload): Call new add_symbols_v2.
Diffstat (limited to 'lto-plugin')
-rw-r--r--lto-plugin/ChangeLog20
-rw-r--r--lto-plugin/lto-plugin.c141
2 files changed, 150 insertions, 11 deletions
diff --git a/lto-plugin/ChangeLog b/lto-plugin/ChangeLog
index 9b3f8fbe5a6..205652cdda4 100644
--- a/lto-plugin/ChangeLog
+++ b/lto-plugin/ChangeLog
@@ -1,3 +1,23 @@
12020-03-19 Martin Liska <mliska@suse.cz>
2
3 * lto-plugin.c (LTO_SECTION_PREFIX): Rename to ...
4 (LTO_SYMTAB_PREFIX): ... this.
5 (LTO_SECTION_PREFIX_LEN): Rename to ...
6 (LTO_SYMTAB_PREFIX_LEN): ... this.
7 (LTO_SYMTAB_EXT_PREFIX): New.
8 (LTO_SYMTAB_EXT_PREFIX_LEN): New.
9 (LTO_LTO_PREFIX): New.
10 (LTO_LTO_PREFIX_LEN): New.
11 (parse_table_entry): Fill up unused to zero.
12 (parse_table_entry_extension): New.
13 (parse_symtab_extension): New.
14 (finish_conflict_resolution): Change type
15 for resolution.
16 (process_symtab): Use new macro name.
17 (process_symtab_extension): New.
18 (claim_file_handler): Parse also process_symtab_extension.
19 (onload): Call new add_symbols_v2.
20
12020-01-01 Jakub Jelinek <jakub@redhat.com> 212020-01-01 Jakub Jelinek <jakub@redhat.com>
2 22
3 Update copyright years. 23 Update copyright years.
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index c307fc871bf..ca6c84a1ffd 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -88,10 +88,14 @@ along with this program; see the file COPYING3. If not see
88 88
89/* LTO magic section name. */ 89/* LTO magic section name. */
90 90
91#define LTO_SECTION_PREFIX ".gnu.lto_.symtab" 91#define LTO_SYMTAB_PREFIX ".gnu.lto_.symtab"
92#define LTO_SECTION_PREFIX_LEN (sizeof (LTO_SECTION_PREFIX) - 1) 92#define LTO_SYMTAB_PREFIX_LEN (sizeof (LTO_SYMTAB_PREFIX) - 1)
93#define OFFLOAD_SECTION ".gnu.offload_lto_.opts" 93#define LTO_SYMTAB_EXT_PREFIX ".gnu.lto_.ext_symtab"
94#define OFFLOAD_SECTION_LEN (sizeof (OFFLOAD_SECTION) - 1) 94#define LTO_SYMTAB_EXT_PREFIX_LEN (sizeof (LTO_SYMTAB_EXT_PREFIX) - 1)
95#define LTO_LTO_PREFIX ".gnu.lto_.lto"
96#define LTO_LTO_PREFIX_LEN (sizeof (LTO_LTO_PREFIX) - 1)
97#define OFFLOAD_SECTION ".gnu.offload_lto_.opts"
98#define OFFLOAD_SECTION_LEN (sizeof (OFFLOAD_SECTION) - 1)
95 99
96/* The part of the symbol table the plugin has to keep track of. Note that we 100/* The part of the symbol table the plugin has to keep track of. Note that we
97 must keep SYMS until all_symbols_read is called to give the linker time to 101 must keep SYMS until all_symbols_read is called to give the linker time to
@@ -159,7 +163,7 @@ static ld_plugin_register_cleanup register_cleanup;
159static ld_plugin_add_input_file add_input_file; 163static ld_plugin_add_input_file add_input_file;
160static ld_plugin_add_input_library add_input_library; 164static ld_plugin_add_input_library add_input_library;
161static ld_plugin_message message; 165static ld_plugin_message message;
162static ld_plugin_add_symbols add_symbols; 166static ld_plugin_add_symbols add_symbols, add_symbols_v2;
163 167
164static struct plugin_file_info *claimed_files = NULL; 168static struct plugin_file_info *claimed_files = NULL;
165static unsigned int num_claimed_files = 0; 169static unsigned int num_claimed_files = 0;
@@ -286,6 +290,8 @@ parse_table_entry (char *p, struct ld_plugin_symbol *entry,
286 else 290 else
287 entry->comdat_key = xstrdup (entry->comdat_key); 291 entry->comdat_key = xstrdup (entry->comdat_key);
288 292
293 entry->unused = entry->section_kind = entry->symbol_type = 0;
294
289 t = *p; 295 t = *p;
290 check (t <= 4, LDPL_FATAL, "invalid symbol kind found"); 296 check (t <= 4, LDPL_FATAL, "invalid symbol kind found");
291 entry->def = translate_kind[t]; 297 entry->def = translate_kind[t];
@@ -309,6 +315,32 @@ parse_table_entry (char *p, struct ld_plugin_symbol *entry,
309 return p; 315 return p;
310} 316}
311 317
318/* Parse an entry of the IL symbol table. The data to be parsed is pointed
319 by P and the result is written in ENTRY. The slot number is stored in SLOT.
320 Returns the address of the next entry. */
321
322static char *
323parse_table_entry_extension (char *p, struct ld_plugin_symbol *entry)
324{
325 unsigned char t;
326 enum ld_plugin_symbol_type symbol_types[] =
327 {
328 LDST_UNKNOWN,
329 LDST_FUNCTION,
330 LDST_VARIABLE,
331 };
332
333 t = *p;
334 check (t <= 2, LDPL_FATAL, "invalid symbol type found");
335 entry->symbol_type = symbol_types[t];
336 p++;
337 entry->section_kind = *p;
338 p++;
339
340 return p;
341}
342
343
312/* Translate the IL symbol table located between DATA and END. Append the 344/* Translate the IL symbol table located between DATA and END. Append the
313 slots and symbols to OUT. */ 345 slots and symbols to OUT. */
314 346
@@ -339,6 +371,24 @@ translate (char *data, char *end, struct plugin_symtab *out)
339 out->aux = aux; 371 out->aux = aux;
340} 372}
341 373
374static void
375parse_symtab_extension (char *data, char *end, struct plugin_symtab *out)
376{
377 unsigned i;
378
379 unsigned char version = *data;
380 data++;
381
382 /* Version 1 contains the following data per entry:
383 - symbol_type
384 - section_kind
385 . */
386
387 if (version == 1)
388 for (i = 0; i < out->nsyms; i++)
389 data = parse_table_entry_extension (data, &out->syms[i]);
390}
391
342/* Free all memory that is no longer needed after writing the symbol 392/* Free all memory that is no longer needed after writing the symbol
343 resolution. */ 393 resolution. */
344 394
@@ -431,7 +481,7 @@ finish_conflict_resolution (struct plugin_symtab *symtab,
431 481
432 for (i = 0; i < symtab->nsyms; i++) 482 for (i = 0; i < symtab->nsyms; i++)
433 { 483 {
434 int resolution = LDPR_UNKNOWN; 484 char resolution = LDPR_UNKNOWN;
435 485
436 if (symtab->aux[i].next_conflict == -1) 486 if (symtab->aux[i].next_conflict == -1)
437 continue; 487 continue;
@@ -953,7 +1003,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
953 char *s; 1003 char *s;
954 char *secdatastart, *secdata; 1004 char *secdatastart, *secdata;
955 1005
956 if (strncmp (name, LTO_SECTION_PREFIX, LTO_SECTION_PREFIX_LEN) != 0) 1006 if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0)
957 return 1; 1007 return 1;
958 1008
959 s = strrchr (name, '.'); 1009 s = strrchr (name, '.');
@@ -995,6 +1045,59 @@ err:
995 return 0; 1045 return 0;
996} 1046}
997 1047
1048/* Process one section of an object file. */
1049
1050static int
1051process_symtab_extension (void *data, const char *name, off_t offset,
1052 off_t length)
1053{
1054 struct plugin_objfile *obj = (struct plugin_objfile *)data;
1055 char *s;
1056 char *secdatastart, *secdata;
1057
1058 if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0)
1059 return 1;
1060
1061 s = strrchr (name, '.');
1062 if (s)
1063 sscanf (s, ".%" PRI_LL "x", &obj->out->id);
1064 secdata = secdatastart = xmalloc (length);
1065 offset += obj->file->offset;
1066 if (offset != lseek (obj->file->fd, offset, SEEK_SET))
1067 goto err;
1068
1069 do
1070 {
1071 ssize_t got = read (obj->file->fd, secdata, length);
1072 if (got == 0)
1073 break;
1074 else if (got > 0)
1075 {
1076 secdata += got;
1077 length -= got;
1078 }
1079 else if (errno != EINTR)
1080 goto err;
1081 }
1082 while (length > 0);
1083 if (length > 0)
1084 goto err;
1085
1086 parse_symtab_extension (secdatastart, secdata, obj->out);
1087 obj->found++;
1088 free (secdatastart);
1089 return 1;
1090
1091err:
1092 if (message)
1093 message (LDPL_FATAL, "%s: corrupt object file", obj->file->name);
1094 /* Force claim_file_handler to abandon this file. */
1095 obj->found = 0;
1096 free (secdatastart);
1097 return 0;
1098}
1099
1100
998/* Find an offload section of an object file. */ 1101/* Find an offload section of an object file. */
999 1102
1000static int 1103static int
@@ -1055,8 +1158,17 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
1055 if (!obj.objfile && !err) 1158 if (!obj.objfile && !err)
1056 goto err; 1159 goto err;
1057 1160
1058 if (obj.objfile) 1161 if (obj.objfile)
1059 errmsg = simple_object_find_sections (obj.objfile, process_symtab, &obj, &err); 1162 {
1163 errmsg = simple_object_find_sections (obj.objfile, process_symtab, &obj,
1164 &err);
1165 /* Parsing symtab extension should be done only for add_symbols_v2 and
1166 later versions. */
1167 if (!errmsg && add_symbols_v2 != NULL)
1168 errmsg = simple_object_find_sections (obj.objfile,
1169 process_symtab_extension,
1170 &obj, &err);
1171 }
1060 1172
1061 if (!obj.objfile || errmsg) 1173 if (!obj.objfile || errmsg)
1062 { 1174 {
@@ -1080,8 +1192,12 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
1080 1192
1081 if (obj.found > 0) 1193 if (obj.found > 0)
1082 { 1194 {
1083 status = add_symbols (file->handle, lto_file.symtab.nsyms, 1195 if (add_symbols_v2)
1084 lto_file.symtab.syms); 1196 status = add_symbols_v2 (file->handle, lto_file.symtab.nsyms,
1197 lto_file.symtab.syms);
1198 else
1199 status = add_symbols (file->handle, lto_file.symtab.nsyms,
1200 lto_file.symtab.syms);
1085 check (status == LDPS_OK, LDPL_FATAL, "could not add symbols"); 1201 check (status == LDPS_OK, LDPL_FATAL, "could not add symbols");
1086 1202
1087 num_claimed_files++; 1203 num_claimed_files++;
@@ -1242,6 +1358,9 @@ onload (struct ld_plugin_tv *tv)
1242 case LDPT_REGISTER_CLAIM_FILE_HOOK: 1358 case LDPT_REGISTER_CLAIM_FILE_HOOK:
1243 register_claim_file = p->tv_u.tv_register_claim_file; 1359 register_claim_file = p->tv_u.tv_register_claim_file;
1244 break; 1360 break;
1361 case LDPT_ADD_SYMBOLS_V2:
1362 add_symbols_v2 = p->tv_u.tv_add_symbols;
1363 break;
1245 case LDPT_ADD_SYMBOLS: 1364 case LDPT_ADD_SYMBOLS:
1246 add_symbols = p->tv_u.tv_add_symbols; 1365 add_symbols = p->tv_u.tv_add_symbols;
1247 break; 1366 break;