https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69761
Bug ID: 69761 Summary: collect2 cannot find ld when built with in-tree binutils on Cygwin Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: john.levin at tutanota dot com Target Milestone: --- When linking, collect2 cannot find ld if gcc is built with in-tree binutils on Cygwin. Command line to reproduce the bug: avr-gcc -v -Wl,-debug (There are no input files. This is a minimal reproduction of the bug.) Output from running the above command: Using built-in specs. Reading specs from /opt/test-a/lib/gcc/avr/5.3.0/device-specs/specs-avr2 COLLECT_GCC=avr-gcc COLLECT_LTO_WRAPPER=/opt/test-a/libexec/gcc/avr/5.3.0/lto-wrapper.exe Target: avr Configured with: ../gcc-5.3.0/configure --target=avr --prefix=/opt/test-a --without-headers --enable-languages=c --disable-werror Thread model: single gcc version 5.3.0 (GCC) COMPILER_PATH=/opt/test-a/libexec/gcc/avr/5.3.0/:/opt/test-a/libexec/gcc/avr/5.3.0/:/opt/test-a/libexec/gcc/avr/:/opt/test-a/lib/gcc/avr/5.3.0/:/opt/test-a/lib/gcc/avr/:/opt/test-a/lib/gcc/avr/5.3.0/../../../../avr/bin/ LIBRARY_PATH=/opt/test-a/lib/gcc/avr/5.3.0/:/opt/test-a/lib/gcc/avr/5.3.0/../../../../avr/lib/ COLLECT_GCC_OPTIONS='-v' '-specs=device-specs/specs-avr2' /opt/test-a/libexec/gcc/avr/5.3.0/collect2.exe -plugin /opt/test-a/libexec/gcc/avr/5.3.0/cyglto_plugin-0.dll -plugin-opt=/opt/test-a/libexec/gcc/avr/5.3.0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/cc35FaPo.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lc -L/opt/test-a/lib/gcc/avr/5.3.0 -L/opt/test-a/lib/gcc/avr/5.3.0/../../../../avr/lib -debug --start-group -lgcc -lm -lc --end-group Convert string '/opt/test-a/libexec/gcc/avr/5.3.0/:/opt/test-a/libexec/gcc/avr/5.3.0/:/opt/test-a/libexec/gcc/avr/:/opt/test-a/lib/gcc/avr/5.3.0/:/opt/test-a/lib/gcc/avr/:/opt/test-a/lib/gcc/avr/5.3.0/../../../../avr/bin/' into prefixes, separator = ':' - add prefix: /opt/test-a/libexec/gcc/avr/5.3.0/ - add prefix: /opt/test-a/libexec/gcc/avr/5.3.0/ - add prefix: /opt/test-a/libexec/gcc/avr/ - add prefix: /opt/test-a/lib/gcc/avr/5.3.0/ - add prefix: /opt/test-a/lib/gcc/avr/ - add prefix: /opt/test-a/lib/gcc/avr/5.3.0/../../../../avr/bin/ Convert string '/usr/local/bin:/usr/bin:/opt/test-a/bin' into prefixes, separator = ':' - add prefix: /usr/local/bin/ - add prefix: /usr/bin/ - add prefix: /opt/test-a/bin/ Looking for 'real-ld' Looking for 'collect-ld' Looking for 'ld-new.exe' Looking for 'avr-ld-new.exe' Looking for 'gnm' Looking for 'avr-gnm' Looking for 'nm' Looking for 'avr-nm' Looking for 'gstrip' Looking for 'avr-gstrip' Looking for 'strip' Looking for 'avr-strip' Looking for 'avr-gcc' Looking for 'avr-gcc' collect2 version 5.3.0 ld_file_name = not found c_file_name = /opt/test-a/bin/avr-gcc nm_file_name = not found strip_file_name = not found c_file = /tmp/ccOdjCVk.c o_file = /tmp/ccIIRg3V.o COLLECT_GCC_OPTIONS = '-v' '-specs=device-specs/specs-avr2' COLLECT_GCC = avr-gcc COMPILER_PATH = /opt/test-a/libexec/gcc/avr/5.3.0/:/opt/test-a/libexec/gcc/avr/5.3.0/:/opt/test-a/libexec/gcc/avr/:/opt/test-a/lib/gcc/avr/5.3.0/:/opt/test-a/lib/gcc/avr/:/opt/test-a/lib/gcc/avr/5.3.0/../../../../avr/bin/ LIBRARY_PATH = /opt/test-a/lib/gcc/avr/5.3.0/:/opt/test-a/lib/gcc/avr/5.3.0/../../../../avr/lib/ [cannot find ld] -plugin /opt/test-a/libexec/gcc/avr/5.3.0/cyglto_plugin-0.dll -plugin-opt=/opt/test-a/libexec/gcc/avr/5.3.0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/cc35FaPo.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lc -L/opt/test-a/lib/gcc/avr/5.3.0 -L/opt/test-a/lib/gcc/avr/5.3.0/../../../../avr/lib --start-group -lgcc -lm -lc --end-group collect2: fatal error: cannot find 'ld' compilation terminated. [Leaving /tmp/ccOdjCVk.c] [Leaving /tmp/ccIIRg3V.o] Tested with gcc 5.3.0 and binutils 2.24 (newer versions of binutils don't work in-tree; that has been fixed on gcc trunk). Actual result: Linking fails with the following error: collect2: fatal error: cannot find 'ld' Expected result: collect2 finds and executes ld Here are the steps that lead to the wrong ld name being used by collect2: 1. gcc/configure detects an in-tree ld and sets gcc_cv_ld accordingly, including the exe extension (remember, this is Cygwin): elif test -f $gcc_cv_ld_gld_srcdir/configure.in \ && test -f ../ld/Makefile \ && test x$build = x$host; then gcc_cv_ld=../ld/ld-new$build_exeext config.log: gcc_cv_ld=../ld/ld-new.exe 2. gcc/configure sets PLUGIN_LD_SUFFIX to the basename of the detected ld, but because it does not strip the exe extension, it won't get converted from ld-new to the actual installed name ld: PLUGIN_LD_SUFFIX=`basename $gcc_cv_ld | sed -e "s,$target_alias-,,"` # if the PLUGIN_LD is set ld-new, just have it as ld # as that is the installed named. if test x$PLUGIN_LD_SUFFIX = xld-new \ || test x$PLUGIN_LD_SUFFIX = xcollect-ld ; then PLUGIN_LD_SUFFIX=ld fi config.log: #define PLUGIN_LD_SUFFIX "ld-new.exe" 3. gcc/collect2.c uses the incorrect value from PLUGIN_LD_SUFFIX as the name of the linker, which can be seen in the debug output when linking: Looking for 'ld-new.exe' Looking for 'avr-ld-new.exe' Changing the following line in gcc/configure.ac to remove the exe extension fixes the bug: -PLUGIN_LD_SUFFIX=`basename $gcc_cv_ld | sed -e "s,$target_alias-,,"` +PLUGIN_LD_SUFFIX=`basename $gcc_cv_ld $build_exeext | sed -e "s,$target_alias-,,"`