This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] compile: Fix function pointers
- From: Jan Kratochvil <jkratoch at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 22 Jan 2015 18:20:06 -0000
- Subject: [binutils-gdb] compile: Fix function pointers
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4b62a76e0cd716407859077467fddbb66b715a43
commit 4b62a76e0cd716407859077467fddbb66b715a43
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Thu Jan 22 19:18:16 2015 +0100
compile: Fix function pointers
TBH while I always comment reasons for each of the compilation options in
reality I tried them all and chose that combination that needs the most simple
compile/compile-object-load.c (ld.so emulation) implementation.
gdb/ChangeLog
2015-01-22 Jan Kratochvil <jan.kratochvil@redhat.com>
* compile/compile.c (_initialize_compile): Use -fPIE for compile_args.
gdb/testsuite/ChangeLog
2015-01-22 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.compile/compile.exp (pointer to jit function): New test.
Diff:
---
gdb/ChangeLog | 4 ++++
gdb/compile/compile.c | 7 ++++---
gdb/testsuite/ChangeLog | 4 ++++
gdb/testsuite/gdb.compile/compile.exp | 5 +++++
4 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 06be4ed..fecedeb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2015-01-22 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ * compile/compile.c (_initialize_compile): Use -fPIE for compile_args.
+
2015-01-22 Eli Zaretskii <eliz@gnu.org>
* Makefile.in (HFILES_NO_SRCDIR): Remove ada-varobj.h.
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index ccac49d..70b6d44 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -645,12 +645,13 @@ String quoting is parsed like in shell, for example:\n\
/* Override flags possibly coming from DW_AT_producer. */
compile_args = xstrdup ("-O0 -gdwarf-4"
- /* We use -fPIC Otherwise GDB would need to reserve space large enough for
+ /* We use -fPIE Otherwise GDB would need to reserve space large enough for
any object file in the inferior in advance to get the final address when
to link the object file to and additionally the default system linker
script would need to be modified so that one can specify there the
- absolute target address. */
- " -fPIC"
+ absolute target address.
+ -fPIC is not used at is would require from GDB to generate .got. */
+ " -fPIE"
/* We don't want warnings. */
" -w"
/* Override CU's possible -fstack-protector-strong. */
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9dd10f0..b01a4c9 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2015-01-22 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ * gdb.compile/compile.exp (pointer to jit function): New test.
+
2015-01-17 Wei-cheng Wang <cole945@gmail.com>
* lib/gdb.exp (supports_process_record): Return true for
diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp
index e426cc1..dc09770 100644
--- a/gdb/testsuite/gdb.compile/compile.exp
+++ b/gdb/testsuite/gdb.compile/compile.exp
@@ -259,6 +259,11 @@ gdb_test_no_output "end" "compile code -r multiline 4"
gdb_test "print 'compile.c'::globalshadow" " = 77000" \
"check globalshadow with -r"
+# Test GOT vs. resolving jit function pointers.
+
+gdb_test_no_output "compile -raw -- int func(){return 21;} _gdb_expr(){int (*funcp)()=func; if (funcp()!=21) abort();}" \
+ "pointer to jit function"
+
#
# Test the case where the registers structure would not normally have
# any fields.