From patchwork Thu Dec 7 12:10:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 845540 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-468674-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="MLr1dMne"; 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 3ysvTG271Bz9s83 for ; Thu, 7 Dec 2017 23:10:56 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=y0HLPo4pDjbMPBSgD36EW14tOnyABOFNCnCJHAPnECIWSRl1Rz KHhYZlEpGpgHyqLZ2TGecnUEj+v4TOsV2o5XxxZkHRAiTT/pklLuDDsllNw0Qqo0 Y5LMWA05qnNyBnTyGwUWb2KdivvBkkXFSRGIJxJ9+TqwuXYXCK7ci9VBU= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=KDu/+D6IhZwU9feuxnfnspBigCg=; b=MLr1dMne0gogvZqaZL/P xePLp3eYnay1AevZ0M0xeZs/Ssht19+7fHALZPYuv1Ku8sCC/aZtZkyj+4wkr/3Q Y+ICN6qPMJioZfalZ+O7/zltpC5YfUnLMr9KJRClGmzCMvU5ZoTlw/R/cR4A9muB SNY38tH8Yu+SmsPucx1WNaM= Received: (qmail 6629 invoked by alias); 7 Dec 2017 12:10:44 -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 6585 invoked by uid 89); 7 Dec 2017 12:10:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=xo X-HELO: mail-qt0-f180.google.com Received: from mail-qt0-f180.google.com (HELO mail-qt0-f180.google.com) (209.85.216.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Dec 2017 12:10:36 +0000 Received: by mail-qt0-f180.google.com with SMTP id i40so16830553qti.8 for ; Thu, 07 Dec 2017 04:10:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=MV2YmA4WVY2MQRwlzaEjPD2Inr7HY3LxYd8KUvmo4ks=; b=OCzs2LNWv6YO3vPuY1RT2AJf5+F5ty7J1T0Zvw+w6lmV+kT666qTSpn7VOOqx5mQwj 1FdstkmMba4BjNQFHoWZAupRfjSjh0bnxYhtqK0dL+wMTeUYXfVEePAvGC2zRNl1OtNu lwhSsJxc+fO4jb7Ir9tHYzxprapYKf5tHzCa9Cr6GawhjEcriAtVt9VRKzLMYfz62awZ Bos/wKyPjstaidEzzwO9GgnEXzpB16xORQ0I6Q66tN8jsbb77Wpgjk+TFSmVSdWeho6j qLPRtlymCX1O2xzvvvWhdBXZO7moa3WZiX666LxyujxSWKhCpM29BxdfLhWh5Rkqsra3 2t3g== X-Gm-Message-State: AKGB3mJeGTeUlDEciTs4fLFxiW9Es2k/ZMNWeKuRUAwJZGrkUu1mcPlX Ty0hwRAV3NSIcq9lcb+Tbak= X-Google-Smtp-Source: AGs4zMau+mhpG1pmm+RvZ3HNlg3uOFSEsvYZ3NW9ofUdqAcmN41Xqo0zO078onlhQfgCCA5kqYelAw== X-Received: by 10.200.63.209 with SMTP id v17mr8501023qtk.242.1512648634999; Thu, 07 Dec 2017 04:10:34 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::7207]) by smtp.googlemail.com with ESMTPSA id v58sm3270167qtk.18.2017.12.07.04.10.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Dec 2017 04:10:34 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [PATCH] -fdump-tree, -save-temps=obj & subdirs Message-ID: <5390131e-c9ed-15f4-7faa-1a0e3a2f15ff@acm.org> Date: Thu, 7 Dec 2017 07:10:33 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 There's an unfortunate interaction between -save-temps=obj and -fdump-tree- when subdirectories are in play. Consider: g++ -fdump-tree-all -save-temps=obj -c -o tgt/x.o sub/x.cc we end up with a bunch of errors of the form: sub/x.cc:1:0: error: could not open dump file ‘tgt/tgt/x.046t.profile_estimate’: No such file or directory you'll see it's added the 'tgt' sub directory twice. The reason is that cc1plus is invoked as: /usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -E -quiet -v -D_GNU_SOURCE sub/x.cc -mtune=generic -march=x86-64 -ansi -Woverloaded-virtual -Wall -Wpointer-arith -Wwrite-strings -felide-constructors -fdump-tree-all -fpch-preprocess -o tgt/x.ii to generate the preprocessed output, and then as: /usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -fpreprocessed tgt/x.ii -quiet -dumpbase tgt/x -mtune=generic -march=x86-64 -auxbase-strip tgt/x.o -Woverloaded-virtual -Wall -Wpointer-arith -Wwrite-strings -ansi -version -felide-constructors -fdump-tree-all -o tgt/x.s for the compilation itself. That has '-dumpbase tgt/x' and '-auxbase-strip tgt/x.o' passed in. The options processing checks if dump-base is absolute, and if not prefixes dump_dir_name or aux_base_name's directory components. It seems to me that the absolute path check is incomplete. We should check if dump-base has /any/ directory components. If it does, we shouldn't touch it. That's what this patch does: 1) remove the absolute dir check. That's subsumed into ... 2) look for any DIR_SEPARATOR in the dump-base. If so, no prefixing 3 & 4) existing prefix code 5) always set dump_base_name_prefixed, so we don't repeat #2 on a subsequent invocation. With this patch we now get a successful compilation: nathans@lyta:7>egcs/trunk/obj/x86_64/gcc/xg++ -B egcs/trunk/obj/x86_64/gcc/ -fdump-tree-all -save-temps=obj -c -o tgt/x.o sub/x.cc nathans@lyta:8>ls tgt total 100 4 x.003t.original 4 x.010t.eh 4 x.020t.ssa 4 x.049t.release_ssa 4 x.220t.switchlower 4 x.o 4 x.004t.gimple 4 x.011t.cfg 4 x.027t.fixup_cfg3 4 x.050t.local-fnsummary2 4 x.226t.resx 4 x.s 4 x.006t.omplower 4 x.012t.ompexp 4 x.028t.local-fnsummary1 4 x.087t.fixup_cfg4 4 x.228t.optimized 4 x.007t.lower 4 x.013t.printf-return-value1 4 x.029t.einline 4 x.218t.veclower 0 x.313t.statistics 4 x.009t.ehopt 4 x.019t.fixup_cfg1 0 x.046t.profile_estimate 4 x.219t.cplxlower0 4 x.ii ok? nathan 2017-12-06 Nathan Sidwell * opts.c (finish_options): Don't prefix dump_base_name if it already contains directories. Index: gcc/opts.c =================================================================== --- gcc/opts.c (revision 255442) +++ gcc/opts.c (working copy) @@ -698,19 +698,27 @@ finish_options (struct gcc_options *opts enum unwind_info_type ui_except; if (opts->x_dump_base_name - && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name) && ! opts->x_dump_base_name_prefixed) { - /* First try to make OPTS->X_DUMP_BASE_NAME relative to the - OPTS->X_DUMP_DIR_NAME directory. Then try to make - OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME - directory, typically the directory to contain the object - file. */ - if (opts->x_dump_dir_name) + const char *sep = opts->x_dump_base_name; + + for (; *sep; sep++) + if (IS_DIR_SEPARATOR (*sep)) + break; + + if (*sep) + /* If dump_base_path contains subdirectories, don't prepend + anything. */; + else if (opts->x_dump_dir_name) + /* We have a DUMP_DIR_NAME, prepend that. */ opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name, opts->x_dump_base_name, NULL); else if (opts->x_aux_base_name && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0) + /* AUX_BASE_NAME is set and is not the bit bucket. If it + contains a directory component, prepend those directories. + Typically this places things in the same directory as the + object file. */ { const char *aux_base; @@ -729,7 +737,9 @@ finish_options (struct gcc_options *opts opts->x_dump_base_name = new_dump_base_name; } } - opts->x_dump_base_name_prefixed = true; + + /* It is definitely prefixed now. */ + opts->x_dump_base_name_prefixed = true; } /* Handle related options for unit-at-a-time, toplevel-reorder, and