From owner-freebsd-toolchain@FreeBSD.ORG Sun Nov 14 23:10:02 2010 Return-Path: Delivered-To: freebsd-toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6D563106566C for ; Sun, 14 Nov 2010 23:10:02 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (cl-327.ede-01.nl.sixxs.net [IPv6:2001:7b8:2ff:146::2]) by mx1.freebsd.org (Postfix) with ESMTP id 229E88FC12 for ; Sun, 14 Nov 2010 23:10:02 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7:0:20d4:5ad4:8ef9:2ce4] (unknown [IPv6:2001:7b8:3a7:0:20d4:5ad4:8ef9:2ce4]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 45ED35C43; Mon, 15 Nov 2010 00:09:59 +0100 (CET) Message-ID: <4CE06C4F.7000002@FreeBSD.org> Date: Mon, 15 Nov 2010 00:10:07 +0100 From: Dimitry Andric Organization: The FreeBSD Project User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.13pre) Gecko/20101113 Lanikai/3.1.7pre MIME-Version: 1.0 To: Erik Cederstrand References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-toolchain@freebsd.org Subject: Re: Clang and -frandom-seed X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Nov 2010 23:10:02 -0000 On 2010-11-14 23:29, Erik Cederstrand wrote: > I noticed that two consecutive builds of (GCC-built) Clang don't produce identical binaries. This is true for clang, clang++ and tblgen. I asked on the llvm-dev list yesterday, and it turns out it's because GCC uses a random seed on some symbols. Apparently, this can be controlled with the -frandom-seed flag. I haven't tested if this is also the case for Clang-built Clang. > > I'm not sure I understand the exact implications, but I'm wondering if we could add the flag to the build scripts in FreeBSD in a way that both satisfies the randomness criteria and makes builds deterministic? Hmm, it seems this is only used for C++ compilations, not for plain C. The gcc manual says: -frandom-seed=string This option provides a seed that GCC uses when it would otherwise use random numbers. It is used to generate certain symbol names that have to be different in every compiled file. It is also used to place unique stamps in coverage data files and the object files that produce them. You can use the -frandom-seed option to produce reproducibly identical object files. The string should be different for every file you compile. The stanza "have to be different in every compiled file" is what worries me. There is probably a good reason that gcc needs to be able to emit unique function names. In contrib/gcc/tree.c, there's this piece of code: /* Generate a name for a function unique to this translation unit. TYPE is some string to identify the purpose of this function to the linker or collect2. */ tree get_file_function_name_long (const char *type) { ... /* We don't have anything that we know to be unique to this translation unit, so use what we do have and throw in some randomness. */ ... sprintf (q + len, "_%08X_%08X", crc32_string (0, name), crc32_string (0, flag_random_seed)); So this is all on purpose, and I think it would be a bad idea to disable it, unless we fully understand the consequences. On the other hand, the requirement "The string should be different for every file you compile", could possibly be fulfilled. Maybe by using the filename, relative to $SRCDIR, that is being compiled as "seed"? This would be unique for each compiled file, but still give the same result for each build, and also be independent of the particular machine you are building on.