msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.28k stars 483 forks source link

Add aarch64-w64-mingw32 target to mingw-w64-cross-binutils package #3998

Open Blackhex opened 10 months ago

Blackhex commented 10 months ago

This issue serves for tracking progress and documenting issues needed to be overcome while adding aarch64-w64-mingw32 target to mingw-w64-cross-binutils package.

This is a subtask of https://github.com/msys2/MSYS2-packages/issues/3834, for broader discussions, please, head there.

The development is happening in this branch.

Blackhex commented 10 months ago

Issue

make[4]: Entering directory '/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/build-aarch64-w64-mingw32/sim'
 CC       aarch64/modules.o
In file included from ../gnulib/import/stdlib.h:100,
                from /usr/include/sys/cpuset.h:12,
                from /usr/include/sys/_pthreadtypes.h:12,
                from /usr/include/sys/types.h:221,
                from ../gnulib/import/sys/types.h:39,
                from ../gnulib/import/stdio.h:58,
                from /c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/sim/../include/libiberty.h:49,
                from aarch64/modules.c:3:
../gnulib/import/unistd.h:663:3: error: #error "Please include config.h first."
 663 |  #error "Please include config.h first."
     |   ^~~~~
../gnulib/import/unistd.h:665:24: error: expected ‘;’ before ‘extern’
 665 | _GL_INLINE_HEADER_BEGIN
     |                        ^
     |                        ;
../gnulib/import/unistd.h:2830:22: error: expected ‘;’ before ‘extern’
2830 | _GL_INLINE_HEADER_END
     |                      ^
     |                      ;
make[4]: *** [Makefile:4009: aarch64/modules.o] Error 1

Solution

