[WebAssembly] Add skeleton MC support for the Wasm container format

This just adds the basic skeleton for supporting a new object file format.
All of the actual encoding will be implemented in followup patches.

Differential Revision: https://reviews.llvm.org/D26722


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295803 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2017-02-22 01:23:18 +00:00
parent 9a736108d4
commit d660a5d68c
35 changed files with 1307 additions and 22 deletions
@@ -30,8 +30,10 @@
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSectionWasm.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCSymbolWasm.h"
#include "llvm/MC/MCValue.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/COFF.h"
@@ -1155,3 +1157,53 @@ void TargetLoweringObjectFileCOFF::emitLinkerFlagsForGlobal(
raw_ostream &OS, const GlobalValue *GV) const {
emitLinkerFlagsForGlobalCOFF(OS, GV, getTargetTriple(), getMangler());
}
//===----------------------------------------------------------------------===//
// Wasm
//===----------------------------------------------------------------------===//
MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
llvm_unreachable("getExplicitSectionGlobal not yet implemented");
return nullptr;
}
MCSection *TargetLoweringObjectFileWasm::SelectSectionForGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
if (Kind.isText())
return TextSection;
assert(!Kind.isMetadata() && "metadata sections not yet implemented");
return DataSection;
}
bool TargetLoweringObjectFileWasm::shouldPutJumpTableInFunctionSection(
bool UsesLabelDifference, const Function &F) const {
// We can always create relative relocations, so use another section
// that can be marked non-executable.
return false;
}
const MCExpr *TargetLoweringObjectFileWasm::lowerRelativeReference(
const GlobalValue *LHS, const GlobalValue *RHS,
const TargetMachine &TM) const {
// We may only use a PLT-relative relocation to refer to unnamed_addr
// functions.
if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
return nullptr;
// Basic sanity checks.
if (LHS->getType()->getPointerAddressSpace() != 0 ||
RHS->getType()->getPointerAddressSpace() != 0 || LHS->isThreadLocal() ||
RHS->isThreadLocal())
return nullptr;
return MCBinaryExpr::createSub(
MCSymbolRefExpr::create(TM.getSymbol(LHS), MCSymbolRefExpr::VK_None,
getContext()),
MCSymbolRefExpr::create(TM.getSymbol(RHS), getContext()), getContext());
}
void
TargetLoweringObjectFileWasm::InitializeWasm() {
// TODO: Initialize StaticCtorSection and StaticDtorSection.
}