This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to force code alignment for all functions in the code

Hi,

I have code (rather large bunch of functions) which should be 64 bits aligned on per function basis.

 

I am looking for something like --align_code=8  for Cortex-R4 which would force alignment of all functions on 64 bits boundary. The alternative approach would be to place every function in a separate sections and force the linker to align all sections. I do not see a solution for this one either.

I see that I can place every function into separate section using --gen_func_subsections. How do I make linker align all sections ?

Is there any solution for this problem?

 

Thank you, Arkady.

 

 

 

  • Arkady,

    Have you tried the align keyword in the linker? You can align an entire section or a subsection with the keyword. This is described in the ARM Assembly Language Tools Users Guide (section 7.5.4.2) and includes some examples as well.

  • Aarti,

    I have hundreds of functions and each and every one of them should be 64 bits aligned. I can generate an object file where every function is placed in a separate section. I  can automatically generate a linker script file which places all such sections at aligned addresses.

     My question is there anything simpler besides writing a python script which pulls sections from the OUT file and generates a linker script file with hundreds of sections?  I want the compiler to pad the functions to 64 bits and to start the functions at 64 bits boundary. There is such support for structures with -align-struct

    Let me explain where the problem originates from. There is a ROM with 64 bits bus. All fetches are 64 bits. I want to enable patching of the ROM. There is chunk of hardware with checks the fetch addresses agains addresses in the hardware table and returns abort to the Cortex-R4 if the address on the bus matches the address in the hardware table. The prefetch abort handler will execute the patch code. The problem is that all addresses are 64 bits aligned. For example, fetch from address 0xC0 and 0x80 are going to happen in one clycle on the bus. If a function I want to patch starts at 32 bits boundary I will have to patch both this function and last opcode (or two in case of thumb-2) in the previous function. The best approach to the problem is to force the functions at 64 bits boundaries. I see that GCC compiler does the trick with -falign-function. Is there anything like this in tms470?

  • Arkady Miasnikov said:
    I see that GCC compiler does the trick with -falign-function. Is there anything like this in tms470?

    No. Sorry.

    This wiki article may help with that python script.

    Thanks and regards,

    -George

  • Apparently IAR compiler allows the trick too with --align_func compilation flag. The flag was added somewhere around 2008. Similar flag exists in GCC.

    I wonder why TI's compiler for ARM does not allow this.

  • We are considering to switch to GCC or IAR for the ROM part of the code. Is there any documentation which covers benchmark tests between GCC/IAR/TI compilers? I will appreciate any link.

    Thank you, Arkady.