Messages in this thread |  | | From | Keith Owens <> | Subject | Re: [PATCH] ISA PnP (2.4.0-test9) | Date | Mon, 09 Oct 2000 22:30:10 +1100 |
| |
On Mon, 9 Oct 2000 12:55:28 +0200 (MEST), Jaroslav Kysela <perex@suse.cz> wrote: >I fully understand your point, but I don't want to have a special >case for ISA PnP. What about this change: > >#define MODULE_GENERIC_TABLE(gtype,name) \ >const struct gtype##_id * __module_##gtype##_table = name > >to > >#define MODULE_GENERIC_TABLE(gtype,name) \ >const unsigned long __module_##gtype_size = sizeof(struct gtype##_id); \ >const struct gtype##_id * __module_##gtype##_table = name
Make that
#define MODULE_GENERIC_TABLE(gtype,name) \ static const unsigned long __module_##gtype##_size \ __attribute__ ((unused)) = sizeof(struct gtype##_id); \ static const struct gtype##_id * __module_##gtype##_table = name
and you've got a deal. The _size must be static to avoid name clashes when two or more objects that use MODULE_GENERIC_TABLE(sametype,..) are linked together. __attribute__ ((unused)) stops the compiler complaining about unused static variables; we know that they are used by modutils, not by the code itself.
Ideally __module_##gtype##_size would be in section .modinfo so it did not get loaded into memory. However modutils expects all .modinfo entries to be char[] with contents "variable=value" as a character string. I cannot see any way for MODULE_GENERIC_TABLE(isapnp,name) to generate
static const char __module_isapnp_size[] \ __attribute__ ((section(".modinfo"))) = \ "module_isapnp_size=42";
Interpolating gtype is easy, even into the middle of the string. Getting the number '42' instead of 'sizeof(struct isapnp_id)' appears to be impossible. Neither the # nor ## operators will replace a string with its constant value. It's times like this that make me wish that C had a decent macro preprocessor instead of a glorified string replacer. Requiring m4 to build the kernel is not an option.
ObWarStory: ICL's assembler for George 2/3 (GIN) had brilliant macro capabilities. All the Assembler internals were accessible to the code that was being assembled, including functions for string and number manipulation. You could even compile code as part of your input that would be immediately executed as if it was the assembler itself then it would resume assembling the main code. Sometimes newer is not better.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/
|  |