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

Current latest vlang gives error on Raspberry Pi - v.c:(.text+0xa78): undefined reference to `__atomic_load_8' #12907

Open
ckqee opened this issue Dec 20, 2021 · 13 comments
Labels
Arch: ARM Bugs/feature requests, that are related to architecture ARM. Bug This tag is applied to issues which reports bugs.

Comments

@ckqee
Copy link

ckqee commented Dec 20, 2021

V version:
latest today

tried v up but did not work so did a git pull as well

./v up
failed    cmd: "/home/pi/v/v" -skip-unused  -g "/home/pi/v/cmd/tools/vup.v"
failed   code: 1
vlib/builtin/builtin.c.v:1:1: error: unknown module attribute `[has_globals]`
    1 | [has_globals]
      | ~~~~~~~~~~~~~
    2 | module builtin
    3 |

OS:
Linux pi 5.10.63-v7+ #1496 SMP Wed Dec 1 15:58:11 GMT 2021 armv7l GNU/Linux
What did you do?
date;
make;
date

What did you expect to see?
clean compilation of v compiler

What did you see instead?

date; make ;date
Mon 20 Dec 11:15:32 UTC 2021
cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread 
/usr/bin/ld: /tmp/ccplBfxf.o: in function `atomic_load_u64':
v.c:(.text+0xa78): undefined reference to `__atomic_load_8'
/usr/bin/ld: /tmp/ccplBfxf.o: in function `atomic_store_u64':
v.c:(.text+0xad0): undefined reference to `__atomic_store_8'
/usr/bin/ld: /tmp/ccplBfxf.o: in function `atomic_fetch_add_u64':
v.c:(.text+0xb04): undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: /tmp/ccplBfxf.o: in function `atomic_fetch_sub_u64':
v.c:(.text+0xb44): undefined reference to `__atomic_fetch_sub_8'
collect2: error: ld returned 1 exit status
make: *** [GNUmakefile:93: all] Error 1
Mon 20 Dec 11:17:21 UTC 2021
@ckqee ckqee added the Bug This tag is applied to issues which reports bugs. label Dec 20, 2021
@ckqee
Copy link
Author

ckqee commented Dec 20, 2021

Did a fresh new git clone and same message appears today

  1 git clone https://github.com/vlang/v
  2 Cloning into 'v'...
  3 remote: Enumerating objects: 107356, done.
  4 remote: Counting objects: 100% (32/32), done.
  5 remote: Compressing objects: 100% (30/30), done.
  6 remote: Total 107356 (delta 2), reused 23 (delta 2), pack-reused 107324
  7 Receiving objects: 100% (107356/107356), 45.98 MiB | 3.58 MiB/s, done.
  8 Resolving deltas: 100% (76575/76575), done.
  9 Checking out files: 100% (3988/3988), done.
 10 cd v
 11 make
 12 make fresh_vc
 13 make[1]: Entering directory '/mnt/sda/v_dir/v'
 14 rm -rf ./vc
 15 git clone --depth 1 --quiet --single-branch https://github.com/vlang/vc ./vc
 16 make[1]: Leaving directory '/mnt/sda/v_dir/v'
 17 cd ./vc && git clean -xf && git pull --quiet
 18 make fresh_tcc
 19 make[1]: Entering directory '/mnt/sda/v_dir/v'
 20 rm -rf ./thirdparty/tcc
 21 git clone --depth 1 --quiet --single-branch --branch thirdparty-linux-arm https://github.com/vlang/tccbin ./thirdparty/tcc
 22 make[1]: Leaving directory '/mnt/sda/v_dir/v'
 23 cd ./thirdparty/tcc && git clean -xf && git pull --quiet
 24 cc  -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread
 25 /usr/bin/ld: /tmp/cceiQ4E0.o: in function `atomic_load_u64':
 26 v.c:(.text+0xa78): undefined reference to `__atomic_load_8'
 27 /usr/bin/ld: /tmp/cceiQ4E0.o: in function `atomic_store_u64':
 28 v.c:(.text+0xad0): undefined reference to `__atomic_store_8'
 29 /usr/bin/ld: /tmp/cceiQ4E0.o: in function `atomic_fetch_add_u64':
 30 v.c:(.text+0xb04): undefined reference to `__atomic_fetch_add_8'
 31 /usr/bin/ld: /tmp/cceiQ4E0.o: in function `atomic_fetch_sub_u64':
 32 v.c:(.text+0xb44): undefined reference to `__atomic_fetch_sub_8'
 33 collect2: error: ld returned 1 exit status
 34 make: *** [GNUmakefile:93: all] Error 1

@ckqee ckqee changed the title Current latest vlang give error on Raspberry Pi - v.c:(.text+0xa78): undefined reference to `__atomic_load_8' Current latest vlang gives error on Raspberry Pi - v.c:(.text+0xa78): undefined reference to `__atomic_load_8' Dec 20, 2021
@danieldaeschle
Copy link
Member

