Proper usage of clCreateProgramWithIL

I am trying to figure out how to properly use the clCreateProgramWithIL function of the OpenCL C API.

More specifically, I am working on a project where I need to get a .cl file from a user, compile it to LLVM IR, instrument the LLVM IR bitcode (using the LLVM IR C++ API) for profiling purposes and then run the instrumented kernels on any device. It seems like clCreateProgramWithIL is what I need, but after using it followed by clBuildProgram, the latter always fails with the following error:

error: undefined reference to `get_global_id()'
error: backend compiler failed build.

I tried converting LLVM IR to SPIR-V with llvm-spirv but I got the same error. Isn’t clBuildProgram supposed to link the intermediate representation (LLVM IR or SPIR-V) with the OpenCL runtime library? Am I misusing the clCreateProgramWithIL function? I can not find any instructions or examples as to how to use it properly.