From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 761F23858C52 for ; Thu, 29 Feb 2024 18:46:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 761F23858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 761F23858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709232400; cv=none; b=S7zXBZopzcuoW0JqWMi3ZJ1s6rf0LHsKs1NO1Yx4nOn3ZuwTwcfmnhFQ0Q1uU0h4T3FCZeEJUQ+j+t5pzZDAd9mXQC4Hnne9f1qtyJ543UVzoB4cJ5ijhXIHMwFX8UgT0aRWZMy4mlfHkYF4B7BEW4YdRDktkN/ZbEr5JKlvcmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709232400; c=relaxed/simple; bh=qLTYXuBjG87mcVAkDfRFjLAKgYnHVHP40/xGXrvKd40=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=X65qpTu9UfHO32W/gchnZTaJe6DhCuA4h8jCyypdqbjhnQZhbWESUaDnd2CxuWu/t7fSExxNns3KbEVpb1ddktKgUPWCOsRHEeen+cvngpH/U9uom9stZ8zHSVxQXKem+X/PP2UjUR+0Uy/bsfHv02qlpKHvtbeYiwYFxjI1d0Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id E19A440B279F; Thu, 29 Feb 2024 18:46:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru E19A440B279F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1709232395; bh=ZueNtnE8e+GoDOmFhgBmI5p4JwtVKo1lYUtT/S42Pxg=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=EVkxvNJNvsnFMWJ+rqw9ka8h80O3oaH64+/EFk712kFopJS5hjK5E+ueSSrFNpzCe xIobjaJjvQqui25HJrC9QJdMe0jccEjt+2b8G1jxMcmnatf3UxDZ58arVHHRm3ekrV 0KxgnFOJA4bkf9F5CtlM0LS7LU2iaWmkvQSq0nJI= Date: Thu, 29 Feb 2024 21:46:35 +0300 (MSK) From: Alexander Monakov To: Sebastian Huber cc: gcc-help Subject: Re: Using -frandom-seed=0 for reproducible builds? In-Reply-To: Message-ID: <552cd7f3-8ced-0f3a-d2be-64dad87a2a05@ispras.ru> References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 29 Feb 2024, Sebastian Huber wrote: > 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. Heh, -frandom-seed=0 is the same as not passing -frandom-seed at all: get_random_seed reseeds random_seed if it is zero. > Why should the string be different for every file you compile? In very rare circumstances GCC relies on random identifiers not colliding at link stage. One example I'm aware of is global constructors on AIX (which used the COFF object file format, not ELF). If you deliberately construct a testcase where two constructor function get the same section name, you get a linker warning: ld: 0711-224 WARNING: Duplicate symbol: global constructors keyed to 65535_0_t.c_00000000_0xb3fc9bb6 ld: 0711-224 WARNING: Duplicate symbol: .global constructors keyed to 65535_0_t.c_00000000_0xb3fc9bb6 ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. and one of the constructors is not executed (a correctness issue). On ELF targets this issue does not arise. > Or, what could happen if two files use the same random seed? Per the above, the program may be miscompiled. > 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? I am not sure why you'd want to do that, but FWIW the usual trick is to pass the source file name as the seed: gcc -c src/foo.c -frandom-seed=src/foo.c this way each file with high probability gets a reproducible unique seed. Alexander