Skip to content

Commit

Permalink
Test IBT externalization method
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Paulo de Souza <[email protected]>
  • Loading branch information
marcosps committed Jun 5, 2024
1 parent e83d41e commit 062bf32
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions testsuite/small/Modules.symvers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x00000000 crc32c lib/libcrc32c EXPORT_SYMBOL
21 changes: 21 additions & 0 deletions testsuite/small/ibt-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* { dg-options "-DCE_EXTRACT_FUNCTIONS=f -DCE_RENAME_SYMBOLS -include ../testsuite/small/linux/livepatch.h -DCE_SYMVERS_PATH=../testsuite/small/Modules.symvers -DKBUILD_MODNAME=crc32c -D__USE_IBT__" } */

#include <linux/types.h>

typedef unsigned int u32;

u32 crc32c(u32 crc, const void *address, unsigned int length);

int f(void)
{
u32 lcrc = 0;
void *addr = 0;
unsigned int len = 0;

(void)crc32c(lcrc, addr, len);
return 0;
}

/* { dg-final { scan-tree-dump "u32 klpe_crc32c" } } */
/* { dg-final { scan-tree-dump "KLP_RELOC_SYMBOL\(crc32c, crc32c, crc32c\)" } } */
/* { dg-final { scan-tree-dump-not "\(\*klpe_crc32c\)" } } */
18 changes: 18 additions & 0 deletions testsuite/small/linux/livepatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* KLP_RELOC_SYMBOL_POS - define relocation for external symbols
*
* @LP_OBJ_NAME: name of the livepatched object where the symbol is needed
* @SYM_OBJ_NAME: name of the object where the symbol exists
* @SYM_NAME: symbol name
* @SYM_POS: position of the symbol in SYM_OBJ when there are more
* symbols of the same name.
*
* Use for annotating external symbols used in livepatches which are
* not exported in vmlinux or are in livepatched modules, see
* Documentation/livepatch/module-elf-format.rst
*/
#define KLP_RELOC_SYMBOL_POS(LP_OBJ_NAME, SYM_OBJ_NAME, SYM_NAME, SYM_POS) \
asm("\".klp.sym.rela." #LP_OBJ_NAME "." #SYM_OBJ_NAME "." #SYM_NAME "," #SYM_POS "\"")

#define KLP_RELOC_SYMBOL(LP_OBJ_NAME, SYM_OBJ_NAME, SYM_NAME) \
KLP_RELOC_SYMBOL_POS(LP_OBJ_NAME, SYM_OBJ_NAME, SYM_NAME, 0)

0 comments on commit 062bf32

Please sign in to comment.