tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays).


From: Rob Landley
Subject: Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays).
Date: Wed, 3 Oct 2007 02:12:27 -0500
User-agent: KMail/1.9.6

On Wednesday 03 October 2007 12:10:17 am Antti-Juhani Kaijanaho wrote:
> On Tue, Oct 02, 2007 at 06:26:58PM -0500, Rob Landley wrote:
> > Confirmed that gcc makes sizeof() a runtime function in this case:
> >
> > #include <stdio.h>
> >
> > int main(int argc, char *argv[])
> > {
> >   int walrus[atoi(argv[1])];
> >   printf("%d\n", sizeof(walrus));
> >   return 0;
> > }
> >
> > Running "./a.out 42" produced 168.
> >
> > Oh yeah, that's gonna be fun...
>
> As far as I can tell, it's supposed to be implemented as the equivalent of:
>
>   size_t walrus_sizeof = atoi(argv[1]);
>   int walrus[walrus_sizeof];
>   printf("%d\n", walrus_sizeof);
>   return 0;
>
> Obviously, walrus_sizeof should not actually be named in such a way but
> to be a fresh compiler-generated name.

A hidden internal symbol.  Right, that's doable.

For right now, I just want to implement enough to make the binutils build 
happy, and worry about the corner cases as I hit software that uses them.  
Considering that this is one of the blocking issues for building an 
unmodified Linux kernel, I suspect there are more corner cases to come, but 
for now...

Thanks for the analysis.  Now I have to figure out more existing tcc 
infrastructure...

It wouldn't be so bad if there were more comments, and if they weren't so...  
Well...  Example.

> /* Parse a type declaration (except basic type), and return the type
>    in 'type'. 'td' is a bitmask indicating which kind of type decl is
>    expected. 'type' should contain the basic type. 'ad' is the
>    attribute definition of the basic type. It can be modified by
>    type_decl().
>  */
> static void type_decl(CType *type, AttributeDef *ad, int *v, int td)

It can be modified?  Which it?  type?  ad?  Both?  What are the side effects?  
(I notice that this calls stuff that pushes stuff onto the symbol stack, but 
the comment just mentions the return value...)  Yeah, I think I've figured it 
out now, but the comment was surprisingly little help...

Rob

P.S.  I'm still boggling you can do "int a[42], b(char *c);"  But apparently, 
yes you can.  Unfortunately, in tcc you can _also_ do:
  int blah(char a)(char b);
And it happily takes it.  (I note that gcc has a specific error for this.  Of 
course gcc has a specific error for everything.)

Sigh.  So...  many... corner... cases...!
-- 
"One of my most productive days was throwing away 1000 lines of code."
  - Ken Thompson.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]