public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/str_starts_with-v2)] LTO plugin: use startswith function.
@ 2021-03-23 11:56 Martin Liska
0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-03-23 11:56 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:19de9e8829d2a9ea89daf86a372aedd78a4a2e73
commit 19de9e8829d2a9ea89daf86a372aedd78a4a2e73
Author: Martin Liska <mliska@suse.cz>
Date: Fri Mar 19 15:23:01 2021 +0100
LTO plugin: use startswith function.
Diff:
---
lto-plugin/lto-plugin.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 32478f070e8..cd57ebca677 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
#define LTO_SEGMENT_NAME "__GNU_LTO"
-/* LTO magic section name. */
+/* Return true if STR string starts with PREFIX. */
-#define LTO_SYMTAB_PREFIX ".gnu.lto_.symtab"
-#define LTO_SYMTAB_PREFIX_LEN (sizeof (LTO_SYMTAB_PREFIX) - 1)
-#define LTO_SYMTAB_EXT_PREFIX ".gnu.lto_.ext_symtab"
-#define LTO_SYMTAB_EXT_PREFIX_LEN (sizeof (LTO_SYMTAB_EXT_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)
+static inline bool
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
/* The part of the symbol table the plugin has to keep track of. Note that we
must keep SYMS until all_symbols_read is called to give the linker time to
@@ -832,7 +829,7 @@ all_symbols_read_handler (void)
unsigned int i;
for (i = 0; i < num_pass_through_items; i++)
{
- if (strncmp (pass_through_items[i], "-l", 2) == 0)
+ if (startswith (pass_through_items[i], "-l"))
add_input_library (pass_through_items[i] + 2);
else
add_input_file (pass_through_items[i]);
@@ -1022,7 +1019,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.symtab"))
return 1;
s = strrchr (name, '.');
@@ -1074,7 +1071,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.ext_symtab"))
return 1;
s = strrchr (name, '.');
@@ -1122,7 +1119,7 @@ err:
static int
process_offload_section (void *data, const char *name, off_t offset, off_t len)
{
- if (!strncmp (name, OFFLOAD_SECTION, OFFLOAD_SECTION_LEN))
+ if (startswith (name, ".gnu.offload_lto_.opts"))
{
struct plugin_objfile *obj = (struct plugin_objfile *) data;
obj->offload = 1;
@@ -1325,7 +1322,7 @@ process_option (const char *option)
save_temps = true;
else if (strcmp (option, "-nop") == 0)
nop = 1;
- else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
+ else if (startswith (option, "-pass-through="))
{
num_pass_through_items++;
pass_through_items = xrealloc (pass_through_items,
@@ -1333,7 +1330,7 @@ process_option (const char *option)
pass_through_items[num_pass_through_items - 1] =
xstrdup (option + strlen ("-pass-through="));
}
- else if (!strncmp (option, "-sym-style=", sizeof ("-sym-style=") - 1))
+ else if (startswith (option, "-sym-style="))
{
switch (option[sizeof ("-sym-style=") - 1])
{
@@ -1356,7 +1353,7 @@ process_option (const char *option)
size = lto_wrapper_num_args * sizeof (char *);
lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size);
lto_wrapper_argv[lto_wrapper_num_args - 1] = opt;
- if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0)
+ if (startswith (option, "-fresolution="))
resolution_file = opt + sizeof ("-fresolution=") - 1;
}
save_temps = save_temps || debug;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/marxin/heads/str_starts_with-v2)] LTO plugin: use startswith function.
@ 2021-04-21 8:36 Martin Liska
0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-04-21 8:36 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:9240951e836088928056649f50179179eeb43e0f
commit 9240951e836088928056649f50179179eeb43e0f
Author: Martin Liska <mliska@suse.cz>
Date: Fri Mar 19 15:23:01 2021 +0100
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.
Diff:
---
lto-plugin/lto-plugin.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 32478f070e8..cd57ebca677 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
#define LTO_SEGMENT_NAME "__GNU_LTO"
-/* LTO magic section name. */
+/* Return true if STR string starts with PREFIX. */
-#define LTO_SYMTAB_PREFIX ".gnu.lto_.symtab"
-#define LTO_SYMTAB_PREFIX_LEN (sizeof (LTO_SYMTAB_PREFIX) - 1)
-#define LTO_SYMTAB_EXT_PREFIX ".gnu.lto_.ext_symtab"
-#define LTO_SYMTAB_EXT_PREFIX_LEN (sizeof (LTO_SYMTAB_EXT_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)
+static inline bool
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
/* The part of the symbol table the plugin has to keep track of. Note that we
must keep SYMS until all_symbols_read is called to give the linker time to
@@ -832,7 +829,7 @@ all_symbols_read_handler (void)
unsigned int i;
for (i = 0; i < num_pass_through_items; i++)
{
- if (strncmp (pass_through_items[i], "-l", 2) == 0)
+ if (startswith (pass_through_items[i], "-l"))
add_input_library (pass_through_items[i] + 2);
else
add_input_file (pass_through_items[i]);
@@ -1022,7 +1019,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.symtab"))
return 1;
s = strrchr (name, '.');
@@ -1074,7 +1071,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.ext_symtab"))
return 1;
s = strrchr (name, '.');
@@ -1122,7 +1119,7 @@ err:
static int
process_offload_section (void *data, const char *name, off_t offset, off_t len)
{
- if (!strncmp (name, OFFLOAD_SECTION, OFFLOAD_SECTION_LEN))
+ if (startswith (name, ".gnu.offload_lto_.opts"))
{
struct plugin_objfile *obj = (struct plugin_objfile *) data;
obj->offload = 1;
@@ -1325,7 +1322,7 @@ process_option (const char *option)
save_temps = true;
else if (strcmp (option, "-nop") == 0)
nop = 1;
- else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
+ else if (startswith (option, "-pass-through="))
{
num_pass_through_items++;
pass_through_items = xrealloc (pass_through_items,
@@ -1333,7 +1330,7 @@ process_option (const char *option)
pass_through_items[num_pass_through_items - 1] =
xstrdup (option + strlen ("-pass-through="));
}
- else if (!strncmp (option, "-sym-style=", sizeof ("-sym-style=") - 1))
+ else if (startswith (option, "-sym-style="))
{
switch (option[sizeof ("-sym-style=") - 1])
{
@@ -1356,7 +1353,7 @@ process_option (const char *option)
size = lto_wrapper_num_args * sizeof (char *);
lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size);
lto_wrapper_argv[lto_wrapper_num_args - 1] = opt;
- if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0)
+ if (startswith (option, "-fresolution="))
resolution_file = opt + sizeof ("-fresolution=") - 1;
}
save_temps = save_temps || debug;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/marxin/heads/str_starts_with-v2)] LTO plugin: use startswith function.
@ 2021-04-12 13:27 Martin Liska
0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-04-12 13:27 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:de71a67f86dadd6769962690654c5e25e1d9c1a5
commit de71a67f86dadd6769962690654c5e25e1d9c1a5
Author: Martin Liska <mliska@suse.cz>
Date: Fri Mar 19 15:23:01 2021 +0100
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.
Diff:
---
lto-plugin/lto-plugin.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 32478f070e8..cd57ebca677 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
#define LTO_SEGMENT_NAME "__GNU_LTO"
-/* LTO magic section name. */
+/* Return true if STR string starts with PREFIX. */
-#define LTO_SYMTAB_PREFIX ".gnu.lto_.symtab"
-#define LTO_SYMTAB_PREFIX_LEN (sizeof (LTO_SYMTAB_PREFIX) - 1)
-#define LTO_SYMTAB_EXT_PREFIX ".gnu.lto_.ext_symtab"
-#define LTO_SYMTAB_EXT_PREFIX_LEN (sizeof (LTO_SYMTAB_EXT_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)
+static inline bool
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
/* The part of the symbol table the plugin has to keep track of. Note that we
must keep SYMS until all_symbols_read is called to give the linker time to
@@ -832,7 +829,7 @@ all_symbols_read_handler (void)
unsigned int i;
for (i = 0; i < num_pass_through_items; i++)
{
- if (strncmp (pass_through_items[i], "-l", 2) == 0)
+ if (startswith (pass_through_items[i], "-l"))
add_input_library (pass_through_items[i] + 2);
else
add_input_file (pass_through_items[i]);
@@ -1022,7 +1019,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.symtab"))
return 1;
s = strrchr (name, '.');
@@ -1074,7 +1071,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.ext_symtab"))
return 1;
s = strrchr (name, '.');
@@ -1122,7 +1119,7 @@ err:
static int
process_offload_section (void *data, const char *name, off_t offset, off_t len)
{
- if (!strncmp (name, OFFLOAD_SECTION, OFFLOAD_SECTION_LEN))
+ if (startswith (name, ".gnu.offload_lto_.opts"))
{
struct plugin_objfile *obj = (struct plugin_objfile *) data;
obj->offload = 1;
@@ -1325,7 +1322,7 @@ process_option (const char *option)
save_temps = true;
else if (strcmp (option, "-nop") == 0)
nop = 1;
- else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
+ else if (startswith (option, "-pass-through="))
{
num_pass_through_items++;
pass_through_items = xrealloc (pass_through_items,
@@ -1333,7 +1330,7 @@ process_option (const char *option)
pass_through_items[num_pass_through_items - 1] =
xstrdup (option + strlen ("-pass-through="));
}
- else if (!strncmp (option, "-sym-style=", sizeof ("-sym-style=") - 1))
+ else if (startswith (option, "-sym-style="))
{
switch (option[sizeof ("-sym-style=") - 1])
{
@@ -1356,7 +1353,7 @@ process_option (const char *option)
size = lto_wrapper_num_args * sizeof (char *);
lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size);
lto_wrapper_argv[lto_wrapper_num_args - 1] = opt;
- if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0)
+ if (startswith (option, "-fresolution="))
resolution_file = opt + sizeof ("-fresolution=") - 1;
}
save_temps = save_temps || debug;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/marxin/heads/str_starts_with-v2)] LTO plugin: use startswith function.
@ 2021-03-26 11:36 Martin Liska
0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-03-26 11:36 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:98b512beabd53984a1b75c0a23a46ea34146baaf
commit 98b512beabd53984a1b75c0a23a46ea34146baaf
Author: Martin Liska <mliska@suse.cz>
Date: Fri Mar 19 15:23:01 2021 +0100
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.
Diff:
---
lto-plugin/lto-plugin.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 32478f070e8..cd57ebca677 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
#define LTO_SEGMENT_NAME "__GNU_LTO"
-/* LTO magic section name. */
+/* Return true if STR string starts with PREFIX. */
-#define LTO_SYMTAB_PREFIX ".gnu.lto_.symtab"
-#define LTO_SYMTAB_PREFIX_LEN (sizeof (LTO_SYMTAB_PREFIX) - 1)
-#define LTO_SYMTAB_EXT_PREFIX ".gnu.lto_.ext_symtab"
-#define LTO_SYMTAB_EXT_PREFIX_LEN (sizeof (LTO_SYMTAB_EXT_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)
+static inline bool
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
/* The part of the symbol table the plugin has to keep track of. Note that we
must keep SYMS until all_symbols_read is called to give the linker time to
@@ -832,7 +829,7 @@ all_symbols_read_handler (void)
unsigned int i;
for (i = 0; i < num_pass_through_items; i++)
{
- if (strncmp (pass_through_items[i], "-l", 2) == 0)
+ if (startswith (pass_through_items[i], "-l"))
add_input_library (pass_through_items[i] + 2);
else
add_input_file (pass_through_items[i]);
@@ -1022,7 +1019,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.symtab"))
return 1;
s = strrchr (name, '.');
@@ -1074,7 +1071,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.ext_symtab"))
return 1;
s = strrchr (name, '.');
@@ -1122,7 +1119,7 @@ err:
static int
process_offload_section (void *data, const char *name, off_t offset, off_t len)
{
- if (!strncmp (name, OFFLOAD_SECTION, OFFLOAD_SECTION_LEN))
+ if (startswith (name, ".gnu.offload_lto_.opts"))
{
struct plugin_objfile *obj = (struct plugin_objfile *) data;
obj->offload = 1;
@@ -1325,7 +1322,7 @@ process_option (const char *option)
save_temps = true;
else if (strcmp (option, "-nop") == 0)
nop = 1;
- else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
+ else if (startswith (option, "-pass-through="))
{
num_pass_through_items++;
pass_through_items = xrealloc (pass_through_items,
@@ -1333,7 +1330,7 @@ process_option (const char *option)
pass_through_items[num_pass_through_items - 1] =
xstrdup (option + strlen ("-pass-through="));
}
- else if (!strncmp (option, "-sym-style=", sizeof ("-sym-style=") - 1))
+ else if (startswith (option, "-sym-style="))
{
switch (option[sizeof ("-sym-style=") - 1])
{
@@ -1356,7 +1353,7 @@ process_option (const char *option)
size = lto_wrapper_num_args * sizeof (char *);
lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size);
lto_wrapper_argv[lto_wrapper_num_args - 1] = opt;
- if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0)
+ if (startswith (option, "-fresolution="))
resolution_file = opt + sizeof ("-fresolution=") - 1;
}
save_temps = save_temps || debug;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/marxin/heads/str_starts_with-v2)] LTO plugin: use startswith function.
@ 2021-03-23 10:42 Martin Liska
0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-03-23 10:42 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b60310c608fe525e1248b02dcf11de8776eb8c02
commit b60310c608fe525e1248b02dcf11de8776eb8c02
Author: Martin Liska <mliska@suse.cz>
Date: Fri Mar 19 15:23:01 2021 +0100
LTO plugin: use startswith function.
Diff:
---
lto-plugin/lto-plugin.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 32478f070e8..cd57ebca677 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
#define LTO_SEGMENT_NAME "__GNU_LTO"
-/* LTO magic section name. */
+/* Return true if STR string starts with PREFIX. */
-#define LTO_SYMTAB_PREFIX ".gnu.lto_.symtab"
-#define LTO_SYMTAB_PREFIX_LEN (sizeof (LTO_SYMTAB_PREFIX) - 1)
-#define LTO_SYMTAB_EXT_PREFIX ".gnu.lto_.ext_symtab"
-#define LTO_SYMTAB_EXT_PREFIX_LEN (sizeof (LTO_SYMTAB_EXT_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)
+static inline bool
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
/* The part of the symbol table the plugin has to keep track of. Note that we
must keep SYMS until all_symbols_read is called to give the linker time to
@@ -832,7 +829,7 @@ all_symbols_read_handler (void)
unsigned int i;
for (i = 0; i < num_pass_through_items; i++)
{
- if (strncmp (pass_through_items[i], "-l", 2) == 0)
+ if (startswith (pass_through_items[i], "-l"))
add_input_library (pass_through_items[i] + 2);
else
add_input_file (pass_through_items[i]);
@@ -1022,7 +1019,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.symtab"))
return 1;
s = strrchr (name, '.');
@@ -1074,7 +1071,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.ext_symtab"))
return 1;
s = strrchr (name, '.');
@@ -1122,7 +1119,7 @@ err:
static int
process_offload_section (void *data, const char *name, off_t offset, off_t len)
{
- if (!strncmp (name, OFFLOAD_SECTION, OFFLOAD_SECTION_LEN))
+ if (startswith (name, ".gnu.offload_lto_.opts"))
{
struct plugin_objfile *obj = (struct plugin_objfile *) data;
obj->offload = 1;
@@ -1325,7 +1322,7 @@ process_option (const char *option)
save_temps = true;
else if (strcmp (option, "-nop") == 0)
nop = 1;
- else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
+ else if (startswith (option, "-pass-through="))
{
num_pass_through_items++;
pass_through_items = xrealloc (pass_through_items,
@@ -1333,7 +1330,7 @@ process_option (const char *option)
pass_through_items[num_pass_through_items - 1] =
xstrdup (option + strlen ("-pass-through="));
}
- else if (!strncmp (option, "-sym-style=", sizeof ("-sym-style=") - 1))
+ else if (startswith (option, "-sym-style="))
{
switch (option[sizeof ("-sym-style=") - 1])
{
@@ -1356,7 +1353,7 @@ process_option (const char *option)
size = lto_wrapper_num_args * sizeof (char *);
lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size);
lto_wrapper_argv[lto_wrapper_num_args - 1] = opt;
- if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0)
+ if (startswith (option, "-fresolution="))
resolution_file = opt + sizeof ("-fresolution=") - 1;
}
save_temps = save_temps || debug;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/marxin/heads/str_starts_with-v2)] LTO plugin: use startswith function.
@ 2021-03-22 9:10 Martin Liska
0 siblings, 0 replies; 6+ messages in thread
From: Martin Liska @ 2021-03-22 9:10 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4af8df83b745c525531855086015e521cff7d799
commit 4af8df83b745c525531855086015e521cff7d799
Author: Martin Liska <mliska@suse.cz>
Date: Fri Mar 19 15:23:01 2021 +0100
LTO plugin: use startswith function.
Diff:
---
lto-plugin/lto-plugin.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 32478f070e8..cd57ebca677 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
#define LTO_SEGMENT_NAME "__GNU_LTO"
-/* LTO magic section name. */
+/* Return true if STR string starts with PREFIX. */
-#define LTO_SYMTAB_PREFIX ".gnu.lto_.symtab"
-#define LTO_SYMTAB_PREFIX_LEN (sizeof (LTO_SYMTAB_PREFIX) - 1)
-#define LTO_SYMTAB_EXT_PREFIX ".gnu.lto_.ext_symtab"
-#define LTO_SYMTAB_EXT_PREFIX_LEN (sizeof (LTO_SYMTAB_EXT_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)
+static inline bool
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
/* The part of the symbol table the plugin has to keep track of. Note that we
must keep SYMS until all_symbols_read is called to give the linker time to
@@ -832,7 +829,7 @@ all_symbols_read_handler (void)
unsigned int i;
for (i = 0; i < num_pass_through_items; i++)
{
- if (strncmp (pass_through_items[i], "-l", 2) == 0)
+ if (startswith (pass_through_items[i], "-l"))
add_input_library (pass_through_items[i] + 2);
else
add_input_file (pass_through_items[i]);
@@ -1022,7 +1019,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.symtab"))
return 1;
s = strrchr (name, '.');
@@ -1074,7 +1071,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
char *s;
char *secdatastart, *secdata;
- if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0)
+ if (!startswith (name, ".gnu.lto_.ext_symtab"))
return 1;
s = strrchr (name, '.');
@@ -1122,7 +1119,7 @@ err:
static int
process_offload_section (void *data, const char *name, off_t offset, off_t len)
{
- if (!strncmp (name, OFFLOAD_SECTION, OFFLOAD_SECTION_LEN))
+ if (startswith (name, ".gnu.offload_lto_.opts"))
{
struct plugin_objfile *obj = (struct plugin_objfile *) data;
obj->offload = 1;
@@ -1325,7 +1322,7 @@ process_option (const char *option)
save_temps = true;
else if (strcmp (option, "-nop") == 0)
nop = 1;
- else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
+ else if (startswith (option, "-pass-through="))
{
num_pass_through_items++;
pass_through_items = xrealloc (pass_through_items,
@@ -1333,7 +1330,7 @@ process_option (const char *option)
pass_through_items[num_pass_through_items - 1] =
xstrdup (option + strlen ("-pass-through="));
}
- else if (!strncmp (option, "-sym-style=", sizeof ("-sym-style=") - 1))
+ else if (startswith (option, "-sym-style="))
{
switch (option[sizeof ("-sym-style=") - 1])
{
@@ -1356,7 +1353,7 @@ process_option (const char *option)
size = lto_wrapper_num_args * sizeof (char *);
lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size);
lto_wrapper_argv[lto_wrapper_num_args - 1] = opt;
- if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0)
+ if (startswith (option, "-fresolution="))
resolution_file = opt + sizeof ("-fresolution=") - 1;
}
save_temps = save_temps || debug;
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-04-21 8:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 11:56 [gcc(refs/users/marxin/heads/str_starts_with-v2)] LTO plugin: use startswith function Martin Liska
-- strict thread matches above, loose matches on Subject: below --
2021-04-21 8:36 Martin Liska
2021-04-12 13:27 Martin Liska
2021-03-26 11:36 Martin Liska
2021-03-23 10:42 Martin Liska
2021-03-22 9:10 Martin Liska
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).