9front - general discussion about 9front
 help / color / mirror / Atom feed
* Patch: Assemblers do not handle minimum vlong value correctly.
@ 2017-03-22  4:48 Ori Bernstein
  2017-03-22  5:05 ` [9front] " Benjamin Purcell
  0 siblings, 1 reply; 2+ messages in thread
From: Ori Bernstein @ 2017-03-22  4:48 UTC (permalink / raw)
  To: 9front

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] Patch: Assemblers do not handle minimum vlong value correctly.
  2017-03-22  4:48 Patch: Assemblers do not handle minimum vlong value correctly Ori Bernstein
@ 2017-03-22  5:05 ` Benjamin Purcell
  0 siblings, 0 replies; 2+ messages in thread
From: Benjamin Purcell @ 2017-03-22  5:05 UTC (permalink / raw)
  To: 9front

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-22  5:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22  4:48 Patch: Assemblers do not handle minimum vlong value correctly Ori Bernstein
2017-03-22  5:05 ` [9front] " Benjamin Purcell

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).