feat: added optimization level option to lld
This commit is contained in:
parent
0b1245b9cc
commit
2a688816fb
|
@ -6,7 +6,7 @@
|
|||
#include <link/clang/driver.h>
|
||||
#include <mem/cache.h>
|
||||
|
||||
bool clang_link(TargetLinkConfig* config) {
|
||||
bool clang_link(TargetConfig*, TargetLinkConfig* config) {
|
||||
|
||||
GString* commandString = g_string_new("");
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <link/driver.h>
|
||||
|
||||
bool clang_link(TargetLinkConfig* config);
|
||||
bool clang_link(TargetConfig*, TargetLinkConfig* config);
|
||||
|
||||
BinaryDriver* clang_get_driver();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <link/clang/driver.h>
|
||||
#include <mem/cache.h>
|
||||
|
||||
bool gcc_link(TargetLinkConfig* config) {
|
||||
bool gcc_link(TargetConfig*, TargetLinkConfig* config) {
|
||||
|
||||
GString* commandString = g_string_new("");
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <link/driver.h>
|
||||
|
||||
bool gcc_link(TargetLinkConfig* config);
|
||||
bool gcc_link(TargetConfig*, TargetLinkConfig* config);
|
||||
|
||||
BinaryDriver* gcc_get_driver();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <link/driver.h>
|
||||
|
||||
bool lldc_link(TargetLinkConfig* config);
|
||||
bool lldc_link(TargetConfig* target_config, TargetLinkConfig* link_config);
|
||||
|
||||
BinaryDriver* lldc_get_driver();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue