prevent rewriting for array element type
Fix issue #2352.
Corresponding llvm bug: https://bugs.llvm.org/show_bug.cgi?id=41918.
If the element type is array type, the rewriter may generate code like
addr = ({ typeof(__u8 [16]) _val; __builtin_memset(&_val, 0, sizeof(_val));
bpf_probe_read(&_val, sizeof(_val), (u64)&daddr->s6_addr); _val; })
for something like
addr = daddr->s6_addr;
where s6_addr is an array.
The above code has an issue then as addr is pointing to some data
which is out of scope, which meaning compiler is free to use the space.
Let us disable such transformation until we find a good solution.
Signed-off-by: Yonghong Song <yhs@fb.com>
diff --git a/tools/tcptop.py b/tools/tcptop.py
index 5f09bed..330d5bb 100755
--- a/tools/tcptop.py
+++ b/tools/tcptop.py
@@ -112,10 +112,10 @@
} else if (family == AF_INET6) {
struct ipv6_key_t ipv6_key = {.pid = pid};
- __builtin_memcpy(&ipv6_key.saddr,
- sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32, sizeof(ipv6_key.saddr));
- __builtin_memcpy(&ipv6_key.daddr,
- sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32, sizeof(ipv6_key.daddr));
+ bpf_probe_read(&ipv6_key.saddr, sizeof(ipv6_key.saddr),
+ &sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32);
+ bpf_probe_read(&ipv6_key.daddr, sizeof(ipv6_key.daddr),
+ &sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32);
ipv6_key.lport = sk->__sk_common.skc_num;
dport = sk->__sk_common.skc_dport;
ipv6_key.dport = ntohs(dport);
@@ -153,10 +153,10 @@
} else if (family == AF_INET6) {
struct ipv6_key_t ipv6_key = {.pid = pid};
- __builtin_memcpy(&ipv6_key.saddr,
- sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32, sizeof(ipv6_key.saddr));
- __builtin_memcpy(&ipv6_key.daddr,
- sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32, sizeof(ipv6_key.daddr));
+ bpf_probe_read(&ipv6_key.saddr, sizeof(ipv6_key.saddr),
+ &sk->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32);
+ bpf_probe_read(&ipv6_key.daddr, sizeof(ipv6_key.daddr),
+ &sk->__sk_common.skc_v6_daddr.in6_u.u6_addr32);
ipv6_key.lport = sk->__sk_common.skc_num;
dport = sk->__sk_common.skc_dport;
ipv6_key.dport = ntohs(dport);