Skip to contentSkip to conversation

Add ELF note with Linux version

PATCH In review Bernhard Walle 5 participants 14 messages Sep 4, 2007 – Sep 15, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add ELF note with Linux version

This patch adds version information to the ELF kernel file. Together with the bzImage version information, this allows distributions to identify the kernel version based on the file name.

---
 include/linux/elfnote.h |    9 +++++++++
 init/version.c          |    3 +++
 2 files changed, 12 insertions(+)
include/linux/elfnote.h +9 -0
@@ -93,6 +93,15 @@
 
 #define ELFNOTE32(name, type, desc) ELFNOTE(32, name, type, desc)
 #define ELFNOTE64(name, type, desc) ELFNOTE(64, name, type, desc)
+
+#ifdef CONFIG_64BIT
+#define ELFNOTE_C(params...) ELFNOTE64(params)
+#else
+#define ELFNOTE_C(params...) ELFNOTE32(params)
+#endif
+
 #endif	/* __ASSEMBLER__ */
 
+#define LINUX_ELFNOTE_UTS_RELEASE    0
+
 #endif /* _LINUX_ELFNOTE_H */
init/version.c +3 -0
@@ -11,6 +11,7 @@
 #include <linux/uts.h>
 #include <linux/utsname.h>
 #include <linux/utsrelease.h>
+#include <linux/elfnote.h>
 #include <linux/version.h>
 
 #define version(a) Version_ ## a
@@ -42,3 +43,5 @@ const char linux_proc_banner[] =
 	"%s version %s"
 	" (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ")"
 	" (" LINUX_COMPILER ") %s\n";
+
+ELFNOTE_C("LINUX", LINUX_ELFNOTE_UTS_RELEASE, UTS_RELEASE);
#1 lore raw
Quoted 4 lines · Bernhard Walle

This patch adds version information to the ELF kernel file. Together with the bzImage version information, this allows distributions to identify the kernel version based on the file name.

Seems reasonable to me, but I think the macro could be just called "ELFNOTE".

J

#2 lore raw
Quoted 9 lines · On Thu, 06 Sep 2007 11:36:21 +0100 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 4 lines · Bernhard Walle

This patch adds version information to the ELF kernel file. Together with the bzImage version information, this allows distributions to identify the kernel version based on the file name.

Seems reasonable to me, but I think the macro could be just called "ELFNOTE".

You removed Bernhard from the cc list.

I'd like to know a little bit more about why this is needed, how it will be used, etc. And given that this feature is intended to improve life for distributors, it would be nice to get some feedback from the appropriate persons.

So could you please redo the patch as Jermey suggests (if you agree), revamp the description and then cc suitable people at suitable distros so we can get their input?

Thanks.

#3 lore raw
Quoted 11 lines · Andrew Morton
Quoted 7 lines · On Thu, 06 Sep 2007 11:36:21 +0100 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 5 lines · Bernhard Walle

This patch adds version information to the ELF kernel file. Together with the bzImage version information, this allows distributions to identify the kernel version based on the file name.

Quoted 7 lines
Quoted 4 lines

Seems reasonable to me, but I think the macro could be just called "ELFNOTE".

You removed Bernhard from the cc list.

Didn't mean to... Oh, he has a "mail-followup-to" header which doesn't include himself...

Quoted 4 lines

I'd like to know a little bit more about why this is needed, how it will be used, etc. And given that this feature is intended to improve life for distributors, it would be nice to get some feedback from the appropriate persons.

Hm, yes. ELF notes don't appear in the bzImage, since it isn't an ELF file, so perhaps this doesn't satisfy the requirement. It would help to have more detail.

J

#4 lore raw
Quoted 9 lines · Jeremy Fitzhardinge
Quoted 5 lines

I'd like to know a little bit more about why this is needed, how it will be used, etc. And given that this feature is intended to improve life for distributors, it would be nice to get some feedback from the appropriate persons.

Hm, yes. ELF notes don't appear in the bzImage, since it isn't an ELF file, so perhaps this doesn't satisfy the requirement. It would help to have more detail.

