public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Using -frandom-seed=0 for reproducible builds?
@ 2024-02-29  7:32 Sebastian Huber
  2024-02-29 18:46 ` Alexander Monakov
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Huber @ 2024-02-29  7:32 UTC (permalink / raw)
  To: gcc-help

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-29 18:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29  7:32 Using -frandom-seed=0 for reproducible builds? Sebastian Huber
2024-02-29 18:46 ` Alexander Monakov

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).