Search code examples
gcccompiler-constructionelf

What's the pass in GCC handles const strings?


What's the pass name in GCC that handles building string array into .rodata section? Would like to write a plugin to intercept also strings in source code, I know there're a bunch of tools in binutils can achieve the same goal, but what if we want to do some postprocessing, for example verify words.


Solution

  • Read-only data section, also known as .rodata, generates after the last step of all rtl passes. You can see how it works in file varasm.c, which lays in /gcc folder. Look at section

    section *
    default_function_rodata_section (tree decl) 
    

    and below. You can also easily add some functions to intercept data into asm file or some other output file here or write an external function.

    varasm.c file handles the generation of all the assembler code except the instructions of a function. This includes declarations of variables and their initial values.