Skip to content

Commit 51ca278

Browse files
PhazonicRidleyDinoKengi
authored andcommitted
✨ Gcc callgraph generation base (#30)
* Created POC GCC IPA callgraph parser Script is designed for testing and workshopping. Script is written in python and documented on how it works * 👷 Added debugging settings and defaulted to Debug builds * ❇️ Started to port the parsing code for gcc No API yet
1 parent 58f4d82 commit 51ca278

File tree

16 files changed

+740
-7
lines changed

16 files changed

+740
-7
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ SpacesBeforeTrailingComments: 2
99
ColumnLimit: 80
1010
IndentWidth: 4
1111
TabWidth: 4
12+
AlignOperands: Align
13+
BreakBeforeBinaryOperators: All

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,4 @@ build/
180180
.html/
181181
.latex/
182182

183+
out/

CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ set(CMAKE_CXX_STANDARD 23)
44
set(CMAKE_CXX_STANDARD_REQUIRED ON)
55
set(CMAKE_CXX_EXTENSIONS OFF) # Ensure only standard C++ features
66

7-
# TODO: Maybe get rid of? Don't remember why its here and I think libhal's cmake utils handles this
8-
# set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
9-
# add_custom_target(copy_compile_commands ALL
10-
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
11-
# ${CMAKE_BINARY_DIR}/compile_commands.json
12-
# ${CMAKE_SOURCE_DIR}/compile_commands.json
13-
# DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json)
7+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
8+
9+
find_package(ctre REQUIRED)
10+
11+
1412

1513
# Find package dependancies
1614
#TODO: Remove due to this being a temporary patch for libraries to work
@@ -26,6 +24,11 @@ target_link_libraries(${PROJECT_NAME} libelf::libelf)
2624

2725
#Linking Libraries
2826
target_link_libraries(${PROJECT_NAME} libelf::libelf)
27+
add_executable(${PROJECT_NAME} src/main.cpp src/gcc_parse.cpp)
28+
29+
# Add include directories
30+
target_include_directories(${PROJECT_NAME} PUBLIC include/)
31+
target_link_libraries(${PROJECT_NAME} PUBLIC ctre::ctre)
2932

3033
# Add compile options
3134
list(APPEND COMPILER_BUILD_FLAGS

conanfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def _min_cppstd(self) -> str:
2828
"""
2929
def requirements(self):
3030
self.requires("tl-function-ref/1.0.0")
31+
self.requires("ctre/[^3.9.0]")
3132

3233
def generate(self):
3334
c = CMake(self)

demo_class.wpa.081i.whole-program

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
Marking local functions: method/0
3+
4+
5+
Marking externally visible functions: main/6 foo/2 bar/1
6+
7+
8+
Marking externally visible variables:
9+
10+
11+
Reclaiming functions:
12+
Reclaiming variables:
13+
Clearing address taken flags:
14+
Symbol table:
15+
16+
__builtin_eh_pointer/10 (__builtin_eh_pointer)
17+
Type: function
18+
Visibility: semantic_interposition external public visibility_specified artificial
19+
References:
20+
Referring:
21+
Availability: not_available
22+
Unit id: 1
23+
Function flags:
24+
Called by: main/6
25+
Calls:
26+
__cxa_begin_catch/11 (__cxa_begin_catch)
27+
Type: function
28+
Visibility: semantic_interposition external public visibility_specified artificial
29+
References:
30+
Referring:
31+
Availability: not_available
32+
Unit id: 1
33+
Function flags:
34+
Called by: main/6
35+
Calls:
36+
__cxa_end_catch/12 (__cxa_end_catch)
37+
Type: function
38+
Visibility: semantic_interposition external public visibility_specified artificial
39+
References:
40+
Referring:
41+
Availability: not_available
42+
Unit id: 1
43+
Function flags:
44+
Called by: main/6
45+
Calls:
46+
__cxa_allocate_exception/7 (__cxa_allocate_exception)
47+
Type: function
48+
Visibility: semantic_interposition external public visibility_specified artificial
49+
References:
50+
Referring:
51+
Availability: not_available
52+
Unit id: 1
53+
Function flags: decl_is_malloc
54+
Called by: _Z3barv/1
55+
Calls:
56+
__cxa_throw/8 (__cxa_throw)
57+
Type: function
58+
Visibility: semantic_interposition external public visibility_specified artificial
59+
References:
60+
Referring:
61+
Availability: not_available
62+
Unit id: 1
63+
Function flags:
64+
Called by: _Z3barv/1 (can throw external)
65+
Calls:
66+
__gxx_personality_v0/13 (__gxx_personality_v0)
67+
Type: function
68+
Visibility: semantic_interposition external public artificial
69+
Address is taken.
70+
References:
71+
Referring: main/6 (addr)
72+
Availability: not_available
73+
Unit id: 1
74+
Function flags:
75+
Called by:
76+
Calls:
77+
main/6 (main)
78+
Type: function definition analyzed
79+
Visibility: force_output externally_visible semantic_interposition no_reorder public
80+
References: __gxx_personality_v0/13 (addr)
81+
Referring:
82+
Read from file: /private/tmp/nix-shell-14976-0/cceFgUpS.o
83+
Availability: available
84+
Unit id: 1
85+
Function flags:
86+
Called by:
87+
Calls: __cxa_end_catch/12 __cxa_begin_catch/11 __builtin_eh_pointer/10 _Z3foov/2 _ZN1A6methodEv/0
88+
_Z3foov/2 (foo)
89+
Type: function definition analyzed
90+
Visibility: force_output externally_visible semantic_interposition no_reorder public
91+
References:
92+
Referring:
93+
Read from file: /private/tmp/nix-shell-14976-0/cceFgUpS.o
94+
Availability: available
95+
Unit id: 1
96+
Function flags:
97+
Called by: main/6
98+
Calls: _Z3barv/1 (can throw external)
99+
_ZTIi/9 (_ZTIi)
100+
Type: variable
101+
Body removed by symtab_remove_unreachable_nodes
102+
Visibility: semantic_interposition external public artificial
103+
References:
104+
Referring: _Z3barv/1 (addr)
105+
Read from file: /private/tmp/nix-shell-14976-0/cceFgUpS.o
106+
Availability: not_available
107+
Varpool flags: read-only
108+
_Z3barv/1 (bar)
109+
Type: function definition analyzed
110+
Visibility: force_output externally_visible semantic_interposition no_reorder public
111+
References: _ZTIi/9 (addr)
112+
Referring:
113+
Read from file: /private/tmp/nix-shell-14976-0/cceFgUpS.o
114+
Availability: available
115+
Unit id: 1
116+
Function flags:
117+
Called by: _Z3foov/2 (can throw external)
118+
Calls: __cxa_throw/8 (can throw external) __cxa_allocate_exception/7
119+
_ZN1A6methodEv/0 (method)
120+
Type: function definition analyzed
121+
Visibility: semantic_interposition no_reorder prevailing_def_ironly
122+
References:
123+
Referring:
124+
Read from file: /private/tmp/nix-shell-14976-0/cceFgUpS.o
125+
Availability: local
126+
Unit id: 1
127+
Function flags: local
128+
Called by: main/6
129+
Calls:

include/gcc_parse.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include <algorithm>
3+
#include <cctype>
4+
#include <cstddef>
5+
#include <ctll/fixed_string.hpp>
6+
#include <ctre.hpp>
7+
#include <ctre/wrapper.hpp>
8+
#include <ranges>
9+
#include <string>
10+
11+
namespace rng = std::ranges;
12+
namespace views = rng::views;
13+
14+
using string = std::string;
15+
using std::operator""sv;
16+
17+
struct Node;
18+
19+
void parse(std::string file_path);
20+
21+
constexpr bool is_word_in_str(std::string_view const word,
22+
std::string_view const full_str)
23+
{
24+
constexpr auto pattern = ctll::fixed_string{ "\\n| |\\t" };
25+
return rng::any_of(ctre::split<pattern>(full_str),
26+
[word](auto&& c) { return word == c; });
27+
}

0 commit comments

Comments
 (0)