[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] Software packaging (was: opkg / coldmint)



Hi,

On maanantai 18 helmikuu 2013, Helmut Karlowski wrote:
> > I forgot that it would link the whole lib unless the dynamic linker was
> 
> And slow down process-launch even more.
> 
> How does it work in real dynamic linking? Is always the whole lib loaded
> or only the portions that are really needed?

That kind of files are memory mapped.  Kernel will then demand load them
into memory, page [1] at the time, when any application mapping that file
tries to access mapped memory address which content hasn't been loaded from
disk yet.

When dynamically linked program is created, linker adds dynamic linker
path to the binary.  Kernel will invoke the dynamic linker (ld.so) when
user runs the program.  Dynamic linker will memory map files for all
the libraries program links directly and sets up their symbol lookup tables
(library symbols get resolved when they're first called).

Because libraries have different kinds of data in different sections 
depending on how they're accessed, dynamic linker maps these sections
separately:
- code is read-only executable (const data is also often in code section)
  and shared
- data is read/write and copy-on-write (i.e. shared with other processes'
  mappings until program modifies the data)

Each mapping for each library takes at least one page of memory,
more if section is larger.


	- Eero

[1] MMU is typically set up to use 4kB pages, but depending on architecture,
    also larger ones can be used.  For disk performance reasons kernel could
    also load multiple pages when page fault happens.