From: Michal Jires <mjires@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: rguenther@suse.de
Subject: [PATCH] lto: Remove link() to fix build with MinGW [PR118238]
Date: Mon, 13 Jan 2025 09:35:07 +0100 [thread overview]
Message-ID: <7ftge2ap4jpwnbm4uy7j7cc72h2f4hbnjt6gcuzirst7n7i4io@na3bugcfcg65> (raw)
I used link() to create cheap copies of Incremental LTO cache contents
to prevent their deletion once linking is finished.
This is unnecessary, since output_files are deleted in our lto-plugin
and not in the linker itself.
Bootstrapped/regtested on x86_64-linux.
lto-wrapper now again builds on MinGW. Though so far I have not setup
MinGW to be able to do full bootstrap.
Ok for trunk?
PR lto/118238
gcc/ChangeLog:
* lto-wrapper.cc (run_gcc): Remove link() copying.
lto-plugin/ChangeLog:
* lto-plugin.c (cleanup_handler):
Keep output_files when using Incremental LTO.
(onload): Detect Incremental LTO.
---
gcc/lto-wrapper.cc | 34 +++++-----------------------------
lto-plugin/lto-plugin.c | 9 +++++++--
2 files changed, 12 insertions(+), 31 deletions(-)
diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
index f9b2511c38e..a980b208783 100644
--- a/gcc/lto-wrapper.cc
+++ b/gcc/lto-wrapper.cc
@@ -1571,6 +1571,8 @@ run_gcc (unsigned argc, char *argv[])
/* Exists. */
if (access (option->arg, W_OK) == 0)
ltrans_cache_dir = option->arg;
+ else
+ fatal_error (input_location, "missing directory: %s", option->arg);
break;
case OPT_flto_incremental_cache_size_:
@@ -2218,39 +2220,13 @@ cont:
{
for (i = 0; i < nr; ++i)
{
- char *input_name = input_names[i];
- char const *output_name = output_names[i];
-
ltrans_file_cache::item* item;
- item = ltrans_cache.get_item (input_name);
+ item = ltrans_cache.get_item (input_names[i]);
- if (item && !save_temps)
+ if (item)
{
+ /* Ensure LTRANS for this item finished. */
item->lock.lock_read ();
- /* Ensure that cached compiled file is not deleted.
- Create copy. */
-
- obstack_grow (&env_obstack, output_name,
- strlen (output_name) - 2);
- obstack_grow (&env_obstack, ".cache_copy.XXX.o",
- sizeof (".cache_copy.XXX.o"));
-
- char* output_name_link = XOBFINISH (&env_obstack, char *);
- char* name_idx = output_name_link + strlen (output_name_link)
- - strlen ("XXX.o");
-
- /* lto-wrapper can run in parallel and access
- the same partition. */
- for (int j = 0; ; j++)
- {
- gcc_assert (j < 1000);
- sprintf (name_idx, "%03d.o", j);
-
- if (link (output_name, output_name_link) != EEXIST)
- break;
- }
-
- output_names[i] = output_name_link;
item->lock.unlock ();
}
}
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 6bccb56291c..6c78d019cf1 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -214,6 +214,7 @@ static char *ltrans_objects = NULL;
static bool debug;
static bool save_temps;
+static bool flto_incremental;
static bool verbose;
static char nop;
static char *resolution_file = NULL;
@@ -941,8 +942,9 @@ cleanup_handler (void)
if (arguments_file_name)
maybe_unlink (arguments_file_name);
- for (i = 0; i < num_output_files; i++)
- maybe_unlink (output_files[i]);
+ if (!flto_incremental)
+ for (i = 0; i < num_output_files; i++)
+ maybe_unlink (output_files[i]);
free_2 ();
return LDPS_OK;
@@ -1615,6 +1617,9 @@ onload (struct ld_plugin_tv *tv)
if (strstr (collect_gcc_options, "'-save-temps'"))
save_temps = true;
+ if (strstr (collect_gcc_options, "'-flto-incremental="))
+ flto_incremental = true;
+
if (strstr (collect_gcc_options, "'-v'")
|| strstr (collect_gcc_options, "'--verbose'"))
verbose = true;
--
2.47.1
next reply other threads:[~2025-01-13 8:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 8:35 Michal Jires [this message]
2025-01-13 9:20 ` Richard Biener
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=7ftge2ap4jpwnbm4uy7j7cc72h2f4hbnjt6gcuzirst7n7i4io@na3bugcfcg65 \
--to=mjires@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
/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).