New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
riscv64-linux-musl fails to build: cannot link object files with different floating-point ABI #4863
Comments
Check this out. |
I tried this diff: diff --git a/src/codegen.cpp b/src/codegen.cpp
index c9e67dcac..b2210ba0c 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -8940,10 +8940,17 @@ static void init(CodeGen *g) {
fprintf(stderr, "name=%s target_specific_cpu_args=%s\n", buf_ptr(g->root_out_name), target_specific_cpu_args);
fprintf(stderr, "name=%s target_specific_features=%s\n", buf_ptr(g->root_out_name), target_specific_features);
}
+
+ // TODO handle float ABI better- it should depend on the ABI portion of std.Target
+ ZigLLVMABIType float_abi = ZigLLVMABITypeDefault;
+ if (g->zig_target->os == OsLinux && target_is_riscv(g->zig_target)) {
+ // RISC-V Linux defaults to ilp32d/lp64d
+ float_abi = ZigLLVMABITypeHard;
+ }
g->target_machine = ZigLLVMCreateTargetMachine(target_ref, buf_ptr(&g->llvm_triple_str),
target_specific_cpu_args, target_specific_features, opt_level, reloc_mode,
- to_llvm_code_model(g), g->function_sections);
+ to_llvm_code_model(g), g->function_sections, float_abi);
g->target_data_ref = LLVMCreateTargetDataLayout(g->target_machine);
diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp
index 5569f90cd..e06683ef7 100644
--- a/src/zig_llvm.cpp
+++ b/src/zig_llvm.cpp
@@ -100,7 +100,7 @@ static const bool assertions_on = false;
LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple,
const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
- LLVMCodeModel CodeModel, bool function_sections)
+ LLVMCodeModel CodeModel, bool function_sections, ZigLLVMABIType float_abi)
{
Optional<Reloc::Model> RM;
switch (Reloc){
@@ -147,6 +147,17 @@ LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Tri
TargetOptions opt;
opt.FunctionSections = function_sections;
+ switch (float_abi) {
+ case ZigLLVMABITypeDefault:
+ opt.FloatABIType = FloatABI::Default;
+ break;
+ case ZigLLVMABITypeSoft:
+ opt.FloatABIType = FloatABI::Soft;
+ break;
+ case ZigLLVMABITypeHard:
+ opt.FloatABIType = FloatABI::Hard;
+ break;
+ }
TargetMachine *TM = reinterpret_cast<Target*>(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM,
OL, JIT);
diff --git a/src/zig_llvm.h b/src/zig_llvm.h
index c2c4b4dd7..24e14f2f7 100644
--- a/src/zig_llvm.h
+++ b/src/zig_llvm.h
@@ -51,9 +51,16 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi
bool is_small, bool time_report,
const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename);
+
+enum ZigLLVMABIType {
+ ZigLLVMABITypeDefault, // Target-specific (either soft or hard depending on triple, etc).
+ ZigLLVMABITypeSoft, // Soft float.
+ ZigLLVMABITypeHard // Hard float.
+};
+
ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple,
const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
- LLVMCodeModel CodeModel, bool function_sections);
+ LLVMCodeModel CodeModel, bool function_sections, ZigLLVMABIType float_abi);
ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref);
Still got the error "cannot link object files with different floating-point ABI". I wonder what the clang argumentsl |
@luismarques do you have any clues? What LLVM API do we need to match clang's behavior here? |
The |
Before, this would cause a link failure when mixing Zig and C code for RISC-V targets. Now, the ABIs match and Zig and C code can be mixed successfully. I will file a follow-up issue for the ability to deal more explicitly with ABIs. closes #4863
Before, this would cause a link failure when mixing Zig and C code for RISC-V targets. Now, the ABIs match and Zig and C code can be mixed successfully. I will file a follow-up issue for the ability to deal more explicitly with ABIs. closes #4863
Sorry, with the UK lockdown and the nurseries closing my available time has dramatically diminished, so I haven't been able to look into this. |
No worries @luismarques - btw this issue was solved with 11b50e3 |
Extracted from #4485. See also #4456.
The text was updated successfully, but these errors were encountered: