Quantcast
Viewing all articles
Browse latest Browse all 22166

Forcing GCC to put specific statements in a specific section

I know that a compiler (at least GCC) can be forced to place specific functions in specific sections.

For example, consider the function foo.

int foo(int a, int b, int c);

By rewriting as follows, the compiler generates an executable ELF binary with the function placed in the output section .custom. (This also forces non-in-lining, because I need those functions to be called from their specific memory positions instead of just being replicated by the compiler.)

#define CUSTOMIZE    __attribute__((__section__(".custom"))) __attribute__ ((noinline))int  CUSTOMIZE  foo(int a, int b, int c);

So my question is, is it possible to do so automatically for specific statements or blocks inside a function?

Obviously one way to do that is to just extract those parts (let's say the for loop for example, or the statement 3) and put them in specific functions, but this is too much surgery and doesn't scale for me. Any ideas?

int foo(int a, int b, int c){   // Statement 1   // Statement 2   // Statement 3   // For Loop Block   for ( ... )   {       // For loop body   }   return some_value;}

EDIT

What I'm looking for is something equivalent to the following. Where the For loop is isolated in a separate function, that I can place in my custom section now.

I hope my intent is clearer now. My objective is just to know if there is a way to do that automatically by the compiler without extracting those parts manually (plus I also have to manage the arguments ...etc. long story short, too much surgery).

int CUSTOMIZE my_isolated_for_loop( some_arguments_here ){   // Place my for loop here, with the correct   // For Loop Block   for ( ... )   {       // For loop body   }   return result}int foo(int a, int b, int c){   // Statement 1   // Statement 2   // Statement 3   intermediate_result = my_isolated_for_loop( some_arguments_here )   return some_value;}

Thank you.


Viewing all articles
Browse latest Browse all 22166

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>