the bzImage already contains the version (and much more, e.g. if the kernel is relocatable, the command line length it accepts). See Documentation/i386/boot.txt.

Thanks,
Bernhard

#5 lore raw
Quoted 7 lines · Bernhard Walle
Quoted 5 lines · Jeremy Fitzhardinge
Quoted 5 lines

I'd like to know a little bit more about why this is needed, how it will be used, etc. And given that this feature is intended to improve life for distributors, it would be nice to get some feedback from the appropriate persons.

Quoted 9 lines
Quoted 4 lines

Hm, yes. ELF notes don't appear in the bzImage, since it isn't an ELF file, so perhaps this doesn't satisfy the requirement. It would help to have more detail.

the bzImage already contains the version (and much more, e.g. if the kernel is relocatable, the command line length it accepts). See Documentation/i386/boot.txt.

Yes, I'm familiar with that. I'm wondering what end result you're trying to achieve though. What's the specific problem?

J

#6 lore raw
In reply to Andrew Morton
Quoted 15 lines · Andrew Morton
Quoted 9 lines · On Thu, 06 Sep 2007 11:36:21 +0100 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 4 lines · Bernhard Walle

This patch adds version information to the ELF kernel file. Together with the bzImage version information, this allows distributions to identify the kernel version based on the file name.

Seems reasonable to me, but I think the macro could be just called "ELFNOTE".

You removed Bernhard from the cc list.

Quoted 8 lines

I'd like to know a little bit more about why this is needed, how it will be used, etc. And given that this feature is intended to improve life for distributors, it would be nice to get some feedback from the appropriate persons.

So could you please redo the patch as Jermey suggests (if you agree), revamp the description and then cc suitable people at suitable distros so we can get their input?

I would rather see allt this ELFNOTE stuff reverted. It causes troubles for several archs and is at the moment being discussed at arm-kernel for example.

Having it reverted and then applied when it is ready for all archs would be preferred.

On top of this I never understood the actual purpose of it...

Sam

#7 lore raw
Quoted 7 lines · Sam Ravnborg

I would rather see allt this ELFNOTE stuff reverted. It causes troubles for several archs and is at the moment being discussed at arm-kernel for example.

Having it reverted and then applied when it is ready for all archs would be preferred.

What problems does it cause on other archs? It should be cross-architecture.

Quoted 1 line

On top of this I never understood the actual purpose of it...

It was originally there to put ELF notes into the vdso objects. I'm using it to create notes in vmlinux for Xen, and apparently people are using it to put other metadata into their kernel images.

J

#8 lore raw
Quoted 14 lines · Jeremy Fitzhardinge
Quoted 7 lines · Sam Ravnborg

I would rather see allt this ELFNOTE stuff reverted. It causes troubles for several archs and is at the moment being discussed at arm-kernel for example.

Having it reverted and then applied when it is ready for all archs would be preferred.

What problems does it cause on other archs? It should be cross-architecture.

Quoted 1 line

On top of this I never understood the actual purpose of it...

Quoted 7 lines

It was originally there to put ELF notes into the vdso objects. I'm using it to create notes in vmlinux for Xen, and apparently people are using it to put other metadata into their kernel images. From a post on arm-kernel:

With build-id binutils (e.g. the latest bintuils 2.18), objcopy produces a 3.1 Gbytes Image file.

This seems outright silly.
Either we should revert the notes changes or someone caring about it should sweep all archs and make sure it does not hurt there.

Sam

#9 lore raw
Quoted 9 lines · Sam Ravnborg
Quoted 4 lines · Jeremy Fitzhardinge

It was originally there to put ELF notes into the vdso objects. I'm using it to create notes in vmlinux for Xen, and apparently people are using it to put other metadata into their kernel images.

From a post on arm-kernel:

Quoted 7 lines
Quoted 3 lines

With build-id binutils (e.g. the latest bintuils 2.18), objcopy produces a 3.1 Gbytes Image file.

