Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christian Dietrich
clang-hash
Commits
55a8ec1e
Commit
55a8ec1e
authored
Apr 05, 2016
by
Christian Dietrich
Browse files
ELF: store metadata in named metadata section
parent
edb0f6af
Pipeline
#524
passed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/clang-hash.cc
View file @
55a8ec1e
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
#include
"clang/AST/ASTConsumer.h"
#include
"clang/AST/ASTConsumer.h"
#include
"clang/Frontend/CompilerInstance.h"
#include
"clang/Frontend/CompilerInstance.h"
#include
"clang/Frontend/FrontendPluginRegistry.h"
#include
"clang/Frontend/FrontendPluginRegistry.h"
#include
"clang/CodeGen/CodeGenAction.h"
#include
"llvm/Support/raw_ostream.h"
#include
"llvm/Support/raw_ostream.h"
#include
"hash-visitor.h"
#include
"hash-visitor.h"
...
@@ -15,9 +17,8 @@ public:
...
@@ -15,9 +17,8 @@ public:
HashTranslationUnitConsumer
(
raw_ostream
*
OS
)
:
toplevel_hash_stream
(
OS
)
{}
HashTranslationUnitConsumer
(
raw_ostream
*
OS
)
:
toplevel_hash_stream
(
OS
)
{}
virtual
void
HandleTranslationUnit
(
clang
::
ASTContext
&
Context
)
{
virtual
void
HandleTranslationUnit
(
clang
::
ASTContext
&
Context
)
{
// Traversing the translation unit decl via a RecursiveASTVisitor
TranslationUnitDecl
*
TU
=
Context
.
getTranslationUnitDecl
();
// will visit all nodes in the AST.
Visitor
.
hashDecl
(
TU
);
Visitor
.
hashDecl
(
Context
.
getTranslationUnitDecl
());
// Context.getTranslationUnitDecl()->dump();
// Context.getTranslationUnitDecl()->dump();
unsigned
processed_bytes
;
unsigned
processed_bytes
;
...
@@ -30,6 +31,14 @@ public:
...
@@ -30,6 +31,14 @@ public:
llvm
::
errs
()
<<
"top-level-hash: "
<<
hash
<<
"
\n
"
;
llvm
::
errs
()
<<
"top-level-hash: "
<<
hash
<<
"
\n
"
;
llvm
::
errs
()
<<
"processed bytes: "
<<
processed_bytes
<<
"
\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:
private:
raw_ostream
*
toplevel_hash_stream
;
raw_ostream
*
toplevel_hash_stream
;
...
@@ -37,9 +46,11 @@ private:
...
@@ -37,9 +46,11 @@ private:
};
};
class
HashTranslationUnitAction
:
public
PluginASTAction
{
class
HashTranslationUnitAction
:
public
PluginASTAction
{
CompilerInstance
*
CI
;
protected:
protected:
std
::
unique_ptr
<
ASTConsumer
>
CreateASTConsumer
(
CompilerInstance
&
CI
,
std
::
unique_ptr
<
ASTConsumer
>
CreateASTConsumer
(
CompilerInstance
&
CI
,
llvm
::
StringRef
)
override
{
llvm
::
StringRef
)
override
{
this
->
CI
=
&
CI
;
// Write hash database to .o.hash if the compiler produces a object file
// Write hash database to .o.hash if the compiler produces a object file
llvm
::
raw_ostream
*
Out
=
nullptr
;
llvm
::
raw_ostream
*
Out
=
nullptr
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment