This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Can I tell which version of newlib I have?


Dave Korn wrote:
On 25 April 2007 00:19, Ray Hurst wrote:

Brian Dessent wrote:

In the case of Cygwin, the C library is provided by Cygwin, in the form
of cygwin1.dll. Cygwin relies on newlib to implement some things, but
malloc is not one of them.

Technically you are correct. gcc does not care. However, gcc is
typically used to invoke the linker which does care where the C library
is. Most command lines that use gcc to compile and link do not specify
where the C library is as gcc or the linker knows where it is.

What I am asking is how do these programs find the C library on a cygwin
system running on windows? Specifically. I am looking for the library
that contains the malloc function but I would like the general info also.

Take a look at the output from "gcc -v" when compiling and linking a "Hello World":

--------------------------------<snip!>--------------------------------
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure
--verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls
--without-included-gettext --enable-version-specific-runtime-libs --without-x
--enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter
--disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm
--disable-win32-registry --enable-sjlj-exceptions
--enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/cc1.exe -quiet -v -D__CYGWIN32__
-D__CYGWIN__ -Dunix -D__unix__ -D__unix -idirafter
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib/../include/w3
2api -idirafter
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib/../../include
/w32api hello.c -quiet -dumpbase hello.c -mtune=pentiumpro -auxbase hello
-version -o /win/c/DOCUME~1/dk/LOCALS~1/Temp/ccccycor.s
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/include
/usr/include
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib/../include/w3
2api
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib/../../include
/w32api
End of search list.
GNU C version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
(i686-pc-cygwin)
compiled by GNU C version 3.4.4 (cygming special, gdc 0.12, using dmd
0.125).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/as.exe -o
/win/c/DOCUME~1/dk/LOCALS~1/Temp/cc8gFoYM.o
/win/c/DOCUME~1/dk/LOCALS~1/Temp/ccccycor.s
--------------------------------<snip!>--------------------------------


This is the interesting bit: the linker commandline.

--------------------------------<snip!>--------------------------------
 /usr/lib/gcc/i686-pc-cygwin/3.4.4/collect2.exe -Bdynamic
--dll-search-prefix=cyg -o hello.exe
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib/crt0.o
-L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4
-L/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib
-L/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../..
/win/c/DOCUME~1/dk/LOCALS~1/Temp/cc8gFoYM.o -lgcc -lcygwin -luser32 -lkernel32
-ladvapi32 -lshell32 -lgcc
--------------------------------<snip!>--------------------------------

  Gcc just supplies the relevant search paths for the libraries.  The standard
system libraries to link against are this bit:

--------------------------------<snip!>--------------------------------
-lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc
--------------------------------<snip!>--------------------------------

Where do they come from? Look at the start of the output again:

--------------------------------<snip!>--------------------------------
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
--------------------------------<snip!>--------------------------------

  That's the specs file.  Specs are an internal set of options that gcc uses
to specify how to parse a commandline and pass options on to the substages
(preprocessing, compilation, assembly, linking) of the whole process: see
section 3.15, "Specifying subprocesses and the switches to pass to them" in
"info gcc" for more detail.  The stuff it contains is actually built-in to the
gcc compile driver as well.  Look at the output of "gcc --help":

--------------------------------<snip!>--------------------------------
/tmp $ gcc --help
Usage: gcc [options] file...
Options:
  -pass-exit-codes         Exit with highest error code from a phase
  --help                   Display this information
  --target-help            Display target specific command line options
  (Use '-v --help' to display command line options of sub-processes)
  -dumpspecs               Display all of the built in spec strings
  -dumpversion             Display the version of the compiler
  -dumpmachine             Display the compiler's target processor
  -print-search-dirs       Display the directories in the compiler's search
path

  -print-libgcc-file-name  Display the name of the compiler's companion
library
  -print-file-name=<lib>   Display the full path to library <lib>
  -print-prog-name=<prog>  Display the full path to compiler component <prog>
  -print-multi-directory   Display the root directory for versions of libgcc
  -print-multi-lib         Display the mapping between command line options
and
                           multiple library search directories
  -print-multi-os-directory Display the relative path to OS libraries
  -Wa,<options>            Pass comma-separated <options> on to the assembler
  -Wp,<options>            Pass comma-separated <options> on to the
