[llvm] [SPARC][IAS] Add v8plus feature bit (PR #101367)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 31 18:22:44 PDT 2024
================
@@ -21,11 +21,16 @@ using namespace llvm;
namespace {
class SparcELFObjectWriter : public MCELFObjectTargetWriter {
public:
- SparcELFObjectWriter(bool Is64Bit, bool HasV9, uint8_t OSABI)
+ SparcELFObjectWriter(bool Is64Bit, bool IsV8Plus, bool HasV9, uint8_t OSABI)
: MCELFObjectTargetWriter(
Is64Bit, OSABI,
- Is64Bit ? ELF::EM_SPARCV9
- : (HasV9 ? ELF::EM_SPARC32PLUS : ELF::EM_SPARC),
+ Is64Bit
+ ? ELF::EM_SPARCV9
+ // Note that we still need to emit an EM_SPARC32PLUS object
+ // even when V8+ isn't explicitly requested, if we're
+ // targeting a V9-capable CPU. This matches GAS behavior upon
+ // encountering any V9 instructions in its input.
+ : ((IsV8Plus || HasV9) ? ELF::EM_SPARC32PLUS : ELF::EM_SPARC),
----------------
koachan wrote:
> This is a pretty surprising behavior given that there are assembler [options for V8+](https://sourceware.org/binutils/docs/as/Sparc_002dOpts.html) and a note:
>
> > Use one of the ‘-A’ options to select one of the SPARC architectures explicitly. If you select an architecture explicitly, as reports a fatal error if it encounters an instruction or feature requiring an incompatible or higher level.
>
> The thing that concerns me is that we unconditionally create SPARC32PLUS objects that the linker might reject to link with SPARC objects. Even if it does not complain, the resulting V8+ executable might be rejected by the loader if the OS does not support V8+.
Mhm. Looking at the output of `gcc -v`, it does make use of `-Av8plus` and friends, it's just it doesn't seem to affect the emitted binary.
On the other hand, the wording in the V8+ spec seems to imply that any 32-bit binaries that use any V9 features must be tagged as V8+ anyways, regardless of whether it uses 64-bit registers or not. From page 2-5:
> A binary that uses SPARC V9 and UltraSPARC features, referred to as a V8+ binary, must contain an indication of this in its ELF header since it will not execute in a vanilla V8 environment.
- - - - -
> With that said I think we should create V8+ objects only when explicitly requested. Can we do this or the kernel buildsystem relies on gas bumping ISA level? (Does it not pass -mv8plus to the compiler driver?)
In any case, though, the kernel does set `-mv8plus` in its CFLAGS, so I suppose it would be fine too if we create V8+ objects only when requested?
https://github.com/llvm/llvm-project/pull/101367
More information about the llvm-commits
mailing list