X-Spam-Check-By: sourceware.org From: "Dave Korn" To: References: <462E734D DOT F08DE9A AT dessent DOT net> <462E7390 DOT 3DC65869 AT dessent DOT net> <462E8715 DOT DFA7F457 AT dessent DOT net> Subject: RE: Can I tell which version of newlib I have? Date: Wed, 25 Apr 2007 01:44:03 +0100 Message-ID: <013501c786d2$d3622ff0$2e08a8c0@CAM.ARTIMI.COM> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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": ---------------------------------------------------------------- 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 ---------------------------------------------------------------- This is the interesting bit: the linker commandline. ---------------------------------------------------------------- /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 ---------------------------------------------------------------- Gcc just supplies the relevant search paths for the libraries. The standard system libraries to link against are this bit: ---------------------------------------------------------------- -lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc ---------------------------------------------------------------- Where do they come from? Look at the start of the output again: ---------------------------------------------------------------- Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs ---------------------------------------------------------------- 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": ---------------------------------------------------------------- /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= Display the full path to library -print-prog-name= Display the full path to compiler component -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, Pass comma-separated on to the assembler -Wp, Pass comma-separated on to the preprocessor -Wl, Pass comma-separated on to the linker -Xassembler Pass on to the assembler -Xpreprocessor Pass on to the preprocessor -Xlinker Pass 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= Override built-in specs with the contents of -std= Assume that the input sources are for -B Add to the compiler's search paths -b Run gcc for target , if installed -V Run gcc version number , 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 Place the output into -x 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 options must be used. For bug reporting instructions, please see: . @_______. . ( /"\ ||--||(___) '" '"'---' /tmp $ ---------------------------------------------------------------- It's the various -print* and -dump* ones that are interest. Take a look at the specs: ---------------------------------------------------------------- /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 AT 12} %{!mno-cygwin:__cygwin_dll_entry AT 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. }} %-------------------------------- This is the pertinent one: ---------------------------------------------------------------- *lib: %{pg:-lgmon} %{!mno-cygwin:-lcygwin} %{mno-cygwin:%{mthreads:-lmingwthrd} -lmingw32} %{mwindows:-lgdi32 -lcomdlg32} -luser32 -lkernel32 -ladvapi32 -lshell32 ---------------------------------------------------------------- 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= 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 -- Can't think of a witty .sigline today.... -- 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/