From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id BAB3F384640E for ; Thu, 6 Aug 2020 13:56:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BAB3F384640E Received: by mail-pl1-x634.google.com with SMTP id z20so6816689plo.6 for ; Thu, 06 Aug 2020 06:56:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Y2GpdYP0KM6sy502nA/v4T7uVOM9Fi+u9NjGysJSSbI=; b=N8/VAdUZ9Db1Nkk8Km86yepiK2A0e643eNzn6FbWQjP8I5LzX3b8NxKv+EQv2ZDIsj Oxh+RBNUF67VeuTbM9YoXzGZoONUk6MVOOtYB/L/fN+qFhpdtbkqElVP1uEW7n+8YZtD DkvT+ok1pb1icmX994mxULcuTNsk2YIr3WlNeQc2rILqsFzsNn6mq1rTqLYgJHXXefJQ nJfVGHmvnNdaZ8/LlXKf130On4s5VIHMrNEE4dRaNVpQVqMjbEW9z1B7Hmw+96Fs2hB8 S6htICYmI+f6N3hq5Lw+Pbfs91BKodnKi4dv01OpJQ1ynJZYhHvwAEMQeRx0bS40xrsQ mBCQ== X-Gm-Message-State: AOAM532H37trVTE1EB3wMkoO/mVm16qK9Y8qkhiLcF6ScUR6Yt04Aj6d SqwL6ihWq6mTEcAajiraCQRc6j4uAbY= X-Google-Smtp-Source: ABdhPJxjF/HWIPiuHq/LOFiTQF/7UH3Sc3AyxvjtWM9DEKJV0JaXB5IbwuDx/H74871cQ/vGQiKXwQ== X-Received: by 2002:a17:902:bd84:: with SMTP id q4mr8180189pls.29.1596722166882; Thu, 06 Aug 2020 06:56:06 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:e8de:b381:7174:6b5d]) by smtp.gmail.com with ESMTPSA id e124sm8219751pfe.176.2020.08.06.06.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 06:56:05 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 306E4880EE; Thu, 6 Aug 2020 23:26:02 +0930 (ACST) Date: Thu, 6 Aug 2020 23:26:02 +0930 From: Alan Modra To: Alex Coplan Cc: binutils@sourceware.org Subject: Re: [PATCH] gas: Fix internal error on long local labels Message-ID: <20200806135602.GG15695@bubble.grove.modra.org> References: <20200805135105.vtbqtd5lqcdrqzkm@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200805135105.vtbqtd5lqcdrqzkm@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-9.5 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Aug 2020 13:56:09 -0000 On Wed, Aug 05, 2020 at 02:51:05PM +0100, Alex Coplan wrote: > * read.c (read_a_source_file): Use long for local labels, detect > overflow and raise an error for overly-long labels. > * testsuite/gas/all/gas.exp: Add local-label-overflow test. > * testsuite/gas/all/local-label-overflow.d: New test. > * testsuite/gas/all/local-label-overflow.l: Error output. > * testsuite/gas/all/local-label-overflow.s: Input. OK, but fix the following nits please. > @@ -1212,10 +1214,21 @@ read_a_source_file (const char *name) > /* Read the whole number. */ > while (ISDIGIT (*input_line_pointer)) > { > - temp = (temp * 10) + *input_line_pointer - '0'; > + const char digit = *input_line_pointer - '0'; "long digit" is probably better, since you're doing long arithmetic with "digit". > + if (temp > ((LONG_MAX - digit) / 10)) Unnecessary parens. > + { > + as_bad (_("local label too large near %s"), backup); > + temp = -1; > + break; > + } > + temp = (temp * 10) + digit; Here too. (Yes, they were in the original source.) > ++input_line_pointer; > } > > + /* Overflow: stop processing the label. */ > + if (temp == -1) > + continue; > + > if (LOCAL_LABELS_DOLLAR > && *input_line_pointer == '$' > && *(input_line_pointer + 1) == ':') > @@ -1224,7 +1237,7 @@ read_a_source_file (const char *name) > > if (dollar_label_defined (temp)) > { > - as_fatal (_("label \"%d$\" redefined"), temp); > + as_fatal (_("label \"%ld$\" redefined"), temp); > } > > define_dollar_label (temp); > diff --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp > index 5496d0bf7a7..a0158f38dde 100644 > --- a/gas/testsuite/gas/all/gas.exp > +++ b/gas/testsuite/gas/all/gas.exp > @@ -102,6 +102,7 @@ if { ![istarget "bfin-*-*"] } then { > } > gas_test_error "assign-bad.s" "" "== assignment for symbol already set" > run_dump_test assign-bad-recursive > +run_dump_test local-label-overflow > > run_dump_test simple-forward > run_dump_test forward > diff --git a/gas/testsuite/gas/all/local-label-overflow.d b/gas/testsuite/gas/all/local-label-overflow.d > new file mode 100644 > index 00000000000..1786a45743a > --- /dev/null > +++ b/gas/testsuite/gas/all/local-label-overflow.d > @@ -0,0 +1,6 @@ > +#source: local-label-overflow.s > +#error_output: local-label-overflow.l > +#skip: hppa*-*-* > +#skip: ia64-*-vms > +#skip: mmix-*-* > +#skip: sh-*-pe Use #notarget: hppa*-*-* ia64-*-vms mmix-*-* sh-*-pe instead of #skip. See binutils-common.exp for description of skip. -- Alan Modra Australia Development Lab, IBM