Skip to contentSkip to conversation

ld-Script needed OR (predicted) Architecture of Kernel 3.0 ;-)

DISCUSSION Hartmut Zybell 4 participants 8 messages Oct 14, 2003 – Oct 15, 2003

lore
Share & tools
lore
#0 lore raw

First things first: Please CC me, because I'm not
subscribed.

I need a ld-Script to construct an elf-File that is a tar-File too. Can
anyone help me? Especially the Checksum is tricky.

The reason I ask this (and an example to see what I mean) is longer to
explain. There are two variants (and therefore two examples) where the
easier one has nothing to do with the kernel, so please bear with me.
First Example: I want to construct a statically linked program, that
read as tar-File contains the dynamically linked program and the used
shared library(s), so that I can run it to install a system, where no
/lib/ld-linux.so is and can free the diskspace later when there is.
As picture:
Seen as elf Seen as tar

  +-------------------+           +--------------+---+
  |   ELF-Header      |           |   File-Name  |   |
  +-------------------+           +--------------'   |
  | Garbage           |           |   tar-header     |
  +-------------------+           +------------------+
  |   Programheader   |           |    Content of    |
  |  and Relocations  |           |    file \x7fELF  |
  |  for statically   |           |   (Garbage)      |
  |  linked version   |           |                  |
  +-------------------+           +------------------+
  |                   |           |   tar-header     |
  |                   |           +--------------+---+
  |                   |           |   ELF-Header |   |
  |                   |           +--------------'   |
  |    Garbage        |           | Content of dyna- |
  |                   |           | mically linked   |
  |                   |           | Program          |
  |                   |           +--------------+   |
  |                   |           |Programheader |   |
  |                   |           |and Relocation|   |
  +-------------------+           +--------------+   |
  |  Programcode      |           |   Programcode    |
  |  (.text+.data)    |           | (.text+.data)    |
  +-------------------+           +------------------+
  |                   |           |   tar-header     |
  |                   |           +--------------+---+
  |                   |           |   ELF-Header |   |
  |                   |           +--------------'   |
  |    Garbage        |           | Content of dyna- |
  |                   |           | mically linked   |
  |                   |           | Library          |
  |                   |           +--------------+   |
  |                   |           |Programheader |   |
  |                   |           |and Relocation|   |
  +-------------------+           +--------------+   |
  |  Librarycode      |           |   Librarycode    |
  |  (.text+.data)    |           | (.text+.data)    |
  +-------------------+           +------------------+

That lays the Groundwork for the second Example and for the Architecture of
Kernel 3.0. The idea is that the kernel is booted like a statically linked
Program, but loading modules is like shared librarys. After we have seen
above, that both could be combined in a single file, we can predict the
Architecture as follows. Every byte in the kernel is owned by a module or
a process. The process-owned bytes don't concern us here, so I will ignore
them in my explanation. The in-memory image of the kernel will be as if a
hypothetical module-loader had loaded all compiled-in modules from an also
hypotehtical source into the memory. The only difference of a compiled-in
module and its to-be-loaded counterpart is that its name ends in the version
number of the kernel. Every compiled-in module gets a tar-header in the kernel
image. The first tar-header, and therefore the "static" image, is for a piece
of setup code that corrects the page tables to free garbage and duplicated
entries. All pieces of code that are currently not loadable (VFS,scheduler etc.)
get a module header, but directly or indirectly the module loader (a module
too) or the personality (modules too) of a process depends on them, so they
could not be removed without replacing them or removing the module loader, the
very tool with which the removing is done. Replacing a module will be a new technology that allows the update of the
kernel in the running system. To do this, the updated module must be extracted
from the new kernel (that must be a tar-file therefore too) with either
tar xzf vmlinux module.ko (Please
note: no version in name)
or
tar xf vmlinuz -O k|tar xz module.ko (x86
and compatible).
Then it will be insmod. Then a rmmod module-old (where old is the old version
number) will trigger the replacement going which works like this:
Any module that needs the services of another module requests them by symbol.
The module that provides that symbol has in its module header a version
independent name (the beginning of the module name). The rest (the version) is
the name of another module that is called the symbol table. If it's blank it's
the table for to-be-loaded modules. Therefore symbol tables are separated by
version.
If a module is loaded that has the same version independent name its symbols
will go into another symbol table. To resolve a symbol the symbol will be
first searched in the symbol table of the same version, then in the version
independent symbol table (where symbols of to-be-loaded modules go), then in
other versions in version decreasing order. If a module is to be removed and
is needed by another module and there is another module with the same version
independent name, all dependent modules will be notified and must reresolve
their symbols.

