aboutsummaryrefslogtreecommitdiff
path: root/x86_64-gen.c
diff options
context:
space:
mode:
authorEdmund Grimley Evans <Edmund.Grimley.Evans@gmail.com>2015-11-19 18:21:14 +0000
committerEdmund Grimley Evans <Edmund.Grimley.Evans@gmail.com>2015-11-19 18:21:14 +0000
commit553242c18a2387fb896df66eb9b5a502f0e87ff0 (patch)
tree51501263aac1ea67fffb969466c31004cec9060e /x86_64-gen.c
parent5d496b169580d0cd4a1fbb454fc1ac55a78a0ee5 (diff)
downloadtinycc-553242c18a2387fb896df66eb9b5a502f0e87ff0.tar.gz
tinycc-553242c18a2387fb896df66eb9b5a502f0e87ff0.tar.bz2
Replace pointer casts with calls to (read|write)(16|32|64)le.
This stops UBSan from giving runtime misaligned address errors and might eventually allow building on a non-little-endian host.
Diffstat (limited to 'x86_64-gen.c')
-rw-r--r--x86_64-gen.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/x86_64-gen.c b/x86_64-gen.c
index 5394bf5..d8dfaab 100644
--- a/x86_64-gen.c
+++ b/x86_64-gen.c
@@ -214,11 +214,10 @@ void orex(int ll, int r, int r2, int b)
/* output a symbol and patch all calls to it */
void gsym_addr(int t, int a)
{
- int n, *ptr;
while (t) {
- ptr = (int *)(cur_text_section->data + t);
- n = *ptr; /* next value */
- *ptr = a - t - 4;
+ unsigned char *ptr = cur_text_section->data + t;
+ uint32_t n = read32le(ptr); /* next value */
+ write32le(ptr, a - t - 4);
t = n;
}
}
@@ -248,7 +247,7 @@ ST_FUNC int oad(int c, int s)
ind1 = ind + 4;
if (ind1 > cur_text_section->data_allocated)
section_realloc(cur_text_section, ind1);
- *(int *)(cur_text_section->data + ind) = s;
+ write32le(cur_text_section->data + ind, s);
s = ind;
ind = ind1;
return s;
@@ -1691,9 +1690,7 @@ void gjmp_addr(int a)
/* generate a test. set 'inv' to invert test. Stack entry is popped */
int gtst(int inv, int t)
{
- int v, t1, *p;
-
- v = vtop->r & VT_VALMASK;
+ int v = vtop->r & VT_VALMASK;
if (v == VT_CMP) {
/* fast case : can jump directly since flags are set */
if (vtop->c.i & 0x100)
@@ -1719,14 +1716,12 @@ int gtst(int inv, int t)
} else if (v == VT_JMP || v == VT_JMPI) {
/* && or || optimization */
if ((v & 1) == inv) {
+ uint32_t n1, n = vtop->c.i;
/* insert vtop->c jump list in t */
- t1 = vtop->c.i;
- p = &t1;
- while (*p != 0)
- p = (int *)(cur_text_section->data + *p);
- *p = t;
- vtop->c.i = t1;
- t = t1;
+ while ((n1 = read32le(cur_text_section->data + n)))
+ n = n1;
+ write32le(cur_text_section->data + n, t);
+ t = vtop->c.i;
} else {
t = gjmp(t);
gsym(vtop->c.i);