@@ -1398,6 +1398,7 @@ struct kcore_copy_info {
1398
1398
u64 last_symbol ;
1399
1399
u64 first_module ;
1400
1400
u64 last_module_symbol ;
1401
+ size_t phnum ;
1401
1402
struct phdr_data kernel_map ;
1402
1403
struct phdr_data modules_map ;
1403
1404
struct list_head phdrs ;
@@ -1517,6 +1518,8 @@ static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf)
1517
1518
if (kci -> modules_map .len )
1518
1519
list_add_tail (& kci -> modules_map .node , & kci -> phdrs );
1519
1520
1521
+ kci -> phnum = !!kci -> kernel_map .len + !!kci -> modules_map .len ;
1522
+
1520
1523
return 0 ;
1521
1524
}
1522
1525
@@ -1678,7 +1681,6 @@ int kcore_copy(const char *from_dir, const char *to_dir)
1678
1681
{
1679
1682
struct kcore kcore ;
1680
1683
struct kcore extract ;
1681
- size_t count = 2 ;
1682
1684
int idx = 0 , err = -1 ;
1683
1685
off_t offset = page_size , sz , modules_offset = 0 ;
1684
1686
struct kcore_copy_info kci = { .stext = 0 , };
@@ -1705,10 +1707,7 @@ int kcore_copy(const char *from_dir, const char *to_dir)
1705
1707
if (kcore__init (& extract , extract_filename , kcore .elfclass , false))
1706
1708
goto out_kcore_close ;
1707
1709
1708
- if (!kci .modules_map .addr )
1709
- count -= 1 ;
1710
-
1711
- if (kcore__copy_hdr (& kcore , & extract , count ))
1710
+ if (kcore__copy_hdr (& kcore , & extract , kci .phnum ))
1712
1711
goto out_extract_close ;
1713
1712
1714
1713
if (kcore__add_phdr (& extract , idx ++ , offset , kci .kernel_map .addr ,
0 commit comments