Bug 100293 - MinGW-w64 of nvptx offload engine fails
Summary: MinGW-w64 of nvptx offload engine fails
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 11.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: openmp
Depends on:
Blocks:
 
Reported: 2021-04-27 17:52 UTC by Brecht Sanders
Modified: 2021-08-15 19:21 UTC (History)
2 users (show)

See Also:
Host: MinGW-w64
Target: nvptx
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
libatomic/config.log (3.54 KB, text/plain)
2021-04-27 17:52 UTC, Brecht Sanders
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brecht Sanders 2021-04-27 17:52:35 UTC
Created attachment 50691 [details]
libatomic/config.log

When doing a Windows native build of the GCC 11.1.0 nvptx offload engine on Windows using MinGW-w64 and binutils 2.36.1 with:
--target=nvptx-none --enable-as-accelerator-for=x86_64-w64-mingw32
or:
--target=nvptx-none --enable-as-accelerator-for=i686-w64-mingw32
the following error is shown:

configure: error: in `/R/winlibs64_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/nvptx-none/libatomic':
configure: error: C compiler cannot create executables
See `config.log' for more details

Note that binutils is version 2.36.1 but had patches applied as advises in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98860 as these were needed to build the earlier GCC 11 snapshots.
Comment 1 Brecht Sanders 2021-04-27 18:45:44 UTC
Also tried with unpatched binutils 2.36.1, same outcome.

Building GCC targetting nvptx (--target=nvptx-none) also stops with the same error. libatomic/config.log reports:

