@@ -607,7 +607,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)
607
607
608
608
shstrtab = find_section_by_name (& kelf -> sections , ".shstrtab" );
609
609
if (!shstrtab )
610
- ERROR ( "find_section_by_name" ) ;
610
+ return ;
611
611
612
612
/* determine size of string table */
613
613
size = 1 ; /* for initial NULL terminator */
@@ -648,7 +648,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)
648
648
649
649
void kpatch_create_strtab (struct kpatch_elf * kelf )
650
650
{
651
- struct section * strtab ;
651
+ struct section * strtab , * shstrtab ;
652
652
struct symbol * sym ;
653
653
size_t size = 0 , offset = 0 , len ;
654
654
char * buf ;
@@ -657,13 +657,24 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
657
657
if (!strtab )
658
658
ERROR ("find_section_by_name" );
659
659
660
+ shstrtab = find_section_by_name (& kelf -> sections , ".shstrtab" );
661
+
660
662
/* determine size of string table */
661
663
list_for_each_entry (sym , & kelf -> symbols , list ) {
662
664
if (sym -> type == STT_SECTION )
663
665
continue ;
664
666
size += strlen (sym -> name ) + 1 ; /* include NULL terminator */
665
667
}
666
668
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
+
667
678
/* allocate data buffer */
668
679
buf = malloc (size );
669
680
if (!buf )
@@ -682,8 +693,20 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
682
693
offset += len ;
683
694
}
684
695
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
+
685
708
if (offset != size )
686
- ERROR ("shstrtab size mismatch" );
709
+ ERROR ("strtab size mismatch" );
687
710
688
711
strtab -> data -> d_buf = buf ;
689
712
strtab -> data -> d_size = size ;
@@ -928,7 +951,9 @@ void kpatch_write_output_elf(struct kpatch_elf *kelf, Elf *elf, char *outfile,
928
951
929
952
shstrtab = find_section_by_name (& kelf -> sections , ".shstrtab" );
930
953
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" );
932
957
933
958
ehout .e_shstrndx = (unsigned short )shstrtab -> index ;
934
959
0 commit comments