I am currently trying to write a basic C stack walker using LLVM's stackmap feature. I have generated the stackmaps and now I am trying to pass the stackmap to a C function so I can work with it.
In particular I am having trouble passing in __LLVM_StackMaps
to my stack walker. I have tried passing it as a parameter from an assembly function:
.text
.globl stackHelper
.extern stackWalker
.extern __LLVM_StackMaps
stackHelper:
mov %rsp, %rdi
mov __LLVM_StackMaps, %rsi
jmp stackWalker
I get the error
(.text+0x7): undefined reference to ``__LLVM_StackMaps'
.
objdump says __LLVM_StackMaps
is not in .text or .data but rather in a custom .llvm_stackmaps
section. Here is the objdump output:
factorial.o: file format elf64-x86-64
factorial.o
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000067 0000000000000000 0000000000000000 00000040 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .rodata.str1.1 00000005 0000000000000000 0000000000000000 000000a7 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.GNU-stack 00000000 0000000000000000 0000000000000000 000000ac 2**0
CONTENTS, READONLY
3 .llvm_stackmaps 00000050 0000000000000000 0000000000000000 000000b0 2**3
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
4 .eh_frame 00000050 0000000000000000 0000000000000000 00000100 2**3
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
SYMBOL TABLE:
0000000000000000 l df *ABS* 0000000000000000 factorial.ll
0000000000000000 l .llvm_stackmaps 0000000000000000 __LLVM_StackMaps
0000000000000000 l d .text 0000000000000000 .text
0000000000000000 l d .rodata.str1.1 0000000000000000 .rodata.str1.1
0000000000000030 g F .text 0000000000000037 fact
0000000000000000 g F .text 0000000000000023 main
0000000000000000 *UND* 0000000000000000 printf
0000000000000000 *UND* 0000000000000000 stackHelper
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0000000000000011 R_X86_64_32 .rodata.str1.1
000000000000001b R_X86_64_PC32 printf-0x0000000000000004
000000000000004e R_X86_64_PC32 stackHelper-0x0000000000000004
RELOCATION RECORDS FOR [.llvm_stackmaps]:
OFFSET TYPE VALUE
0000000000000010 R_X86_64_64 fact
RELOCATION RECORDS FOR [.eh_frame]:
OFFSET TYPE VALUE
0000000000000020 R_X86_64_PC32 .text
0000000000000034 R_X86_64_PC32 .text+0x0000000000000030
My guess is that it does not have access to the symbols in this table. Is there a way to access this data from my assembly function or would I need to do something during the linking stage to allow it to access this properly?