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++) {