ARM support added 62/148062/2
authorRafal Pietruch <r.pietruch@samsung.com>
Thu, 29 Jun 2017 09:09:35 +0000 (11:09 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 8 Sep 2017 09:38:16 +0000 (11:38 +0200)
* fix compilation errors on 32bit systems regarding int128
* add function calling convention for ARM (R0-R3) as defined
  in "Procedure Call Standard for the ARM Architecture"
* disable including kernel header files with ARM assembly code
  as for arm64 (https://patchwork.kernel.org/patch/7605601/)
* provide BPF syscall number for ARM (386)
  as defined in kernel src: linux/arch/arm/tools/syscall.tbl
* create clang driver for armv7l-tizen-linux-gnueabi triple
* fix libbcc python/C wrapper with proper arguments types
* define generic PT_REGS macros for ARM

Change-Id: Ifbd2ea3f18a8851e8b93b6936548b097bbe66ef7

src/cc/export/helpers.h
src/cc/frontends/b/type_helper.h
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/kbuild_helper.cc
src/cc/frontends/clang/loader.cc
src/cc/libbpf.c
src/python/bcc/libbcc.py

index 4b982ce..4b6b947 100644 (file)
@@ -329,10 +329,12 @@ u64 bpf_ntohll(u64 val) {
   return __builtin_bswap64(val);
 }
 
+#ifdef __SIZEOF_INT128__
 static inline __attribute__((always_inline))
 unsigned __int128 bpf_ntoh128(unsigned __int128 val) {
   return (((unsigned __int128)bpf_ntohll(val) << 64) | (u64)bpf_ntohll(val >> 64));
 }
+#endif
 
 static inline __attribute__((always_inline))
 u16 bpf_htons(u16 val) {
@@ -349,10 +351,12 @@ u64 bpf_htonll(u64 val) {
   return bpf_ntohll(val);
 }
 
+#ifdef __SIZEOF_INT128__
 static inline __attribute__((always_inline))
 unsigned __int128 bpf_hton128(unsigned __int128 val) {
   return bpf_ntoh128(val);
 }
+#endif
 
 static inline __attribute__((always_inline))
 u64 load_dword(void *skb, u64 off) {
@@ -371,7 +375,9 @@ bpf_store_dword(void *skb, u64 off, u64 val) {
 }
 
 #define MASK(_n) ((_n) < 64 ? (1ull << (_n)) - 1 : ((u64)-1LL))
+#ifdef __SIZEOF_INT128__
 #define MASK128(_n) ((_n) < 128 ? ((unsigned __int128)1 << (_n)) - 1 : ((unsigned __int128)-1))
+#endif
 
 static inline __attribute__((always_inline))
 unsigned int bpf_log2(unsigned int v)
@@ -388,7 +394,7 @@ unsigned int bpf_log2(unsigned int v)
 }
 
 static inline __attribute__((always_inline))
-unsigned int bpf_log2l(unsigned long v)
+unsigned int bpf_log2l(unsigned long long v)
 {
   unsigned int hi = v >> 32;
   if (hi)
@@ -566,6 +572,18 @@ int bpf_usdt_readarg_p(int argc, struct pt_regs *ctx, void *buf, u64 len) asm("l
 #define PT_REGS_RC(x)          ((x)->regs[0])
 #define PT_REGS_SP(x)          ((x)->sp)
 #define PT_REGS_IP(x)          ((x)->pc)
+#elif defined(__arm__)
+#define PT_REGS_PARM1(x)       ((x)->uregs[0])
+#define PT_REGS_PARM2(x)       ((x)->uregs[1])
+#define PT_REGS_PARM3(x)       ((x)->uregs[2])
+#define PT_REGS_PARM4(x)       ((x)->uregs[3])
+#define PT_REGS_PARM5(x)       ((x)->uregs[4])
+#define PT_REGS_PARM6(x)       ((x)->uregs[5])
+#define PT_REGS_RET(x)         ((x)->uregs[14])
+#define PT_REGS_FP(x)          ((x)->uregs[11])
+#define PT_REGS_RC(x)          ((x)->uregs[0])
+#define PT_REGS_SP(x)          ((x)->uregs[13])
+#define PT_REGS_IP(x)          ((x)->uregs[12])
 #else
 #error "bcc does not support this platform yet"
 #endif
index 45e5e33..2daab70 100644 (file)
@@ -36,7 +36,9 @@ static inline size_t enum_to_size(const FieldType t) {
     case UINT16_T: return sizeof(uint16_t);
     case UINT32_T: return sizeof(uint32_t);
     case UINT64_T: return sizeof(uint64_t);
+#ifdef __SIZEOF_INT128__
     case UINT128_T: return sizeof(__uint128_t);
+#endif
     default:
       return 0;
   }
index 29e6d31..63969bb 100644 (file)
@@ -45,6 +45,10 @@ const char *calling_conv_regs_s390x[] = {"gprs[2]", "gprs[3]", "gprs[4]",
 
 const char *calling_conv_regs_arm64[] = {"regs[0]", "regs[1]", "regs[2]",
                                        "regs[3]", "regs[4]", "regs[5]"};
+
+const char *calling_conv_regs_arm[] = {"uregs[0]", "uregs[1]", "uregs[2]",
+                                       "uregs[3]"};
+
 // todo: support more archs
 #if defined(__powerpc__)
 const char **calling_conv_regs = calling_conv_regs_ppc;
@@ -52,6 +56,8 @@ const char **calling_conv_regs = calling_conv_regs_ppc;
 const char **calling_conv_regs = calling_conv_regs_s390x;
 #elif defined(__aarch64__)
 const char **calling_conv_regs = calling_conv_regs_arm64;
+#elif defined(__arm__)
+const char **calling_conv_regs = calling_conv_regs_arm;
 #else
 const char **calling_conv_regs = calling_conv_regs_x86;
 #endif
index 0c0f58d..62d1e94 100644 (file)
@@ -40,6 +40,11 @@ int KBuildHelper::get_flags(const char *uname_machine, vector<string> *cflags) {
     arch = "x86";
   } else if (!strncmp(uname_machine, "arm", 3)) {
     arch = "arm";
+    // disable including kernel header files with assembly code
+    // as there is no assembly parser for ARM implemented yet
+    // same for arm64 arch: https://patchwork.kernel.org/patch/7605601/
+    cflags->push_back("-D__ASM_SYSREG_H");
+    cflags->push_back("-D__LINUX_ARM_ARCH__=7");
   } else if (!strncmp(uname_machine, "sa110", 5)) {
     arch = "arm";
   } else if (!strncmp(uname_machine, "s390x", 5)) {
index 5c1f8be..c255dba 100644 (file)
@@ -186,6 +186,8 @@ int ClangLoader::parse(unique_ptr<llvm::Module> *mod, TableStorage &ts, const st
   driver::Driver drv("", "s390x-ibm-linux-gnu", diags);
 #elif defined(__aarch64__)
   driver::Driver drv("", "aarch64-unknown-linux-gnu", diags);
+#elif defined(__arm__)
+  driver::Driver drv("", "armv7l-tizen-linux-gnueabi", diags);
 #else
   driver::Driver drv("", "x86_64-unknown-linux-gnu", diags);
 #endif
index 55f960e..f0c372b 100644 (file)
@@ -55,6 +55,8 @@
 #define __NR_bpf 351
 #elif defined(__aarch64__)
 #define __NR_bpf 280
+#elif defined(__arm__)
+#define __NR_bpf 386
 #else
 #define __NR_bpf 321
 #endif
index 01ebc6c..70b0011 100644 (file)
@@ -31,39 +31,39 @@ lib.bpf_module_license.restype = ct.c_char_p
 lib.bpf_module_license.argtypes = [ct.c_void_p]
 lib.bpf_module_kern_version.restype = ct.c_uint
 lib.bpf_module_kern_version.argtypes = [ct.c_void_p]
-lib.bpf_num_functions.restype = ct.c_ulonglong
+lib.bpf_num_functions.restype = ct.c_size_t
 lib.bpf_num_functions.argtypes = [ct.c_void_p]
 lib.bpf_function_name.restype = ct.c_char_p
-lib.bpf_function_name.argtypes = [ct.c_void_p, ct.c_ulonglong]
+lib.bpf_function_name.argtypes = [ct.c_void_p, ct.c_size_t]
 lib.bpf_function_start.restype = ct.c_void_p
 lib.bpf_function_start.argtypes = [ct.c_void_p, ct.c_char_p]
 lib.bpf_function_size.restype = ct.c_size_t
 lib.bpf_function_size.argtypes = [ct.c_void_p, ct.c_char_p]
-lib.bpf_table_id.restype = ct.c_ulonglong
+lib.bpf_table_id.restype = ct.c_size_t
 lib.bpf_table_id.argtypes = [ct.c_void_p, ct.c_char_p]
 lib.bpf_table_fd.restype = ct.c_int
 lib.bpf_table_fd.argtypes = [ct.c_void_p, ct.c_char_p]
 lib.bpf_table_type_id.restype = ct.c_int
-lib.bpf_table_type_id.argtypes = [ct.c_void_p, ct.c_ulonglong]
-lib.bpf_table_max_entries_id.restype = ct.c_ulonglong
-lib.bpf_table_max_entries_id.argtypes = [ct.c_void_p, ct.c_ulonglong]
+lib.bpf_table_type_id.argtypes = [ct.c_void_p, ct.c_size_t]
+lib.bpf_table_max_entries_id.restype = ct.c_size_t
+lib.bpf_table_max_entries_id.argtypes = [ct.c_void_p, ct.c_size_t]
 lib.bpf_table_flags_id.restype = ct.c_int
-lib.bpf_table_flags_id.argtypes = [ct.c_void_p, ct.c_ulonglong]
+lib.bpf_table_flags_id.argtypes = [ct.c_void_p, ct.c_size_t]
 lib.bpf_table_key_desc.restype = ct.c_char_p
 lib.bpf_table_key_desc.argtypes = [ct.c_void_p, ct.c_char_p]
 lib.bpf_table_leaf_desc.restype = ct.c_char_p
 lib.bpf_table_leaf_desc.argtypes = [ct.c_void_p, ct.c_char_p]
 lib.bpf_table_key_snprintf.restype = ct.c_int
-lib.bpf_table_key_snprintf.argtypes = [ct.c_void_p, ct.c_ulonglong,
-        ct.c_char_p, ct.c_ulonglong, ct.c_void_p]
+lib.bpf_table_key_snprintf.argtypes = [ct.c_void_p, ct.c_size_t,
+        ct.c_char_p, ct.c_size_t, ct.c_void_p]
 lib.bpf_table_leaf_snprintf.restype = ct.c_int
-lib.bpf_table_leaf_snprintf.argtypes = [ct.c_void_p, ct.c_ulonglong,
-        ct.c_char_p, ct.c_ulonglong, ct.c_void_p]
+lib.bpf_table_leaf_snprintf.argtypes = [ct.c_void_p, ct.c_size_t,
+        ct.c_char_p, ct.c_size_t, ct.c_void_p]
 lib.bpf_table_key_sscanf.restype = ct.c_int
-lib.bpf_table_key_sscanf.argtypes = [ct.c_void_p, ct.c_ulonglong,
+lib.bpf_table_key_sscanf.argtypes = [ct.c_void_p, ct.c_size_t,
         ct.c_char_p, ct.c_void_p]
 lib.bpf_table_leaf_sscanf.restype = ct.c_int
-lib.bpf_table_leaf_sscanf.argtypes = [ct.c_void_p, ct.c_ulonglong,
+lib.bpf_table_leaf_sscanf.argtypes = [ct.c_void_p, ct.c_size_t,
         ct.c_char_p, ct.c_void_p]
 
 # keep in sync with libbpf.h