]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/lib/jit-elf-helpers.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / jit-elf-helpers.exp
CommitLineData
213516ef 1# Copyright 2020-2023 Free Software Foundation, Inc.
f8012071
MS
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
80ad340c
MS
16# Magic constants used to calculate a starting address when linking
17# "jit" shared libraries. When loaded, will be mapped by jit-elf-main
18# to the same address.
19
20set jit_load_address 0x7000000
21set jit_load_increment 0x1000000
22
f8012071
MS
23# Compile jit-elf-main.c as an executable.
24#
25# BINSUFFIX is appended to the binary name.
26# OPTIONS is passed to gdb_compile when compiling the program.
27#
28# On success, return 0.
29# On failure, return -1.
30proc compile_jit_main {main_srcfile main_binfile options} {
80ad340c
MS
31 global jit_load_address jit_load_increment
32
33 set options [concat \
34 $options \
35 additional_flags=-DLOAD_ADDRESS=$jit_load_address \
36 additional_flags=-DLOAD_INCREMENT=$jit_load_increment \
37 debug]
f8012071
MS
38
39 if { [gdb_compile ${main_srcfile} ${main_binfile} \
1b59ca1c
TV
40 executable $options] != "" } {
41 set f [file tail $main_binfile]
42 untested "failed to compile $f"
43 return -1
f8012071
MS
44 }
45
46 return 0
47}
48
49# Compile jit-elf-main.c as a shared library.
50#
51# OPTIONS is passed to gdb_compile when compiling the program.
52#
53# On success, return 0.
54# On failure, return -1.
55proc compile_jit_elf_main_as_so {main_solib_srcfile main_solib_binfile options} {
80ad340c
MS
56 global jit_load_address jit_load_increment
57
4281b0c8
TV
58 set options [concat \
59 $options \
80ad340c
MS
60 additional_flags=-DLOAD_ADDRESS=$jit_load_address \
61 additional_flags=-DLOAD_INCREMENT=$jit_load_increment \
62 debug]
f8012071
MS
63
64 if { [gdb_compile_shlib ${main_solib_srcfile} ${main_solib_binfile} \
1b59ca1c
TV
65 $options] != "" } {
66 set f [file tail $main_solib_binfile]
67 untested "failed to compile shared library $f"
f8012071
MS
68 return -1
69 }
70
71 return 0
72}
73
74# Compile jit-elf-solib.c as a shared library in multiple copies and
75# upload them to the target.
76#
66984afd
AB
77# OPTIONS_LIST is a list of additional options to pass through to
78# gdb_compile_shlib.
79#
f8012071
MS
80# On success, return a list of target path to the shared libraries.
81# On failure, return -1.
66984afd
AB
82proc compile_and_download_n_jit_so {jit_solib_basename jit_solib_srcfile \
83 count {options_list {}}} {
80ad340c 84 global jit_load_address jit_load_increment
f8012071
MS
85 set binfiles_target {}
86
87 for {set i 1} {$i <= $count} {incr i} {
88 set binfile [standard_output_file ${jit_solib_basename}.$i.so]
89
90 # Note: compiling without debug info by default: some test
91 # do symbol renaming by munging on ELF symbol table, and that
92 # wouldn't work for .debug sections. Also, output for "info
93 # function" changes when debug info is present.
80ad340c 94 set addr [format 0x%x [expr $jit_load_address + $jit_load_increment * [expr $i-1]]]
2bb8c72b
VB
95
96 # Use "text_segment=..." to ask the linker to relocate everything in the
97 # compiled shared library against a fixed base address. Combined
80ad340c
MS
98 # with mapping the resulting binary to the same fixed base it allows
99 # to dynamically execute functions from it without any further adjustments.
66984afd 100 set fname [format "jit_function_%04d" $i]
80ad340c 101 set options [list \
66984afd
AB
102 ${options_list} \
103 additional_flags=-DFUNCTION_NAME=$fname \
104 text_segment=$addr]
1b59ca1c
TV
105 if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} \
106 $options] != "" } {
107 set f [file tail $binfile]
8f7d38ef 108 untested "failed to compile shared library $f"
f8012071
MS
109 return -1
110 }
111
112 set path [gdb_remote_download target ${binfile}]
113 lappend binfiles_target $path
114 }
115
116 return $binfiles_target
1b59ca1c 117}