From: Andrew Morton <akpm@linux-foundation.org>
To: Roland McGrath <roland@frob.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/7] Add /sys/kernel/notes
Date: Wed, 11 Jul 2007 16:45:31 -0700 [thread overview]
Message-ID: <20070711164531.aef1dcac.akpm@linux-foundation.org> (raw)
In-Reply-To: <20070711190434.D0F0C4D0555@magilla.localdomain>
On Wed, 11 Jul 2007 12:04:34 -0700 (PDT)
Roland McGrath <roland@frob.com> 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?
next prev parent reply other threads:[~2007-07-12 0:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-11 19:04 [PATCH 6/7] Add /sys/kernel/notes Roland McGrath
2007-07-11 19:16 ` Linus Torvalds
2007-07-11 20:51 ` Roland McGrath
2007-07-11 21:45 ` Linus Torvalds
2007-07-11 22:04 ` Roland McGrath
2007-07-11 22:17 ` Linus Torvalds
2007-07-11 22:42 ` Roland McGrath
2007-07-11 22:48 ` Linus Torvalds
2007-07-11 23:45 ` Andrew Morton [this message]
2007-07-12 0:37 ` Roland McGrath
2007-07-11 23:57 ` Jeremy Fitzhardinge
2007-07-12 0:42 ` Roland McGrath
2007-07-12 2:41 ` Jeremy Fitzhardinge
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070711164531.aef1dcac.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roland@frob.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.