LTO plugin: modernize a bit.
Commit Message
The patch is about small refactoring of the plugin.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
include/ChangeLog:
* plugin-api.h (enum ld_plugin_tag): Do not set implicit enum
values.
lto-plugin/ChangeLog:
* lto-plugin.c (struct plugin_objfile): Use bool for offset
field.
(exec_lto_wrapper): Assign true/false to bool variables.
(process_offload_section): Likewise.
(claim_file_handler): Likewise.
(onload): Likewise.
---
include/plugin-api.h | 68 ++++++++++++++++++++---------------------
lto-plugin/lto-plugin.c | 19 ++++++------
2 files changed, 44 insertions(+), 43 deletions(-)
Comments
On 1/5/2022 4:06 AM, Martin Liška wrote:
> The patch is about small refactoring of the plugin.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
> include/ChangeLog:
>
> * plugin-api.h (enum ld_plugin_tag): Do not set implicit enum
> values.
>
> lto-plugin/ChangeLog:
>
> * lto-plugin.c (struct plugin_objfile): Use bool for offset
> field.
> (exec_lto_wrapper): Assign true/false to bool variables.
> (process_offload_section): Likewise.
> (claim_file_handler): Likewise.
> (onload): Likewise.
I don't see anything controversial in here. But the timing isn't
great. We're in stage3 and presumably moving into stage4 shortly.
Shouldn't this wait until stage1 re-opens?
jeff
On 1/5/22 18:43, Jeff Law wrote:
> But the timing isn't great. We're in stage3 and presumably moving into stage4 shortly. Shouldn't this wait until stage1 re-opens?
Agree, I'm going to prepare the changes for GCC 13, same as LTO plugin support for ld.mold.
Cheers,
Martin
Hi!
On 2022-01-05T12:06:12+0100, Martin Liška <mliska@suse.cz> wrote:
> The patch is about small refactoring of the plugin.
Yay!
> include/ChangeLog:
>
> * plugin-api.h (enum ld_plugin_tag): Do not set implicit enum
> values.
I did wonder whether the original idea there would've been to fixate
these values, which are part of a public API/ABI? (..., and thus, even
if the values don't change now if not assigning them explicitly, maybe
that should still be kept as-is, for robustness.) But then, all other
'enum's in 'include/plugin-api.h' also don't assign explicit 'enum'
values, so probably there's indeed no reason for this one to be
different.
Grüße
Thomas
> --- a/include/plugin-api.h
> +++ b/include/plugin-api.h
> @@ -487,40 +487,40 @@ enum ld_plugin_level
>
> enum ld_plugin_tag
> {
> - LDPT_NULL = 0,
> - LDPT_API_VERSION = 1,
> - LDPT_GOLD_VERSION = 2,
> - LDPT_LINKER_OUTPUT = 3,
> - LDPT_OPTION = 4,
> - LDPT_REGISTER_CLAIM_FILE_HOOK = 5,
> - LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK = 6,
> - LDPT_REGISTER_CLEANUP_HOOK = 7,
> - LDPT_ADD_SYMBOLS = 8,
> - LDPT_GET_SYMBOLS = 9,
> - LDPT_ADD_INPUT_FILE = 10,
> - LDPT_MESSAGE = 11,
> - LDPT_GET_INPUT_FILE = 12,
> - LDPT_RELEASE_INPUT_FILE = 13,
> - LDPT_ADD_INPUT_LIBRARY = 14,
> - LDPT_OUTPUT_NAME = 15,
> - LDPT_SET_EXTRA_LIBRARY_PATH = 16,
> - LDPT_GNU_LD_VERSION = 17,
> - LDPT_GET_VIEW = 18,
> - LDPT_GET_INPUT_SECTION_COUNT = 19,
> - LDPT_GET_INPUT_SECTION_TYPE = 20,
> - LDPT_GET_INPUT_SECTION_NAME = 21,
> - LDPT_GET_INPUT_SECTION_CONTENTS = 22,
> - LDPT_UPDATE_SECTION_ORDER = 23,
> - LDPT_ALLOW_SECTION_ORDERING = 24,
> - LDPT_GET_SYMBOLS_V2 = 25,
> - LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS = 26,
> - LDPT_UNIQUE_SEGMENT_FOR_SECTIONS = 27,
> - LDPT_GET_SYMBOLS_V3 = 28,
> - LDPT_GET_INPUT_SECTION_ALIGNMENT = 29,
> - LDPT_GET_INPUT_SECTION_SIZE = 30,
> - LDPT_REGISTER_NEW_INPUT_HOOK = 31,
> - LDPT_GET_WRAP_SYMBOLS = 32,
> - LDPT_ADD_SYMBOLS_V2 = 33
> + LDPT_NULL,
> + LDPT_API_VERSION,
> + LDPT_GOLD_VERSION,
> + LDPT_LINKER_OUTPUT,
> + LDPT_OPTION,
> + LDPT_REGISTER_CLAIM_FILE_HOOK,
> + LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK,
> + LDPT_REGISTER_CLEANUP_HOOK,
> + LDPT_ADD_SYMBOLS,
> + LDPT_GET_SYMBOLS,
> + LDPT_ADD_INPUT_FILE,
> + LDPT_MESSAGE,
> + LDPT_GET_INPUT_FILE,
> + LDPT_RELEASE_INPUT_FILE,
> + LDPT_ADD_INPUT_LIBRARY,
> + LDPT_OUTPUT_NAME,
> + LDPT_SET_EXTRA_LIBRARY_PATH,
> + LDPT_GNU_LD_VERSION,
> + LDPT_GET_VIEW,
> + LDPT_GET_INPUT_SECTION_COUNT,
> + LDPT_GET_INPUT_SECTION_TYPE,
> + LDPT_GET_INPUT_SECTION_NAME,
> + LDPT_GET_INPUT_SECTION_CONTENTS,
> + LDPT_UPDATE_SECTION_ORDER,
> + LDPT_ALLOW_SECTION_ORDERING,
> + LDPT_GET_SYMBOLS_V2,
> + LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS,
> + LDPT_UNIQUE_SEGMENT_FOR_SECTIONS,
> + LDPT_GET_SYMBOLS_V3,
> + LDPT_GET_INPUT_SECTION_ALIGNMENT,
> + LDPT_GET_INPUT_SECTION_SIZE,
> + LDPT_REGISTER_NEW_INPUT_HOOK,
> + LDPT_GET_WRAP_SYMBOLS,
> + LDPT_ADD_SYMBOLS_V2,
> };
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
@@ -487,40 +487,40 @@ enum ld_plugin_level
enum ld_plugin_tag
{
- LDPT_NULL = 0,
- LDPT_API_VERSION = 1,
- LDPT_GOLD_VERSION = 2,
- LDPT_LINKER_OUTPUT = 3,
- LDPT_OPTION = 4,
- LDPT_REGISTER_CLAIM_FILE_HOOK = 5,
- LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK = 6,
- LDPT_REGISTER_CLEANUP_HOOK = 7,
- LDPT_ADD_SYMBOLS = 8,
- LDPT_GET_SYMBOLS = 9,
- LDPT_ADD_INPUT_FILE = 10,
- LDPT_MESSAGE = 11,
- LDPT_GET_INPUT_FILE = 12,
- LDPT_RELEASE_INPUT_FILE = 13,
- LDPT_ADD_INPUT_LIBRARY = 14,
- LDPT_OUTPUT_NAME = 15,
- LDPT_SET_EXTRA_LIBRARY_PATH = 16,
- LDPT_GNU_LD_VERSION = 17,
- LDPT_GET_VIEW = 18,
- LDPT_GET_INPUT_SECTION_COUNT = 19,
- LDPT_GET_INPUT_SECTION_TYPE = 20,
- LDPT_GET_INPUT_SECTION_NAME = 21,
- LDPT_GET_INPUT_SECTION_CONTENTS = 22,
- LDPT_UPDATE_SECTION_ORDER = 23,
- LDPT_ALLOW_SECTION_ORDERING = 24,
- LDPT_GET_SYMBOLS_V2 = 25,
- LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS = 26,
- LDPT_UNIQUE_SEGMENT_FOR_SECTIONS = 27,
- LDPT_GET_SYMBOLS_V3 = 28,
- LDPT_GET_INPUT_SECTION_ALIGNMENT = 29,
- LDPT_GET_INPUT_SECTION_SIZE = 30,
- LDPT_REGISTER_NEW_INPUT_HOOK = 31,
- LDPT_GET_WRAP_SYMBOLS = 32,
- LDPT_ADD_SYMBOLS_V2 = 33
+ LDPT_NULL,
+ LDPT_API_VERSION,
+ LDPT_GOLD_VERSION,
+ LDPT_LINKER_OUTPUT,
+ LDPT_OPTION,
+ LDPT_REGISTER_CLAIM_FILE_HOOK,
+ LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK,
+ LDPT_REGISTER_CLEANUP_HOOK,
+ LDPT_ADD_SYMBOLS,
+ LDPT_GET_SYMBOLS,
+ LDPT_ADD_INPUT_FILE,
+ LDPT_MESSAGE,
+ LDPT_GET_INPUT_FILE,
+ LDPT_RELEASE_INPUT_FILE,
+ LDPT_ADD_INPUT_LIBRARY,
+ LDPT_OUTPUT_NAME,
+ LDPT_SET_EXTRA_LIBRARY_PATH,
+ LDPT_GNU_LD_VERSION,
+ LDPT_GET_VIEW,
+ LDPT_GET_INPUT_SECTION_COUNT,
+ LDPT_GET_INPUT_SECTION_TYPE,
+ LDPT_GET_INPUT_SECTION_NAME,
+ LDPT_GET_INPUT_SECTION_CONTENTS,
+ LDPT_UPDATE_SECTION_ORDER,
+ LDPT_ALLOW_SECTION_ORDERING,
+ LDPT_GET_SYMBOLS_V2,
+ LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS,
+ LDPT_UNIQUE_SEGMENT_FOR_SECTIONS,
+ LDPT_GET_SYMBOLS_V3,
+ LDPT_GET_INPUT_SECTION_ALIGNMENT,
+ LDPT_GET_INPUT_SECTION_SIZE,
+ LDPT_REGISTER_NEW_INPUT_HOOK,
+ LDPT_GET_WRAP_SYMBOLS,
+ LDPT_ADD_SYMBOLS_V2,
};
/* The plugin transfer vector. */
@@ -122,7 +122,7 @@ struct plugin_symtab
struct plugin_objfile
{
int found;
- int offload;
+ bool offload;
simple_object_read *objfile;
struct plugin_symtab *out;
const struct ld_plugin_input_file *file;
@@ -205,7 +205,7 @@ static const char *link_output_name = NULL;
/* This indicates link_output_name already contains the dot of the
suffix, so we can skip it in extensions. */
-static int skip_in_suffix = 0;
+static bool skip_in_suffix = false;
/* The version of gold being used, or -1 if not gold. The number is
MAJOR * 100 + MINOR. */
@@ -636,7 +636,8 @@ exec_lto_wrapper (char *argv[])
/* Write argv to a file to avoid a command line that is too long
Save the file locally on save-temps. */
const char *suffix = ".lto_wrapper_args";
- suffix += skip_in_suffix;
+ if (skip_in_suffix)
+ suffix++;
if (save_temps && link_output_name)
arguments_file_name = concat (link_output_name, suffix, NULL);
else
@@ -1132,7 +1133,7 @@ process_offload_section (void *data, const char *name, off_t offset, off_t len)
if (startswith (name, ".gnu.offload_lto_.opts"))
{
struct plugin_objfile *obj = (struct plugin_objfile *) data;
- obj->offload = 1;
+ obj->offload = true;
return 0;
}
@@ -1175,7 +1176,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
*claimed = 0;
obj.file = file;
obj.found = 0;
- obj.offload = 0;
+ obj.offload = false;
obj.out = <o_file.symtab;
errmsg = NULL;
obj.objfile = simple_object_start_read (file->fd, file->offset, LTO_SEGMENT_NAME,
@@ -1213,7 +1214,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
simple_object_find_sections (obj.objfile, process_offload_section,
&obj, &err);
- if (obj.found == 0 && obj.offload == 0)
+ if (obj.found == 0 && !obj.offload)
goto err;
if (obj.found > 1)
@@ -1250,10 +1251,10 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
/* If this is an LTO file without offload, and it is the first LTO file, save
the pointer to the last offload file in the list. Further offload LTO
files will be inserted after it, if any. */
- if (*claimed && obj.offload == 0 && offload_files_last_lto == NULL)
+ if (*claimed && !obj.offload && offload_files_last_lto == NULL)
offload_files_last_lto = offload_files_last;
- if (obj.offload == 1)
+ if (obj.offload)
{
/* Add file to the list. The order must be exactly the same as the final
order after recompilation and linking, otherwise host and target tables
@@ -1540,7 +1541,7 @@ onload (struct ld_plugin_tv *tv)
assert (escapes == 0);
assert (ticks == oddticks);
assert (q - link_output_name == len - 1);
- skip_in_suffix = 1;
+ skip_in_suffix = true;
}
}