[PATCH] D74531: [WebAssembly] Emit PCH __clang_ast in custom section
Yuta Saito via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 01:44:56 PST 2020
kateinoigakukun created this revision.
kateinoigakukun added a project: LLVM.
Herald added subscribers: llvm-commits, sunfish, aheejin, hiraditya, jgravelle-google, sbc100, dschuff.
kateinoigakukun added reviewers: dschuff, uweigand.
Resolve https://bugs.llvm.org/show_bug.cgi?id=35928 to promote Swift for WebAssembly
`__clang_ast` section should be aligned by 4 bytes, so I added padding after the size of custom section name.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74531
Files:
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/MC/WasmObjectWriter.cpp
Index: llvm/lib/MC/WasmObjectWriter.cpp
===================================================================
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -373,7 +373,16 @@
Section.PayloadOffset = W.OS.tell();
// Custom sections in wasm also have a string identifier.
- writeString(Name);
+ if (Name != "__clangast") {
+ writeString(Name);
+ } else {
+ // pad section start to nearest 4 bytes for Clang PCH
+ uint64_t MinLength =
+ Section.PayloadOffset + 5ULL /* min ULEB128 length */ + Name.size();
+ uint64_t RoundedUpLength = (MinLength + 3ULL) & ~3ULL;
+ encodeULEB128(Name.size(), W.OS, 5 + (RoundedUpLength - MinLength));
+ W.OS << Name;
+ }
// The position where the custom section starts.
Section.ContentsOffset = W.OS.tell();
@@ -1099,6 +1108,10 @@
if (Sym.isSection())
return false;
+ // Clang's precompiled headers are in a separate custom section
+ if (Sym.getName() == "__clang_ast")
+ return false;
+
return true;
}
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1696,6 +1696,10 @@
if (K.isText())
return SectionKind::getText();
+ // Clang precompiled header data isn't needed at runtime; use custom section
+ if (Name == "__clangast")
+ return SectionKind::getMetadata();
+
// Otherwise, ignore whatever section type the generic impl detected and use
// a plain data section.
return SectionKind::getData();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74531.244358.patch
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200213/3d675146/attachment.bin>
More information about the llvm-commits
mailing list