Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cygwin Build Broken #1672

Closed
patacongo opened this issue Aug 30, 2020 · 10 comments · Fixed by #1682
Closed

Cygwin Build Broken #1672

patacongo opened this issue Aug 30, 2020 · 10 comments · Fixed by #1682
Labels
blocker Release Blocker bug Something isn't working
Milestone

Comments

@patacongo
Copy link
Contributor

PR #1450 broke the Cygwin build and it is still broken in the current master. Consider this:

$ tools/configure.sh -c nucleo-l476rg:nsh
$ make -j V=1

Results in:

arm-none-eabi-ld --entry=__start -nostartfiles -nodefaultlibs -g -T "D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\boards\arm\stm32l4\nucleo-l476rg\scripts\l476rg.ld"  -L"D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\staging" -L"D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\arch\arm\src\board" -L "c:/ ./ (x86)/ ./ ./ embedded/ 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/" -L "c:/ ./ (x86)/ ./ ./ embedded/ 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/" \
        -o "D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\nuttx.exe"   \
        --start-group -lsched -ldrivers -lboards -lc -lmm -larch -lxx -lapps -lfs -lbinfmt -lboard -lgcc -lm --end-group
C:\Program Files (x86)\GNU Tools ARM Embedded\9 2019-q4-major\bin\arm-none-eabi-ld.exe: cannot find -lgcc
C:\Program Files (x86)\GNU Tools ARM Embedded\9 2019-q4-major\bin\arm-none-eabi-ld.exe: cannot find -lm
make[1]: *** [Makefile:172: nuttx.exe] Error 1

Trying again with a different configuration, no -j and no V=1 gives me the same error:

$ make distclean
$ tools/configure.sh -c stm32f4discovery:nsh
...
LD: nuttx
C:\Program Files (x86)\GNU Tools ARM Embedded\9 2019-q4-major\bin\arm-none-eabi-ld.exe: cannot find -lgcc
C:\Program Files (x86)\GNU Tools ARM Embedded\9 2019-q4-major\bin\arm-none-eabi-ld.exe: cannot find -lm
make[1]: *** [Makefile:172: nuttx.exe] Error 1

The problem is due to this commit:

commit 4910d43ab0fc360dbddb1f8a31db2a3ee383b46d
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date:   Wed Jul 15 20:51:26 2020 +0800

    build: Move the toolchain library setting to the common place

    so all boards support C++ automatically

Commit 4910d43 adds logic like the following to all Toolchain.defs files:

+
+# Add the builtin library
+
+EXTRA_LIBS += -lgcc
+EXTRA_LIBPATHS += -L "${dir ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcc.a}}"
+
+ifneq ($(CONFIG_LIBM),y)
+  EXTRA_LIBS += -lm
+  EXTRA_LIBPATHS += -L "${dir ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}}"
+endif
+
+ifeq ($(CONFIG_CXX_LIBSUPCXX),y)
+  EXTRA_LIBS += -lsupc++
+  EXTRA_LIBPATHS += -L "${dir ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a}}"
+endif

But look what happens under Cygwin:

$ arm-none-eabi-gcc --print-file-name=libgcc.a
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/libgcc.a

$ dir `arm-none-eabi-gcc --print-file-name=libgcc.a`
dir: cannot access 'c:/program': No such file or directory
dir: cannot access 'files': No such file or directory
dir: cannot access '(x86)/gnu': No such file or directory
dir: cannot access 'arm': No such file or directory
dir: cannot access 'embedded/9': No such file or directory
dir: cannot access '2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/libgcc.a'$'\r': No such file or directory
...

Broken!

@patacongo patacongo added blocker Release Blocker bug Something isn't working labels Aug 30, 2020
@patacongo
Copy link
Contributor Author

This problem really applies to any path that contains spaces or any unusual characters. It breaks on Cygwin because of the extensive use of unusual characters under Windows. But it is equally broken on other platforms.

We must not release code with this showstopping bug in it.

@protobits protobits added this to the v10.0 milestone Aug 30, 2020
@protobits
Copy link
Contributor

I added this to the next release milestone so that it becomes a blocker for next release

@protobits
Copy link
Contributor

