Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CFI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source Software
CFI
Commits
12eb2b57
Commit
12eb2b57
authored
9 years ago
by
an7s
Browse files
Options
Downloads
Patches
Plain Diff
More attributes output
parent
a12fd573
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
color_map.cpp
+5
-2
5 additions, 2 deletions
color_map.cpp
scfi_instr.cpp
+81
-1
81 additions, 1 deletion
scfi_instr.cpp
with
86 additions
and
3 deletions
color_map.cpp
+
5
−
2
View file @
12eb2b57
...
...
@@ -72,11 +72,14 @@ bool ColoredInstructionNonces_t::create()
}
// output stats
cout
<<
"#ATTRIBUTE slots_used="
<<
slots_used
.
size
()
<<
endl
;
cout
<<
"# ATTRIBUTE slots_used="
<<
slots_used
.
size
()
<<
endl
;
int
total_slots
=
0
;
for
(
int
slot_no
=
0
;
slot_no
<
slots_used
.
size
();
slot_no
++
)
{
cout
<<
"#ATTRIBUTE used_slot"
<<
slot_no
<<
"="
<<
slots_used
[
slot_no
].
SlotsUsed
()
<<
endl
;
cout
<<
"# ATTRIBUTE used_slot"
<<
slot_no
<<
"="
<<
slots_used
[
slot_no
].
SlotsUsed
()
<<
endl
;
total_slots
+=
slots_used
[
slot_no
].
SlotsUsed
();
}
cout
<<
"# ATTRIBUTE total_slots="
<<
total_slots
<<
endl
;
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
scfi_instr.cpp
+
81
−
1
View file @
12eb2b57
...
...
@@ -25,6 +25,7 @@
#include
"color_map.hpp"
#include
<stdlib.h>
#include
<memory>
#include
<math.h>
...
...
@@ -471,7 +472,7 @@ void SCFI_Instrument::AddReturnCFI(Instruction_t* insn, ColoredSlotValue_t *v)
if
(
d
.
Argument1
.
ArgType
!=
NO_ARGUMENT
)
{
unsigned
int
sp_adjust
=
d
.
Instruction
.
Immediat
-
firp
->
GetArchitectureBitWidth
()
/
8
;
cout
<<
"Found relat
e
ively rare ret_with_pop insn: "
<<
d
.
CompleteInstr
<<
endl
;
cout
<<
"Found relatively rare ret_with_pop insn: "
<<
d
.
CompleteInstr
<<
endl
;
char
buf
[
30
];
sprintf
(
buf
,
"pop %s [%s+%d]"
,
worddec
.
c_str
(),
rspreg
.
c_str
(),
sp_adjust
);
Instruction_t
*
newafter
=
insertAssemblyBefore
(
firp
,
insn
,
buf
);
...
...
@@ -562,9 +563,42 @@ void SCFI_Instrument::AddReturnCFI(Instruction_t* insn, ColoredSlotValue_t *v)
#endif
}
static
void
display_histogram
(
std
::
ostream
&
out
,
std
::
string
attr_label
,
std
::
map
<
int
,
int
>
&
p_map
)
{
if
(
p_map
.
size
())
{
out
<<
"# ATTRIBUTE "
<<
attr_label
<<
"="
;
out
<<
"{ibt_size:count,"
;
bool
first_time
=
true
;
for
(
map
<
int
,
int
>::
iterator
it
=
p_map
.
begin
();
it
!=
p_map
.
end
();
++
it
)
{
if
(
!
first_time
)
out
<<
","
;
out
<<
it
->
first
<<
":"
<<
it
->
second
;
first_time
=
false
;
}
out
<<
"}"
<<
endl
;
}
}
bool
SCFI_Instrument
::
instrument_jumps
()
{
int
cfi_checks
=
0
;
int
cfi_branch_jmp_checks
=
0
;
int
cfi_branch_jmp_complete
=
0
;
int
cfi_branch_call_checks
=
0
;
int
cfi_branch_call_complete
=
0
;
int
cfi_branch_ret_checks
=
0
;
int
cfi_branch_ret_complete
=
0
;
int
ibt_complete
=
0
;
double
cfi_branch_jmp_complete_ratio
=
NAN
;
double
cfi_branch_ret_complete_ratio
=
NAN
;
std
::
map
<
int
,
int
>
jmps
;
std
::
map
<
int
,
int
>
rets
;
// build histogram of target sizes
// for each instruction
for
(
InstructionSet_t
::
iterator
it
=
firp
->
GetInstructions
().
begin
();
...
...
@@ -590,6 +624,12 @@ bool SCFI_Instrument::instrument_jumps()
if
((
d
.
Argument1
.
ArgType
&
MEMORY_TYPE
)
==
MEMORY_TYPE
)
{
cfi_checks
++
;
cfi_branch_jmp_checks
++
;
if
(
insn
->
GetIBTargets
()
&&
insn
->
GetIBTargets
()
->
IsComplete
())
{
cfi_branch_jmp_complete
++
;
jmps
[
insn
->
GetIBTargets
()
->
size
()]
++
;
}
AddJumpCFI
(
insn
);
}
break
;
...
...
@@ -599,9 +639,19 @@ bool SCFI_Instrument::instrument_jumps()
{
// not yet implemented.
assert
(
0
);
// fix calls should conver these to jumps
cfi_branch_call_checks
++
;
if
(
insn
->
GetIBTargets
()
&&
insn
->
GetIBTargets
()
->
IsComplete
())
cfi_branch_call_complete
++
;
cfi_checks
++
;
}
break
;
case
RetType
:
cfi_branch_ret_checks
++
;
if
(
insn
->
GetIBTargets
()
&&
insn
->
GetIBTargets
()
->
IsComplete
())
{
cfi_branch_ret_complete
++
;
rets
[
insn
->
GetIBTargets
()
->
size
()]
++
;
}
cfi_checks
++
;
AddReturnCFI
(
insn
);
break
;
...
...
@@ -611,9 +661,39 @@ bool SCFI_Instrument::instrument_jumps()
}
}
cout
<<
"# ATTRIBUTE cfi_jmp_checks="
<<
std
::
dec
<<
cfi_branch_jmp_checks
<<
endl
;
cout
<<
"# ATTRIBUTE cfi_jmp_complete="
<<
std
::
dec
<<
cfi_branch_jmp_complete
<<
endl
;
display_histogram
(
cout
,
"cfi_jmp_complete_histogram"
,
jmps
);
/*
cout<<"# ATTRIBUTE cfi_branch_call_checks="<<std::dec<<cfi_branch_call_checks<<endl;
cout<<"# ATTRIBUTE cfi_branch_call_complete="<<std::dec<<cfi_branch_call_complete<<endl;
*/
cout
<<
"# ATTRIBUTE cfi_ret_checks="
<<
std
::
dec
<<
cfi_branch_ret_checks
<<
endl
;
cout
<<
"# ATTRIBUTE cfi_ret_complete="
<<
std
::
dec
<<
cfi_branch_ret_complete
<<
endl
;
display_histogram
(
cout
,
"cfi_ret_complete_histogram"
,
rets
);
cout
<<
"# ATTRIBUTE cfi_checks="
<<
std
::
dec
<<
cfi_checks
<<
endl
;
ibt_complete
=
cfi_branch_jmp_complete
+
cfi_branch_call_complete
+
cfi_branch_ret_complete
;
cout
<<
"# ATTRIBUTE ibt_complete="
<<
std
::
dec
<<
ibt_complete
<<
endl
;
if
(
cfi_branch_jmp_checks
>
0
)
cfi_branch_jmp_complete_ratio
=
(
double
)
cfi_branch_jmp_complete
/
cfi_branch_jmp_checks
;
if
(
cfi_branch_ret_checks
>
0
)
cfi_branch_ret_complete_ratio
=
(
double
)
cfi_branch_ret_complete
/
cfi_branch_ret_checks
;
double
cfi_branch_complete_ratio
=
NAN
;
if
(
ibt_complete
>
0
)
cfi_branch_complete_ratio
=
(
double
)
cfi_checks
/
ibt_complete
;
cout
<<
"# ATTRIBUTE cfi_jmp_complete_ratio="
<<
cfi_branch_jmp_complete_ratio
<<
endl
;
cout
<<
"# ATTRIBUTE cfi_ret_complete_ratio="
<<
cfi_branch_ret_complete_ratio
<<
endl
;
cout
<<
"# ATTRIBUTE cfi_complete_ratio="
<<
cfi_branch_ret_complete_ratio
<<
endl
;
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment