Thanks for the response.
I don't think I understand your answer. Maybe I explained it incorrectly.
For the Multiboot 2 ELF symbol tag I use the following structure
Code:
struct mboot2_tag_elf_sections
{
uint32_t type;
uint32_t size;
uint32_t num;
uint32_t entsize;
uint32_t shndx;
char sections[];
};
The num, entsize, and shndx entries correspond to the ‘shdr_*’ entries in
the elf specification in the program header.
The kernel is an elf64 binary. Now, according to the specification the elf
section headers start at the sections member in the above structure. For elf64
section headers I use the following structure
Code:
struct elf64_shdr
{
uint32_t name;
uint32_t type;
uint64_t flags;
uint64_t addr;
uint64_t offset;
uint64_t size;
uint32_t link;
uint32_t info;
uint64_t addralign;
uint64_t entsize;
};
At some point I iterate through all of the section headers that are in the
mboot2_tag_elf_sections tag with the following function.
Code:
void mboot2_it_elf64(
const struct mboot2_info *header, elf64_shdr_it it, void *data)
{
uint32_t i;
uintptr_t shdr;
struct mboot2_tag_elf *tag;
tag = (struct mboot2_tag_elf *)mboot2_get_tag(
header, MBOOT2_TAG_ELF_TYPE);
if (!tag)
return;
for (i = 0; i < tag->num; ++i) {
shdr = (uintptr_t)tag->sections + tag->entsize * i;
it((struct elf64_shdr *)shdr, data);
}
}
The issue then occurs when I access a member of the elf64_shdr struct in the
callback, for example:
Code:
/* called with mboot2_it_elf64(header, example, NULL) */
void example(const struct elf64_shdr *shdr, void *data)
{
uint64_t flags;
flags = shdr->flags; /* misaligned access */
}
So the end result is that all of the structures seem correct. The tag itself
contains elf64 section headers at the section member. I've manually checked if
the values of the section headers are correct by comparing it to the results of
objdump -h on the kernel binary.
The issue isn't with incorrect data but because the sections member of the
mboot2_tag_elf_sections structure starts at an offset of 20 bytes the section
headers member is thus 4-byte aligned and not 8-byte aligned.
Because of the above I don't understand what you mean with 'using the correct
structure'.
Edit:
Unless you mean defining a structure that is a copy of the elf64_shdr
defined above but marking it to avoid alignment requirements and using that
one instead?