关于c runtime library

原创 2005年03月01日 13:43:00
Ramanathan Ramadass   Oct 14 2003, 8:53 pm     show options
Newsgroups: comp.compilers
From: ramanathan.ramad...@spirentcom.com (Ramanathan Ramadass) - Find messages by this author
Date: 14 Oct 2003 23:46:56 -0400
Local: Tues, Oct 14 2003 8:46 pm
Subject: GCC C/C++ runtime library question
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

Hi,

I am trying to replace the standard C and C++ libraries which comes
with a Linux distro with our own(licensed from a 3rd party vendor). We
will be providing the lower level layer which the C/C++ library
uses(i.e. the system calls). What i would like to do is replace the
standard and the runtime libraries which come with gcc with our own. I
am a newbie in this and hence have some basic questions;

1. What is the exact difference between the C runtime and the C
standard libraries i.e where does one end and the other begin;
specifically w.r.t gcc? While i am going through a lot of text(both
online and book form) i am not 100% clear on this.

2. In a gcc distribution where exactly does the compiler specific
magic lie within the runtime libraries? I might have to modify gcc to
use only my libraries but where and how do i begin? Currently i have
built the 3rd party vendor's library and am linking with it but for
some symbols i still have to go to the gcc runtimes. I am running "nm"
and extracting the object modules using "ar" for all the unresolved
symbols; which seems to be a roundabout way of doing things. What i
would like is to understand the structure of how gcc interfaces with
its runtimes. Would appreciate any and all help on this. Pointers to
other articles/links/books will also be very welcome.

Thanks
Ram

[Good luck.  The OS interface library, the standard C library, and the
magic helper code libraries are rarely easy to separate out, and the
low level details are rarely documented. -John]


Brian Inglis   Oct 18 2003, 12:33 pm     show options
Newsgroups: comp.compilers
From: Brian Inglis <Brian.Ing...@SystematicSw.ab.ca> - Find messages by this author
Date: 18 Oct 2003 15:31:45 -0400
Local: Sat, Oct 18 2003 12:31 pm
Subject: Re: GCC C/C++ runtime library question
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

On 14 Oct 2003 23:46:56 -0400 in comp.compilers,

ramanathan.ramad...@spirentcom.com (Ramanathan Ramadass) wrote:
>I am trying to replace the standard C and C++ libraries which comes
>with a Linux distro with our own(licensed from a 3rd party vendor). We
>will be providing the lower level layer which the C/C++ library
>uses(i.e. the system calls). What i would like to do is replace the
>standard and the runtime libraries which come with gcc with our own. I
>am a newbie in this and hence have some basic questions;

Your vendor should be able to provide information about replacing a
compiler specific library with theirs, assuming they don't provide a
compiler, and maybe even if they do. ;^>

>1. What is the exact difference between the C runtime and the C
>standard libraries i.e where does one end and the other begin;
>specifically w.r.t gcc? While i am going through a lot of text(both
>online and book form) i am not 100% clear on this.

If you have gcc installed, 'info gccint' gives you more
information about the compiler collection and its interfaces, and
there are web pages and manuals at http://gcc.gnu.org/onlinedocs
at the bottom under Current Development.
And there really is not a great distinction between C runtime and
standard libraries: the C standard library is a subset of the
POSIX standard library which is a subset of any *IX system's
library. Runtime support may be just another routine in the
library, or maybe flagged as such with an _.

>2. In a gcc distribution where exactly does the compiler specific
>magic lie within the runtime libraries? I might have to modify gcc to
>use only my libraries but where and how do i begin? Currently i have
>built the 3rd party vendor's library and am linking with it but for
>some symbols i still have to go to the gcc runtimes. I am running "nm"
>and extracting the object modules using "ar" for all the unresolved
>symbols; which seems to be a roundabout way of doing things. What i
>would like is to understand the structure of how gcc interfaces with
>its runtimes. Would appreciate any and all help on this. Pointers to
>other articles/links/books will also be very welcome.

If you're lucky, runtime support routines should begin with _.
Substituting standard libraries should only require specifying
the 3rd party header include directory on the compile/cc command
line -Iincdir and their standard library and directory on the
build/ld command line: -Llibdir -lstd.
Alternatively, environment variables CPATH, C_INCLUDE_PATH,
CPLUS_INCLUDE_PATH, and LIBRARY_PATH can be set to provide all
the directories.
The gcc/gpp/g++ driver programs shouldn't be hard to tweak to add
these paths and library, once you get everything working using
options or environment variables.

Getting any gcc helper routines to call your standard library
helper routines requires deleting any routines with the same name
from (a copy of) the gcc libraries glib*, and adding your
standard library both before and after glib* on the build/ld
command line.
Similarly, supplying your own system call interface routines
requires deleting any routines with the same name from glib*, and
adding your syscall library and its directory at the end of the
build/ld command line.
Alternatively, you could build total replacement libraries with
your standard and syscall routines, and only include those other
parts of glib* required by gcc, some with names starting with an
_.

The interesting part of the job starts with writing tests to
verify all this stuff works: info at http://gcc.gnu.org/install
and http://gcc.gnu.org/testing

You also need to give consideration to what you will do now to
make it possible/easier to handle compiler and library upgrades
(3rd party and gcc) in the future.

Haven't done this kind of stuff with gcc, but have dealt with
similar issues.

Thanks. Take care, Brian Inglis         Calgary, Alberta, Canada
--
Brian.Ing...@CSi.com    (Brian dot Inglis at SystematicSw dot ab dot ca)
    fake address                use address above to reply


Marco van de Voort   Oct 18 2003, 12:33 pm     show options
Newsgroups: comp.compilers
From: Marco van de Voort <mar...@stack.nl> - Find messages by this author
Date: 18 Oct 2003 15:32:33 -0400
Local: Sat, Oct 18 2003 12:32 pm
Subject: Re: GCC C/C++ runtime library question
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

