@@ -1238,42 +1238,6 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
12381238 return near ;
12391239}
12401240
1241- /*
1242- * Convert a section name to the function/data attribute
1243- * .init.text => __init
1244- * .memexitconst => __memconst
1245- * etc.
1246- *
1247- * The memory of returned value has been allocated on a heap. The user of this
1248- * method should free it after usage.
1249- */
1250- static char * sec2annotation (const char * s )
1251- {
1252- if (match (s , init_exit_sections )) {
1253- char * p = NOFAIL (malloc (20 ));
1254- char * r = p ;
1255-
1256- * p ++ = '_' ;
1257- * p ++ = '_' ;
1258- if (* s == '.' )
1259- s ++ ;
1260- while (* s && * s != '.' )
1261- * p ++ = * s ++ ;
1262- * p = '\0' ;
1263- if (* s == '.' )
1264- s ++ ;
1265- if (strstr (s , "rodata" ) != NULL )
1266- strcat (p , "const " );
1267- else if (strstr (s , "data" ) != NULL )
1268- strcat (p , "data " );
1269- else
1270- strcat (p , " " );
1271- return r ;
1272- } else {
1273- return NOFAIL (strdup ("" ));
1274- }
1275- }
1276-
12771241static int is_function (Elf_Sym * sym )
12781242{
12791243 if (sym )
@@ -1282,19 +1246,6 @@ static int is_function(Elf_Sym *sym)
12821246 return -1 ;
12831247}
12841248
1285- static void print_section_list (const char * const list [20 ])
1286- {
1287- const char * const * s = list ;
1288-
1289- while (* s ) {
1290- fprintf (stderr , "%s" , * s );
1291- s ++ ;
1292- if (* s )
1293- fprintf (stderr , ", " );
1294- }
1295- fprintf (stderr , "\n" );
1296- }
1297-
12981249static inline void get_pretty_name (int is_func , const char * * name , const char * * name_p )
12991250{
13001251 switch (is_func ) {
@@ -1312,141 +1263,31 @@ static inline void get_pretty_name(int is_func, const char** name, const char**
13121263static void report_sec_mismatch (const char * modname ,
13131264 const struct sectioncheck * mismatch ,
13141265 const char * fromsec ,
1315- unsigned long long fromaddr ,
13161266 const char * fromsym ,
1317- int from_is_func ,
1318- const char * tosec , const char * tosym ,
1319- int to_is_func )
1267+ const char * tosec , const char * tosym )
13201268{
1321- const char * from , * from_p ;
1322- const char * to , * to_p ;
1323- char * prl_from ;
1324- char * prl_to ;
1325-
13261269 sec_mismatch_count ++ ;
13271270
1328- get_pretty_name (from_is_func , & from , & from_p );
1329- get_pretty_name (to_is_func , & to , & to_p );
1330-
1331- warn ("%s(%s+0x%llx): Section mismatch in reference from the %s %s%s "
1332- "to the %s %s:%s%s\n" ,
1333- modname , fromsec , fromaddr , from , fromsym , from_p , to , tosec ,
1334- tosym , to_p );
1335-
13361271 switch (mismatch -> mismatch ) {
13371272 case TEXT_TO_ANY_INIT :
1338- prl_from = sec2annotation (fromsec );
1339- prl_to = sec2annotation (tosec );
1340- fprintf (stderr ,
1341- "The function %s%s() references\n"
1342- "the %s %s%s%s.\n"
1343- "This is often because %s lacks a %s\n"
1344- "annotation or the annotation of %s is wrong.\n" ,
1345- prl_from , fromsym ,
1346- to , prl_to , tosym , to_p ,
1347- fromsym , prl_to , tosym );
1348- free (prl_from );
1349- free (prl_to );
1350- break ;
1351- case DATA_TO_ANY_INIT : {
1352- prl_to = sec2annotation (tosec );
1353- fprintf (stderr ,
1354- "The variable %s references\n"
1355- "the %s %s%s%s\n"
1356- "If the reference is valid then annotate the\n"
1357- "variable with __init* or __refdata (see linux/init.h) "
1358- "or name the variable:\n" ,
1359- fromsym , to , prl_to , tosym , to_p );
1360- print_section_list (mismatch -> symbol_white_list );
1361- free (prl_to );
1362- break ;
1363- }
1273+ case DATA_TO_ANY_INIT :
13641274 case TEXT_TO_ANY_EXIT :
1365- prl_to = sec2annotation (tosec );
1366- fprintf (stderr ,
1367- "The function %s() references a %s in an exit section.\n"
1368- "Often the %s %s%s has valid usage outside the exit section\n"
1369- "and the fix is to remove the %sannotation of %s.\n" ,
1370- fromsym , to , to , tosym , to_p , prl_to , tosym );
1371- free (prl_to );
1372- break ;
1373- case DATA_TO_ANY_EXIT : {
1374- prl_to = sec2annotation (tosec );
1375- fprintf (stderr ,
1376- "The variable %s references\n"
1377- "the %s %s%s%s\n"
1378- "If the reference is valid then annotate the\n"
1379- "variable with __exit* (see linux/init.h) or "
1380- "name the variable:\n" ,
1381- fromsym , to , prl_to , tosym , to_p );
1382- print_section_list (mismatch -> symbol_white_list );
1383- free (prl_to );
1384- break ;
1385- }
1275+ case DATA_TO_ANY_EXIT :
13861276 case XXXINIT_TO_SOME_INIT :
13871277 case XXXEXIT_TO_SOME_EXIT :
1388- prl_from = sec2annotation (fromsec );
1389- prl_to = sec2annotation (tosec );
1390- fprintf (stderr ,
1391- "The %s %s%s%s references\n"
1392- "a %s %s%s%s.\n"
1393- "If %s is only used by %s then\n"
1394- "annotate %s with a matching annotation.\n" ,
1395- from , prl_from , fromsym , from_p ,
1396- to , prl_to , tosym , to_p ,
1397- tosym , fromsym , tosym );
1398- free (prl_from );
1399- free (prl_to );
1400- break ;
14011278 case ANY_INIT_TO_ANY_EXIT :
1402- prl_from = sec2annotation (fromsec );
1403- prl_to = sec2annotation (tosec );
1404- fprintf (stderr ,
1405- "The %s %s%s%s references\n"
1406- "a %s %s%s%s.\n"
1407- "This is often seen when error handling "
1408- "in the init function\n"
1409- "uses functionality in the exit path.\n"
1410- "The fix is often to remove the %sannotation of\n"
1411- "%s%s so it may be used outside an exit section.\n" ,
1412- from , prl_from , fromsym , from_p ,
1413- to , prl_to , tosym , to_p ,
1414- prl_to , tosym , to_p );
1415- free (prl_from );
1416- free (prl_to );
1417- break ;
14181279 case ANY_EXIT_TO_ANY_INIT :
1419- prl_from = sec2annotation (fromsec );
1420- prl_to = sec2annotation (tosec );
1421- fprintf (stderr ,
1422- "The %s %s%s%s references\n"
1423- "a %s %s%s%s.\n"
1424- "This is often seen when error handling "
1425- "in the exit function\n"
1426- "uses functionality in the init path.\n"
1427- "The fix is often to remove the %sannotation of\n"
1428- "%s%s so it may be used outside an init section.\n" ,
1429- from , prl_from , fromsym , from_p ,
1430- to , prl_to , tosym , to_p ,
1431- prl_to , tosym , to_p );
1432- free (prl_from );
1433- free (prl_to );
1280+ warn ("%s: section mismatch in reference: %s (section: %s) -> %s (section: %s)\n" ,
1281+ modname , fromsym , fromsec , tosym , tosec );
14341282 break ;
14351283 case EXPORT_TO_INIT_EXIT :
1436- prl_to = sec2annotation (tosec );
1437- fprintf (stderr ,
1438- "The symbol %s is exported and annotated %s\n"
1439- "Fix this by removing the %sannotation of %s "
1440- "or drop the export.\n" ,
1441- tosym , prl_to , prl_to , tosym );
1442- free (prl_to );
1284+ warn ("%s: EXPORT_SYMBOL used for init/exit symbol: %s (section: %s)\n" ,
1285+ modname , tosym , tosec );
14431286 break ;
14441287 case EXTABLE_TO_NON_TEXT :
1445- fatal ("There's a special handler for this mismatch type, "
1446- "we should never get here." );
1288+ fatal ("There's a special handler for this mismatch type, we should never get here.\n" );
14471289 break ;
14481290 }
1449- fprintf (stderr , "\n" );
14501291}
14511292
14521293static void default_mismatch_handler (const char * modname , struct elf_info * elf ,
@@ -1470,9 +1311,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
14701311 if (secref_whitelist (mismatch ,
14711312 fromsec , fromsym , tosec , tosym )) {
14721313 report_sec_mismatch (modname , mismatch ,
1473- fromsec , r -> r_offset , fromsym ,
1474- is_function (from ), tosec , tosym ,
1475- is_function (to ));
1314+ fromsec , fromsym , tosec , tosym );
14761315 }
14771316}
14781317
0 commit comments