Merge branch 'master' into bill/bedrock

This commit is contained in:
gingerBill
2026-06-24 11:07:02 +01:00
committed by GitHub
296 changed files with 26882 additions and 12209 deletions

View File

@@ -2063,7 +2063,8 @@ gb_internal bool lb_init_global_var(lbModule *m, lbProcedure *p, Entity *e, Ast
GB_ASSERT(!var.is_initialized);
Type *t = type_deref(var.var.type);
if (is_type_any(t)) {
// NOTE: 'any' literals or 'any's that point to other variables can be handled by the generic path
if (is_type_any(t) && !is_type_any(var.init.type) && init_expr->tav.mode != Addressing_Variable) {
// NOTE(bill): Edge case for 'any' type
Type *var_type = default_type(var.init.type);
gbString var_name = gb_string_make(permanent_allocator(), "__$global_any::");
@@ -2166,6 +2167,9 @@ gb_internal lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProc
lbProcedure *p = lb_create_dummy_procedure(main_module, str_lit(LB_STARTUP_RUNTIME_PROC_NAME), proc_type);
p->is_startup = true;
if (build_context.no_plt) {
lb_add_attribute_to_proc(p->module, p->value, "nonlazybind");
}
lb_add_attribute_to_proc(p->module, p->value, "optnone");
lb_add_attribute_to_proc(p->module, p->value, "noinline");
@@ -2186,6 +2190,9 @@ gb_internal lbProcedure *lb_create_cleanup_runtime(lbModule *main_module) { // C
lbProcedure *p = lb_create_dummy_procedure(main_module, str_lit(LB_CLEANUP_RUNTIME_PROC_NAME), proc_type);
p->is_startup = true;
if (build_context.no_plt) {
lb_add_attribute_to_proc(p->module, p->value, "nonlazybind");
}
lb_add_attribute_to_proc(p->module, p->value, "optnone");
lb_add_attribute_to_proc(p->module, p->value, "noinline");
@@ -3172,42 +3179,12 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
// NOTE(bill, 2021-05-04): Target machines must be unique to each module because they are not thread safe
auto target_machines = array_make<LLVMTargetMachineRef>(permanent_allocator(), 0, gen->modules.count);
// NOTE(dweiler): Dynamic libraries require position-independent code.
LLVMRelocMode reloc_mode = LLVMRelocDefault;
if (build_context.build_mode == BuildMode_DynamicLibrary) {
reloc_mode = LLVMRelocPIC;
}
switch (build_context.reloc_mode) {
case RelocMode_Default:
if (build_context.metrics.os == TargetOs_openbsd || build_context.metrics.os == TargetOs_haiku) {
// Always use PIC for OpenBSD and Haiku: they default to PIE
reloc_mode = LLVMRelocPIC;
}
if (build_context.metrics.arch == TargetArch_riscv64) {
// NOTE(laytan): didn't seem to work without this.
reloc_mode = LLVMRelocPIC;
}
break;
case RelocMode_Static:
reloc_mode = LLVMRelocStatic;
break;
case RelocMode_PIC:
reloc_mode = LLVMRelocPIC;
break;
case RelocMode_DynamicNoPIC:
reloc_mode = LLVMRelocDynamicNoPic;
break;
}
for (auto const &entry : gen->modules) {
LLVMTargetMachineRef target_machine = LLVMCreateTargetMachine(
target, target_triple, (const char *)llvm_cpu.text,
llvm_features,
code_gen_level,
reloc_mode,
get_reloc_mode(),
code_mode);
lbModule *m = entry.value;
m->target_machine = target_machine;
@@ -3445,7 +3422,8 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
cc.link_section = e->Variable.link_section;
ExactValue v = tav.value;
lbValue init = lb_const_value(m, e->type, v, cc);
lbValue init = lb_const_value(m, e->type, v, tav.type, cc);
LLVMDeleteGlobal(g.value);
g.value = nullptr;