History

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.

David Mertens committed 9 years ago

Commit 5420bb81 parent 5d1bc3f1 file · +5 −4Browse files

Unified · Split

tccrun.c+5−4
@@ -175,9 +175,9 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) · 174 unmodified lines
175175 }
176176
177177 #ifdef TCC_TARGET_X86_64
178− #define SECTION_ALIGNMENT 511
178+ #define RUN_SECTION_ALIGNMENT 63
179179 #else
180− #define SECTION_ALIGNMENT 15
180+ #define RUN_SECTION_ALIGNMENT 15
181181 #endif
182182
183183 /* 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) · 20 unmodified lines
204204 }
205205
206206 offset = 0, mem = (addr_t)ptr;
207+ mem += -(int)mem & RUN_SECTION_ALIGNMENT;
207208 #ifdef _WIN64
208209 offset += sizeof (void*);
209210 #endif
@@ -211,7 +212,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 1 unmodified line
211212 s = s1->sections[i];
212213 if (0 == (s->sh_flags & SHF_ALLOC))
213214 continue;
214− offset = (offset + SECTION_ALIGNMENT) & ~SECTION_ALIGNMENT;
215+ offset = (offset + RUN_SECTION_ALIGNMENT) & ~RUN_SECTION_ALIGNMENT;
215216 s->sh_addr = mem ? mem + offset : 0;
216217 offset += s->data_offset;
217218 }
@@ -222,7 +223,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 4 unmodified lines
222223 return -1;
223224
224225 if (0 == mem)
225− return offset;
226+ return offset + RUN_SECTION_ALIGNMENT;
226227
227228 /* relocate each section */
228229 for(i = 1; i < s1->nb_sections; i++) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t