creating a C function with a given size in the text segment

后端 未结 4 1685
梦谈多话
梦谈多话 2021-02-19 11:48

I\'m programming an embedded powerpc 32 system with a 32 kbyte 8-way set associative L2 instruction cache. To avoid cache thrashing we align functions in a way such that the tex

4条回答
  •  心在旅途
    2021-02-19 12:21

    Assuming you're using GCC and GAS, this may be a simple solution for you:

    void high_freq1(void)
    {
       ...
    }
    asm(".org .+288"); /* Advance location by 288 bytes */
    void high_freq2(void)
    {
       ...
    }
    

    You could, possibly, even use it to set absolute locations for the functions rather than using relative increments in address, which would insulate you from consequences due to the functions changing in size when/if you modify them.

    It's not pure C89, for sure, but it may be less ugly than using dummy functions. :)

    (Then again, it should be mentioned that linker scripts aren't standardized either.)

    EDIT: As noted in the comments, it seems to be important to pass the -fno-toplevel-reorder flag to GCC in this case.

提交回复
热议问题