Explorar el Código

Adds return values to linker stages

Platin21 hace 4 años
padre
commit
66fb2a94ee
Se han modificado 1 ficheros con 63 adiciones y 42 borrados
  1. 63 42
      src/main.cpp

+ 63 - 42
src/main.cpp

@@ -121,7 +121,6 @@ i32 system_exec_command_line_app(char const *name, char const *fmt, ...) {
 		gb_printf_err("%s\n\n", cmd_line);
 	}
 	exit_code = system(cmd_line);
-
 	// pid_t pid = fork();
 	// int status = 0;
 
@@ -147,12 +146,7 @@ i32 system_exec_command_line_app(char const *name, char const *fmt, ...) {
 	// 	status = WEXITSTATUS(s);
 	// }
 
-	// exit_code = status;
-
-	if (exit_code) {
-		exit(exit_code);
-	}
-
+	// exit_code = status
 	return exit_code;
 #endif
 }
@@ -161,8 +155,9 @@ i32 system_exec_command_line_app(char const *name, char const *fmt, ...) {
 
 
 #if defined(LLVM_BACKEND_SUPPORT)
-void linker_stage(lbGenerator *gen) {
-	Timings *timings = &global_timings;
+i32 linker_stage(lbGenerator *gen) {
+  i32 result = 0;
+  Timings *timings = &global_timings;
 
 	String output_base = gen->output_base;
 
@@ -176,7 +171,7 @@ void linker_stage(lbGenerator *gen) {
 
 	if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) {
 #ifdef GB_SYSTEM_UNIX
-		system_exec_command_line_app("linker", "x86_64-essence-gcc \"%.*s.o\" -o \"%.*s\" %.*s %.*s",
+		result = system_exec_command_line_app("linker", "x86_64-essence-gcc \"%.*s.o\" -o \"%.*s\" %.*s %.*s",
 			LIT(output_base), LIT(output_base), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
 #else
 		gb_printf_err("Linking for cross compilation for this platform is not yet supported (%.*s %.*s)\n",
@@ -273,28 +268,30 @@ void linker_stage(lbGenerator *gen) {
 		char const *subsystem_str = build_context.use_subsystem_windows ? "WINDOWS" : "CONSOLE";
 		if (!build_context.use_lld) { // msvc
 			if (build_context.has_resource) {
-				system_exec_command_line_app("msvc-link",
+				result = system_exec_command_line_app("msvc-link",
 					"\"rc.exe\" /nologo /fo \"%.*s.res\" \"%.*s.rc\"",
 					LIT(output_base),
 					LIT(build_context.resource_filepath)
 				);
-
-				system_exec_command_line_app("msvc-link",
-					"\"%.*slink.exe\" %s \"%.*s.res\" -OUT:\"%.*s.%s\" %s "
-					"/nologo /incremental:no /opt:ref /subsystem:%s "
-					" %.*s "
-					" %.*s "
-					" %s "
-					"",
-					LIT(find_result.vs_exe_path), object_files, LIT(output_base), LIT(output_base), output_ext,
-					link_settings,
-					subsystem_str,
-					LIT(build_context.link_flags),
-					LIT(build_context.extra_linker_flags),
-					lib_str
-				);
+        
+        if(result == 0) {
+          result = system_exec_command_line_app("msvc-link",
+            "\"%.*slink.exe\" %s \"%.*s.res\" -OUT:\"%.*s.%s\" %s "
+            "/nologo /incremental:no /opt:ref /subsystem:%s "
+            " %.*s "
+            " %.*s "
+            " %s "
+            "",
+            LIT(find_result.vs_exe_path), object_files, LIT(output_base), LIT(output_base), output_ext,
+            link_settings,
+            subsystem_str,
+            LIT(build_context.link_flags),
+            LIT(build_context.extra_linker_flags),
+            lib_str
+          );
+        }
 			} else {
-				system_exec_command_line_app("msvc-link",
+				result = system_exec_command_line_app("msvc-link",
 					"\"%.*slink.exe\" %s -OUT:\"%.*s.%s\" %s "
 					"/nologo /incremental:no /opt:ref /subsystem:%s "
 					" %.*s "
@@ -310,7 +307,7 @@ void linker_stage(lbGenerator *gen) {
 				);
 			}
 		} else { // lld
-			system_exec_command_line_app("msvc-link",
+			  result = system_exec_command_line_app("msvc-link",
 				"\"%.*s\\bin\\lld-link\" %s -OUT:\"%.*s.%s\" %s "
 				"/nologo /incremental:no /opt:ref /subsystem:%s "
 				" %.*s "
@@ -428,8 +425,8 @@ void linker_stage(lbGenerator *gen) {
 				output_ext = substring(build_context.out_filepath, pos, build_context.out_filepath.len);
 			}
 		}
-
-		system_exec_command_line_app("ld-link",
+    
+		result = system_exec_command_line_app("ld-link",
 			"%s %s -o \"%.*s%.*s\" %s "
 			" %s "
 			" %.*s "
@@ -470,8 +467,8 @@ void linker_stage(lbGenerator *gen) {
 
 	#endif
 	}
-
-	return;
+  
+	return result;
 }
 #endif
 
@@ -2150,7 +2147,10 @@ int main(int arg_count, char const **arg_ptr) {
 		switch (build_context.build_mode) {
 		case BuildMode_Executable:
 		case BuildMode_DynamicLibrary:
-			linker_stage(&gen);
+			i32 result = linker_stage(&gen);
+      if(result != 0) {
+        return 1;
+      }
 			break;
 		}
 
@@ -2344,13 +2344,17 @@ int main(int arg_count, char const **arg_ptr) {
 
 			if (!build_context.use_lld) { // msvc
 				if (build_context.has_resource) {
-					system_exec_command_line_app("msvc-link",
+					i32 result = system_exec_command_line_app("msvc-link",
 						"\"rc.exe\" /nologo /fo \"%.*s.res\" \"%.*s.rc\"",
 						LIT(output_base),
 						LIT(build_context.resource_filepath)
 					);
-
-					system_exec_command_line_app("msvc-link",
+          
+          if(result != 0) {
+            return 1;
+          }
+          
+          result = system_exec_command_line_app("msvc-link",
 						"\"%.*slink.exe\" \"%.*s.obj\" \"%.*s.res\" -OUT:\"%.*s.%s\" %s "
 						"/nologo /incremental:no /opt:ref /subsystem:%s "
 						" %.*s "
@@ -2364,8 +2368,13 @@ int main(int arg_count, char const **arg_ptr) {
 						LIT(build_context.extra_linker_flags),
 						lib_str
 					);
+          
+          if(result != 0) {
+            return 1;
+          }
+          
 				} else {
-					system_exec_command_line_app("msvc-link",
+          i32 result =  system_exec_command_line_app("msvc-link",
 						"\"%.*slink.exe\" \"%.*s.obj\" -OUT:\"%.*s.%s\" %s "
 						"/nologo /incremental:no /opt:ref /subsystem:%s "
 						" %.*s "
@@ -2379,9 +2388,13 @@ int main(int arg_count, char const **arg_ptr) {
 						LIT(build_context.extra_linker_flags),
 						lib_str
 					);
+          
+          if(result != 0) {
+            return 1;
+          }
 				}
 			} else { // lld
-				system_exec_command_line_app("msvc-link",
+				i32 result = system_exec_command_line_app("msvc-link",
 					"\"%.*s\\bin\\lld-link\" \"%.*s.obj\" -OUT:\"%.*s.%s\" %s "
 					"/nologo /incremental:no /opt:ref /subsystem:%s "
 					" %.*s "
@@ -2396,6 +2409,10 @@ int main(int arg_count, char const **arg_ptr) {
 					LIT(build_context.extra_linker_flags),
 					lib_str
 				);
+        
+        if(result != 0) {
+          return 1;
+        }
 			}
 
 			if (build_context.show_timings) {
@@ -2506,8 +2523,8 @@ int main(int arg_count, char const **arg_ptr) {
 				}
 			}
 
-
-			system_exec_command_line_app("ld-link",
+      gb_printf("Started Linking!");
+			i32 result = system_exec_command_line_app("ld-link",
 				"%s \"%.*s.o\" -o \"%.*s%.*s\" %s "
 				" %s "
 				" %.*s "
@@ -2531,7 +2548,11 @@ int main(int arg_count, char const **arg_ptr) {
 				LIT(build_context.link_flags),
 				LIT(build_context.extra_linker_flags),
 				link_settings);
-
+      
+      if(result != 0) {
+        return 1;
+      }
+      
 		#if defined(GB_SYSTEM_OSX)
 			if (build_context.ODIN_DEBUG) {
 				// NOTE: macOS links DWARF symbols dynamically. Dsymutil will map the stubs in the exe
@@ -2558,6 +2579,6 @@ int main(int arg_count, char const **arg_ptr) {
 		#endif
 		}
 	}
-
+  
 	return 0;
 }