From patchwork Mon Apr 16 07:34:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 898490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476413-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SLto5jnz"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40PgBW1Xl4z9s0b for ; Mon, 16 Apr 2018 17:34:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=Np5qr9q0ngOF jmRV+GY/6SMd6g4aH9BMnSyB0IXZRhYQXRmZtBleUm+ER392GvTDEhQcAoK5OBL3 TAkI/hsootV7wkiHgxZH5sIb2lI+v9LjkDjamUMyPIZwwFH/6HKiFH3Ld6+ipiC3 Xv6MZQ87TzRifcNqOQcKaV7PqwsNdi0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=To3Aa3iuJkofDW7HAr ixmCS0Bm4=; b=SLto5jnzAoJiQ0EljMHL/5URiaqwhzZkBl1QzsEJgmWNcoGrsq c5QlFJYhwuNJTlHkbb1iWy56DGTqjmxTVtJ9iQ7/Yb/qCiIwwwf4Xe+HovmGVVyf HhiHmEfKQqQFmUTDq35OlYLUhjGonnh/TrngS0QdsDn0IUceJe0lRSYlY= Received: (qmail 87081 invoked by alias); 16 Apr 2018 07:34:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 87070 invoked by uid 89); 16 Apr 2018 07:34:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=pick, H*F:U*mark, UD:dwarf2out.c, dwarf2out.c X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Apr 2018 07:34:32 +0000 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id BA235302BB23; Mon, 16 Apr 2018 09:34:29 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 8433E413CEBB; Mon, 16 Apr 2018 09:34:29 +0200 (CEST) From: Mark Wielaard To: gcc-patches@gcc.gnu.org Cc: Mark Wielaard Subject: [PATCH] DWARF sort longer dirs before shorter ones in directory table. Date: Mon, 16 Apr 2018 09:34:17 +0200 Message-Id: <1523864057-7701-1-git-send-email-mark@klomp.org> When gcc dwarf2out generates the .debug_line table itself (for example when generating one for a split DWARF .dwo) it uses natural sorting for the directory table. Longer directory paths come before shorter directory paths with the same prefix. This causes the files in the line table to pick the shorter dir. Creating slightly ineffecient line tables because the longer directory paths will never be used. Fix this by changing file_info_cmp () to pick longer directory prefixes before shorter ones. We still sort files (the compilation unit) without any directory path before all entries with a directory path, so they will still use dir entry 0 (the working directory). A hello.c program would get the following dir and line table before: Directory table: /opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/8.0.1/include /usr/include /usr/include/bits File name table: Entry Dir Time Size Name 1 0 0 0 hello.c 2 1 0 0 stddef.h 3 2 0 0 bits/types.h 4 2 0 0 libio.h 5 2 0 0 stdio.h 6 2 0 0 bits/sys_errlist.h Note that the last directory table entry is never used. After this patch it looks as follows: Directory table: /opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/8.0.1/include /usr/include/bits /usr/include File name table: Entry Dir Time Size Name 1 0 0 0 hello.c 2 1 0 0 stddef.h 3 2 0 0 types.h 4 3 0 0 libio.h 5 3 0 0 stdio.h 6 2 0 0 sys_errlist.h Which is similar to what gas would output. gcc/ChangeLog: * dwarf2out.c (file_info_cmp): Sort longer dir prefixes before shorter ones. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 620e669..d3d925d 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -11955,7 +11955,9 @@ file_info_cmp (const void *p1, const void *p2) we return consistent values to qsort since some will get confused if we return the same value when identical operands are passed in opposite orders. So if neither has a directory, return 0 and otherwise return - 1 or -1 depending on which one has the directory. */ + 1 or -1 depending on which one has the directory. We want the one with + the directory to sort after the one without, so all no directory files + are at the start (normally only the compilation unit file). */ if ((s1->path == s1->fname || s2->path == s2->fname)) return (s2->path == s2->fname) - (s1->path == s1->fname); @@ -11966,11 +11968,12 @@ file_info_cmp (const void *p1, const void *p2) { ++cp1; ++cp2; - /* Reached the end of the first path? If so, handle like above. */ + /* Reached the end of the first path? If so, handle like above, + but now we want longer directory prefixes before shorter ones. */ if ((cp1 == (const unsigned char *) s1->fname) || (cp2 == (const unsigned char *) s2->fname)) - return ((cp2 == (const unsigned char *) s2->fname) - - (cp1 == (const unsigned char *) s1->fname)); + return ((cp1 == (const unsigned char *) s1->fname) + - (cp2 == (const unsigned char *) s2->fname)); /* Character of current path component the same? */ else if (*cp1 != *cp2)