This seems outright silly.
Either we should revert the notes changes or someone caring about it should sweep all archs and make sure it does not hurt there.

Hm, sounds like yet another binutils bug; unfortunately common when ELF notes are about. Was there any further effort to isolate what was causing the problem?

J

#10 lore raw
Quoted 7 lines
Quoted 3 lines

This seems outright silly.
Either we should revert the notes changes or someone caring about it should sweep all archs and make sure it does not hurt there.

Hm, sounds like yet another binutils bug; unfortunately common when ELF notes are about. Was there any further effort to isolate what was causing the problem?

Lennart posted this:
An ARM vmlinux kernel image built with pre-build-id binutils has:

        Program Header:
            LOAD off    0x00008000 vaddr 0xc0008000 paddr 0xc0008000 align 2**15
                 filesz 0x002e503c memsz 0x003032c0 flags rwx
        private flags = 4000002: [Version4 EABI] [has entry point]

Whereas a build-id binutils-built vmlinux kernel image ends up with:

        Program Header:
            LOAD off    0x00008000 vaddr 0x00000000 paddr 0x00000000 align 2**15
                 filesz 0x00000024 memsz 0x00000024 flags r--
            LOAD off    0x00010000 vaddr 0xc0008000 paddr 0xc0008000 align 2**15
                 filesz 0x002e503c memsz 0x003032c0 flags rwx
            NOTE off    0x00008000 vaddr 0x00000000 paddr 0x00000000 align 2**2
                 filesz 0x00000024 memsz 0x00000024 flags r--
        private flags = 4000002: [Version4 EABI] [has entry point]

The .note.gnu.build-id section causes objcopy to produce a 3G+ Image file, breaking the build.

Samuel Ortiz posted following patch:

Quoted 16 lines

With build-id binutils (e.g. the latest bintuils 2.18), objcopy produces a 3.1 Gbytes Image file. Adding a note section fixes the problem.

Cc Lennert Buytenhek <[email protected]>
Cc Sam Ravnborg <[email protected]>
---
 arch/arm/kernel/vmlinux.lds.S |    1 +
 1 file changed, 1 insertion(+)

Index: linux-2.6.22/arch/arm/kernel/vmlinux.lds.S
===================================================================

arch/arm/kernel/vmlinux.lds.S 2007-09-11 18:33:42.000000000 +0200 line 100

Quoted 7 lines
arch/arm/kernel/vmlinux.lds.S 2007-09-11 18:33:42.000000000 +0200 renamed from arch/arm/kernel/vmlinux.lds.S 2007-09-11 18:32:29.000000000 +0200 +1 -0
@@ -94,6 +94,7 @@
                      TEXT_TEXT
                      SCHED_TEXT
                      LOCK_TEXT
+                     *(.note.*)
 #ifdef CONFIG_MMU
                      *(.fixup)
 #endif

I cannot see why this should fix it since the patch does not discard the section. Maybe the inclusion of the section in some oter section does some good.

Anyway the original submitter of the build-id should have identified such issues and fixed all archs.

And I still do not get exactly what problem the note section solves when included in vmlinux....

Sam

#11 lore raw

The right fix for the linker script is to use the NOTES macro after RODATA. I'm pretty sure this has been posted before. Each arch's vmlinux.lds.S needs that change, but the details vary if it uses an explicit PHDRS.

Thanks,
Roland

#12 lore raw
In reply to Sam Ravnborg
Quoted 30 lines · Sam Ravnborg
Quoted 8 lines
Quoted 4 lines

This seems outright silly.
Either we should revert the notes changes or someone caring about it should sweep all archs and make sure it does not hurt there.

Hm, sounds like yet another binutils bug; unfortunately common when ELF notes are about. Was there any further effort to isolate what was causing the problem?

Lennart posted this:
An ARM vmlinux kernel image built with pre-build-id binutils has:

        Program Header:
            LOAD off    0x00008000 vaddr 0xc0008000 paddr 0xc0008000 align 2**15
                 filesz 0x002e503c memsz 0x003032c0 flags rwx
        private flags = 4000002: [Version4 EABI] [has entry point]

