fixed forced section padding in mld

This commit is contained in:
Murphy 2024-10-04 22:09:01 -04:00
parent e470009a16
commit 9ae3442c85
Signed by: freya
GPG key ID: 744AB800E383AE52
3 changed files with 2 additions and 24 deletions

View file

@ -565,20 +565,6 @@ static void update_offsets(struct linker *linker)
// sections
for (uint32_t i = 0; i < linker->segments.len; i++) {
struct segment_table_entry *ent = &linker->segments.entries[i];
// section padding
{
uint32_t m = ptr % SEC_ALIGN;
if (m) {
uint32_t add = SEC_ALIGN - m;
ptr += add;
ent->off = ptr;
ent->padding = add;
} else {
ent->padding = 0;
}
}
uint32_t idx = i + 1;
uint32_t size = segtab_ent_size(ent);
linker->phdr[i].p_offset = B32(ptr);
@ -634,13 +620,6 @@ static int write_file(struct linker *linker)
// sections
for (uint32_t i = 0; i < linker->segments.len; i++) {
struct segment_table_entry *ent = &linker->segments.entries[i];
// section padding
{
for (uint32_t i = 0; i < ent->padding; i++) {
uint8_t zero = 0;
res |= fwrite(&zero, 1, 1, out);
}
}
for (uint32_t j = 0; j < ent->len; j++) {
struct segment *seg = ent->parts[j];
res |= fwrite(seg->bytes, 1, seg->size, out);

View file

@ -173,8 +173,6 @@ struct segment_table_entry {
uint32_t vaddr;
// weak segment pointers. we do not own these!!!
struct segment **parts;
// section padding
uint32_t padding;
};
int segtab_ent_init(struct segment_table_entry *ent);

View file

@ -67,7 +67,7 @@ static int load_ehdr(struct object *object)
*/
static int load_shdr(struct object *object)
{
size_t shdr_len = B16(object->ehdr->e_shentsize) *
size_t shdr_len = sizeof(Elf32_Shdr) *
B16(object->ehdr->e_shnum);
size_t shdr_off = B32(object->ehdr->e_shoff);
object->shdr = (Elf32_Shdr *) (object->mapped + shdr_off);
@ -334,6 +334,7 @@ int object_load(struct object *object, char *path, uint32_t index)
object->mapped = NULL;
object->name = path;
object->index = index;
object->phdr = NULL;
object->phdr_to_shdr_mapping = NULL;
/** load the file */