blob: 71c2c9580e35a89675d4618363ad05aacdbb534e [file] [log] [blame]
Mike Dodd8cfa7022010-11-17 11:12:26 -08001/**
2 * @file opjitconv.h
3 * Convert a jit dump file to an ELF file
4 *
5 * @remark Copyright 2007 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author Jens Wilke
9 * @Modifications Maynard Johnson
10 * @Modifications Philippe Elie
11 * @Modifications Daniel Hansel
12 *
13 * Copyright IBM Corporation 2007
14 *
15 */
16
17#ifndef OPJITCONV_H
18#define OPJITCONV_H
19
20#define OP_JIT_CONV_OK 0
21#define OP_JIT_CONV_FAIL -1
22#define OP_JIT_CONV_NO_DUMPFILE 1
23#define OP_JIT_CONV_NO_ANON_SAMPLES 2
24#define OP_JIT_CONV_NO_MATCHING_ANON_SAMPLES 3
25#define OP_JIT_CONV_NO_JIT_RECS_IN_DUMPFILE 4
26#define OP_JIT_CONV_ALREADY_DONE 5
27#define OP_JIT_CONV_TMPDIR_NOT_REMOVED 6
28
29#include <bfd.h>
30#include <stddef.h>
31#include <sys/stat.h>
32
33#include "op_list.h"
34#include "op_types.h"
35
36/* Structure that contains all information
37 * for one function entry in the jit dump file.
38 * the jit dump file gets mmapped and code and
39 * symbol_name point directly into the file */
40struct jitentry {
41 /* linked list. see jitentry_list */
42 struct jitentry * next;
43 /* vma */
44 unsigned long long vma;
45 /* point to code in the memory mapped file */
46 void const * code;
47 /* size of the jitted code */
48 int code_size;
49 /* point to the name in memory mapped jitdump file, or
50 * to a malloced string, if we have a disambiguation replacement */
51 char * symbol_name;
52 /* sym_name_malloced ==1 means we need to free the memory when done. */
53 int sym_name_malloced;
54 /* seconds since epoch when the code was created */
55 unsigned long long life_start;
56 /* seconds since epoch when the code was overwritten */
57 unsigned long long life_end;
58 /* after ordering and partitioning this is the ELF
59 * section we put this code to */
60 asection * section;
61};
62
63struct jitentry_debug_line {
64 struct jitentry_debug_line * next;
65 struct jr_code_debug_info const * data;
66 /* seconds since epoch when the code was created */
67 unsigned long long life_start;
68 /* seconds since epoch when the code was overwritten */
69 unsigned long long life_end;
70 void const * end;
71};
72
73struct op_jitdump_info
74{
75 void * dmp_file;
76 struct stat dmp_file_stat;
77};
78
79struct pathname
80{
81 char * name;
82 struct list_head neighbor;
83};
84
85/* jitsymbol.c */
86void create_arrays(void);
87int resolve_overlaps(unsigned long long start_time);
88void disambiguate_symbol_names(void);
89
90/* parse_dump.c */
91int parse_all(void const * start, void const * end,
92 unsigned long long end_time);
93
94/* conversion.c */
95int op_jit_convert(struct op_jitdump_info file_info, char const * elffile,
96 unsigned long long start_time, unsigned long long end_time);
97
98/* create_bfd.c */
99bfd * open_elf(char const * filename);
100int partition_sections(void);
101int fill_sections(void);
102asection * create_section(bfd * abfd, char const * section_name,
103 size_t size, bfd_vma vma, flagword flags);
104int fill_section_content(bfd * abfd, asection * section,
105 void const * b, file_ptr offset, size_t sz);
106
107/* debug_line.c */
108int init_debug_line_info(bfd * abfd);
109int finalize_debug_line_info(bfd * abfd);
110
111/* jit dump header information */
112extern enum bfd_architecture dump_bfd_arch;
113extern int dump_bfd_mach;
114extern char const * dump_bfd_target_name;
115/*
116 * list head. The linked list is used during parsing (parse_all) to
117 * hold all jitentry elements. After parsing, the program works on the
118 * array structures (entries_symbols_ascending, entries_address_ascending)
119 * and the linked list is not used any more.
120 */
121extern struct jitentry * jitentry_list;
122/* count of jitentries in the list */
123extern u32 entry_count;
124/* list head for debug line information */
125extern struct jitentry_debug_line * jitentry_debug_line_list;
126/* maximum space in the entry arrays, needed to add entries */
127extern u32 max_entry_count;
128/* array pointing to all jit entries, sorted by symbol names */
129extern struct jitentry ** entries_symbols_ascending;
130/* array pointing to all jit entries sorted by address */
131extern struct jitentry ** entries_address_ascending;
132/* Global variable for asymbols so we can free the storage later. */
133extern asymbol ** syms;
134/* the bfd handle of the ELF file we write */
135extern bfd * cur_bfd;
136/* debug flag, print some information */
137extern int debug;
138
139
140#endif /* OPJITCONV_H */