Libomptarget's libLLVMSupport dependency for bare metal RISCV32 target

Dear all,

previously in our downstream compiler, we were able to build libomptarget standalone for RISCV32 bare metal targets, linking only against dependencies from a RISCV GNU Newlib toolchain.

After merging the latest changes from upstream LLVM, libomptarget depends on libLLVMSupport. This mainly seems to be caused by things like using llvm::SmallVector instead of std::vector. Hence, we cannot build libomptarget as before.

Now, a fix for us would be to build (the necessary parts of) libLLVMSupport for our target, linking only against dependencies from a RISCV GNU Newlib toolchain. (The libLLVMObject dependency would not be necessary due to our downstream modifications, as far as I can see.)

However, I do not know whether it is possible to only build this part of LLVM for a target, I can only remember I managed to build the whole libLLVM using the standard way of building, and this only worked using a full-featured RISCV GNU Linux toolchain, not the more basic Newlib one.

Any ideas on how I could solve this new dependency problem would be greatly appreciated.

The decision to make the libomptarget runtime and plugins an LLVM library happened during the LLVM 15 release. The plugins rely heavily on the LLVM features, while libomiptarget proper mostly uses it for the more efficient data structures and platform agnostic dynamic library support. Is RISCV unable to build LLVM at all? These dependencies should be resolved statically at build time unless you manually override the default via -DBUILD_SHARED_LIBS=ON.

Another thing to note is libomptarget no longer support 32-bit targets.

Thanks for your answer!

Yes, I am able to build LLVM (without any subprojects, just the libraries I need such as libLLVMSupport.a) for RISCV32 with the RISCV GNU Linux toolchain.

The problem however is that we are targeting a bare metal RISCV32 system and use the Newlib toolchain to provide libraries instead of the Linux one. In the Newlib toolchain, e.g. libatomic is missing because it is not yet implemented, and then CMake configuration of LLVM complains

-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Failed
-- Looking for __atomic_fetch_add_4 in atomic
-- Looking for __atomic_fetch_add_4 in atomic - not found
CMake Error at cmake/modules/CheckAtomic.cmake:59 (message):
  Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
  cmake/config-ix.cmake:413 (include)
  CMakeLists.txt:861 (include)

I can remember that some time ago, I tried to build the LLVM libraries with the RISCV GNU Newlib toolchain and gave up after some time, I think there were more problems than the above.

Maybe I can find out how to only build libLLVMSupport.a or even only the necessary parts… Since the CMake configuration of LLVM is not trivial, however, I have to check,

Thanks for your answer! That is interesting!

If I remember right, when I provided support for libomptarget on RISCV32 in our downstream compiler, there seemed to be no support for 32 bit targets and I had to do corresponding modifications. For example, the size of an offload entry in a binary can vary due to different pointer sizes on 64 and 32 bit targets.

So this means that in the meantime, support for 32 bit has been provided and then removed again? Is there a certain reason for not supporting 32 bit targets? In my impression, e.g. heterogeneous accelerators are gaining importance, so I can imagine that 32 bit support would be interesting to have in general.

Could you tell what exactly has been removed in terms of 32 bit support, so I could at least correct this locally in our downstream compiler?