zig icon indicating copy to clipboard operation
zig copied to clipboard

`std.Target`: Bump baseline CPU for sparc32 to v9; add `sparcv9-linux-gnu` to `process_headers.zig`

Open alexrp opened this issue 1 year ago • 6 comments

It is impossible to even build projects like glibc when targeting a generic SPARC v8 CPU; LEON3 is effectively considered the baseline for sparc-linux-gnu now, particularly due to it supporting a CASA instruction similar to the one in SPARC v9. However, it's slightly incompatible with SPARC v9 due to having a different ASI tag, so resulting binaries would not be portable to regular SPARC CPUs. So, as the least bad option, make v9 the baseline for sparc32.

https://sourceware.org/git/?p=glibc.git;a=blob;f=scripts/build-many-glibcs.py;h=8bfe29876d8a137be7622a1a00c8566829a1365d;hb=HEAD#l460

alexrp avatar Aug 04 '24 09:08 alexrp

cc @koachan (tell me if these review requests are too much :slightly_smiling_face:)

alexrp avatar Aug 04 '24 09:08 alexrp

Hmmm, not really sure if we should default to LEON instead of 32-bit V9 - especially since all the other compilers I know targets V9 by default. The issue is that LEONs use a slightly different (and incompatible) use of CASA compared to desktop/server V9 systems:

// LEON-style CAS
casa [ptr] 0x0A, cmp, xchg // 0x0A = #ASI_USER_DATA

// V9-style CAS
casa [ptr] 0x80, cmp, xchg // 0x80 = #ASI_PRIMARY

(i.e the ASI tags are different)

But otherwise the changes look fine.

koachan avatar Aug 04 '24 18:08 koachan

Well, if you build GCC for sparc-linux-gnu for example, that GCC will fail to build glibc because it targets generic SPARC v8. But if you configure GCC with --with-cpu=leon3, it works.

Not necessarily against bumping the baseline to 32-bit v9. That might make sense too. I'm just going off GCC's behavior here.

alexrp avatar Aug 04 '24 18:08 alexrp

Hmm. Just to be clear, compiling for 32-bit v9 would still mean using the v8 ABI, right? As long as that's true, then this might be the way to go. Agree that it's bad if resulting binaries are only compatible with LEON processors by default.

alexrp avatar Aug 04 '24 18:08 alexrp

Hmm. Just to be clear, compiling for 32-bit v9 would still mean using the v8 ABI, right? As long as that's true, then this might be the way to go. Agree that it's bad if resulting binaries are only compatible with LEON processors by default.

Yep, code for 32-bit V9 and V8 can be mixed freely.

koachan avatar Aug 05 '24 01:08 koachan

Ok, I changed the PR to bump the sparc32 baseline CPU to v9 instead.

alexrp avatar Aug 05 '24 10:08 alexrp