X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fwrapper%2Fkallsyms.c;h=97897c425469ea5411a0feded86a0ad03f9b8942;hb=a1f1ecf44b7798d27c762f37afe5cea518fec534;hp=6af77f538950d7b3718bd33fffb749053ae03333;hpb=cfa6cc1d0f01c2cfcc1a679abf3a6572d411c309;p=lttng-modules.git diff --git a/src/wrapper/kallsyms.c b/src/wrapper/kallsyms.c index 6af77f53..97897c42 100644 --- a/src/wrapper/kallsyms.c +++ b/src/wrapper/kallsyms.c @@ -14,12 +14,31 @@ #include #include -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,7,0)) #ifndef CONFIG_KPROBES # error "LTTng-modules requires CONFIG_KPROBES on kernels >= 5.7.0" #endif +#ifdef LTTNG_CONFIG_PPC64_ELF_ABI_V1 +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0)) +#include + +#define LTTNG_FUNC_DESC_TYPE struct func_desc +#define LTTNG_FUNC_DESC_ADDR_NAME addr + +#else + +#include + +#define LTTNG_FUNC_DESC_TYPE func_descr_t +#define LTTNG_FUNC_DESC_ADDR_NAME entry +#endif + +static +LTTNG_FUNC_DESC_TYPE kallsyms_lookup_name_func_desc; +#endif + static unsigned long (*kallsyms_lookup_name_sym)(const char *name); @@ -39,10 +58,36 @@ unsigned long do_get_kallsyms(void) memset(&probe, 0, sizeof(probe)); probe.pre_handler = dummy_kprobe_handler; probe.symbol_name = "kallsyms_lookup_name"; +#ifdef LTTNG_CONFIG_PPC64_ELF_ABI_V2 + /* + * With powerpc64 ABIv2, we need the global entry point of + * kallsyms_lookup_name to call it later, while kprobe_register would + * automatically adjust the global entry point to the local entry point, + * when a kprobe was registered at a function entry. So we add 4 bytes + * which is the length of one instruction to kallsyms_lookup_name to + * avoid the adjustment. + */ + probe.offset = 4; +#endif ret = register_kprobe(&probe); if (ret) return 0; +#ifdef LTTNG_CONFIG_PPC64_ELF_ABI_V2 + /* Substract 4 bytes to get what we originally want */ + addr = (unsigned long)(((char *)probe.addr) - 4); +#elif defined(LTTNG_CONFIG_PPC64_ELF_ABI_V1) + /* + * Build a function descriptor from the address of + * 'kallsyms_lookup_name' returned by kprobe and the toc of + * 'sprint_symbol' which is in the same compile unit and exported. I + * hate this on so many levels but it works. + */ + kallsyms_lookup_name_func_desc.LTTNG_FUNC_DESC_ADDR_NAME = (unsigned long) probe.addr; + kallsyms_lookup_name_func_desc.toc = ((LTTNG_FUNC_DESC_TYPE *) &sprint_symbol)->toc; + addr = (unsigned long) &kallsyms_lookup_name_func_desc; +#else addr = (unsigned long)probe.addr; +#endif #ifdef CONFIG_ARM #ifdef CONFIG_THUMB2_KERNEL if (addr) @@ -61,7 +106,7 @@ unsigned long wrapper_kallsyms_lookup_name(const char *name) if (kallsyms_lookup_name_sym) return kallsyms_lookup_name_sym(name); else { - printk_once(KERN_WARNING "LTTng requires kallsyms_lookup_name\n"); + printk_once(KERN_WARNING "LTTng: requires kallsyms_lookup_name\n"); return 0; } }