(assuming 10.0 will be next, we can rename it to whatever we think it should be)

@patacongo
Copy link
Contributor Author

This has been broken since July 15. This is why is it essential to get at least one Cygwin build using a Windows native toolchain into the PR checks.

@patacongo
Copy link
Contributor Author

$ dir arm-none-eabi-gcc --print-file-name=libgcc.a
dir: cannot access 'c:/program': No such file or directory
dir: cannot access 'files': No such file or directory
dir: cannot access '(x86)/gnu': No such file or directory
dir: cannot access 'arm': No such file or directory
dir: cannot access 'embedded/9': No such file or directory
dir: cannot access '2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/libgcc.a'$'\r': No such file or directory
...

Just as a clarification. The above uses the command 'dir' which is not the same as the make 'dir' command. So lets do things right:

diff --git a/arch/arm/src/armv7-m/Toolchain.defs b/arch/arm/src/armv7-m/Toolchain.defs
index 74e071bb0f..4d3b80c42f 100644
--- a/arch/arm/src/armv7-m/Toolchain.defs
+++ b/arch/arm/src/armv7-m/Toolchain.defs
@@ -155,6 +155,9 @@ OBJDUMP = $(CROSSDEV)objdump
 EXTRA_LIBS += -lgcc
 EXTRA_LIBPATHS += -L "${dir ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name}}"

+$(warning libgcc= ${shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name})
+$(warning EXTRA_LIBPATHS=$(EXTRA_LIBPATHS))
+
 ifneq ($(CONFIG_LIBM),y)
   EXTRA_LIBS += -lm
   EXTRA_LIBPATHS += -L "${dir ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libm.a}}"

Now we see:

make[1]: Entering directory '/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src'
/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/armv7-m/Toolchain.defs:158: libgcc= c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a
/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/armv7-m/Toolchain.defs:159: EXTRA_LIBPATHS=-L "c:/ ./ (x86)/ ./ ./ embedded/ 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/"
make[2]: Entering directory '/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/board'
/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/armv7-m/Toolchain.defs:158: libgcc= c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a
/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/armv7-m/Toolchain.defs:159: EXTRA_LIBPATHS=-L "c:/ ./ (x86)/ ./ ./ embedded/ 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/"
/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/armv7-m/Toolchain.defs:158: libgcc= c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a
/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/armv7-m/Toolchain.defs:159: EXTRA_LIBPATHS=-L "c:/ ./ (x86)/ ./ ./ embedded/ 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/" -L "c:/ ./ (x86)/ ./ ./ embedded/ 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/" -L "c:/ ./ (x86)/ ./ ./ embedded/ 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/"
make[2]: 'libboard.a' is up to date.
make[2]: Leaving directory '/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/board'
LD: nuttx
C:\Program Files (x86)\GNU Tools ARM Embedded\9 2019-q4-major\bin\arm-none-eabi-ld.exe: cannot find -lgcc
C:\Program Files (x86)\GNU Tools ARM Embedded\9 2019-q4-major\bin\arm-none-eabi-ld.exe: cannot find -lm
make[1]: *** [Makefile:172: nuttx.exe] Error 1

Proving that PR #1450 is the cause of the Cygwin build failure.

@btashton
Copy link
Contributor

This has been broken since July 15. This is why is it essential to get at least one Cygwin build using a Windows native toolchain into the PR checks.

There is a PR that I put up months aggo and then closed a couple days ago because I did not have the time to finish that adds Cygwin to the CI. I did not quite understand how to get the right toolchain involved, but we could at least get the sim building which hits a lot of the build infrastructure code.

@patacongo
Copy link
Contributor Author

patacongo commented Aug 30, 2020

I believe the the root cause of the problem is this:

  1. When a Windows native tool is used (ie., CONFIG_CYGWIN_TOOL=y), then the compiler will return a Windows style path and not a POSIX compatible path
  2. the make 'dir' command expects a POSIX style path.

So the solution might be to use cygpath to convert the windows path to a Windows path like:

EXTRA_LIBS += -lgcc
LIBGCC_PATH = ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcc.a}

