From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 2C6813858D35 for ; Thu, 29 Jun 2023 13:28:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C6813858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 5165D21866; Thu, 29 Jun 2023 13:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1688045279; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=74oHPUzt5PPq9Ala4czqC58o+hpL1T56FIOxyDVV7HU=; b=zOokGqste0PsRF/dTHk/ssPb3mRQGSJbTDNSEFqfPE+VBfRhE3WZGfUF1AB98CwkS8c9qe grOuHQT4a8NFQO2JnW8smzU5IKaodk8R/s6kyE85K3BM7HrHZkWYUGr2x4Gs5jfEvkk+Dv SiuXwmjVz0eWdSYLb6vJmAvmhw1Pp88= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1688045279; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=74oHPUzt5PPq9Ala4czqC58o+hpL1T56FIOxyDVV7HU=; b=zBAgPHPkAoYYc5I51bPprERzAYCpCcpVdmOxMkLyMhy69Hoc3XjJ+hUW+O1PMJyWPN0Skg IlcmZCi8C/qYJcAQ== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 438C22C141; Thu, 29 Jun 2023 13:27:59 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id 3896867ED; Thu, 29 Jun 2023 13:27:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id 372566766; Thu, 29 Jun 2023 13:27:59 +0000 (UTC) Date: Thu, 29 Jun 2023 13:27:59 +0000 (UTC) From: Michael Matz To: Julian Waters cc: Andrew Pinski , gcc@gcc.gnu.org Subject: Re: [PATCH] Basic asm blocks should always be volatile In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: Hello, On Thu, 29 Jun 2023, Julian Waters via Gcc wrote: > int main() { > asm ("nop" "\n" > "\t" "nop" "\n" > "\t" "nop"); > > asm volatile ("nop" "\n" > "\t" "nop" "\n" > "\t" "nop"); > } > > objdump --disassemble-all -M intel -M intel-mnemonic a.exe > disassembly.txt > > 00000001400028c0
: > 1400028c0: 48 83 ec 28 sub rsp,0x28 > 1400028c4: e8 37 ec ff ff call 140001500 <__main> > 1400028c9: 90 nop > 1400028ca: 90 nop > 1400028cb: 90 nop > 1400028cc: 31 c0 xor eax,eax > 1400028cd: 48 83 c4 28 add rsp,0x28 > 1400028ce: c3 ret > > Note how there are only 3 nops above when there should be 6, as the first 3 > have been deleted by the compiler. With the patch, the correct 6 nops > instead of 3 are compiled into the final code. > > Of course, the above was compiled with the most extreme optimizations > available to stress test the possible bug, -O3, -ffunction-sections > -fdata-sections -Wl,--gc-sections -flto=auto. Compiled as C++17 and intel > assembly syntax Works just fine here: % cat xx.c int main() { asm ("nop" "\n" "\t" "nop" "\n" "\t" "nop"); asm volatile ("nop" "\n" "\t" "nop" "\n" "\t" "nop"); } % g++ -v ... gcc version 12.2.1 20230124 [revision 193f7e62815b4089dfaed4c2bd34fd4f10209e27] (SUSE Linux) % g++ -std=c++17 -flto=auto -O3 -ffunction-sections -fdata-sections xx.c % objdump --disassemble-all -M intel -M intel-mnemonic a.out ... 0000000000401020
: 401020: 90 nop 401021: 90 nop 401022: 90 nop 401023: 90 nop 401024: 90 nop 401025: 90 nop 401026: 31 c0 xor eax,eax 401028: c3 ret 401029: 0f 1f 80 00 00 00 00 nop DWORD PTR [rax+0x0] ... Testing with recent trunk works as well with no differences in output. This is for x86_64-linux. So, as suspected, something else is broken for you. Which compiler version are you using? (And we need to check if it's something in the mingw target) Ciao, Michael.