From patchwork Thu Jan 11 18:24:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 187469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1638614dyi; Thu, 11 Jan 2024 10:25:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhJ2WAaYTzFcUcLbjKlU3etFYAdAfv3uZXmNGLRJhUoGs4UqAkJnZCyOyKW6u9jxUcPgVT X-Received: by 2002:a05:690c:c9c:b0:5f6:d37f:fa7f with SMTP id cm28-20020a05690c0c9c00b005f6d37ffa7fmr218728ywb.20.1704997520174; Thu, 11 Jan 2024 10:25:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704997520; cv=pass; d=google.com; s=arc-20160816; b=Vcy2wVMRys/zqu1REJnQ6iezv9+81ToU1wQVlp+MJyfDYlYiMQjJjRpjBE2VZhk7Vw gzwQFcBeOAYx8jboRQLSBQj0Fg9CLcGfhVVmcSB9wpJ/lCtrGdK9kNU+LVCmmLq/Tln0 RZm21drrJsEZc6Xg0e2ScQIcn6+eVdgH1viJMArvRLQNVWarrM/NLNwFuwUl+cfL8rkL ec7pGbql2pyAOi1xU6Lx83q5Yiev/E5ZXLOlvlKL2FsBnoco62AsDGYz6rweyrRCJ/EO t/kS5p8o8PdeU+qjxBK8pzgRyoqQjP10PBFkArWyub1Wvzgg5qnyGxMF/dsXWZ/8S+Lm /zrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:from:subject:message-id :mime-version:date:dkim-signature:arc-filter:dmarc-filter :delivered-to; bh=aCyLwPi5rbn97IBpQW+mvQIH0bvOdvkCWIIlsLkeN7c=; fh=PUPb0xuoA/atz2zSiMqinSSauQy4wi3ccNzRnWTnT90=; b=hM56E7F69Pv0yMkPJ9U9klps9J2P9yRV/W+42K6RIYs4QXKJnGLoXegDgy9kwMxowu no6TwehrafLh48jlwhoh5K0hqoP5y/mNbjSOSuuu4bAMGb2yJMAqYGYeT8WOS6Olf+BV 6/PqjxYmYvVgFuvQXu/tIO1IBJvrpH0tfe3uydPdEX3Ew3nx+prttTZqSLXu4GrQK28L wPvD5M3zqw4VKPs3GQPXhZUiEC4JgLI/YmkSBoLCqk0On4hUF9Uj9rozjY5S8OJXomOE D2eWafZZD0x48T+eaJx40xsV7dtHBFe07eHWPSNBIMflAiERsKgAVKmhJkzCfaqhxOVo H6vA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=B8ILdKxV; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u1-20020a0c8dc1000000b0067f9789bea1si1294405qvb.53.2024.01.11.10.25.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 10:25:20 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=B8ILdKxV; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A015B386F463 for ; Thu, 11 Jan 2024 18:25:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id AE540386C5BE for ; Thu, 11 Jan 2024 18:24:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE540386C5BE Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=flex--maskray.bounces.google.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE540386C5BE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704997477; cv=none; b=V+t6uXrnDmGtfIvnr1652OIPnLAgmS2lVtIVHuauYuJO06k+Pr6bSHP2jrOFgr71Rl2F1vjXl8+q+VfQ+6mL1vf21ptcaRhVCTeqxEpaxewfqXR2sS9WmdlMkq6UBhSh7B0REO9k9F55pXjyCRCcbbQMB5iraCeQ4D4Q7OULr30= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704997477; c=relaxed/simple; bh=1sEDK+p7/hQsQKMB88lqQs/iGslChIpOBQlMGserPl4=; h=DKIM-Signature:Date:Mime-Version:Message-ID:Subject:From:To; b=vXVD6fFJzIdZiy+euF0J5mNFYpwA1dytnu/Qzmmn+hVZjQDBsNvfRv/FmDpWG9SXbxnUAzaSl9IRsFz5C4NrHnLzA/dpRpmyCkKtzxKUf5T49ABYIfhjY6gXdpQUy+UXqGdbByMWLazNEiVOKU3vv5t52SeWjZ29FcIrwrr59+8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dbe9dacc912so6845588276.2 for ; Thu, 11 Jan 2024 10:24:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704997475; x=1705602275; darn=gcc.gnu.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=aCyLwPi5rbn97IBpQW+mvQIH0bvOdvkCWIIlsLkeN7c=; b=B8ILdKxVBAYYODHL+Hnmr9Q6gTcn/z5SBlzJX+pd5YidlATZdUtqgYdKgCFW5bN9aR rLT5GhGz3S8Qmn7BZO6CWDs3K85Px3JDvzbAd+oIepzvLJA1F4J3rTt5Nf9/Zd0u1txu Mv5czaT4eEi9DIBHA6LtXGptDaTexGk501QKfQWu7lSEEOea/uF7PH+69tkbdFL4B+Ag 0XSAjvNmQ+/HkaWKSua7tUIPzENNaRMfjmp9LKnoiAg3h7BNbuhm/M+2Qa1aYqMLDjTb uY+Onms7S3oBwqyZo7DSrJ7hgwsVd9809QuenNlPJM8SVkeqG43tAKfkGe7I6aiYzL09 cU8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704997475; x=1705602275; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aCyLwPi5rbn97IBpQW+mvQIH0bvOdvkCWIIlsLkeN7c=; b=oDP6UHESWqGnsSwFyq6SeENAGb/45hwi3v+17kGbOUnnEWB7QvaaCU9sQpN3zWgWEG 7Wkm/+4ZaS6opI/IhgaQ9hG2DvhIz4HFNJPQyFN/4rLho1cWvjqDok+H0nFMDUVkMeOV ZOBYaEIqmWGbfuNl3ovatEzoXTFgn6XNctiGQv7GnQJu4o8EfEnmrY2IR7iffsewlIQi rhTLlgAVe5W1hq4Gd1s40SLFCENLCKIfxxX1qHSkTDTo3FHhCEFk1ac9K7jv5MIf7Ct8 vrcORYa776EQOEicevlHQ6MRsY4GRcdo1YwEhO0gIoka7zMw7iwtKQGc27jgKZ93qWR6 e5HQ== X-Gm-Message-State: AOJu0Yyp1uGX4eP91KeEDK4PN0m5HoP4CmDFoImFujkVPsCZVYHf24TC M+pT5OCqVK/Sz6f8t2CKk4mTsOm0rBIR+RIPMUw= X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:ecd9:ef92:c56d:6d2f]) (user=maskray job=sendgmr) by 2002:a05:6902:1784:b0:dbe:32b0:9250 with SMTP id ca4-20020a056902178400b00dbe32b09250mr621ybb.0.1704997475137; Thu, 11 Jan 2024 10:24:35 -0800 (PST) Date: Thu, 11 Jan 2024 10:24:25 -0800 Mime-Version: 1.0 Message-ID: <20240111182425.547195-1-maskray@google.com> Subject: [PATCH] i386: Add "Ws" constraint for symbolic address/label reference [PR105576] From: Fangrui Song To: Jan Hubicka , Uros Bizjak , gcc-patches@gcc.gnu.org Cc: Fangrui Song X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787819479612827931 X-GMAIL-MSGID: 1787819479612827931 Printing the raw symbol is useful in inline asm (e.g. in C++ to get the mangled name). Similar constraints are available in other targets (e.g. "S" for aarch64/riscv, "Cs" for m68k). There isn't a good way for x86 yet, e.g. "i" doesn't work for PIC/-mcmodel=large. This patch adds "Ws". Here are possible use cases: ``` namespace ns { extern int var; } asm (".pushsection .xxx,\"aw\"; .dc.a %0; .popsection" :: "Ws"(&var)); asm (".reloc ., BFD_RELOC_NONE, %0" :: "Ws"(&var)); ``` gcc/ChangeLog: PR target/105576 * config/i386/constraints.md: Define constraint "Ws". * doc/md.texi: Document it. gcc/testsuite/ChangeLog: * gcc.target/i386/asm-raw-symbol.c: New testcase. --- This obsoletes https://gcc.gnu.org/pipermail/gcc-patches/2024-January/642580.html I initially tried 'z', but Uros requested that a W prefix is used. --- gcc/config/i386/constraints.md | 4 ++++ gcc/doc/md.texi | 4 ++++ gcc/testsuite/gcc.target/i386/asm-raw-symbol.c | 13 +++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/asm-raw-symbol.c diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md index 0c6e662df25..280e4c8e36c 100644 --- a/gcc/config/i386/constraints.md +++ b/gcc/config/i386/constraints.md @@ -348,6 +348,10 @@ (define_constraint "Wf" to double word size." (match_operand 0 "x86_64_dwzext_immediate_operand")) +(define_constraint "Ws" + "A symbolic reference or label reference." + (match_code "const,symbol_ref,label_ref")) + (define_constraint "Z" "32-bit unsigned integer constant, or a symbolic reference known to fit that range (for immediate operands in zero-extending x86-64 diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi index 47a87d6ceec..b0c61925120 100644 --- a/gcc/doc/md.texi +++ b/gcc/doc/md.texi @@ -4275,6 +4275,10 @@ require non-@code{VOIDmode} immediate operands). 128-bit integer constant where both the high and low 64-bit word satisfy the @code{e} constraint. +@item Ws +A symbolic reference or label reference. +You can use the @code{%p} modifier to print the raw symbol. + @item Z 32-bit unsigned integer constant, or a symbolic reference known to fit that range (for immediate operands in zero-extending x86-64 diff --git a/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c b/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c new file mode 100644 index 00000000000..b7854567dd9 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +extern int var; + +void +func (void) +{ + __asm__ ("@ %p0" : : "Ws" (func)); + __asm__ ("@ %p0" : : "Ws" (&var + 1)); +} + +/* { dg-final { scan-assembler "@ func" } } */ +/* { dg-final { scan-assembler "@ var\\+4" } } */