elf: Load non-load sections in memory for multiboot
diff --git a/common/lib/elf.c b/common/lib/elf.c
index 32e53b46..f6f41919 100644
--- a/common/lib/elf.c
+++ b/common/lib/elf.c
@@ -312,6 +312,19 @@ struct elf_section_hdr_info* elf64_section_hdr_info(uint8_t *elf) {
memcpy(info->section_hdrs, elf + (hdr.shoff), info->section_hdr_size);
+ for (size_t i = 0; i < info->num; i++) {
+ struct elf64_shdr *shdr = info->section_hdrs + i * hdr.shdr_size;
+
+ if (shdr->sh_addr != 0 || shdr->sh_size == 0) {
+ continue;
+ }
+
+ void *section = conv_mem_alloc(shdr->sh_size);
+ memcpy(section, elf + shdr->sh_offset, shdr->sh_size);
+
+ shdr->sh_addr = (uintptr_t)section;
+ }
+
return info;
}
@@ -331,6 +344,19 @@ struct elf_section_hdr_info* elf32_section_hdr_info(uint8_t *elf) {
memcpy(info->section_hdrs, elf + (hdr.shoff), info->section_hdr_size);
+ for (size_t i = 0; i < info->num; i++) {
+ struct elf32_shdr *shdr = info->section_hdrs + i * hdr.shdr_size;
+
+ if (shdr->sh_addr != 0 || shdr->sh_size == 0) {
+ continue;
+ }
+
+ void *section = conv_mem_alloc(shdr->sh_size);
+ memcpy(section, elf + shdr->sh_offset, shdr->sh_size);
+
+ shdr->sh_addr = (uintptr_t)section;
+ }
+
return info;
}
