aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mertens <dcmertens.perl@gmail.com>2017-01-08 07:27:24 -0500
committerDavid Mertens <dcmertens.perl@gmail.com>2017-01-08 07:27:24 -0500
commit5420bb8a67f5f782ac49c90afb7da178a60c448a (patch)
tree86ea1d123964a8badbadf966a135c4dc60d63f2e
parent5d1bc3fbd4d65af960992fb48ed76990ec673239 (diff)
downloadtinycc-5420bb8a67f5f782ac49c90afb7da178a60c448a.tar.gz
tinycc-5420bb8a67f5f782ac49c90afb7da178a60c448a.tar.bz2
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.
-rw-r--r--tccrun.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/tccrun.c b/tccrun.c
index 517205e..7b533df 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++) {