Raspberry Pi would indeed nice to work :)

@danieldaeschle
Copy link
Member

@crthpl Do you know about this?

@lvl100-one
Copy link

I found a workaround for this error on my Raspberry Pi by providing proper LDFLAGS in GNUmakefile.

I located, then added path to 'libatomic.so' to GNUmakefile:

CC ?= cc
CFLAGS ?=
LDFLAGS ?=/usr/lib/gcc/arm-linux-gnueabihf/8/libatomic.so
TMPDIR ?= /tmp
VROOT ?= .
...

After this 'make' just worked and I was able to compile v executable.

@ckqee
Copy link
Author

ckqee commented Jan 13, 2022

Just tried this now not sure why it is not working:

time make
cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread 
/usr/bin/ld: /tmp/ccJF7eUu.o: in function `atomic_load_u64':
v.c:(.text+0xa78): undefined reference to `__atomic_load_8'
/usr/bin/ld: /tmp/ccJF7eUu.o: in function `atomic_store_u64':
v.c:(.text+0xad0): undefined reference to `__atomic_store_8'
/usr/bin/ld: /tmp/ccJF7eUu.o: in function `atomic_fetch_add_u64':
v.c:(.text+0xb04): undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: /tmp/ccJF7eUu.o: in function `atomic_fetch_sub_u64':
v.c:(.text+0xb44): undefined reference to `__atomic_fetch_sub_8'
collect2: error: ld returned 1 exit status
make: *** [GNUmakefile:93: all] Error 1

real    2m5.522s
user    1m55.285s
sys     0m3.897s

Contents of Makefile

more Makefile 
CC ?= cc
CFLAGS ?=
LDFLAGS ?=/usr/lib/gcc/arm-linux-gnueabihf/8/libatomic.so
TMPDIR ?= /tmp
VROOT ?= .

all:
        rm -rf vc/
        git clone --depth 1 --quiet https://github.com/vlang/vc
        $(CC) -std=gnu11 -w -I ./thirdparty/stdatomic/nix -o v1 vc/v.c -lm -lexecinfo -lpthread
        ./v1 -no-parallel -o v2 $(VFLAGS) cmd/v
        ./v2 -o v $(VFLAGS) cmd/v
        rm -rf v1 v2 vc/
        @echo "V has been successfully built"

@crthpl
Copy link
Member

crthpl commented Jan 13, 2022

try replacing LDFLAGS ?=/usr/lib/gcc/arm-linux-gnueabihf/8/libatomic.so with LDFLAGS ?= -latomic

@ckqee
Copy link
Author

ckqee commented Jan 14, 2022

@bitSweetBYTES Could you kindly help with more information such as
which exact commit this worked for you as per your previous
comment #12907 (comment) ?

@crthpl Thanks for this suggestion by alas it does not seem to work:

time make
cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread
/usr/bin/ld: /tmp/ccCbVRu9.o: in function `atomic_load_u64':
v.c:(.text+0xa78): undefined reference to `__atomic_load_8'
/usr/bin/ld: /tmp/ccCbVRu9.o: in function `atomic_store_u64':
v.c:(.text+0xad0): undefined reference to `__atomic_store_8'
/usr/bin/ld: /tmp/ccCbVRu9.o: in function `atomic_fetch_add_u64':
v.c:(.text+0xb04): undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: /tmp/ccCbVRu9.o: in function `atomic_fetch_sub_u64':
v.c:(.text+0xb44): undefined reference to `__atomic_fetch_sub_8'
collect2: error: ld returned 1 exit status
make: *** [GNUmakefile:93: all] Error 1

real    2m3.492s
user    1m54.066s
sys     0m3.169s

Contents of Makefile

cat Makefile
CC ?= cc
CFLAGS ?=
LDFLAGS ?= -latomic
TMPDIR ?= /tmp
VROOT ?= .

all:
        rm -rf vc/
        git clone --depth 1 --quiet https://github.com/vlang/vc
        $(CC) -std=gnu11 -w -I ./thirdparty/stdatomic/nix -o v1 vc/v.c -lm -lexecinfo -lpthread
        ./v1 -no-parallel -o v2 $(VFLAGS) cmd/v
        ./v2 -o v $(VFLAGS) cmd/v
        rm -rf v1 v2 vc/
        @echo "V has been successfully built"

@crthpl
Copy link
Member

crthpl commented Jan 14, 2022

As it seems that LDFLAGS didn't change the c flags, try changing

        $(CC) -std=gnu11 -w -I ./thirdparty/stdatomic/nix -o v1 vc/v.c -lm -lexecinfo -lpthread

to

        $(CC) -std=gnu11 -w -I ./thirdparty/stdatomic/nix -o v1 vc/v.c -lm -lexecinfo -lpthread -latomic

@Crilum
Copy link

Crilum commented Jan 17, 2022