preprocessor

  -Wl,<options>            Pass comma-separated <options> on to the linker
  -Xassembler <arg>        Pass <arg> on to the assembler
  -Xpreprocessor <arg>     Pass <arg> on to the preprocessor
  -Xlinker <arg>           Pass <arg> on to the linker
  -save-temps              Do not delete intermediate files
  -pipe                    Use pipes rather than intermediate files
  -time                    Time the execution of each subprocess
  -specs=<file>            Override built-in specs with the contents of <file>
  -std=<standard>          Assume that the input sources are for <standard>
  -B <directory>           Add <directory> to the compiler's search paths
  -b <machine>             Run gcc for target <machine>, if installed
  -V <version>             Run gcc version number <version>, if installed
  -v                       Display the programs invoked by the compiler
  -###                     Like -v but options quoted and commands not
executed
  -E                       Preprocess only; do not compile, assemble or link
  -S                       Compile only; do not assemble or link
  -c                       Compile and assemble, but do not link
  -o <file>                Place the output into <file>
  -x <language>            Specify the language of the following input files
                           Permissible languages include: c c++ assembler none
                           'none' means revert to the default behavior of
                           guessing the language based on the file's extension

Options starting with -g, -f, -m, -O, -W, or --param are automatically
 passed on to the various sub-processes invoked by gcc.  In order to pass
 other options on to these processes the -W<letter> options must be used.

For bug reporting instructions, please see:
<URL:http://cygwin.com/problems.html>.
@_______. .
(       /"\
 ||--||(___)
 '"  '"'---'
/tmp $
--------------------------------<snip!>--------------------------------

  It's the various -print* and -dump* ones that are interest.  Take a look at
the specs:

--------------------------------<snip!>--------------------------------
/tmp $ gcc -dumpspecs 2>&1 | tee -a gcc.log
*asm:


*asm_debug: %{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}

*asm_final:


*asm_options: %a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}

*invoke_as:
%{!S:-o %|.s |
 as %(asm_options) %m.s %A }

*cpp:
%(cpp_cpu) %{posix:-D_POSIX_SOURCE}   %{mno-win32:%{mno-cygwin: %emno-cygwin
and mno-win32 are not compatible}}   %{mno-cygwin:-D__MSVCRT__ -D__MINGW32__
%{!ansi:%{mthreads:-D_MT}}}  %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__
%{!ansi:-Dunix} -D__unix__ -D__unix }  %{mwin32|mno-cygwin:-DWIN32 -D_WIN32
-D__WIN32 -D__WIN32__ %{!ansi:-DWINNT}}
%{!nostdinc:%{!mno-win32|mno-cygwin:-idirafter ../include/w32api%s -idirafter
../../include/w32api%s}}

*cpp_options:
%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}
%{f*} %{g*:%{!g0:%{!fno-working-directory:-fworking-directory}}} %{O*}
%{undef}

*cpp_debug_options:
%{d*}

*cpp_unique_options:
%{C|CC:%{!E:%eGCC does not support -C or -CC without -E}} %{!Q:-quiet}
%{nostdinc*} %{C} %{CC} %{v} %{I*} %{P} %I %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}
%{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}} %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}
%{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}} %{remap} %{g3:-dD} %{H} %C
%{D*&U*&A*} %{i*} %Z %i %{E|M|MM:%W{o*}}

*trad_capable_cpp:
cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}

*cc1:
%(cc1_cpu)


*cc1_options:
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}
%1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*} %{c|S:%{o*:-auxbase-strip
%*}%{!o*:-auxbase %b}}%{!c:%{!S:-auxbase %b}} %{g*} %{O*} %{W*&pedantic*} %{w}
%{std*&ansi&trigraphs} %{v:-version} %{pg:-p} %{p} %{f*} %{undef}
%{Qn:-fno-ident} %{--help:--help} %{--target-help:--target-help}
%{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}} %{fsyntax-only:-o %j} %{-param*}

*cc1plus:


*link_gcc_c_sequence: %G %L %G

*endfile:


*link: %{mwindows:--subsystem windows} %{mconsole:--subsystem console} %{shared: %{mdll: %eshared and mdll are not compatible}} %{shared: --shared} %{mdll:--dll} %{static:-Bstatic} %{!static:-Bdynamic} %{shared|mdll: -e %{mno-cygwin:_DllMainCRTStartup@12} %{!mno-cygwin:__cygwin_dll_entry@12}} %{!mno-cygwin:--dll-search-prefix=cyg}

*lib:
  %{pg:-lgmon}   %{!mno-cygwin:-lcygwin}
%{mno-cygwin:%{mthreads:-lmingwthrd} -lmingw32}   %{mwindows:-lgdi32
-lcomdlg32}   -luser32 -lkernel32 -ladvapi32 -lshell32

