[PATCH] bpf: several small fixes in the simulator

Jose E. Marchesi jose.marchesi@oracle.com
Thu Sep 3 14:27:43 GMT 2020


This patch fixes the following problems:
- Missing includes in several files leading to implicit function
  declarations.
- Missing prototype for bpf_trace_printk in bpf-helpers.h
- The simulator bitsize was set to 32 bits, causing truncation of
  the program counter.

Tested in bpf-unknown-none.

sim/ChangeLog:

2020-09-03  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* bpf/bpf.c: Include bpf-helpers.h.
	* bpf/bpf-helpers.h: Provide a prototype for bpf_trace_printk.
	* bpf/configure.ac: Set simulator bitsize to 64.
	* bpf/configure: Regenerate.
	* bpf/sim-if.c: Include stdlib.h.
	* bpf/traps.c: Likewise.
---
 sim/ChangeLog         |  9 ++++++
 sim/bpf/bpf-helpers.h |  2 +-
 sim/bpf/bpf.c         |  1 +
 sim/bpf/configure     | 65 +++++++++++++++++++++++++++++++++++++++++--
 sim/bpf/configure.ac  |  1 +
 sim/bpf/sim-if.c      |  2 ++
 sim/bpf/traps.c       |  2 ++
 7 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/sim/bpf/bpf-helpers.h b/sim/bpf/bpf-helpers.h
index fe9413f266..021649cb02 100644
--- a/sim/bpf/bpf-helpers.h
+++ b/sim/bpf/bpf-helpers.h
@@ -26,6 +26,6 @@ enum bpf_kernel_helper
 #undef DEF_HELPER
   };
 
-/* void bpf_trace_printk (const char *fmt); */
+void bpf_trace_printk (SIM_CPU *current_cpu);
 
 #endif /* ! BPF_HELPERS_H */
diff --git a/sim/bpf/bpf.c b/sim/bpf/bpf.c
index 0fb8d81c46..f413b36ab4 100644
--- a/sim/bpf/bpf.c
+++ b/sim/bpf/bpf.c
@@ -27,6 +27,7 @@
 #include "decode.h"
 
 #include "defs-le.h"  /* For SCACHE */
