John Ulvr
John Ulvr

Reputation: 636

LINUX: order of statically linked module loading

If I have two modules which are being statically linked in. One modules' module_init function depends on another module's module_init function having already run. Is there a way to force one module to load before the other?

Also, is the first module's init function guaranteed to finish before the second one is invoked?

Lastly, if the answer to the above is NO, what is the recommended way of synchronizing the two module init calls to make sure I don't run into issues?

Upvotes: 12

Views: 6426

Answers (2)

adobriyan
adobriyan

Reputation: 2662

Is there a way to force one module to load before the other?

Answer is surprisingly simple, make sure first module is first in Makefile:

obj-y += mod1.o
obj-y += mod2.o

is the first module's init function guaranteed to finish before the second one is invoked?

Yes, initcalls (module_init hook) in your case are called one-by-one. See init/main.c, do_one_initcall() callers.

Upvotes: 13

sehe
sehe

Reputation: 393934

I'm assuming you want to fix the static initialization fiasco

Have a look at

Static Initialization Order Fiasco

Upvotes: 0

Related Questions