From owner-freebsd-bugs@FreeBSD.ORG Wed Sep 25 01:40:03 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 3BD3D67A for ; Wed, 25 Sep 2013 01:40:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0F88E2B6E for ; Wed, 25 Sep 2013 01:40:03 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r8P1e2uw049558 for ; Wed, 25 Sep 2013 01:40:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r8P1e27D049557; Wed, 25 Sep 2013 01:40:02 GMT (envelope-from gnats) Date: Wed, 25 Sep 2013 01:40:02 GMT Message-Id: <201309250140.r8P1e27D049557@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Derek Schrock Subject: Re: bin/182098: [patch] Change kldxref fts_open ordering so it produces a consistent linker.hints between machines of the same architecture. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Derek Schrock List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Sep 2013 01:40:03 -0000 The following reply was made to PR bin/182098; it has been noted by GNATS. From: Derek Schrock To: Jilles Tjoelker Cc: bug-followup@FreeBSD.org Subject: Re: bin/182098: [patch] Change kldxref fts_open ordering so it produces a consistent linker.hints between machines of the same architecture. Date: Tue, 24 Sep 2013 21:32:42 -0400 --NzB8fVQJ5HfG6fxh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Sep 16, 2013 at 12:39:58AM +0200, Jilles Tjoelker wrote: > In the interest of reproducible builds, your patch seems a good idea. It > seems unattractive to run kldxref /boot/kernel on every machine. > > The implementation of compare() seems unnecessarily complex though. In > find -s, the fts_names are simply passed to strcoll() (here, strcmp() > would be better). The trickery with the length may cause inconsistent > results if one filename is a prefix of another (rare). Fair enough after reading more of the fts(3) man fts_name is always null terminated. > > This change may also expose a latent bug with kldxref -R: it does not > work properly if a directory contains both files that need a mention in > a hints file and subdirectories, and at least one such file appears > after a subdirectory. Because your change alters the traversal order, it > might break a use of kldxref -R that previously happened to work. You > can make it work reliably by sorting FTS_D entries after other entries. Yep, after some additional testing with the patched kldxref it produced different linker.hints files. The new patch uses fts_parent's fts_name (the directory's name). First compare the parent's name, if the same compare the passed FTSENTs. --NzB8fVQJ5HfG6fxh Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" --- kldxref.c.old 2013-09-24 21:06:07.000000000 -0400 +++ kldxref.c 2013-09-24 21:31:39.000000000 -0400 @@ -275,6 +275,19 @@ exit(1); } +int +compare(const FTSENT* const* a, const FTSENT* const* b) +{ + char* a_parent = ((*a)->fts_parent)->fts_name; + char* b_parent = ((*b)->fts_parent)->fts_name; + int match = strcmp(a_parent, b_parent); + + if (match == 0) + match = strcmp((*a)->fts_name, (*b)->fts_name); + + return match; +} + int main(int argc, char *argv[]) { @@ -316,7 +329,7 @@ err(1, "%s", argv[0]); } - ftsp = fts_open(argv, fts_options, 0); + ftsp = fts_open(argv, fts_options, compare); if (ftsp == NULL) exit(1); --NzB8fVQJ5HfG6fxh--