From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 211643858D20 for ; Wed, 30 Nov 2022 10:49:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 211643858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AU906Gv003858 for ; Wed, 30 Nov 2022 10:49:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : content-type : in-reply-to : content-transfer-encoding : mime-version; s=pp1; bh=wdl+RVvEPpOEgjVnCLuZtgu3OEbfllyErtBTbsuDlAA=; b=F8pzwvwq7iBjy7w2PNtqGdeyW+rE+eTF+HUeUDXupidbZRj+Vr/KGLx6FEqsmopPIn6H rmMqd7m6XGPVS4YK+P79SjgCh3redrW6CndMnlXVe9BtkKl8ogzffVsRqnv2mR2wslk3 76e49wO9knlcm4OTpwqal0/5Vxyn38haqoRmhYOKJKn726r70QEqX3Qlbl9vqoVmeXrI TvnLrlwKMt7r/6E/gh9pgNbZ4K6SiBBTHOBbaa6dvWAvHfaA81cjQMhDlHUiSsWYuRnm 5BazGxjqxbNUDliBRTu06NXUMH5NB+OGK3QuRJpkbPbd6fxegfoHXsCXOfs9DJ4r5R77 sg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m61jjx47j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 30 Nov 2022 10:49:19 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AUAWwDp040670 for ; Wed, 30 Nov 2022 10:49:18 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m61jjx46u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Nov 2022 10:49:18 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AUAaPR0028554; Wed, 30 Nov 2022 10:49:17 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3m3a2hwn4p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Nov 2022 10:49:16 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AUAnEhD62456080 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Nov 2022 10:49:14 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5AA67A404D; Wed, 30 Nov 2022 10:49:14 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 26451A4040; Wed, 30 Nov 2022 10:49:14 +0000 (GMT) Received: from li-42a4824c-28a0-11b2-a85c-f55c0d5956ce.ibm.com (unknown [9.179.1.253]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 30 Nov 2022 10:49:14 +0000 (GMT) Date: Wed, 30 Nov 2022 11:49:13 +0100 From: Stefan Schulze Frielinghaus To: Richard Biener Cc: gcc@gcc.gnu.org Subject: Re: How to debug while using LTO? Message-ID: References: <689A7218-A12B-4612-B8C0-EACE12C4F8AC@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <689A7218-A12B-4612-B8C0-EACE12C4F8AC@gmail.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: J9YQaE6rAG2sUcZX9_Hpw-MMdqpW1LuU X-Proofpoint-ORIG-GUID: p4_p2WOx94l9PKgAHjVpIeX4v0eOSMwJ Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-30_04,2022-11-29_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 impostorscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211300076 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP 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, Nov 24, 2022 at 05:53:53PM +0100, Richard Biener wrote: > > > > Am 24.11.2022 um 17:28 schrieb Stefan Schulze Frielinghaus via Gcc : > > > > Hi everyone, > > > > Currently I'm looking into a wrong-code bug and would like to understand > > a certain optimization done by combine during local transformation. > > Without LTO I would simply debug cc1 and step through combine. However, > > with LTO enabled AFAIK I have to debug lto1 instead. In order to get > > the lto1 command line of interest according to > > https://gcc.gnu.org/legacy-ml/gcc/2009-11/msg00047.html > > I have to pass -Wl,-debug to gcc in order to get the command for > > collect2 to which itself I have to pass -plugin-opt=-debug in order to > > get the command for lto-wrapper. According to the aforementioned mail I > > should add option -debug to lto-wrapper, however, it appears to me that > > option -debug was removed. I gave options -v and -### a chance without > > luck, i.e., those only print the usual environment variables and > > afterwards a list of object files like > > > > /tmp/ccPEIV35.ltrans0.ltrans.o > > /tmp/ccNmpKfS.debug.temp.o > > /tmp/cceiCIFg.debug.temp.o > > /tmp/ccZ4Qc7E.debug.temp.o > > ... > > > > but no lto1 command. Thus, how do you retrieve the lto1 command? > > > > While desperate I retrieved it manually via strace. However, the lto1 > > command refers to temporary files which have been erased meanwhile. I > > actually didn't expect that because I added -save-temps to all the > > intermediate commands which is also reflected in the environment > > variable COLLECT_GCC_OPTIONS. Thus, how do you keep temporary files? > > Adding -v -save-temps and then running gdb on the lto1 command works and is what I usually do. Strangely this is not the case for the current project I'm looking at. The link step is done via /usr/local/bin/s390x-linux-gnu-gcc -save-temps \ -O3 -DNDEBUG -flto=auto -fno-fat-lto-objects \ -march=z15 -static -nostdlib \ -Wl,--fatal-warnings -Wl,--no-warn-rwx-segments \ -Werror -Wall -Wundef -T/devel/foo.ld \ obj1.o ... objN.o where -save-temps is given and was also given during compile time of each object obj1.o ... objN.o file. Anyhow, adding -Wl,-debug to the link command above I see that -save-temps is also included in the environment variable COLLECT_GCC_OPTIONS="... -save-temps ..." and I get the linker command /usr/local/lib/gcc/s390x-linux-gnu/13.0.0/../../../../s390x-linux-gnu/bin/ld \ -plugin /usr/local/libexec/gcc/s390x-linux-gnu/13.0.0/liblto_plugin.so \ -plugin-opt=/usr/local/libexec/gcc/s390x-linux-gnu/13.0.0/lto-wrapper \ -plugin-opt=-fresolution=foo.res \ -m elf64_s390 -static -o foo \ -L/usr/local/lib/gcc/s390x-linux-gnu/13.0.0 \ -L/usr/local/lib/gcc/s390x-linux-gnu/13.0.0/../../../../s390x-linux-gnu/lib \ --fatal-warnings --no-warn-rwx-segments \ obj1.o ... objN.o -lgcc -T /devel/foo.ld to which I add -plugin-opt=-debug in order to get the lto-wrapper command /usr/local/libexec/gcc/s390x-linux-gnu/13.0.0/lto-wrapper \ -fresolution=foo.res -flinker-output=exec \ obj1.o ... objN.o to which I add -v -save-temps in order to actually get the lto1 command. From the output printed to stderr I see one lto1 command: /usr/local/libexec/gcc/s390x-linux-gnu/13.0.0/lto1 -quiet -dumpbase ./a.wpa \ -march=z15 -m64 -mzarch -g -O3 -version -fno-openmp -fno-openacc -fno-pie \ -fcf-protection=none -fltrans-output-list=/tmp/ccsuw4Nj.ltrans.out \ -fwpa=32 -fresolution=foo.res -flinker-output=exec @./a.wpa.args.0 However, this lto1 invocation does no local transformation. Having a look at the strace output I see a second lto1 invocation: /usr/local/libexec/gcc/s390x-linux-gnu/13.0.0/lto1 -quiet \ -dumpbase ./a.ltrans0.ltrans -march=z15 -m64 -mzarch -g -O3 \ -fno-openmp -fno-openacc -fno-pie -fcf-protection=none \ -fltrans /tmp/ccsuw4Nj.ltrans0.o -o /tmp/cc69wMp3.s This lto1 invocation seems to originate from Makefile /tmp/cc5piuXT.mk generated by lto-wrapper. To my surprise the Makefile as well as the temporary file /tmp/ccsuw4Nj.ltrans0.o are removed although -save-temps was given all the time. Stepping through lto-wrapper with gdb I see that save_temps = 1; is never executed while walking over decoded_options. For the time being I hard coded save_temps=1 into lto-wrapper.cc and I am now able to debug the lto1 invocation of interest. Not sure whether there is a more elegant way? All this is based upon a rather huge CMake based project and so far I didn't find the time to come up with a small reproducer. Still hoping this might be useful for someone else. Cheers, Stefan