質問

EDIT: Solved - the linker script property "SUBALIGN(32)" applied to the static data sections does exactly what I required, forcing each object file linked to be aligned to a 32byte boundary, with padding automatically inserted.

__bss_start = .;  
.bss            :  
SUBALIGN(32)  
{  
  *(.dynbss)  
  *(.bss .bss.* .gnu.linkonce.b.*)  
  *(COMMON)  
      SORT(CONSTRUCTORS)  
  . = ALIGN(32);  
} = 0  
  . = ALIGN(32);  

I am building a multiprogram benchmark on a cache-incoherent architecture, comprised of multiple instances of the EEMBC suite renamed and linked together.

The problem is that the libraries are not cache line aligned in the writable data segments, and I am getting data corruption here (evidenced by cache line thrashing in a coherent simulation).

For example cache line at 0x7500 is being shared between the cores operating on Viterb0 and Viterb1, the map output indicates that this is where library 0 is running into the cache line that library1 starts in:

...  
 .bss           0x000068e8      0xc24 ../EEMBClib/libmark_0.a(renamed_renamed_viterb00_viterb00.o)  
 .bss           0x0000750c        0x4 ../EEMBClib/libmark_1.a(renamed_renamed_viterb00_bmark_lite.o)  
...  

I need to align every object file linked in the various data segments to 32byte boundaries, I only know how to align the whole section, the current .bss sections is:

  __bss_start = .;  
  .bss            :  
  {  
    *(.dynbss)  
    *(.bss .bss.* .gnu.linkonce.b.*)  
    *(COMMON)  
        SORT(CONSTRUCTORS)  
    . = ALIGN(32);  
  } = 0  
    . = ALIGN(32);  

Any help would be greatly appreciated here, rebuilding the libraries with padding isn't really an option I want to consider yet as I would like this more robust solution for future linking purposes on this platform.

役に立ちましたか?

解決

The solution is the linker script property "SUBALIGN(32)". When applied to the static data sections this does exactly what I required, forcing each object file linked to be aligned to a 32byte boundary, with padding automatically inserted.

__bss_start = .;  
.bss            :  
SUBALIGN(32)  
{  
  *(.bss .bss.* .gnu.linkonce.b.*)
} = 0  
  . = ALIGN(32);  

gives the fixed result

.bss 0x00006940 0xc24 ../EEMBClib/libmark_0.a(renamed_renamed_viterb00_viterb00.o)
fill 0x00007564 0x1c 00000000
.bss 0x00007580 0x4 ../EEMBClib/libmark_1.a(renamed_renamed_viterb00_bmark_lite.o)

instead of

.bss           0x000068e8      0xc24 ../EEMBClib/libmark_0.a(renamed_renamed_viterb00_viterb00.o)  
.bss           0x0000750c        0x4 ../EEMBClib/libmark_1.a(renamed_renamed_viterb00_bmark_lite.o) 

他のヒント

(Apologies that this is at least currently more a collection of thoughts than a concrete answer, but it's going to be a bit long to post in comments)

Probably the first thing that would be worth doing is to come up with some verification routine that parses objdump/readelf output to verify if your alignment requirement has been met, and put this into your build process as a check. If you can't do it at compile time, at least do it as a run time check.

Then some paths of achieving the alignment could be investigated.

Assume for a minute that a custom section is created and all data with this requirement is placed there with pragmas in the source code. Something to look into would then be if the linker is willing to honor the section alignment setting given in the occurrence of that section in each object file. You could for example hexedit one of the objects to increase that alignment and use your dump processor to see what happens. If this works out, great - it seems like the proper way to handle the task, and hopefully there's a reasonable way to specify the alignment size requirement for that section which will end up in the object files.

Another idea would be to attempt some sort of scripted allocation adjustment. For example, use objcopy to join all the applicable sections into one file, while stripping them out of the others. Analyze the file and figure out what allocations you want, then use objcopy or a custom elf modification program to set that. Maybe you could even make this modification to the fully linked result, at least if you have your linker script put the special section at the end, so that you don't have to move other allocations out of its way when you grow it to achieve internal alignment.

If you don't want to get into modifying elf's, another approach for doing your own auxiallary linking with a script could be to calculate the size of each object's data in the special section, then automatically generate an additional object file that simply pads that section out to the next alignment boundary. Your link stage would then specify objects in a list: program1.o padding1.o program2.o padding2.o

Or you could have each program put its special data in its own uniquely named linker section. Dump out the sizes of all of these, figure out where you want them to be, and then have the script create a customized linker script which explicitly puts the named sections in the just determined places.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top