@@ -433,8 +433,7 @@ static int add_dead_ends(struct objtool_file *file)
433433
434434static int create_static_call_sections (struct objtool_file * file )
435435{
436- struct section * sec , * reloc_sec ;
437- struct reloc * reloc ;
436+ struct section * sec ;
438437 struct static_call_site * site ;
439438 struct instruction * insn ;
440439 struct symbol * key_sym ;
@@ -460,8 +459,7 @@ static int create_static_call_sections(struct objtool_file *file)
460459 if (!sec )
461460 return -1 ;
462461
463- reloc_sec = elf_create_reloc_section (file -> elf , sec , SHT_RELA );
464- if (!reloc_sec )
462+ if (!elf_create_reloc_section (file -> elf , sec , SHT_RELA ))
465463 return -1 ;
466464
467465 idx = 0 ;
@@ -471,25 +469,11 @@ static int create_static_call_sections(struct objtool_file *file)
471469 memset (site , 0 , sizeof (struct static_call_site ));
472470
473471 /* populate reloc for 'addr' */
474- reloc = malloc (sizeof (* reloc ));
475-
476- if (!reloc ) {
477- perror ("malloc" );
478- return -1 ;
479- }
480- memset (reloc , 0 , sizeof (* reloc ));
481-
482- insn_to_reloc_sym_addend (insn -> sec , insn -> offset , reloc );
483- if (!reloc -> sym ) {
484- WARN_FUNC ("static call tramp: missing containing symbol" ,
485- insn -> sec , insn -> offset );
472+ if (elf_add_reloc_to_insn (file -> elf , sec ,
473+ idx * sizeof (struct static_call_site ),
474+ R_X86_64_PC32 ,
475+ insn -> sec , insn -> offset ))
486476 return -1 ;
487- }
488-
489- reloc -> type = R_X86_64_PC32 ;
490- reloc -> offset = idx * sizeof (struct static_call_site );
491- reloc -> sec = reloc_sec ;
492- elf_add_reloc (file -> elf , reloc );
493477
494478 /* find key symbol */
495479 key_name = strdup (insn -> call_dest -> name );
@@ -526,18 +510,11 @@ static int create_static_call_sections(struct objtool_file *file)
526510 free (key_name );
527511
528512 /* populate reloc for 'key' */
529- reloc = malloc (sizeof (* reloc ));
530- if (!reloc ) {
531- perror ("malloc" );
513+ if (elf_add_reloc (file -> elf , sec ,
514+ idx * sizeof (struct static_call_site ) + 4 ,
515+ R_X86_64_PC32 , key_sym ,
516+ is_sibling_call (insn ) * STATIC_CALL_SITE_TAIL ))
532517 return -1 ;
533- }
534- memset (reloc , 0 , sizeof (* reloc ));
535- reloc -> sym = key_sym ;
536- reloc -> addend = is_sibling_call (insn ) ? STATIC_CALL_SITE_TAIL : 0 ;
537- reloc -> type = R_X86_64_PC32 ;
538- reloc -> offset = idx * sizeof (struct static_call_site ) + 4 ;
539- reloc -> sec = reloc_sec ;
540- elf_add_reloc (file -> elf , reloc );
541518
542519 idx ++ ;
543520 }
@@ -547,8 +524,7 @@ static int create_static_call_sections(struct objtool_file *file)
547524
548525static int create_mcount_loc_sections (struct objtool_file * file )
549526{
550- struct section * sec , * reloc_sec ;
551- struct reloc * reloc ;
527+ struct section * sec ;
552528 unsigned long * loc ;
553529 struct instruction * insn ;
554530 int idx ;
@@ -571,8 +547,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
571547 if (!sec )
572548 return -1 ;
573549
574- reloc_sec = elf_create_reloc_section (file -> elf , sec , SHT_RELA );
575- if (!reloc_sec )
550+ if (!elf_create_reloc_section (file -> elf , sec , SHT_RELA ))
576551 return -1 ;
577552
578553 idx = 0 ;
@@ -581,32 +556,11 @@ static int create_mcount_loc_sections(struct objtool_file *file)
581556 loc = (unsigned long * )sec -> data -> d_buf + idx ;
582557 memset (loc , 0 , sizeof (unsigned long ));
583558
584- reloc = malloc (sizeof (* reloc ));
585- if (!reloc ) {
586- perror ("malloc" );
559+ if (elf_add_reloc_to_insn (file -> elf , sec ,
560+ idx * sizeof (unsigned long ),
561+ R_X86_64_64 ,
562+ insn -> sec , insn -> offset ))
587563 return -1 ;
588- }
589- memset (reloc , 0 , sizeof (* reloc ));
590-
591- if (insn -> sec -> sym ) {
592- reloc -> sym = insn -> sec -> sym ;
593- reloc -> addend = insn -> offset ;
594- } else {
595- reloc -> sym = find_symbol_containing (insn -> sec , insn -> offset );
596-
597- if (!reloc -> sym ) {
598- WARN ("missing symbol for insn at offset 0x%lx\n" ,
599- insn -> offset );
600- return -1 ;
601- }
602-
603- reloc -> addend = insn -> offset - reloc -> sym -> offset ;
604- }
605-
606- reloc -> type = R_X86_64_64 ;
607- reloc -> offset = idx * sizeof (unsigned long );
608- reloc -> sec = reloc_sec ;
609- elf_add_reloc (file -> elf , reloc );
610564
611565 idx ++ ;
612566 }
0 commit comments