diff options
author | Sam Ravnborg <sam@ravnborg.org> | 2007-06-02 15:18:51 -0400 |
---|---|---|
committer | Sam Ravnborg <sam@ravnborg.org> | 2007-07-16 17:21:34 -0400 |
commit | 1087247b7d8f1938425906d2ac983df76c6dcc18 (patch) | |
tree | bfd2bfb82a68de0f74fa429258e8f7a233026df0 /scripts/mod | |
parent | b28242e7e3c08072251da6d7bc4895fbd3e58299 (diff) |
kbuild: refactor code in modpost to improve maintainability
There were a great deal of overlap between the two functions
that check which sections may reference .init.text and .exit.text.
Factor out common check to a separate function and
sort entries in the original functions.
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/mod')
-rw-r--r-- | scripts/mod/modpost.c | 154 |
1 files changed, 75 insertions, 79 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 9c35f30d2eda..f22c8b4911bc 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -858,14 +858,6 @@ static void warn_sec_mismatch(const char *modname, const char *fromsec, | |||
858 | elf->strtab + before->st_name, refsymname)) | 858 | elf->strtab + before->st_name, refsymname)) |
859 | return; | 859 | return; |
860 | 860 | ||
861 | /* fromsec whitelist - without a valid 'before' | ||
862 | * powerpc has a GOT table in .got2 section | ||
863 | * and also a .toc section */ | ||
864 | if (strcmp(fromsec, ".got2") == 0) | ||
865 | return; | ||
866 | if (strcmp(fromsec, ".toc") == 0) | ||
867 | return; | ||
868 | |||
869 | if (before && after) { | 861 | if (before && after) { |
870 | warn("%s(%s+0x%llx): Section mismatch: reference to %s:%s " | 862 | warn("%s(%s+0x%llx): Section mismatch: reference to %s:%s " |
871 | "(between '%s' and '%s')\n", | 863 | "(between '%s' and '%s')\n", |
@@ -1087,6 +1079,61 @@ static void check_sec_ref(struct module *mod, const char *modname, | |||
1087 | } | 1079 | } |
1088 | } | 1080 | } |
1089 | 1081 | ||
1082 | /* | ||
1083 | * Identify sections from which references to either a | ||
1084 | * .init or a .exit section is OK. | ||
1085 | * | ||
1086 | * [OPD] Keith Ownes <kaos@sgi.com> commented: | ||
1087 | * For our future {in}sanity, add a comment that this is the ppc .opd | ||
1088 | * section, not the ia64 .opd section. | ||
1089 | * ia64 .opd should not point to discarded sections. | ||
1090 | * [.rodata] like for .init.text we ignore .rodata references -same reason | ||
1091 | **/ | ||
1092 | static int initexit_section_ref_ok(const char *name) | ||
1093 | { | ||
1094 | const char **s; | ||
1095 | /* Absolute section names */ | ||
1096 | const char *namelist1[] = { | ||
1097 | "__bug_table", /* used by powerpc for BUG() */ | ||
1098 | "__ex_table", | ||
1099 | ".altinstructions", | ||
1100 | ".cranges", /* used by sh64 */ | ||
1101 | ".fixup", | ||
1102 | ".opd", /* See comment [OPD] */ | ||
1103 | ".parainstructions", | ||
1104 | ".pdr", | ||
1105 | ".plt", /* seen on ARCH=um build on x86_64. Harmless */ | ||
1106 | ".smp_locks", | ||
1107 | ".stab", | ||
1108 | NULL | ||
1109 | }; | ||
1110 | /* Start of section names */ | ||
1111 | const char *namelist2[] = { | ||
1112 | ".debug", | ||
1113 | ".eh_frame", | ||
1114 | ".note", /* ignore ELF notes - may contain anything */ | ||
1115 | ".got", /* powerpc - global offset table */ | ||
1116 | ".toc", /* powerpc - table of contents */ | ||
1117 | NULL | ||
1118 | }; | ||
1119 | /* part of section name */ | ||
1120 | const char *namelist3 [] = { | ||
1121 | ".unwind", /* Sample: IA_64.unwind.exit.text */ | ||
1122 | NULL | ||
1123 | }; | ||
1124 | |||
1125 | for (s = namelist1; *s; s++) | ||
1126 | if (strcmp(*s, name) == 0) | ||
1127 | return 1; | ||
1128 | for (s = namelist2; *s; s++) | ||
1129 | if (strncmp(*s, name, strlen(*s)) == 0) | ||
1130 | return 1; | ||
1131 | for (s = namelist3; *s; s++) | ||
1132 | if (strstr(name, *s) != NULL) | ||
1133 | return 1; | ||
1134 | return 0; | ||
1135 | } | ||
1136 | |||
1090 | /** | 1137 | /** |
1091 | * Functions used only during module init is marked __init and is stored in | 1138 | * Functions used only during module init is marked __init and is stored in |
1092 | * a .init.text section. Likewise data is marked __initdata and stored in | 1139 | * a .init.text section. Likewise data is marked __initdata and stored in |
@@ -1103,7 +1150,7 @@ static int init_section(const char *name) | |||
1103 | return 0; | 1150 | return 0; |
1104 | } | 1151 | } |
1105 | 1152 | ||
1106 | /** | 1153 | /* |
1107 | * Identify sections from which references to a .init section is OK. | 1154 | * Identify sections from which references to a .init section is OK. |
1108 | * | 1155 | * |
1109 | * Unfortunately references to read only data that referenced .init | 1156 | * Unfortunately references to read only data that referenced .init |
@@ -1117,59 +1164,41 @@ static int init_section(const char *name) | |||
1117 | * | 1164 | * |
1118 | * where vgacon_startup is __init. If you want to wade through the false | 1165 | * where vgacon_startup is __init. If you want to wade through the false |
1119 | * positives, take out the check for rodata. | 1166 | * positives, take out the check for rodata. |
1120 | **/ | 1167 | */ |
1121 | static int init_section_ref_ok(const char *name) | 1168 | static int init_section_ref_ok(const char *name) |
1122 | { | 1169 | { |
1123 | const char **s; | 1170 | const char **s; |
1124 | /* Absolute section names */ | 1171 | /* Absolute section names */ |
1125 | const char *namelist1[] = { | 1172 | const char *namelist1[] = { |
1126 | ".init", | ||
1127 | ".opd", /* see comment [OPD] at exit_section_ref_ok() */ | ||
1128 | ".toc1", /* used by ppc64 */ | ||
1129 | ".stab", | ||
1130 | ".data.rel.ro", /* used by parisc64 */ | ||
1131 | ".parainstructions", | ||
1132 | ".text.lock", | ||
1133 | "__bug_table", /* used by powerpc for BUG() */ | ||
1134 | ".pci_fixup_header", | ||
1135 | ".pci_fixup_final", | ||
1136 | ".pdr", | ||
1137 | "__param", | ||
1138 | "__ex_table", | ||
1139 | ".fixup", | ||
1140 | ".smp_locks", | ||
1141 | ".plt", /* seen on ARCH=um build on x86_64. Harmless */ | ||
1142 | "__ftr_fixup", /* powerpc cpu feature fixup */ | 1173 | "__ftr_fixup", /* powerpc cpu feature fixup */ |
1143 | "__fw_ftr_fixup", /* powerpc firmware feature fixup */ | 1174 | "__fw_ftr_fixup", /* powerpc firmware feature fixup */ |
1144 | ".cranges", /* used by sh64 */ | 1175 | "__param", |
1176 | ".data.rel.ro", /* used by parisc64 */ | ||
1177 | ".init", | ||
1178 | ".text.lock", | ||
1145 | NULL | 1179 | NULL |
1146 | }; | 1180 | }; |
1147 | /* Start of section names */ | 1181 | /* Start of section names */ |
1148 | const char *namelist2[] = { | 1182 | const char *namelist2[] = { |
1149 | ".init.", | 1183 | ".init.", |
1150 | ".altinstructions", | 1184 | ".pci_fixup", |
1151 | ".eh_frame", | ||
1152 | ".debug", | ||
1153 | ".parainstructions", | ||
1154 | ".rodata", | 1185 | ".rodata", |
1155 | ".note", /* ignore ELF notes - may contain anything */ | ||
1156 | NULL | ||
1157 | }; | ||
1158 | /* part of section name */ | ||
1159 | const char *namelist3 [] = { | ||
1160 | ".unwind", /* sample: IA_64.unwind.init.text */ | ||
1161 | NULL | 1186 | NULL |
1162 | }; | 1187 | }; |
1163 | 1188 | ||
1189 | if (initexit_section_ref_ok(name)) | ||
1190 | return 1; | ||
1191 | |||
1164 | for (s = namelist1; *s; s++) | 1192 | for (s = namelist1; *s; s++) |
1165 | if (strcmp(*s, name) == 0) | 1193 | if (strcmp(*s, name) == 0) |
1166 | return 1; | 1194 | return 1; |
1167 | for (s = namelist2; *s; s++) | 1195 | for (s = namelist2; *s; s++) |
1168 | if (strncmp(*s, name, strlen(*s)) == 0) | 1196 | if (strncmp(*s, name, strlen(*s)) == 0) |
1169 | return 1; | 1197 | return 1; |
1170 | for (s = namelist3; *s; s++) | 1198 | |
1171 | if (strstr(name, *s) != NULL) | 1199 | /* If section name ends with ".init" we allow references |
1172 | return 1; | 1200 | * as is the case with .initcallN.init, .early_param.init, .taglist.init etc |
1201 | */ | ||
1173 | if (strrcmp(name, ".init") == 0) | 1202 | if (strrcmp(name, ".init") == 0) |
1174 | return 1; | 1203 | return 1; |
1175 | return 0; | 1204 | return 0; |
@@ -1194,59 +1223,26 @@ static int exit_section(const char *name) | |||
1194 | 1223 | ||
1195 | /* | 1224 | /* |
1196 | * Identify sections from which references to a .exit section is OK. | 1225 | * Identify sections from which references to a .exit section is OK. |
1197 | * | 1226 | */ |
1198 | * [OPD] Keith Ownes <kaos@sgi.com> commented: | ||
1199 | * For our future {in}sanity, add a comment that this is the ppc .opd | ||
1200 | * section, not the ia64 .opd section. | ||
1201 | * ia64 .opd should not point to discarded sections. | ||
1202 | * [.rodata] like for .init.text we ignore .rodata references -same reason | ||
1203 | **/ | ||
1204 | static int exit_section_ref_ok(const char *name) | 1227 | static int exit_section_ref_ok(const char *name) |
1205 | { | 1228 | { |
1206 | const char **s; | 1229 | const char **s; |
1207 | /* Absolute section names */ | 1230 | /* Absolute section names */ |
1208 | const char *namelist1[] = { | 1231 | const char *namelist1[] = { |
1209 | ".exit.text", | ||
1210 | ".exit.data", | 1232 | ".exit.data", |
1233 | ".exit.text", | ||
1234 | ".exitcall.exit", | ||
1211 | ".init.text", | 1235 | ".init.text", |
1212 | ".rodata", | 1236 | ".rodata", |
1213 | ".opd", /* See comment [OPD] */ | ||
1214 | ".toc1", /* used by ppc64 */ | ||
1215 | ".altinstructions", | ||
1216 | ".pdr", | ||
1217 | "__bug_table", /* used by powerpc for BUG() */ | ||
1218 | ".exitcall.exit", | ||
1219 | ".eh_frame", | ||
1220 | ".parainstructions", | ||
1221 | ".stab", | ||
1222 | "__ex_table", | ||
1223 | ".fixup", | ||
1224 | ".smp_locks", | ||
1225 | ".plt", /* seen on ARCH=um build on x86_64. Harmless */ | ||
1226 | ".cranges", /* used by sh64 */ | ||
1227 | NULL | ||
1228 | }; | ||
1229 | /* Start of section names */ | ||
1230 | const char *namelist2[] = { | ||
1231 | ".debug", | ||
1232 | ".note", /* ignore ELF notes - may contain anything */ | ||
1233 | NULL | ||
1234 | }; | ||
1235 | /* part of section name */ | ||
1236 | const char *namelist3 [] = { | ||
1237 | ".unwind", /* Sample: IA_64.unwind.exit.text */ | ||
1238 | NULL | 1237 | NULL |
1239 | }; | 1238 | }; |
1240 | 1239 | ||
1240 | if (initexit_section_ref_ok(name)) | ||
1241 | return 1; | ||
1242 | |||
1241 | for (s = namelist1; *s; s++) | 1243 | for (s = namelist1; *s; s++) |
1242 | if (strcmp(*s, name) == 0) | 1244 | if (strcmp(*s, name) == 0) |
1243 | return 1; | 1245 | return 1; |
1244 | for (s = namelist2; *s; s++) | ||
1245 | if (strncmp(*s, name, strlen(*s)) == 0) | ||
1246 | return 1; | ||
1247 | for (s = namelist3; *s; s++) | ||
1248 | if (strstr(name, *s) != NULL) | ||
1249 | return 1; | ||
1250 | return 0; | 1246 | return 0; |
1251 | } | 1247 | } |
1252 | 1248 | ||