Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection of small llvm fixes #1305

Merged
merged 3 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2717,7 +2717,9 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
/* Ignore any discarded sections */
list_for_each_entry(sec, &kelf->sections, list) {
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;
}

Expand Down
33 changes: 29 additions & 4 deletions kpatch-build/kpatch-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)

shstrtab = find_section_by_name(&kelf->sections, ".shstrtab");
if (!shstrtab)
ERROR("find_section_by_name");
return;

/* determine size of string table */
size = 1; /* for initial NULL terminator */
Expand Down Expand Up @@ -648,7 +648,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf)

void kpatch_create_strtab(struct kpatch_elf *kelf)
{
struct section *strtab;
struct section *strtab, *shstrtab;
struct symbol *sym;
size_t size = 0, offset = 0, len;
char *buf;
Expand All @@ -657,13 +657,24 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
if (!strtab)
ERROR("find_section_by_name");

shstrtab = find_section_by_name(&kelf->sections, ".shstrtab");

/* determine size of string table */
list_for_each_entry(sym, &kelf->symbols, list) {
if (sym->type == STT_SECTION)
continue;
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 */
buf = malloc(size);
if (!buf)
Expand All @@ -682,8 +693,20 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
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)
ERROR("shstrtab size mismatch");
ERROR("strtab size mismatch");

strtab->data->d_buf = buf;
strtab->data->d_size = size;
Expand Down Expand Up @@ -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");
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;

Expand Down