From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9521AC433C1 for ; Mon, 22 Mar 2021 07:57:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF86F61937 for ; Mon, 22 Mar 2021 07:57:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF86F61937 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOFRi-0003Ye-Oy for qemu-devel@archiver.kernel.org; Mon, 22 Mar 2021 03:57:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOFP9-00022n-48 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 03:55:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47999) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOFP6-0001Tw-Ng for qemu-devel@nongnu.org; Mon, 22 Mar 2021 03:55:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616399710; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hztruVF4mejuuV/LmIoB1GaSJGgFI5Eu1b6BoY/FwEE=; b=S/k0/Sgz1JHTMhd0y2ij55/RceguP7ifA1yYdAxPQ9DcdBLCNZAS46bhhiajfQT4pVsFkF K2p5GSlFw2s2yKSptO2I5mMA8tEoK8Engj8ZpnLEZX3u0ISRrcb+stokZ53iYgE27DR7NC 28JHrx7KOTLrBrg8LvQT/SKNpZRzkfU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-80aQ2DG7MUyDlwD-1N3PfA-1; Mon, 22 Mar 2021 03:55:09 -0400 X-MC-Unique: 80aQ2DG7MUyDlwD-1N3PfA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49CEB87A826; Mon, 22 Mar 2021 07:55:07 +0000 (UTC) Received: from [10.64.54.40] (vpn2-54-40.bne.redhat.com [10.64.54.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 28692E2E5; Mon, 22 Mar 2021 07:55:03 +0000 (UTC) Subject: Re: [PATCH] configure: Improve alias attribute check To: Richard Henderson , Paolo Bonzini References: <20210320042753.69297-1-gshan@redhat.com> <5a6e5d96-7b23-7a56-3096-fb80155cac26@redhat.com> <107a73a0-aafe-bfce-7c28-8ed5fe6c022f@linaro.org> <4c8d854e-a8a1-2a44-5a02-96a5ce5598bc@linaro.org> <0cad2de8-1150-be7c-237b-9f3ddea52473@linaro.org> From: Gavin Shan Message-ID: <4231d15c-493f-cb3d-39ef-aff40e3618ee@redhat.com> Date: Mon, 22 Mar 2021 21:54:36 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <0cad2de8-1150-be7c-237b-9f3ddea52473@linaro.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=gshan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=63.128.21.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Gavin Shan Cc: Aldy Hernandez , Thomas Huth , qemu-devel , Laurent Vivier , qemu-arm , Shan Gavin , Philippe Mathieu Daude Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Hi Richard and Paolo, On 3/22/21 5:23 AM, Richard Henderson wrote: > On 3/21/21 11:46 AM, Paolo Bonzini wrote: >> HRM, what about biting the bullet and making exec-vary.c a C++ source?... Then instead of making it conditional an attribute((alias)), we make it conditional on having a C++ compiler. > > Doesn't help.  The gcc bug I filed talks about c++, because that's the closest analogy. > > But set_preferred_target_page_bits is called *much* later than a constructor. Though still before any use of the variable in question, for which we have an --enable-debug-tcg assertion. > It looks this issue can be avoided after "volatile" is applied to @target_page. However, I'm not sure if it's the correct fix to have. If it is, I can post a formal patch so that it can be included. --- a/exec-vary.c +++ b/exec-vary.c -extern const TargetPageBits target_page +extern const TargetPageBits volatile target_page __attribute__((alias("init_target_page"))); --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h -extern const TargetPageBits target_page; +extern const TargetPageBits volatile target_page; According to the experiments I did, it would be function call to set_preferred_target_page_bits() is dropped when the machine is created. The following c files are used in the experiment: --- a.c --- static int x; const extern int VOLATILE y __attribute__((alias("x"))); extern int read_y(void); void write_x(int val) { x = 1; } int main(void) { return read_y(); } --- b.c--- extern const int VOLATILE y; extern void write_x(int val); int read_y(void) { write_x(1); return y; } # gcc a.c b.c -O2 -flto=auto -DVOLATILE= -o a; ./a; echo $? 0 # gdb -nw ./a (gdb) disassem main Dump of assembler code for function main: 0x0000000000400480 <+0>: adrp x1, 0x420000 <__libc_start_main@got.plt> 0x0000000000400484 <+4>: mov w2, #0x1 // #1 0x0000000000400488 <+8>: mov w0, #0x0 // #0 0x000000000040048c <+12>: str w2, [x1, #32] 0x0000000000400490 <+16>: ret End of assembler dump. # gcc a.c b.c -O2 -flto=auto -DVOLATILE=volatile -o a; ./a; echo $? 1 # gdb -nw ./a (gdb) disassem main Dump of assembler code for function main: 0x0000000000400480 <+0>: adrp x1, 0x420000 <__libc_start_main@got.plt> 0x0000000000400484 <+4>: mov w2, #0x1 // #1 0x0000000000400488 <+8>: adrp x0, 0x420000 <__libc_start_main@got.plt> 0x000000000040048c <+12>: str w2, [x1, #32] 0x0000000000400490 <+16>: ldr w0, [x0, #32] 0x0000000000400494 <+20>: ret Thanks, Gavin