Re: riscv: link error when supporting KCSAN

Andrea Parri
2024-06-12T06:28:38Z

On Wed, Jun 12, 2024 at 11:02:32AM +0800, Li Zetao wrote:
> Hi all,
>
> I'm developing support for KCSAN on riscv but getting the following link
> error:
>
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L996':
> core.c:(.text+0x2b62): undefined reference to `__atomic_exchange_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1015':
> core.c:(.text+0x2c40): undefined reference to `__atomic_fetch_add_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1034':
> core.c:(.text+0x2d1e): undefined reference to `__atomic_fetch_sub_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1053':
> core.c:(.text+0x2dfc): undefined reference to `__atomic_fetch_and_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1071':
> core.c:(.text+0x2eda): undefined reference to `__atomic_fetch_or_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1090':
> core.c:(.text+0x2fb8): undefined reference to `__atomic_fetch_xor_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1109':
> core.c:(.text+0x3096): undefined reference to `__atomic_fetch_nand_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1128':
> core.c:(.text+0x3182): undefined reference to `__atomic_compare_exchange_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1147':
> core.c:(.text+0x3274): undefined reference to `__atomic_compare_exchange_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1166':
> core.c:(.text+0x3366): undefined reference to `__atomic_compare_exchange_1'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1220':
> core.c:(.text+0x35ec): undefined reference to `__atomic_exchange_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1239':
> core.c:(.text+0x36ce): undefined reference to `__atomic_fetch_add_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1258':
> core.c:(.text+0x37b0): undefined reference to `__atomic_fetch_sub_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1277':
> core.c:(.text+0x3892): undefined reference to `__atomic_fetch_and_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1296':
> core.c:(.text+0x3974): undefined reference to `__atomic_fetch_or_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1315':
> core.c:(.text+0x3a56): undefined reference to `__atomic_fetch_xor_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1334':
> core.c:(.text+0x3b38): undefined reference to `__atomic_fetch_nand_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1353':
> core.c:(.text+0x3c28): undefined reference to `__atomic_compare_exchange_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1372':
> core.c:(.text+0x3d1e): undefined reference to `__atomic_compare_exchange_2'
> riscv64-linux-gnu-ld: kernel/kcsan/core.o: in function `.L1391':
> core.c:(.text+0x3e14): undefined reference to `__atomic_compare_exchange_2'
> make[2]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1
> make[1]: *** [/home/l00517538/PrIntFuzz/third_party/linux/Makefile:1171:
> vmlinux] Error 2
>
> The reason for the error is that riscv only supports 32-bit or 64-bit atomic
> operations.As far as I know, this error is solved through the
> no-outline-atomics option on arm64. How can I solve this problem on riscv?

IIRC, support for inline subword atomic ops has been added to riscv/gcc
with

https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616807.html

(-minline-atomics becoming the default behavior with the above changes).

It appears as if your compiler does not include these changes and might
have to be upgraded?

+ Patrick and Palmer, FYI.

Andrea