bmc0 / dsp

An audio processing program with an interactive mode.
ISC License
219 stars 31 forks source link

Use GCC attribute for shared object constructor/destructor routines #23

Closed chedr closed 6 years ago

chedr commented 6 years ago

Found an interesting linker bug when porting over the build system... looked into it and found that ladspa_dsp was using the deprecated init/cleanup routine prototypes.

Libraries should export initialization and cleanup routines using the gcc __attribute__((constructor)) and __attribute__((destructor)) function attributes. See the gcc info pages for information on these. Constructor routines are executed before dlopen returns (or before main() is started if the library is loaded at load time). Destructor routines are executed before dlclose returns (or after exit() or completion of main() if the library is loaded at load time). The C prototypes for these functions are:

void __attribute__ ((constructor)) my_init(void);
void __attribute__ ((destructor)) my_fini(void);

Historically there have been two special functions, _init and _fini that can be used to control constructors and destructors. However, they are obsolete, and their use can lead to unpredicatable results. Your libraries should not use these; use the function attributes constructor and destructor above instead.

More info: http://www.faqs.org/docs/Linux-HOWTO/Program-Library-HOWTO.html#INIT-AND-CLEANUP

bmc0 commented 6 years ago

Thanks for catching that, but your commit by itself may cause problems according to the document you linked because ladspa_dsp.so is linked with -nostartfiles (see GNUMakefile, line 48). I've pushed a commit (4b2ce63) containing the appropriate changes.

chedr commented 6 years ago

Good catch! I will close this.