Skip to content

Commit 6507700

Browse files
authored
Merge pull request #1305 from joe-lawrence/llvm-from-swine
Collection of small llvm fixes
2 parents 114878a + 85781b7 commit 6507700

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

kpatch-build/create-diff-object.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,9 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
27192719
/* Ignore any discarded sections */
27202720
list_for_each_entry(sec, &kelf->sections, list) {
27212721
if (!strncmp(sec->name, ".discard", 8) ||
2722-
!strncmp(sec->name, ".rela.discard", 13))
2722+
!strncmp(sec->name, ".rela.discard", 13) ||
2723+
!strncmp(sec->name, ".llvm_addrsig", 13) ||
2724+
!strncmp(sec->name, ".llvm.", 6))
27232725
sec->ignore = 1;
27242726
}
27252727

kpatch-build/kpatch-elf.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

649649
void 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

Comments
 (0)