From patchwork Thu Feb 15 01:28:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 201229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp101443dyb; Wed, 14 Feb 2024 17:28:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWshfDarbl2XCeChB/DWj3rczVkoTpVkUbigVUtIpj216B3OYvNrAtfBYiSa7uy6O5xVJ1WCR4ZR/Va7vOssqGo5q/s7A== X-Google-Smtp-Source: AGHT+IGPAezoErSHpqLUGJ0dZGV0cfubELUk+oWisuoW4JKkd+AO1wY925uF+4gGe3ySW5ya4ZPN X-Received: by 2002:a05:6102:c8f:b0:46e:df6f:ccf8 with SMTP id f15-20020a0561020c8f00b0046edf6fccf8mr718156vst.21.1707960510084; Wed, 14 Feb 2024 17:28:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707960510; cv=pass; d=google.com; s=arc-20160816; b=TeMe7nQtHcZxdQi+nKvQhN2zc1cj3wMxH8lGild32NSsToNbqeR0EvDCX8h3UHn1/3 F3uXFUrgPrMjMNiLth/kbDApC+wV6upRerrhs0cHcmHSr3N6k/7zbfpsLQKUippb5xU2 6qZOEyPR9fNGmN8ZL/XP4iBsRE1tmaLqlIASB1DS9MHlqW91qkhuBaKbbZV0kecDrCnX ih0oMc6WY72Gf/qXySFRhaLUozAInkCSCrpdMDo8wfekdgiOoDqua801OF6FQg/fG7jt aBd0ORWSxvVNkgR6fzRKWTXHMzmn/ztQCjo4yAX5dvQVuKhMIx1nUBqXmQKVzOnJ+0Ux vFmQ== 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:content-disposition :mime-version:message-id:subject:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=wTdL3T5/Q9KazGZ/G4rWhQcCOq0gMbdhUAuHsidtMj8=; fh=NLxAvL/bDfPg4AGOtxqvQlND8vazkZrNzKLY8+LAbBY=; b=bDX/66WOFO6fOIcHOMpNXvdLoYw6sxLdv+yXqp8eY4MOzS92A7lcLXKUlzKPHw/RvN vzY/3F166kxHZnuBNDQ3aFThNnnRl1VY3ulSghzdf9p0Un8pDcNsZJUKR6lwpsCQLx2p ziD9jWpT2Ewi47gH01aCISvmX+VKE6IIU5OCFdYA+x7HLyNioI/QSZm5DwqqY7V9QeMa AkB6iL3gwt4rOH8FqadC5oXoepDeYNqWEBcaa3To0cmo0ydCJON20o+B9ymM/O4iVGnh 0jhGfkVyJ1RXrKT8W4dYjyJ6BUuoTaXN1X8l0dv5jdUmZRpBO5nXJVvOOwWaOomF0bdS zbdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XWw2416H; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h14-20020ac8744e000000b0042c508fdea5si255268qtr.742.2024.02.14.17.28.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 17:28:30 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XWw2416H; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4C4E386180D for ; Thu, 15 Feb 2024 01:28:29 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id DDC56386103D for ; Thu, 15 Feb 2024 01:28:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDC56386103D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DDC56386103D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707960502; cv=none; b=YzajC1bYXTXeb61ysZ8h3TEY5VOJZnIQmYxqOZN/fpDR9lQykXBVkdZRB6RDGB2dE587U0Pak428mJ6sGlkMnQcST6gRYG9i163E/dxRhNcKyX0dfMsh8gikSxDY8dpiQCySoUUH0OOp79b5jBA29UgIp8oeysUmxjfBVRyIXSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707960502; c=relaxed/simple; bh=u2q3OFjVRudwYhq8WQNbZqGegTTI6wUc0+lZehVxc2Y=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=uAwKKZisl3XIQCgkHwKimr63cI3HQDoNkrG1kEGo3GXyHAIj/ifSTDHspI0Dwym8xeQDFW4RTd1SVVt9BaA9VH3kg9YPn0A1EjANeOVdEWBxSgxzzcLOJF0RREzGQcx2Pe//p2oKYGgoGHqGMSmg+ppsdeeEeOcSmpYAo8ChLD8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d8aadc624dso2936505ad.0 for ; Wed, 14 Feb 2024 17:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707960499; x=1708565299; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=wTdL3T5/Q9KazGZ/G4rWhQcCOq0gMbdhUAuHsidtMj8=; b=XWw2416HHx81t9S1Xxfb94i/lTfdeGXP4YkvhYU1tY/GBgcP6i7eTM2a2gq89lvOK3 xO5jSHLble44t+cyNny5n402oPhBIVUdgqpumPeXND831zMcCz/ksoy401y4bjiVZsC5 fOYqej3fhzVUjRcwpONdlw0321NmSivwjoXYOJNYOncSggNTfPLCxWFFgbTFrolazzdE HkHQdA1yV6/AB2FIAjrqIpNkq0ZM8p/So77/B57Oe6iLxL4N6n/3aYSZc2Vbe4UoWtFr WVrDJFElyFly3hnh+F7qQResWO0JZX5tD8FFmS4xcb9ZIbsvbAMt1jVOI7LRgg+3c7Kl KP9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707960499; x=1708565299; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wTdL3T5/Q9KazGZ/G4rWhQcCOq0gMbdhUAuHsidtMj8=; b=p02xmCl/HWAKEpCICh4ufs1PjZon/LlkmErqh+61FTndr0SaymO12szcNSOENWHShg 3kUxpQLonEd7wVthkyAT1iSKld+8rFsWBgBGWy8knTqHFsM7wRCSeNAl2qcdOaIQsXWP aLYe+KUPMApYiKtAWykw9KYML4DQQFimmlBXg0VfcA/E2PELXwF3Oy/gVuCiDAYwxssX S1DitLi89W+nQ5iNbOxksQYg8GaZPqeznEVxhPWcoYuyyZRR1yj6MqwgMrCJ53UJ9zOc nMdLYPGlA+YleXYbtROWfV5SLs2g8uH1ywz26OEJtJZs/hn9zNOXjYLcI2T1c6t/V/8o Ai9g== X-Gm-Message-State: AOJu0YxDkJ2KtJhyNyw+EmGKY/unrO+OGEI/hElw/SgQ9qXoLPWlEj9B sAzKGya8W/JT7vo34K1vjHO7QEPJAr/sj8G9FQiIy2cE1o8DBeJVzOtRNKgC X-Received: by 2002:a17:902:b902:b0:1d9:8ddf:5fa0 with SMTP id bf2-20020a170902b90200b001d98ddf5fa0mr374473plb.62.1707960498963; Wed, 14 Feb 2024 17:28:18 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:28c1:7401:14e:6837]) by smtp.gmail.com with ESMTPSA id u2-20020a170903124200b001d8be6d1ec4sm86419plh.39.2024.02.14.17.28.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 17:28:18 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 1AEAD1141951; Thu, 15 Feb 2024 11:58:16 +1030 (ACDT) Date: Thu, 15 Feb 2024 11:58:16 +1030 From: Alan Modra To: binutils@sourceware.org Subject: PR30308, infinite recursion in i386_intel_simplify Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.4 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, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790926400125229643 X-GMAIL-MSGID: 1790926400125229643 This patch exposes the symbol "resolving" flag for use in i386_intel_simplify, not only preventing infinite recursion on the testcase in the PR but also more complicated cases like: .intel_syntax b = a a = b mov eax, [a] PR 30308 * symbols.c (symbol_mark_resolving, symbol_clear_resolving), (symbol_resolving_p): New functions. * symbols.h: Declare them. * config/tc-i386-intel.c (i386_intel_simplify): Delete forward declaration. Formatting. (i386_intel_simplify_symbol): Use resolving flag to prevent infinite recursion. diff --git a/gas/config/tc-i386-intel.c b/gas/config/tc-i386-intel.c index c95af419cf7..3011606d574 100644 --- a/gas/config/tc-i386-intel.c +++ b/gas/config/tc-i386-intel.c @@ -369,21 +369,25 @@ i386_intel_simplify_register (expressionS *e) return 2; } -static int i386_intel_simplify (expressionS *); - -static INLINE int i386_intel_simplify_symbol(symbolS *sym) +static int +i386_intel_simplify_symbol (symbolS *sym) { - int ret = i386_intel_simplify (symbol_get_value_expression (sym)); + if (symbol_resolving_p (sym)) + return 1; + symbol_mark_resolving (sym); + int ret = i386_intel_simplify (symbol_get_value_expression (sym)); if (ret == 2) - { - S_SET_SEGMENT(sym, absolute_section); - ret = 1; - } + { + S_SET_SEGMENT (sym, absolute_section); + ret = 1; + } + symbol_clear_resolving (sym); return ret; } -static int i386_intel_simplify (expressionS *e) +static int +i386_intel_simplify (expressionS *e) { const reg_entry *the_reg = (this_operand >= 0 ? i.op[this_operand].regs : NULL); diff --git a/gas/symbols.c b/gas/symbols.c index 41f273c85ff..4df83bab0e9 100644 --- a/gas/symbols.c +++ b/gas/symbols.c @@ -2936,7 +2936,7 @@ symbol_removed_p (symbolS *s) return s->flags.removed; } -/* Mark a symbol has having been resolved. */ +/* Mark a symbol as having been resolved. */ void symbol_mark_resolved (symbolS *s) @@ -2952,6 +2952,28 @@ symbol_resolved_p (symbolS *s) return s->flags.resolved; } +/* Mark a symbol as being resolved. */ + +void +symbol_mark_resolving (symbolS *s) +{ + s->flags.resolving = 1; +} + +void +symbol_clear_resolving (symbolS *s) +{ + s->flags.resolving = 0; +} + +/* Return whether a symbol is being resolved. */ + +int +symbol_resolving_p (symbolS *s) +{ + return s->flags.resolving; +} + /* Return whether a symbol is a section symbol. */ int diff --git a/gas/symbols.h b/gas/symbols.h index 3232f1b2a33..c61fabcbe0a 100644 --- a/gas/symbols.h +++ b/gas/symbols.h @@ -206,6 +206,9 @@ extern void symbol_mark_removed (symbolS *); extern int symbol_removed_p (symbolS *); extern void symbol_mark_resolved (symbolS *); extern int symbol_resolved_p (symbolS *); +extern void symbol_mark_resolving (symbolS *); +extern void symbol_clear_resolving (symbolS *); +extern int symbol_resolving_p (symbolS *); extern int symbol_section_p (symbolS *); extern int symbol_equated_p (symbolS *); extern int symbol_equated_reloc_p (symbolS *);