ifeq ($(CONFIG_CYWGIN_WINTOOL),y)
  EXTRA_LIBPATHS += -L "${dir $(shell cygpath -u $(LIBGCC_PATH)}"
else
  EXTRA_LIBPATHS += -L "${dir $(LIBGCC_PATH)}"
endif

@xiaoxiang781216
Copy link
Contributor

But EXTRA_LIBPATHS is finally consumed by arm-none-eabi-ld which require Windows style path, not POSIX style path?

@patacongo
Copy link
Contributor Author

But EXTRA_LIBPATHS is finally consumed by arm-none-eabi-ld which require Windows style path, not POSIX style path?

The Bash dirname seems to work okay:

$ arm-none-eabi-gcc --print-file-name=libgcc.a
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/libgcc.a
$ dirname "c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/libgcc.a"
c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1

patacongo pushed a commit to patacongo/nuttx that referenced this issue Aug 31, 2020
PR apache#1450 broke the Cygwin build.  Refer to Issue apache#1672.

The use of of logic like:

    EXTRA_LIBPATHS += -L "${dir ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcc.a}}"

fails when the Toolchain $(CC) is a native Windows toolchain.  That is because the returned path is a Windows-style patch which cannot be handled by the make 'dir' command.  Commit 4910d43 reorganized a lot of definitions and replaced the correct code with the use of the limit make 'dir' command.  The original code used the Bash dirname command which does not suffer from this limitation; it can handle both POSIX and Windows paths.

This was verified using the stm32f4discover:nsh toolchain with the Windows native ARM Embedded toolchain.  That toolchain returns:

    arm-none-eabi-gcc --print-file-name=libgcc.a
    c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/libgcc.a
@patacongo patacongo linked a pull request Aug 31, 2020 that will close this issue
@patacongo
Copy link
Contributor Author

PR #1682 appears to correct this problem. With that change applied:

make[2]: Leaving directory '/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src/board'
echo "LD: nuttx"
LD: nuttx
arm-none-eabi-ld --entry=__start -nostartfiles -nodefaultlibs -T "D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\boards\arm\stm32\stm32f4discovery\scripts\ld.script"  -L"D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\staging" -L"D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\arch\arm\src\board" -L "c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp" -L "c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp" \
    -o "D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\nuttx.exe"   \
    --start-group -lsched -ldrivers -lboards -lc -lmm -larch -lxx -lapps -lfs -lbinfmt -lboard -lgcc -lm --end-group
arm-none-eabi-nm "D:\Spuda\Documents\projects\nuttx\master\nuttx_fork\nuttx.exe" | \
grep -v '\(compiled\)\|\(\.o$\)\|\( [aUw] \)\|\(\.\.ng$\)\|\(LASH[RL]DI\)' | \
sort > /cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/System.map
make[1]: Leaving directory '/cygdrive/d/Spuda/Documents/projects/nuttx/master/nuttx_fork/arch/arm/src'
if [ -w /tftpboot ] ; then \
        cp -f nuttx.exe /tftpboot/nuttx.exe.arm; \
fi
CP: nuttx.hex
arm-none-eabi-objcopy  -O ihex nuttx.exe nuttx.hex
CP: nuttx.bin
arm-none-eabi-objcopy  -O binary nuttx.exe nuttx.bin

xiaoxiang781216 pushed a commit that referenced this issue Sep 1, 2020
PR #1450 broke the Cygwin build.  Refer to Issue #1672.

The use of of logic like:

    EXTRA_LIBPATHS += -L "${dir ${shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcc.a}}"

fails when the Toolchain $(CC) is a native Windows toolchain.  That is because the returned path is a Windows-style patch which cannot be handled by the make 'dir' command.  Commit 4910d43 reorganized a lot of definitions and replaced the correct code with the use of the limit make 'dir' command.  The original code used the Bash dirname command which does not suffer from this limitation; it can handle both POSIX and Windows paths.

This was verified using the stm32f4discover:nsh toolchain with the Windows native ARM Embedded toolchain.  That toolchain returns:

    arm-none-eabi-gcc --print-file-name=libgcc.a
    c:/program files (x86)/gnu tools arm embedded/9 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/libgcc.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Release Blocker bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants