SECTION_ALIGNMENT -> RUN_SECTION_ALIGNMENT, and tweaks

Based on feedback from grischka, this commit
(1) updates the name of the alignment constant to be more specific
(2) aligns all sections, including the first (which previosly was
    not aligned)
(3) reduces the x86-64 alignment from 512 to 64 bytes.

The original x86-64 alignment of 512 bytes was based on testing.
After ensuring that the initial section is also aligned, the same
tests indicated that 64 bytes is sufficient.
master
David Mertens 2017-01-08 07:27:24 -05:00
parent 5d1bc3fbd4
commit 5420bb8a67
1 changed files with 5 additions and 4 deletions

View File

@ -175,9 +175,9 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
}
#ifdef TCC_TARGET_X86_64
#define SECTION_ALIGNMENT 511
#define RUN_SECTION_ALIGNMENT 63
#else
#define SECTION_ALIGNMENT 15
#define RUN_SECTION_ALIGNMENT 15
#endif
/* relocate code. Return -1 on error, required size if ptr is NULL,
@ -204,6 +204,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr)
}
offset = 0, mem = (addr_t)ptr;
mem += -(int)mem & RUN_SECTION_ALIGNMENT;
#ifdef _WIN64
offset += sizeof (void*);
#endif
@ -211,7 +212,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr)
s = s1->sections[i];
if (0 == (s->sh_flags & SHF_ALLOC))
continue;
offset = (offset + SECTION_ALIGNMENT) & ~SECTION_ALIGNMENT;
offset = (offset + RUN_SECTION_ALIGNMENT) & ~RUN_SECTION_ALIGNMENT;
s->sh_addr = mem ? mem + offset : 0;
offset += s->data_offset;
}
@ -222,7 +223,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr)
return -1;
if (0 == mem)
return offset;
return offset + RUN_SECTION_ALIGNMENT;
/* relocate each section */
for(i = 1; i < s1->nb_sections; i++) {