[no-plt] enable no-plt behavior on linux arm64 and amd64 targets

This commit is contained in:
A1029384756
2026-06-08 10:58:05 -04:00
parent 43b057dfeb
commit da742fc526
4 changed files with 26 additions and 0 deletions

View File

@@ -602,6 +602,7 @@ struct BuildContext {
RelocMode reloc_mode;
bool disable_red_zone;
bool disable_unwind;
bool no_plt;
isize max_error_count;
@@ -1902,6 +1903,12 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
if (bc->reloc_mode == RelocMode_Default) {
bc->reloc_mode = RelocMode_PIC;
}
switch (metrics->arch) {
case TargetArch_arm64:
case TargetArch_amd64:
bc->no_plt = true;
break;
}
} else if (metrics->os == TargetOs_openbsd) {
// Always use PIC for OpenBSD: it defaults to PIE
if (bc->reloc_mode == RelocMode_Default) {

View File

@@ -2142,6 +2142,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");
@@ -2162,6 +2165,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");

View File

@@ -59,6 +59,12 @@ gb_internal WORKER_TASK_PROC(lb_init_module_worker_proc) {
m->ctx = LLVMContextCreate();
m->mod = LLVMModuleCreateWithNameInContext(m->module_name, m->ctx);
// m->debug_builder = nullptr;
if (build_context.no_plt) {
LLVMAddModuleFlag(m->mod,
LLVMModuleFlagBehaviorWarning,
"RtLibUseGOT", 11,
LLVMValueAsMetadata(LLVMConstInt(LLVMInt32TypeInContext(m->ctx), 1, true)));
}
if (build_context.ODIN_DEBUG) {
enum {DEBUG_METADATA_VERSION = 3};

View File

@@ -2,6 +2,9 @@ gb_internal LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLV
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
GB_ASSERT_MSG(id != 0, "Unable to find %s", name);
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, type_count);
if (build_context.no_plt) {
lb_add_attribute_to_proc(p->module, ip, "nonlazybind");
}
LLVMTypeRef call_type = LLVMIntrinsicGetType(p->module->ctx, id, types, type_count);
return LLVMBuildCall2(p->builder, call_type, ip, args, arg_count, "");
}
@@ -153,6 +156,10 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
lb_ensure_abi_function_type(m, p);
lb_add_function_type_attributes(p->value, p->abi_function_type, p->abi_function_type->calling_convention);
if (build_context.no_plt) {
lb_add_attribute_to_proc(m, p->value, "nonlazybind");
}
if (build_context.disable_unwind) {
lb_add_attribute_to_proc(m, p->value, "nounwind");
}