Skip to content

driver: build for a declared host in emit-obj and --run, and add the riscv64 arm (#4308) - #4432

Open
SycamoreQ wants to merge 3 commits into
vx-lang:mainfrom
SycamoreQ:riscv/target-riscv64-arm
Open

SycamoreQ wants to merge 3 commits into
vx-lang:mainfrom
SycamoreQ:riscv/target-riscv64-arm

Conversation

@SycamoreQ

Copy link
Copy Markdown
Contributor

Part of #4308 (P0.1 of #4305), on top of #4430. That PR moved the target-fact table to arch::base_for_arch; this one makes the run and object paths use it.

Because both branches share #4430's commit, the diff against main shows both PRs until #4430 merges. Only the commit driver: build for a declared host in emit-obj and --run, and add the riscv64 arm is new here.

What

Verification

In the repo's Linux LLVM 22 container (x86_64):

  • a program built against a declared arch: riscv64 host gives an object whose ELF header reads Machine: EM_RISCV (0xF3), Flags: 0x5 (RVC + double-float ABI, the lp64d the ABI column asks for), and an emit-llvm module carrying llvm.target_triple = "riscv64-unknown-linux-gnu", the lp64d data layout, and "target-features" = "+m,+a,+f,+d,+c";
  • the same program against a declared x86_64 host gives Machine: EM_X86_64 -- no regression;
  • cargo check --workspace --all-targets, cargo test -p vxc --lib (1075 tests), cargo clippy --workspace --all-targets --all-features -- -D warnings, and cargo fmt --check are clean. Unit tests in arch.rs cover the riscv64 facts, the isa:/features: merge, and the refusal word for word.

Not here yet

…base_for_arch

arch_triple_and_datalayout moves to arch::base_for_arch and gains the base
feature and ABI columns the run and object paths need (vx-lang#4308). The x86_64
and aarch64 data layout strings are stale copies of LLVM's defaults
(missing i128:128 and the p270/p271/p272 + Fn32 entries respectively);
both are corrected against LLVM 22.1.8 and pinned by tests.
…riscv64 arm

TargetSpec carries the triple, data layout, CPU, features and ABI of the
host a --host file declares, and the run and object paths take the target
from it instead of llvm-config --host-target and -mcpu=native (vx-lang#4308,
vx-lang#4305 P0.1). -mcpu=native stays the native path's alone (vx-lang#4305 decision
3): a declared build, even on the machine running vxc, names no CPU, so
it is reproducible.

riscv64 answers its arm: the triple riscv64-unknown-linux-gnu, the lp64d
data layout, the base features +m,+a,+f,+d,+c always, and
-target-abi=lp64d -- without them a weak feature set gives soft-float
code that does not link with glibc. emit-llvm writes the triple, the
layout and target-features as module attributes; the object path runs
llc with the same facts.

A declared arch the machine running vxc cannot run is refused with a
message naming vx-lang#4309 (cross linking) and vx-lang#4310 (running under an
emulator), rather than linking and running as the wrong machine, which
is what emit-obj and --run did before this change.
host_arch_of prefers a host the program itself declares over the
synthesised native one, and it exists for the triple emit-llvm stamps
(vx-lang#342), not for machine code. Building the run and object target from it
made --emit-mlir refuse a program that declares a spirv64 device
topology, and the backend corpus, which passes no --host, stopped
producing its objects (the spirv64 local-device test failed on CI).

The run and object paths now take the declaration from --host alone:
a file naming a host builds for it, --host default and no --host build
for the machine vxc runs on, as they always have. emit-llvm keeps
answering host_arch_of, where the derivation belongs.
@SycamoreQ

Copy link
Copy Markdown
Contributor Author

The two CI failures are fixed in ce3880f, and the cause is worth recording.

host_arch_of answers the arch of a host the program itself declares when no --host names one: a program with Topology Dev { arch: spirv64 } (the local-device test) answers spirv64. That derivation exists for the triple emit-llvm stamps (#342). Building the run and object target from it turned that answer into a refusal for every action -- so --emit-mlir on that test failed, and the emit-obj corpus, which passes no --host at all, lost its objects.

The fix: the run and object paths build for a declared host only when --host names a host file. --host default and no --host build for the machine vxc runs on, exactly as before. emit-llvm keeps answering host_arch_of, where the derivation belongs.

Re-verified in the LLVM 22 container: the spirv64 test's --emit-mlir prints vx.local_devices again, its --action emit-obj produces an object, --action emit-llvm still refuses it (the behavior of #4430), a declared riscv64 --host still gives EM_RISCV with Flags: 0x5, and cargo test -p vxc --lib (1075 tests), clippy -D warnings and cargo fmt --check are clean.

@SycamoreQ

Copy link
Copy Markdown
Contributor Author

working on the integration tests and topology parsing. Will update it soon

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant