feat: added support for entry point flag in ld.lld
This commit is contained in:
parent
044a11f28c
commit
a71385d508
|
@ -11,7 +11,8 @@
|
||||||
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",
|
||||||
|
"--nostdlib"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* get_optimization_level_string(TargetConfig* config)
|
const char* get_optimization_level_string(TargetConfig* config)
|
||||||
|
@ -35,6 +36,11 @@ bool lldc_link(TargetConfig* target_config, TargetLinkConfig* link_config) {
|
||||||
g_array_append_val(arguments, colored_diagnostics);
|
g_array_append_val(arguments, colored_diagnostics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (link_config->entry != NULL) {
|
||||||
|
char* colored_diagnostics = mem_asprintf(MemoryNamespaceLld, "--entry=%s", link_config->entry);
|
||||||
|
g_array_append_val(arguments, colored_diagnostics);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ TargetLinkConfig* lld_create_link_config(__attribute__((unused))
|
||||||
mem_new_g_array(MemoryNamespaceLld, sizeof(char*));
|
mem_new_g_array(MemoryNamespaceLld, sizeof(char*));
|
||||||
config->colorize = stdout_supports_ansi_esc();
|
config->colorize = stdout_supports_ansi_esc();
|
||||||
config->driver = target_config->driver;
|
config->driver = target_config->driver;
|
||||||
|
config->entry = module->entry;
|
||||||
|
|
||||||
// append build object file
|
// append build object file
|
||||||
char* basename = g_strjoin(".", target_config->name, "o", NULL);
|
char* basename = g_strjoin(".", target_config->name, "o", NULL);
|
||||||
|
|
|
@ -369,3 +369,19 @@ GHashTable* mem_new_g_hash_table(MemoryNamespaceName name, GHashFunc hash_func,
|
||||||
|
|
||||||
return namespace_new_g_hash_table(cache, hash_func, key_equal_func);
|
return namespace_new_g_hash_table(cache, hash_func, key_equal_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* mem_asprintf(MemoryNamespaceName name, const char* format, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
|
||||||
|
char* buffer = NULL;
|
||||||
|
int chars = vasprintf(&buffer, format, args);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
char* cached = mem_clone(name, buffer, chars);
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
|
@ -87,6 +87,15 @@ char* mem_strdup(MemoryNamespaceName name, char* string);
|
||||||
*/
|
*/
|
||||||
void* mem_clone(MemoryNamespaceName name, void* data, size_t size);
|
void* mem_clone(MemoryNamespaceName name, void* data, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Write formatted output into a dynamically allocated buffer managed by this cache,
|
||||||
|
* @param name
|
||||||
|
* @param format
|
||||||
|
* @param ...
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
char* mem_asprintf(MemoryNamespaceName name, const char* format, ...);
|
||||||
|
|
||||||
void print_memory_statistics();
|
void print_memory_statistics();
|
||||||
|
|
||||||
GArray* mem_new_g_array(MemoryNamespaceName name, guint element_size);
|
GArray* mem_new_g_array(MemoryNamespaceName name, guint element_size);
|
||||||
|
|
|
@ -2868,6 +2868,7 @@ Module* create_set(AST_NODE_PTR currentNode) {
|
||||||
rootModule->variables = variables;
|
rootModule->variables = variables;
|
||||||
rootModule->imports = imports;
|
rootModule->imports = imports;
|
||||||
rootModule->includes = includes;
|
rootModule->includes = includes;
|
||||||
|
rootModule->entry = NULL;
|
||||||
|
|
||||||
DEBUG("created Module struct");
|
DEBUG("created Module struct");
|
||||||
|
|
||||||
|
@ -2922,11 +2923,24 @@ Module* create_set(AST_NODE_PTR currentNode) {
|
||||||
Function* function =
|
Function* function =
|
||||||
mem_alloc(MemoryNamespaceSet, sizeof(Function));
|
mem_alloc(MemoryNamespaceSet, sizeof(Function));
|
||||||
|
|
||||||
if (createFunction(function, AST_get_node(currentNode, i))
|
AST_NODE_PTR function_node = AST_get_node(currentNode, i);
|
||||||
|
if (createFunction(function, function_node)
|
||||||
== SEMANTIC_ERROR) {
|
== SEMANTIC_ERROR) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (function_node->annotation.kind == AnnotationKindArray) {
|
||||||
|
if (AST_annotation_array_contains_flag(&function_node->annotation, "entry")) {
|
||||||
|
|
||||||
|
if (rootModule->entry != NULL) {
|
||||||
|
print_diagnostic(&function_node->location, Error, "Multiple functions marked as entry points");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
rootModule->entry = function->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_hash_table_insert(rootModule->functions, function->name, function);
|
g_hash_table_insert(rootModule->functions, function->name, function);
|
||||||
|
|
||||||
DEBUG("created function successfully");
|
DEBUG("created function successfully");
|
||||||
|
|
|
@ -602,6 +602,8 @@ typedef struct Module_t {
|
||||||
// parent modules in descending order
|
// parent modules in descending order
|
||||||
// root > submodule > current-module
|
// root > submodule > current-module
|
||||||
GArray* path;
|
GArray* path;
|
||||||
|
// entry point symbol
|
||||||
|
char* entry;
|
||||||
} Module;
|
} Module;
|
||||||
|
|
||||||
// .------------------------------------------------.
|
// .------------------------------------------------.
|
||||||
|
|
Loading…
Reference in New Issue