Modulesinit() help in runtime

It is mentioned in the comments of the modulesInit() function in the symtab.go file inside the runtime folder of the Go source code, that when a module is first loaded by a dynamic linker, addmoduledata is called and a number of modules built with -linkshared and the plugin can be loaded.

The modulesinit() function gets invoked twice when I run an application that is made with -buildmode=shared and -linkshared flag, and the plugin is used in LD_PRELOAD.

My observation:

The myapplication is built using the -linkshared and the plugin so is loaded using plugin.Open() or LD_PRELOAD. In this case, the modulesinit() inside the symtab.go is invoked twice.

Application is built using -linkshared and shared library created with -buildmode=shared is loaded using LD_PRELOAD. In this case, the modulesinit() doesn’t get invoked.

export LD_PRELOAD=/usr/lib/ ; ./myapplication

In the case of the plugin, if I don’t compile the binary with -linkshared then modulesinit() doesn’t get invoked at all, is it possible to invoke it somehow in the same?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.