Browse Source

Merge pull request #1425 from graphitemaster/more_linux_shared_library_fixes

Fixes for shared library initialization and finalization
Jeroen van Rijn 3 years ago
parent
commit
50668fa7a6
1 changed files with 5 additions and 4 deletions
  1. 5 4
      src/main.cpp

+ 5 - 4
src/main.cpp

@@ -446,8 +446,9 @@ i32 linker_stage(lbGenerator *gen) {
 			link_settings = gb_string_appendc(link_settings, "-shared ");
 			link_settings = gb_string_appendc(link_settings, "-shared ");
 
 
 			// NOTE(dweiler): _odin_entry_point must be called at initialization
 			// NOTE(dweiler): _odin_entry_point must be called at initialization
-			// time of the shared object, we can pass -init to the linker by using
-			// a comma separated list of arguments to -Wl.
+			// time of the shared object, similarly, _odin_exit_point must be called
+			// at deinitialization. We can pass both -init and -fini to the linker by
+			// using a comma separated list of arguments to -Wl.
 			//
 			//
 			// This previously used ld but ld cannot actually build a shared library
 			// This previously used ld but ld cannot actually build a shared library
 			// correctly this way since all the other dependencies provided implicitly
 			// correctly this way since all the other dependencies provided implicitly
@@ -457,11 +458,11 @@ i32 linker_stage(lbGenerator *gen) {
 			// Shared libraries are .dylib on MacOS and .so on Linux.
 			// Shared libraries are .dylib on MacOS and .so on Linux.
 			#if defined(GB_SYSTEM_OSX)
 			#if defined(GB_SYSTEM_OSX)
 				output_ext = STR_LIT(".dylib");
 				output_ext = STR_LIT(".dylib");
-				link_settings = gb_string_appendc(link_settings, "-Wl,-init,'__odin_entry_point' ");
 			#else
 			#else
 				output_ext = STR_LIT(".so");
 				output_ext = STR_LIT(".so");
-				link_settings = gb_string_appendc(link_settings, "-Wl,-init,'__odin_entry_point' ");
 			#endif
 			#endif
+			link_settings = gb_string_appendc(link_settings, "-Wl,-init,'_odin_entry_point' ");
+			link_settings = gb_string_appendc(link_settings, "-Wl,-fini,'_odin_exit_point' ");
 		} else {
 		} else {
 			link_settings = gb_string_appendc(link_settings, "-no-pie ");
 			link_settings = gb_string_appendc(link_settings, "-no-pie ");
 		}
 		}