Skip to contentSkip to conversation

libbpf: fix ptr to u64 conversion warning on 32-bit platforms

PATCH In review Andrii Nakryiko 4 participants 4 messages Jul 9, 2019 – Jul 12, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: fix ptr to u64 conversion warning on 32-bit platforms

On 32-bit platforms compiler complains about conversion:

libbpf.c: In function ‘perf_event_open_probe’:
libbpf.c:4112:17: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
attr.config1 = (uint64_t)(void *)name; /* kprobe_func or uprobe_path */

                 ^
Fixes b26500274767 ("libbpf: add kprobe/uprobe attach API")
---
 tools/lib/bpf/libbpf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
index ed07789b3e62..794dd5064ae8 100644
@@ -4126,8 +4126,8 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
 	}
 	attr.size = sizeof(attr);
 	attr.type = type;
-	attr.config1 = (uint64_t)(void *)name; /* kprobe_func or uprobe_path */
-	attr.config2 = offset;		       /* kprobe_addr or probe_offset */
+	attr.config1 = ptr_to_u64(name); /* kprobe_func or uprobe_path */
+	attr.config2 = offset;		 /* kprobe_addr or probe_offset */
 
 	/* pid filter is meaningful only for uprobes */
 	pfd = syscall(__NR_perf_event_open, &attr,
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Andrii Nakryiko

On 32-bit platforms compiler complains about conversion:

libbpf.c: In function ‘perf_event_open_probe’:
libbpf.c:4112:17: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
attr.config1 = (uint64_t)(void *)name; /* kprobe_func or uprobe_path */

Quoted 6 lines
                  ^
Fixes b26500274767 ("libbpf: add kprobe/uprobe attach API")
Quoted 20 lines
---
  tools/lib/bpf/libbpf.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
index ed07789b3e62..794dd5064ae8 100644
@@ -4126,8 +4126,8 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
  	}
  	attr.size = sizeof(attr);
  	attr.type = type;
-	attr.config1 = (uint64_t)(void *)name; /* kprobe_func or uprobe_path */
-	attr.config2 = offset;		       /* kprobe_addr or probe_offset */
+	attr.config1 = ptr_to_u64(name); /* kprobe_func or uprobe_path */
+	attr.config2 = offset;		 /* kprobe_addr or probe_offset */
 
  	/* pid filter is meaningful only for uprobes */
  	pfd = syscall(__NR_perf_event_open, &attr,
#2 lore raw
Quoted 12 lines · Yonghong Song
Quoted 8 lines · Andrii Nakryiko

On 32-bit platforms compiler complains about conversion:

libbpf.c: In function ‘perf_event_open_probe’:
libbpf.c:4112:17: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
attr.config1 = (uint64_t)(void *)name; /* kprobe_func or uprobe_path */

                  ^
Quoted 7 lines
Quoted 4 lines
Fixes b26500274767 ("libbpf: add kprobe/uprobe attach API")

How do we get this merged? I see the build failure has now propagated up to mainline :(

Quoted 20 lines
Quoted 20 lines
---
  tools/lib/bpf/libbpf.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
index ed07789b3e62..794dd5064ae8 100644
@@ -4126,8 +4126,8 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
      }
      attr.size = sizeof(attr);
      attr.type = type;
-     attr.config1 = (uint64_t)(void *)name; /* kprobe_func or uprobe_path */
-     attr.config2 = offset;                 /* kprobe_addr or probe_offset */
+     attr.config1 = ptr_to_u64(name); /* kprobe_func or uprobe_path */
+     attr.config2 = offset;           /* kprobe_addr or probe_offset */
 
      /* pid filter is meaningful only for uprobes */
      pfd = syscall(__NR_perf_event_open, &attr,
maintainer
#3 lore raw
Quoted 15 lines · Matt Hart
Quoted 14 lines · Yonghong Song
Quoted 12 lines · Andrii Nakryiko

On 32-bit platforms compiler complains about conversion:

libbpf.c: In function ‘perf_event_open_probe’:
libbpf.c:4112:17: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
attr.config1 = (uint64_t)(void *)name; /* kprobe_func or uprobe_path */

                  ^
Fixes b26500274767 ("libbpf: add kprobe/uprobe attach API")
Quoted 4 lines
Quoted 1 line

How do we get this merged? I see the build failure has now propagated up to mainline :(

I just applied the fix to bpf tree, will go its usual route to mainline.