HPCToolkit
arm-process-ranges.cpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 /******************************************************************************
48  * system include files
49  *****************************************************************************/
50 
51 
52 #include <stdio.h>
53 #include <assert.h>
54 #include <string>
55 
56 
57 
58 /******************************************************************************
59  * include files
60  *****************************************************************************/
61 
62 #include "code-ranges.h"
63 #include "function-entries.h"
64 #include "process-ranges.h"
65 #include "sections.h"
66 
67 #include <include/hpctoolkit-config.h>
68 
69 
70 
71 /******************************************************************************
72  * macros
73  *****************************************************************************/
74 
75 const uint32_t ADRP_MASK = 0x9f000000;
76 const uint32_t BR_MASK = 0xfffffc1f;
77 
78 const uint32_t BR_OPCODE = 0xd61f0000;
79 const uint32_t ADRP_OPCODE = 0x90000000;
80 
81 
82 
83 /******************************************************************************
84  * type declarations
85  *****************************************************************************/
86 
87 typedef enum arm_state_e {
90 } arm_state_t;
91 
92 
93 
94 /******************************************************************************
95  * forward declarations
96  *****************************************************************************/
97 
98 #define RELOCATE(u, offset) (((char *) (u)) + (offset))
99 
100 
101 /******************************************************************************
102  * local variables
103  *****************************************************************************/
104 
106 
107 
108 
109 /******************************************************************************
110  * private operations
111  *****************************************************************************/
112 
113 static inline bool
114 isInsn_BR(uint32_t insn)
115 {
116  return ((insn & BR_MASK) == BR_OPCODE);
117 }
118 
119 
120 static inline bool
121 isInsn_ADRP(uint32_t insn)
122 {
123  return ((insn & ADRP_MASK) == ADRP_OPCODE);
124 }
125 
126 
127 
128 /******************************************************************************
129  * interface operations
130  *****************************************************************************/
131 
132 void
134 {
135 }
136 
137 
138 void
139 process_range(const char *name, long offset, void *vstart, void *vend, DiscoverFnTy fn_discovery)
140 {
141  if (name != SECTION_PLT || fn_discovery == DiscoverFnTy_None) {
142  return;
143  }
144 
145  uint32_t *ins = (uint32_t *) vstart;
146  uint32_t *end = (uint32_t *) vend;
147 
148  //----------------------------------------------------------------------------
149  // lightweight analysis for PLT section
150  //
151  // assumptions:
152  // - each PLT entry ends with BR - branch to register
153  // - all but the first begin with ADRP
154  //
155  // approach:
156  // - treat a PLT each ADRP other than those in
157  // the first PLT stub as the beginning of a function
158  //----------------------------------------------------------------------------
159  for (; ins < end; ins++) {
160  if (isInsn_BR(*ins)) {
162  } else if (isInsn_ADRP(*ins)) {
163  if (state == ARM_STATE_BR_SEEN) {
164  uint32_t *ins_vaddr = (uint32_t *) RELOCATE(ins, offset);
165  add_function_entry(ins_vaddr, NULL, true /* isvisible */, 0);
166  }
168  }
169  }
170 }
171 
172 
173 
174 bool
175 range_contains_control_flow(void *vstart, void *vend)
176 {
177  return true;
178 }
#define RELOCATE(u, offset)
const uint32_t BR_MASK
const uint32_t ADRP_OPCODE
void process_range_init(void)
enum arm_state_e arm_state_t
static bool isInsn_BR(uint32_t insn)
static bool isInsn_ADRP(uint32_t insn)
const char * SECTION_PLT
Definition: sections.cpp:59
const uint32_t BR_OPCODE
void add_function_entry(void *addr, const string *comment, bool isvisible, int call_count)
DiscoverFnTy
Definition: code-ranges.h:52
bool range_contains_control_flow(void *vstart, void *vend)
#define NULL
Definition: ElfHelper.cpp:85
void process_range(const char *name, long offset, void *vstart, void *vend, DiscoverFnTy fn_discovery)
static arm_state_t state
const uint32_t ADRP_MASK