From patchwork Mon Dec 9 09:20:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 102649 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 349C8385842A for ; Mon, 9 Dec 2024 09:22:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 349C8385842A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=dMOEpEAF X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 6529F3858D34 for ; Mon, 9 Dec 2024 09:20:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6529F3858D34 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6529F3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733736016; cv=none; b=WN/rjMSBh7K4vOD2EoBypfU2Qkei/vLQxNxXyHwOMuWUUJVLTBhXjvXmXBoDnXTof+ENYj2Icux6o5ERBhjJxtQM7FM53ijZKvgcZtMb9YJIofrTBiJEeqaJs/VIGpQQIocYurT2Ofx+ylCH4QsIiGBoXUF6742NNf14K0oZNIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733736016; c=relaxed/simple; bh=fRBr/SOeIIBP49Kto65Jp51nPL32ndxODWuosRyrp+A=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=pUSVU7INUqGTAY72XlqAtzupasDMT/IAYsFRKvDH/AuQiwePvGXfaaZKFbfmNRfj5GbK8B5at+qlOOIS/OH2Slf2EkSGbKFMi+sAyD05mWlvOg0yP/2GAgmTlRfL2ydXGBxywd8d5Dw6obpurH3eJQ9ISUtbin3R47peS5j23nc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6529F3858D34 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-382610c7116so2091720f8f.0 for ; Mon, 09 Dec 2024 01:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1733736015; x=1734340815; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=D9Fr1O1guJ8dpnppAaSAA6DhNBEp6/T69uKknQr6+Wc=; b=dMOEpEAF+3nFRpn7ELjeCi4d5c1Y+gmmJYhyB1cwB/o6Jl/tYmjFuci5JqBb8T22z5 yjEqSzRNqykTorwnogtgWFeUgXiBP9kttsfhbMBf+39S+VnElww5pLdW7GsXzBagBEFF YLfLf7Wk77oABh61DnyeyLy64SGo5OunqQLOsK/aF5+dofDeF95kUd3BrOdW4t5z/bG1 0hwj3ub7jMZp21D4/9AyljnJApdZ7EhY9dE33VbDLy8NDqKB3XT8fM2YOwEex/2A6mKX IxDzM5vcsFd2IuhBOqIzWo8P1M79Eexniw3bFjIoMihgKId4/3/Ue4cDkAwb9fHNySx0 mgXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733736015; x=1734340815; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D9Fr1O1guJ8dpnppAaSAA6DhNBEp6/T69uKknQr6+Wc=; b=BYI+Tns8WUuZ8aTEf2NZXSEjt7j74aOXkmn47rcrb8C/dD47/Dx6/g2obE1AFFYoPH 67YySWEKc+aYcMEkxdOCwxpkSwdiSAm8/ZM/UzbBSdHbHsiizrnElkQPqvv/hFD+VFek G5IiA8aXYyRAJEy58uIJUzLAajNQU3EvXPHtuuuzto7yAGoGCUQyuJF8a8qWFq8Bsn6K cEJlFLN7hGRoi8UHy2U8lv0149qZBAR5S3fF2oU6tyT0hZOS7b2/Zpn2HdAA7k4Q4ydZ yw/cf7eu1mluhMyQOowJotWXO3skVh6ZBcwsRp6jPLcZGpSm92UZJ/krNn+V+kfXWF9u nVTw== X-Gm-Message-State: AOJu0YxpnNoSnUV++AkNPxvBTsnCyjZ3jiyseUsA3oiQWYOe8uB1el0r hHWa/olHM1vcgcDOYAccupPg3BMwysPGzUOa7aFWhMNWo7qgc15eMdtVQE/iGTxvaQzrndYJs7w = X-Gm-Gg: ASbGnct5ajhCGRHQNDr0NGMp5CiqeAF3KD6QWqJnR4JBG1DB0Qjxw0Y6VK7hd5NVR7f Z9Hfz8b4ZmJwYZZhbP1fH7UoXOJf/nKXUB43UmDkoQy7PBA+Fnj8uzLfzRzsv7HbmJpansszFVR 6iyfjMt/MBsLsPG+8O13eisN/xMdSo+HnLuSjRwqBbahr+vM14OXko8ULT2Gc47qJUtmy/6wchO 3BKD3+oRqCW+q5JHO8fQ8icao9A11BUcyUXWnt1eBoD2eG/6OZw/jtabNS1q6fWfzNGUbGUPiEC qnAMctaTrrv2/r9boaiJVyaMT8qniULeGjg= X-Google-Smtp-Source: AGHT+IEugC5wrk4rP/rGTi58Fj7fGWktQCn5vODuuHnr2RXaTQnNKKpzREO7kkAnYPOVhMCtoHs4cg== X-Received: by 2002:a05:6000:470d:b0:385:f38e:c0d3 with SMTP id ffacd0b85a97d-3862b3f0cabmr8194946f8f.58.1733736014992; Mon, 09 Dec 2024 01:20:14 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-216221db645sm45040095ad.46.2024.12.09.01.20.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Dec 2024 01:20:14 -0800 (PST) Message-ID: <9be71c9f-4399-4898-87e8-18ae9af03728@suse.com> Date: Mon, 9 Dec 2024 10:20:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH RFC 1/3] gas: defer printing version ID From: Jan Beulich To: Binutils References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: X-Spam-Status: No, score=-3022.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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~patchwork=sourceware.org@sourceware.org In order to be able to silence earlier uses of -v, don't print while processing command line arguments; defer until all options were consumed or we're about the exit (leaving alone all paths reaching as_fatal()). --- a/gas/as.c +++ b/gas/as.c @@ -631,7 +631,6 @@ parse_args (int * pargc, char *** pargv) if (optc == 'v') { case 'v': - print_version_id (); verbose = 1; break; } @@ -644,6 +643,8 @@ parse_args (int * pargc, char *** pargv) /* Fall through. */ case '?': + if (verbose > 0) + print_version_id (); exit (EXIT_FAILURE); case 1: /* File name. */ @@ -654,10 +655,14 @@ parse_args (int * pargc, char *** pargv) break; case OPTION_TARGET_HELP: + if (verbose > 0) + print_version_id (); md_show_usage (stdout); exit (EXIT_SUCCESS); case OPTION_HELP: + if (verbose > 0) + print_version_id (); show_usage (stdout); exit (EXIT_SUCCESS); @@ -694,6 +699,8 @@ parse_args (int * pargc, char *** pargv) break; case OPTION_VERSION: + if (verbose > 0) + print_version_id (); /* This output is intended to follow the GNU standards document. */ printf (_("GNU assembler %s\n"), BFD_VERSION_STRING); printf (_("Copyright (C) 2024 Free Software Foundation, Inc.\n")); @@ -721,6 +728,8 @@ This program has absolutely no warranty. break; case OPTION_DUMPCONFIG: + if (verbose > 0) + print_version_id (); fprintf (stderr, _("alias = %s\n"), TARGET_ALIAS); fprintf (stderr, _("canonical = %s\n"), TARGET_CANONICAL); fprintf (stderr, _("cpu-type = %s\n"), TARGET_CPU); @@ -1130,6 +1139,9 @@ This program has absolutely no warranty. } } + if (verbose > 0) + print_version_id (); + free (shortopts); free (longopts); From patchwork Mon Dec 9 09:20:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 102650 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61947385841C for ; Mon, 9 Dec 2024 09:24:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61947385841C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=XFzrE5qS X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id EA2AB3858CDB for ; Mon, 9 Dec 2024 09:20:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA2AB3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EA2AB3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733736062; cv=none; b=J6qkFjmS1Dc15VMiKyQKYouZXLDYIDgYwfb2AjlaiNvMlxVfUbdafS75fn3fZcjXEfbCi3rwQ6ttu0HzdlFIVkg7nmHaBwToJFyA0p7AL2pKaY5rlDwjDBFdKL5rEuYGeocnzF69kmcdWdwxxJQBmAjBrTi2OLjfy7AmNAOiL3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733736062; c=relaxed/simple; bh=7Z07DeK2zAePkAFfrsCCFYpDyQRd3nAER0wiBPPbV5I=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=qTTxH0+nuA3zpVM+6yFquYV7V2H4Gw/0UP8n9z67lk9kBWSXUm8bO2lh+OnTkYGC+XtkqBYs+NZYwk2aZL7Mvjh1wjspVEJohDjW9HkMDro5toaDJ7mn9nu4sk9moWJjyW/uHsEdiAEHTsTuqg2QnaZ9u//4Pnm4b9lDFWTV6W4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA2AB3858CDB Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-385d7b4da2bso3403002f8f.1 for ; Mon, 09 Dec 2024 01:20:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1733736055; x=1734340855; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2hkSBRblSgAh2bCNuNeBGzy4jBiVEFtLJuB93iEau3Y=; b=XFzrE5qS3HzyztyJtfubt3XjDJg4zjckSSbxR7v5tgWZhZ2lb3PvWxw0rY513fOY2N whC3FL+APtqWwRWY3GNjOfLeD4vzMzNNS2kE6o83eAuagV3bBels+fRQKdAWCGZe77ks uvG9RaU7SwFnL2QTOQ62zLwYtj3eqjBtG7d5IIugMyh6hHOZSTeC2KzXA7iwfzEH+lvu en8mipll9etWDLz3AYiF+ytQEVkuSROCc9QrOuLUTrYPBq302hF01hrmqX3l9UdTboBB 2HiEPgZMf4YmgIyWCPnYN/EMVr1tTz/GmL+QvGPa02RHEGcblkfCDZFdF0eLk3iolFPJ B9jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733736055; x=1734340855; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2hkSBRblSgAh2bCNuNeBGzy4jBiVEFtLJuB93iEau3Y=; b=rOCmwr3fv9eKiyjN1MceE3SGEt4A+F22k2UBj8ciWe8SeB46ROBoyzYp4RmqeS3dpR hzU7BM+EVdYuM2ej69qxK0LfIhBY+xlj74rD3nT9hhZv1nlxddUjg3HbiBWnhV2/fixW AOx0mBsnIHhxuUzcA4OoIPbcPY/tWoNtWNIeLi2UliwUtEzz+fTxvfv8gbGOpYCd770e jEMQWuG72ho/Ke83sZuDuGQBfd/yDKoOFHsIrRHc/DlwCL0CQg4IILCqW1UZNQqn+TOA 124a8rXZSh0ZEW1a6w/EkJu7HapUhw3iqbCKLNQ7Y6bNlySI4nhebeySdyF+zXOOkquX 0gJw== X-Gm-Message-State: AOJu0Yz4GlmbhdQAjnxvKpr8X8Y3oOiqKJkHvj9xnrA2jGhew80KHjnV QVyezLz6a1UQix+pt7m9EfofuxPWs0eNTQ8yZsFPiysu/2l7Ot2Y6hCkE8MM5Bg+xjNYnAzI5r8 = X-Gm-Gg: ASbGnct628vBuO51wuG0kQQhmfEhMJ/qCBJOZNSHvvYp2nGaplvwfhpN866Zv/XjYB+ fdqmLaPsFkONN266/CqDsU6wPTmnz5GY2NembWQBwbcFzEMlRjhdVo+wwfdINS4VpAcH+RKm1R2 Kjp6SD3k/d6JhAEKXXtG5bWZiHereKMfusabR/rAvmBQLtKF/2o95R0tlFSzO0d9nFRrF1PjWQq y/maIa9HcGTw/UnrkkbQUsgFn2OwPdYEsTOdClgOwteAk19X83rCd8Bsd8RESReG5ObrdzOw52z defmbiYzpHQy8HAXfGV8+jNOk3daCW5/ISs= X-Google-Smtp-Source: AGHT+IFskVnp7pbBkBOpS7FvevaXJZfKOqwdFvI/1dKj5eykIzEENPIkKrs9xfizHZeMwjScWUgPXA== X-Received: by 2002:a05:6000:402b:b0:385:e877:c037 with SMTP id ffacd0b85a97d-3862b3ce0c3mr7138154f8f.42.1733736055300; Mon, 09 Dec 2024 01:20:55 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725ea44c362sm1957229b3a.102.2024.12.09.01.20.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Dec 2024 01:20:54 -0800 (PST) Message-ID: <85359ef4-5c18-40c8-afbb-edc163813c59@suse.com> Date: Mon, 9 Dec 2024 10:20:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH RFC 2/3] gas: add a means to programmatically determine the assembler version From: Jan Beulich To: Binutils References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: X-Spam-Status: No, score=-3022.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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~patchwork=sourceware.org@sourceware.org It has been more than once that I would have wanted to have a way to know the gas version in assembly sources, perhaps for use with .if. Add such a pre-defined symbol, yet key exposure to -v being used at least twice (three times to also emit the symbols to the symbol table). Together with attempting to use non-symbol characters as separators (thus requiring quotation), this is to keep the risk of collisions with users' symbols as low as possible. To compensate for the effect the first -v has, also introduce --silent (to override that meaning of -v). Seeing that the "verbose" variable presently has no consumers, re-use it for the purposes here. Limit its visibility though, just to be on the safe side (e.g. with out-of-tree changes). If access is needed from elsewhere, an accessor function may want introducing instead. Similarly permit determining whether the assembler is a released version. The exact value probably isn't of much use, it's more the defined-ness that one might care about. Yet the symbol needs to have some value anyway. While fiddling with documentation, split -v from -version/--version. They aren't the same; -v long form is --verbose, which so far wasn't mentioned at all. --- Subsequently we may want to consider whether target-specific code should introduce further such symbols to indicate e.g. new ISA extensions they support (e.g. __x86_apx__ or just __apx__ on x86, with underscores again replaced as is done here). The string literal near the top of predefine_symbol() effectively becomes part of the gas specification: It may not easily have characters re-ordered (let alone dropped) for example, and even adding characters at the end may pose compatibility issues. The version2 test would certainly be nice to run for non-ELF as well, yet I can't seem to be able to thinks of a way to sensibly arrange for that (checking for the absence of any _other_ symbols). The ECOFF/XCOFF special casing of the 3rd test feels bogus. I wonder if this doesn't need to be XFAIL instead. At the example of XCOFF: ppc_saw_abs isn't set for local symbols, yet ppc_adjust_symtab() doesn't distinguish local and non-local ones. --- a/gas/as.c +++ b/gas/as.c @@ -95,7 +95,7 @@ int chunksize = 0; int debug_memory = 0; /* Enable verbose mode. */ -int verbose = 0; +static int verbose = 0; /* Which version of DWARF CIE to produce. This default value of -1 indicates that this value has not been set yet, a default value is @@ -461,6 +461,9 @@ parse_args (int * pargc, char *** pargv) OPTION_NOCPP, OPTION_STATISTICS, OPTION_VERSION, + OPTION_VERBOSE2, + OPTION_VERBOSE3, + OPTION_SILENT, OPTION_DUMPCONFIG, OPTION_EMULATION, OPTION_DEBUG_PREFIX_MAP, @@ -577,10 +580,13 @@ parse_args (int * pargc, char *** pargv) ,{"no-pad-sections", no_argument, NULL, OPTION_NO_PAD_SECTIONS} ,{"no-warn", no_argument, NULL, 'W'} ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS} + ,{"silent", no_argument, NULL, OPTION_SILENT} ,{"statistics", no_argument, NULL, OPTION_STATISTICS} ,{"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE} ,{"version", no_argument, NULL, OPTION_VERSION} ,{"verbose", no_argument, NULL, 'v'} + ,{"vv", no_argument, NULL, OPTION_VERBOSE2} + ,{"vvv", no_argument, NULL, OPTION_VERBOSE3} ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP} ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT} ,{"warn", no_argument, NULL, OPTION_WARN} @@ -631,7 +637,9 @@ parse_args (int * pargc, char *** pargv) if (optc == 'v') { case 'v': - verbose = 1; + if (verbose < 0) + verbose = -verbose; + ++verbose; break; } else if (is_a_char (optc)) @@ -718,6 +726,23 @@ This program has absolutely no warranty. #endif exit (EXIT_SUCCESS); + case OPTION_VERBOSE2: + if (verbose < 0) + verbose = -verbose; + verbose += 2; + break; + + case OPTION_VERBOSE3: + if (verbose < 0) + verbose = -verbose; + verbose += 3; + break; + + case OPTION_SILENT: + if (verbose > 0) + verbose = -verbose; + break; + case OPTION_EMULATION: #ifdef USE_EMULATIONS if (strcmp (optarg, this_emulation->name)) @@ -1153,6 +1178,50 @@ This program has absolutely no warranty. #endif } +/* Depending on command line options, optionally pre-define a symbol with its + name derived from TMPL (by replacing underscores if possible), to value + VAL. */ + +void +predefine_symbol (const char *tmpl, valueT val) +{ + static const char separators[] = ".@$?%&#"; + static char sep; + char name[64 /* Arbitrary, yet ought to fit all needs. */]; + symbolS *s; + + if (abs (verbose) <= 1) + return; + + /* To limit the risk of name collisions, try to find a non-symbol char to + use as separator. */ + if (sep == '\0') + for (const char *p = separators; *p != '\0'; ++p) + if (!is_name_beginner (*p) && !is_part_of_name (*p)) + { + sep = *p; + break; + } + + if (sep == '\0') + sep = '_'; + + for (char *p = name; ; ++p, ++tmpl) + { + *p = *tmpl != '_' ? *tmpl : sep; + if (*tmpl == '\0') + break; + } + + /* Also put the symbol in the symbol table in yet more "verbose" mode. */ + if (abs (verbose) > 2) + s = symbol_new (name, absolute_section, &zero_address_frag, val); + else + s = symbol_create (name, absolute_section, &zero_address_frag, val); + S_CLEAR_EXTERNAL (s); + symbol_table_insert (s); +} + static void dump_statistics (void) { @@ -1221,6 +1290,10 @@ perform_an_assembly_pass (int argc, char subseg_set (text_section, 0); #endif + predefine_symbol ("__gas_version__", BFD_VERSION); + if (strstr (BFD_VERSION_STRING, "." XSTRING (BFD_VERSION_DATE)) != NULL) + predefine_symbol ("__gas_date__", BFD_VERSION_DATE); + /* This may add symbol table entries, which requires having an open BFD, and sections already created. */ md_begin (); --- a/gas/as.h +++ b/gas/as.h @@ -410,9 +410,6 @@ extern unsigned int dwarf_level; /* Maximum level of macro nesting. */ extern int max_macro_nest; -/* Verbosity level. */ -extern int verbose; - struct obstack; /* Obstack chunk size. Keep large for efficient space use, make small to @@ -510,6 +507,7 @@ void as_report_context (void); const char * as_where (unsigned int *); const char * as_where_top (unsigned int *); const char * as_where_physical (unsigned int *); +void predefine_symbol (const char *, valueT); void bump_line_counters (void); void do_scrub_begin (int); void input_scrub_begin (void); --- a/gas/doc/as.texi +++ b/gas/doc/as.texi @@ -257,9 +257,11 @@ gcc(1), ld(1), and the Info entries for [@b{-o} @var{objfile}] [@b{-R}] [@b{--scfi=experimental}] [@b{--sectname-subst}] + [@b{--silent}] [@b{--size-check=[error|warning]}] [@b{--statistics}] - [@b{-v}] [@b{-version}] [@b{--version}] + [@b{-v}] [@b{--verbose}] + [@b{-version}] [@b{--version}] [@b{-W}] [@b{--no-warn}] [@b{--warn}] [@b{--fatal-warnings}] [@b{-w}] [@b{-x}] [@b{-Z}] [@b{@@@var{FILE}}] @@ -961,6 +963,11 @@ Honor substitution sequences in section @xref{Section Name Substitutions,,@code{.section @var{name}}}. @end ifclear +@item --silent +Since @option{-v}, when used multiple times, has dual purpose, this option +suppresses the emission of the version ID message from any earlier @option{-v}. +Later uses of @option{-v} will further override this. + @item --size-check=error @itemx --size-check=warning Issue an error or warning for invalid ELF .size directive. @@ -974,10 +981,15 @@ assembly. Remove local absolute symbols from the outgoing symbol table. @item -v -@itemx -version -Print the @command{as} version. +@itemx --verbose +Print the @command{as} version. When used more than once, it also controls the +insertion of certain pre-defined symbols in the symbol table: When used twice, +those symbols become available for use in source code, without inserting them +into the symbol table. When used three times, such symbols are also inserted +in the symbol table. (@pxref{Predefined Symbols}) @item --version +@itemx -version Print the @command{as} version and exit. @item -W @@ -3896,6 +3908,7 @@ the same order they were declared. This * Symbol Names:: Symbol Names * Dot:: The Special Dot Symbol * Symbol Attributes:: Symbol Attributes +* Predefined Symbols:: Predefined Symbols @end menu @node Labels @@ -4237,6 +4250,30 @@ Language Reference Manual} (HP 92432-900 @code{EXPORT} assembler directive documentation. @end ifset +@node Predefined Symbols +@section Predefined Symbols + +If enabled, certain pre-defined symbols will be made available for use, and +possibly also inserted in the symbol table. Below @code{_} is used as a word +separator. The actual separator used is target specific, and will typically +be a character not usable in plain symbol names. Access to these symbols will +therefore normally require quotation. + +Independent of the specific target, the following symbols can be made +available: +@itemize @bullet + +@item __gas_version__ +The version of the assembler, expressed as @samp{major} @code{*} 100000000 +@code{+} @samp{minor} @code{*} 1000000 @code{+} @samp{rev} @code{*} 10000. + +@item __gas_date__ +The date of the assembler sources (which may not be the date the assembler was +built). This is added only for non-release versions of gas. The specific +value probably better isn't checked for, just its defined-ness. + +@end itemize + @node Expressions @chapter Expressions --- a/gas/testsuite/gas/all/gas.exp +++ b/gas/testsuite/gas/all/gas.exp @@ -566,3 +566,39 @@ run_dump_test "multibyte1" run_dump_test "multibyte2" run_list_test "multibyte3" "--multibyte-handling=warn" run_list_test "multibyte3" "-f --multibyte-handling=warn" + +# ONLY_STANDARD_ESCAPES targets can't deal with the macro-argument-like +# expansion used in the test. +# EVAX has an extra line printed by objdump when there are no relocations, +# and doesn't appear to enter absolute symbols into the symbol table. +# HPPA has too many flavors, quite a few of which won't properly handle +# the tests. +# IA-64 doesn't like the # that the test probes for, as that's a suffix +# operator there. +# The TI C54x backend segfaults apparently because of the use of $, after +# having claimed over 90k times that it would have stopped substitution +# symbol recursion. +switch -glob $target_triplet { + alpha-*-*vms* { } + avr-*-* { } + *c54x*-*-* { } + cris*-*-* { } + hppa*-*-* { } + ia64-*-* { } + msp430*-*-* { } + z80-*-* { } + default { + run_dump_test "version" + # Non-ELF symbol tables may include section symbols. + # RL78 includes a special absolute symbol. + if { [is_elf_format] && ![istarget "rl78*-*-*"] } { + run_dump_test "version2" + } + # ECOFF/XCOFF don't look to (reliably) emit local absolute symbols. + if { ![is_xcoff_format] + && ![istarget "alpha-*-linux*ecoff*"] + && ![istarget "alpha-*-osf*"] } { + run_dump_test "version3" + } + } +} --- /dev/null +++ b/gas/testsuite/gas/all/version.d @@ -0,0 +1,9 @@ +#as: -vv -silent +#as: -v -v -silent +#objdump: -rsj .data +#name: pre-defined version symbol + +.*: +file format .* + +Contents of section .data: + 0+ [0-9a-f]*[1-9a-f][0-9a-f]* .* --- /dev/null +++ b/gas/testsuite/gas/all/version.s @@ -0,0 +1,6 @@ + .data + .irpc sep, ".@$?%&#_" + .ifdef "\sep\sep\()gas\sep\()version\sep\sep" + .dc.l "\sep\sep\()gas\sep\()version\sep\sep" + .endif + .endr --- /dev/null +++ b/gas/testsuite/gas/all/version2.d @@ -0,0 +1,5 @@ +#as: -vv -silent +#as: -v -v -silent +#nm: --quiet +#name: pre-defined version symbol (empty symbol table) +#source: version.s --- /dev/null +++ b/gas/testsuite/gas/all/version3.d @@ -0,0 +1,9 @@ +#as: -vvv -silent +#as: -v -v -v -silent +#nm: -f bsd +#name: pre-defined version symbol (non-empty symbol table) +#source: version.s + +#... +.* a ..gas.version.. +#pass From patchwork Mon Dec 9 09:22:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 102651 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0B7B3858D34 for ; Mon, 9 Dec 2024 09:26:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0B7B3858D34 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=FJn9MFAU X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id C7769385829B for ; Mon, 9 Dec 2024 09:22:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7769385829B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C7769385829B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733736137; cv=none; b=hNUNFgodYaA8AOsP9bEcz3mzYP3WrOlQ/aFo5zXhZOLr0kmJIAhQ2OAGMQaMEqx1XUy78lfYhNuiRD5x+MwG7JuxC1f0puImKb+IbUAQQKi98aC5veOf0tHRRGza1OIUTmORQHKYY0M7reGFq+K+GFfxnN1tpnG31PlE8gwp/lI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733736137; c=relaxed/simple; bh=KT8aV6sNrrX3vdZfVzZTqFWQJiX4cX5gHYbNmPLnnIs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=wxOgQGS2HJnNyP+Q3KRihwDVCnNZzeLz4/UeoxRycAwKPkWEQGrHgcneHZnjTiPvnoEjxLGVNwcrJfzB0WhEI50WVnnvyp0lJ2Lfbj7EW+xSGyI2EjLu7V5r8yg3xOSLGwtATgYj8svigY8W74+RU04shO4W+prITl20Q7xIAls= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7769385829B Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3862ca8e0bbso2094238f8f.0 for ; Mon, 09 Dec 2024 01:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1733736135; x=1734340935; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ZLaoY1KF4UTe1tqPFcMqvBtXj7Pk0TKEvEA/OmZg0IU=; b=FJn9MFAUxC0iX+VvuIx1lLHub7iHaAtX9SK9RNJ2YbzpazUDyqf3aYcuuB4uDTM50P A3bC97bbmeAawUqJxfYDSolEx/m96FlPMxLrrWX/SLF0cMHIqQnmrp16DW5tMLFVDhnm SbF1p41W15CHIURjIGKgT8xnr8wAPL68vAiVEoJeoCPI8TPvI6P1d7r/TqJ1WXZ6RZDs TxSLEM61jVFIlyACE+5wIX2VDqwWUt3BOaeV7q+rIDGezsdu8ophW1WYGZrK5cgt4ZQC XtsjVzCR6q7bjKwKy5g3AkbpYPqs4ttWCNi+5ntTv+6ZMedPkihQMI7pvY2tvYGxCa+K SPlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733736135; x=1734340935; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZLaoY1KF4UTe1tqPFcMqvBtXj7Pk0TKEvEA/OmZg0IU=; b=e3r+x4rd9ALfj9C0GO3H8t7oOnAaeOCkAriTnQSeiz+to/1uLzRk6XEwPj1L1tAUHr 8kYdyH2oIHe1tzaV44SBBqOOWZNvWiiHVprvbbUikdGeFUkSxwPcPW9IlSFgPyVW+kM/ aJSVlgDGg+SLoRqAR4JoDz44eQdJz3nowJt2kjU6m3WkGbs1MRjXb4/kLpL92wYRahla TRuq1vFEVpiP4hKbS6d6HlD6eOCv1OeZ83YOJzczKHEULofjYGwOfg4TG5NO+xgtrsT5 MihZs21QE39vgqqdVp+I24A+7ICvP9nJMpyDVC85NtekovbrvqPDwB7hiMaBpCsZJyBN 3EOA== X-Gm-Message-State: AOJu0Yz/U6sycEX84KV6U6BCHR7vgU2t9cw1tdkMxtdrLDPppKO4/1pr 0hNDMx43hbJHvAybQziw1EWfPOLUFOyg79NS04XQSs4kGPDHKatt8qMQw7prAcnGF5GS8m3ncpA = X-Gm-Gg: ASbGncunfnKmk7KKVrwFMC4zeo/R06Qzt5jENgOfxePklloiVmws/q/0dHVEWdhXR2O 46Twu2bO8jWmR5YFFJkPoL23qK2hpr28A4+ffmCGb10MSFcKxYEIjVul937bVYMtDwOa6gQlbpy WZ6pcX10pioejsWJlANI4r6I0NGq+ZT6YQzxfEAY2SkgA6ABfvvx32t0TqYms+E2uVIt5fWgcUJ iZuRHT0haPLYDkoWffN9bh92ZT5sRLay9klqZ7M4GpNEL0qAsP2u1q4kudPcgsw+Aenvzb8kb7y 9pNmZdzZVEXD8OymOI87BPtAE0x8SYp9Zgw= X-Google-Smtp-Source: AGHT+IGSnQbw61AF88BU1k5KamHVDwjClz8TVOfe/W4wG7SjkugYxZpsSgBH9mt4+E/3fBEgBN6s9A== X-Received: by 2002:a05:6000:1fa9:b0:385:fc00:f5e1 with SMTP id ffacd0b85a97d-3862b33e036mr8013098f8f.9.1733736135548; Mon, 09 Dec 2024 01:22:15 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2163543fbb2sm27894045ad.205.2024.12.09.01.22.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Dec 2024 01:22:15 -0800 (PST) Message-ID: Date: Mon, 9 Dec 2024 10:22:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH RFC 3/3] gas: introduce .errif and .warnif From: Jan Beulich To: Binutils References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: X-Spam-Status: No, score=-3022.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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~patchwork=sourceware.org@sourceware.org Rather than having people resort to indirect means to issue a certain kind of diagnostic conditionally upon an expression which can (or should) only be evaluated when all sections were sized and all symbols has their final values established, provide directives to directly achieve this. --- Should we save the (textual) expression, to quote it when emitting the diagnostic? NOTE: Depends on "aarch64: re-work PR gas/27217 fix again" (latched_dot_expression()), unless that would be re-worked such that deferred_expression() would need using here. --- a/gas/NEWS +++ b/gas/NEWS @@ -1,5 +1,8 @@ -*- text -*- +* Add .errif and .warnif directives, permitting user-controlled diagnostics + with conditionals that are evaluated only at the end of assembly. + * Add support for the x86 Intel MSR_IMM instructions. * Add support for the x86 Zhaoxin GMI instructions. --- a/gas/doc/as.texi +++ b/gas/doc/as.texi @@ -4577,6 +4577,7 @@ Some machine configurations provide addi * Equiv:: @code{.equiv @var{symbol}, @var{expression}} * Eqv:: @code{.eqv @var{symbol}, @var{expression}} * Err:: @code{.err} +* Errif:: @code{.errif @var{expression}} * Error:: @code{.error @var{string}} * Exitm:: @code{.exitm} * Extern:: @code{.extern} @@ -4709,6 +4710,7 @@ Some machine configurations provide addi * VTableInherit:: @code{.vtable_inherit @var{child}, @var{parent}} @end ifset +* Warnif:: @code{.warnif @var{expression}} * Warning:: @code{.warning @var{string}} * Weak:: @code{.weak @var{names}} * Weakref:: @code{.weakref @var{alias}, @var{symbol}} @@ -5529,6 +5531,13 @@ If @command{@value{AS}} assembles a @cod message and, unless the @option{-Z} option was used, it will not generate an object file. This can be used to signal an error in conditionally compiled code. +@node Errif +@section @code{.errif "@var{expression}"} +@cindex errif directive + +Record @var{expression} for evaluation at the end of assembly. Raise an error +if the expression evaluates to non-zero. + @node Error @section @code{.error "@var{string}"} @cindex error directive @@ -7714,6 +7723,13 @@ parent whose addend is the value of the parent name of @code{0} is treated as referring to the @code{*ABS*} section. @end ifset +@node Warnif +@section @code{.warnif "@var{expression}"} +@cindex errif directive + +Record @var{expression} for evaluation at the end of assembly. Raise a +warning if the expression evaluates to non-zero. + @node Warning @section @code{.warning "@var{string}"} @cindex warning directive --- a/gas/read.c +++ b/gas/read.c @@ -257,6 +257,7 @@ static void do_s_func (int end_p, const static void s_align (int, int); static void s_altmacro (int); static void s_bad_end (int); +static void s_errwarn_if (int); static void s_reloc (int); static int hex_float (int, char *); static segT get_known_segmented_expression (expressionS * expP); @@ -415,6 +416,7 @@ static const pseudo_typeS potable[] = { {"equiv", s_set, 1}, {"eqv", s_set, -1}, {"err", s_err, 0}, + {"errif", s_errwarn_if, 1}, {"error", s_errwarn, 1}, {"exitm", s_mexit, 0}, /* extend */ @@ -529,6 +531,7 @@ static const pseudo_typeS potable[] = { {"xdef", s_globl, 0}, {"xref", s_ignore, 0}, {"xstabs", s_xstab, 's'}, + {"warnif", s_errwarn_if, 0}, {"warning", s_errwarn, 0}, {"weakref", s_weakref, 0}, {"word", cons, 2}, @@ -2236,6 +2239,62 @@ s_errwarn (int err) demand_empty_rest_of_line (); } +/* Handle the .errif and .warnif pseudo-ops. */ + +static struct deferred_diag { + struct deferred_diag *next; + const char *file; + unsigned int lineno; + bool err; + expressionS exp; +} *deferred_diags, *last_deferred_diag; + +static void +s_errwarn_if (int err) +{ + struct deferred_diag *diag = XNEW (struct deferred_diag); + int errcnt = had_errors (); + + latched_dot_expression (&diag->exp); + if (errcnt != had_errors ()) + { + ignore_rest_of_line (); + return; + } + + diag->err = err; + diag->file = as_where (&diag->lineno); + diag->next = NULL; + if ( deferred_diags == NULL ) + deferred_diags = diag; + else + last_deferred_diag->next = diag; + last_deferred_diag = diag; + + demand_empty_rest_of_line (); +} + +void +evaluate_deferred_diags (void) +{ + struct deferred_diag *diag; + + for (diag = deferred_diags; diag != NULL; diag = diag->next) + { + if (!resolve_expression (&diag->exp) || diag->exp.X_op != O_constant) + as_warn_where (diag->file, diag->lineno, + _("expression does not evaluate to a constant")); + else if (diag->exp.X_add_number == 0) + continue; + else if (diag->err) + as_bad_where (diag->file, diag->lineno, + _(".errif expression evaluates to true")); + else + as_warn_where (diag->file, diag->lineno, + _(".warnif expression evaluates to true")); + } +} + /* Handle the MRI fail pseudo-op. */ void --- a/gas/read.h +++ b/gas/read.h @@ -162,6 +162,7 @@ extern symbolS *s_comm_internal (int, sy extern symbolS *s_lcomm_internal (int, symbolS *, addressT); extern void temp_ilp (char *); extern void restore_ilp (void); +extern void evaluate_deferred_diags (void); extern void s_file_string (char *); extern void s_abort (int) ATTRIBUTE_NORETURN; --- a/gas/write.c +++ b/gas/write.c @@ -2329,6 +2329,8 @@ write_object_file (void) resolve_local_symbol_values (); resolve_reloc_expr_symbols (); + evaluate_deferred_diags (); + #ifdef OBJ_ELF if (IS_ELF) maybe_generate_build_notes (); --- /dev/null +++ b/gas/testsuite/gas/all/cond-diag.l @@ -0,0 +1,6 @@ +# This should match the output of gas cond-diag.s. +.*: Assembler messages: +.*:1: Error: non-constant .* +.*:6: Error: backward ref .* +.*:7: Warning: \.warning .* +.*:4: Warning: \.warnif .* --- /dev/null +++ b/gas/testsuite/gas/all/cond-diag.s @@ -0,0 +1,12 @@ + .if end - start > 16 + .warning + .endif + .warnif end - start < 16 + .errif end - start >= 16 + .warnif 1b + .warning + + .data +start: + .uleb128 end - start +end: --- a/gas/testsuite/gas/all/gas.exp +++ b/gas/testsuite/gas/all/gas.exp @@ -488,6 +488,19 @@ switch -glob $target_triplet { } } +# This test uses a local label, which some targets don't support. +# MeP can't deal with forward ref labels in .uleb128. +switch -glob $target_triplet { + *c54x*-*-* { } + hppa*-*-* { } + ia64-*-*vms* { } + mep-*-* { } + sh-*-pe* { } + default { + run_list_test "cond-diag" + } +} + gas_test_error "weakref2.s" "" "e: would close weakref loop: e => a => b => c => d => e" gas_test_error "weakref3.s" "" "a: would close weakref loop: a => b => c => d => e => a" gas_test_error "weakref4.s" "" "is already defined"