As it seems that LDFLAGS didn't change the c flags, try changing

        $(CC) -std=gnu11 -w -I ./thirdparty/stdatomic/nix -o v1 vc/v.c -lm -lexecinfo -lpthread

to

        $(CC) -std=gnu11 -w -I ./thirdparty/stdatomic/nix -o v1 vc/v.c -lm -lexecinfo -lpthread -latomic

@crthpl I'm having the same issue as @ckqee, adding -latomic (like you suggested) to that command didn't work..

However, @bitSweetBYTES's workaround works, part of my v/GNUmakefile:

CC ?= cc
CFLAGS ?=
LDFLAGS ?= /lib/arm-linux-gnueabihf/libatomic.so.1.2.0
TMPDIR ?= /tmp
VROOT  ?= .
VC     ?= ./vc
V      ?= ./v
VCREPO ?= https://github.com/vlang/vc
TCCREPO ?= https://github.com/vlang/tccbin

VCFILE := v.c
TMPTCC := $(VROOT)/thirdparty/tcc
TCCOS := unknown
TCCARCH := unknown
GITCLEANPULL := git clean -xf && git pull --quiet
GITFASTCLONE := git clone --depth 1 --quiet --single-branch

#### Platform detections and overrides:
_SYS := $(shell uname 2>/dev/null || echo Unknown)
_SYS := $(patsubst MSYS%,MSYS,$(_SYS))
_SYS := $(patsubst MINGW%,MinGW,$(_SYS))

ifneq ($(filter $(_SYS),MSYS MinGW),)
WIN32 := 1
V:=./v.exe
endif

And then make:

$ make
cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread /lib/arm-linux-gnueabihf/libatomic.so.1.2.0
./v1.exe -no-parallel -o v2.exe  cmd/v
./v2.exe -o ./v  cmd/v
rm -rf v1.exe v2.exe
V has been successfully built
V 0.2.4 db48594

@lvl100-one
Copy link

@bitSweetBYTES Could you kindly help with more information such as which exact commit this worked for you as per your previous comment #12907 (comment) ?

@crthpl Thanks for this suggestion by alas it does not seem to work:

time make
cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc  -std=gnu99 -w -I ./thirdparty/stdatomic/nix -o v1.exe ./vc/v.c -lm -lpthread
/usr/bin/ld: /tmp/ccCbVRu9.o: in function `atomic_load_u64':
v.c:(.text+0xa78): undefined reference to `__atomic_load_8'
/usr/bin/ld: /tmp/ccCbVRu9.o: in function `atomic_store_u64':
v.c:(.text+0xad0): undefined reference to `__atomic_store_8'
/usr/bin/ld: /tmp/ccCbVRu9.o: in function `atomic_fetch_add_u64':
v.c:(.text+0xb04): undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: /tmp/ccCbVRu9.o: in function `atomic_fetch_sub_u64':
v.c:(.text+0xb44): undefined reference to `__atomic_fetch_sub_8'
collect2: error: ld returned 1 exit status
make: *** [GNUmakefile:93: all] Error 1

real    2m3.492s
user    1m54.066s
sys     0m3.169s

Contents of Makefile

cat Makefile
CC ?= cc
CFLAGS ?=
LDFLAGS ?= -latomic
TMPDIR ?= /tmp
VROOT ?= .

all:
        rm -rf vc/
        git clone --depth 1 --quiet https://github.com/vlang/vc
        $(CC) -std=gnu11 -w -I ./thirdparty/stdatomic/nix -o v1 vc/v.c -lm -lexecinfo -lpthread
        ./v1 -no-parallel -o v2 $(VFLAGS) cmd/v
        ./v2 -o v $(VFLAGS) cmd/v
        rm -rf v1 v2 vc/
        @echo "V has been successfully built"

It was commit ed2d128

@larpon
Copy link
Contributor

larpon commented Mar 7, 2022

I'm using :

export LDFLAGS=-latomic
make

This works on Raspbian GNU/Linux 10 (buster) with gcc version 8.3.0 (standard RPi4 Rasbian install)

I can't get V's tcc to work, though

I made it work with tcc as described here

@spytheman
Copy link
Member

On most Linux machines, make is GNU make, and it uses GNUmakefile with a priority over Makefile.

On MacOS/BSDs and probably others, make is BSD make, which uses only Makefile, and ignores GNUmakefile. On such systems, GNU make is often available as gmake, so if you want to use GNUmakefile there too, try running gmake instead of make.

@spytheman
Copy link
Member

spytheman commented Mar 8, 2022

Since latest V 137fade, the BSD Makefile also has support for CFLAGS and LDFLAGS in the bootstrapping stage (the one that compiles vc/v.c to a V executable initially).

@felipensp felipensp added the Arch: ARM Bugs/feature requests, that are related to architecture ARM. label Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: ARM Bugs/feature requests, that are related to architecture ARM. Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

8 participants