Nim: sparc64: error: size of array ‘Nim_and_C_compiler_disagree_on_target_architecture’ is negative

Created on 29 May 2019  Â·  13Comments  Â·  Source: nim-lang/Nim

The build on linux-sparc64 (Debian) fails with:

PATH=./bin/:$PATH  ./build.sh --os linux --cpu unsupported:sparc64
./build.sh: 142: ./build.sh: isainfo: not found
# OS: linux
# CPU: sparc
gcc -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -fdebug-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -w -O3 -fno-strict-aliasing -Ic_code -c c_code/2_1/compiler_nim.c -o c_code/2_1/compiler_nim.o
In file included from c_code/2_1/compiler_nim.c:7:
c_code/nimbase.h:488:13: error: size of array ‘Nim_and_C_compiler_disagree_on_target_architecture’ is negative
 typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8 ? 1 : -1];
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Full build log available at: https://buildd.debian.org/status/fetch.php?pkg=nim&arch=sparc64&ver=0.19.6-2&stamp=1559043839&raw=0

Access to a sparc64 porterbox is available through the gcc compile farm, see: https://gcc.gnu.org/wiki/CompileFarm

Any open source developer can ask for an account and get access to a fast SPARC T5 porterbox running Debian unstable. I am the admin of this porterbox and can install additional packages on request.

Installation OArch specific

Most helpful comment

Well, I never worked on Nim before, so you have to excuse me when I'm asking stupid questions ;).

Edit: I'll open a PR for that.

All 13 comments

Try this please:

 *sparc*|*sun* )
    mycpu="sparc"
    if [ "$(isainfo -b)" = "64" ]; then
      mycpu="sparc64"
    fi
    ;;

in build.sh, replace it with:

 *sun* )
    mycpu="sparc"
    if [ "$(isainfo -b)" = "64" ]; then
      mycpu="sparc64"
    fi
    ;;

I should have mentioned (although it should be clear from the build log) that this on Linux, no Solaris. So there is no "sun" in the uname string.

I haven't tried that particular change yet, but without looking at the code, I would wild-guess that the problem is that the code uses detects sparc64 with #if defined(__sparc64__) (which doesn't exist on Linux) instead of #if defined(__sparc__) && defined(__arch64__). I will have a look later.

As expected, this change breaks the build:

PATH=./bin/:$PATH  ./build.sh --os linux --cpu unsupported:sparc64
Error: unknown processor: unsupported:sparc64

But spark64 is a valid CPU arch known to Nim, see https://github.com/nim-lang/Nim/blob/devel/compiler/platform.nim#L213

The C sources were not built for it though, spark64 is only build for Solaris, see https://github.com/nim-lang/Nim/blob/devel/compiler/installer.ini#L9

Ah, the problem is the isainfo command which doesn't exist on Linux. It's specific to Solaris.

Let me see what I can come up with, second.

One could use getconf LONG_BIT but it claims to be 32 bits on a 64-bit Solaris:

root@tokyo:~# uname -a
SunOS tokyo 5.11 11.3 sun4v sparc SUNW,T5240
root@tokyo:~# isainfo -b
64
root@tokyo:~# getconf LONG_BIT
32
root@tokyo:~#

So, I'll have to keep searching for a better solution.

Hmm, on a Solaris box with 11.4, getconf LONG_BIT produces the correct output:

sysadmin@deimos:~$ uname -a
SunOS deimos 5.11 11.4.1.4.0 sun4v sparc sun4v
sysadmin@deimos:~$ getconf LONG_BIT
64
sysadmin@deimos:~$

I'll whip up a patch and open a PR.

I just opened https://github.com/nim-lang/csources/pull/26 to fix this issue.

Now, when I try to build it with this fix, I'm getting this. Looking at the makefile, I noticed there were no csource defined for linux/sparc64 so I just copied the filelist for solaris/sparc64 but that doesn't seem to be enough.

It still fails with:

glaubitz@gcc202:~/nim/Nim$ sh ./build_all.sh 

build_nim_csources

cd csources

sh build.sh
# OS: linux
# CPU: sparc64
gcc -o ../bin/nim -ldl -lm -lrt
/usr/bin/ld: /usr/lib/gcc/sparc64-linux-gnu/8/../../../sparc64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1c): undefined reference to `main'
/usr/bin/ld: (.text+0x28): undefined reference to `main'
/usr/bin/ld: (.text+0x34): undefined reference to `main'
collect2: error: ld returned 1 exit status
glaubitz@gcc202:~/nim/Nim$

Looking at the C sources, they seem to be autogenerated. If someone can point me at how those are generated, I'm happy to do that for all Linux architectures where it's missing as I have access to machines with all architectures supported by Debian.

I already told you, you need to patch https://github.com/nim-lang/Nim/blob/devel/compiler/installer.ini#L9 instead and let us do the C sources update.

Well, I never worked on Nim before, so you have to excuse me when I'm asking stupid questions ;).

Edit: I'll open a PR for that.

As far as I can tell, this issue has been resolved.

That's correct. We only have the issue left that builds on big-endian generally fail although I haven't tested with git master for some time now.

Was this page helpful?
0 / 5 - 0 ratings