To order the elements in a static library when it is being built by ar, use the commands lorder(1) and tsort(1):
demo% ar -cr mylib.a ’lorder exg.o fofx.o diffz.o | tsort’