Contributions from input files usually appear in the output file in the order of their contribution. Tentative symbols are an exception to this rule, as these symbols are not fully defined until their resolution is complete. The order of tentative symbols within the output file might not follow the order of their contribution.
If you need to control the ordering of a group of symbols, then any tentative definition should be redefined to a zero-initialized data item. For example, the following tentative definitions result in a reordering of the data items within the output file, as compared to the original order described in the source file foo.c.
$ cat foo.c char One_array[0x10]; char Two_array[0x20]; char Three_array[0x30]; $ cc -o libfoo.so -G -Kpic foo.c $ elfdump -sN.dynsym libfoo.so | grep array | sort -k 2,2 [11] 0x10614 0x20 OBJT GLOB D 0 .bss Two_array [3] 0x10634 0x30 OBJT GLOB D 0 .bss Three_array [4] 0x10664 0x10 OBJT GLOB D 0 .bss One_array
Sorting the symbols based on their address shows that their output order is different than the order they were defined in the source. In contrast, defining these symbols as initialized data items ensures that the relative ordering of these symbols within the input file is carried over to the output file.
$ cat foo.c char A_array[0x10] = { 0 }; char B_array[0x20] = { 0 }; char C_array[0x30] = { 0 }; $ cc -o libfoo.so -G -Kpic foo.c $ elfdump -sN.dynsym libfoo.so | grep array | sort -k 2,2 [4] 0x10614 0x10 OBJT GLOB D 0 .data One_array [11] 0x10624 0x20 OBJT GLOB D 0 .data Two_array [3] 0x10644 0x30 OBJT GLOB D 0 .data Three_array