tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] __builtin_return_address(): any tips?


From: Edmund Grimley Evans
Subject: Re: [Tinycc-devel] __builtin_return_address(): any tips?
Date: Wed, 4 Mar 2015 14:19:46 +0000

Sergey Korshunoff <address@hidden>:

> A current tcc (from git) can compile a linux kernel 2.4.26. All
> patches are commited.

For which architectures can tcc compile the kernel? How is assembler
source handled?

> A kernel boots fine. But a question is: how to implement a
> __builtin_return_address() ?
> Any tips?

It's very similar to __builtin_frame_address, which is already
implemented.

The patch below seems to do the job on arm64, but it assumes that the
return address is just above the frame address on the stack, which
might not be true on other architectures.

Do you also need __builtin_extract_return_addr and
__builtin_frob_return_address? They are probably the identity function
on all of TCC's target architectures.

Edmund


diff --git a/tccgen.c b/tccgen.c
index 64033b2..bcb7295 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -3874,7 +3874,9 @@ ST_FUNC void unary(void)
         }
         break;
     case TOK_builtin_frame_address:
+    case TOK_builtin_return_address:
         {
+            int tok1 = tok;
             int level;
             CType type;
             next();
@@ -3892,6 +3894,12 @@ ST_FUNC void unary(void)
                 mk_pointer(&vtop->type);
                 indir();                    /* -> parent frame */
             }
+            if (tok1 == TOK_builtin_return_address) {
+                vpushi(PTR_SIZE);
+                gen_op('+');
+                mk_pointer(&vtop->type);
+                indir();
+            }
         }
         break;
 #ifdef TCC_TARGET_X86_64
diff --git a/tcctok.h b/tcctok.h
index 64d1288..2a4abc6 100644
--- a/tcctok.h
+++ b/tcctok.h
@@ -130,6 +130,7 @@
      DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
      DEF(TOK_builtin_constant_p, "__builtin_constant_p")
      DEF(TOK_builtin_frame_address, "__builtin_frame_address")
+     DEF(TOK_builtin_return_address, "__builtin_return_address")
 #ifdef TCC_TARGET_X86_64
 #ifdef TCC_TARGET_PE
      DEF(TOK_builtin_va_start, "__builtin_va_start")



reply via email to

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