Whereas a build-id binutils-built vmlinux kernel image ends up with:

        Program Header:
            LOAD off    0x00008000 vaddr 0x00000000 paddr 0x00000000 align 2**15
                 filesz 0x00000024 memsz 0x00000024 flags r--
            LOAD off    0x00010000 vaddr 0xc0008000 paddr 0xc0008000 align 2**15
                 filesz 0x002e503c memsz 0x003032c0 flags rwx
            NOTE off    0x00008000 vaddr 0x00000000 paddr 0x00000000 align 2**2
                 filesz 0x00000024 memsz 0x00000024 flags r--
        private flags = 4000002: [Version4 EABI] [has entry point]
Quoted 3 lines

The .note.gnu.build-id section causes objcopy to produce a 3G+ Image file, breaking the build.

Hm, these phdrs seem OK though; I don't see any ~3Gish numbers here, so it looks like objcopy is just going off into the weeds.

I don't know how ARM images are built, but I would guess that something is trying to make the file large enough to accomodate a 3Gish kernel virtual address address which hasn't being appropriately phys-ized. It may be more a linker script bug than an inherent problem with either notes or build-id themselves.

Quoted 23 lines

Samuel Ortiz posted following patch:

Quoted 21 lines

With build-id binutils (e.g. the latest bintuils 2.18), objcopy produces a 3.1 Gbytes Image file. Adding a note section fixes the problem.

Cc Lennert Buytenhek <[email protected]>
Cc Sam Ravnborg <[email protected]>
---
 arch/arm/kernel/vmlinux.lds.S |    1 +
 1 file changed, 1 insertion(+)

Index: linux-2.6.22/arch/arm/kernel/vmlinux.lds.S
===================================================================

arch/arm/kernel/vmlinux.lds.S 2007-09-11 18:33:42.000000000 +0200 renamed from arch/arm/kernel/vmlinux.lds.S 2007-09-11 18:32:29.000000000 +0200 +1 -0
@@ -94,6 +94,7 @@
                      TEXT_TEXT
                      SCHED_TEXT
                      LOCK_TEXT
+                     *(.note.*)
 #ifdef CONFIG_MMU
Quoted 9 lines

arch/arm/kernel/vmlinux.lds.S 2007-09-11 18:33:42.000000000 +0200 line 100

Quoted 3 lines
arch/arm/kernel/vmlinux.lds.S 2007-09-11 18:33:42.000000000 +0200 renamed from arch/arm/kernel/vmlinux.lds.S 2007-09-11 18:32:29.000000000 +0200 +0 -0
                      *(.fixup)
 #endif

I cannot see why this should fix it since the patch does not discard the section. Maybe the inclusion of the section in some oter section does some good.

Yes, binutils can be pretty fragile with notes about. In this case it seems to be a specific problem with build-id; I'm not really sure what build-id actually does.

Though if my theory above is true, it may end up properly assigning a value to a symbol
by putting it into the right section. Or something.

Quoted 5 lines

Anyway the original submitter of the build-id should have identified such issues and fixed all archs.

And I still do not get exactly what problem the note section solves when included in vmlinux....

The Note section is supposed to be a general extensible way of adding metadata to an object file, either for a linker or a loader. There's no inherent connection between notes and build-id (other than build-id is one of the users of notes, I suppose).

J

#13 lore raw
Quoted 3 lines

Yes, binutils can be pretty fragile with notes about. In this case it seems to be a specific problem with build-id; I'm not really sure what build-id actually does.

The thing about the build ID section that brings up issues with linking is that it is a SHF_ALLOC, SHT_NOTE section. As you mentioned, this is a general, straightforward, and well-defined thing in ELF. But in practice, there were not previously SHF_ALLOC note sections used with custom linker scripts like the kernel's. (They are used every day in normal executables and DSOs, but those don't use custom linker scripts.)

Thanks,
Roland