I want my program such that each function in the binary has some space left after it ends. So that later if some minor change is required only that function is changed with the extra space acting as room for accounting the minor change. -falign-function can do the job but it will not give consistent space. Is there anyway to do it? Or better way to do it?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You could use an inline assembly statement to add a series of nops at the start (or end) of each function. Then later when you need to modify the function, you could remove some of the nops to keep the overall size of the function the same. For example:
int foo(...) {
__asm__ __volatile__("nop; nop; nop; nop;" ::);
...
}
Or you could even reserve large chunks of memory in the function with something like this:
__asm__ __volatile__("ba,a 1f; .skip 1000; 1: ;" ::);
This reserves a big chunk of memory and simply branches around it in the code.
回答2:
If you are using a sufficiently new compiler, they have recently added a new option: -fprolog-pad=N
and -fprolog-pad=M,N
which means issue M nops before the function an N nops after it.