summaryrefslogtreecommitdiffstats
path: root/lto-plugin
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2021-03-19 15:23:01 +0100
committerMartin Liska <mliska@suse.cz>2021-05-10 09:33:32 +0200
commita2d7e58f4ea787eafdf3e7d39567739451d12d39 (patch)
tree5336825c5c76b918ed478bfbd3f48dcebeff1643 /lto-plugin
parentCome up with startswith function. (diff)
downloadgcc-a2d7e58f4ea787eafdf3e7d39567739451d12d39.tar.gz
gcc-a2d7e58f4ea787eafdf3e7d39567739451d12d39.tar.bz2
gcc-a2d7e58f4ea787eafdf3e7d39567739451d12d39.tar.xz
LTO plugin: use startswith function.
lto-plugin/ChangeLog: * lto-plugin.c (LTO_SEGMENT_NAME): Remove. (LTO_SYMTAB_PREFIX): Likewise. (LTO_SYMTAB_PREFIX_LEN): Likewise. (LTO_SYMTAB_EXT_PREFIX): Likewise. (LTO_SYMTAB_EXT_PREFIX_LEN): Likewise. (LTO_LTO_PREFIX): Likewise. (LTO_LTO_PREFIX_LEN): Likewise. (OFFLOAD_SECTION): Likewise. (OFFLOAD_SECTION_LEN): Likewise. (startswith): New function. (all_symbols_read_handler): Use it. (process_symtab): Likewise. (process_symtab_extension): Likewise. (process_offload_section): Likewise. (process_option): Likewise.
Diffstat (limited to 'lto-plugin')
-rw-r--r--lto-plugin/lto-plugin.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 4e90ce03ade..ff79f4ac462 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -89,16 +89,13 @@ along with this program; see the file COPYING3. If not see
89 89
90#define LTO_SEGMENT_NAME "__GNU_LTO" 90#define LTO_SEGMENT_NAME "__GNU_LTO"
91 91
92/* LTO magic section name. */ 92/* Return true if STR string starts with PREFIX. */
93 93
94#define LTO_SYMTAB_PREFIX ".gnu.lto_.symtab" 94static inline bool
95#define LTO_SYMTAB_PREFIX_LEN (sizeof (LTO_SYMTAB_PREFIX) - 1) 95startswith (const char *str, const char *prefix)
96#define LTO_SYMTAB_EXT_PREFIX ".gnu.lto_.ext_symtab" 96{
97#define LTO_SYMTAB_EXT_PREFIX_LEN (sizeof (LTO_SYMTAB_EXT_PREFIX) - 1) 97 return strncmp (str, prefix, strlen (prefix)) == 0;
98#define LTO_LTO_PREFIX ".gnu.lto_.lto" 98}
99#define LTO_LTO_PREFIX_LEN (sizeof (LTO_LTO_PREFIX) - 1)
100#define OFFLOAD_SECTION ".gnu.offload_lto_.opts"
101#define OFFLOAD_SECTION_LEN (sizeof (OFFLOAD_SECTION) - 1)
102 99
103/* 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
104 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
@@ -832,7 +829,7 @@ all_symbols_read_handler (void)
832 unsigned int i; 829 unsigned int i;
833 for (i = 0; i < num_pass_through_items; i++) 830 for (i = 0; i < num_pass_through_items; i++)
834 { 831 {
835 if (strncmp (pass_through_items[i], "-l", 2) == 0) 832 if (startswith (pass_through_items[i], "-l"))
836 add_input_library (pass_through_items[i] + 2); 833 add_input_library (pass_through_items[i] + 2);
837 else 834 else
838 add_input_file (pass_through_items[i]); 835 add_input_file (pass_through_items[i]);
@@ -1022,7 +1019,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
1022 char *s; 1019 char *s;
1023 char *secdatastart, *secdata; 1020 char *secdatastart, *secdata;
1024 1021
1025 if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0) 1022 if (!startswith (name, ".gnu.lto_.symtab"))
1026 return 1; 1023 return 1;
1027 1024
1028 s = strrchr (name, '.'); 1025 s = strrchr (name, '.');
@@ -1074,7 +1071,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
1074 char *s; 1071 char *s;
1075 char *secdatastart, *secdata; 1072 char *secdatastart, *secdata;
1076 1073
1077 if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0) 1074 if (!startswith (name, ".gnu.lto_.ext_symtab"))
1078 return 1; 1075 return 1;
1079 1076
1080 s = strrchr (name, '.'); 1077 s = strrchr (name, '.');
@@ -1122,7 +1119,7 @@ err:
1122static int 1119static int
1123process_offload_section (void *data, const char *name, off_t offset, off_t len) 1120process_offload_section (void *data, const char *name, off_t offset, off_t len)
1124{ 1121{
1125 if (!strncmp (name, OFFLOAD_SECTION, OFFLOAD_SECTION_LEN)) 1122 if (startswith (name, ".gnu.offload_lto_.opts"))
1126 { 1123 {
1127 struct plugin_objfile *obj = (struct plugin_objfile *) data; 1124 struct plugin_objfile *obj = (struct plugin_objfile *) data;
1128 obj->offload = 1; 1125 obj->offload = 1;
@@ -1325,7 +1322,7 @@ process_option (const char *option)
1325 save_temps = true; 1322 save_temps = true;
1326 else if (strcmp (option, "-nop") == 0) 1323 else if (strcmp (option, "-nop") == 0)
1327 nop = 1; 1324 nop = 1;
1328 else if (!strncmp (option, "-pass-through=", strlen("-pass-through="))) 1325 else if (startswith (option, "-pass-through="))
1329 { 1326 {
1330 num_pass_through_items++; 1327 num_pass_through_items++;
1331 pass_through_items = xrealloc (pass_through_items, 1328 pass_through_items = xrealloc (pass_through_items,
@@ -1333,7 +1330,7 @@ process_option (const char *option)
1333 pass_through_items[num_pass_through_items - 1] = 1330 pass_through_items[num_pass_through_items - 1] =
1334 xstrdup (option + strlen ("-pass-through=")); 1331 xstrdup (option + strlen ("-pass-through="));
1335 } 1332 }
1336 else if (!strncmp (option, "-sym-style=", sizeof ("-sym-style=") - 1)) 1333 else if (startswith (option, "-sym-style="))
1337 { 1334 {
1338 switch (option[sizeof ("-sym-style=") - 1]) 1335 switch (option[sizeof ("-sym-style=") - 1])
1339 { 1336 {
@@ -1356,7 +1353,7 @@ process_option (const char *option)
1356 size = lto_wrapper_num_args * sizeof (char *); 1353 size = lto_wrapper_num_args * sizeof (char *);
1357 lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size); 1354 lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size);
1358 lto_wrapper_argv[lto_wrapper_num_args - 1] = opt; 1355 lto_wrapper_argv[lto_wrapper_num_args - 1] = opt;
1359 if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0) 1356 if (startswith (option, "-fresolution="))
1360 resolution_file = opt + sizeof ("-fresolution=") - 1; 1357 resolution_file = opt + sizeof ("-fresolution=") - 1;
1361 } 1358 }
1362 save_temps = save_temps || debug; 1359 save_temps = save_temps || debug;