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
175}175}
176 176
177#ifdef TCC_TARGET_X86_64177#ifdef TCC_TARGET_X86_64
178 #define SECTION_ALIGNMENT 511178 #define RUN_SECTION_ALIGNMENT 63
179#else179#else
180 #define SECTION_ALIGNMENT 15180 #define RUN_SECTION_ALIGNMENT 15
181#endif181#endif
182 182
183/* relocate code. Return -1 on error, required size if ptr is NULL,183/* 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
204 }204 }
205 205
206 offset = 0, mem = (addr_t)ptr;206 offset = 0, mem = (addr_t)ptr;
207 mem += -(int)mem & RUN_SECTION_ALIGNMENT;
207#ifdef _WIN64208#ifdef _WIN64
208 offset += sizeof (void*);209 offset += sizeof (void*);
209#endif210#endif
@@ -211,7 +212,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 1 unmodified line
211 s = s1->sections[i];212 s = s1->sections[i];
212 if (0 == (s->sh_flags & SHF_ALLOC))213 if (0 == (s->sh_flags & SHF_ALLOC))
213 continue;214 continue;
214 offset = (offset + SECTION_ALIGNMENT) & ~SECTION_ALIGNMENT;215 offset = (offset + RUN_SECTION_ALIGNMENT) & ~RUN_SECTION_ALIGNMENT;
215 s->sh_addr = mem ? mem + offset : 0;216 s->sh_addr = mem ? mem + offset : 0;
216 offset += s->data_offset;217 offset += s->data_offset;
217 }218 }
@@ -222,7 +223,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 4 unmodified lines
222 return -1;223 return -1;
223 224
224 if (0 == mem)225 if (0 == mem)
225 return offset;226 return offset + RUN_SECTION_ALIGNMENT;
226 227
227 /* relocate each section */228 /* relocate each section */
228 for(i = 1; i < s1->nb_sections; i++) {229 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