3 # tests related to ELFinated .core files
5 # This software is part of the SBCL system. See the README file for
8 # While most of SBCL is derived from the CMU CL system, the test
9 # files (like this one) were written from scratch after the fork
12 # This software is in the public domain and is provided with
13 # absolutely no warranty. See the COPYING and CREDITS files for
19 #+(and linux x86-64 sb-thread)
20 (unless (member :immobile-space sb-impl:+internal-features+)
21 (exit :code 0)) ; proceed with test
22 (exit :code 2) ; otherwise skip the test
25 if [ $status != 0 ]; then # test can't be executed
26 # we don't have a way to exit shell tests with "inapplicable" as the result
30 set -e # exit on error
32 create_test_subdirectory
33 temp
=$TEST_DIRECTORY/$TEST_FILESTEM
35 run_sbcl
--load ..
/tools-for-build
/elftool \
36 --eval '(sb-editcore:move-dynamic-code-to-text-space "../output/sbcl.core" "'${temp}'-patched.core")' \
37 --eval '(sb-editcore:redirect-text-space-calls "'${temp}'-patched.core")' \
38 --eval '(sb-editcore:split-core "'${temp}'-patched.core" "'${temp}'-src.s")' --quit
40 m_arg
=`run_sbcl --eval '(progn #+sb-core-compression (princ " -lzstd") #+x86 (princ " -m32"))' --quit`
42 (cd ..
/src
/runtime
; make libsbcl.a
)
43 exefile
=$TEST_DIRECTORY/sbcl-new-elf
44 cc
-no-pie -o ${exefile} -Wl,--export-dynamic -Wl,-no-as-needed \
45 ${temp}-src.s ${temp}-src-core.o ../src/runtime/libsbcl.a -lm -ldl ${m_arg}
47 result
=`${exefile} --eval '(princ "Success")' --quit`
49 if [ "$result" = Success
]
51 echo "basic ELF: smoke test PASS"
55 result
=`${exefile} --eval '(defun fib (n) (if (<= n 1) 1 (+ (fib (- n 1)) (fib (- n 2)))))' \
56 --eval "(compile 'fib)" \
57 --eval "(if (equal (loop for i from 2 to 5 collect (fib i)) '(2 3 5 8)) (print 'ok))" --quit`
65 set +e
# no exit on error
66 ${exefile} --noprint n
<<EOF
68 (defun disassembly-contains-query-read-char ()
69 (search "FDEFN QUERY-READ-CHAR"
70 (with-output-to-string (ss) (disassemble 'y-or-n-p :stream ss))))
71 (assert (not (disassembly-contains-query-read-char)))
72 (defun query-read-char () #\y) ; will undo static linkage
73 (assert (disassembly-contains-query-read-char))
74 (if (let ((*query-io* (make-broadcast-stream))) (y-or-n-p)) (exit :code 42))
80 echo "Undo static linkage: PASS"