mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-19 12:22:23 -07:00
Add @(link_section=<string>) for global variables
This commit is contained in:
@@ -934,6 +934,9 @@ void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast *type_expr,
|
||||
if (ac.link_name.len > 0) {
|
||||
e->Variable.link_name = ac.link_name;
|
||||
}
|
||||
if (ac.link_section.len > 0) {
|
||||
e->Variable.link_section = ac.link_section;
|
||||
}
|
||||
|
||||
if (e->Variable.is_foreign || e->Variable.is_export) {
|
||||
String name = e->token.string;
|
||||
|
||||
@@ -2650,6 +2650,16 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) {
|
||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||
}
|
||||
return true;
|
||||
} else if (name == "link_section") {
|
||||
if (ev.kind == ExactValue_String) {
|
||||
ac->link_section = ev.value_string;
|
||||
if (!is_foreign_name_valid(ac->link_section)) {
|
||||
error(elem, "Invalid link section: %.*s", LIT(ac->link_section));
|
||||
}
|
||||
} else {
|
||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ struct AttributeContext {
|
||||
bool set_cold;
|
||||
String link_name;
|
||||
String link_prefix;
|
||||
String link_section;
|
||||
isize init_expr_list_count;
|
||||
String thread_local_model;
|
||||
String deprecated_message;
|
||||
|
||||
@@ -158,6 +158,7 @@ struct Entity {
|
||||
Ast * foreign_library_ident;
|
||||
String link_name;
|
||||
String link_prefix;
|
||||
String link_section;
|
||||
bool is_foreign;
|
||||
bool is_export;
|
||||
} Variable;
|
||||
|
||||
@@ -14880,6 +14880,9 @@ void lb_generate_code(lbGenerator *gen) {
|
||||
LLVMSetLinkage(g.value, LLVMInternalLinkage);
|
||||
}
|
||||
}
|
||||
if (e->Variable.link_section.len > 0) {
|
||||
LLVMSetSection(g.value, alloc_cstring(permanent_allocator(), e->Variable.link_section));
|
||||
}
|
||||
|
||||
lbGlobalVariable var = {};
|
||||
var.var = g;
|
||||
|
||||
Reference in New Issue
Block a user