Skip to content

Conversation

@kbkpbot
Copy link
Contributor

@kbkpbot kbkpbot commented Dec 28, 2025

Fix issue #25856
Fix issue #26158

This bug is caused by on aarch64, tcc remove the prefix __ from __atomic_thread_fence, so a workaround needed here.
Maybe a tcc fix is needed for upstream.

ping @spytheman would you please help me verify that the test file is written in a correct format ? I just want to check it can be compiled under tcc/arm64. Do it need to set a VFLAGS = -no-retry-compilation?

@spytheman
Copy link
Member

@kbkpbot I think it should be fine now; I'll test on macos to be sure and in a VM asap.

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Dec 28, 2025

Thank you @spytheman

@tankf33der
Copy link
Contributor

Also will fix #25856

@kbkpbot kbkpbot marked this pull request as draft December 29, 2025 04:12
@kbkpbot kbkpbot marked this pull request as ready for review December 29, 2025 11:29
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work 🙇🏻 .
@tankf33der what do you think?

@tankf33der
Copy link
Contributor

Since all checks have passed this should be merged.
I will check everywhere and comment here.

@tankf33der
Copy link
Contributor

@spytheman - i take my words back. do not merge. i am testing.

@tankf33der
Copy link
Contributor

During the pause, I decided to check that the patch works.

@tankf33der
Copy link
Contributor

x64 alpine - ok

@tankf33der
Copy link
Contributor

some fail on one of the ARM

tankf33der@cfarm103:~/v$ gmake
cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=c99 -w -o v1 ./vc/v.c -lm -lpthread  || cmd/tools/cc_compilation_failed_non_windows.sh
./v1 -no-parallel -o v2 -no-retry-compilation -no-parallel cmd/v
================== C compilation error (from /home/tankf33der/v/thirdparty/tcc/tcc.exe): ==============
cc: /tmp/v_62104/v2.01KDNDDK4KEKCD1649CT8Z8KR5.tmp.c:1223: error: ARM asm not implemented.
=======================================================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
gmake: *** [GNUmakefile:115: all] Error 1

@spytheman
Copy link
Member

spytheman commented Dec 29, 2025

what is on line /tmp/v_62104/v2.01KDNDDK4KEKCD1649CT8Z8KR5.tmp.c:1223 ?

@tankf33der
Copy link
Contributor

what is on line /tmp/v_62104/v2.01KDNDDK4KEKCD1649CT8Z8KR5.tmp.c:1223 ?

@spytheman @kbkpbot

Some line from patch of this PR

image

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Dec 30, 2025

Yes, due to tcc does not support arm asm right now, this should not work as inline asm.
Maybe a .s file will work.
But I am not sure we can have a .s in the thirdparty directory.

@kbkpbot kbkpbot marked this pull request as draft December 30, 2025 07:33
@spytheman
Copy link
Member

Afaik, there is no policy restriction for .s files in thirdparty/ , but I am not sure if there will not be technical ones 🤔 . I have not tried using separate .s files till now.

@spytheman
Copy link
Member

thirdparty/libatomic_ops/atomic_ops.h:293 has a AO_compiler_barrier() macro.
Can it be used instead?

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Dec 30, 2025

thirdparty/libatomic_ops/atomic_ops.h:293 has a AO_compiler_barrier() macro. Can it be used instead?

no.
I just created a c file,
c.c

#include <stdio.h>

void main() {
        __asm__ __volatile__("" : : : "memory")
}
$ ./tcc.exe c.c -o c -I ./include -I ./lib/tcc/include
c.c:4: error: ARM asm not implemented.

spytheman pushed a commit that referenced this pull request Dec 31, 2025
@kbkpbot kbkpbot marked this pull request as ready for review January 1, 2026 00:46
@tankf33der
Copy link
Contributor

@spytheman let me know when i should start manual testing.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.
Thank you @kbkpbot .

@spytheman
Copy link
Member

@tankf33der I think it is ready to be tested (and merged).

@tankf33der
Copy link
Contributor

@tankf33der I think it is ready to be tested (and merged).

I will start testing in 90mins.

@tankf33der
Copy link
Contributor

@spytheman @kbkpbot

CPU Distro Status
X64 Apine compilation failed
X64 Debian Passed
ARM64 Debian Passed
ARM64 Debian Passed
RISCV64 Alpine compilation failed
RISCV64 Debian Passed
PPC64LE Debian Passed
  1. compilation failed text will be on next comments.
  2. When i say Passed it means - that after patching v, v list and VTEST=ONLY=closure ./v test vlib/ works.

@tankf33der
Copy link
Contributor

X64 on Alpine failed this way with patch.
v compiled, v list failed. Note it worked on prev. testing, see above.

lambda:~/v$ v list
cannot compile `/home/mpech/v/cmd/tools/vpm`: 1
================== C compilation error (from tcc): ==============
cc: tcc: error: undefined symbol '__atomic_thread_fence'
=================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

@tankf33der
Copy link
Contributor

RISCV64 on Alpine v compilation failed this way with or without patch:

