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

ARM Raspberry pi - "Illegal instruction" #19457

Closed
SewerynKaminski opened this issue Sep 27, 2023 · 11 comments
Closed

ARM Raspberry pi - "Illegal instruction" #19457

SewerynKaminski opened this issue Sep 27, 2023 · 11 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@SewerynKaminski
Copy link
Contributor

SewerynKaminski commented Sep 27, 2023

Describe the bug

$ cat test.v
fn main() {
println ( 'hello wolrd!' )
}

$ v test.v
$ test
Illegal instruction
$ file test
test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=bf8649fddea99dfa24b3181c9e481ef975b27354, not stripped

Reproduction Steps

$ v test.v
$ test

Expected Behavior

Generate valid binary

Current Behavior

After executing generated binary got error message "Illegal instruction"

Possible Solution

$ v -prod test.v
$ test
hello wolrd!

Additional Information/Context

No response

V version

V 0.4.1 981f76c

Environment details (OS name and version, etc.)

$ v doctor
Illegal instruction
$ uname -a
Linux raspberrypi 5.10.103+ #1529 Tue Mar 8 12:19:18 GMT 2022 armv6l GNU/Linux
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/8/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 8.3.0-6+rpi1' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --disable-werror --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1)

Note

You can vote for this issue using the 👍 reaction. More votes increase the issue's priority for developers.

Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.

@SewerynKaminski SewerynKaminski added the Bug This tag is applied to issues which reports bugs. label Sep 27, 2023
@JalonSolov
Copy link
Contributor

Can you get a newer version of gcc? That one is... quite old.

@SewerynKaminski
Copy link
Contributor Author

$ v -showcc test.v
> C compiler cmd: '/home/pi/vlang/v/thirdparty/tcc/tcc.exe' '@/tmp/v_1001/test.10519296450509670088.tmp.c.rsp'
> C compiler response file "/tmp/v_1001/test.10519296450509670088.tmp.c.rsp":
  -fwrapv -o "/home/seweryn/vlang/test" -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -I "/home/pi/vlang/v/thirdparty/libgc/include" "/tmp/v_1001/test.10519296450509670088.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE -bt25 "/home/pi/vlang/v/thirdparty/tcc/lib/libgc.a" -ldl -lpthread  
> C compiler cmd: 'cc' '@/tmp/v_1001/test.10519296450509670088.tmp.c.rsp'
> C compiler response file "/tmp/v_1001/test.10519296450509670088.tmp.c.rsp":
 -o "/home/seweryn/vlang/test" -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -I `"/home/pi/vlang/v/thirdparty/libgc/include" "/tmp/v_1001/test.10519296450509670088.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE "/home/pi/vlang/v/thirdparty/tcc/lib/libgc.a" -ldl -lpthread
$ ./test
Illegal instruction

@SewerynKaminski
Copy link
Contributor Author

$ v -showcc -prod test.v
> C compiler cmd: 'cc' '@/tmp/v_1001/test.14794684856179002000.tmp.c.rsp'
> C compiler response file "/tmp/v_1001/test.14794684856179002000.tmp.c.rsp":
  -fwrapv -O3 -fno-strict-aliasing -flto -DNDEBUG "/home/seweryn/.vmodules/cache/b8/b87fae2f0bb8949b61369ce2e159138c.module.builtin.o" -o "/home/seweryn/vlang/test" -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -I "/home/pi/vlang/v/thirdparty/libgc/include" "/tmp/v_1001/test.14794684856179002000.tmp.c" -std=gnu99 -D_DEFAULT_SOURCE -ldl -lpthread  
$ ./test 
hello world

@SewerynKaminski
Copy link
Contributor Author

SewerynKaminski commented Sep 28, 2023

I think the problem is in tcc because v -showcc -prod test.v generate valid binary using gcc.

That one is... quite old.
JalonSolov

I don't think so, -std=gnu99 standard is very old and gcc-8 support it very well.

@JalonSolov
Copy link
Contributor

Yes, but there are other features V uses that weren't added until gcc-9.3, I believe.

Latest version is, of course, 13.2.

@SewerynKaminski
Copy link
Contributor Author

SewerynKaminski commented Sep 28, 2023

Without -prod flag

$ v -cc gcc-10.1 test.v
$ ./test 
Illegal instruction

With -prod flag

$ v -cc gcc-10.1 -prod test.v
$ ./test 
hello world

Without -prod flag + O3

$ v -cc gcc-10.1 -cflags -O3 test.v
$ ./test 
Illegal instruction

@JalonSolov
Copy link
Contributor

In both cases, you're using gcc. The only difference is when the code is optimized, it works.

@SewerynKaminski
Copy link
Contributor Author

But why? Adding -cflags -O3 without prod flag don't work.

@JalonSolov
Copy link
Contributor

V adds more than -O3. Add the -showcc option on the V command, and it will print the full command it sends to the C compiler.

@SewerynKaminski
Copy link
Contributor Author

It's tcc issue.
Give up.

@SewerynKaminski SewerynKaminski closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2023
@JalonSolov
Copy link
Contributor

If you wish, go ahead, even though you showed it failing with gcc above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

2 participants