From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 974C3385B1A4 for ; Wed, 30 Nov 2022 13:23:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 974C3385B1A4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x22c.google.com with SMTP id n1so16161806ljg.3 for ; Wed, 30 Nov 2022 05:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=eLbDFBD2PTGMEc++ybAEreOD8LpxcO2vWSgrXhiJ9bA=; b=GD6pyAJZ3g9SBcEcqkDUTtMgpgpVAc+EouUYty47p0pLlqpYz8HpQPUVOMoGOc/Cm1 EOOytwkSiWgwbLK2fT3F0ZeOECZkKeMjLHPBKwV7o2aGtrSHiu3gT1+6hnhBi1FruS19 xg/IOWlX6UgWA2AdF73kOkcBguXquJRtoyREyxzjrS9Z8yNiy2TtZag833aNClvhA1FY 7qDkpeASpwPWarwCU+VPwvRKvc24EcYJ9Wy+zCtVc1plLrhgt71Jhqq8aUiob/IZHZ0v L4eTKEbSdeqcSHWWmcfSTqztCmbDIQeyZfPeCJ80WQtft+Ta06IckypZqeptxjqOWQ3J Gdbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eLbDFBD2PTGMEc++ybAEreOD8LpxcO2vWSgrXhiJ9bA=; b=SOXeoDfnRG4SzAZ/WN/5284OYE85DaNxdz39Ny43+9FkFLK/RK63jsbPyUfr7rRga1 5bsGneusePZaR03f21jpM4jMNjye4q0bmiThePQ2WrHLMV09zHbFCfRAELVkrgbcpPpd RXVR9uz16QFzu+yl0gJJijfg1kBuwVdGtOyZfGce3CIXzWnKm+e7Zdc485dN+/gVrPN6 Sd5N/MsKQK1U/YWpSIBORmRYGzi2J+c4Smb8TC6xnvxS6PfQQvEvlgbeUD8XSnOHRc5d Ae6LVqvuTESyxga/MGAKFsEwZKBwCa+3nIHdvXo8o9MKR7DmPwaz7K3PokVLDMMgkXDn Rmew== X-Gm-Message-State: ANoB5pkz+cxFjwmav9CupheZHSo4kfZdfhivYLgYT7OTcF2eGY736uAw V1Ucjj9YuSBAJ4qjBXlYDnQDbYAvPZSpfeQxq7o= X-Google-Smtp-Source: AA0mqf5Y3zk7zPZAKfMqnYkPgzkYtKdvdarkSdIIZIhNLwk1fctdoGfzgCQLy5k7SYijbFMrUaukv3dIHbFxutfuaao= X-Received: by 2002:a2e:8750:0:b0:279:9466:9355 with SMTP id q16-20020a2e8750000000b0027994669355mr8089352ljj.253.1669814585864; Wed, 30 Nov 2022 05:23:05 -0800 (PST) MIME-Version: 1.0 References: <689A7218-A12B-4612-B8C0-EACE12C4F8AC@gmail.com> In-Reply-To: From: Richard Biener Date: Wed, 30 Nov 2022 14:22:53 +0100 Message-ID: Subject: Re: How to debug while using LTO? To: Stefan Schulze Frielinghaus Cc: gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,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 Wed, Nov 30, 2022 at 11:49 AM Stefan Schulze Frielinghaus wrote: > > 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 : > > > > > > =EF=BB=BFHi everyone, > > > > > > Currently I'm looking into a wrong-code bug and would like to underst= and > > > a certain optimization done by combine during local transformation. > > > Without LTO I would simply debug cc1 and step through combine. Howev= er, > > > 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=3D-debug in order= to > > > get the command for lto-wrapper. According to the aforementioned mai= l I > > > should add option -debug to lto-wrapper, however, it appears to me th= at > > > option -debug was removed. I gave options -v and -### a chance witho= ut > > > 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 lto= 1 > > > 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 an= d is what I usually do. > > Strangely this is not the case for the current project I'm looking at. T= he > link step is done via > > /usr/local/bin/s390x-linux-gnu-gcc -save-temps \ > -O3 -DNDEBUG -flto=3Dauto -fno-fat-lto-objects \ > -march=3Dz15 -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 com= mand > above I see that -save-temps is also included in the environment variable > COLLECT_GCC_OPTIONS=3D"... -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=3D/usr/local/libexec/gcc/s390x-linux-gnu/13.0.0/lto-wrapper= \ > -plugin-opt=3D-fresolution=3Dfoo.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=3D-debug in order to get the lto-wrapper comma= nd > > /usr/local/libexec/gcc/s390x-linux-gnu/13.0.0/lto-wrapper \ > -fresolution=3Dfoo.res -flinker-output=3Dexec \ > 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.w= pa \ > -march=3Dz15 -m64 -mzarch -g -O3 -version -fno-openmp -fno-openacc -fno= -pie \ > -fcf-protection=3Dnone -fltrans-output-list=3D/tmp/ccsuw4Nj.ltrans.out = \ > -fwpa=3D32 -fresolution=3Dfoo.res -flinker-output=3Dexec @./a.wpa.args.= 0 > > However, this lto1 invocation does no local transformation. Having a loo= k 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=3Dz15 -m64 -mzarch -g -O3 \ > -fno-openmp -fno-openacc -fno-pie -fcf-protection=3Dnone \ > -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 tem= porary > file /tmp/ccsuw4Nj.ltrans0.o are removed although -save-temps was given a= ll the > time. Stepping through lto-wrapper with gdb I see that > > save_temps =3D 1; > > is never executed while walking over decoded_options. > > For the time being I hard coded save_temps=3D1 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 did= n't > find the time to come up with a small reproducer. Still hoping this migh= t be > useful for someone else. At some point passing -Wl,-debug -Wl,-v to the gcc driver was necessary but I think we've meanwhile fixed it so that -save-temps -v works just fine= , preserving everything necessary to even invoke the LTRANS optimization stages, so I'm not sure what kind of issue you are running into here. > > Cheers, > Stefan