aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-03-20 11:40:34 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:43:05 +0000
commit349cc55c9796c4596a5b9904cd3281af295f878f (patch)
tree410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
parentcb2ae6163174b90e999326ecec3699ee093a5d43 (diff)
parentc0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp59
1 files changed, 38 insertions, 21 deletions
diff --git a/contrib/llvm-project/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/contrib/llvm-project/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
index 1adf0ad9c0e5..f7b83c45022d 100644
--- a/contrib/llvm-project/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ b/contrib/llvm-project/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -27,10 +27,10 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
+#include "llvm/MC/TargetRegistry.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/TargetRegistry.h"
#include <memory>
#include <utility>
@@ -264,31 +264,48 @@ public:
std::string Error;
auto Triple = Ctx.getTargetInfo().getTriple();
if (!llvm::TargetRegistry::lookupTarget(Triple.getTriple(), Error))
- llvm::report_fatal_error(Error);
+ llvm::report_fatal_error(llvm::Twine(Error));
// Emit the serialized Clang AST into its own section.
assert(Buffer->IsComplete && "serialization did not complete");
auto &SerializedAST = Buffer->Data;
auto Size = SerializedAST.size();
- auto Int8Ty = llvm::Type::getInt8Ty(*VMContext);
- auto *Ty = llvm::ArrayType::get(Int8Ty, Size);
- auto *Data = llvm::ConstantDataArray::getString(
- *VMContext, StringRef(SerializedAST.data(), Size),
- /*AddNull=*/false);
- auto *ASTSym = new llvm::GlobalVariable(
- *M, Ty, /*constant*/ true, llvm::GlobalVariable::InternalLinkage, Data,
- "__clang_ast");
- // The on-disk hashtable needs to be aligned.
- ASTSym->setAlignment(llvm::Align(8));
-
- // Mach-O also needs a segment name.
- if (Triple.isOSBinFormatMachO())
- ASTSym->setSection("__CLANG,__clangast");
- // COFF has an eight character length limit.
- else if (Triple.isOSBinFormatCOFF())
- ASTSym->setSection("clangast");
- else
- ASTSym->setSection("__clangast");
+
+ if (Triple.isOSBinFormatWasm()) {
+ // Emit __clangast in custom section instead of named data segment
+ // to find it while iterating sections.
+ // This could be avoided if all data segements (the wasm sense) were
+ // represented as their own sections (in the llvm sense).
+ // TODO: https://github.com/WebAssembly/tool-conventions/issues/138
+ llvm::NamedMDNode *MD =
+ M->getOrInsertNamedMetadata("wasm.custom_sections");
+ llvm::Metadata *Ops[2] = {
+ llvm::MDString::get(*VMContext, "__clangast"),
+ llvm::MDString::get(*VMContext,
+ StringRef(SerializedAST.data(), Size))};
+ auto *NameAndContent = llvm::MDTuple::get(*VMContext, Ops);
+ MD->addOperand(NameAndContent);
+ } else {
+ auto Int8Ty = llvm::Type::getInt8Ty(*VMContext);
+ auto *Ty = llvm::ArrayType::get(Int8Ty, Size);
+ auto *Data = llvm::ConstantDataArray::getString(
+ *VMContext, StringRef(SerializedAST.data(), Size),
+ /*AddNull=*/false);
+ auto *ASTSym = new llvm::GlobalVariable(
+ *M, Ty, /*constant*/ true, llvm::GlobalVariable::InternalLinkage,
+ Data, "__clang_ast");
+ // The on-disk hashtable needs to be aligned.
+ ASTSym->setAlignment(llvm::Align(8));
+
+ // Mach-O also needs a segment name.
+ if (Triple.isOSBinFormatMachO())
+ ASTSym->setSection("__CLANG,__clangast");
+ // COFF has an eight character length limit.
+ else if (Triple.isOSBinFormatCOFF())
+ ASTSym->setSection("clangast");
+ else
+ ASTSym->setSection("__clangast");
+ }
LLVM_DEBUG({
// Print the IR for the PCH container to the debug output.