safepoint: Remove unused context argument.
[sbcl.git] / tests / elfcore.test.sh
blobfe3b550ebb7a7c9e7302fb9004946ac389b3deea
1 #!/bin/sh
3 # tests related to ELFinated .core files
5 # This software is part of the SBCL system. See the README file for
6 # more information.
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
10 # from CMU CL.
12 # This software is in the public domain and is provided with
13 # absolutely no warranty. See the COPYING and CREDITS files for
14 # more information.
16 . ./subr.sh
18 run_sbcl <<EOF
19 #+(and linux elf sb-thread)
20 (let ((s (find-symbol "IMMOBILE-SPACE-OBJ-P" "SB-KERNEL")))
21 (when (and s (funcall s #'car)) (exit :code 0))) ; good
22 (exit :code 2) ; otherwise
23 EOF
24 status=$?
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
27 exit $EXIT_TEST_WIN
30 set -e # exit on error
32 # Ensure that we're not running a stale shrinkwrap-sbcl
33 (cd $SBCL_PWD/../src/runtime ; rm -f shrinkwrap-sbcl ; make shrinkwrap-sbcl)
35 # Prevent style-warnings in the editcore script, but don't assume that it
36 # can be compiled in the first place unless actually doing the ELFcore tests.
37 run_sbcl <<EOF
38 (let ((*evaluator-mode* :interpret))
39 (load "../tests/test-util")
40 (load "../tools-for-build/corefile"))
41 (test-util:with-scratch-file (fasl "fasl")
42 (assert (not (nth-value 1
43 (compile-file "../tools-for-build/editcore"
44 :output-file fasl :print nil)))))
45 EOF
47 $SBCL_PWD/../src/runtime/shrinkwrap-sbcl --disable-debugger --no-sysinit --no-userinit --noprint <<EOF
48 (sb-vm::make-immobile-symbol "junk") ; crashed 'cause I forgot to use rip-relative-EA
49 ;; I think this tests immobile space exhaustion
50 (dotimes (i 100000) (sb-vm::alloc-immobile-fdefn))
52 ;; Test that the link step did not use --export-dynamic
53 (assert (gethash '("TEXT_SPACE_START") (car sb-sys:*linkage-info*))) ; C symbol exists
54 ; but dlsym() can't see it
55 (assert (not (sb-sys:find-dynamic-foreign-symbol-address "TEXT_SPACE_START")))
56 ; but we can read the value
57 (assert (funcall (compile nil '(lambda () sb-vm:text-space-start))))
59 ;; Test that CODE-SERIAL# is never 0 except for simple-fun-less objects
60 (sb-vm:map-allocated-objects
61 (lambda (obj type size)
62 (declare (ignore size))
63 (when (and (= type sb-vm:code-header-widetag)
64 (> (sb-kernel:code-n-entries obj) 0))
65 (assert (/= (sb-kernel:%code-serialno obj) 0))))
66 :all)
67 ;; This just needs any function that when ELFinated has its packed fixups rewritten.
68 ;; If the packed value is a bignum, it goes into a C data section.
69 (let* ((code (sb-kernel:fun-code-header #'compile-file))
70 (fixups (sb-vm::%code-fixups code)))
71 (assert (typep fixups 'bignum))
72 (assert (not (heap-allocated-p fixups))))
73 EOF
74 (cd $SBCL_PWD/../src/runtime ; rm -f shrinkwrap-sbcl shrinkwrap-sbcl.s shrinkwrap-sbcl-core.o shrinkwrap-sbcl.core)
76 # reaching here means no crash happened in the allocator
77 # and that the fixups were rewritten into C data space
78 echo Basic smoke test: PASS
80 create_test_subdirectory
81 tmpcore=$TEST_DIRECTORY/$TEST_FILESTEM.tmpcore
83 run_sbcl <<EOF
84 (setq sb-c:*compile-to-memory-space* :dynamic)
85 ;; Call an assembly routine from dynamic space
86 (defun f (x y z) (+ x (- y z)))
87 (compile 'f)
88 ;; :AUTO physically allocates code in immobile space (unless it fills up)
89 ;; using instruction forms that do not assume immobile space
90 ;; (for that same reason) which caused a glitch in editcore.
91 (setq sb-c:*compile-to-memory-space* :auto)
92 (defun g (fun &rest args) (apply fun args)) ; exercise TAIL-CALL-VARIABLE
93 (compile 'g)
94 (save-lisp-and-die "${tmpcore}")
95 EOF
97 m_arg=`run_sbcl --eval '(progn #+sb-core-compression (princ " -lzstd") #+x86 (princ " -m32"))' --quit`
99 (cd $SBCL_PWD/../src/runtime ; rm -f libsbcl.a; make libsbcl.a)
100 run_sbcl --script ../tools-for-build/editcore.lisp split \
101 ${tmpcore} $TEST_DIRECTORY/elfcore-test.s
102 # I guess we're going to have to hardwire the system libraries
103 # until I can figure out how to get a Makefile to work, which is fine
104 # for now because elfination is only supported on linux/x86-64.
105 ./run-compiler.sh -no-pie -g -o $TEST_DIRECTORY/elfcore-test \
106 $TEST_DIRECTORY/elfcore-test.s \
107 $TEST_DIRECTORY/elfcore-test-core.o \
108 $SBCL_PWD/../src/runtime/libsbcl.a -lm -lpthread ${m_arg}
110 $TEST_DIRECTORY/elfcore-test $SBCL_ARGS --eval '(assert (zerop (f 1 2 3)))' --quit
111 echo Custom core: PASS
113 ./run-compiler.sh -no-pie -g -o $TEST_DIRECTORY/relocating-elfcore-test \
114 $TEST_DIRECTORY/elfcore-test.s \
115 $TEST_DIRECTORY/elfcore-test-core.o \
116 $SBCL_PWD/../tests/heap-reloc/fake-mman.c \
117 $SBCL_PWD/../src/runtime/libsbcl.a -lm -lpthread ${m_arg}
119 (cd $SBCL_PWD/../src/runtime ; rm -f libsbcl.a)
121 export SBCL_FAKE_MMAP_INSTRUCTION_FILE=heap-reloc/fakemap
123 while [ $i -le 6 ]
125 echo Trial $i
126 i=`expr $i + 1`
127 $TEST_DIRECTORY/relocating-elfcore-test $SBCL_ARGS --eval '(assert (zerop (f 1 2 3)))' --quit
128 done
130 exit $EXIT_TEST_WIN