*libgcc:
%{mno-cygwin: %{mthreads:-lmingwthrd} -lmingw32} -lgcc
%{mno-cygwin:-lmoldname -lmingwex -lmsvcrt}

*startfile:
  %{shared|mdll: %{mno-cygwin:dllcrt2%O%s}}  %{!shared: %{!mdll:
%{!mno-cygwin:crt0%O%s} %{mno-cygwin:crt2%O%s}  %{pg:gcrt0%O%s}}}

*switches_need_spaces:


*cross_compile: 0

*version:
3.4.4

*multilib:
. ;

*multilib_defaults:


*multilib_extra:



*multilib_matches:



*multilib_exclusions:



*multilib_options:



*linker: collect2

*link_libgcc:
%D

*md_exec_prefix:


*md_startfile_prefix:



*md_startfile_prefix_1:



*startfile_prefix_spec:



*sysroot_suffix_spec:



*sysroot_hdrs_suffix_spec:



*cc1_cpu: %{!mtune*: %{m386:mtune=i386 %n`-m386' is deprecated. Use `-march=i386' or `-mtune=i386' instead. } %{m486:-mtune=i486 %n`-m486' is deprecated. Use `-march=i486' or `-mtune=i486' instead. } %{mpentium:-mtune=pentium %n`-mpentium' is deprecated. Use `-march=pentium' or `-mtune=pentium' instead. } %{mpentiumpro:-mtune=pentiumpro %n`-mpentiumpro' is deprecated. Use `-march=pentiumpro' or `-mtune=pentiumpro' instead. } %{mcpu=*:-mtune=%* %n`-mcpu=' is deprecated. Use `-mtune=' or '-march=' instead. }} %<mcpu=* %{mpni:-msse3 %n`-mpni' is deprecated. Use `-msse3' instead. } %{mno-pni:-mno-sse3 %n`-mno-pni' is deprecated. Use `-mno-sse3' instead. } %{mintel-syntax:-masm=intel %n`-mintel-syntax' is deprecated. Use `-masm=intel' instead. } %{mno-intel-syntax:-masm=att %n`-mno-intel-syntax' is deprecated. Use `-masm=att' instead. }

*mingw_include_path:
i686-pc-cygwin

*link_command:
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:    %(linker) %l %{pie:-pie} %X
%{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}    %{s} %{t} %{u*} %{x} %{z} %{Z}
%{!A:%{!nostdlib:%{!nostartfiles:%S}}}    %{static:} %{L*} %(link_libgcc) %o
%{fprofile-arcs|fprofile-generate:-lgcov}
%{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}
%{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}
--------------------------------<snip!>--------------------------------


This is the pertinent one:


--------------------------------<snip!>--------------------------------
*lib:
  %{pg:-lgmon}   %{!mno-cygwin:-lcygwin}
%{mno-cygwin:%{mthreads:-lmingwthrd} -lmingw32}   %{mwindows:-lgdi32
-lcomdlg32}   -luser32 -lkernel32 -ladvapi32 -lshell32
--------------------------------<snip!>--------------------------------

  You can look up the docs I mentioned above to see how it works, but I guess
you can probably see that it's the sort of thing that might be responsible for
causing

-lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc

to appear.  (The compiler prefixes and suffixes the list with -lgcc twice
automatically).

  So, now you know where the linker is told to search, and what for.  Most of
this is specified when the compiler is configured for a cygwin system.  If you
wanted to play with it, you could make a copy of the default specs file, hack
it about, and get gcc to make use of it by the -specs=<file> commandline
option.

  The final piece of the jigsaw?  You know it links against cygwin1.dll, you
know it searchs in /usr/lib, so let's take a look at the symbols defined
there:

/tmp $ nm /usr/lib/libcygwin.a | grep '__imp__'

and there, amongst many many others, you will see:

00000000 I __imp__lroundf
00000000 I __imp__lsearch
00000000 I __imp__lutimes
00000000 I __imp__mallinfo
00000000 I __imp__malloc
00000000 I __imp__malloc_stats
00000000 I __imp__malloc_trim
00000000 I __imp__malloc_usable_size
00000000 I __imp__mallopt
00000000 I __imp__matherr
00000000 I __imp__mblen
00000000 I __imp__mbrlen
00000000 I __imp__mbrtowc
00000000 I __imp__mbsinit

so, it gets malloc imported from cygwin1.dll.  There is no way to know from
the sight of the symbol whether it was originally from newlib or whether
cygwin supplied its own; that's the point at which you have to start checking
the sources to know.  (Though as Brian says, it's from cygwin.)


cheers, DaveK

Thanks. This is the stuff I was looking for. Ray


-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]