从gcc的中间文件编译目标文件 [英] Compiling object file from an intermediate file of gcc

查看:435
本文介绍了从gcc的中间文件编译目标文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用 -fdump-tree - * 标志,可以在编译源代码文件期间转储一些中间格式文件。我的问题是如果可以使用该中间文件作为输入到gcc获取最终的目标文件。

By using the -fdump-tree-* flag , one can dump some intermediate format file during compilation of a source code file. My question is if one can use that intermediate file as an input to gcc to get the final object file.

我问这个问题,因为我想向 gimple 的中间文件添加一些代码(使用 -fdump-tree-gimple )格式。当然我可以使用钩子和添加自己的传球,但我不想达到这种水平的复杂性。我只想给gcc修改中间文件,所以它可以从那里开始编译,并给我最终的目标文件。任何想法如何实现这一点?

I'm asking this because I want to add some code to the intermediate file of the gimple (obtained by using the flag -fdump-tree-gimple) format. Sure I can use hooks and add my own pass, but I don't want to get to that level of complexity yet. I just want to give gcc my modified intermediate file, so it can start its compilation from there and give me the final object file. Any ideas how to achieve this?

推荐答案

GIMPLE是一个二进制内部格式,难以完全转储,与LLVM比较,LLVM IR被设计为可转储的并可重新加载到通常的文件中(这种文件的文本和二进制格式可以从每个文件完全转换为其他文件)。您可以运行Clang fronted以发出LLVMIR,然后启动 opt 程序与一些优化,然后与其他,并将在相之间有LLVM IR位码文件。然后你可以从IR位码开始代码生成到本地代码(甚至在理论上,进入不同的平台,参见PNaCl项目)。

GIMPLE was a binary internal format which is hard to dump fully and reload back correctly. Comparing with LLVM, LLVM IR was designed to be dumpable and reloadable into usual file (text and binary format of such files are fully-convertible from each to other). You can run Clang fronted to emit LLVMIR, then start opt program with some optimizations, then with other, and there will be LLVM IR bitcode files between phases. And then you can start codegeneration from IR bitcode into native code (even, in theory, into not the same platform, see PNaCl project).

有一些倾销项目/重新加载GCC的内部表示。我知道这样的项目是创建集成gcc与商业编译工具。作者不能只是链接商业代码与gcc,因为gcc是VIRAL(它将感染任何链接的代码与反商业GPL)。因此,作者将GIMPLE的GPL转储器/加载器写入一些外部(xml)格式;专有工具能够读取并将此XML翻译为相同格式的其他XML,然后使用GPL工具重新加载。

There are some projects of dumping/reloading internal representation of GCC. I know such project was created to integrate gcc with commercial compiler tool. The author can't just link commercial code with gcc, because gcc is VIRAL (it will infect any linked code with anti-commercial GPL). So, author wrote a GPL dumper/loader of GIMPLE to some external (xml) format; the proprietary tool was able to read and translate this XML into other XML of the same format and then it was reloaded back with GPL tool.

在新版本的gcc中,编写一个插件,其中是VIRAL(23.2.1)的GPL。插件将操作在程序的内存中表示,将没有通过外部文件转储/重新加载GIMPLE的问题。
有一些插件可以配置/可以使用用户提供的程序,例如MELT(Lisp)和GCC Python(Python)。 一些gcc插件列表

In newer gcc you have an option of writing a plugin, which is VIRAL (23.2.1) in terms of GPL. Plugin will operate on in-memory representation of program and there will be no problem of dumping/reloading GIMPLE via external file. There are some plugins which may be configured/may use user-supplied program, e.g MELT (Lisp) and GCC Python (Python). Some list of gcc plugins is there

这篇关于从gcc的中间文件编译目标文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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