Get the address of basic block (mapping to llvm ir)

Hi

I want to get the address of basic block in llvm ir ,

so I use and BlockAddress,

and then use GlobalVariable 's setInitializer to pass it to my own program.

but I found that BlockAddress sometime would be wrong.

Because code gen (llvm backend) is free to insert instructions in to bb,

like “mov rax” or “add rsp”.

and even change the order of basic block .

like this:

[llvm-dev] Is BlockAddress always correct ?

http://lists.llvm.org/pipermail/llvm-dev/2020-February/139563.html
http://lists.llvm.org/pipermail/llvm-dev/2020-February/139571.html

Then, I study some discussion in llvm-dev

[llvm-dev] Figuring out return address of a call

http://lists.llvm.org/pipermail/llvm-dev/2017-March/110719.html
http://lists.llvm.org/pipermail/llvm-dev/2017-March/110721.html

[llvm-dev] Stackmap question

http://lists.llvm.org/pipermail/llvm-dev/2016-December/107713.html

I also study the shadow stack paper in SP’19, but it is purely in llvm backend , right ?

After survey, I found that BlockAddress and patchpoint/stack map both can’t exactly get the address of basic block , especially the basic block is before a call instruction.

Have you solved this problem?
Or get the address of basic block in other way ?

Thank you ~