aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2021-02-26 16:09:32 -0800
committerSam Clegg <sbc@chromium.org>2021-05-10 13:15:12 -0700
commit5000a1b4b9edeb9e994f2a5b36da8d48599bea49 (patch)
tree2ea607d953c66899df9e9b9af3e1562dd3062f28 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parent85af8a8c1b574faa0d5d57d189ae051debdfada8 (diff)
downloadllvm-5000a1b4b9edeb9e994f2a5b36da8d48599bea49.zip
llvm-5000a1b4b9edeb9e994f2a5b36da8d48599bea49.tar.gz
llvm-5000a1b4b9edeb9e994f2a5b36da8d48599bea49.tar.bz2
[lld][WebAssembly] Initial support merging string data
This change adds support for a new WASM_SEG_FLAG_STRINGS flag in the object format which works in a similar fashion to SHF_STRINGS in the ELF world. Unlike the ELF linker this support is currently limited: - No support for SHF_MERGE (non-string merging) - Always do full tail merging ("lo" can be merged with "hello") - Only support single byte strings (p2align 0) Like the ELF linker merging is only performed at `-O1` and above. This fixes part of https://bugs.llvm.org/show_bug.cgi?id=48828, although crucially it doesn't not currently support debug sections because they are not represented by data segments (they are custom sections) Differential Revision: https://reviews.llvm.org/D97657
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 3227fd7..54d65cc 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -21,6 +21,7 @@
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/BinaryFormat/MachO.h"
+#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/CodeGen/BasicBlockSectionUtils.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
@@ -2005,6 +2006,17 @@ static const Comdat *getWasmComdat(const GlobalValue *GV) {
return C;
}
+static unsigned getWasmSectionFlags(SectionKind K) {
+ unsigned Flags = 0;
+
+ // TODO(sbc): Add suport for K.isMergeableConst()
+
+ if (K.isMergeableCString())
+ Flags |= wasm::WASM_SEG_FLAG_STRINGS;
+
+ return Flags;
+}
+
MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
// We don't support explict section names for functions in the wasm object
@@ -2028,9 +2040,9 @@ MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
Group = C->getName();
}
- MCSectionWasm* Section =
- getContext().getWasmSection(Name, Kind, Group,
- MCContext::GenericSectionID);
+ unsigned Flags = getWasmSectionFlags(Kind);
+ MCSectionWasm *Section = getContext().getWasmSection(
+ Name, Kind, Flags, Group, MCContext::GenericSectionID);
return Section;
}
@@ -2062,7 +2074,8 @@ static MCSectionWasm *selectWasmSectionForGlobal(
(*NextUniqueID)++;
}
- return Ctx.getWasmSection(Name, Kind, Group, UniqueID);
+ unsigned Flags = getWasmSectionFlags(Kind);
+ return Ctx.getWasmSection(Name, Kind, Flags, Group, UniqueID);
}
MCSection *TargetLoweringObjectFileWasm::SelectSectionForGlobal(