feat: add triple customization in target configuration
This commit is contained in:
parent
caeda1224c
commit
dee972a637
|
@ -43,6 +43,33 @@ const char* ENV_ANDROID = "android";
|
||||||
const char* ENV_MACHO = "macho";
|
const char* ENV_MACHO = "macho";
|
||||||
const char* ENV_ELF = "elf";
|
const char* ENV_ELF = "elf";
|
||||||
|
|
||||||
|
bool target_has_shared_dependency(TargetLinkConfig* config)
|
||||||
|
{
|
||||||
|
bool has_shared = false;
|
||||||
|
|
||||||
|
const char* shared_files[] = {
|
||||||
|
".so",
|
||||||
|
".dll"
|
||||||
|
};
|
||||||
|
|
||||||
|
for (guint i = 0; i < config->object_file_names->len; i++)
|
||||||
|
{
|
||||||
|
char* object_file = g_array_index(config->object_file_names, char*, i);
|
||||||
|
|
||||||
|
for (int k = 0; k < sizeof(shared_files)/sizeof(char*); k++)
|
||||||
|
{
|
||||||
|
has_shared = g_str_has_suffix(object_file, shared_files[k]);
|
||||||
|
if (has_shared)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_shared)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return has_shared;
|
||||||
|
}
|
||||||
|
|
||||||
const char* find_string(const char* haystack, const char** options, size_t size)
|
const char* find_string(const char* haystack, const char** options, size_t size)
|
||||||
{
|
{
|
||||||
const static char* found = NULL;
|
const static char* found = NULL;
|
||||||
|
@ -571,6 +598,8 @@ static int parse_target(const ProjectConfig* config,
|
||||||
|
|
||||||
get_int(&target_config->optimization_level, target_table, "opt");
|
get_int(&target_config->optimization_level, target_table, "opt");
|
||||||
|
|
||||||
|
get_str(&target_config->triple, target_table, "triple");
|
||||||
|
|
||||||
char* mode = NULL;
|
char* mode = NULL;
|
||||||
get_str(&mode, target_table, "mode");
|
get_str(&mode, target_table, "mode");
|
||||||
int err = get_mode_from_str(&target_config->mode, mode);
|
int err = get_mode_from_str(&target_config->mode, mode);
|
||||||
|
|
|
@ -168,6 +168,8 @@ const char* extract_sys_from_triple(const char* triple);
|
||||||
|
|
||||||
const char* extract_env_from_triple(const char* triple);
|
const char* extract_env_from_triple(const char* triple);
|
||||||
|
|
||||||
|
bool target_has_shared_dependency(TargetLinkConfig*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create the default configuration for targets.
|
* @brief Create the default configuration for targets.
|
||||||
* @return A pointer to a new target configuration.
|
* @return A pointer to a new target configuration.
|
||||||
|
|
|
@ -11,9 +11,7 @@
|
||||||
extern int lld_main(int Argc, const char **Argv, const char **outstr);
|
extern int lld_main(int Argc, const char **Argv, const char **outstr);
|
||||||
|
|
||||||
const char* FLAGS[] = {
|
const char* FLAGS[] = {
|
||||||
"--fatal-warnings",
|
"--fatal-warnings"
|
||||||
"--Bdynamic",
|
|
||||||
"--dynamic-linker=/usr/bin/ld.so"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* get_optimization_level_string(TargetConfig* config)
|
const char* get_optimization_level_string(TargetConfig* config)
|
||||||
|
@ -35,6 +33,26 @@ bool lldc_link(TargetConfig* target_config, TargetLinkConfig* link_config) {
|
||||||
const char* optimization_level = get_optimization_level_string(target_config);
|
const char* optimization_level = get_optimization_level_string(target_config);
|
||||||
g_array_append_val(arguments, optimization_level);
|
g_array_append_val(arguments, optimization_level);
|
||||||
|
|
||||||
|
// enable dynamic linker on linux
|
||||||
|
if (extract_sys_from_triple(target_config->triple) == SYS_LINUX)
|
||||||
|
{
|
||||||
|
if (target_has_shared_dependency(link_config))
|
||||||
|
{
|
||||||
|
// add dynamic linker
|
||||||
|
print_message(Info, "Enabling dynamic linker for build");
|
||||||
|
|
||||||
|
const char* enable_dynamic_linker = "--Bdynamic";
|
||||||
|
g_array_append_val(arguments, enable_dynamic_linker);
|
||||||
|
|
||||||
|
const char* default_dynamic_linker_path = "/usr/bin/ld.so";
|
||||||
|
const char* dynamic_linker_option = "--dynamic-linker=";
|
||||||
|
|
||||||
|
char* buffer = mem_alloc(MemoryNamespaceLld, strlen(dynamic_linker_option) + strlen(default_dynamic_linker_path) + 1);
|
||||||
|
sprintf(buffer, "%s%s", dynamic_linker_option, default_dynamic_linker_path);
|
||||||
|
g_array_append_val(arguments, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(FLAGS)/sizeof(char*); i++) {
|
for (int i = 0; i < sizeof(FLAGS)/sizeof(char*); i++) {
|
||||||
char* flag = (char*) FLAGS[i];
|
char* flag = (char*) FLAGS[i];
|
||||||
|
|
||||||
|
|
|
@ -62,10 +62,35 @@ static char* create_target_output_name(const TargetConfig* config) {
|
||||||
return cached_name;
|
return cached_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
Target create_target_from_config(const TargetConfig* config) {
|
Target create_target_from_triple(char* triple)
|
||||||
|
{
|
||||||
|
Target target;
|
||||||
|
|
||||||
|
target.triple.str = mem_strdup(MemoryNamespaceLld, triple);
|
||||||
|
target.triple.allocation = NONE;
|
||||||
|
|
||||||
|
// select default
|
||||||
|
target.cpu.str = "";
|
||||||
|
target.cpu.allocation = NONE;
|
||||||
|
|
||||||
|
// select default
|
||||||
|
target.features.str = "";
|
||||||
|
target.features.allocation = NONE;
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
Target create_target_from_config(TargetConfig* config) {
|
||||||
DEBUG("Building target from configuration");
|
DEBUG("Building target from configuration");
|
||||||
|
|
||||||
Target target = create_native_target();
|
Target target = create_native_target();
|
||||||
|
if (config->triple != NULL)
|
||||||
|
{
|
||||||
|
target = create_target_from_triple(config->triple);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
config->triple = target.triple.str;
|
||||||
|
}
|
||||||
|
|
||||||
target.name.str = create_target_output_name(config);
|
target.name.str = create_target_output_name(config);
|
||||||
target.name.allocation = NONE; // freed later by compiler
|
target.name.allocation = NONE; // freed later by compiler
|
||||||
|
|
|
@ -23,7 +23,7 @@ typedef struct Target_t {
|
||||||
|
|
||||||
Target create_native_target();
|
Target create_native_target();
|
||||||
|
|
||||||
Target create_target_from_config(const TargetConfig* config);
|
Target create_target_from_config(TargetConfig* config);
|
||||||
|
|
||||||
void delete_target(Target target);
|
void delete_target(Target target);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ driver = "ld.lld"
|
||||||
print_asm = true
|
print_asm = true
|
||||||
print_ir = true
|
print_ir = true
|
||||||
print_ast = true
|
print_ast = true
|
||||||
|
opt = 3
|
||||||
|
triple = "x86_64-unknown-linux"
|
||||||
|
|
||||||
[targets.dependencies]
|
[targets.dependencies]
|
||||||
std = { build-path = "../../lib/src", target = "gsc-libc" }
|
std = { build-path = "../../lib/src", target = "gsc-libc" }
|
||||||
|
|
Loading…
Reference in New Issue