diff options
author | Mihails Strasuns <mihails.strasuns@intel.com> | 2020-02-17 11:36:47 +0100 |
---|---|---|
committer | Mihails Strasuns <mihails.strasuns@intel.com> | 2020-05-12 09:52:46 +0200 |
commit | 80ad340c90234f7294ee71468c984e7f853d9bb6 (patch) | |
tree | a3c2677b51aa3c0eaa7eddc6e082e7f65e3833da /gdb/testsuite/gdb.base | |
parent | f80120719777e671e871434d727716355d6ab57d (diff) | |
download | binutils-gdb-80ad340c90234f7294ee71468c984e7f853d9bb6.tar.gz |
[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/gdb.base')
-rw-r--r-- | gdb/testsuite/gdb.base/jit-elf-main.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/gdb/testsuite/gdb.base/jit-elf-main.c b/gdb/testsuite/gdb.base/jit-elf-main.c index acfd17d4179..be7185ef1a1 100644 --- a/gdb/testsuite/gdb.base/jit-elf-main.c +++ b/gdb/testsuite/gdb.base/jit-elf-main.c @@ -51,20 +51,16 @@ usage (void) exit (1); } -/* Update .p_vaddr and .sh_addr as if the code was JITted to ADDR. */ +/* Rename jit_function_XXXX to match idx */ static void -update_locations (const void *const addr, int idx) +update_name (const void *const addr, int idx) { const ElfW (Ehdr) *const ehdr = (ElfW (Ehdr) *)addr; ElfW (Shdr) *const shdr = (ElfW (Shdr) *)((char *)addr + ehdr->e_shoff); ElfW (Phdr) *const phdr = (ElfW (Phdr) *)((char *)addr + ehdr->e_phoff); int i; - for (i = 0; i < ehdr->e_phnum; ++i) - if (phdr[i].p_type == PT_LOAD) - phdr[i].p_vaddr += (ElfW (Addr))addr; - for (i = 0; i < ehdr->e_shnum; ++i) { if (shdr[i].sh_type == SHT_STRTAB) @@ -81,9 +77,6 @@ update_locations (const void *const addr, int idx) if (strcmp (p, "jit_function_XXXX") == 0) sprintf (p, "jit_function_%04d", idx); } - - if (shdr[i].sh_flags & SHF_ALLOC) - shdr[i].sh_addr += (ElfW (Addr))addr; } } @@ -96,6 +89,15 @@ update_locations (const void *const addr, int idx) #define MAIN main #endif +/* Must be defined by .exp file when compiling to know + what address to map the ELF binary to. */ +#ifndef LOAD_ADDRESS +#error "Must define LOAD_ADDRESS" +#endif +#ifndef LOAD_INCREMENT +#error "Must define LOAD_INCREMENT" +#endif + /* Used to spin waiting for GDB. */ volatile int wait_for_gdb = ATTACH; #define WAIT_FOR_GDB do {} while (wait_for_gdb) @@ -139,8 +141,9 @@ MAIN (int argc, char *argv[]) exit (1); } - const void *const addr = mmap (0, st.st_size, PROT_READ|PROT_WRITE, - MAP_PRIVATE, fd, 0); + void *load_addr = (void *) (size_t) (LOAD_ADDRESS + (i - 1) * LOAD_INCREMENT); + const void *const addr = mmap (load_addr, st.st_size, PROT_READ|PROT_WRITE, + MAP_PRIVATE | MAP_FIXED, fd, 0); struct jit_code_entry *const entry = calloc (1, sizeof (*entry)); if (addr == MAP_FAILED) @@ -149,7 +152,7 @@ MAIN (int argc, char *argv[]) exit (1); } - update_locations (addr, i); + update_name (addr, i); /* Link entry at the end of the list. */ entry->symfile_addr = (const char *)addr; |