+#include "bpf-helpers.h"
 
 /* It is not possible to include both defs-le.h and defs-be.h due to
    duplicated definitions, so we need a bunch of forward declarations
diff --git a/sim/bpf/configure b/sim/bpf/configure
index 7125c50ff1..34e70693a4 100755
--- a/sim/bpf/configure
+++ b/sim/bpf/configure
@@ -782,6 +782,7 @@ enable_sim_environment
 enable_sim_inline
 with_pkgversion
 with_bugurl
+enable_sim_bitsize
 enable_sim_endian
 enable_sim_alignment
 enable_sim_scache
@@ -1436,6 +1437,7 @@ Optional Features:
                           environment
   --enable-sim-inline=inlines
                           Specify which functions should be inlined
+  --enable-sim-bitsize=N  Specify target bitsize (32 or 64)
   --enable-sim-endian=endian
                           Specify target byte endian orientation
   --enable-sim-alignment=align
@@ -12882,7 +12884,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12885 "configure"
+#line 12899 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12988,7 +12990,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12991 "configure"
+#line 13005 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13539,6 +13541,65 @@ _ACEOF
 
 
 
+wire_word_bitsize="64"
+wire_word_msb=""
+wire_address_bitsize=""
+wire_cell_bitsize=""
+# Check whether --enable-sim-bitsize was given.
+if test "${enable_sim_bitsize+set}" = set; then :
+  enableval=$enable_sim_bitsize; sim_bitsize=
+case "${enableval}" in
+  64,63 | 64,63,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=63";;
+  32,31 | 32,31,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=31";;
+  64,0 | 64,0,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0";;
+  32,0 | 64,0,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0";;
+  32) if test x"$wire_word_msb" != x -a x"$wire_word_msb" != x0; then
+        sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=31"
+      else
+        sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0"
+      fi ;;
+  64) if test x"$wire_word_msb" != x -a x"$wire_word_msb" != x0; then
+        sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=63"
+      else
+        sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=0"
+      fi ;;
+  *)  as_fn_error $? "\"--enable-sim-bitsize was given $enableval.  Expected 32 or 64\"" "$LINENO" 5 ;;
+esac
+# address bitsize
+tmp=`echo "${enableval}" | sed -e "s/^[0-9]*,*[0-9]*,*//"`
+case x"${tmp}" in
+  x ) ;;
+  x32 | x32,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_ADDRESS_BITSIZE=32" ;;
+  x64 | x64,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_ADDRESS_BITSIZE=64" ;;
+  * ) as_fn_error $? "\"--enable-sim-bitsize was given address size $enableval.  Expected 32 or 64\"" "$LINENO" 5 ;;
+esac
+# cell bitsize
+tmp=`echo "${enableval}" | sed -e "s/^[0-9]*,*[0-9*]*,*[0-9]*,*//"`
+case x"${tmp}" in
+  x ) ;;
+  x32 | x32,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_CELL_BITSIZE=32" ;;
+  x64 | x64,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_CELL_BITSIZE=64" ;;
+  * ) as_fn_error $? "\"--enable-sim-bitsize was given cell size $enableval.  Expected 32 or 64\"" "$LINENO" 5 ;;
+esac
+if test x"$silent" != x"yes" && test x"$sim_bitsize" != x""; then
+  echo "Setting bitsize flags = $sim_bitsize" 6>&1
+fi
+else
+  sim_bitsize=""
+if test x"$wire_word_bitsize" != x; then
+  sim_bitsize="$sim_bitsize -DWITH_TARGET_WORD_BITSIZE=$wire_word_bitsize"
+fi
+if test x"$wire_word_msb" != x; then
+  sim_bitsize="$sim_bitsize -DWITH_TARGET_WORD_MSB=$wire_word_msb"
+fi
+if test x"$wire_address_bitsize" != x; then
+  sim_bitsize="$sim_bitsize -DWITH_TARGET_ADDRESS_BITSIZE=$wire_address_bitsize"
+fi
+if test x"$wire_cell_bitsize" != x; then
+  sim_bitsize="$sim_bitsize -DWITH_TARGET_CELL_BITSIZE=$wire_cell_bitsize"
+fi
+fi
+
 
 wire_endian=""
 default_endian="LITTLE"
diff --git a/sim/bpf/configure.ac b/sim/bpf/configure.ac
index 16ca54e86c..e7cd72a1c6 100644
--- a/sim/bpf/configure.ac
+++ b/sim/bpf/configure.ac
@@ -4,6 +4,7 @@ sinclude(../common/acinclude.m4)
 
 SIM_AC_COMMON
 
+SIM_AC_OPTION_BITSIZE([64])
 SIM_AC_OPTION_ENDIAN([], [LITTLE])
 SIM_AC_OPTION_ALIGNMENT(NONSTRICT_ALIGNMENT)
 SIM_AC_OPTION_SCACHE(16384)
diff --git a/sim/bpf/sim-if.c b/sim/bpf/sim-if.c
index fbb122b36e..e7e5de61df 100644
--- a/sim/bpf/sim-if.c
+++ b/sim/bpf/sim-if.c
@@ -16,6 +16,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include <stdlib.h>
+
 #include "sim-main.h"
 #include "sim-options.h"
 #include "libiberty.h"
diff --git a/sim/bpf/traps.c b/sim/bpf/traps.c
index e7ac0c2838..646db4a957 100644
--- a/sim/bpf/traps.c
+++ b/sim/bpf/traps.c
@@ -19,6 +19,8 @@
 #define WANT_CPU bpfbf
 #define WANT_CPU_BPFBF
 
+#include <stdlib.h>
+
 #include "sim-main.h"
 
 SEM_PC
-- 
2.25.0.2.g232378479e



More information about the Gdb-patches mailing list