Skip to content
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

cannot link object files with different floating-point ABI on RV32 target #22727

Open
XiangYyang opened this issue Feb 3, 2025 · 0 comments
Open
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@XiangYyang
Copy link

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

Start a new project and use zig init. Then, set the target in build.zig.

    const target_query = .{
        .cpu_arch = .riscv32,
        .cpu_model = .{ .explicit = &std.Target.riscv.cpu.baseline_rv32 },
        .os_tag = .freestanding,
        .abi = .eabi,
    };

    // reslove target
    const target = b.resolveTargetQuery(target_query);

    // ...
    const exe = b.addExecutable(.{
        .name = "test",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

Then, create an assembly source file like the following, and add it to the exe archive.

; A rv32 asm source file, like `src/asmfile.s`
.section    .text._start, "ax", @progbits
.globl       _start
.align      1
_start:
	    j   _start 
// add it into `exe`
exe.addAssemblyFile(b.path("src/asmfile.s"));

Now try to run zig build, and if everything works, you will get an elf file. However, when I enable lto, an error occurs. Modify the build.zig to add the LTO.

exe.want_lto = true;

And re-run zig build, the ld.lld said.

error: ld.lld: D:\a\test\.zig-cache\o\somehash\test.lto.o:
       cannot link object files with different floating-point ABI from D:\a\test\.zig-cache\o\somehash\asmfile.o

I tried reading the elf header file with readelf and found that the header of asmfile.o is different from the header of the zig build output file without LTO.

# asmfile.o
ELF Header:
  ...
  Flags:                             0x5, RVC, double-float ABI
# `zig build` output with exe.want_lto = true; excluding the assembly file
ELF Header:
  ...
  Flags:                             0x0
# `zig build` output with exe.want_lto = false; excluding the assembly file
ELF Header:
  ...
  Flags:                             0x5, RVC, double-float ABI

It looks like it's caused by something missing from the ELF header on the LTO output.

Is this a bug? how should I fix it

Expected Behavior

baseline_rv32 is rv32iamcd, so it includes the D extension, so LTO's ELF Header should include double-float ABI

  1. The ELF Header for LTO's output should also have double-float ABI
@XiangYyang XiangYyang added the bug Observed behavior contradicts documented or intended behavior label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant