130 likes | 269 Vues
The creation of a library following cross-compiler setup is crucial in system development. Selection of the right library, such as Newlib or GNU libc, impacts the compilation and running of programs. Key considerations include conforming to standards like ANSI and IEEE, ensuring that the library supports special functions dictated by the hardware, and implementing reentrancy for multiprocessor environments. Understanding the hierarchy of the compiler, library, and operating system allows for smoother interaction and optimal performance. This guide explores library porting and its critical aspects.
E N D
Building a target library An example of Newlib
Role of a library • After the creation of the cross compiler the creation of a library is the next major task • There are a number of choices • If the system has pre-compiled or source libraries that can be used • May not be possible will all compilers or languages • Use the standard GNU libc • Port another library
Where does the library fit in the system? • There is a 3 level hierarchy of compiler – library – and operating system • The link between C and the library should be straight forward • The OS – library link can be more problematic • It is possible to do without a library Compiler Operating System Library Implements calls Adds functionality Does the calls Calls functions getchar,
Which library? • Selection of the library is important • The features and functions of the board may dictate the library • i.e. if the board has lots of special, non-standard functions your library will have to implement these • Should use conformant library • i.e. ANSI, IEEE • Beware of over conformance
GNUlibc vs Newlib vs Minos • There are often a number of options • The original libraries with the board • In our case the Minos libraries • GNU has its own library GNU libc • There are a number of other libraries around • For example Newlib developed by Cygnus for cross development • Another library, slib, has been developed for the uCLinux, embedded linux system
Which library? GNU libc Newlib Minos lib + + - -
Using Newlib • Newlib is a good choice for embedded systems work • It provides ANSI and K & R standard C libraries • It has a good range of functionality • It is reasonably small • It is intended for porting – lots of ports available • Integrated with GNU
Issues around porting a library • Does the code need to be reentrant? • This is only really important in a multiprocessing environment • In general it is better to build a reentrant library • The library may have to assume that there is no/limited OS support for reentrancy • Newlib provides library support for reentrancy
Reentrancy • If the Operating System does not provide support for process state variables, i.e. error numbers, file descriptors, then either the library code will be non-reentrant or the library will have to support such variables Process 1 Process 2 Read, write, etc Volatile State data Volatile State data Library Code
System Call Interface • _open_r • _close_r • _lseek_r • _read_r • _write_r • _fork_r • _wait_r • _stat_r • _fstat_r • _link_r • _unlink_r • _sbrk_r