Add @(link_section=<string>) for global variables

This commit is contained in:
gingerBill
2021-05-24 15:41:22 +01:00
parent 79f115d6a7
commit c440296ae8
5 changed files with 18 additions and 0 deletions
+3
View File
@@ -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;
+10
View File
@@ -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;
}
+1
View File
@@ -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;
+1
View File
@@ -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;
+3
View File
@@ -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;