cfarm94:~/v$ gmake
cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=c99 -w -o v1 ./vc/v.c -lm -lpthread  || cmd/tools/cc_compilation_failed_non_windows.sh
./v1 -no-parallel -o v2  cmd/v
./v2 -nocache -o ./v  cmd/v
rm -rf v1 v2
================== C compilation error (from cc): ==============
cc: /usr/lib/gcc/riscv64-alpine-linux-musl/14.2.0/../../../../riscv64-alpine-linux-musl/bin/ld: cannot find /home/tankf33der/v/thirdparty/tcc/lib/libgc.a: No such file or directory
cc: collect2: error: ld returned 1 exit status
================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
gmake: *** [GNUmakefile:118: all] Error 1

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Jan 2, 2026

X64 on Alpine failed this way with patch. v compiled, v list failed. Note it worked on prev. testing, see above.

lambda:~/v$ v list
cannot compile `/home/mpech/v/cmd/tools/vpm`: 1
================== C compilation error (from tcc): ==============
cc: tcc: error: undefined symbol '__atomic_thread_fence'
=================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

I need more info to find out what is really going on.
Do you upgrade master to latest git before this test?

please provide more info about your tcc version.

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Jan 2, 2026

RISCV64 on Alpine v compilation failed this way with or without patch:

cfarm94:~/v$ gmake
cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=c99 -w -o v1 ./vc/v.c -lm -lpthread  || cmd/tools/cc_compilation_failed_non_windows.sh
./v1 -no-parallel -o v2  cmd/v
./v2 -nocache -o ./v  cmd/v
rm -rf v1 v2
================== C compilation error (from cc): ==============
cc: /usr/lib/gcc/riscv64-alpine-linux-musl/14.2.0/../../../../riscv64-alpine-linux-musl/bin/ld: cannot find /home/tankf33der/v/thirdparty/tcc/lib/libgc.a: No such file or directory
cc: collect2: error: ld returned 1 exit status
================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
gmake: *** [GNUmakefile:118: all] Error 1

It seems you miss a prebuilt libgc.a at that location.

@spytheman
Copy link
Member

I've checked in a Docker container with Alpine x64 , v -no-retry-compilation -cc tcc cmd/tools/vpm (which v list does invoke, to compile vpm), failed with tcc: error: undefined symbol '__atomic_thread_fence' .

386deb8 fixes it for me, by adding a flag for the .S file, and changing _V_atomic_thread_fence for that case to __atomic_thread_fence .

@spytheman
Copy link
Member

For the Alpine X64 case, make does:

git clone --filter=blob:none --quiet --branch thirdparty-linuxmusl-amd64 https://github.com/vlang/tccbin ./thirdparty/tcc

and for that clone:

/src # ./thirdparty/tcc/tcc.exe --version
tcc version 0.9.27 mob:d3e940c (x86_64 Linux)

@spytheman
Copy link
Member

spytheman commented Jan 2, 2026

tcc d3e940c is from 2022-04-28 . We should update it indeed. It is currently 499 commits behind the tip of the mob branch of git://repo.or.cz/tinycc.git .

@spytheman
Copy link
Member

Can we provide both _V_atomic_thread_fence and __atomic_thread_fence symbols in the same .S file?

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Jan 2, 2026

Can we provide both _V_atomic_thread_fence and __atomic_thread_fence symbols in the same .S file?

I am not sure it can pass vtcc test, as vtcc already provide a symbol __atomic_thread_fence
https://github.com/felipensp/vtcc/blob/78da82675cf56e2a4c36e1d006bb19265114bd81/lib/libtcc1/stdatomic.v#L14-L17

@spytheman
Copy link
Member

hm, if there is a pure V implementation (well with inline assembly), why do we need a separate .S file ?

@spytheman
Copy link
Member

the vtcc implementation does not use a memory barrier 🤔

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Jan 2, 2026

hm, if there is a pure V implementation (well with inline assembly), why do we need a separate .S file ?

That is for vtcc only, not for tcc.
And I think vtcc is compiled by gcc not by tcc, as gcc support inline asm for arm64.

@spytheman
Copy link
Member

vtcc can be compiled with the PR from here on Alpine, just checked:

/src/vtcc # v run make.vsh /src/vtcc
building bt-log.o (tcc_backtrace symbol): ok
building bcheck.o: : ok
building bt-exe.o: : ok
building dso.o: : ok
buildind libtcc1.o: : ok
building vtcc.o: : ok
building libtcc1.a: : ok
buildind vtcc: : ok
/src/vtcc # ./vtcc --version
tcc version 0.9.28rc (x86_64 Linux)
/src/vtcc # ./vtcc -c hello.c -o hello.o
/src/vtcc # ls -la hello.o
-rw-r--r--    1 root     root           976 Jan  2 14:30 hello.o
/src/vtcc #
/src/vtcc #
/src/vtcc # ./vtcc hello.c
tcc: error: file 'crt1.o' not found
tcc: error: file 'crti.o' not found
tcc: error: file 'crtn.o' not found
/src/vtcc #

The last compilation fails because of unrelated reasons - it is tuned to work on a glibc system, and imho making it work on a musl one, is out of scope for this PR.

@spytheman
Copy link
Member

If the new docker-alpine-musl-tcc CI job passes here, I intend to merge this as it is. We can improve the RISCV64 Alpine case later.

@spytheman
Copy link
Member

The sanitized CI jobs failed due to an unrelated problem, that is fixed on master.

@spytheman spytheman merged commit 8018dde into vlang:master Jan 3, 2026
89 of 93 checks passed
@spytheman
Copy link
Member

Thank you @kbkpbot 🙇🏻 .
Thank you @tankf33der.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants