zephyrproject-rtos / meta-zephyr-sdk

Zephyr SDK (obsolete)
MIT License
44 stars 29 forks source link

ARC and Nios II compilers do not support atomic builtins #65

Closed zephyrbot closed 7 years ago

zephyrbot commented 8 years ago

Reported by Andrew Boie:

In testing this patch I found that I get linker errors on ARC and Nios II:

https://gerrit.zephyrproject.org/r/3291

It seems that the current compiler versions do not support these operations.

https://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Atomic-Builtins.html

Errors typically resemble:

kernel/built-in.o: In function `atomic_or':
/projects/zephyr3/include/atomic.h:193: undefined reference to `__sync_fetch_and_or_4'
kernel/built-in.o: In function `atomic_and':
/projects/zephyr3/include/atomic.h:228: undefined reference to `__sync_fetch_and_and_4'
kernel/built-in.o: In function `atomic_or':
/projects/zephyr3/include/atomic.h:193: undefined reference to `__sync_fetch_and_or_4'
kernel/built-in.o: In function `atomic_and':
/projects/zephyr3/include/atomic.h:228: undefined reference to `__sync_fetch_and_and_4'
net/built-in.o: In function `atomic_and':
/projects/zephyr3/include/atomic.h:228: undefined reference to `__sync_fetch_and_and_4'
net/built-in.o: In function `atomic_or':
/projects/zephyr3/include/atomic.h:193: undefined reference to `__sync_fetch_and_or_4'
net/built-in.o: In function `atomic_set':
/projects/zephyr3/include/atomic.h:158: undefined reference to `__sync_lock_test_and_set_4'
net/built-in.o: In function `atomic_or':
/projects/zephyr3/include/atomic.h:193: undefined reference to `__sync_fetch_and_or_4'
net/built-in.o: In function `atomic_add':
/projects/zephyr3/include/atomic.h:70: undefined reference to `__sync_fetch_and_add_4'
net/built-in.o: In function `atomic_sub':
/projects/zephyr3/include/atomic.h:88: undefined reference to `__sync_fetch_and_sub_4'
net/built-in.o: In function `atomic_set':
/projects/zephyr3/include/atomic.h:158: undefined reference to `__sync_lock_test_and_set_4'
net/built-in.o: In function `atomic_or':
/projects/zephyr3/include/atomic.h:193: undefined reference to `__sync_fetch_and_or_4'
net/built-in.o: In function `atomic_and':
/projects/zephyr3/include/atomic.h:228: undefined reference to `__sync_fetch_and_and_4'
net/built-in.o: In function `atomic_or':
/projects/zephyr3/include/atomic.h:193: undefined reference to `__sync_fetch_and_or_4'
net/built-in.o: In function `atomic_and':
/projects/zephyr3/include/atomic.h:228: undefined reference to `__sync_fetch_and_and_4'
/projects/zephyr3/include/atomic.h:228: undefined reference to `__sync_fetch_and_and_4'
net/built-in.o: In function `atomic_set':
/projects/zephyr3/include/atomic.h:158: undefined reference to `__sync_lock_test_and_set_4'
/projects/zephyr3/include/atomic.h:158: undefined reference to `__sync_lock_test_and_set_4'
net/built-in.o: In function `atomic_and':
/projects/zephyr3/include/atomic.h:228: undefined reference to `__sync_fetch_and_and_4'
/projects/zephyr3/include/atomic.h:228: undefined reference to `__sync_fetch_and_and_4'

(Imported from Jira SDK-46)

zephyrbot commented 8 years ago

by Claudiu Zissulescu:

Hi,

Atomic builtins are available only for ARCHS processors as they have LLOCK and SCOND instructions. Others ARC cpus need use inline assembly/builins to implement the desired ops.

Cheers, Claudiu

zephyrbot commented 8 years ago

by Andrew Boie:

That's somewhat tangential to the point of this JIRA. If the HW doesn't have native instructions, I think there should still exist implementations of _sync* functions.

{quote} Not all operations are supported by all target processors. If a particular operation cannot be implemented on the target processor, a warning will be generated and a call an external function will be generated. The external function will carry the same name as the builtin, with an additional suffix `_n' where n is the size of the data type. {quote}

For example Nios II doesn't have hardware division, so GCC pulls in division functions instead.

zephyrbot commented 8 years ago

by Claudiu Zissulescu:

Division is something else as it is essential for the compiler. Usually all the essential compiler operations which are not supported by hw are implemented via emulation using libgcc.

However, atomic ops are used in a multi-processor environment, hence, if you do not have support for this, it seems to me useless to have something there. Anyhow, if ones needs atomic support, gcc comes with libatomic, but one needs to target it for ARC.

Cheers, Claudiu

zephyrbot commented 8 years ago

by Andrew Boie:

I'm not following your argument. The GCC manual (quoted above) states that function calls will be emitted if the necessary ASM operations aren't present. Are you saying implementation of __sync_fetchand* is an exercise for the end user?

zephyrbot commented 8 years ago

by Claudiu Zissulescu:

It may be, as I do not know if your ARC variant has or not support for MP. libAtomic is coming with a software implementation but it may ask for some OS support. Otherwise, you can just make a simple lib having those builtins names and with a simple implementation as u do not need to sync the variables on a single processor. As you indicated GCC will create that call, but someone needs to provide a library.

On the other hand, maybe libatomic is already there and you just need to add -latomic when linking. Just try it.

zephyrbot commented 7 years ago

by Mark Linkmeyer:

Per review with Anas and Juro: "Support for multiprocessors will come at some point in the future."

zephyrbot commented 7 years ago

by Andrew Boie:

This is orthogonal to multiprocessing and is an issue on uniprocessor systems (example: interrupt handling)

zephyrbot commented 7 years ago

by Mark Linkmeyer:

Per review with Juro, someone needs to create the implementation behind the stubbed-out functions for ARC and NIOS II.