mirror of
https://github.com/frida/tinycc
synced 2025-01-01 17:44:26 +03:00
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.
This commit is contained in:
parent
5d1bc3fbd4
commit
5420bb8a67
9
tccrun.c
9
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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user