The infrastructure to reresolve the symbols is the second task the linker must
do after placing the modules in tar-headers. It's like the global object table
in dynamic linking. The notifcation infrastructure must be either erected by
the module loader (by spending a notification function for every global object)
or must be contained in the symbol table by making that a full fledged dynamic
loader. I like the first alternative better.

BTW, the module loader shouldn't contain any struct Elf_*, but should rely on
binfmt(_elf) for that. So could even the binary format of the modules (and of
the kernel therefore) change without reboot.

This Architecture gives us for free updateability of drivers for boot media,
kexec, switchable scheduler, fixed modules after boot with modules and probably
many more applications.

__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Logos und Klingeltöne fürs Handy bei http://sms.yahoo.de

#1 lore raw
Quoted 7 lines · On Tue, 14 Oct 2003, [iso-8859-1] Hartmut Zybell wrote:

First things first: Please CC me, because I'm not
subscribed.

I need a ld-Script to construct an elf-File that is a tar-File too. Can
anyone help me? Especially the Checksum is tricky.

[SNIPPED....]

I don't think you are aware that the kernel is compressed, then expanded when installed. It therefore has all the good attributes of a tar.gz file without any of the bad ones.

Also, we have a module loader and unloader that allows modules to be inserted and removed from a running system. There are even experimental systems that allow the whole kernel to be changed without (apparent) re-booting.

A file with a 'tar' header is useful for recovering a directory tree, intact, as it was initially backed-up. It has no usefulness in the kernel where the content of a file (or files) are located into various offsets in RAM. This is done by the linker and 'helper code' within the kernel itself.

You can readily run an install-system without any runtime libraries and/or you can use temporary ones. This is currently done for every major distribution.

The runtime libraries are not used by the kernel. Instead they are used by user-mode code.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.

#2 lore raw

--- "Richard B. Johnson" <[email protected]>
schrieb: > On Tue, 14 Oct 2003, [iso-8859-1] Hartmut Zybell

Quoted 10 lines
Quoted 4 lines · wrote:

First things first: Please CC me, because I'm not
subscribed.

I need a ld-Script to construct an elf-File that

is a

Quoted 3 lines

tar-File too. Can
anyone help me? Especially the Checksum is tricky.

Quoted 9 lines

[SNIPPED....]

I don't think you are aware that the kernel is compressed,
then expanded when installed. It therefore has all the good
attributes of a tar.gz file without any of the bad ones.

Of course I'm aware. But what bad ones do you mean?

Quoted 3 lines

Also, we have a module loader and unloader that allows modules
to be inserted and removed from a running system.

Can you remove modules from a running system, that are compiled into the kernel? For instance the Filesystem driver, that were used to boot and is not longer needed because / has another filesystem than
/initrd.

Quoted 5 lines

There are
even experimental systems that allow the whole kernel to be
changed without (apparent) re-booting.

Quoted 9 lines

A file with a 'tar' header is useful for recovering a
directory tree, intact, as it was initially backed-up.
It has no usefulness in the kernel where the content of a file (or files) are located into various offsets
in RAM. This is done by the linker and 'helper code' within the kernel itself.

I seem to have misread here. I *don't* want to change the kernel with tar, as you seem to assume. Thats why I'm asking for an ld-script. I want to be able to *extract* (READ-ONLY) modules from a kernelfile that are compiled into this (not currently running) kernel to insert them into the currently running kernel to update it. And I want to do it *with* the current module loader.

Quoted 5 lines

You can readily run an install-system without any runtime libraries and/or you can use temporary ones. This is currently done for every major distribution.

Of course it's done. You have 2 files: one staticaly linked to run at install time, one binary archive (descendent of tar) to install into the system. If I could make the binary do double duty as install archive, I could save 50% space. Thats a lot on a floppy based install. And make no mistake: Even CDROM (not all, I know!) boot from a floppy image.

Quoted 3 lines

The runtime libraries are not used by the kernel. Instead they are used by user-mode code.

I *wrote* that the first example has nothing to do with
the kernel. It's only there because it's simpler. And useful too.

__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Logos und Klingeltöne fürs Handy bei http://sms.yahoo.de

#3 lore raw
Quoted 1 line

From [email protected] Tue Oct 14 11:42:18 2003

To: [email protected]
From: "[iso-8859-1] Hartmut Zybell" <[email protected]>
Cc: [email protected]
Subject: Re: ld-Script needed OR (predicted) Architecture of Kernel 3.0 ;-)

