[llvm-dev] How to read stack map

256 views
Skip to first unread message

Kavindu Gimhan Zoysa via llvm-dev

unread,
May 12, 2021, 3:16:13 AM5/12/21
to llvm...@lists.llvm.org
Hi all,

I was able to generate the Stack Map which is shown here https://llvm.org/docs/StackMaps.html#stack-map-format. Now I want to read those entries. What I did was, I manually change the .s file as shown below (Added the .globl __LLVM_StackMaps manually). Then I can read the entries using C code.  

.globl __LLVM_StackMaps
__LLVM_StackMaps:
.byte 3
.byte 0
.short 0

I want to know, whether this is the correct approach. If not could you please suggest me the correct approach?

Really appreciate your input on this.

Thank you,
Kavindu

Kavindu Gimhan Zoysa,
BSc(Hons) | ENTC | UoM,
SSE | WSO2

Kavindu Gimhan Zoysa via llvm-dev

unread,
May 12, 2021, 5:52:40 AM5/12/21
to llvm...@lists.llvm.org

Kavindu Gimhan Zoysa,
BSc(Hons) | ENTC | UoM,
SSE | WSO2


Denis Antrushin via llvm-dev

unread,
May 12, 2021, 9:07:39 AM5/12/21
to llvm...@lists.llvm.org
LLVM puts stack map into special section, see https://llvm.org/docs/StackMaps.html#stackmap-section
You can use any ELF-reading library to extract/read it

On 12.05.2021 10:15, Kavindu Gimhan Zoysa via llvm-dev wrote:
> Hi all,
>

> I was able to generate the Stack Map which is shown here https://llvm.org/docs/StackMaps.html#stack-map-format <https://llvm.org/docs/StackMaps.html#stack-map-format>. Now I want to read those entries. What I did was, I manually change the .s file as shown below (Added the *.globl __LLVM_StackMaps *manually). Then I can read the entries using C code.


>
> .globl __LLVM_StackMaps
> __LLVM_StackMaps:
> .byte 3
> .byte 0
> .short 0
>
> I want to know, whether this is the correct approach. If not could you please suggest me the correct approach?
>
> Really appreciate your input on this.
>
> Thank you,
> Kavindu
>
> Kavindu Gimhan Zoysa,
> BSc(Hons) | ENTC | UoM,
> SSE | WSO2
>

> GitHub <https://github.com/KavinduZoysa> LinkedIn <https://www.linkedin.com/in/kavindu-gimhan-zoysa-85939a122/> Medium <https://medium.com/@kavindugimhanzoysa>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm...@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Kavindu Gimhan Zoysa via llvm-dev

unread,
May 12, 2021, 2:33:53 PM5/12/21
to Denis Antrushin, llvm...@lists.llvm.org
What should I do, if I want to read the stack map within the same program where the stack map is generated? I think an ELF-reading library should be used externally.

Can't I use this C API `LLVMCreateSimpleMCJITMemoryManager()`?

Kavindu Gimhan Zoysa,
BSc(Hons) | ENTC | UoM,
SSE | WSO2


Philip Reames via llvm-dev

unread,
May 12, 2021, 2:37:24 PM5/12/21
to Kavindu Gimhan Zoysa, Denis Antrushin, llvm...@lists.llvm.org

Kavindu,

I can't parse your question.  Can you rephrase?

Philip

On 5/12/21 11:33 AM, Kavindu Gimhan Zoysa via llvm-dev wrote:
What should I do, if I want to read the stack map within the same program where the stack map is generated? I think an ELF-reading library should be used externally.

Can't I use this C API `LLVMCreateSimpleMCJITMemoryManager()`?
This is almost certainly unrelated to your question if I'm even vaguely understanding you. 

Philip Reames via llvm-dev

unread,
May 12, 2021, 2:44:07 PM5/12/21
to Kavindu Gimhan Zoysa, llvm...@lists.llvm.org

This is generally the right approach, yes.

You may also find include/llvm/Object/StackMapParser.h helpful.

Philip

Kavindu Gimhan Zoysa via llvm-dev

unread,
May 13, 2021, 12:19:26 AM5/13/21
to Philip Reames, llvm...@lists.llvm.org
Hi Philip, 

Let's say my code structure is as follows.

func foo() {}
func bar() {
      call foo(); // this is a statepoint
}
func readLLVMStackMap() {}
func main() {
      call bar(); // this is a statepoint
      call readLLVMStackMap();
}

Actually, my question is that how do I read the LLVM Stack map. Simply I want to implement readLLVMStackMap method, in order to read the LLVM Stack Map. What is the best approach should I follow?

Philip, that was my question. So according to your previous answers, What I need to do is following this document https://llvm.org/docs/StackMaps.html#stack-map-section. Am I right?

Kavindu Gimhan Zoysa,
BSc(Hons) | ENTC | UoM,
SSE | WSO2


Kavindu Gimhan Zoysa via llvm-dev

unread,
May 14, 2021, 5:10:45 AM5/14/21
to Philip Reames, llvm...@lists.llvm.org
Hi All,

I was able to read the stack map. This is my code https://github.com/KavinduZoysa/test-GCs/tree/master/statepoints

Kavindu Gimhan Zoysa,
BSc(Hons) | ENTC | UoM,
SSE | WSO2


Reply all
Reply to author
Forward
0 new messages