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

libmetal/atomic: enable 64-bit atomic by toolchain builtin flags #301

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

anchao
Copy link
Contributor

@anchao anchao commented Jun 29, 2024

libmetal/atomic: enable 64-bit atomic by toolchain builtin flags

Fix compile error:

arm-none-eabi-ld: (remoteproc_virtio.o): in function `metal_io_read':
metal/io.h:252: undefined reference to `__atomic_load_8'
arm-none-eabi-ld: (remoteproc_virtio.o): in function `metal_io_write':
metal/io.h:290: undefined reference to `__atomic_store_8'

Not all 32-bit architectures support 64bit atomic, gcc/clang
toolchains have built-in properties to indicate whether support atomic64:

| $ arm-none-eabi-gcc -march=armv7e-m  -dM -E - < /dev/null | grep SYNC
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1

Signed-off-by: chao an [email protected]

Copy link

This pull request has been marked as a stale pull request because it has been open (more than) 45 days with no activity.

@github-actions github-actions bot added the Stale label Aug 20, 2024
@wmamills
Copy link
Contributor

wmamills commented Sep 5, 2024

@ancho please tell us more about your compiler RTOS platform etc. We don't see this issue on other gcc based 32 bit platforms

CV-Bowen and others added 2 commits October 17, 2024 10:10
Because nuttx/io.c use NULL and NULL is defined in <stddef.h>

Signed-off-by: Bowen Wang <[email protected]>
Fix compile error:
arm-none-eabi-ld: (remoteproc_virtio.o): in function `metal_io_read':
metal/io.h:252: undefined reference to `__atomic_load_8'
arm-none-eabi-ld: (remoteproc_virtio.o): in function `metal_io_write':
metal/io.h:290: undefined reference to `__atomic_store_8'

Not all 32-bit architectures support 64bit atomic, gcc/clang
toolchains have built-in properties to indicate whether support atomic64:

| $ arm-none-eabi-gcc -march=armv7e-m  -dM -E - < /dev/null | grep SYNC
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1

Signed-off-by: chao an <[email protected]>
@anchao
Copy link
Contributor Author

anchao commented Oct 17, 2024

@ancho please tell us more about your compiler RTOS platform etc. We don't see this issue on other gcc based 32 bit platforms

@wmamills @arnopo @xiaoxiang781216
GCC ARM32 has similar problems on many architecture variants. I have sorted out the relevant information and hope it will help for understanding this problem.

ARM32 arch list:

archer@archerc:~/code/libmetal$ cat arch_list.txt 
armv4 armv4t armv5t armv5te armv5tej armv6 armv6j armv6k armv6z armv6kz armv6zk armv6t2 armv6-m armv6s-m armv7 armv7-a armv7ve armv7-r armv7-m armv7e-m armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8-m.base armv8-m.main armv8-r armv8.1-m.main armv9-a iwmmxt iwmmxt2

atomic 64 test code:

archer@archerc:~/code/libmetal$ cat test.c
#include <stdatomic.h>

void _start(void)
{
  atomic_ullong ullong;

  atomic_load_explicit(&ullong, memory_order_seq_cst);
}

Try all architectures:

archer@archerc:~/code/libmetal$ j=0;for i in `cat arch_list.txt `;do j=`expr $j + 1`;echo -e "---------------------------------------\n $j compiler arch:$i";arm-none-eabi-gcc -nostdlib -march=$i test.c;arm-none-eabi-gcc -march=$i -dM -E - < /dev/null | grep __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8;done
---------------------------------------
 1 compiler arch:armv4
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cccgTCz3.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 2 compiler arch:armv4t
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cc4TsRvb.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 3 compiler arch:armv5t
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccURuZb2.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 4 compiler arch:armv5te
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccFyHQcb.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 5 compiler arch:armv5tej
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccpglToh.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 6 compiler arch:armv6
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccZiYR8B.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 7 compiler arch:armv6j
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccrLVQPH.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 8 compiler arch:armv6k
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 9 compiler arch:armv6z
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccLK9QVC.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 10 compiler arch:armv6kz
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 11 compiler arch:armv6zk
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 12 compiler arch:armv6t2
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccpYIWQ1.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 13 compiler arch:armv6-m
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cc8wff5H.o: in function `_start':
test.c:(.text+0x12): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 14 compiler arch:armv6s-m
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccAnnjEG.o: in function `_start':
test.c:(.text+0x12): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 15 compiler arch:armv7
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccKKeSkw.o: in function `_start':
test.c:(.text+0x10): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 16 compiler arch:armv7-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 17 compiler arch:armv7ve
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 18 compiler arch:armv7-r
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 19 compiler arch:armv7-m
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cciBSDDu.o: in function `_start':
test.c:(.text+0x10): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 20 compiler arch:armv7e-m
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccIMIiBT.o: in function `_start':
test.c:(.text+0x10): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 21 compiler arch:armv8-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 22 compiler arch:armv8.1-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 23 compiler arch:armv8.2-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 24 compiler arch:armv8.3-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 25 compiler arch:armv8.4-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 26 compiler arch:armv8.5-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 27 compiler arch:armv8.6-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 28 compiler arch:armv8-m.base
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccnD7ohq.o: in function `_start':
test.c:(.text+0x12): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 29 compiler arch:armv8-m.main
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccQcDi02.o: in function `_start':
test.c:(.text+0x10): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 30 compiler arch:armv8-r
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 31 compiler arch:armv8.1-m.main
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccXyTZ71.o: in function `_start':
test.c:(.text+0x10): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 32 compiler arch:armv9-a
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
---------------------------------------
 33 compiler arch:iwmmxt
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cc5YtGE6.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
---------------------------------------
 34 compiler arch:iwmmxt2
/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /tmp/ccmjb0dX.o: in function `_start':
test.c:(.text+0x1c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status

From the test results, you can see that only the variant containing the built-in macro __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 will compile successfully.

@anchao
Copy link
Contributor Author

anchao commented Oct 17, 2024

Missing some information, here is my GCC compiler version:

archer@archerc:~/code/libmetal$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/home/archer/code/ln/l1/prebuilts/linux/gcc/arm/bin/../libexec/gcc/arm-none-eabi/13.3.1/lto-wrapper
Target: arm-none-eabi
Configured with: /data/jenkins/workspace/GNU-toolchain/arm-13/src/gcc/configure --target=arm-none-eabi --prefix=/data/jenkins/workspace/GNU-toolchain/arm-13/build-arm-none-eabi/install --with-gmp=/data/jenkins/workspace/GNU-toolchain/arm-13/build-arm-none-eabi/host-tools --with-mpfr=/data/jenkins/workspace/GNU-toolchain/arm-13/build-arm-none-eabi/host-tools --with-mpc=/data/jenkins/workspace/GNU-toolchain/arm-13/build-arm-none-eabi/host-tools --with-isl=/data/jenkins/workspace/GNU-toolchain/arm-13/build-arm-none-eabi/host-tools --disable-shared --disable-nls --disable-threads --disable-tls --enable-checking=release --enable-languages=c,c++,fortran --with-newlib --with-gnu-as --with-headers=yes --with-gnu-ld --with-native-system-header-dir=/include --with-sysroot=/data/jenkins/workspace/GNU-toolchain/arm-13/build-arm-none-eabi/install/arm-none-eabi --with-multilib-list=aprofile,rmprofile --with-pkgversion='Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)' --with-bugurl=https://bugs.linaro.org/
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 13.3.1 20240614 (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24))

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