lld: order of object files to be put into executable

Hi all!

Is it possible somehow to specify *order* of object files to be put to executable file?
For example, I want to put obj1.o and obj2.o somewhere at the beginning, so when executable file would be mapped
to memory, this code would be accessed quickly.

Hi Quolick,

the order of pages in an executable doesn't really matter in modern operating systems. The relevant parts of the executable are mmap()ed and loaded on demand.

Although, keeping related code together for locality could be an advantage (both at load times w/ readahead and in the TLB during runtime), so that's a more interesting question to pursue.


Hi Quolick,

I don’t know if you are using the ELF or COFF LLD (I do not know the latter), but at least if you are using the ELF linker, you could use the --symbol-ordering-file option to put symbols from the object files you care about next to each other. This orders the input sections from the object file, based on the requested symbol order. This could be used to achieve the code locality as suggested by Nicolai.