top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Inserting named labels through a GCC plugin

+1 vote
292 views

I'm writing a gcc plugin to find out target basic blocks to branch instructions, and need to match instructions and basic blocks with compiled binaries, so I decided to explicitly annotate all the branch
instructions and basic blocks with named labels, then from the compiler plugin I assign named labels to branch instructions and basic blocks, and from symbol table I can get offset to these instructions
and basic blocks. Is this the right way to do it, or I shouldn't do this task in compiling phase?

When I was trying with this method, I wrote a plugin with some code like this:

unsigned int
first_rtl_exec(void)
{
 rtx insn, bb_start, bb_end;
 basic_block bb;
 FOR_EACH_BB(bb)
 {
 bb_start = gen_label_rtx();
 LABEL_NAME(bb_start) = "BB Start";
 LABEL_NUSES(bb_start) = 1;
 bb_end = gen_label_rtx();
 LABEL_NAME(bb_end) = "BB End";
 LABEL_NUSES(bb_end) = 1;

 emit_label_before(bb_start, BB_HEAD(bb));
 emit_label_after(bb_end, BB_END(bb));
 }

 return 0;
}

I insert this pass before final pass. But when compiling C program with this plugin, I got error:

foo.c:7:1: internal compiler error: in final, at final.c:1958
 }
 ^

It seems this is not the correct way to insert labels. Am I using emit_label_* in a wrong way, at wrong time, or I'm totally in the wrong direction?

posted Jun 8, 2013 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
0 votes

is it possible to add a private extension to the core language (C/C++) by writing a gcc plugin?

The extension in mind is something like this

[variable_definitions;]

Later I want this be possible also inside statement headers, for example

for ([double d = 1.0; bool f = false;] size_t i = 0; i < vec.size(); ++i)
 ...

The scope of the so-defined variables shall be the same scope they are in, ie. in the for-loop case just the scope of the for-loop itself, much like the case with i.

+3 votes

I've been using the profiling tool valgrind for a while now. It requires an executable to run, i.e.

$ valgrind ./a.out

I want to use it on a dynamically linked GCC plugin, and list the time taken and the number of calls by each function used in the plugin. I am running the GCC plugin as follows:

 $ gcc -fplugin=./plugin.so myfile.c

When I run the following command, valgrind reports the memory leaks for only gcc and not for plugin.so. I need a way to run valgrind exclusively on my plugin, which is a .so file.

 $ valgrind gcc -fplugin=./plugin.so myfile.c
 $ gcc -fplugin=./plugin.so myfile.c -wrapper valgrind

Is it even possible to do that? I've searched up on this a lot but haven't found any concrete answer on it.

+2 votes

Advance apologies if this question has been asked previously, Google searches only turned up results for using -fPIE/-fPIC.

Is it possible to build GCC as a PIE? If so, would it be a matter of including the -FPIC/-FPIE params for CFLAGS and/or LDFLAGS and running configure && make, or are there issues I should be aware of (for example, should I set parameters for cross-building)?

Background: Android 5.0 requires PIE, which means that upgrading will break my existing native build environment...unless I can build a PIE GCC first, then re-build all of my utilities with it.

...