@@ -627,7 +627,7 @@ static int add_jump_destinations(struct objtool_file *file)
627
627
* However this code can't completely replace the
628
628
* read_symbols() code because this doesn't detect the
629
629
* case where the parent function's only reference to a
630
- * subfunction is through a switch table.
630
+ * subfunction is through a jump table.
631
631
*/
632
632
if (!strstr (insn -> func -> name , ".cold." ) &&
633
633
strstr (insn -> jump_dest -> func -> name , ".cold." )) {
@@ -899,20 +899,24 @@ static int add_special_section_alts(struct objtool_file *file)
899
899
return ret ;
900
900
}
901
901
902
- static int add_switch_table (struct objtool_file * file , struct instruction * insn ,
902
+ static int add_jump_table (struct objtool_file * file , struct instruction * insn ,
903
903
struct rela * table , struct rela * next_table )
904
904
{
905
905
struct rela * rela = table ;
906
- struct instruction * alt_insn ;
906
+ struct instruction * dest_insn ;
907
907
struct alternative * alt ;
908
908
struct symbol * pfunc = insn -> func -> pfunc ;
909
909
unsigned int prev_offset = 0 ;
910
910
911
- list_for_each_entry_from (rela , & table -> rela_sec -> rela_list , list ) {
911
+ /*
912
+ * Each @rela is a switch table relocation which points to the target
913
+ * instruction.
914
+ */
915
+ list_for_each_entry_from (rela , & table -> sec -> rela_list , list ) {
912
916
if (rela == next_table )
913
917
break ;
914
918
915
- /* Make sure the switch table entries are consecutive: */
919
+ /* Make sure the table entries are consecutive: */
916
920
if (prev_offset && rela -> offset != prev_offset + 8 )
917
921
break ;
918
922
@@ -921,12 +925,12 @@ static int add_switch_table(struct objtool_file *file, struct instruction *insn,
921
925
rela -> addend == pfunc -> offset )
922
926
break ;
923
927
924
- alt_insn = find_insn (file , rela -> sym -> sec , rela -> addend );
925
- if (!alt_insn )
928
+ dest_insn = find_insn (file , rela -> sym -> sec , rela -> addend );
929
+ if (!dest_insn )
926
930
break ;
927
931
928
- /* Make sure the jmp dest is in the function or subfunction : */
929
- if (alt_insn -> func -> pfunc != pfunc )
932
+ /* Make sure the destination is in the same function : */
933
+ if (dest_insn -> func -> pfunc != pfunc )
930
934
break ;
931
935
932
936
alt = malloc (sizeof (* alt ));
@@ -935,7 +939,7 @@ static int add_switch_table(struct objtool_file *file, struct instruction *insn,
935
939
return -1 ;
936
940
}
937
941
938
- alt -> insn = alt_insn ;
942
+ alt -> insn = dest_insn ;
939
943
list_add_tail (& alt -> list , & insn -> alts );
940
944
prev_offset = rela -> offset ;
941
945
}
@@ -950,7 +954,7 @@ static int add_switch_table(struct objtool_file *file, struct instruction *insn,
950
954
}
951
955
952
956
/*
953
- * find_switch_table () - Given a dynamic jump, find the switch jump table in
957
+ * find_jump_table () - Given a dynamic jump, find the switch jump table in
954
958
* .rodata associated with it.
955
959
*
956
960
* There are 3 basic patterns:
@@ -992,13 +996,13 @@ static int add_switch_table(struct objtool_file *file, struct instruction *insn,
992
996
*
993
997
* NOTE: RETPOLINE made it harder still to decode dynamic jumps.
994
998
*/
995
- static struct rela * find_switch_table (struct objtool_file * file ,
999
+ static struct rela * find_jump_table (struct objtool_file * file ,
996
1000
struct symbol * func ,
997
1001
struct instruction * insn )
998
1002
{
999
- struct rela * text_rela , * rodata_rela ;
1003
+ struct rela * text_rela , * table_rela ;
1000
1004
struct instruction * orig_insn = insn ;
1001
- struct section * rodata_sec ;
1005
+ struct section * table_sec ;
1002
1006
unsigned long table_offset ;
1003
1007
1004
1008
/*
@@ -1031,7 +1035,7 @@ static struct rela *find_switch_table(struct objtool_file *file,
1031
1035
continue ;
1032
1036
1033
1037
table_offset = text_rela -> addend ;
1034
- rodata_sec = text_rela -> sym -> sec ;
1038
+ table_sec = text_rela -> sym -> sec ;
1035
1039
1036
1040
if (text_rela -> type == R_X86_64_PC32 )
1037
1041
table_offset += 4 ;
@@ -1045,29 +1049,31 @@ static struct rela *find_switch_table(struct objtool_file *file,
1045
1049
* need to be placed in the C_JUMP_TABLE_SECTION section. They
1046
1050
* have symbols associated with them.
1047
1051
*/
1048
- if (find_symbol_containing (rodata_sec , table_offset ) &&
1049
- strcmp (rodata_sec -> name , C_JUMP_TABLE_SECTION ))
1052
+ if (find_symbol_containing (table_sec , table_offset ) &&
1053
+ strcmp (table_sec -> name , C_JUMP_TABLE_SECTION ))
1050
1054
continue ;
1051
1055
1052
- rodata_rela = find_rela_by_dest (rodata_sec , table_offset );
1053
- if (rodata_rela ) {
1054
- /*
1055
- * Use of RIP-relative switch jumps is quite rare, and
1056
- * indicates a rare GCC quirk/bug which can leave dead
1057
- * code behind.
1058
- */
1059
- if (text_rela -> type == R_X86_64_PC32 )
1060
- file -> ignore_unreachables = true;
1056
+ /* Each table entry has a rela associated with it. */
1057
+ table_rela = find_rela_by_dest (table_sec , table_offset );
1058
+ if (!table_rela )
1059
+ continue ;
1061
1060
1062
- return rodata_rela ;
1063
- }
1061
+ /*
1062
+ * Use of RIP-relative switch jumps is quite rare, and
1063
+ * indicates a rare GCC quirk/bug which can leave dead code
1064
+ * behind.
1065
+ */
1066
+ if (text_rela -> type == R_X86_64_PC32 )
1067
+ file -> ignore_unreachables = true;
1068
+
1069
+ return table_rela ;
1064
1070
}
1065
1071
1066
1072
return NULL ;
1067
1073
}
1068
1074
1069
1075
1070
- static int add_func_switch_tables (struct objtool_file * file ,
1076
+ static int add_func_jump_tables (struct objtool_file * file ,
1071
1077
struct symbol * func )
1072
1078
{
1073
1079
struct instruction * insn , * last = NULL , * prev_jump = NULL ;
@@ -1080,7 +1086,7 @@ static int add_func_switch_tables(struct objtool_file *file,
1080
1086
1081
1087
/*
1082
1088
* Store back-pointers for unconditional forward jumps such
1083
- * that find_switch_table () can back-track using those and
1089
+ * that find_jump_table () can back-track using those and
1084
1090
* avoid some potentially confusing code.
1085
1091
*/
1086
1092
if (insn -> type == INSN_JUMP_UNCONDITIONAL && insn -> jump_dest &&
@@ -1095,17 +1101,17 @@ static int add_func_switch_tables(struct objtool_file *file,
1095
1101
if (insn -> type != INSN_JUMP_DYNAMIC )
1096
1102
continue ;
1097
1103
1098
- rela = find_switch_table (file , func , insn );
1104
+ rela = find_jump_table (file , func , insn );
1099
1105
if (!rela )
1100
1106
continue ;
1101
1107
1102
1108
/*
1103
- * We found a switch table, but we don't know yet how big it
1109
+ * We found a jump table, but we don't know yet how big it
1104
1110
* is. Don't add it until we reach the end of the function or
1105
- * the beginning of another switch table in the same function.
1111
+ * the beginning of another jump table in the same function.
1106
1112
*/
1107
1113
if (prev_jump ) {
1108
- ret = add_switch_table (file , prev_jump , prev_rela , rela );
1114
+ ret = add_jump_table (file , prev_jump , prev_rela , rela );
1109
1115
if (ret )
1110
1116
return ret ;
1111
1117
}
@@ -1115,7 +1121,7 @@ static int add_func_switch_tables(struct objtool_file *file,
1115
1121
}
1116
1122
1117
1123
if (prev_jump ) {
1118
- ret = add_switch_table (file , prev_jump , prev_rela , NULL );
1124
+ ret = add_jump_table (file , prev_jump , prev_rela , NULL );
1119
1125
if (ret )
1120
1126
return ret ;
1121
1127
}
@@ -1128,7 +1134,7 @@ static int add_func_switch_tables(struct objtool_file *file,
1128
1134
* section which contains a list of addresses within the function to jump to.
1129
1135
* This finds these jump tables and adds them to the insn->alts lists.
1130
1136
*/
1131
- static int add_switch_table_alts (struct objtool_file * file )
1137
+ static int add_jump_table_alts (struct objtool_file * file )
1132
1138
{
1133
1139
struct section * sec ;
1134
1140
struct symbol * func ;
@@ -1142,7 +1148,7 @@ static int add_switch_table_alts(struct objtool_file *file)
1142
1148
if (func -> type != STT_FUNC )
1143
1149
continue ;
1144
1150
1145
- ret = add_func_switch_tables (file , func );
1151
+ ret = add_func_jump_tables (file , func );
1146
1152
if (ret )
1147
1153
return ret ;
1148
1154
}
@@ -1339,7 +1345,7 @@ static int decode_sections(struct objtool_file *file)
1339
1345
if (ret )
1340
1346
return ret ;
1341
1347
1342
- ret = add_switch_table_alts (file );
1348
+ ret = add_jump_table_alts (file );
1343
1349
if (ret )
1344
1350
return ret ;
1345
1351
0 commit comments