From patchwork Tue Jun 8 15:46:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1489490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=CTnr+bNq; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fzvl56l20z9sPf for ; Wed, 9 Jun 2021 01:47:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A116395C03E for ; Tue, 8 Jun 2021 15:47:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A116395C03E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623167263; bh=5pkDaLQOfa3y3/aY/Kti/1JvHeqnknWJj8uzEOtwsdw=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CTnr+bNquM9iF6mycDc+5GUdBK+1gJY3j4S9IxvbA3hEZpvOIbCrWPCdtvkTAbc9x hh3DloVvoxUp78DOS2HAoN3K5rI1DdJKFKYQoXrUcFtnFLslzdjALW74rl4hPSDtlR BssdW58DM2QWFcBL+tTUZgQosCUjr/pU5nzIczoE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by sourceware.org (Postfix) with ESMTPS id CC990383543A for ; Tue, 8 Jun 2021 15:47:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC990383543A Received: by mail-qv1-xf33.google.com with SMTP id im10so10148702qvb.3 for ; Tue, 08 Jun 2021 08:47:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=5pkDaLQOfa3y3/aY/Kti/1JvHeqnknWJj8uzEOtwsdw=; b=LTL3k4+nwxPUf/By5mE5/vB9YxUOBFaZw/JW6whCUuu/1a4FwcxB9j2F4bwJ3qmVpy +iW+Zj3Xb+t3TxjsShucQsMiqAPtfaSn28ckoNUSh3asF1KkIalyWXIWj1UvE2enP+0f ut4/+mu+QUn50wJI2oQ/wqy0p0w5Hv4fNulkffLzRwcJbQOl+bioY0DBwNDn2JiMtaAT NkN6azBVWdgmfRLrS4yEA8bCVwu4vdStSH3C+jMk6IQQ0CyzRw0MWd2mc0dHomfVnoJn vxkM2O2tQvVrtKt+ghcDOgwjEI4MGtWTD57BxpzDMxrNtbSv38N5Ol6cQmlpn6aukeWr z+9w== X-Gm-Message-State: AOAM532VDSFhv0ZdZp8+8g0RavAaJrUmpBZ8apqovcow0tKSYbLXONu/ Jg/JvfJ5Nu7DkIkkeZ+tPBXwQe96uwxT14nsIQR7yRyVBeiVow== X-Google-Smtp-Source: ABdhPJx2iGLRYmL9bmUBM3lJltd6adio/7mhVpdDMYJO0l1idctIlHkyzQpT9+c9KbObJru0OmqKjib4ufDq87ultPM= X-Received: by 2002:a0c:aac8:: with SMTP id g8mr840822qvb.4.1623167220246; Tue, 08 Jun 2021 08:47:00 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 8 Jun 2021 17:46:49 +0200 Message-ID: Subject: [RFC PATCH] i386: Do not emit segment overrides for %p and %P [PR100936] To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Uros Bizjak via Gcc-patches From: Uros Bizjak Reply-To: Uros Bizjak Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Using %p to move the address of a symbol using LEA: asm ("lea %p1, %0" : "=r"(addr) : "m"(var)); emits assembler warning when VAR is declared in a non-generic address space: Warning: segment override on `lea' is ineffectual The problem is with %p operand modifier, which should emit raw symbol name: p -- print raw symbol name. Similar problem exists with %P modifier, trying to CALL or JMP to an overridden symbol,e.g: call %gs:zzz jmp %gs:zzz emits assembler warning: Warning: skipping prefixes on `call' Warning: skipping prefixes on `jmp' Ensure that %p and %P never emit segment overrides. 2021-06-08 Uroš Bizjak gcc/ PR target/100936 * config/i386/i386.c (print_operand_address_as): Rename "no_rip" argument to "raw". Do not emit segment overrides when "raw" is true. gcc/testsuite/ PR target/100936 * gcc.target/i386/pr100936.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Uros. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index b0d19a61a76..05b8dc806cd 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -13531,7 +13531,7 @@ ix86_print_operand_punct_valid_p (unsigned char code) static void ix86_print_operand_address_as (FILE *file, rtx addr, - addr_space_t as, bool no_rip) + addr_space_t as, bool raw) { struct ix86_address parts; rtx base, index, disp; @@ -13570,7 +13570,7 @@ ix86_print_operand_address_as (FILE *file, rtx addr, else gcc_assert (ADDR_SPACE_GENERIC_P (parts.seg)); - if (!ADDR_SPACE_GENERIC_P (as)) + if (!ADDR_SPACE_GENERIC_P (as) && !raw) { if (ASSEMBLER_DIALECT == ASM_ATT) putc ('%', file); @@ -13589,7 +13589,7 @@ ix86_print_operand_address_as (FILE *file, rtx addr, } /* Use one byte shorter RIP relative addressing for 64bit mode. */ - if (TARGET_64BIT && !base && !index && !no_rip) + if (TARGET_64BIT && !base && !index && !raw) { rtx symbol = disp; diff --git a/gcc/testsuite/gcc.target/i386/pr100936.c b/gcc/testsuite/gcc.target/i386/pr100936.c new file mode 100644 index 00000000000..c076cbb2405 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr100936.c @@ -0,0 +1,34 @@ +/* PR target/100936 */ +/* { dg-do assemble } */ +/* { dg-options "-O2" } */ + +__seg_gs int var; + +static int +*foo (void) +{ + int *addr; + + asm ("lea %p1, %0" : "=r"(addr) : "m"(var)); + + return addr; +} + +static int +bar (int *addr) +{ + int val; + + asm ("mov %%gs:%1, %0" : "=r"(val) : "m"(*addr)); + + return val; +} + +int +baz (void) +{ + int *addr = foo(); + int val = bar (addr); + + return val; +}