Compiling an object file from a gcc intermediate file

Using the -fdump-tree - * flag, you can upload an intermediate format file during compilation of the source code file. My question is whether this intermediate file can be used as input in gcc to get the final object file.

I ask this because I want to add some code to the intermediate gimple file (obtained using the -fdump-tree-gimple flag ), Of course, I can use hooks and add my own pass, but so far I do not want to reach that level difficulties. I just want to provide gcc with my modified intermediate file so that it can start compiling from there and give me the final object file. Any ideas how to achieve this?

+4
source share
2 answers

GIMPLE was a binary internal format that is difficult to completely reset and load correctly. Compared to LLVM, LLVM IR was designed to be awkward and reloaded into a regular file (the text and binary format of such files are fully convertible from one to another). You can run Clang to emit LLVMIR, and then run opt with some optimizations and then with others, and there will be files between the phases of the LBVM IR bitcode. And then you can start coding from the IR bit code to your own code (even theoretically, in the wrong platform, see PNaCl Project).

There are several projects to reset / reload the internal GCC view. I know that such a project was created to integrate gcc with a commercial compiler tool. An author cannot simply associate commercial code with gcc because gcc is VIRAL (it will infect any associated code with anti-commercial GPLs). Thus, the author wrote the GPL dumper / loader GIMPLE in some external (xml) format; the proprietary tool was able to read and translate this XML into another XML of the same format, and then was reloaded with the GPL tool.

In the new version of gcc, you have the opportunity to write a plugin that is VIRAL (23.2.1) in terms of the GPL. The plugin will work with representing the program in memory and there will be no problems loading / reloading GIMPLE via an external file. There are some plugins that can be configured / can be used by a user-supplied program, for example, MELT (Lisp) and GCC Python (Python). Some list of gcc plugins is

+3
source

There is no built-in tool to translate the text of the GIMPLE representation back to the original internal GIMPLE representation.

You will need to use a user interface (such as the one offered by GIMPLE FE ) in order to make sense to reset GIMPLE.

+1
source

Source: https://habr.com/ru/post/1394287/


All Articles