diff --git a/src/link/clang/driver.c b/src/link/clang/driver.c index 8ee1c05..8e40bae 100644 --- a/src/link/clang/driver.c +++ b/src/link/clang/driver.c @@ -6,7 +6,7 @@ #include #include -bool clang_link(TargetLinkConfig* config) { +bool clang_link(TargetConfig*, TargetLinkConfig* config) { GString* commandString = g_string_new(""); diff --git a/src/link/clang/driver.h b/src/link/clang/driver.h index e8f15da..2b472f9 100644 --- a/src/link/clang/driver.h +++ b/src/link/clang/driver.h @@ -7,7 +7,7 @@ #include -bool clang_link(TargetLinkConfig* config); +bool clang_link(TargetConfig*, TargetLinkConfig* config); BinaryDriver* clang_get_driver(); diff --git a/src/link/driver.h b/src/link/driver.h index 9d05f7c..f0e03fa 100644 --- a/src/link/driver.h +++ b/src/link/driver.h @@ -10,7 +10,7 @@ #define DEFAULT_DRIVER "ld.lld" //! @brief Function a binary driver used to link files -typedef bool (*driver_link)(TargetLinkConfig*); +typedef bool (*driver_link)(TargetConfig*, TargetLinkConfig*); typedef struct BinaryDriver_t { const char* name; diff --git a/src/link/gcc/driver.c b/src/link/gcc/driver.c index 1d3b672..e38f695 100644 --- a/src/link/gcc/driver.c +++ b/src/link/gcc/driver.c @@ -6,7 +6,7 @@ #include #include -bool gcc_link(TargetLinkConfig* config) { +bool gcc_link(TargetConfig*, TargetLinkConfig* config) { GString* commandString = g_string_new(""); diff --git a/src/link/gcc/driver.h b/src/link/gcc/driver.h index 8227353..9f17a41 100644 --- a/src/link/gcc/driver.h +++ b/src/link/gcc/driver.h @@ -7,7 +7,7 @@ #include -bool gcc_link(TargetLinkConfig* config); +bool gcc_link(TargetConfig*, TargetLinkConfig* config); BinaryDriver* gcc_get_driver(); diff --git a/src/link/lib.c b/src/link/lib.c index 25d288f..b21d84e 100644 --- a/src/link/lib.c +++ b/src/link/lib.c @@ -39,7 +39,7 @@ void link_init() { } } -bool link_run(TargetLinkConfig* config) { +bool link_run(TargetConfig* target_config, TargetLinkConfig* config) { if (g_hash_table_contains(binary_driver, config->driver)) { print_message(Info, "Invoking binary driver: %s", config->driver); @@ -47,7 +47,7 @@ bool link_run(TargetLinkConfig* config) { BinaryDriver* driver = g_hash_table_lookup(binary_driver, config->driver); - if (!driver->link_func(config)) { + if (!driver->link_func(target_config, config)) { print_message(Error, "Driver %s failed", config->driver); return false; } diff --git a/src/link/lib.h b/src/link/lib.h index 71c6054..b06d3ea 100644 --- a/src/link/lib.h +++ b/src/link/lib.h @@ -11,7 +11,7 @@ typedef BinaryDriver* (*driver_init)(); void link_init(); -bool link_run(TargetLinkConfig*); +bool link_run(TargetConfig*, TargetLinkConfig*); void link_print_available_driver(); diff --git a/src/link/lldc/lldc.c b/src/link/lldc/lldc.c index 44fce15..58a837d 100644 --- a/src/link/lldc/lldc.c +++ b/src/link/lldc/lldc.c @@ -16,32 +16,51 @@ const char* FLAGS[] = { "--dynamic-linker=/usr/bin/ld.so" }; -bool lldc_link(TargetLinkConfig* config) { +const char* get_optimization_level_string(TargetConfig* config) +{ + char* buffer = mem_alloc(MemoryNamespaceLld, 6); + + sprintf(buffer, "-O%d", config->optimization_level); + + return buffer; +} + +bool lldc_link(TargetConfig* target_config, TargetLinkConfig* link_config) { GArray* arguments = mem_new_g_array(MemoryNamespaceLld, sizeof(char*)); char* linker = "ld.lld"; g_array_append_val(arguments, linker); + const char* optimization_level = get_optimization_level_string(target_config); + g_array_append_val(arguments, optimization_level); + for (int i = 0; i < sizeof(FLAGS)/sizeof(char*); i++) { char* flag = (char*) FLAGS[i]; g_array_append_val(arguments, flag); } - for (guint i = 0; i < config->object_file_names->len; i++) { - char* obj = g_array_index(config->object_file_names, char*, i); + for (guint i = 0; i < link_config->object_file_names->len; i++) { + char* obj = g_array_index(link_config->object_file_names, char*, i); g_array_append_val(arguments, obj); } char* output_flag = "-o"; g_array_append_val(arguments, output_flag); - g_array_append_val(arguments, config->output_file); + g_array_append_val(arguments, link_config->output_file); + size_t chars = 0; for (guint i = 0; i < arguments->len; i++) { - printf("%s ", g_array_index(arguments, char*, i)); + chars += strlen(g_array_index(arguments, char*, i)); } - printf("\n"); + + char* buffer = mem_alloc(MemoryNamespaceLld, chars + 1); + size_t offset = 0; + for (guint i = 0; i < arguments->len; i++) { + offset += sprintf(buffer + offset, "%s ", g_array_index(arguments, char*, i)); + } + print_message(Info, buffer); const char* message = NULL; const bool code = lld_main(arguments->len, (const char**) arguments->data, &message); diff --git a/src/link/lldc/lldc.h b/src/link/lldc/lldc.h index 5e596b7..4549078 100644 --- a/src/link/lldc/lldc.h +++ b/src/link/lldc/lldc.h @@ -7,7 +7,7 @@ #include -bool lldc_link(TargetLinkConfig* config); +bool lldc_link(TargetConfig* target_config, TargetLinkConfig* link_config); BinaryDriver* lldc_get_driver(); diff --git a/src/llvm/link/lld.c b/src/llvm/link/lld.c index 2ec24d1..385304c 100644 --- a/src/llvm/link/lld.c +++ b/src/llvm/link/lld.c @@ -121,9 +121,9 @@ TargetLinkConfig* lld_create_link_config(__attribute__((unused)) return config; } -BackendError lld_link_target(TargetLinkConfig* config) { +BackendError lld_link_target(TargetConfig* target_config, TargetLinkConfig* config) { - if (link_run(config)) { + if (link_run(target_config, config)) { return SUCCESS; } diff --git a/src/llvm/link/lld.h b/src/llvm/link/lld.h index 8de1318..084eddc 100644 --- a/src/llvm/link/lld.h +++ b/src/llvm/link/lld.h @@ -13,7 +13,7 @@ TargetLinkConfig* lld_create_link_config(__attribute__((unused)) const TargetConfig* target_config, const Module* module); -BackendError lld_link_target(TargetLinkConfig* config); +BackendError lld_link_target(TargetConfig* target_config, TargetLinkConfig* config); void lld_delete_link_config(TargetLinkConfig* config); diff --git a/src/llvm/parser.c b/src/llvm/parser.c index 1080bb0..7cd256d 100644 --- a/src/llvm/parser.c +++ b/src/llvm/parser.c @@ -269,7 +269,7 @@ BackendError parse_module(const Module* module, const TargetConfig* config) { lld_create_link_config(&target, config, module); if (link_config != NULL) { - err = lld_link_target(link_config); + err = lld_link_target((TargetConfig*) config, link_config); lld_delete_link_config(link_config); } else {