9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Ori Bernstein <ori@eigenstate.org>
To: 9front@9front.org
Subject: Patch: Assemblers do not handle minimum vlong value correctly.
Date: Tue, 21 Mar 2017 21:48:43 -0700	[thread overview]
Message-ID: <20170321214843.03541405e369f0c84be4a3f1@eigenstate.org> (raw)

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


             reply	other threads:[~2017-03-22  4:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22  4:48 Ori Bernstein [this message]
2017-03-22  5:05 ` [9front] " Benjamin Purcell

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=20170321214843.03541405e369f0c84be4a3f1@eigenstate.org \
    --to=ori@eigenstate.org \
    --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).