[ The following text is in the "iso-8859-1" character set. ] [ Your display is set for the "US-ASCII" character set. ] [ Some characters may be displayed incorrectly. ]

--- "Richard B. Johnson" <[email protected]>
schrieb: > On Tue, 14 Oct 2003, [iso-8859-1] Hartmut Zybell

Quoted 20 lines
Quoted 10 lines
Quoted 4 lines · wrote:

First things first: Please CC me, because I'm not
subscribed.

I need a ld-Script to construct an elf-File that

is a

Quoted 3 lines

tar-File too. Can
anyone help me? Especially the Checksum is tricky.

Quoted 10 lines

[SNIPPED....]

I don't think you are aware that the kernel is compressed,
then expanded when installed. It therefore has all the good
attributes of a tar.gz file without any of the bad ones.

Quoted 1 line

Of course I'm aware. But what bad ones do you mean?

The wasted space of the header(s) themselves, plus the fact that it can't be updated, only re-written from scratch.

Quoted 10 lines
Quoted 3 lines

Also, we have a module loader and unloader that allows modules
to be inserted and removed from a running system.

Can you remove modules from a running system, that are compiled into the kernel? For instance the Filesystem driver, that were used to boot and is not longer needed because / has another filesystem than
/initrd.

Drivers that are compiled into the kernel are not modules. Once the linking occurs, all information necessary to replace such code is lost.

No system that is statically linked can have portions of the statically-linked area removed or replaced except with code and data that is exactly the same length with the exact same offsets of the global symbols.

In general, to have such exact characteristics requires that the code be identical. So, one would not usually reload an identical section of code.

This applies to all systems, not just Linux on Intel. All systems, including those which haven't been invented yet. Anything that executes instructions loaded into RAM will have the same problem. That's why 'relocatable' code was invented. But once you preform a static allocation on relocatable code so that it occupies some specific contiguous RAM (like the kernel), then the relocation information is gone. You can't re-do it.

Make a 'C' program with a single variable:

int foo;

Then compile it into an object file. Then look at it with objdump. What do you see? Nothing! That variable doesn't even show up. The presence of that variable was put into the header which basically tells the loader (eventually) to allocate some space in the .bss segment for this variable. Where that data will eventually exist will not be known until it is either statically linked or fixed up by the loader during dynamic linking.

Now change that variable to:

int foo = 0;

This makes it exist in the .data segment because it has been initialized. Now look at it with objdump. You will see that there is an allocation, but the offset of that allocation is 0x00000000. These are the offsets that are fixed up by either the linker, for static linking, or the loader for dynamic.

Modules relocate at run-time. They are entirely different than the statically-linked built-in code, even though both are generated from the same source and create nearly indentical object files. The module objects contain relocation tables (part of ELF object format) that allow code to be put anywhere (on certain bounadries) and then fixed up by the loader. The final fixup resolves all the relative offsets.

Quoted 15 lines
Quoted 5 lines

There are
even experimental systems that allow the whole kernel to be
changed without (apparent) re-booting.

Quoted 9 lines

A file with a 'tar' header is useful for recovering a
directory tree, intact, as it was initially backed-up.
It has no usefulness in the kernel where the content of a file (or files) are located into various offsets
in RAM. This is done by the linker and 'helper code' within the kernel itself.

Quoted 8 lines

I seem to have misread here. I *don't* want to change the kernel with tar, as you seem to assume. Thats why I'm asking for an ld-script. I want to be able to *extract* (READ-ONLY) modules from a kernelfile that are compiled into this (not currently running) kernel to insert them into the currently running kernel to update it. And I want to do it *with* the current module loader.

You need the original object files. You can't take portions of the statically-linked kernel. You need these original object files because they contain the required relocation information. Once they get linked into the kernel, the essential information is lost.

You can store these object files anyway you want. The usual way to store them is to use ar. The existing module loader doesn't know how to extract the object files from an archive, but you could make a simple script to do it.

Quoted 5 lines
Quoted 5 lines

You can readily run an install-system without any runtime libraries and/or you can use temporary ones. This is currently done for every major distribution.

Quoted 7 lines

Of course it's done. You have 2 files: one staticaly linked to run at install time, one binary archive (descendent of tar) to install into the system. If I could make the binary do double duty as install archive, I could save 50% space. Thats a lot on a floppy based install. And make no mistake: Even CDROM (not all, I know!) boot from a floppy image.

Well no. You have a kernel image that was built with a minimum of built-in drivers. Then you have some code that looks at the PCI bus and installs the modules necessary to activate the devices it finds. Then you have more code to probe for other devices and you install those modules, etc. Then you have a kernel that will run the specific configuration found. After that's done, the install program writes an initrd script and builds an initial RAM disk so that modules necessary to access the root file-system can be installed prior to attempting to mount it. It's all there, it all works and it doesn't waste the 50% space you claim above.

