Merge pull request #1305 from joe-lawrence/llvm-from-swine

Collection of small llvm fixes
This commit is contained in:
Joe Lawrence 2022-10-04 10:06:23 -04:00 committed by GitHub
commit 6507700d02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 5 deletions

View File

@ -2719,7 +2719,9 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
/* Ignore any discarded sections */ /* Ignore any discarded sections */
list_for_each_entry(sec, &kelf->sections, list) { list_for_each_entry(sec, &kelf->sections, list) {
if (!strncmp(sec->name, ".discard", 8) || if (!strncmp(sec->name, ".discard", 8) ||
!strncmp(sec->name, ".rela.discard", 13)) !strncmp(sec->name, ".rela.discard", 13) ||
!strncmp(sec->name, ".llvm_addrsig", 13) ||
!strncmp(sec->name, ".llvm.", 6))
sec->ignore = 1; sec->ignore = 1;
} }

View File

@ -607,7 +607,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)
shstrtab = find_section_by_name(&kelf->sections, ".shstrtab"); shstrtab = find_section_by_name(&kelf->sections, ".shstrtab");
if (!shstrtab) if (!shstrtab)
ERROR("find_section_by_name"); return;
/* determine size of string table */ /* determine size of string table */
size = 1; /* for initial NULL terminator */ size = 1; /* for initial NULL terminator */
@ -648,7 +648,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)
void kpatch_create_strtab(struct kpatch_elf *kelf) void kpatch_create_strtab(struct kpatch_elf *kelf)
{ {
struct section *strtab; struct section *strtab, *shstrtab;
struct symbol *sym; struct symbol *sym;
size_t size = 0, offset = 0, len; size_t size = 0, offset = 0, len;
char *buf; char *buf;
@ -657,6 +657,8 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
if (!strtab) if (!strtab)
ERROR("find_section_by_name"); ERROR("find_section_by_name");
shstrtab = find_section_by_name(&kelf->sections, ".shstrtab");
/* determine size of string table */ /* determine size of string table */
list_for_each_entry(sym, &kelf->symbols, list) { list_for_each_entry(sym, &kelf->symbols, list) {
if (sym->type == STT_SECTION) if (sym->type == STT_SECTION)
@ -664,6 +666,15 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
size += strlen(sym->name) + 1; /* include NULL terminator */ size += strlen(sym->name) + 1; /* include NULL terminator */
} }
/* and when covering for missing .shstrtab ... */
if (!shstrtab) {
/* factor out into common (sh)strtab feeder */
struct section *sec;
list_for_each_entry(sec, &kelf->sections, list)
size += strlen(sec->name) + 1; /* include NULL terminator */
}
/* allocate data buffer */ /* allocate data buffer */
buf = malloc(size); buf = malloc(size);
if (!buf) if (!buf)
@ -682,8 +693,20 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
offset += len; offset += len;
} }
if (!shstrtab) {
struct section *sec;
/* populate string table and link with section header */
list_for_each_entry(sec, &kelf->sections, list) {
len = strlen(sec->name) + 1;
sec->sh.sh_name = (unsigned int)offset;
memcpy(buf + offset, sec->name, len);
offset += len;
}
}
if (offset != size) if (offset != size)
ERROR("shstrtab size mismatch"); ERROR("strtab size mismatch");
strtab->data->d_buf = buf; strtab->data->d_buf = buf;
strtab->data->d_size = size; strtab->data->d_size = size;
@ -928,7 +951,9 @@ void kpatch_write_output_elf(struct kpatch_elf *kelf, Elf *elf, char *outfile,
shstrtab = find_section_by_name(&kelf->sections, ".shstrtab"); shstrtab = find_section_by_name(&kelf->sections, ".shstrtab");
if (!shstrtab) if (!shstrtab)
ERROR("missing .shstrtab section"); shstrtab = find_section_by_name(&kelf->sections, ".strtab");
if (!shstrtab)
ERROR("missing .shstrtab, .strtab sections");
ehout.e_shstrndx = (unsigned short)shstrtab->index; ehout.e_shstrndx = (unsigned short)shstrtab->index;