aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/lib/jit-elf-helpers.exp
diff options
context:
space:
mode:
authorMihails Strasuns <mihails.strasuns@intel.com>2020-02-17 11:36:47 +0100
committerMihails Strasuns <mihails.strasuns@intel.com>2020-05-12 09:52:46 +0200
commit80ad340c90234f7294ee71468c984e7f853d9bb6 (patch)
treea3c2677b51aa3c0eaa7eddc6e082e7f65e3833da /gdb/testsuite/lib/jit-elf-helpers.exp
parentf80120719777e671e871434d727716355d6ab57d (diff)
downloadgdb-80ad340c90234f7294ee71468c984e7f853d9bb6.zip
gdb-80ad340c90234f7294ee71468c984e7f853d9bb6.tar.gz
gdb-80ad340c90234f7294ee71468c984e7f853d9bb6.tar.bz2
[gdb/testsuite] use -Ttext-segment for jit-elf tests
Removes the need to manually relocate loaded ELF binary by using a fixed constant as both mmap base address and as a requested first segment address supplied to the linker. In future will enable JIT tests with a valid DWARF debug info. Current tests still need to compile without a debug info though, because they do a function name modification. gdb/testsuite/ChangeLog: 2020-02-18 Mihails Strasuns <mihails.strasuns@intel.com> * lib/jit-elf-helpers.exp: Supply -Ttext-segment linker flag and define LOAD_ADDRESS/LOAD_INCREMENT macros for the compiled binaries. * gdb.base/jit-elf-main.c: Use LOAD_ADDRESS/LOAD_INCREMENT to calculate the mmap address.
Diffstat (limited to 'gdb/testsuite/lib/jit-elf-helpers.exp')
-rw-r--r--gdb/testsuite/lib/jit-elf-helpers.exp34
1 files changed, 31 insertions, 3 deletions
diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp
index 91b64f2..032417b 100644
--- a/gdb/testsuite/lib/jit-elf-helpers.exp
+++ b/gdb/testsuite/lib/jit-elf-helpers.exp
@@ -13,6 +13,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# Magic constants used to calculate a starting address when linking
+# "jit" shared libraries. When loaded, will be mapped by jit-elf-main
+# to the same address.
+
+set jit_load_address 0x7000000
+set jit_load_increment 0x1000000
+
# Compile jit-elf-main.c as an executable.
#
# BINSUFFIX is appended to the binary name.
@@ -21,7 +28,13 @@
# On success, return 0.
# On failure, return -1.
proc compile_jit_main {main_srcfile main_binfile options} {
- set options [concat $options debug]
+ global jit_load_address jit_load_increment
+
+ set options [concat \
+ $options \
+ additional_flags=-DLOAD_ADDRESS=$jit_load_address \
+ additional_flags=-DLOAD_INCREMENT=$jit_load_increment \
+ debug]
if { [gdb_compile ${main_srcfile} ${main_binfile} \
executable $options] != "" } {
@@ -39,7 +52,13 @@ proc compile_jit_main {main_srcfile main_binfile options} {
# On success, return 0.
# On failure, return -1.
proc compile_jit_elf_main_as_so {main_solib_srcfile main_solib_binfile options} {
- set options [concat $options debug]
+ global jit_load_address jit_load_increment
+
+ set options [list \
+ additional_flags="-DMAIN=jit_dl_main" \
+ additional_flags=-DLOAD_ADDRESS=$jit_load_address \
+ additional_flags=-DLOAD_INCREMENT=$jit_load_increment \
+ debug]
if { [gdb_compile_shlib ${main_solib_srcfile} ${main_solib_binfile} \
$options] != "" } {
@@ -56,6 +75,7 @@ proc compile_jit_elf_main_as_so {main_solib_srcfile main_solib_binfile options}
# On success, return a list of target path to the shared libraries.
# On failure, return -1.
proc compile_and_download_n_jit_so {jit_solib_basename jit_solib_srcfile count} {
+ global jit_load_address jit_load_increment
set binfiles_target {}
for {set i 1} {$i <= $count} {incr i} {
@@ -65,7 +85,15 @@ proc compile_and_download_n_jit_so {jit_solib_basename jit_solib_srcfile count}
# do symbol renaming by munging on ELF symbol table, and that
# wouldn't work for .debug sections. Also, output for "info
# function" changes when debug info is present.
- if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} {}] != "" } {
+ set addr [format 0x%x [expr $jit_load_address + $jit_load_increment * [expr $i-1]]]
+ # Using -Ttext-segment flag to ask linked to relocate everything
+ # in the compiled shared library against a fixed base address. Combined
+ # with mapping the resulting binary to the same fixed base it allows
+ # to dynamically execute functions from it without any further adjustments.
+ set options [list \
+ additional_flags=-Xlinker \
+ additional_flags=-Ttext-segment=$addr]
+ if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} $options] != "" } {
untested "failed to compile ${jit_solib_basename}.c as a shared library"
return -1
}