Skip to content
Snippets Groups Projects
Commit 55a8ec1e authored by Christian Dietrich's avatar Christian Dietrich
Browse files

ELF: store metadata in named metadata section

parent edb0f6af
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -2,6 +2,8 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/CodeGen/CodeGenAction.h"
#include "llvm/Support/raw_ostream.h"
#include "hash-visitor.h"
......@@ -15,9 +17,8 @@ public:
HashTranslationUnitConsumer(raw_ostream *OS) : toplevel_hash_stream(OS) {}
virtual void HandleTranslationUnit(clang::ASTContext &Context) {
// Traversing the translation unit decl via a RecursiveASTVisitor
// will visit all nodes in the AST.
Visitor.hashDecl(Context.getTranslationUnitDecl());
TranslationUnitDecl *TU = Context.getTranslationUnitDecl();
Visitor.hashDecl(TU);
// Context.getTranslationUnitDecl()->dump();
unsigned processed_bytes;
......@@ -30,6 +31,14 @@ public:
llvm::errs() << "top-level-hash: " << hash << "\n";
llvm::errs() << "processed bytes: " << processed_bytes << "\n";
StringRef val[2] = {"clang.asthash", hash};
TU->addAttr(NamedMetadataStringAttr::CreateImplicit(Context,
"llvm.extra_sections", val, 2));
StringRef val2[2] = {"foo", hash};
TU->addAttr(NamedMetadataStringAttr::CreateImplicit(Context,
"llvm.extra_sections", val2, 2));
}
private:
raw_ostream *toplevel_hash_stream;
......@@ -37,9 +46,11 @@ private:
};
class HashTranslationUnitAction : public PluginASTAction {
CompilerInstance *CI;
protected:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef) override {
this->CI = &CI;
// Write hash database to .o.hash if the compiler produces a object file
llvm::raw_ostream *Out = nullptr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment