@@ -627,56 +627,6 @@ static struct instruction *find_last_insn(struct objtool_file *file,
627627 return insn ;
628628}
629629
630- /*
631- * Mark "ud2" instructions and manually annotated dead ends.
632- */
633- static int add_dead_ends (struct objtool_file * file )
634- {
635- struct section * rsec ;
636- struct reloc * reloc ;
637- struct instruction * insn ;
638- uint64_t offset ;
639-
640- /*
641- * UD2 defaults to being a dead-end, allow them to be annotated for
642- * non-fatal, eg WARN.
643- */
644- rsec = find_section_by_name (file -> elf , ".rela.discard.reachable" );
645- if (!rsec )
646- return 0 ;
647-
648- for_each_reloc (rsec , reloc ) {
649- if (reloc -> sym -> type == STT_SECTION ) {
650- offset = reloc_addend (reloc );
651- } else if (reloc -> sym -> local_label ) {
652- offset = reloc -> sym -> offset ;
653- } else {
654- WARN ("unexpected relocation symbol type in %s" , rsec -> name );
655- return -1 ;
656- }
657-
658- insn = find_insn (file , reloc -> sym -> sec , offset );
659- if (insn )
660- insn = prev_insn_same_sec (file , insn );
661- else if (offset == reloc -> sym -> sec -> sh .sh_size ) {
662- insn = find_last_insn (file , reloc -> sym -> sec );
663- if (!insn ) {
664- WARN ("can't find reachable insn at %s+0x%" PRIx64 ,
665- reloc -> sym -> sec -> name , offset );
666- return -1 ;
667- }
668- } else {
669- WARN ("can't find reachable insn at %s+0x%" PRIx64 ,
670- reloc -> sym -> sec -> name , offset );
671- return -1 ;
672- }
673-
674- insn -> dead_end = false;
675- }
676-
677- return 0 ;
678- }
679-
680630static int create_static_call_sections (struct objtool_file * file )
681631{
682632 struct static_call_site * site ;
@@ -2306,6 +2256,7 @@ static int read_annotate(struct objtool_file *file,
23062256 struct section * sec ;
23072257 struct instruction * insn ;
23082258 struct reloc * reloc ;
2259+ uint64_t offset ;
23092260 int type , ret ;
23102261
23112262 sec = find_section_by_name (file -> elf , ".discard.annotate_insn" );
@@ -2327,8 +2278,19 @@ static int read_annotate(struct objtool_file *file,
23272278 for_each_reloc (sec -> rsec , reloc ) {
23282279 type = * (u32 * )(sec -> data -> d_buf + (reloc_idx (reloc ) * sec -> sh .sh_entsize ) + 4 );
23292280
2330- insn = find_insn (file , reloc -> sym -> sec ,
2331- reloc -> sym -> offset + reloc_addend (reloc ));
2281+ offset = reloc -> sym -> offset + reloc_addend (reloc );
2282+ insn = find_insn (file , reloc -> sym -> sec , offset );
2283+
2284+ /*
2285+ * Reachable annotations are 'funneh' and act on the previous instruction :/
2286+ */
2287+ if (type == ANNOTYPE_REACHABLE ) {
2288+ if (insn )
2289+ insn = prev_insn_same_sec (file , insn );
2290+ else if (offset == reloc -> sym -> sec -> sh .sh_size )
2291+ insn = find_last_insn (file , reloc -> sym -> sec );
2292+ }
2293+
23322294 if (!insn ) {
23332295 WARN ("bad .discard.annotate_insn entry: %d of type %d" , reloc_idx (reloc ), type );
23342296 return -1 ;
@@ -2420,6 +2382,10 @@ static int __annotate_late(struct objtool_file *file, int type, struct instructi
24202382 insn -> unret = 1 ;
24212383 break ;
24222384
2385+ case ANNOTYPE_REACHABLE :
2386+ insn -> dead_end = false;
2387+ break ;
2388+
24232389 default :
24242390 break ;
24252391 }
@@ -2566,14 +2532,6 @@ static int decode_sections(struct objtool_file *file)
25662532 if (ret )
25672533 return ret ;
25682534
2569- /*
2570- * Must be after add_call_destinations() such that it can override
2571- * dead_end_function() marks.
2572- */
2573- ret = add_dead_ends (file );
2574- if (ret )
2575- return ret ;
2576-
25772535 ret = add_jump_table_alts (file );
25782536 if (ret )
25792537 return ret ;
@@ -2582,6 +2540,10 @@ static int decode_sections(struct objtool_file *file)
25822540 if (ret )
25832541 return ret ;
25842542
2543+ /*
2544+ * Must be after add_call_destinations() such that it can override
2545+ * dead_end_function() marks.
2546+ */
25852547 ret = read_annotate (file , __annotate_late );
25862548 if (ret )
25872549 return ret ;
0 commit comments