@@ -607,7 +607,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)
607607
608608 shstrtab = find_section_by_name (& kelf -> sections , ".shstrtab" );
609609 if (!shstrtab )
610- ERROR ( "find_section_by_name" ) ;
610+ return ;
611611
612612 /* determine size of string table */
613613 size = 1 ; /* for initial NULL terminator */
@@ -648,7 +648,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)
648648
649649void kpatch_create_strtab (struct kpatch_elf * kelf )
650650{
651- struct section * strtab ;
651+ struct section * strtab , * shstrtab ;
652652 struct symbol * sym ;
653653 size_t size = 0 , offset = 0 , len ;
654654 char * buf ;
@@ -657,13 +657,24 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
657657 if (!strtab )
658658 ERROR ("find_section_by_name" );
659659
660+ shstrtab = find_section_by_name (& kelf -> sections , ".shstrtab" );
661+
660662 /* determine size of string table */
661663 list_for_each_entry (sym , & kelf -> symbols , list ) {
662664 if (sym -> type == STT_SECTION )
663665 continue ;
664666 size += strlen (sym -> name ) + 1 ; /* include NULL terminator */
665667 }
666668
669+ /* and when covering for missing .shstrtab ... */
670+ if (!shstrtab ) {
671+ /* factor out into common (sh)strtab feeder */
672+ struct section * sec ;
673+
674+ list_for_each_entry (sec , & kelf -> sections , list )
675+ size += strlen (sec -> name ) + 1 ; /* include NULL terminator */
676+ }
677+
667678 /* allocate data buffer */
668679 buf = malloc (size );
669680 if (!buf )
@@ -682,8 +693,20 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
682693 offset += len ;
683694 }
684695
696+ if (!shstrtab ) {
697+ struct section * sec ;
698+
699+ /* populate string table and link with section header */
700+ list_for_each_entry (sec , & kelf -> sections , list ) {
701+ len = strlen (sec -> name ) + 1 ;
702+ sec -> sh .sh_name = (unsigned int )offset ;
703+ memcpy (buf + offset , sec -> name , len );
704+ offset += len ;
705+ }
706+ }
707+
685708 if (offset != size )
686- ERROR ("shstrtab size mismatch" );
709+ ERROR ("strtab size mismatch" );
687710
688711 strtab -> data -> d_buf = buf ;
689712 strtab -> data -> d_size = size ;
@@ -928,7 +951,9 @@ void kpatch_write_output_elf(struct kpatch_elf *kelf, Elf *elf, char *outfile,
928951
929952 shstrtab = find_section_by_name (& kelf -> sections , ".shstrtab" );
930953 if (!shstrtab )
931- ERROR ("missing .shstrtab section" );
954+ shstrtab = find_section_by_name (& kelf -> sections , ".strtab" );
955+ if (!shstrtab )
956+ ERROR ("missing .shstrtab, .strtab sections" );
932957
933958 ehout .e_shstrndx = (unsigned short )shstrtab -> index ;
934959
0 commit comments