From 5420bb8a67f5f782ac49c90afb7da178a60c448a Mon Sep 17 00:00:00 2001 From: David Mertens Date: Sun, 8 Jan 2017 07:27:24 -0500 Subject: [PATCH] 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. --- tccrun.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tccrun.c b/tccrun.c index 517205eb..7b533df2 100644 --- a/tccrun.c +++ b/tccrun.c @@ -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++) {