Skip to content

Commit fd56823

Browse files
authored
Merge pull request #5052 from eisenhauer/DillUpstream
Dill Upstream
2 parents 7b2deb9 + b86195a commit fd56823

5 files changed

Lines changed: 149 additions & 14 deletions

File tree

thirdparty/dill/dill/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
33
# The directory label is used for CDash to treat DILL as a subproject of GTKorvo
44
set(CMAKE_DIRECTORY_LABELS DILL)
55

6-
project(DILL VERSION 3.4.1 LANGUAGES C CXX)
6+
project(DILL VERSION 3.5.0 LANGUAGES C CXX)
77

88
# Some boilerplate to setup nice output directories
99
include(GNUInstallDirs)

thirdparty/dill/dill/arm64.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,19 +605,23 @@ arm64_proc_start(dill_stream s, char *subr_name, int arg_count,
605605
void
606606
arm64_emit_save(dill_stream s)
607607
{
608+
arm64_mach_info ami = (arm64_mach_info)s->p->mach_info;
608609
void *save_ip = s->p->cur_ip;
610+
int ar_size = ami->act_rec_size;
611+
/* Align to 16 bytes (ARM64 SP must be 16-byte aligned) */
612+
ar_size = (ar_size + 15) & ~15;
613+
609614
s->p->fp = (char*)s->p->code_base;
615+
616+
/* Patch the SUB SP instruction in the prologue.
617+
* The SUB SP, SP, #imm is the 12th instruction (index 11) after
618+
* the 10 STP saves + MOV FP,SP.
619+
* SUB SP, SP, #imm = 0xD10003FF | (imm12 << 10)
620+
*/
621+
unsigned int *prologue = (unsigned int*)s->p->fp;
622+
prologue[11] = 0xD10003FF | ((ar_size & 0xFFF) << 10);
623+
610624
s->p->cur_ip = save_ip;
611-
if (s->dill_debug) {
612-
int num_insns = ((char*)s->p->cur_ip - (char*)s->p->fp) / 4;
613-
printf("arm64_emit_save: fp=%p, code_base=%p, cur_ip=%p, %d instructions\n",
614-
s->p->fp, s->p->code_base, s->p->cur_ip, num_insns);
615-
printf(" All instructions at fp:\n");
616-
unsigned int *code = (unsigned int*)s->p->fp;
617-
for (int i = 0; i < num_insns && i < 32; i++) {
618-
printf(" %p: %08x\n", &code[i], code[i]);
619-
}
620-
}
621625
}
622626

623627
/*

thirdparty/dill/dill/dill_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,13 +951,13 @@ free_code_blocks(dill_stream s)
951951
(s->p->virtual.code_base != s->p->code_base)) {
952952
int vsize = (long)s->p->virtual.code_limit -
953953
(long)s->p->virtual.code_base + END_OF_CODE_BUFFER;
954-
if (munmap(s->p->code_base, vsize) == -1)
954+
if (munmap(s->p->virtual.code_base, vsize) == -1)
955955
perror("unmap v");
956956
}
957957
if (s->p->native.code_base && (s->p->native.code_base != s->p->code_base)) {
958958
int nsize = (long)s->p->native.code_limit -
959959
(long)s->p->native.code_base + END_OF_CODE_BUFFER;
960-
if (munmap(s->p->code_base, nsize) == -1)
960+
if (munmap(s->p->native.code_base, nsize) == -1)
961961
perror("unmap n");
962962
}
963963
#else

thirdparty/dill/dill/vtests/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
set(TESTS basic_call general t1 opt branch prefix_test mixed_params loop_reg)
2+
set(TESTS basic_call general t1 opt branch prefix_test mixed_params loop_reg local_block)
33

44
if(NATIVE_CG)
55
list(APPEND TESTS pkg_test multi_test)
@@ -41,6 +41,9 @@ ENDIF()
4141
set_tests_properties(vtest_loop_reg
4242
PROPERTIES PASS_REGULAR_EXPRESSION "No errors!")
4343

44+
set_tests_properties(vtest_local_block
45+
PROPERTIES PASS_REGULAR_EXPRESSION "No errors!")
46+
4447
set_tests_properties(vtest_basic_call
4548
PROPERTIES PASS_REGULAR_EXPRESSION "########## A
4649
In ff a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=0
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include "stdio.h"
2+
#include "dill.h"
3+
4+
static int errors = 0;
5+
6+
static void check_i(int got, int expected) {
7+
if (got != expected) {
8+
printf("FAIL: got %d expected %d\n", got, expected);
9+
errors++;
10+
}
11+
}
12+
13+
static void check_l(long got, long expected) {
14+
if (got != expected) {
15+
printf("FAIL: got %ld expected %ld\n", got, expected);
16+
errors++;
17+
}
18+
}
19+
20+
static void noop7(void *a, void *b, void *c, int d, int e, int f, void *g) {
21+
volatile int x = d + e + f;
22+
(void)a; (void)b; (void)c; (void)g; (void)x;
23+
}
24+
25+
int main() {
26+
dill_stream s;
27+
dill_exec_handle h;
28+
dill_reg blk_reg, tmp, d1, d2;
29+
int blk;
30+
31+
/* Test 1: local block survives a function call */
32+
printf("Test 1: local block across call\n");
33+
s = dill_create_stream();
34+
dill_start_simple_proc(s, "t1", DILL_V);
35+
blk = dill_getvblock(s, 32);
36+
blk_reg = dill_getreg(s, DILL_P);
37+
tmp = dill_getreg(s, DILL_I);
38+
dill_virtual_lea(s, blk_reg, blk);
39+
dill_seti(s, tmp, 42);
40+
dill_stii(s, tmp, blk_reg, 0);
41+
dill_seti(s, tmp, 99);
42+
dill_stii(s, tmp, blk_reg, 4);
43+
44+
d1 = dill_getreg(s, DILL_P);
45+
d2 = dill_getreg(s, DILL_P);
46+
dill_setp(s, d1, 0);
47+
dill_setp(s, d2, 0);
48+
dill_scallv(s, (void*)noop7, "noop7",
49+
"%p%p%p%I%I%I%p", blk_reg, d1, d2, 1, 2, 3, blk_reg);
50+
51+
dill_ldii(s, tmp, blk_reg, 0);
52+
dill_scallv(s, (void*)check_i, "post", "%i%I", tmp, 42);
53+
dill_ldii(s, tmp, blk_reg, 4);
54+
dill_scallv(s, (void*)check_i, "chk", "%i%I", tmp, 99);
55+
56+
h = dill_finalize(s);
57+
((void(*)())dill_get_fp(h))();
58+
dill_free_handle(h);
59+
dill_free_stream(s);
60+
61+
/* Test 2: multiple local blocks, all survive calls */
62+
printf("Test 2: multiple local blocks across calls\n");
63+
s = dill_create_stream();
64+
dill_start_simple_proc(s, "t2", DILL_V);
65+
{
66+
int blk1 = dill_getvblock(s, 16);
67+
int blk2 = dill_getvblock(s, 16);
68+
dill_reg r1, r2, t;
69+
r1 = dill_getreg(s, DILL_P);
70+
r2 = dill_getreg(s, DILL_P);
71+
t = dill_getreg(s, DILL_I);
72+
dill_virtual_lea(s, r1, blk1);
73+
dill_virtual_lea(s, r2, blk2);
74+
75+
dill_seti(s, t, 111);
76+
dill_stii(s, t, r1, 0);
77+
dill_seti(s, t, 222);
78+
dill_stii(s, t, r2, 0);
79+
80+
d1 = dill_getreg(s, DILL_P);
81+
dill_setp(s, d1, 0);
82+
dill_scallv(s, (void*)noop7, "noop7",
83+
"%p%p%p%I%I%I%p", r1, d1, d1, 0, 0, 0, r2);
84+
85+
dill_ldii(s, t, r1, 0);
86+
dill_scallv(s, (void*)check_i, "chk", "%i%I", t, 111);
87+
dill_ldii(s, t, r2, 0);
88+
dill_scallv(s, (void*)check_i, "chk", "%i%I", t, 222);
89+
}
90+
h = dill_finalize(s);
91+
((void(*)())dill_get_fp(h))();
92+
dill_free_handle(h);
93+
dill_free_stream(s);
94+
95+
/* Test 3: long (8-byte) values in local block across call */
96+
printf("Test 3: long values in local block across call\n");
97+
s = dill_create_stream();
98+
dill_start_simple_proc(s, "t3", DILL_V);
99+
{
100+
int b = dill_getvblock(s, 16);
101+
dill_reg br, t;
102+
br = dill_getreg(s, DILL_P);
103+
t = dill_getreg(s, DILL_L);
104+
dill_virtual_lea(s, br, b);
105+
dill_setl(s, t, (IMM_TYPE)0x123456789ABCDEF0LL);
106+
dill_stli(s, t, br, 0);
107+
108+
d1 = dill_getreg(s, DILL_P);
109+
dill_setp(s, d1, 0);
110+
dill_scallv(s, (void*)noop7, "noop7",
111+
"%p%p%p%I%I%I%p", br, d1, d1, 0, 0, 0, d1);
112+
113+
dill_ldli(s, t, br, 0);
114+
dill_scallv(s, (void*)check_l, "chk", "%l%L",
115+
t, (IMM_TYPE)0x123456789ABCDEF0LL);
116+
}
117+
h = dill_finalize(s);
118+
((void(*)())dill_get_fp(h))();
119+
dill_free_handle(h);
120+
dill_free_stream(s);
121+
122+
if (errors == 0) {
123+
printf("No errors!\n");
124+
} else {
125+
printf("%d errors\n", errors);
126+
}
127+
return errors != 0;
128+
}

0 commit comments

Comments
 (0)