forked from OSchip/llvm-project
[WebAssembly] Add a EM_WEBASSEMBLY value, and several bits of code that use it.
A request has been made to the official registry, but an official value is not yet available. This patch uses a temporary value in order to support development. When an official value is recieved, the value of EM_WEBASSEMBLY will be updated. llvm-svn: 257517
This commit is contained in:
parent
45c7439d11
commit
4635017176
|
@ -842,6 +842,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
|
|||
case ELF::EM_SPARC:
|
||||
case ELF::EM_SPARC32PLUS:
|
||||
return "ELF32-sparc";
|
||||
case ELF::EM_WEBASSEMBLY:
|
||||
return "ELF32-wasm";
|
||||
default:
|
||||
return "ELF32-unknown";
|
||||
}
|
||||
|
@ -861,6 +863,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
|
|||
return "ELF64-sparc";
|
||||
case ELF::EM_MIPS:
|
||||
return "ELF64-mips";
|
||||
case ELF::EM_WEBASSEMBLY:
|
||||
return "ELF64-wasm";
|
||||
default:
|
||||
return "ELF64-unknown";
|
||||
}
|
||||
|
@ -908,6 +912,12 @@ unsigned ELFObjectFile<ELFT>::getArch() const {
|
|||
return IsLittleEndian ? Triple::sparcel : Triple::sparc;
|
||||
case ELF::EM_SPARCV9:
|
||||
return Triple::sparcv9;
|
||||
case ELF::EM_WEBASSEMBLY:
|
||||
switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
|
||||
case ELF::ELFCLASS32: return Triple::wasm32;
|
||||
case ELF::ELFCLASS64: return Triple::wasm64;
|
||||
default: return Triple::UnknownArch;
|
||||
}
|
||||
|
||||
default:
|
||||
return Triple::UnknownArch;
|
||||
|
|
|
@ -309,7 +309,12 @@ enum {
|
|||
EM_COOL = 217, // iCelero CoolEngine
|
||||
EM_NORC = 218, // Nanoradio Optimized RISC
|
||||
EM_CSR_KALIMBA = 219, // CSR Kalimba architecture family
|
||||
EM_AMDGPU = 224 // AMD GPU architecture
|
||||
EM_AMDGPU = 224, // AMD GPU architecture
|
||||
|
||||
// A request has been made to the maintainer of the official registry for
|
||||
// such numbers for an official value for WebAssembly. As soon as one is
|
||||
// allocated, this enum will be updated to use it.
|
||||
EM_WEBASSEMBLY = 0x4157, // WebAssembly architecture
|
||||
};
|
||||
|
||||
// Object file classes.
|
||||
|
|
|
@ -91,6 +91,13 @@ StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case ELF::EM_WEBASSEMBLY:
|
||||
switch (Type) {
|
||||
#include "llvm/Support/ELFRelocs/WebAssembly.def"
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -30,13 +30,10 @@ protected:
|
|||
};
|
||||
} // end anonymous namespace
|
||||
|
||||
// FIXME: Use EM_NONE as a temporary hack. Should we decide to pursue ELF
|
||||
// writing seriously, we should email generic-abi@googlegroups.com and ask
|
||||
// for our own ELF code.
|
||||
WebAssemblyELFObjectWriter::WebAssemblyELFObjectWriter(bool Is64Bit,
|
||||
uint8_t OSABI)
|
||||
: MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_NONE,
|
||||
/*HasRelocationAddend=*/true) {}
|
||||
: MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_WEBASSEMBLY,
|
||||
/*HasRelocationAddend=*/false) {}
|
||||
|
||||
unsigned WebAssemblyELFObjectWriter::GetRelocType(const MCValue &Target,
|
||||
const MCFixup &Fixup,
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
|
||||
#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
|
||||
|
||||
#include "llvm/CodeGen/MachineValueType.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
|
||||
namespace llvm {
|
||||
|
|
|
@ -7,6 +7,7 @@ target triple = "wasm32-unknown-unknown"
|
|||
|
||||
; CHECK-LABEL: f0:
|
||||
; CHECK: return{{$}}
|
||||
; CHECK: .endfunc{{$}}
|
||||
; CHECK: .size f0,
|
||||
define void @f0() {
|
||||
ret void
|
||||
|
|
|
@ -482,6 +482,23 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
|||
case ELF::EM_MIPS:
|
||||
res = Target;
|
||||
break;
|
||||
case ELF::EM_WEBASSEMBLY:
|
||||
switch (type) {
|
||||
case ELF::R_WEBASSEMBLY_DATA: {
|
||||
std::string fmtbuf;
|
||||
raw_string_ostream fmt(fmtbuf);
|
||||
fmt << Target << (addend < 0 ? "" : "+") << addend;
|
||||
fmt.flush();
|
||||
Result.append(fmtbuf.begin(), fmtbuf.end());
|
||||
break;
|
||||
}
|
||||
case ELF::R_WEBASSEMBLY_FUNCTION:
|
||||
res = Target;
|
||||
break;
|
||||
default:
|
||||
res = "Unknown";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
res = "Unknown";
|
||||
}
|
||||
|
|
|
@ -708,7 +708,8 @@ static const EnumEntry<unsigned> ElfMachineType[] = {
|
|||
LLVM_READOBJ_ENUM_ENT(ELF, EM_VIDEOCORE5 ),
|
||||
LLVM_READOBJ_ENUM_ENT(ELF, EM_78KOR ),
|
||||
LLVM_READOBJ_ENUM_ENT(ELF, EM_56800EX ),
|
||||
LLVM_READOBJ_ENUM_ENT(ELF, EM_AMDGPU )
|
||||
LLVM_READOBJ_ENUM_ENT(ELF, EM_AMDGPU ),
|
||||
LLVM_READOBJ_ENUM_ENT(ELF, EM_WEBASSEMBLY ),
|
||||
};
|
||||
|
||||
static const EnumEntry<unsigned> ElfSymbolBindings[] = {
|
||||
|
|
Loading…
Reference in New Issue