From patchwork Wed Nov 7 07:42:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 994137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489209-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xPeCELuC"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qdgl2JKJz9sBN for ; Wed, 7 Nov 2018 18:43:13 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=xsQN3VURHLUqtyq+ enoGLUr3ke6Xr/5dwld32UppnnPqmTAbdIaVzc5os8L1FQOi0FfC48LQp6H37Cvy Z5mjv1SDZ8qF0tdIst6ddl7NlLiDrZvq23x1wXBgEg+/ytXrJ5XgEOWLUVQ2TgQB j4kEUpbOcJzhyA2PPLfiyq/aSmA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=0tXGe8i/ffBCtB/CWGwq9r WRKZM=; b=xPeCELuCowPC6iV5cddt4pbVCpfp1DkFIedDAvJPKPJWuSl3FYYXMC fEZd4GllXkVsANllKRSWH3ut09BMh/mDE5a6fp6TNrR21QiCKBviTVrtKXMBbNWC 0kOE2NmnXIjV02SvVFYWuMPnY+iXmwMOugKU71Dfruc660QmUPrDc= Received: (qmail 24817 invoked by alias); 7 Nov 2018 07:43:06 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 24800 invoked by uid 89); 7 Nov 2018 07:43:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_STOCKGEN, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=gotoff, surgery X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Nov 2018 07:43:04 +0000 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 mx1.redhat.com (Postfix) with ESMTPS id A7B6E659AC for ; Wed, 7 Nov 2018 07:43:02 +0000 (UTC) Received: from free.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61292261A2; Wed, 7 Nov 2018 07:43:02 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTP id wA77gdeq747928; Wed, 7 Nov 2018 05:42:40 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PR87793] reject non-toplevel unspecs in debug loc exprs on x86 Date: Wed, 07 Nov 2018 05:42:39 -0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Before revision 254025, we'd reject UNSPECs in debug loc exprs. TARGET_CONST_NOT_OK_FOR_DEBUG_P still rejects that by default, on all ports that override it, except for x86, that accepts @gotoff unspecs. We can indeed accept them in top-level expressions, but not as subexpressions: the assembler rejects the difference between two @gotoff symbols, for example. We could simplify such a difference and drop the @gotoffs, provided that the symbols are in the same section; we could also accept @gotoffs plus literal constants. However, accepting those but rejecting such combinations as subexpressions would be ugly, and most likely not worth the trouble: sym@gotoff+litconst hardly makes sense as a standalone expression, and the difference between @gotoffs should be avoided to begin with, as follows. Ideally, the debug loc exprs would use the symbolic data in REG_EQUIV/REG_EQUAL notes, or delegitimized addresses, instead of simplifying the difference between two legitimized addresses so that the occurrences of the GOT register cancel each other. That would require some more elaborate surgery in var-tracking and cselib than would be appropriate at this stage. Regstrapped on x86_64- and i686-linux-gnu. Ok to install? for gcc/ChangeLog PR target/87793 * config/i386/i386.c (ix86_const_not_ok_for_debug_p): Reject non-toplevel UNSPEC. for gcc/testsuite/ChangeLog PR target/87793 * gcc.dg/pr87793.c: New. --- gcc/config/i386/i386.c | 12 +++++++++++ gcc/testsuite/gcc.dg/pr87793.c | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr87793.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index ae8971c82b0a..424a4b20631c 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -17172,6 +17172,18 @@ ix86_const_not_ok_for_debug_p (rtx x) if (SYMBOL_REF_P (x) && strcmp (XSTR (x, 0), GOT_SYMBOL_NAME) == 0) return true; + /* Reject UNSPECs within expressions. We could accept symbol@gotoff + + literal_constant, but that would hardly come up in practice, + and it's not worth the trouble of having to reject that as an + operand to pretty much anything else. */ + if (UNARY_P (x) + && GET_CODE (XEXP (x, 0)) == UNSPEC) + return true; + if (BINARY_P (x) + && (GET_CODE (XEXP (x, 0)) == UNSPEC + || GET_CODE (XEXP (x, 1)) == UNSPEC)) + return true; + return false; } diff --git a/gcc/testsuite/gcc.dg/pr87793.c b/gcc/testsuite/gcc.dg/pr87793.c new file mode 100644 index 000000000000..3194313a265d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87793.c @@ -0,0 +1,42 @@ +/* { dg-do compile } */ +/* { dg-options "-fpic -Os -g" } */ + +struct fit_loadable_tbl { + int type; + void (*handler)(int data, int size); +}; + +#define ll_entry_start(_type, _list) \ +({ \ + static char start[0] __attribute__((aligned(4))) \ + __attribute__((unused, section(".u_boot_list_2_"#_list"_1"))); \ + (_type *)&start; \ +}) + +#define ll_entry_end(_type, _list) \ +({ \ + static char end[0] __attribute__((aligned(4))) \ + __attribute__((unused, section(".u_boot_list_2_"#_list"_3"))); \ + (_type *)&end; \ +}) + +#define ll_entry_count(_type, _list) \ + ({ \ + _type *start = ll_entry_start(_type, _list); \ + _type *end = ll_entry_end(_type, _list); \ + unsigned int _ll_result = end - start; \ + _ll_result; \ + }) + +void test(int img_type, int img_data, int img_len) +{ + int i; + const unsigned int count = + ll_entry_count(struct fit_loadable_tbl, fit_loadable); + struct fit_loadable_tbl *fit_loadable_handler = + ll_entry_start(struct fit_loadable_tbl, fit_loadable); + + for (i = 0; i < count; i++, fit_loadable_handler++) + if (fit_loadable_handler->type == img_type) + fit_loadable_handler->handler(img_data, img_len); +}