[Top][All Lists]

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

Re: [Tinycc-devel] Unify C and asm symbols

From: grischka
Subject: Re: [Tinycc-devel] Unify C and asm symbols
Date: Sun, 10 Dec 2017 18:56:58 +0100
User-agent: Thunderbird (Windows/20090812)

Michael Matz wrote:
I wasn't a big fan of the reloc rewriting, and when thinking about the above multi-file problems I had a more linker centric approach in mind.

So what I came up with is below: doing a proper regular-symbol resolution step: basically similar to what's done while reading in .o files. Advantages: no rewriting of reloc entries (which is expensive in your patch as you iterate all relocs for each into-global change), only needing to rebuild the hash table once or twice per output file (or -run), the undef globalization can be folded into it and it's overall a bit shorter (30 lines added) :)

Not too bad ;)

May I suggest however to keep doing the asm-label undef->non-static
conversion on the sym-stack (per file) level, because for one it is
more obvious at what we're doing and why, and also because otherwise
is is not correct for static C symbols, which must be defined in the
same file or are errors otherwise.

This is on top of your last two patches (i.e. without the static-asm-sym patch). If you don't beat me to it I think I'll push your two and this one somewhen tomorrow; together they (and even just your two) are a clear progression (and all three together even source line number neutral! ;) )

What do you think?

You could push first the combined final result of the asm related
patches, (possibly including the suggestion from above), as one
single commit (under your authorship).

I'd then push the "type redefinition check" patch, including a minor
fix (as attached) that is meant to make sure that
- a transition global->static can never happen
- a transition static->global can happen, but only for symbols
  that (initially) come from asm.

I'd then make one more commit with other small fixes, and then I'd
pack the release, say next Sun (17.12.)

How does that sound?

--- grischka


commit 13a9037e137c1f75bb1023fcc9d0226591a5ba0f
Author: grischka <grischka>
Date:   Sun Dec 10 10:25:33 2017 +0100


diff --git a/tccgen.c b/tccgen.c
index 4159b9e..47098c2 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -863,9 +863,12 @@ static void patch_type(Sym *sym, CType *type)
     if (IS_ASM_SYM(sym)) {
-        sym->type = *type;
+        /* stay static if both are static */
+        sym->type.t = type->t & (sym->type.t | ~VT_STATIC);
+        sym->type.ref = type->ref;
+    }
-    } else if (!is_compatible_types(&sym->type, type)) {
+    if (!is_compatible_types(&sym->type, type)) {
         tcc_error("incompatible types for redefinition of '%s'",
                   get_tok_str(sym->v, NULL));
@@ -877,10 +880,11 @@ static void patch_type(Sym *sym, CType *type)
                 get_tok_str(sym->v, NULL));
         if (0 == (type->t & VT_EXTERN)) {
-            /* put complete type */
-            sym->type = *type;
-            /* use static from prototype */
-            sym->type.t |= static_proto;
+            /* put complete type, use static from prototype */
+            sym->type.t = (type->t & ~VT_STATIC) | static_proto;
+            if (type->t & VT_INLINE)
+                sym->type.t = type->t;
+            sym->type.ref = type->ref;
     } else {

reply via email to

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