From: Benjamin Purcell <benjapurcell@gmail.com>
To: 9front@9front.org
Subject: Re: [9front] Patch: Assemblers do not handle minimum vlong value correctly.
Date: Wed, 22 Mar 2017 00:05:43 -0500 [thread overview]
Message-ID: <CAAsuYKeisgaYWd8gqmdciBtk28G4Nh0UacvqAa5Pthf-ur8Fbg@mail.gmail.com> (raw)
In-Reply-To: <20170321214843.03541405e369f0c84be4a3f1@eigenstate.org>
Thank you, committed.
-spew
On Tue, Mar 21, 2017 at 11:48 PM, Ori Bernstein <ori@eigenstate.org> wrote:
> The Plan 9 assemblers use strtoll to parse the integer literals
> in their input. It turns out that this is almost correct, but
> VLONG_MIN is clamped. This patch changes to use strtoull
> in order to allow the full range of integers.
>
> Below is a program that demosntrates the problem:
>
> term% cat test.s
> GLOBL L2<>+0(SB),$8
> DATA L2<>+0(SB)/8,$-9223372036854775808
>
> TEXT main+0(SB),2,$0
> MOVQ L2<>+0(SB),AX
> RET
>
> term% 6a test.s
> term% 6l test.6 /amd64/lib/libc.a
> term% acid 6.out
> 6.out:amd64 plan 9 executable
> /sys/lib/acid/port
> /sys/lib/acid/amd64
> acid: new()
> 33489: overflow _main SUBQ $0x90,SP
> 33489: breakpoint main+0x8 RET
> acid: *L2
> 0x8000000000000001
> acid: -9223372036854775808
> 0x8000000000000000
>
> And the patch:
>
>
> diff -r a01d0802d023 sys/src/cmd/cc/lexbody
> --- a/sys/src/cmd/cc/lexbody Mon Mar 20 19:15:40 2017 +0100
> +++ b/sys/src/cmd/cc/lexbody Tue Mar 21 21:45:44 2017 -0700
> @@ -343,10 +343,9 @@
> goto casee;
> *cp = 0;
> if(sizeof(yylval.lval) == sizeof(vlong))
> - yylval.lval = strtoll(symb, nil, 10);
> + yylval.lval = strtoull(symb, nil, 10);
> else
> - yylval.lval = strtol(symb, nil, 10);
> -
> + yylval.lval = strtoul(symb, nil, 10);
> ncu:
> while(c == 'U' || c == 'u' || c == 'l' || c == 'L')
> c = GETC();
>
> --
> Ori Bernstein
prev parent reply other threads:[~2017-03-22 5:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-22 4:48 Ori Bernstein
2017-03-22 5:05 ` Benjamin Purcell [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAAsuYKeisgaYWd8gqmdciBtk28G4Nh0UacvqAa5Pthf-ur8Fbg@mail.gmail.com \
--to=benjapurcell@gmail.com \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).