Quoted 7 lines
Quoted 3 lines

The runtime libraries are not used by the kernel. Instead they are used by user-mode code.

I *wrote* that the first example has nothing to do with
the kernel. It's only there because it's simpler. And useful too.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.

#4 lore raw

--- "Richard B. Johnson" <[email protected]>
schrieb: > From [email protected] Tue Oct 14 11:42:18 2003

Quoted 35 lines

To: [email protected]
From: "[iso-8859-1] Hartmut Zybell" <[email protected]>
Cc: [email protected]
Subject: Re: ld-Script needed OR (predicted) Architecture of Kernel 3.0 ;-)

--- "Richard B. Johnson" <[email protected]>
schrieb: > On Tue, 14 Oct 2003, [iso-8859-1] Hartmut Zybell

Quoted 3 lines
Quoted 3 lines
Quoted 1 line · wrote:

First things first: Please CC me, because I'm

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

subscribed.

I need a ld-Script to construct an elf-File

that

Quoted 3 lines
Quoted 3 lines

is a

Quoted 2 lines

tar-File too. Can
anyone help me? Especially the Checksum is

tricky.

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

[SNIPPED....]

I don't think you are aware that the kernel is
compressed,
then expanded when installed. It therefore has

all

Quoted 2 lines
Quoted 2 lines

the good
attributes of a tar.gz file without any of the

bad

Quoted 3 lines
Quoted 3 lines

ones.

Quoted 8 lines
Quoted 1 line

Of course I'm aware. But what bad ones do you

mean?

The wasted space of the header(s) themselves, plus the fact
that it can't be updated, only re-written from scratch.

Sorry for the misunderstanding. I meant the *uncompressed* image should look like a tar-file. The compressed one *would* be a tar.gz-file (because the kernel is compressed with gzip)

Quoted 12 lines
Quoted 10 lines
Quoted 3 lines

Also, we have a module loader and unloader that
allows modules
to be inserted and removed from a running system.

Can you remove modules from a running system, that are compiled into the kernel? For instance the Filesystem driver, that were used to boot and is not longer needed because / has another filesystem than
/initrd.

Quoted 2 lines

Drivers that are compiled into the kernel are not modules.

See below. Very below.

Quoted 6 lines

Once the linking occurs, all information necessary to
replace such code is lost.
[SNIP]
information is gone. You can't re-do it.

That was meant to be a rhetoric question to illustrate why my approach could be usefull. Your answer illustrates the point I was trying (apparently unsuccessful) to explain in my first example. The ld-script should include this information into the binary headers that follow the tar headers. Then tar would extract a .o file with exactly the same information (although possibly at other fileoffsets) in it.

Quoted 5 lines

Make a 'C' program with a single variable:
[SNIP]
the offsets that are fixed up by either the linker, for static linking, or the loader for dynamic.

Quoted 14 lines

Modules relocate at run-time. They are entirely different
than the statically-linked built-in code, even though
both are generated from the same source and create nearly indentical object files. The module objects contain relocation tables (part of ELF object format)
that allow code to be put anywhere (on certain bounadries) and
then fixed up by the loader. The final fixup resolves
all the relative offsets.

I want the ld-script so that the relocation tables stay in the static file. Because the kernel is loaded contigously into the memory these tables and their associated tar headers are first loaded too. Because I don't need them in RAM I want the ld-script to make them
a multiple of 8K long (and fill up with zeros because of
the compression) so that a fixup routine can copy the start of a new module over the end of the last page of the previous module and alias that page in the page table to both modules and then free up some memory.

Quoted 32 lines
Quoted 6 lines
Quoted 6 lines

There are
even experimental systems that allow the whole
kernel to be
changed without (apparent) re-booting.

A file with a 'tar' header is useful for

recovering

Quoted 4 lines
Quoted 4 lines

a
directory tree, intact, as it was initially
backed-up.
It has no usefulness in the kernel where the

content

Quoted 3 lines
Quoted 3 lines

of a file (or files) are located into various
offsets
in RAM. This is done by the linker and 'helper

code'

Quoted 3 lines
Quoted 1 line

within the kernel itself.

I seem to have misread here. I *don't* want to

change

Quoted 1 line

the kernel with tar, as you seem to assume. Thats

why

Quoted 2 lines

I'm asking for an ld-script. I want to be able to *extract* (READ-ONLY) modules from a kernelfile

