From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: Using -frandom-seed=0 for reproducible builds?
Date: Thu, 29 Feb 2024 08:32:14 +0100 [thread overview]
Message-ID: <b038b753-cb0a-4cfa-8bb8-caa0ba721544@embedded-brains.de> (raw)
Hello,
I noticed that the coverage and profiling instrumentation needs the
-frandom-seed flag to be reproducible. The documentation
https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html#index-frandom-seed
says:
The string should be different for every file you compile.
Searching the internet suggests that using -frandom-seed=0 is not
unusual. Why should the string be different for every file you compile?
Or, what could happen if two files use the same random seed?
It seems the random seed is only used in two places:
gcc/tree.cc:#include "toplev.h" /* get_random_seed */
gcc/tree.cc: crc32_string (0, name), get_random_seed (false));
/* Generate a name for a special-purpose function.
The generated name may need to be unique across the whole link.
Changes to this function may also require corresponding changes to
xstrdup_mask_random.
TYPE is some string to identify the purpose of this function to the
linker or collect2; it must start with an uppercase letter,
one of:
I - for constructors
D - for destructors
N - for C++ anonymous namespaces
F - for DWARF unwind frame information. */
tree
get_file_function_name (const char *type)
gcc/lto-streamer.cc: sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE,
get_random_seed (false));
char *
lto_get_section_name (int section_type, const char *name,
int node_order, struct lto_file_decl_data *f)
{
[...]
/* Make the section name unique so that ld -r combining sections
doesn't confuse the reader with merged sections.
For options don't add a ID, the option reader cannot deal with them
and merging should be ok here. */
I am not sure which bad things happen if some items are not unique
across the entire link.
For the coverage profiling, the -frandom-seed flag just results in
"local_tick" being -1. The "local_tick" is only used to initialize the
random seed and in coverage.cc for a file stamp for notes file.
Would it make sense to add a new option to just control "local_tick" for
reproducible coverage instrumentation and don't touch the random seed stuff?
--
embedded brains GmbH & Co. KG
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax: +49-89-18 94 741 - 08
Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
next reply other threads:[~2024-02-29 7:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 7:32 Sebastian Huber [this message]
2024-02-29 18:46 ` Alexander Monakov
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=b038b753-cb0a-4cfa-8bb8-caa0ba721544@embedded-brains.de \
--to=sebastian.huber@embedded-brains.de \
--cc=gcc-help@gcc.gnu.org \
/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).