Skip to content

Commit

Permalink
SymbolExternalizer: Always emit KLP_RELOC_SYMBOL
Browse files Browse the repository at this point in the history
Currently clang-extract removes ifndefs of macros that are already
defined, so always emitting KLP_RELOC_SYMBOL under an ifdef will always
emit it before the first usage.

Suggested-by: Giuliano Belinassi <[email protected]>
Signed-off-by: Marcos Paulo de Souza <[email protected]>
  • Loading branch information
marcosps committed Jun 10, 2024
1 parent b630310 commit 20784c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 5 additions & 2 deletions libcextract/SymbolExternalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,17 @@ bool SymbolExternalizer::_Externalize_Symbol(const std::string &to_externalize,
std::string o;
llvm::raw_string_ostream outstr(o);

if (Ibt && !EmittedLinuxLivepatch) {
/*
* It won't be a problem to add the code below multiple times, since
* clang-extract will remove ifndefs for already defined macros
*/
if (Ibt) {
outstr << "#ifndef KLP_RELOC_SYMBOL_POS\n"
"# define KLP_RELOC_SYMBOL_POS(LP_OBJ_NAME, SYM_OBJ_NAME, SYM_NAME, SYM_POS) \\\n"
" asm(\"\\\".klp.sym.rela.\" #LP_OBJ_NAME \".\" #SYM_OBJ_NAME \".\" #SYM_NAME \",\" #SYM_POS \"\\\"\")\n"
"# define KLP_RELOC_SYMBOL(LP_OBJ_NAME, SYM_OBJ_NAME, SYM_NAME) \\\n"
" KLP_RELOC_SYMBOL_POS(LP_OBJ_NAME, SYM_OBJ_NAME, SYM_NAME, 0)\n"
"#endif\n\n";
EmittedLinuxLivepatch = true;
}

new_decl->print(outstr, AST->getLangOpts());
Expand Down
4 changes: 0 additions & 4 deletions libcextract/SymbolExternalizer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class SymbolExternalizer
TM(ast, dump),
IA(ia),
Ibt(ibt),
EmittedLinuxLivepatch(false),
PatchObject(patch_object)
{
}
Expand Down Expand Up @@ -296,9 +295,6 @@ class SymbolExternalizer
/** Defines the method that a private symbol will be searched. */
bool Ibt;

/** Flag if we already emit the #include<linux/livepatch.h> */
bool EmittedLinuxLivepatch;

/* Name of the object that will be patched. */
std::string PatchObject;
};

0 comments on commit 20784c0

Please sign in to comment.