--- a/sim/Makefile.in
+++ b/sim/Makefile.in
@@ -4841,6 +4841,7 @@ common/version.c-stamp: $(srcroot)/gdb/version.in $(srcroot)/bfd/version.h $(src
    ( \
    echo '/* Do not modify this file.  */'; \
    echo '/* It is created automatically by the Makefile.  */'; \
+   echo '#include "defs.h"'; \
    echo '#include "libiberty.h"'; \
    echo '#include "sim-module.h"'; \
    sed -e 's:\(.*\):extern MODULE_INIT_FN \1;:' $@.l-tmp; \
--- a/sim/common/local.mk
+++ b/sim/common/local.mk
@@ -146,6 +146,7 @@ GEN_MODULES_C_SRCS = \
    ( \
    echo '/* Do not modify this file.  */'; \
    echo '/* It is created automatically by the Makefile.  */'; \
+   echo '#include "defs.h"'; \
    echo '#include "libiberty.h"'; \
    echo '#include "sim-module.h"'; \
    sed -e 's:\(.*\):extern MODULE_INIT_FN \1;:' $@.l-tmp; \
Blackhex commented 10 months ago

Issue

make[4]: Entering directory '/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/build-aarch64-w64-mingw32/sim'
  CCLD     aarch64/run.exe
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld: /c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/build-aarch64-w64-mingw32/intl/libintl.a(dcigettext.o): in function `_nl_find_msg':
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/intl/dcigettext.c:940:(.text+0x61f): undefined reference to `libiconv'
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld: /c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/build-aarch64-w64-mingw32/intl/libintl.a(loadmsgcat.o): in function `_nl_init_domain_conv':
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/intl/loadmsgcat.c:869:(.text+0xcf): undefined reference to `libiconv_open'
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld: /c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/intl/loadmsgcat.c:863:(.text+0x167): undefined reference to `libiconv_open'
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld: /c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/build-aarch64-w64-mingw32/intl/libintl.a(loadmsgcat.o): in function `_nl_free_domain_conv':
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/intl/loadmsgcat.c:896:(.text+0x1a6): undefined reference to `libiconv_close'
/usr/lib/gcc/x86_64-pc-msys/11.3.0/../../../../x86_64-pc-msys/bin/ld: /c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/build-aarch64-w64-mingw32/intl/libintl.a(relocatable.o): in function `libintl_set_relocation_prefix':
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/intl/relocatable.c:148:(.text+0x48): undefined reference to `libiconv_set_relocation_prefix'
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:3677: aarch64/run.exe] Error 1

even when the deps should be installed using makepkg --syncdeps and libiconv-devel is in the makedepends

Solution

Adding -liconv to the command line is one workaround, changing --with-libiconv-prefix=/usr configure option to --without-libiconv-prefix is another but I am strugging to find a proper cause/solution so far.

I am seeing the same error when building the mingw-w64-cross-binutils package inside completely fresh MSYS2 environment on CI (using https://github.com/msys2/setup-msys2). So this rather seems as a packaging issue in one of the involved MSYS2 packages (most probably libiconv-devel).

Blackhex commented 10 months ago

Issue

checking for makeinfo... (cached) makeinfo --split-size=5000000
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libctf/configure: line 14872: makeinfo: command not found
configure: WARNING:
*** Makeinfo is too old. Info documentation will not be built.

Solution

Add texinfo to makedepends.

cgudrian commented 10 months ago

I'm currently facing this error myself building a canadian cross compiler on Linux hosted by MinGW and targeting aarch64 using the Linaro build script. In my case libiconv.a is supposed to be pulled in by libtool as a transitive dependency via libintl.a. This mechanism does obviously not work when building libraries for Windows.

Adding -liconv fixed the issued for me as well.

cgudrian commented 10 months ago

The culprit in my special case was the value of LDFLAGS: it contained a linker path entry for the MinGW /usr/lib directory. Because of the convoluted lookup logic the presence of that path leads to /path/to/mingw/usr/lib/libiconv.a being added to libintl.la (which does not work when building for Windows). Leaving MinGW's /usr/lib out of the LDFLAGS leads to -liconv being added to libintl.la (which does work).

Maybe that's the case here as well.

Blackhex commented 10 months ago

Issue

gcc -c -DHAVE_CONFIG_H -g -O2      -I. -I/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/../include  -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes -Wshadow=local -pedantic  -D_GNU_SOURCE  /c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c -o pex-win32.o
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘pex_win32_open_read’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:121:10: warning: implicit declaration of function ‘_open’; did you mean ‘open’? [-Wimplicit-function-declaration]
  121 |   return _open (name, _O_RDONLY | (binary ? _O_BINARY : _O_TEXT));
      |          ^~~~~
      |          open
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:121:23: error: ‘_O_RDONLY’ undeclared (first use in this function); did you mean ‘O_RDONLY’?
  121 |   return _open (name, _O_RDONLY | (binary ? _O_BINARY : _O_TEXT));
      |                       ^~~~~~~~~
      |                       O_RDONLY
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:121:23: note: each undeclared identifier is reported only once for each function it appears in
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:121:45: error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’?
  121 |   return _open (name, _O_RDONLY | (binary ? _O_BINARY : _O_TEXT));
      |                                             ^~~~~~~~~
      |                                             O_BINARY
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:121:57: error: ‘_O_TEXT’ undeclared (first use in this function); did you mean ‘O_TEXT’?
  121 |   return _open (name, _O_RDONLY | (binary ? _O_BINARY : _O_TEXT));
      |                                                         ^~~~~~~
      |                                                         O_TEXT
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘pex_win32_open_write’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:135:18: error: ‘_O_WRONLY’ undeclared (first use in this function); did you mean ‘O_WRONLY’?
  135 |                 (_O_WRONLY | _O_CREAT | _O_TRUNC
      |                  ^~~~~~~~~
      |                  O_WRONLY
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:135:30: error: ‘_O_CREAT’ undeclared (first use in this function); did you mean ‘O_CREAT’?
  135 |                 (_O_WRONLY | _O_CREAT | _O_TRUNC
      |                              ^~~~~~~~
      |                              O_CREAT
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:135:41: error: ‘_O_TRUNC’ undeclared (first use in this function); did you mean ‘O_TRUNC’?
  135 |                 (_O_WRONLY | _O_CREAT | _O_TRUNC
      |                                         ^~~~~~~~
      |                                         O_TRUNC
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:136:30: error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’?
  136 |                  | (binary ? _O_BINARY : _O_TEXT)),
      |                              ^~~~~~~~~
      |                              O_BINARY
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:136:42: error: ‘_O_TEXT’ undeclared (first use in this function); did you mean ‘O_TEXT’?
  136 |                  | (binary ? _O_BINARY : _O_TEXT)),
      |                                          ^~~~~~~
      |                                          O_TEXT
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:137:17: error: ‘_S_IREAD’ undeclared (first use in this function); did you mean ‘S_IREAD’?
  137 |                 _S_IREAD | _S_IWRITE);
      |                 ^~~~~~~~
      |                 S_IREAD
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:137:28: error: ‘_S_IWRITE’ undeclared (first use in this function); did you mean ‘S_IWRITE’?
  137 |                 _S_IREAD | _S_IWRITE);
      |                            ^~~~~~~~~
      |                            S_IWRITE
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘pex_win32_close’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:145:10: warning: implicit declaration of function ‘_close’; did you mean ‘close’? [-Wimplicit-function-declaration]
  145 |   return _close (fd);
      |          ^~~~~~
      |          close
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘win32_spawn’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:652:10: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  652 |   return (pid_t) pi->hProcess;
      |          ^
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘spawn_script’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:674:31: error: ‘_O_RDONLY’ undeclared (first use in this function); did you mean ‘O_RDONLY’?
  674 |   int fd = _open (executable, _O_RDONLY);
      |                               ^~~~~~~~~
      |                               O_RDONLY
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:681:17: warning: implicit declaration of function ‘_read’; did you mean ‘read’? [-Wimplicit-function-declaration]
  681 |       int len = _read (fd, buf, sizeof (buf) - 1);
      |                 ^~~~~
      |                 read
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘pex_win32_exec_child’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:779:8: warning: implicit declaration of function ‘_dup’; did you mean ‘dup’? [-Wimplicit-function-declaration]
  779 |   in = _dup (orig_in);
      |        ^~~~
      |        dup
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘pex_win32_wait’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:911:7: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  911 |   h = (HANDLE) pid;
      |       ^
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘pex_win32_pipe’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:943:10: warning: implicit declaration of function ‘_pipe’; did you mean ‘pipe’? [-Wimplicit-function-declaration]
  943 |   return _pipe (p, 256, (binary ? _O_BINARY : _O_TEXT) | _O_NOINHERIT);
      |          ^~~~~
      |          pipe
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:943:35: error: ‘_O_BINARY’ undeclared (first use in this function); did you mean ‘O_BINARY’?
  943 |   return _pipe (p, 256, (binary ? _O_BINARY : _O_TEXT) | _O_NOINHERIT);
      |                                   ^~~~~~~~~
      |                                   O_BINARY
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:943:47: error: ‘_O_TEXT’ undeclared (first use in this function); did you mean ‘O_TEXT’?
  943 |   return _pipe (p, 256, (binary ? _O_BINARY : _O_TEXT) | _O_NOINHERIT);
      |                                               ^~~~~~~
      |                                               O_TEXT
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:943:58: error: ‘_O_NOINHERIT’ undeclared (first use in this function)
  943 |   return _pipe (p, 256, (binary ? _O_BINARY : _O_TEXT) | _O_NOINHERIT);
      |                                                          ^~~~~~~~~~~~
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:944:1: warning: control reaches end of non-void function [-Wreturn-type]
  944 | }
      | ^
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘pex_win32_open_write’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:138:1: warning: control reaches end of non-void function [-Wreturn-type]
  138 | }
      | ^
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c: In function ‘pex_win32_open_read’:
/c/Projekty/MSYS2-packages/mingw-w64-cross-binutils/src/binutils/libiberty/pex-win32.c:122:1: warning: control reaches end of non-void function [-Wreturn-type]
  122 | }
      | ^
make[2]: *** [Makefile:1173: pex-win32.o] Error 1

Solution

Caused by /usr/include/fcntl.h included instead of /opt/aarch64-w64-mingw32/include/fcntl.h.

TODO