Ramanathan Ramadass wrote:

(assuming some unix)

> 1. What is the exact difference between the C runtime and the C
> standard libraries i.e where does one end and the other begin;
> specifically w.r.t gcc? While i am going through a lot of text(both
> online and book form) i am not 100% clear on this.

Roughly, the runtime is libgcc, the stdlib is libc.  This can be seen
e.g.  on *BSD that use different libc's. (so what the default libc
might be, is platform dependant)

Besides these there are the ELF startup code files (crt*), the .o
files in /usr/lib

The OS interface is a series of calls defined by unistd.h, and usually
a real ugly macro to inline some syscall. You can never be sure that a
call with a certain name (in the stdlib) really exists in the
library. It might be a header only thing and via some macro wrapper
get magically turned into some other call.

> 2. In a gcc distribution where exactly does the compiler specific
> magic lie within the runtime libraries?

(no idea, don't develop with gcc, only use it as systems compiler)

> I might have to modify gcc to use only my libraries but where and how do i
> begin?

Start to link your binary, and see what calls are missing. Find out
what these calls are, and how they interact (e.g. by objdump -D small
static binaries)

> Currently i have built the 3rd party vendor's library and am linking with
> it but for some symbols i still have to go to the gcc runtimes. I am
> running "nm" and extracting the object modules using "ar" for all the
> unresolved symbols; which seems to be a roundabout way of doing things.

- Get the libc source
- objdump small programs using the symbols. Much easier to examine.

> What i would like is to understand the structure of how gcc interfaces
> with its runtimes. Would appreciate any and all help on this. Pointers to
> other articles/links/books will also be very welcome.

No idea. I looked at libc to implement our own runtime, but don't use gcc
(or libc)

> [Good luck.  The OS interface library, the standard C library, and the
> magic helper code libraries are rarely easy to separate out, and the
> low level details are rarely documented. -John]

My main frustration is that a symbol on C language level is not
guaranteed a symbol in the source. This makes POSIX useless if you
don't use C, and, together with liberal use of preprocessor macro's in
Unix headers in general hinders a lot of automatic conversion.

VBDis   Oct 18 2003, 12:43 pm     show options
Newsgroups: comp.compilers
From: v...@aol.com (VBDis) - Find messages by this author
Date: 18 Oct 2003 15:36:26 -0400
Local: Sat, Oct 18 2003 12:36 pm
Subject: Re: GCC C/C++ runtime library question
Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

ramanathan.ramad...@spirentcom.com (Ramanathan Ramadass) schreibt:

>1. What is the exact difference between the C runtime and the C
>standard libraries i.e where does one end and the other begin;
>specifically w.r.t gcc? While i am going through a lot of text(both
>online and book form) i am not 100% clear on this.

Currently I'm doing a similar job, extending the standard library of
another compiler for GNU compatibility. I intend to achieve that
compatibility by creating a glibc with all those modules, which are
not found in the compiler's standard library. Linking with that
library in the first place should exclude all multiply existing
modules.

Some suggestions:

Have a look at the glibc and related documentation. The glibc is a
merge of multiple C standards (C89, C99), and other POSIX
etc. standards and extensions.  The glibc package can be rebuilt with
a selection of these standards, when you modify features.h as
appropriate. At the same time you have a chance to introduce your own
#define for exclusion or replacement of specific modules with those
from your library.

>2. In a gcc distribution where exactly does the compiler specific
>magic lie within the runtime libraries? I might have to modify gcc to
>use only my libraries but where and how do i begin?

I don't know what "magic" you mean, gcc doesn't care for libraries -
that's the task of ld. But as gcc can be used as a cross compiler, at
least the platform specific header files reside in the
/lib/gcc-lib/... directories. You can create another target branch for
your library there, so that you can specify with --target whether gcc
shall compile for the default platform, using the standard glibc, or
for your target, using your glibc replacement. IMO the compiler itself
deserves no modifications herefore, as long as the target machine has
the same instruction set as the build machine.

> Currently i have built the 3rd party vendor's library and am linking
>with it but for some symbols i still have to go to the gcc
>runtimes. I am running "nm" and extracting the object modules using
>"ar" for all the unresolved symbols; which seems to be a roundabout
>way of doing things.

Locate the missing modules in the glibc package, and add these to your
project.  It may become tricky to remove unwanted dependencies from
the glibc "internal" header files.

DoDi


End of messages
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

C Runtime Library

msvcrt.dll (名称:Microsoft C Runtime Library)提供了printf,malloc,strcpy等C语言库函数,并且为使用C/C++(Vc)编绎的程序提供了初始化(...

C Runtime Library来历, API, MFC, ATL关系

CRT原先是指Microsoft开发的C RuntimeLibrary,用于操作系统的开发及运行。后来在此基础上开发了C++ Runtime Library,所以现在CRT是指Microsoft开发的...

C Runtime Library(MSVCRT)来历 .

msvcrt.dll (名称:Microsoft C Runtime Library)提供了printf,malloc,strcpy等C语言库函数,并且为使用C/C++(Vc)编绎的程序提供了初始化(...
  • cay22
  • cay22
  • 2012-01-17 08:50
  • 718

C Runtime Library来历, API, MFC, ATL关系

首先说明,我google了半天,想找到英文的关于这个资料,但是实在找不到,只好转载国人的讨论。   CRT原先是指Microsoft开发的C Runtime Library,用于操作系统的...

C Runtime Library(MSVCRT)来历

转载出处:http://www.byywee.com/page/M0/S256/256862.html msvcrt.dll (名称:Microsoft C Runtime Library)提供...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)