diff options
author | Sam Clegg <sbc@chromium.org> | 2021-02-26 16:09:32 -0800 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2021-05-10 16:03:38 -0700 |
commit | 3b8d2be527259b303d6c3428df16fb3fd02af2bc (patch) | |
tree | 6a69ec8fe4f7a3702ee855682bdcc33717e9f470 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | 7b52aeadfa38c8a1fc0e97066f50900f1efafd42 (diff) | |
download | llvm-3b8d2be527259b303d6c3428df16fb3fd02af2bc.zip llvm-3b8d2be527259b303d6c3428df16fb3fd02af2bc.tar.gz llvm-3b8d2be527259b303d6c3428df16fb3fd02af2bc.tar.bz2 |
Reland: "[lld][WebAssembly] Initial support merging string data"
This change was originally landed in: 5000a1b4b9edeb9e994f2a5b36da8d48599bea49
It was reverted in: 061e071d8c9b98526f35cad55a918a4f1615afd4
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.cpp | 21 |
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( |