Skip to content

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

Closed
@XiangYyang

Description

@XiangYyang

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions