Since some function registeration is required in R, I have to obtain some function pointer from either proc-macro or hand-writting it again.
Currently, I use a some tricks, let Rust treat the const functions as foreign function again, use an extra extern block to catch them:
mod _I_do_not_know_its_name_ {
#[no_mangle] extern "C" fn foo(params:...)->... {...}
}
extern "C" {fn foo();}
const FOO_POINTER:*const() = foo as *const_; // no need to access the old `foo`.
It seems that, If only the function pointer is needed, even the parameters could be omit. But, is it sound? Will Rust make bad assumption for that function and make unsound results?
you are essentially using the address of a linker symbol, and linker symbols, by themselves, don't have types as defined by programming languages like C or Rust, it up to the programmer to declare the type of a linker symbol in language specific way.
to my understanding, what you did is semantically equivalent to pointer casts (or transmute()) in rust, and uses of raw pointers will not trigger UB by themselves, it would potentially trigger UB only when you load through a invalid raw pointer.
so I think what you did is valid, as long you only look the addresses of the raw pointers and not call them as function pointers (of incorrect signatures), as far as rust is concerned. it doesn't matter how FFI code would use the pointers.
since you didn't use unsafe here, and deref raw pointers in rust always need unsafe, it is sound for sure.