I'm using functions which are intrinsic on the arm compiler but not on GCC (i.e. arm's __strex). I'm using the strex function as part of an inline function. Using the arm compiler it works fine. I have two projects, the target using the arm compiler and test project using GCC. Using GCC, I can't get it to compile with the many work-arounds I've tried. I've been unable to get the variable within scope. As the function is inline, that means the target files are expecting the function to be there within the scope of that file. I don't want to modify the target to include a header file which is only needed for the test project to compile. Is there any way to create a function via the linker or compiler attribute/something that would act much like an intrinsic function which has global scope throughout the code base?
You need the function to be declared for the compiler to be able to inline it. If for some reason you don't want to modify any of your sources, modify your build with to compile with command line options.
One possibility is a preprocessor option like -D__strex=something
if you can define it as a CPP macro.
Or more likely use GCC's -include foo.h
option to include a .h that provides a proper definition of whatever intrinsics you need. (It searches the #include "..."
paths by default, not #include <...>
).
-include file
Process file as if "#include "file"" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the "#include "..."" search chain as normal.
GCC does have intrinsics for some instructions. IDK about the LL/SC instructions like strex
, though; that would be tricky because there are limits on what you can put between a ldrex
and strex
without making it always fail. Intrinsics with arbitrary C between them could lead to code that only worked in release mode, if debug mode did extra loads/stores.
e.g. https://github.com/ARMmbed/core-util/issues/76 suggests that project move away from those intrinsics and use GNU C __atomic
builtins. Consider doing the same yourself, e.g. using __atomic_add_fetch
instead of manual __ldrex
and __strex
. https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html