summaryrefslogtreecommitdiff
path: root/tests/fixtures/shared-libs
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-09 18:00:15 +0300
committerkx <kx@radix-linux.su>2026-10-09 18:00:15 +0300
commit065da3509019b15dd0e678072e6be629e5330bef (patch)
tree69c934c9e786ac048b4fbe8f4c4c5571661521f4 /tests/fixtures/shared-libs
parentd130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff)
downloadlibmcpu-0.4.0.tar.xz
Version 0.4.00.4.0
Diffstat (limited to 'tests/fixtures/shared-libs')
-rw-r--r--tests/fixtures/shared-libs/dynamic-liba.s18
-rw-r--r--tests/fixtures/shared-libs/dynamic-libb.s18
-rw-r--r--tests/fixtures/shared-libs/dynamic-main.s35
3 files changed, 71 insertions, 0 deletions
diff --git a/tests/fixtures/shared-libs/dynamic-liba.s b/tests/fixtures/shared-libs/dynamic-liba.s
new file mode 100644
index 0000000..f35cfe2
--- /dev/null
+++ b/tests/fixtures/shared-libs/dynamic-liba.s
@@ -0,0 +1,18 @@
+; Build/run from examples/shared-libs/:
+; make
+; make run
+;
+; make run prints, in order:
+; 43
+; 43
+; 42
+; 42
+; 41
+;
+; Shared-library implementation of foo: adds 2.
+.global foo
+.text
+foo:
+ LDI r64@0x00008, 2
+ IADD r64@0x00000, r64@0x00000, r64@0x00008
+ RET
diff --git a/tests/fixtures/shared-libs/dynamic-libb.s b/tests/fixtures/shared-libs/dynamic-libb.s
new file mode 100644
index 0000000..348b358
--- /dev/null
+++ b/tests/fixtures/shared-libs/dynamic-libb.s
@@ -0,0 +1,18 @@
+; Build/run from examples/shared-libs/:
+; make
+; make run
+;
+; make run prints, in order:
+; 43
+; 43
+; 42
+; 42
+; 41
+;
+; Shared-library implementation of foo: adds 3.
+.global foo
+.text
+foo:
+ LDI r64@0x00008, 3
+ IADD r64@0x00000, r64@0x00000, r64@0x00008
+ RET
diff --git a/tests/fixtures/shared-libs/dynamic-main.s b/tests/fixtures/shared-libs/dynamic-main.s
new file mode 100644
index 0000000..f296429
--- /dev/null
+++ b/tests/fixtures/shared-libs/dynamic-main.s
@@ -0,0 +1,35 @@
+; Build/run from examples/shared-libs/:
+; make
+; make run
+;
+; make run prints, in order:
+; 43
+; 43
+; 42
+; 42
+; 41
+;
+; ABI-v2 startup-dynamic executable example.
+; main-program itself defines foo(), but cpu-ld --dynamic retains CALL foo as
+; a preemptible runtime relocation. cpu-run --ldpreload can therefore replace
+; it before _start executes.
+;
+; Without preload: foo adds 1 -> result 41.
+; With dynamic-liba.so: foo adds 2 -> result 42.
+; With dynamic-liba.so:dynamic-libb.so: rightmost strong GLOBAL wins, so
+; dynamic-libb.so foo adds 3 -> result 43.
+.global _life
+.global foo
+
+.text
+_start_life:
+ LDI r64@0x00000, 40
+ CALL foo
+ MOV r64@0x00018, r64@0x00000
+ LDI r32@0x00030, 0
+ EXIT r32@0x00030
+
+foo:
+ LDI r64@0x00008, 1
+ IADD r64@0x00000, r64@0x00000, r64@0x00008
+ RET