summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-04-26 19:27:28 +0000
committerSam Clegg <sbc@chromium.org>2018-04-26 19:27:28 +0000
commit6a31a0d694a65f5cb11ae6d49c7fdb3f08b0d262 (patch)
tree80ffd86a99679f42be9cb191dcd65305be55e03a /llvm/lib/Target
parent540512c29719dc98429961c38fa882bcfef1de40 (diff)
downloadbcm5719-llvm-6a31a0d694a65f5cb11ae6d49c7fdb3f08b0d262.tar.gz
bcm5719-llvm-6a31a0d694a65f5cb11ae6d49c7fdb3f08b0d262.zip
[WebAssembly] Write DWARF data into wasm object file
- Writes ".debug_XXX" into corresponding custom sections. - Writes relocation records into "reloc.debug_XXX" sections. Patch by Yury Delendik! Differential Revision: https://reviews.llvm.org/D44184 llvm-svn: 330982
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r--llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
index 39abde26df7..ab0125e7c28 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
@@ -20,9 +20,10 @@
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCFixupKindInfo.h"
#include "llvm/MC/MCObjectWriter.h"
+#include "llvm/MC/MCSectionWasm.h"
#include "llvm/MC/MCSymbolWasm.h"
-#include "llvm/MC/MCWasmObjectWriter.h"
#include "llvm/MC/MCValue.h"
+#include "llvm/MC/MCWasmObjectWriter.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
@@ -61,6 +62,25 @@ static bool IsFunctionType(const MCValue &Target) {
return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX;
}
+static const MCSection *GetFixupSection(const MCExpr *Expr) {
+ if (auto SyExp = dyn_cast<MCSymbolRefExpr>(Expr)) {
+ if (SyExp->getSymbol().isInSection())
+ return &SyExp->getSymbol().getSection();
+ return nullptr;
+ }
+
+ if (auto BinOp = dyn_cast<MCBinaryExpr>(Expr)) {
+ auto SectionLHS = GetFixupSection(BinOp->getLHS());
+ auto SectionRHS = GetFixupSection(BinOp->getRHS());
+ return SectionLHS == SectionRHS ? nullptr : SectionLHS;
+ }
+
+ if (auto UnOp = dyn_cast<MCUnaryExpr>(Expr))
+ return GetFixupSection(UnOp->getSubExpr());
+
+ return nullptr;
+}
+
unsigned
WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target,
const MCFixup &Fixup) const {
@@ -86,6 +106,13 @@ WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target,
case FK_Data_4:
if (IsFunction)
return wasm::R_WEBASSEMBLY_TABLE_INDEX_I32;
+ if (auto Section = static_cast<const MCSectionWasm *>(
+ GetFixupSection(Fixup.getValue()))) {
+ if (Section->getKind().isText())
+ return wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32;
+ else if (!Section->isWasmData())
+ return wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32;
+ }
return wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32;
case FK_Data_8:
llvm_unreachable("FK_Data_8 not implemented yet");
OpenPOWER on IntegriCloud