that

Quoted 1 line

are compiled into this (not currently running)

kernel

Quoted 1 line

to insert them into the currently running kernel

to

Quoted 2 lines

update it. And I want to do it *with* the current module loader.

Quoted 6 lines

You need the original object files. You can't take portions of the statically-linked kernel. You need these original object files because they contain the required relocation information. Once they get linked into the kernel, the essential information is lost.

That to avoid is the whole idea. See my rant about a hypothethical module loader in my first post. That should make a Driver seem a loaded module in memory.

Quoted 2 lines

You can store these object files anyway you want.

I want tar because the ar header conflicts with the ELF header. The tar header does not.

Quoted 5 lines

The usual way to store them is to use ar. The existing module loader doesn't know how to extract the object files from an archive, but you could make a simple script to do it.

I seem to have included such a command into my first post.

Quoted 12 lines
Quoted 3 lines
Quoted 3 lines

You can readily run an install-system without any
runtime libraries and/or you can use temporary

ones.

Quoted 1 line
Quoted 1 line

This is currently done for every major

distribution.

Quoted 2 lines
Quoted 1 line

Of course it's done. You have 2 files: one

staticaly

Quoted 3 lines

linked to run at install time, one binary archive (descendent of tar) to install into the system. If I could make the binary do double duty as

Quoted 8 lines

install

Quoted 2 lines

archive, I could save 50% space. Thats a lot on a floppy based install. And make no mistake: Even

CDROM

Quoted 1 line

(not all, I know!) boot from a floppy image.

[SNIP]
to attempting to mount it. It's all there, it all

works

Quoted 1 line

and it doesn't waste the 50% space you claim above.

I wasn't writing about the boot image. I meant the root
image for install. For instance you need a staticaly linked mount to use and you need a dynamic one to install.

__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Logos und Klingeltöne fürs Handy bei http://sms.yahoo.de

#5 lore raw
In reply to Richard B. Johnson
Quoted 5 lines · Richard B. Johnson

Also, we have a module loader and unloader that allows modules to be inserted and removed from a running system. There are even experimental systems that allow the whole kernel to be changed without (apparent) re-booting.

Any pointers. I have heard rumors but I have never seen an actual implementation. Even one that failed in a lot of cases.

Eric

#6 lore raw
Quoted 9 lines · Eric W. Biederman
Quoted 5 lines · Richard B. Johnson

Also, we have a module loader and unloader that allows modules to be inserted and removed from a running system. There are even experimental systems that allow the whole kernel to be changed without (apparent) re-booting.

Any pointers. I have heard rumors but I have never seen an actual implementation. Even one that failed in a lot of cases.

I thought it was a confused description of kexec being able to reboot without involving lilo/grub/etc....

#7 lore raw
In reply to Eric W. Biederman
Quoted 11 lines · Eric W. Biederman
Quoted 5 lines · Richard B. Johnson

Also, we have a module loader and unloader that allows modules to be inserted and removed from a running system. There are even experimental systems that allow the whole kernel to be changed without (apparent) re-booting.

Any pointers. I have heard rumors but I have never seen an actual implementation. Even one that failed in a lot of cases.

Eric

I heard rumors, too. Something going on, on source-forge, but I haven't looked. I surmise that, if it works, it uses hooks for the "suspend-to-disk" code that is also supposed to work but I haven't ever seen either.

In principle, it should not be too hard to do on Intel.

(1) User-mode code opens a module and writes the new kernel into kernel space using ordinary read or write module function calls. The module kernel code saves the data in a temporary kmalloc()ed buffer.

(2) User mode code kills everybody except itself and dismounts all file-systems.

(3) User-mode code, via an ioctl() signals the module code to restart.

(4) The kernel-mode code disables all interrupts, then writes the saved data to a physical location, outside the normal kernel space.

(5) The kernel-mode code then copies some code to low RAM where there is a 1:1 virtual to physical translation below 1 megabyte. It then jumps there. The code needs to be relocatable, not a problem for the simple stuff it needs to do.

(6) Since the virtual:physical transation is 1:1, it can now disable paging.

(7) With paging disabled, it copies the saved data from the physical location used in (4) to offset 1 megabyte, the normal relocation address.

(8) It jumps to the kernel startup code at the normal relocated address.

FYI, I did something like this to non-distructively find the physical address of bad RAM a few years ago. I made a module that transitioned to 1:1 translation with paging disabled to find the real bad RAM (the test program had written some tokens to both sides of the failed area). It then transitioned back to paged mode and, ultimately, back to user-mode code, with the answer.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.