On Wed, 11 Jul 2007 12:04:34 -0700 (PDT) Roland McGrath <[EMAIL PROTECTED]> wrote:
> +/* > + * Make /sys/kernel/notes give the raw contents of our kernel .notes section. > + */ > +extern const char __start_notes __attribute__((weak)); > +extern const char __stop_notes __attribute__((weak)); > +#define notes_size (&__stop_notes - &__start_notes) > + > +static ssize_t notes_read(struct kobject *kobj, > + char *buf, loff_t off, size_t count) > +{ > + memcpy(buf, &__start_notes + off, count); > + return count; > +} > + > +static struct bin_attribute notes_attr = { > + .attr = { > + .name = "notes", > + .mode = S_IRUGO, > + }, > + .read = ¬es_read, > +}; > + > decl_subsys(kernel, NULL, NULL); > EXPORT_SYMBOL_GPL(kernel_subsys); > > @@ -88,6 +110,12 @@ static int __init ksysfs_init(void) > error = sysfs_create_group(&kernel_subsys.kobj, > &kernel_attr_group); > > + if (!error && notes_size > 0) { > + notes_attr.size = notes_size; > + error = sysfs_create_bin_file(&kernel_subsys.kobj, > + ¬es_attr); > + } I'm curios to know what happens if nobody defines __start_notes and __end_notes. We'll use the extern-attribute-weak thing, but those two locations won't even get instantiated in vmlinux, I think. And the code relies upon the difference between two non-existent attribute-weak locations being zero. akpm:/home/akpm> cat t.c #include <stdio.h> extern const char __start_notes __attribute__((weak)); extern const char __stop_notes __attribute__((weak)); main() { int a = &__stop_notes - &__start_notes; printf("%d\n", a); } akpm:/home/akpm> gcc -g t.c akpm:/home/akpm> ./a.out 0 akpm:/home/akpm> nm a.out|grep notes w __start_notes w __stop_notes So it all works OK on this toolchain. But is it _supposed_ to work? Are we venturing into unexplored binutils territory here? - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/