“ __builtin_va_list”的效果如何?实施? [英] How is "__builtin_va_list" implemented?

查看:428
本文介绍了“ __builtin_va_list”的效果如何?实施?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想深入研究macOS上C语言中 printf函数的实现。 printf使用< stdarg.h> 头文件。我打开< stdarg.h> 文件,发现 va_list 只是一个宏。



因此,我真的很好奇 __ builtin_va_list 是如何实现的?我知道它是特定于编译器的。在哪里可以找到 __ builtin_va_list 的定义?我应该下载clang编译器的源代码吗?

解决方案


所以,我真的很好奇__builtin_va_list的实现方式?


__ builtin_va_list 内部中实现 GCC 编译器(或 Clang / LLVM 一个)。因此,您应该研究GCC编译器源代码以了解详细信息。



查看 gcc / builtins.def & gcc / builtins.c 了解更多。



我对 Clang 不太熟悉实现相同的内置函数。



但GCC和Clang是开源或免费软件。它们是复杂的野兽(每行数百万行代码),因此您可能需要花大量的时间才能理解它们。



请注意 ABI 对您的编译器很重要。有关更多详细信息,请参见 X86 psABI 。 p>

BTW, Grady Player 评论:


为每个令牌从栈中取出正确的字节数...


不幸的是,今天它要复杂得多。在当前处理器和ABI上,调用约定确实使用处理器寄存器传递一些参数(而罪魁祸首是细节)。


我应该下载clang编译器的源代码吗?


是的,您还需要分配几年的工作来了解详细信息。



几年前,我确实编写了一些教程幻灯片和指向有关GCC实施的外部文档的链接,请参见我的 GCC MELT文档页(有点烂)。


I want to delve into the implementation of function "printf" in C on macOS. "printf" uses the <stdarg.h> header file. I open the <stdarg.h> file and find that va_list is just a macro.

So, I am really curious about how the __builtin_va_list is implemented? I know it is compiler-specific. Where can I find the definition of the __builtin_va_list? Should I download the source code of clang compiler?

解决方案

So, I am really curious about how the __builtin_va_list is implemented?

__builtin_va_list is implemented inside the GCC compiler (or the Clang/LLVM one). So you should study the GCC compiler source code to understand details.

Look into gcc/builtins.def & gcc/builtins.c for more.

I am less familiar with Clang, which implements the same builtin.

But both GCC & Clang are open source or free software. They are complex beasts (several millions lines of code each), so you could need years of work to understand them.

Be aware that the ABI of your compiler matters. Look for example into X86 psABI for more details.

BTW, Grady Player commented:

Pops the correct number of bytes off of the stack for each of those tokens...

Unfortunately, today it is much more complex than that. On current processors and ABIs the calling conventions do use processor registers to pass some arguments (and the evil is in the details).

Should I download the source code of clang compiler?

Yes, and you also need to allocate several years of work to understand the details.

A few years ago, I did write some tutorial slides and links to external documentation regarding GCC implementation, see my GCC MELT documentation page (a bit rotten).

这篇关于“ __builtin_va_list”的效果如何?实施?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