2009-11-23 22:47:17

by Alan Jenkins

[permalink] [raw]
Subject: [PATCH] modpost: fix modules on ia64 - use @fptr() on exported function symbols

On function descriptor architectures (powerpc and ia64), we need to export
the address of the function descriptor and not the actual function.
The C compiler naturally does this for us. However we now export vmlinux
symbols using the assembler, in order to sort the exports.

This is not a problem on powerpc. On powerpc, the function descriptor
is simply "printk" (the action function entry point is ".printk").
But ia64 assembly needs special handling. The function descriptor for
printk(), for example, is "@fptr(printk)".

I have tested that modpost now generates the desired assembly code when
run against an IA64 module. I have not tested with an actual IA64
vmlinux, assembler, compiler or processor. I assume that the IA64
assembler defines __ia64__, just as the i386 assembler defines __i386__.

Reported-by: Alex Chiang <[email protected]>
Signed-off-by: Alan Jenkins <[email protected]>
---
include/linux/mod_export.h | 17 +++++++++++++++--
scripts/mod/modpost.c | 22 +++++++++++++++++++++-
2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/include/linux/mod_export.h b/include/linux/mod_export.h
index 394795e..3f4e38a 100644
--- a/include/linux/mod_export.h
+++ b/include/linux/mod_export.h
@@ -111,6 +111,12 @@ struct kernel_symbol {
#define SYM(sym) PASTE(SYMBOL_PREFIX, sym)
#endif

+#ifdef __ia64__
+#define FSYM(x) @fptr(SYM(x))
+#else
+#define FSYM(x) SYM(x)
+#endif
+

#ifdef CONFIG_MODVERSIONS
#define __CRC_SYMBOL(sym, crcsec) \
@@ -125,7 +131,7 @@ struct kernel_symbol {
#define __CRC_SYMBOL(sym, section)
#endif

-#define __EXPORT_SYMBOL(sym, sec, strsec, crcsec) \
+#define __EXPORT_SYMBOL_VALUE(sym, symvalue, sec, strsec, crcsec) \
.globl SYM(sym); \
\
__CRC_SYMBOL(sym, crcsec) \
@@ -138,10 +144,17 @@ struct kernel_symbol {
.pushsection sec, "a"; \
ALGN; \
SYM(__ksymtab_##sym): \
- PTR SYM(sym); \
+ PTR symvalue; \
PTR SYM(__kstrtab_##sym); \
.popsection;

+#define __EXPORT_DATA_SYMBOL(sym, sec, strsec, crcsec) \
+ __EXPORT_SYMBOL_VALUE(sym, SYM(sym), sec, strsec, crcsec)
+
+#define __EXPORT_FUNCTION_SYMBOL(sym, sec, strsec, crcsec) \
+ __EXPORT_SYMBOL_VALUE(sym, FSYM(sym), sec, strsec, crcsec)
+
+
#endif /* __MODPOST_EXPORTS__ */

#endif /* __GENKSYMS__ */
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index b5a801d..31256d7 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -158,6 +158,7 @@ struct symbol {
unsigned int kernel:1; /* 1 if symbol is from kernel
* (only for external modules) **/
unsigned int preloaded:1; /* 1 if symbol from Module.symvers */
+ unsigned int function:1; /* 1 if symbol refers to a function */
enum export export; /* Type of export */
char name[0];
};
@@ -582,6 +583,17 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
}
}

+static void mark_function_symbols(Elf_Sym *sym, const char *symname)
+{
+ struct symbol *export_symbol;
+
+ export_symbol = find_symbol(symname);
+ if (!export_symbol)
+ return;
+
+ export_symbol->function = (ELF_ST_TYPE(sym->st_info) == STT_FUNC);
+}
+
/**
* Parse tag=value strings from .modinfo section
**/
@@ -1619,6 +1631,13 @@ static void read_symbols(char *modname)
handle_modversions(mod, &info, sym, symname);
handle_moddevtable(mod, &info, sym, symname);
}
+
+ for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
+ symname = info.strtab + sym->st_name;
+
+ mark_function_symbols(sym, symname);
+ }
+
if (!is_vmlinux(modname) ||
(is_vmlinux(modname) && vmlinux_section_warnings))
check_sec_ref(mod, modname, &info);
@@ -2027,10 +2046,11 @@ static void write_exports(const char *fname)
for (i = 0; i < n; i++) {
sym = symbols[i];

- buf_printf(&buf, "__EXPORT_SYMBOL(%s,"
+ buf_printf(&buf, "__EXPORT_%s_SYMBOL(%s,"
" __ksymtab%s_sorted,"
" __ksymtab_strings_sorted,"
" __kcrctab%s_sorted)\n",
+ sym->function ? "FUNCTION" : "DATA",
sym->name,
section_names[sym->export],
section_names[sym->export]);
--
1.6.3.3



2009-11-23 23:25:17

by Alex Chiang

[permalink] [raw]
Subject: Re: [PATCH] modpost: fix modules on ia64 - use @fptr() on exported function symbols

* Alan Jenkins <[email protected]>:
> On function descriptor architectures (powerpc and ia64), we need to export
> the address of the function descriptor and not the actual function.
> The C compiler naturally does this for us. However we now export vmlinux
> symbols using the assembler, in order to sort the exports.
>
> This is not a problem on powerpc. On powerpc, the function descriptor
> is simply "printk" (the action function entry point is ".printk").
> But ia64 assembly needs special handling. The function descriptor for
> printk(), for example, is "@fptr(printk)".
>
> I have tested that modpost now generates the desired assembly code when
> run against an IA64 module. I have not tested with an actual IA64
> vmlinux, assembler, compiler or processor. I assume that the IA64
> assembler defines __ia64__, just as the i386 assembler defines __i386__.
>
> Reported-by: Alex Chiang <[email protected]>

I applied this patch to a tree that had 20ba8ef1de7e77e4c
(kbuild: sort the list of symbols exported by the kernel
(__ksymtab)) as a HEAD.

Without the patch, I get a panic. With the patch, boot succeeds.

I also applied this patch on top of 9d5bf6fad2 (Add linux-next
specific files for 20091123), and verified that boot also
succeeds.

So for ia64, you can add my:

Tested-by: Alex Chiang <[email protected]>

However, I've cc'ed James Bottomley who is currently testing
parisc. parsic is another function descriptor architecture, and
due to your very specific #ifdef __ia64__ in the patch, it
clearly won't fix parisc (if indeed it is broken).

James mentioned something about needing an fptr arch symbol, but
I'll let him expand on his idea.

Thanks,
/ac