configure:3756: checking whether the C compiler works
configure:3778: /R/winlibs64_stage/nvptx-gcc-11.1.0/gcc-11.1.0/build_nvptx_gcc/./gcc/xgcc -B/R/winlibs64_stage/nvptx-gcc-11.1.0/gcc-11.1.0/build_nvptx_gcc/./gcc/ -nostdinc -B/R/winlibs64_stage/nvptx-gcc-11.1.0/gcc-11.1.0/build_nvptx_gcc/nvptx-none/newlib/ -isystem /R/winlibs64_stage/nvptx-gcc-11.1.0/gcc-11.1.0/build_nvptx_gcc/nvptx-none/newlib/targ-include -isystem /R/winlibs64_stage/nvptx-gcc-11.1.0/gcc-11.1.0/newlib/libc/include -B/R/winlibs64_stage/inst_nvptx-gcc-11.1.0/share/nvptx-gcc/nvptx-none/bin/ -B/R/winlibs64_stage/inst_nvptx-gcc-11.1.0/share/nvptx-gcc/nvptx-none/lib/ -isystem /R/winlibs64_stage/inst_nvptx-gcc-11.1.0/share/nvptx-gcc/nvptx-none/include -isystem /R/winlibs64_stage/inst_nvptx-gcc-11.1.0/share/nvptx-gcc/nvptx-none/sys-include    -g -O2   conftest.c  >&5
error reading R:\winlibs64_stage\_TMP_\ccKq7IbV.o
collect2.exe: error: ld returned 1 exit status
Comment 2 Jakub Jelinek 2021-04-27 19:02:56 UTC
Did you follow https://gcc.gnu.org/wiki/Offloading
in particular have you installed nvptx-tools, linked in the right nvptx newlib, added --disable-sjlj-exceptions --enable-newlib-io-long-long
?
PTX doesn't use binutils, but uses nvptx-tools instead.
Comment 3 Brecht Sanders 2021-04-27 19:54:57 UTC
My bad, yes I was using nvptx-tools (master from https://github.com/MentorEmbedded/nvptx-tools).

my configure command for nvptx offload engine looks like this
./configure --prefix=/R/winlibs64_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=nvptx-none
--enable-as-accelerator-for=x86_64-w64-mingw32 --with-build-time-tools=/d/Prog/winlibs64_stage/custombuilt/share/nvptx-tools/nvptx-none/bin --with-gnu-as --with-gnu-ld --disable-serial-configure --enable-checking=release --without-libbacktrace --without-included-gettext --without-cuda-driver --enable-multiarch --enable-newlib-io-long-long --enable-linker-build-id --enable-multilib --disable-sjlj-exceptions --disable-libunwind-exceptions --disable-libgomp --enable-languages=c,c++,lto,objc,obj-c++,d

So yes, --disable-sjlj-exceptions --enable-newlib-io-long-long is there.

Note that the same build scripts worked fine with GCC 10.3.0 and older.
Comment 4 Tom de Vries 2021-04-28 08:53:24 UTC
If I do:
...
$ cat conftest.c
int
main ()
{
  return 0;
}
...
and copy the corresponding command from libatomic/config.log, and add -v -Wl,-v, I get:
...
 /home/vries/oacc/trunk/build-gcc-offload-nvptx-none/./gcc/collect2 -L/home/vries/oacc/trunk/build-gcc-offload-nvptx-none/./gcc -L/home/vries/oacc/trunk/build-gcc-offload-nvptx-none/nvptx-none/newlib -L/home/vries/oacc/trunk/install/offload-nvptx-none/nvptx-none/lib -L/home/vries/oacc/trunk/install/offload-nvptx-none/nvptx-none/usr/lib /tmp/ccQ2YOg0.o -v -lgcc -lg -lc -lgcc
collect2 version 12.0.0 20210420 (experimental)
/home/vries/oacc/trunk/build-gcc-offload-nvptx-none/./gcc/collect-ld -L/home/vries/oacc/trunk/build-gcc-offload-nvptx-none/./gcc -L/home/vries/oacc/trunk/build-gcc-offload-nvptx-none/nvptx-none/newlib -L/home/vries/oacc/trunk/install/offload-nvptx-none/nvptx-none/lib -L/home/vries/oacc/trunk/install/offload-nvptx-none/nvptx-none/usr/lib /tmp/ccQ2YOg0.o -v -lgcc -lg -lc -lgcc
Linking /tmp/ccQ2YOg0.o as 0
trying lib libc.a
trying lib libg.a
trying lib libgcc.a
...

Looking into collect-ld, it has:
...
ORIGINAL_LD_FOR_TARGET="/home/vries/oacc/trunk/install/offload-nvptx-none/nvptx-none/bin/ld"
...
which is a link to nvptx-none-ld:
...
$ /home/vries/oacc/trunk/install/offload-nvptx-none/nvptx-none/bin/ld --help
Usage: nvptx-none-ld [option...] [files]
Options:
  -o FILE               Write output to FILE
  -v                    Be verbose
  -l LIBRARY            Link with LIBRARY
  -L DIR                Search for libraries in DIR
  --help                Print this help and exit
  --version             Print version number and exit

Report bugs to <https://github.com/MentorEmbedded/nvptx-tools/issues>.
...

Can you do the same: create conftest.c, copy command from config.log, add -Wl,-v -v. Then do you see collect-ld being called? If so, does collect-ld have the correct linker hardcoded in there?
Comment 5 Jakub Jelinek 2021-04-28 08:59:28 UTC
The log file contains:
error reading R:\winlibs64_stage\_TMP_\ccYEwkZW.o
collect2.exe: error: ld returned 1 exit status
which I bet is the problem, but it is unclear if the _TMP_ subdir exists...
Comment 6 Brecht Sanders 2021-04-28 10:03:38 UTC
Yes, that folder exists and that's where my TMP and TEMP environment variables point to.

I also tried to point them to a folder on the C: drive, as R: is a RAM drive and I wanted to exclude that that was the issue, but the result was the same: build fails in the same place when configuring libatomic.
Comment 7 Brecht Sanders 2021-04-28 10:19:10 UTC
I ran the following commands based on what was in config.log

cat > conftest.c << EOF
/* confdefs.h */
#define PACKAGE_NAME "GNU Atomic Library"
#define PACKAGE_TARNAME "libatomic"
#define PACKAGE_VERSION "1.0"
#define PACKAGE_STRING "GNU Atomic Library 1.0"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL "http://www.gnu.org/software/libatomic/"
#define PACKAGE "libatomic"
#define VERSION "1.0"
/* end confdefs.h.  */

int
main ()
{

  ;
  return 0;
}
EOF
/R/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/./gcc/xgcc -B/R/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/./gcc/ -B/R/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/bin/ -B/R/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/lib/ -isystem /R/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/include -isystem /R/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/sys-include    -g -O2   conftest.c -v

and the result was:

Reading specs from R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/specs
COLLECT_GCC=R:\winlibs32_stage\gcc-offload-nvptx-11.1.0\gcc-11.1.0\build_win_offload-nvptx\gcc\xgcc.exe
COLLECT_LTO_WRAPPER=R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/lto-wrapper.exe
Target: nvptx-none
Configured with: ../configure --prefix=/R/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc --build=i686-w64-mingw32 --host=i686-w64-mingw32 --target=nvptx-none --enable-as-accelerator-for=i686-w64-mingw32 --with-pkgversion='built by
Brecht Sanders' --with-build-time-tools=/d/Prog/winlibs32_stage/custombuilt/share/nvptx-tools/nvptx-none/bin --with-gnu-as --with-gnu-ld --disable-serial-configure --enable-checking=release --without-libbacktrace --without-included-gettext
--without-cuda-driver --enable-multiarch --enable-newlib-io-long-long --enable-linker-build-id --enable-multilib --disable-sjlj-exceptions --disable-libunwind-exceptions --disable-libgomp --enable-languages=c,c++,lto,objc,obj-c++,d
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (built by Brecht Sanders)
COLLECT_GCC_OPTIONS='-B' 'R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/' '-B' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/bin/' '-B' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/lib/' '-isystem' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/include' '-isystem' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/sys-include' '-g' '-O2' '-v' '-dumpdir' 'a-'
 R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/cc1.exe -quiet -v -iprefix r:\winlibs32_stage\gcc-offload-nvptx-11.1.0\gcc-11.1.0\build_win_offload-nvptx\gcc\../lib/gcc/i686-w64-mingw32/11.1.0D:/Prog/msys64/accel/nvptx-none/ -isystem R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/include -isystem R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/include-fixed -isystem R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/include -isystem R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/sys-include conftest.c -quiet -dumpdir a- -dumpbase conftest.c -dumpbase-ext .c -g -O2
-version -o R:\winlibs32_stage\_TMP_\ccu9TSoP.s
GNU C17 (built by Brecht Sanders) version 11.1.0 (nvptx-none)
        compiled by GNU C version 11.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.23-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/include"
ignoring nonexistent directory "R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/sys-include"
ignoring nonexistent directory "r:\winlibs32_stage\gcc-offload-nvptx-11.1.0\gcc-11.1.0\build_win_offload-nvptx\gcc\../lib/gcc/i686-w64-mingw32/11.1.0D:/Prog/msys64/accel/nvptx-none/include"
ignoring nonexistent directory "r:\winlibs32_stage\gcc-offload-nvptx-11.1.0\gcc-11.1.0\build_win_offload-nvptx\gcc\../lib/gcc/i686-w64-mingw32/11.1.0D:/Prog/msys64/accel/nvptx-none/include-fixed"
ignoring nonexistent directory "r:\winlibs32_stage\gcc-offload-nvptx-11.1.0\gcc-11.1.0\build_win_offload-nvptx\gcc\../lib/gcc/i686-w64-mingw32/11.1.0D:/Prog/msys64/accel/nvptx-none/../../../../../../nvptx-none/sys-include"
ignoring nonexistent directory "r:\winlibs32_stage\gcc-offload-nvptx-11.1.0\gcc-11.1.0\build_win_offload-nvptx\gcc\../lib/gcc/i686-w64-mingw32/11.1.0D:/Prog/msys64/accel/nvptx-none/../../../../../../nvptx-none/include"
ignoring nonexistent directory "r:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/lib/gcc/i686-w64-mingw32/11.1.0/accel/nvptx-none/include"
ignoring nonexistent directory "r:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/lib/gcc/i686-w64-mingw32/11.1.0/accel/nvptx-none/include-fixed"
ignoring nonexistent directory "r:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/nvptx-none/sys-include"
ignoring nonexistent directory "r:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/nvptx-none/include"
#include "..." search starts here:
#include <...> search starts here:
 R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/include
 R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/include-fixed
 D:\Prog\winlibs32_stage\custombuilt\include
 D:\Prog\winlibs32_stage\mingw32\include
End of search list.
GNU C17 (built by Brecht Sanders) version 11.1.0 (nvptx-none)
        compiled by GNU C version 11.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.23-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8ee8c6ba1ff9d5a1ffe98751099bf036
COLLECT_GCC_OPTIONS='-B' 'R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/' '-B' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/bin/' '-B' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/lib/' '-isystem' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/include' '-isystem' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/sys-include' '-g' '-O2' '-v' '-dumpdir' 'a-'
 R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/as -v -m sm_35 -o R:\winlibs32_stage\_TMP_\ccYJWYIt.o R:\winlibs32_stage\_TMP_\ccu9TSoP.s
COMPILER_PATH=R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/
LIBRARY_PATH=R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/
COLLECT_GCC_OPTIONS='-B' 'R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/' '-B' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/bin/' '-B' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/lib/' '-isystem' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/include' '-isystem' 'R:/winlibs32_stage/inst_gcc-offload-nvptx-11.1.0/share/gcc/nvptx-none/sys-include' '-g' '-O2' '-v' '-dumpdir' 'a.'
 R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/collect2.exe -LR:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc R:\winlibs32_stage\_TMP_\ccYJWYIt.o -lgcc -lg -lc -lgcc
error reading R:\winlibs32_stage\_TMP_\ccYJWYIt.o
collect2.exe: error: ld returned 1 exit status

So the missing file should have been geenrated by gcc/as

I was expecting to find gcc/as.exe in my build folder, but instead gcc/as is a shell script. I very much doubt this can be executed as-is on Windows, even in MSYS2 shell, as the code executing it would need to know about the shebang header and that that needs to be executed by running sh.exe
Comment 8 Brecht Sanders 2021-04-28 10:27:16 UTC
Additional test:
Running this manually (in MSYS2 shell) also fails:
R:/winlibs32_stage/gcc-offload-nvptx-11.1.0/gcc-11.1.0/build_win_offload-nvptx/gcc/as -v -m sm_35 -o 'R:\winlibs32_stage\_TMP_\ccYJWYIt.o' 'R:\winlibs32_stage\_TMP_\ccu9TSoP.s'
nvptx-as: cannot open input ptx file
Comment 9 Brecht Sanders 2021-08-15 19:20:36 UTC
Any update on this?
Issue still exists today (in GCC 11.2.0 and in latest snapshot 11.2.1-20210814).

Both when building gcc on Windows for nvptx as well as the offload engine for nvptx there is an error like this in nvptx-none/libatomic/config.log:

configure:3736: $? = 1
configure:3756: checking whether the C compiler works
configure:3778: /R/winlibs64_stage/nvptx-gcc-11-20210814/gcc-11-20210814/build_nvptx_gcc/./gcc/xgcc -B/R/winlibs64_stage/nvptx-gcc-11-20210814/gcc-11-20210814/build_nvptx_gcc/./gcc/ -nostdinc -B/R/winlibs64_stage/nvptx-gcc-11-20210814/gcc-11-20210814/build_nvptx_gcc/nvptx-none/newlib/ -isystem /R/winlibs64_stage/nvptx-gcc-11-20210814/gcc-11-20210814/build_nvptx_gcc/nvptx-none/newlib/targ-include -isystem /R/winlibs64_stage/nvptx-gcc-11-20210814/gcc-11-20210814/newlib/libc/include -B/R/winlibs64_stage/inst_nvptx-gcc-11-20210814/share/nvptx-gcc/nvptx-none/bin/ -B/R/winlibs64_stage/inst_nvptx-gcc-11-20210814/share/nvptx-gcc/nvptx-none/lib/ -isystem /R/winlibs64_stage/inst_nvptx-gcc-11-20210814/share/nvptx-gcc/nvptx-none/include -isystem /R/winlibs64_stage/inst_nvptx-gcc-11-20210814/share/nvptx-gcc/nvptx-none/sys-include    -g -O2   conftest.c  >&5
error reading C:\Temp\ccqpNwjZ.o
collect2.exe: error: ld returned 1 exit status