From 264a103610e3ee86b27b8cbb0e4ec81cd654d980 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <tcc.dev@web.de>
Date: Tue, 6 Apr 2010 00:33:15 +0200
Subject: [PATCH] tccgen: Detect (but ignore) function redirection

tcc is now able to parse <stdio.h> from gcc, when
__GNUC__ is also defined

--
By by ... Detlef
---
 tccgen.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/tccgen.c b/tccgen.c
index f1fe1ee3..0864ffc7 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -5419,10 +5419,39 @@ ST_FUNC void decl(int l)
                     sym = sym_push(v, &type, INT_ATTR(&ad), 0);
                     sym->type.t |= VT_TYPEDEF;
                 } else if ((type.t & VT_BTYPE) == VT_FUNC) {
+                    Sym *fn;
                     /* external function definition */
                     /* specific case for func_call attribute */
                     type.ref->r = INT_ATTR(&ad);
-                    external_sym(v, &type, 0);
+                    fn = external_sym(v, &type, 0);
+
+                    if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) {
+                        char target[256];
+
+                        *target = 0;
+                        next();
+                        skip('(');
+                        /* Part 1: __USER_LABEL_PREFIX__ (user defined) */
+                        if (tok == TOK_STR)
+                            pstrcat(target, sizeof(target), tokc.cstr->data);
+                        else
+                            pstrcat(target, sizeof(target), get_tok_str(tok, NULL));
+
+                        next();
+                        /* Part 2: api name */
+                        if (tok == TOK_STR)
+                            pstrcat(target, sizeof(target), tokc.cstr->data);
+                        else
+                            pstrcat(target, sizeof(target), get_tok_str(tok, NULL));
+
+                        next();
+                        skip(')');
+                        if (tcc_state->warn_unsupported)
+                            warning("ignoring redirection from %s to %s\n", get_tok_str(v, NULL), target);
+
+                        if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)
+                            parse_attribute((AttributeDef *) &fn->type.ref->r);
+                    }
                 } else {
                     /* not lvalue if array */
                     r = 0;