c++linuxgcclinkerembedded

MontaVista GCC linker throws `cannot find -lgcc_s`


I have the task of containerizing an ancient embedded build plan which uses the MontaVista GCC toolchain released in 2006. Unfortunately, the senior insists on using a setup similar to the old build server. Basically, I have a Windows Server 2025 Core container running the old toolchain using cygwin (I am using the current version).

I managed to get the compilation phase to work, however I have been struggling with the linker for quite a while now. When running the command mips_fp_be-g++ -shared -Wl,-soname,libscl.so.3 -o libscl.so.3.2.1 dbg/*.o api/*.o wrapper/*.o socket/*.o, the linker outputs a message about a missing library: /cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/ld: cannot find -lgcc_s. How can I fix this error? The library libgcc_s.so.1 is on the linker search path as shown below:

mips_fp_be-g++ --print-search-dirs

install: /opt/montavista/devkit/mips/fp_be/lib/gcc-lib/mips-hardhat-linux/3.3.1/
programs: =/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../lib/gcc-lib/mips-hardhat-linux/3.3.1/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../lib/gcc-lib/:/opt/montavista/devkit/mips/fp_be/lib/gcc-lib/mips-hardhat-linux/3.3.1/:/opt/montavista/devkit/mips/fp_be/lib/gcc-lib/mips-hardhat-linux/3.3.1/:/opt/montavista/devkit/mips/fp_be/lib/gcc-lib/mips-hardhat-linux/:/usr/lib/gcc/mips-hardhat-linux/3.3.1/:/usr/lib/gcc/mips-hardhat-linux/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../lib/gcc-lib/mips-hardhat-linux/3.3.1/../../../../mips-hardhat-linux/bin/mips-hardhat-linux/3.3.1/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../lib/gcc-lib/mips-hardhat-linux/3.3.1/../../../../mips-hardhat-linux/bin/:/opt/montavista/devkit/mips/fp_be/mips-hardhat-linux/bin/mips-hardhat-linux/3.3.1/:/opt/montavista/devkit/mips/fp_be/mips-hardhat-linux/bin/
libraries: =/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../lib/gcc-lib/mips-hardhat-linux/3.3.1/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../lib/gcc-lib/:/opt/montavista/devkit/mips/fp_be/lib/gcc-lib/mips-hardhat-linux/3.3.1/:/usr/lib/gcc/mips-hardhat-linux/3.3.1/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../lib/gcc-lib/mips-hardhat-linux/3.3.1/../../../../mips-hardhat-linux/lib/mips-hardhat-linux/3.3.1/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../lib/gcc-lib/mips-hardhat-linux/3.3.1/../../../../mips-hardhat-linux/lib/:/opt/montavista/devkit/mips/fp_be/mips-hardhat-linux/lib/mips-hardhat-linux/3.3.1/:/opt/montavista/devkit/mips/fp_be/mips-hardhat-linux/lib/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../target/lib/mips-hardhat-linux/3.3.1/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../target/lib/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../target/usr/lib/mips-hardhat-linux/3.3.1/:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../target/usr/lib/

However, the file libgcc_s.so.lnk is a (Windows) link to the library file supplied by MontaVista (libgcc_s.so.1), as shown below:

ls -al /cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin/../target/usr/lib/

total 35156
drwxrwx---+ 1 Administrators         ContainerAdministrator        0 Jul 31 09:01 .
drwxrwx---+ 1 ContainerAdministrator ContainerAdministrator        0 Jul 31 07:57 ..
-rwxr-x---+ 1 ContainerAdministrator ContainerAdministrator      108 Jul 11  2006 cpp.lnk
drwxrwx---+ 1 ContainerAdministrator ContainerAdministrator        0 Jul 31 07:45 iptables
-rwxr-x---+ 1 ContainerAdministrator ContainerAdministrator   679858 May 14  2006 ld-2.3.2.so
-rwxr-x---+ 1 ContainerAdministrator ContainerAdministrator      102 Jul 11  2006 ld.so.1.lnk
# output omitted
-rwxr-x---+ 1 ContainerAdministrator ContainerAdministrator   817661 Apr 30  2006 libgcc_s.so.1
-rwxr-x---+ 1 ContainerAdministrator ContainerAdministrator      106 Jul 11  2006 libgcc_s.so.lnk
# output omitted
drwxrwx---+ 1 ContainerAdministrator ContainerAdministrator        0 Jul 31 07:45 modules
drwxrwx---+ 1 ContainerAdministrator ContainerAdministrator        0 Jul 31 07:45 security

For reference, the environment variables are shown below:

env

PWD=/cygdrive/c/jenkins/workspace/xyz_master/libscl
PATH=/usr/bin:/cygdrive/c/MontaVista/opt/montavista/pro/host/bin:/cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin:/cygdrive/c/MontaVista/opt/montavista/comm:/cygdrive/c/MontaVista/bin
CC=mips_fp_be-g++
# output omitted

One thing to note is that I had to tweak the programs available on the path a bit, so that the MontaVista GCC toolchain is called. The alterations made by the commands inside the Containerfile were necessary. Basically, these instructions make sure the MonteVista MIPS toolchain is called first in the path.

edit on 2025-08-01

Previously, the Containerfile created manual links to several of the tools used by the toolchain as shown below:

RUN powershell -Command \
    Expand-Archive -Path "C:\\MontaVista.zip" -DestinationPath "C:\\"; \
    Remove-Item -Force "C:\\MontaVista.zip"
RUN del C:\MontaVista\opt\montavista\pro\devkit\mips\fp_be\target\usr\include\asm.lnk \
    && mklink C:\MontaVista\opt\montavista\pro\devkit\mips\fp_be\target\usr\include\asm C:\MontaVista\opt\montavista\pro\devkit\mips\fp_be\target\usr\include\asm-mips \
    && move C:\MontaVista\bin\as.exe C:\MontaVista\bin\as_backup.exe \
    && mklink C:\MontaVista\bin\as.exe C:\MontaVista\opt\montavista\pro\devkit\mips\fp_be\bin\mips_fp_be-as.exe \
    && move C:\MontaVista\bin\ld.exe C:\MontaVista\bin\ld_backup.exe \
    && mklink C:\MontaVista\opt\montavista\pro\devkit\mips\fp_be\bin\ld.exe C:\MontaVista\opt\montavista\pro\devkit\mips\fp_be\bin\mips_fp_be-ld.exe

However, I suspect that the tools (as, ld, collect2, etc.) are loaded from an incorrect location. I found a batch script that mounts part of the toolchain under /usr/bin and /usr/lib inside the cygwin installation; those directories are the first referenced by the environment variable $PATH and by the linker search path. I am currently trying to figure out which directory to mount under the path so that the tools are correctly loaded. The script is shown below:

@Echo Off

:: cygwin.cmd               doru.carastan@mvista.com
:: 
:: Starts the Cygwin bash or sets a proper Cygwin mount table.
::
:: Command options:
::  [-w]   Starts the Cygwin bash shell or
::  -m     (re)builds the default Cygwin mount table
::  -v     verbose
:: 
:: Changes:
::   2003/11/11 - Peter Rehley <prehley@mvista.com>
::     - Removed start items.  Just call bash directly.
::       Prevents two dos prompts from showing.
::     - Also turn echo on when -v is used.  It was off
::   2003/12/15 - Doru Carastan <doru.carastan@mvista.com>
::     - Double quoted the CYGWIN_ROOT variable.
::     - Show root path in window title.

if "%1" == "-v" shift & echo on

::for /f "delims=" %%p in ('bin\cygpath -a -w /') do set CYGWIN_ROOT=%%p
set HOME=C:\MontaVista
set CYGWIN_ROOT=C:\MontaVista

if "%1" == "-m" goto MOUNT

set CYGWIN=codepage:oem

title BASH Shell   ---   '%CYGWIN_ROOT%' mounted as /
"%CYGWIN_ROOT%\bin\bash.exe" --login -i
goto EOF
exit %ERRORLEVEL%


:MOUNT

echo Setting Cygwin mount table based on %CYGWIN_ROOT% ...

pushd "%CYGWIN_ROOT%\bin"

"%CYGWIN_ROOT%\bin\umount.exe" -A
"%CYGWIN_ROOT%\bin\mount.exe" -f -s -b "%CYGWIN_ROOT%\bin" "/usr/bin"
"%CYGWIN_ROOT%\bin\mount.exe" -f -s -b "%CYGWIN_ROOT%\lib" "/usr/lib"
"%CYGWIN_ROOT%\bin\mount.exe" -f -s -b "%CYGWIN_ROOT%" "/"
"%CYGWIN_ROOT%\bin\mount.exe" -s -b --change-cygdrive-prefix "/cygdrive"
"%CYGWIN_ROOT%\bin\mount.exe"

popd

:EOF

My guess is that either one of the directories /cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin or /cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/mips-hardhat-linux/bin contains the correct binaries.

The snippet below shows the directory listing of ls -al /cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin:

ls -al /cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/bin

total 0
drwxr-xr-x    2 Administ Kein         4096 Jul 31 15:51 .
drwxr-xr-x   15 Administ Kein            0 Jul 31 16:04 ..
-rwxr-xr-x    1 Administ Kein        25018 Apr 30  2006 apxs
-rwxr-xr-x    1 Administ Kein         1917 Jan 14  2004 glib-config
-rwxr-xr-x    1 Administ Kein      2676098 Apr 16  2006 mips_fp_be-addr2line.exe
-rwxr-xr-x    1 Administ Kein      2584605 Apr 16  2006 mips_fp_be-ar.exe
-rwxr-xr-x    1 Administ Kein      3465718 Apr 16  2006 mips_fp_be-as.exe
-rwxr-xr-x    1 Administ Kein      2699561 Apr 16  2006 mips_fp_be-c++filt.exe
-rwxr-xr-x    1 Administ Kein       903226 Apr 30  2006 mips_fp_be-cpp.exe
-rwxr-xr-x    1 Administ Kein         8760 Feb  6  2006 mips_fp_be-e2fs_install
-rwxr-xr-x    1 Administ Kein       904216 Apr 30  2006 mips_fp_be-g++.exe
-rwxr-xr-x    1 Administ Kein       901144 Apr 30  2006 mips_fp_be-gcc.exe
-rwxr-xr-x    1 Administ Kein       766813 Apr 30  2006 mips_fp_be-gcov.exe
-rwxr-xr-x    1 Administ Kein      8658973 Feb  6  2006 mips_fp_be-gdb.exe
-rwxr-xr-x    1 Administ Kein      2870275 Apr 16  2006 mips_fp_be-gprof.exe
-rwxr-xr-x    1 Administ Kein       630959 Dec 24  2003 mips_fp_be-initdconfig.exe
-rwxr-xr-x    1 Administ Kein      2488675 Dec 24  2003 mips_fp_be-ksymoops.exe
-rwxr-xr-x    1 Administ Kein      3258783 Apr 16  2006 mips_fp_be-ld.exe
-rwxr-xr-x    1 Administ Kein         6922 May  7  2004 mips_fp_be-libindex
-rwxr-xr-x    1 Administ Kein        15610 May  7  2004 mips_fp_be-libopt
-rwxr-xr-x    1 Administ Kein         8213 Dec 24  2003 mips_fp_be-libtoolize
-rwxr-xr-x    1 Administ Kein      2720814 Apr 16  2006 mips_fp_be-nm.exe
-rwxr-xr-x    1 Administ Kein      3093750 Apr 16  2006 mips_fp_be-objcopy.exe
-rwxr-xr-x    1 Administ Kein      3195519 Apr 16  2006 mips_fp_be-objdump.exe
-rwxr-xr-x    1 Administ Kein      2587165 Apr 16  2006 mips_fp_be-ranlib.exe
-rwxr-xr-x    1 Administ Kein      1196401 Apr 16  2006 mips_fp_be-readelf.exe
-rwxr-xr-x    1 Administ Kein       630959 Dec 24  2003 mips_fp_be-shellconfig.exe
-rwxr-xr-x    1 Administ Kein      2539522 Apr 16  2006 mips_fp_be-size.exe
-rwxr-xr-x    1 Administ Kein      2573054 Apr 16  2006 mips_fp_be-strings.exe
-rwxr-xr-x    1 Administ Kein      3093750 Apr 16  2006 mips_fp_be-strip.exe

Finally, the snippet below displays the output of ls -al /cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/mips-hardhat-linux/bin:

ls -al /cygdrive/c/MontaVista/opt/montavista/pro/devkit/mips/fp_be/mips-hardhat-linux/bin

drwxr-xr-x    2 Administ Kein         4096 Jul 31 15:52 .
drwxr-xr-x    5 Administ Kein            0 Jul 31 15:52 ..
-rw-r--r--    1 Administ Kein          134 Jul 11  2006 ar.exe.lnk
-rw-r--r--    1 Administ Kein          134 Jul 11  2006 as.exe.lnk
-rw-r--r--    1 Administ Kein          136 Jul 11  2006 cpp.exe.lnk
-rw-r--r--    1 Administ Kein          136 Jul 11  2006 g++.exe.lnk
-rw-r--r--    1 Administ Kein          136 Jul 11  2006 gcc.exe.lnk
-rw-r--r--    1 Administ Kein          138 Jul 11  2006 gcov.exe.lnk
-rw-r--r--    1 Administ Kein           96 Jul 11  2006 gnm.exe.lnk
-rw-r--r--    1 Administ Kein          102 Jul 11  2006 gstrip.exe.lnk
-rw-r--r--    1 Administ Kein          134 Jul 11  2006 ld.exe.lnk
-rw-r--r--    1 Administ Kein          134 Jul 11  2006 nm.exe.lnk
-rw-r--r--    1 Administ Kein          142 Jul 11  2006 ranlib.exe.lnk
-rw-r--r--    1 Administ Kein          140 Jul 11  2006 strip.exe.lnk

How can I make sure that /usr/bin and /usr/lib point to the correct directories for the cross compile toolchain?

The senior developer strictly advised me not to edit the build plan, so I can't change the linker options. If you need any more information, please leave a comment. Thank you for your help.


Solution

  • The problem was caused by the Windows shortcuts (.lnk files), which are used as symbolic links, created by MontaVista in 2006 not correctly being resolved.

    The first issue that at some point in time the shortcut resolution mechanism of cygwin changed and the current cygwin version 3.6.4-1 can not correctly resolve the old-style shortcuts created in 2006 as links. Thus, I switched back to cygwin version 2.10.0-1 available on the cygwin time machine. This resolved the issue on my local system.

    However, when working with Windows containers there were several issues with the file attributes missing due to the file system being used by docker. I initially tried to unzip the ZIP archive into the container file system during the build phase so that the container would start as fast as possible and be self-contained. However, the shortcut resolution did not work due to issues with the file attributes. Thus, as a fix given that the container is an intermediate solution while modernising the build process, I decided to mount the unzipped directory containing the compiler using docker's -v option: docker run --rm --name mips-build -v C:\xyz\resources\MontaVista:C:\MontaVista mips-build:0.0.0.

    However, the compiler needs to be located inside the "D: drive". Thus, I created a symbolic link as part of the CMD instruction within the Docker file:

    CMD [ "C:\\cygwin64\\bin\\bash.exe", "--login", "-i", "-c", "ln -s /cygdrive/c/montavista/ /cygdrive/d/MontaVista", "&&", "..." ]