Skip to content
Merged
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
8 changes: 4 additions & 4 deletions subsys/llext/llext_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,24 @@ static int llext_find_tables(struct llext_loader *ldr, struct llext *ext)

if (shdr->sh_type == SHT_SYMTAB && ldr->hdr.e_type == ET_REL) {
LOG_DBG("symtab at %d", i);
ldr->sects[LLEXT_MEM_SYMTAB] = *shdr;
memcpy(&ldr->sects[LLEXT_MEM_SYMTAB], shdr, sizeof(*shdr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, interesting. Is this compiler-specific? IIRC I've seen a structure assignment being replaced by the compiler with a memcpy builtin. That implementation shouldn't assume any alignment. And in general - as long as there's no alignment attribute, is it valid to assume any such alignment? I think structures are defined to be aligned in arrays, but stand-alone - I wasn't aware of such restrictions at least

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've ran into similar issues with mipi sys-t logging in the past which, yes, when derefencing arbitrary pointers and applying assignment would result in unaligned access faults just like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@teburd but that depends on the type of the pointer. If it's a char * certainly no alignment is needed. For a 2-byte type a two-byte alignment is needed and so on. And for a structure? Even the fact that the linker placed a section header above without a 4-byte alignment suggests, that it's valid. And then the compiler fails to generate code to read it. Interesting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even the fact that the linker placed a section header above without a 4-byte alignment suggests, that it's valid

Its not clear to me why the section header should have any alignment requirements, its a binary data structure, not executable code. Even if it did have an alignment, what should that be? A uint32_t alignment, that would work fine for the 32 bit targets, would still have an incorrect alignment on 64 bit platforms.

ldr->sect_map[i].mem_idx = LLEXT_MEM_SYMTAB;
strtab_ndx = shdr->sh_link;
table_cnt++;
} else if (shdr->sh_type == SHT_DYNSYM && ldr->hdr.e_type == ET_DYN) {
LOG_DBG("dynsym at %d", i);
ldr->sects[LLEXT_MEM_SYMTAB] = *shdr;
memcpy(&ldr->sects[LLEXT_MEM_SYMTAB], shdr, sizeof(*shdr));
ldr->sect_map[i].mem_idx = LLEXT_MEM_SYMTAB;
strtab_ndx = shdr->sh_link;
table_cnt++;
} else if (shdr->sh_type == SHT_STRTAB && i == shstrtab_ndx) {
LOG_DBG("shstrtab at %d", i);
ldr->sects[LLEXT_MEM_SHSTRTAB] = *shdr;
memcpy(&ldr->sects[LLEXT_MEM_SHSTRTAB], shdr, sizeof(*shdr));
ldr->sect_map[i].mem_idx = LLEXT_MEM_SHSTRTAB;
table_cnt++;
} else if (shdr->sh_type == SHT_STRTAB && i == strtab_ndx) {
LOG_DBG("strtab at %d", i);
ldr->sects[LLEXT_MEM_STRTAB] = *shdr;
memcpy(&ldr->sects[LLEXT_MEM_STRTAB], shdr, sizeof(*shdr));
ldr->sect_map[i].mem_idx = LLEXT_MEM_STRTAB;
table_cnt++;
}
Expand Down