Blame SOURCES/bcc-0.24.0-Revert-libbpf-1.0-changes.patch

f5d2bd
From 09cee55c78fe5c165c7d7c21f596c23831f844e1 Mon Sep 17 00:00:00 2001
f5d2bd
From: Jerome Marchand <jmarchan@redhat.com>
f5d2bd
Date: Tue, 19 Apr 2022 18:02:13 +0200
f5d2bd
Subject: [PATCH] Revert libbpf 1.0 changes
f5d2bd
f5d2bd
Revert "libbpf-tools: remove now unnecessary bump_memlock_rlimit()"
f5d2bd
f5d2bd
This reverts commit 5d8f5c45b16c389bb342d2b80c9f5e13e4f3b112.
f5d2bd
f5d2bd
Revert "libbpf-tools: update vfsstat for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit f083d3dc37372e555133519cb417f893c431eef0.
f5d2bd
f5d2bd
Revert "libbpf-tools: update tcprtt for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit a5b6c3cb2d20718ef002e7447046fad877590b91.
f5d2bd
f5d2bd
Revert "libbpf-tools: update tcpconnlat for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit aae06012af8cc8c2b592340f8783a2873aad2023.
f5d2bd
f5d2bd
Revert "libbpf-tools: update tcpconnect for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 4051a9e83cb68733af20ce263fcc41c8aadc2622.
f5d2bd
f5d2bd
Revert "libbpf-tools: update syscount for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit d2dc7bcd0d94ef54e336119a2a79113b87839820.
f5d2bd
f5d2bd
Revert "libbpf-tools: update statsnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 0e348e5ed66aabd0cd5c0c75932f245bd1385b3b.
f5d2bd
f5d2bd
Revert "libbpf-tools: update solisten for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 60dd074e26e762727e685334999bec5851adaef9.
f5d2bd
f5d2bd
Revert "libbpf-tools: update softirqs for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 92806a435c2e1b248acdb9d0dc5b3eedc86994b0.
f5d2bd
f5d2bd
Revert "libbpf-tools: update runqslower for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit e6477620ccfc9abe10f7e630e65381204daa5ba8.
f5d2bd
f5d2bd
Revert "libbpf-tools: update runqlen for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit a7f0148372018140940d66f8faf53cb5add1e858.
f5d2bd
f5d2bd
Revert "libbpf-tools: update runqlat for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 865f990b7139dca166a43bbc8159f6acd4bfbee6.
f5d2bd
f5d2bd
Revert "libbpf-tools: update readahead for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 3c5dae6380dcc2034a8746c648e3bb24ea61f886.
f5d2bd
f5d2bd
Revert "libbpf-tools: update opensnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 34a680ba8da7e61befad67ebccb69c5041e9e288.
f5d2bd
f5d2bd
Revert "libbpf-tools: update offcputime for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 5ef6d9922841d7cfde1994c25ccbac53858ed99f.
f5d2bd
f5d2bd
Revert "libbpf-tools: update numamove for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 824ffd2a1fbb527f5fd25e2caa4b43fbf1ee858b.
f5d2bd
f5d2bd
Revert "libbpf-tools: update mountsnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 08301e93e5cea8575d5dc4b66fb7a76cebd5969b.
f5d2bd
f5d2bd
Revert "libbpf-tools: update llcstat for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit dbee9ea8ede33166fa70ecc33af7d7721ef26280.
f5d2bd
f5d2bd
Revert "libbpf-tools: update hardirqs for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 8fcf08c81d30d80f89f995f79ef3246ce99c72dd.
f5d2bd
f5d2bd
Revert "libbpf-tools: update gethostlatency for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 54a239abd21df9d6fc5d8db7ae7a26c5d8db2440.
f5d2bd
f5d2bd
Revert "libbpf-tools: update funclatency for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit d7b3ed3a8b2169087534738670d108489711f2d1.
f5d2bd
f5d2bd
Revert "libbpf-tools: update fsslower for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 511ab72f046848d6df3f7c6ec0411b1609e165fb.
f5d2bd
f5d2bd
Revert "libbpf-tools: update fsdist for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 21586658c86e1a20e9195d8715d37d714be93bb6.
f5d2bd
f5d2bd
Revert "libbpf-tools: update filetop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit e6d151227f56433a317790d56ba7875ccae00448.
f5d2bd
f5d2bd
Revert "libbpf-tools: update filelife for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 4ca8dd95efb7c4f149b889b700beeda036ebe822.
f5d2bd
f5d2bd
Revert "libbpf-tools: update exitsnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 0a035be644cf818354f3faab25a74e005a66d954.
f5d2bd
f5d2bd
Revert "libbpf-tools: update execsnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 7da38aabbefa41b8553e9fdec7744a5e423b5119.
f5d2bd
f5d2bd
Revert "libbpf-tools: update cpudist for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit dab1d09ef49e74c4c95f933e97e16dfc074338c2.
f5d2bd
f5d2bd
Revert "libbpf-tools: update drsnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 9cfdf5e04b32ca079a634ff60de7c08e3c41ccf5.
f5d2bd
f5d2bd
Revert "libbpf-tools: fix cpufreq.bpf.c and update cpufreq for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit f2006eaa5901d6ccf51d24b18c644f2fb1d41757.
f5d2bd
f5d2bd
Revert "libbpf-tools: update cachestat for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 4970d23f9ff308c5860612ad6395d7692b05104e.
f5d2bd
f5d2bd
Revert "libbpf-tools: update bitesize for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 7bea6c4ad9a460fc34eb618e488e44ca014e8ac7.
f5d2bd
f5d2bd
Revert "libbpf-tools: update biostacks for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 49bb367628500104411d42851194162bec5d1f4c.
f5d2bd
f5d2bd
Revert "libbpf-tools: update biosnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 519ed8cf9c0daff75ecb3f435a3efec2087945a6.
f5d2bd
f5d2bd
Revert "libbpf-tools: update biopattern for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit c5b17e65a6e59fae1223bf493648050643ad9179.
f5d2bd
f5d2bd
Revert "libbpf-tools: update biolatency for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 24d723699fbeeb8686acabc09ecefcceb749b9e0.
f5d2bd
f5d2bd
Revert "libbpf-tools: update bindsnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 7f2f4c4123a55438754b1a29f7ad3d3cfdbc7373.
f5d2bd
f5d2bd
Revert "libbpf-tools: update ksnoop for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 18dc2ac7d84a854e2f5ac9ce1b532a0c59acf49e.
f5d2bd
f5d2bd
Revert "libbpf-tools: update bashreadline for libbpf 1.0"
f5d2bd
f5d2bd
This reverts commit 2cf0ba491d16386529c50ff0a9ec3eb9f86a2493.
f5d2bd
f5d2bd
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
f5d2bd
---
f5d2bd
 libbpf-tools/bashreadline.c   | 24 ++++++++-----
f5d2bd
 libbpf-tools/bindsnoop.c      | 21 +++++++----
f5d2bd
 libbpf-tools/biolatency.c     | 28 +++++++++------
f5d2bd
 libbpf-tools/biopattern.c     |  7 +++-
f5d2bd
 libbpf-tools/biosnoop.c       | 67 +++++++++++++++++++++--------------
f5d2bd
 libbpf-tools/biostacks.c      | 39 ++++++++++++--------
f5d2bd
 libbpf-tools/bitesize.c       |  7 +++-
f5d2bd
 libbpf-tools/cachestat.c      |  7 +++-
f5d2bd
 libbpf-tools/cpudist.c        |  7 +++-
f5d2bd
 libbpf-tools/cpufreq.bpf.c    | 11 ------
f5d2bd
 libbpf-tools/cpufreq.c        | 15 +++++---
f5d2bd
 libbpf-tools/drsnoop.c        | 21 +++++++----
f5d2bd
 libbpf-tools/execsnoop.c      | 22 ++++++++----
f5d2bd
 libbpf-tools/exitsnoop.c      | 20 +++++++----
f5d2bd
 libbpf-tools/filelife.c       | 21 +++++++----
f5d2bd
 libbpf-tools/filetop.c        |  6 +++-
f5d2bd
 libbpf-tools/fsdist.c         | 38 +++++++++++++-------
f5d2bd
 libbpf-tools/fsslower.c       | 46 ++++++++++++++++--------
f5d2bd
 libbpf-tools/funclatency.c    | 32 ++++++++++-------
f5d2bd
 libbpf-tools/gethostlatency.c | 49 +++++++++++++++----------
f5d2bd
 libbpf-tools/hardirqs.c       | 34 +++++++++++-------
f5d2bd
 libbpf-tools/ksnoop.c         | 65 ++++++++++++++++-----------------
f5d2bd
 libbpf-tools/llcstat.bpf.c    |  4 +--
f5d2bd
 libbpf-tools/llcstat.c        | 13 +++++--
f5d2bd
 libbpf-tools/mountsnoop.c     | 20 +++++++----
f5d2bd
 libbpf-tools/numamove.c       | 16 ++++++---
f5d2bd
 libbpf-tools/offcputime.c     |  7 +++-
f5d2bd
 libbpf-tools/opensnoop.c      | 21 +++++++----
f5d2bd
 libbpf-tools/readahead.c      |  7 +++-
f5d2bd
 libbpf-tools/runqlat.c        |  7 +++-
f5d2bd
 libbpf-tools/runqlen.c        | 13 +++++--
f5d2bd
 libbpf-tools/runqslower.c     | 22 ++++++++----
f5d2bd
 libbpf-tools/softirqs.c       |  7 +++-
f5d2bd
 libbpf-tools/solisten.c       | 20 +++++++----
f5d2bd
 libbpf-tools/statsnoop.c      | 20 +++++++----
f5d2bd
 libbpf-tools/syscount.c       | 18 ++++++----
f5d2bd
 libbpf-tools/tcpconnect.c     | 25 ++++++++-----
f5d2bd
 libbpf-tools/tcpconnlat.c     | 24 +++++++++----
f5d2bd
 libbpf-tools/tcprtt.c         |  7 +++-
f5d2bd
 libbpf-tools/trace_helpers.c  | 22 ++++++++----
f5d2bd
 libbpf-tools/trace_helpers.h  |  1 +
f5d2bd
 libbpf-tools/vfsstat.c        |  8 ++++-
f5d2bd
 42 files changed, 576 insertions(+), 293 deletions(-)
f5d2bd
f5d2bd
diff --git a/libbpf-tools/bashreadline.c b/libbpf-tools/bashreadline.c
f5d2bd
index 2fcb2e2c..ab3b955e 100644
f5d2bd
--- a/libbpf-tools/bashreadline.c
f5d2bd
+++ b/libbpf-tools/bashreadline.c
f5d2bd
@@ -149,6 +149,7 @@ int main(int argc, char **argv)
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
 	struct bashreadline_bpf *obj = NULL;
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	char *readline_so_path;
f5d2bd
 	off_t func_off;
f5d2bd
@@ -165,7 +166,11 @@ int main(int argc, char **argv)
f5d2bd
 		return 1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		goto cleanup;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	obj = bashreadline_bpf__open_and_load();
f5d2bd
@@ -182,16 +187,17 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	obj->links.printret = bpf_program__attach_uprobe(obj->progs.printret, true, -1,
f5d2bd
 							 readline_so_path, func_off);
f5d2bd
-	if (!obj->links.printret) {
f5d2bd
-		err = -errno;
f5d2bd
+	err = libbpf_get_error(obj->links.printret);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to attach readline: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
+	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES, &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -205,8 +211,8 @@ int main(int argc, char **argv)
f5d2bd
 	printf("%-9s %-7s %s\n", "TIME", "PID", "COMMAND");
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			warn("error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			warn("error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		err = 0;
f5d2bd
diff --git a/libbpf-tools/bindsnoop.c b/libbpf-tools/bindsnoop.c
f5d2bd
index 5d87d484..c75b57e0 100644
f5d2bd
--- a/libbpf-tools/bindsnoop.c
f5d2bd
+++ b/libbpf-tools/bindsnoop.c
f5d2bd
@@ -174,6 +174,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct bindsnoop_bpf *obj;
f5d2bd
 	int err, port_map_fd;
f5d2bd
@@ -184,7 +185,11 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	obj = bindsnoop_bpf__open();
f5d2bd
@@ -219,10 +224,12 @@ int main(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
+	pb = perf_buffer__new(bpf_map__fd(obj->maps.events),
f5d2bd
+			      PERF_BUFFER_PAGES, &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -240,8 +247,8 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			warn("error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			warn("error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/biolatency.c b/libbpf-tools/biolatency.c
f5d2bd
index 51afa509..f2cf5ffd 100644
f5d2bd
--- a/libbpf-tools/biolatency.c
f5d2bd
+++ b/libbpf-tools/biolatency.c
f5d2bd
@@ -255,9 +255,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = biolatency_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -308,22 +313,25 @@ int main(int argc, char **argv)
f5d2bd
 	}
f5d2bd
 
f5d2bd
 	if (env.queued) {
f5d2bd
-		obj->links.block_rq_insert = bpf_program__attach(obj->progs.block_rq_insert);
f5d2bd
-		if (!obj->links.block_rq_insert) {
f5d2bd
-			err = -errno;
f5d2bd
+		obj->links.block_rq_insert =
f5d2bd
+			bpf_program__attach(obj->progs.block_rq_insert);
f5d2bd
+		err = libbpf_get_error(obj->links.block_rq_insert);
f5d2bd
+		if (err) {
f5d2bd
 			fprintf(stderr, "failed to attach: %s\n", strerror(-err));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 	}
f5d2bd
-	obj->links.block_rq_issue = bpf_program__attach(obj->progs.block_rq_issue);
f5d2bd
-	if (!obj->links.block_rq_issue) {
f5d2bd
-		err = -errno;
f5d2bd
+	obj->links.block_rq_issue =
f5d2bd
+		bpf_program__attach(obj->progs.block_rq_issue);
f5d2bd
+	err = libbpf_get_error(obj->links.block_rq_issue);
f5d2bd
+	if (err) {
f5d2bd
 		fprintf(stderr, "failed to attach: %s\n", strerror(-err));
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
-	obj->links.block_rq_complete = bpf_program__attach(obj->progs.block_rq_complete);
f5d2bd
-	if (!obj->links.block_rq_complete) {
f5d2bd
-		err = -errno;
f5d2bd
+	obj->links.block_rq_complete =
f5d2bd
+		bpf_program__attach(obj->progs.block_rq_complete);
f5d2bd
+	err = libbpf_get_error(obj->links.block_rq_complete);
f5d2bd
+	if (err) {
f5d2bd
 		fprintf(stderr, "failed to attach: %s\n", strerror(-err));
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
diff --git a/libbpf-tools/biopattern.c b/libbpf-tools/biopattern.c
f5d2bd
index 92324702..2cc0d9a3 100644
f5d2bd
--- a/libbpf-tools/biopattern.c
f5d2bd
+++ b/libbpf-tools/biopattern.c
f5d2bd
@@ -172,9 +172,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = biopattern_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/biosnoop.c b/libbpf-tools/biosnoop.c
f5d2bd
index f0f665a6..618af38e 100644
f5d2bd
--- a/libbpf-tools/biosnoop.c
f5d2bd
+++ b/libbpf-tools/biosnoop.c
f5d2bd
@@ -190,6 +190,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct ksyms *ksyms = NULL;
f5d2bd
 	struct biosnoop_bpf *obj;
f5d2bd
@@ -202,9 +203,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = biosnoop_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -251,55 +257,64 @@ int main(int argc, char **argv)
f5d2bd
 		}
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	obj->links.blk_account_io_start = bpf_program__attach(obj->progs.blk_account_io_start);
f5d2bd
-	if (!obj->links.blk_account_io_start) {
f5d2bd
-		err = -errno;
f5d2bd
+	obj->links.blk_account_io_start =
f5d2bd
+		bpf_program__attach(obj->progs.blk_account_io_start);
f5d2bd
+	err = libbpf_get_error(obj->links.blk_account_io_start);
f5d2bd
+	if (err) {
f5d2bd
 		fprintf(stderr, "failed to attach blk_account_io_start: %s\n",
f5d2bd
-			strerror(-err));
f5d2bd
+			strerror(err));
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 	ksyms = ksyms__load();
f5d2bd
 	if (!ksyms) {
f5d2bd
-		err = -ENOMEM;
f5d2bd
 		fprintf(stderr, "failed to load kallsyms\n");
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 	if (ksyms__get_symbol(ksyms, "blk_account_io_merge_bio")) {
f5d2bd
 		obj->links.blk_account_io_merge_bio =
f5d2bd
 			bpf_program__attach(obj->progs.blk_account_io_merge_bio);
f5d2bd
-		if (!obj->links.blk_account_io_merge_bio) {
f5d2bd
-			err = -errno;
f5d2bd
-			fprintf(stderr, "failed to attach blk_account_io_merge_bio: %s\n",
f5d2bd
-				strerror(-err));
f5d2bd
+		err = libbpf_get_error(obj->links.blk_account_io_merge_bio);
f5d2bd
+		if (err) {
f5d2bd
+			fprintf(stderr, "failed to attach "
f5d2bd
+				"blk_account_io_merge_bio: %s\n",
f5d2bd
+				strerror(err));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 	}
f5d2bd
 	if (env.queued) {
f5d2bd
 		obj->links.block_rq_insert =
f5d2bd
 			bpf_program__attach(obj->progs.block_rq_insert);
f5d2bd
-		if (!obj->links.block_rq_insert) {
f5d2bd
-			err = -errno;
f5d2bd
-			fprintf(stderr, "failed to attach block_rq_insert: %s\n", strerror(-err));
f5d2bd
+		err = libbpf_get_error(obj->links.block_rq_insert);
f5d2bd
+		if (err) {
f5d2bd
+			fprintf(stderr, "failed to attach block_rq_insert: %s\n",
f5d2bd
+				strerror(err));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 	}
f5d2bd
-	obj->links.block_rq_issue = bpf_program__attach(obj->progs.block_rq_issue);
f5d2bd
-	if (!obj->links.block_rq_issue) {
f5d2bd
-		err = -errno;
f5d2bd
-		fprintf(stderr, "failed to attach block_rq_issue: %s\n", strerror(-err));
f5d2bd
+	obj->links.block_rq_issue =
f5d2bd
+		bpf_program__attach(obj->progs.block_rq_issue);
f5d2bd
+	err = libbpf_get_error(obj->links.block_rq_issue);
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to attach block_rq_issue: %s\n",
f5d2bd
+			strerror(err));
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
-	obj->links.block_rq_complete = bpf_program__attach(obj->progs.block_rq_complete);
f5d2bd
-	if (!obj->links.block_rq_complete) {
f5d2bd
-		err = -errno;
f5d2bd
-		fprintf(stderr, "failed to attach block_rq_complete: %s\n", strerror(-err));
f5d2bd
+	obj->links.block_rq_complete =
f5d2bd
+		bpf_program__attach(obj->progs.block_rq_complete);
f5d2bd
+	err = libbpf_get_error(obj->links.block_rq_complete);
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to attach block_rq_complete: %s\n",
f5d2bd
+			strerror(err));
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
 	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+			&pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
 		fprintf(stderr, "failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -323,8 +338,8 @@ int main(int argc, char **argv)
f5d2bd
 	/* main: poll */
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		if (env.duration && get_ktime_ns() > time_end)
f5d2bd
diff --git a/libbpf-tools/biostacks.c b/libbpf-tools/biostacks.c
f5d2bd
index 260bc235..c98fd532 100644
f5d2bd
--- a/libbpf-tools/biostacks.c
f5d2bd
+++ b/libbpf-tools/biostacks.c
f5d2bd
@@ -145,9 +145,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = biostacks_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -179,10 +184,12 @@ int main(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	obj->links.blk_account_io_start = bpf_program__attach(obj->progs.blk_account_io_start);
f5d2bd
-	if (!obj->links.blk_account_io_start) {
f5d2bd
-		err = -errno;
f5d2bd
-		fprintf(stderr, "failed to attach blk_account_io_start: %s\n", strerror(-err));
f5d2bd
+	obj->links.blk_account_io_start =
f5d2bd
+		bpf_program__attach(obj->progs.blk_account_io_start);
f5d2bd
+	err = libbpf_get_error(obj->links.blk_account_io_start);
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to attach blk_account_io_start: %s\n",
f5d2bd
+			strerror(err));
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 	ksyms = ksyms__load();
f5d2bd
@@ -192,19 +199,23 @@ int main(int argc, char **argv)
f5d2bd
 	}
f5d2bd
 	if (ksyms__get_symbol(ksyms, "blk_account_io_merge_bio")) {
f5d2bd
 		obj->links.blk_account_io_merge_bio =
f5d2bd
-			bpf_program__attach(obj->progs.blk_account_io_merge_bio);
f5d2bd
-		if (!obj->links.blk_account_io_merge_bio) {
f5d2bd
-			err = -errno;
f5d2bd
-			fprintf(stderr, "failed to attach blk_account_io_merge_bio: %s\n",
f5d2bd
-				strerror(-err));
f5d2bd
+			bpf_program__attach(obj->
f5d2bd
+					progs.blk_account_io_merge_bio);
f5d2bd
+		err = libbpf_get_error(obj->
f5d2bd
+				links.blk_account_io_merge_bio);
f5d2bd
+		if (err) {
f5d2bd
+			fprintf(stderr, "failed to attach "
f5d2bd
+				"blk_account_io_merge_bio: %s\n",
f5d2bd
+				strerror(err));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 	}
f5d2bd
-	obj->links.blk_account_io_done = bpf_program__attach(obj->progs.blk_account_io_done);
f5d2bd
-	if (!obj->links.blk_account_io_done) {
f5d2bd
-		err = -errno;
f5d2bd
+	obj->links.blk_account_io_done =
f5d2bd
+		bpf_program__attach(obj->progs.blk_account_io_done);
f5d2bd
+	err = libbpf_get_error(obj->links.blk_account_io_done);
f5d2bd
+	if (err) {
f5d2bd
 		fprintf(stderr, "failed to attach blk_account_io_done: %s\n",
f5d2bd
-			strerror(-err));
f5d2bd
+			strerror(err));
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
diff --git a/libbpf-tools/bitesize.c b/libbpf-tools/bitesize.c
f5d2bd
index 4c371508..41b1a7db 100644
f5d2bd
--- a/libbpf-tools/bitesize.c
f5d2bd
+++ b/libbpf-tools/bitesize.c
f5d2bd
@@ -167,9 +167,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = bitesize_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/cachestat.c b/libbpf-tools/cachestat.c
f5d2bd
index 05785251..abc81878 100644
f5d2bd
--- a/libbpf-tools/cachestat.c
f5d2bd
+++ b/libbpf-tools/cachestat.c
f5d2bd
@@ -139,9 +139,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = cachestat_bpf__open_and_load();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open and/or load BPF object\n");
f5d2bd
diff --git a/libbpf-tools/cpudist.c b/libbpf-tools/cpudist.c
f5d2bd
index f76d8a67..035100ea 100644
f5d2bd
--- a/libbpf-tools/cpudist.c
f5d2bd
+++ b/libbpf-tools/cpudist.c
f5d2bd
@@ -197,9 +197,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = cpudist_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/cpufreq.bpf.c b/libbpf-tools/cpufreq.bpf.c
f5d2bd
index 88a1bd25..697620ba 100644
f5d2bd
--- a/libbpf-tools/cpufreq.bpf.c
f5d2bd
+++ b/libbpf-tools/cpufreq.bpf.c
f5d2bd
@@ -17,21 +17,11 @@ struct {
f5d2bd
 	__type(value, struct hist);
f5d2bd
 } hists SEC(".maps");
f5d2bd
 
f5d2bd
-#define clamp_umax(VAR, UMAX)						\
f5d2bd
-	asm volatile (							\
f5d2bd
-		"if %0 <= %[max] goto +1\n"				\
f5d2bd
-		"%0 = %[max]\n"						\
f5d2bd
-		: "+r"(VAR)						\
f5d2bd
-		: [max]"i"(UMAX)					\
f5d2bd
-	)
f5d2bd
-
f5d2bd
 SEC("tp_btf/cpu_frequency")
f5d2bd
 int BPF_PROG(cpu_frequency, unsigned int state, unsigned int cpu_id)
f5d2bd
 {
f5d2bd
 	if (cpu_id >= MAX_CPU_NR)
f5d2bd
 		return 0;
f5d2bd
-
f5d2bd
-	clamp_umax(cpu_id, MAX_CPU_NR - 1);
f5d2bd
 	freqs_mhz[cpu_id] = state / 1000;
f5d2bd
 	return 0;
f5d2bd
 }
f5d2bd
@@ -46,7 +36,6 @@ int do_sample(struct bpf_perf_event_data *ctx)
f5d2bd
 
f5d2bd
 	if (cpu >= MAX_CPU_NR)
f5d2bd
 		return 0;
f5d2bd
-	clamp_umax(cpu, MAX_CPU_NR - 1);
f5d2bd
 	freq_mhz = freqs_mhz[cpu];
f5d2bd
 	if (!freq_mhz)
f5d2bd
 		return 0;
f5d2bd
diff --git a/libbpf-tools/cpufreq.c b/libbpf-tools/cpufreq.c
f5d2bd
index c5839560..65876587 100644
f5d2bd
--- a/libbpf-tools/cpufreq.c
f5d2bd
+++ b/libbpf-tools/cpufreq.c
f5d2bd
@@ -102,8 +102,10 @@ static int open_and_attach_perf_event(int freq, struct bpf_program *prog,
f5d2bd
 			return -1;
f5d2bd
 		}
f5d2bd
 		links[i] = bpf_program__attach_perf_event(prog, fd);
f5d2bd
-		if (!links[i]) {
f5d2bd
-			fprintf(stderr, "failed to attach perf event on cpu: %d\n", i);
f5d2bd
+		if (libbpf_get_error(links[i])) {
f5d2bd
+			fprintf(stderr, "failed to attach perf event on cpu: "
f5d2bd
+				"%d\n", i);
f5d2bd
+			links[i] = NULL;
f5d2bd
 			close(fd);
f5d2bd
 			return -1;
f5d2bd
 		}
f5d2bd
@@ -173,7 +175,7 @@ static void print_linear_hists(struct bpf_map *hists,
f5d2bd
 
f5d2bd
 	printf("\n");
f5d2bd
 	print_linear_hist(bss->syswide.slots, MAX_SLOTS, 0, HIST_STEP_SIZE,
f5d2bd
-			  "syswide");
f5d2bd
+			"syswide");
f5d2bd
 }
f5d2bd
 
f5d2bd
 int main(int argc, char **argv)
f5d2bd
@@ -191,9 +193,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	nr_cpus = libbpf_num_possible_cpus();
f5d2bd
 	if (nr_cpus < 0) {
f5d2bd
 		fprintf(stderr, "failed to get # of possible cpus: '%s'!\n",
f5d2bd
diff --git a/libbpf-tools/drsnoop.c b/libbpf-tools/drsnoop.c
f5d2bd
index 705db9a4..89285871 100644
f5d2bd
--- a/libbpf-tools/drsnoop.c
f5d2bd
+++ b/libbpf-tools/drsnoop.c
f5d2bd
@@ -146,6 +146,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct ksyms *ksyms = NULL;
f5d2bd
 	const struct ksym *ksym;
f5d2bd
@@ -157,9 +158,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = drsnoop_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -207,10 +213,13 @@ int main(int argc, char **argv)
f5d2bd
 		printf(" %8s", "FREE(KB)");
f5d2bd
 	printf("\n");
f5d2bd
 
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
 	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+			      &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
 		fprintf(stderr, "failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -228,8 +237,8 @@ int main(int argc, char **argv)
f5d2bd
 	/* main: poll */
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		if (env.duration && get_ktime_ns() > time_end)
f5d2bd
diff --git a/libbpf-tools/execsnoop.c b/libbpf-tools/execsnoop.c
f5d2bd
index 38294816..1fd573da 100644
f5d2bd
--- a/libbpf-tools/execsnoop.c
f5d2bd
+++ b/libbpf-tools/execsnoop.c
f5d2bd
@@ -263,6 +263,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct execsnoop_bpf *obj;
f5d2bd
 	int err;
f5d2bd
@@ -271,9 +272,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = execsnoop_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -311,10 +317,12 @@ int main(int argc, char **argv)
f5d2bd
 	printf("%-16s %-6s %-6s %3s %s\n", "PCOMM", "PID", "PPID", "RET", "ARGS");
f5d2bd
 
f5d2bd
 	/* setup event callbacks */
f5d2bd
-	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
+	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES, &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
 		fprintf(stderr, "failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -328,8 +336,8 @@ int main(int argc, char **argv)
f5d2bd
 	/* main: poll */
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/exitsnoop.c b/libbpf-tools/exitsnoop.c
f5d2bd
index bca9d4d3..410e00da 100644
f5d2bd
--- a/libbpf-tools/exitsnoop.c
f5d2bd
+++ b/libbpf-tools/exitsnoop.c
f5d2bd
@@ -152,6 +152,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct exitsnoop_bpf *obj;
f5d2bd
 	int err;
f5d2bd
@@ -160,7 +161,11 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	obj = exitsnoop_bpf__open();
f5d2bd
@@ -185,10 +190,11 @@ int main(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
+	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES, &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -206,8 +212,8 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			warn("error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			warn("error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/filelife.c b/libbpf-tools/filelife.c
f5d2bd
index ba6b9440..1f94039e 100644
f5d2bd
--- a/libbpf-tools/filelife.c
f5d2bd
+++ b/libbpf-tools/filelife.c
f5d2bd
@@ -110,6 +110,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct filelife_bpf *obj;
f5d2bd
 	int err;
f5d2bd
@@ -118,9 +119,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = filelife_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -145,10 +151,13 @@ int main(int argc, char **argv)
f5d2bd
 	printf("Tracing the lifespan of short-lived files ... Hit Ctrl-C to end.\n");
f5d2bd
 	printf("%-8s %-6s %-16s %-7s %s\n", "TIME", "PID", "COMM", "AGE(s)", "FILE");
f5d2bd
 
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
 	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+			      &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
 		fprintf(stderr, "failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -161,8 +170,8 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/filetop.c b/libbpf-tools/filetop.c
f5d2bd
index 70240d85..f1f7ba96 100644
f5d2bd
--- a/libbpf-tools/filetop.c
f5d2bd
+++ b/libbpf-tools/filetop.c
f5d2bd
@@ -268,7 +268,11 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	obj = filetop_bpf__open();
f5d2bd
diff --git a/libbpf-tools/fsdist.c b/libbpf-tools/fsdist.c
f5d2bd
index f411d162..782a0e6a 100644
f5d2bd
--- a/libbpf-tools/fsdist.c
f5d2bd
+++ b/libbpf-tools/fsdist.c
f5d2bd
@@ -299,44 +299,53 @@ static int attach_kprobes(struct fsdist_bpf *obj)
f5d2bd
 
f5d2bd
 	/* READ */
f5d2bd
 	obj->links.file_read_entry = bpf_program__attach_kprobe(obj->progs.file_read_entry, false, cfg->op_funcs[READ]);
f5d2bd
-	if (!obj->links.file_read_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.file_read_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.file_read_exit = bpf_program__attach_kprobe(obj->progs.file_read_exit, true, cfg->op_funcs[READ]);
f5d2bd
-	if (!obj->links.file_read_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.file_read_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	/* WRITE */
f5d2bd
 	obj->links.file_write_entry = bpf_program__attach_kprobe(obj->progs.file_write_entry, false, cfg->op_funcs[WRITE]);
f5d2bd
-	if (!obj->links.file_write_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.file_write_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.file_write_exit = bpf_program__attach_kprobe(obj->progs.file_write_exit, true, cfg->op_funcs[WRITE]);
f5d2bd
-	if (!obj->links.file_write_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.file_write_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	/* OPEN */
f5d2bd
 	obj->links.file_open_entry = bpf_program__attach_kprobe(obj->progs.file_open_entry, false, cfg->op_funcs[OPEN]);
f5d2bd
-	if (!obj->links.file_open_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.file_open_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.file_open_exit = bpf_program__attach_kprobe(obj->progs.file_open_exit, true, cfg->op_funcs[OPEN]);
f5d2bd
-	if (!obj->links.file_open_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.file_open_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	/* FSYNC */
f5d2bd
 	obj->links.file_sync_entry = bpf_program__attach_kprobe(obj->progs.file_sync_entry, false, cfg->op_funcs[FSYNC]);
f5d2bd
-	if (!obj->links.file_sync_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.file_sync_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.file_sync_exit = bpf_program__attach_kprobe(obj->progs.file_sync_exit, true, cfg->op_funcs[FSYNC]);
f5d2bd
-	if (!obj->links.file_sync_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.file_sync_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	/* GETATTR */
f5d2bd
 	if (!cfg->op_funcs[GETATTR])
f5d2bd
 		return 0;
f5d2bd
 	obj->links.getattr_entry = bpf_program__attach_kprobe(obj->progs.getattr_entry, false, cfg->op_funcs[GETATTR]);
f5d2bd
-	if (!obj->links.getattr_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.getattr_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.getattr_exit = bpf_program__attach_kprobe(obj->progs.getattr_exit, true, cfg->op_funcs[GETATTR]);
f5d2bd
-	if (!obj->links.getattr_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.getattr_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	return 0;
f5d2bd
 errout:
f5d2bd
-	err = -errno;
f5d2bd
 	warn("failed to attach kprobe: %ld\n", err);
f5d2bd
 	return err;
f5d2bd
 }
f5d2bd
@@ -364,9 +373,14 @@ int main(int argc, char **argv)
f5d2bd
 		return 1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	skel = fsdist_bpf__open();
f5d2bd
 	if (!skel) {
f5d2bd
 		warn("failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/fsslower.c b/libbpf-tools/fsslower.c
f5d2bd
index e96c9efa..2975b493 100644
f5d2bd
--- a/libbpf-tools/fsslower.c
f5d2bd
+++ b/libbpf-tools/fsslower.c
f5d2bd
@@ -256,36 +256,43 @@ static int attach_kprobes(struct fsslower_bpf *obj)
f5d2bd
 
f5d2bd
 	/* READ */
f5d2bd
 	obj->links.file_read_entry = bpf_program__attach_kprobe(obj->progs.file_read_entry, false, cfg->op_funcs[READ]);
f5d2bd
-	if (!obj->links.file_read_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.file_read_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.file_read_exit = bpf_program__attach_kprobe(obj->progs.file_read_exit, true, cfg->op_funcs[READ]);
f5d2bd
-	if (!obj->links.file_read_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.file_read_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	/* WRITE */
f5d2bd
 	obj->links.file_write_entry = bpf_program__attach_kprobe(obj->progs.file_write_entry, false, cfg->op_funcs[WRITE]);
f5d2bd
-	if (!obj->links.file_write_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.file_write_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.file_write_exit = bpf_program__attach_kprobe(obj->progs.file_write_exit, true, cfg->op_funcs[WRITE]);
f5d2bd
-	if (!obj->links.file_write_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.file_write_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	/* OPEN */
f5d2bd
 	obj->links.file_open_entry = bpf_program__attach_kprobe(obj->progs.file_open_entry, false, cfg->op_funcs[OPEN]);
f5d2bd
-	if (!obj->links.file_open_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.file_open_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.file_open_exit = bpf_program__attach_kprobe(obj->progs.file_open_exit, true, cfg->op_funcs[OPEN]);
f5d2bd
-	if (!obj->links.file_open_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.file_open_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	/* FSYNC */
f5d2bd
 	obj->links.file_sync_entry = bpf_program__attach_kprobe(obj->progs.file_sync_entry, false, cfg->op_funcs[FSYNC]);
f5d2bd
-	if (!obj->links.file_sync_entry)
f5d2bd
+	err = libbpf_get_error(obj->links.file_sync_entry);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	obj->links.file_sync_exit = bpf_program__attach_kprobe(obj->progs.file_sync_exit, true, cfg->op_funcs[FSYNC]);
f5d2bd
-	if (!obj->links.file_sync_exit)
f5d2bd
+	err = libbpf_get_error(obj->links.file_sync_exit);
f5d2bd
+	if (err)
f5d2bd
 		goto errout;
f5d2bd
 	return 0;
f5d2bd
 
f5d2bd
 errout:
f5d2bd
-	err = -errno;
f5d2bd
 	warn("failed to attach kprobe: %ld\n", err);
f5d2bd
 	return err;
f5d2bd
 }
f5d2bd
@@ -354,6 +361,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct fsslower_bpf *skel;
f5d2bd
 	__u64 time_end = 0;
f5d2bd
@@ -369,9 +377,14 @@ int main(int argc, char **argv)
f5d2bd
 		return 1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	skel = fsslower_bpf__open();
f5d2bd
 	if (!skel) {
f5d2bd
 		warn("failed to open BPF object\n");
f5d2bd
@@ -415,10 +428,13 @@ int main(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
 	pb = perf_buffer__new(bpf_map__fd(skel->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+			      &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -437,8 +453,8 @@ int main(int argc, char **argv)
f5d2bd
 	/* main: poll */
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		if (duration && get_ktime_ns() > time_end)
f5d2bd
diff --git a/libbpf-tools/funclatency.c b/libbpf-tools/funclatency.c
f5d2bd
index 3ea0fec3..b079292e 100644
f5d2bd
--- a/libbpf-tools/funclatency.c
f5d2bd
+++ b/libbpf-tools/funclatency.c
f5d2bd
@@ -185,18 +185,20 @@ static int attach_kprobes(struct funclatency_bpf *obj)
f5d2bd
 {
f5d2bd
 	long err;
f5d2bd
 
f5d2bd
-	obj->links.dummy_kprobe = bpf_program__attach_kprobe(obj->progs.dummy_kprobe, false,
f5d2bd
-							     env.funcname);
f5d2bd
-	if (!obj->links.dummy_kprobe) {
f5d2bd
-		err = -errno;
f5d2bd
+	obj->links.dummy_kprobe =
f5d2bd
+		bpf_program__attach_kprobe(obj->progs.dummy_kprobe, false,
f5d2bd
+					   env.funcname);
f5d2bd
+	err = libbpf_get_error(obj->links.dummy_kprobe);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to attach kprobe: %ld\n", err);
f5d2bd
 		return -1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	obj->links.dummy_kretprobe = bpf_program__attach_kprobe(obj->progs.dummy_kretprobe, true,
f5d2bd
-								env.funcname);
f5d2bd
-	if (!obj->links.dummy_kretprobe) {
f5d2bd
-		err = -errno;
f5d2bd
+	obj->links.dummy_kretprobe =
f5d2bd
+		bpf_program__attach_kprobe(obj->progs.dummy_kretprobe, true,
f5d2bd
+					   env.funcname);
f5d2bd
+	err = libbpf_get_error(obj->links.dummy_kretprobe);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to attach kretprobe: %ld\n", err);
f5d2bd
 		return -1;
f5d2bd
 	}
f5d2bd
@@ -237,8 +239,8 @@ static int attach_uprobes(struct funclatency_bpf *obj)
f5d2bd
 	obj->links.dummy_kprobe =
f5d2bd
 		bpf_program__attach_uprobe(obj->progs.dummy_kprobe, false,
f5d2bd
 					   env.pid ?: -1, bin_path, func_off);
f5d2bd
-	if (!obj->links.dummy_kprobe) {
f5d2bd
-		err = -errno;
f5d2bd
+	err = libbpf_get_error(obj->links.dummy_kprobe);
f5d2bd
+	if (err) {
f5d2bd
 		warn("Failed to attach uprobe: %ld\n", err);
f5d2bd
 		goto out_binary;
f5d2bd
 	}
f5d2bd
@@ -246,8 +248,8 @@ static int attach_uprobes(struct funclatency_bpf *obj)
f5d2bd
 	obj->links.dummy_kretprobe =
f5d2bd
 		bpf_program__attach_uprobe(obj->progs.dummy_kretprobe, true,
f5d2bd
 					   env.pid ?: -1, bin_path, func_off);
f5d2bd
-	if (!obj->links.dummy_kretprobe) {
f5d2bd
-		err = -errno;
f5d2bd
+	err = libbpf_get_error(obj->links.dummy_kretprobe);
f5d2bd
+	if (err) {
f5d2bd
 		warn("Failed to attach uretprobe: %ld\n", err);
f5d2bd
 		goto out_binary;
f5d2bd
 	}
f5d2bd
@@ -296,7 +298,11 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	sigaction(SIGINT, &sigact, 0);
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	obj = funclatency_bpf__open();
f5d2bd
diff --git a/libbpf-tools/gethostlatency.c b/libbpf-tools/gethostlatency.c
f5d2bd
index 9b3ebc28..12076e6a 100644
f5d2bd
--- a/libbpf-tools/gethostlatency.c
f5d2bd
+++ b/libbpf-tools/gethostlatency.c
f5d2bd
@@ -164,14 +164,16 @@ static int attach_uprobes(struct gethostlatency_bpf *obj, struct bpf_link *links
f5d2bd
 	}
f5d2bd
 	links[0] = bpf_program__attach_uprobe(obj->progs.handle_entry, false,
f5d2bd
 					      target_pid ?: -1, libc_path, func_off);
f5d2bd
-	if (!links[0]) {
f5d2bd
-		warn("failed to attach getaddrinfo: %d\n", -errno);
f5d2bd
+	err = libbpf_get_error(links[0]);
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to attach getaddrinfo: %d\n", err);
f5d2bd
 		return -1;
f5d2bd
 	}
f5d2bd
 	links[1] = bpf_program__attach_uprobe(obj->progs.handle_return, true,
f5d2bd
 					      target_pid ?: -1, libc_path, func_off);
f5d2bd
-	if (!links[1]) {
f5d2bd
-		warn("failed to attach getaddrinfo: %d\n", -errno);
f5d2bd
+	err = libbpf_get_error(links[1]);
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to attach getaddrinfo: %d\n", err);
f5d2bd
 		return -1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
@@ -182,14 +184,16 @@ static int attach_uprobes(struct gethostlatency_bpf *obj, struct bpf_link *links
f5d2bd
 	}
f5d2bd
 	links[2] = bpf_program__attach_uprobe(obj->progs.handle_entry, false,
f5d2bd
 					      target_pid ?: -1, libc_path, func_off);
f5d2bd
-	if (!links[2]) {
f5d2bd
-		warn("failed to attach gethostbyname: %d\n", -errno);
f5d2bd
+	err = libbpf_get_error(links[2]);
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to attach gethostbyname: %d\n", err);
f5d2bd
 		return -1;
f5d2bd
 	}
f5d2bd
 	links[3] = bpf_program__attach_uprobe(obj->progs.handle_return, true,
f5d2bd
 					      target_pid ?: -1, libc_path, func_off);
f5d2bd
-	if (!links[3]) {
f5d2bd
-		warn("failed to attach gethostbyname: %d\n", -errno);
f5d2bd
+	err = libbpf_get_error(links[3]);
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to attach gethostbyname: %d\n", err);
f5d2bd
 		return -1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
@@ -200,14 +204,16 @@ static int attach_uprobes(struct gethostlatency_bpf *obj, struct bpf_link *links
f5d2bd
 	}
f5d2bd
 	links[4] = bpf_program__attach_uprobe(obj->progs.handle_entry, false,
f5d2bd
 					      target_pid ?: -1, libc_path, func_off);
f5d2bd
-	if (!links[4]) {
f5d2bd
-		warn("failed to attach gethostbyname2: %d\n", -errno);
f5d2bd
+	err = libbpf_get_error(links[4]);
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to attach gethostbyname2: %d\n", err);
f5d2bd
 		return -1;
f5d2bd
 	}
f5d2bd
 	links[5] = bpf_program__attach_uprobe(obj->progs.handle_return, true,
f5d2bd
 					      target_pid ?: -1, libc_path, func_off);
f5d2bd
-	if (!links[5]) {
f5d2bd
-		warn("failed to attach gethostbyname2: %d\n", -errno);
f5d2bd
+	err = libbpf_get_error(links[5]);
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to attach gethostbyname2: %d\n", err);
f5d2bd
 		return -1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
@@ -221,6 +227,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct bpf_link *links[6] = {};
f5d2bd
 	struct gethostlatency_bpf *obj;
f5d2bd
@@ -230,7 +237,11 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	obj = gethostlatency_bpf__open();
f5d2bd
@@ -251,10 +262,12 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		goto cleanup;
f5d2bd
 
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
 	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+			&pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -270,8 +283,8 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			warn("error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			warn("error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/hardirqs.c b/libbpf-tools/hardirqs.c
f5d2bd
index a2475ef1..759b3949 100644
f5d2bd
--- a/libbpf-tools/hardirqs.c
f5d2bd
+++ b/libbpf-tools/hardirqs.c
f5d2bd
@@ -185,9 +185,14 @@ int main(int argc, char **argv)
f5d2bd
 		return 1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = hardirqs_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -207,27 +212,30 @@ int main(int argc, char **argv)
f5d2bd
 	}
f5d2bd
 
f5d2bd
 	if (env.count) {
f5d2bd
-		obj->links.handle__irq_handler = bpf_program__attach(obj->progs.handle__irq_handler);
f5d2bd
-		if (!obj->links.handle__irq_handler) {
f5d2bd
-			err = -errno;
f5d2bd
+		obj->links.handle__irq_handler =
f5d2bd
+			bpf_program__attach(obj->progs.handle__irq_handler);
f5d2bd
+		err = libbpf_get_error(obj->links.handle__irq_handler);
f5d2bd
+		if (err) {
f5d2bd
 			fprintf(stderr,
f5d2bd
 				"failed to attach irq/irq_handler_entry: %s\n",
f5d2bd
-				strerror(-err));
f5d2bd
+				strerror(err));
f5d2bd
 		}
f5d2bd
 	} else {
f5d2bd
-		obj->links.irq_handler_entry = bpf_program__attach(obj->progs.irq_handler_entry);
f5d2bd
-		if (!obj->links.irq_handler_entry) {
f5d2bd
-			err = -errno;
f5d2bd
+		obj->links.irq_handler_entry =
f5d2bd
+			bpf_program__attach(obj->progs.irq_handler_entry);
f5d2bd
+		err = libbpf_get_error(obj->links.irq_handler_entry);
f5d2bd
+		if (err) {
f5d2bd
 			fprintf(stderr,
f5d2bd
 				"failed to attach irq_handler_entry: %s\n",
f5d2bd
-				strerror(-err));
f5d2bd
+				strerror(err));
f5d2bd
 		}
f5d2bd
-		obj->links.irq_handler_exit_exit = bpf_program__attach(obj->progs.irq_handler_exit_exit);
f5d2bd
-		if (!obj->links.irq_handler_exit_exit) {
f5d2bd
-			err = -errno;
f5d2bd
+		obj->links.irq_handler_exit_exit =
f5d2bd
+			bpf_program__attach(obj->progs.irq_handler_exit_exit);
f5d2bd
+		err = libbpf_get_error(obj->links.irq_handler_exit_exit);
f5d2bd
+		if (err) {
f5d2bd
 			fprintf(stderr,
f5d2bd
 				"failed to attach irq_handler_exit: %s\n",
f5d2bd
-				strerror(-err));
f5d2bd
+				strerror(err));
f5d2bd
 		}
f5d2bd
 	}
f5d2bd
 
f5d2bd
diff --git a/libbpf-tools/ksnoop.c b/libbpf-tools/ksnoop.c
f5d2bd
index a6ea6107..a5f59a0f 100644
f5d2bd
--- a/libbpf-tools/ksnoop.c
f5d2bd
+++ b/libbpf-tools/ksnoop.c
f5d2bd
@@ -38,6 +38,7 @@ static bool verbose = false;
f5d2bd
 static __u32 filter_pid;
f5d2bd
 static bool stack_mode;
f5d2bd
 
f5d2bd
+#define libbpf_errstr(val)	strerror(-libbpf_get_error(val))
f5d2bd
 
f5d2bd
 static void __p(enum log_level level, char *level_str, char *fmt, ...)
f5d2bd
 {
f5d2bd
@@ -222,12 +223,14 @@ static int get_func_btf(struct btf *btf, struct func *func)
f5d2bd
 		return -ENOENT;
f5d2bd
 	}
f5d2bd
 	type = btf__type_by_id(btf, func->id);
f5d2bd
-	if (!type || BTF_INFO_KIND(type->info) != BTF_KIND_FUNC) {
f5d2bd
+	if (libbpf_get_error(type) ||
f5d2bd
+	    BTF_INFO_KIND(type->info) != BTF_KIND_FUNC) {
f5d2bd
 		p_err("Error looking up function type via id '%d'", func->id);
f5d2bd
 		return -EINVAL;
f5d2bd
 	}
f5d2bd
 	type = btf__type_by_id(btf, type->type);
f5d2bd
-	if (!type || BTF_INFO_KIND(type->info) != BTF_KIND_FUNC_PROTO) {
f5d2bd
+	if (libbpf_get_error(type) ||
f5d2bd
+	    BTF_INFO_KIND(type->info) != BTF_KIND_FUNC_PROTO) {
f5d2bd
 		p_err("Error looking up function proto type via id '%d'",
f5d2bd
 		      func->id);
f5d2bd
 		return -EINVAL;
f5d2bd
@@ -341,16 +344,15 @@ static int trace_to_value(struct btf *btf, struct func *func, char *argname,
f5d2bd
 static struct btf *get_btf(const char *name)
f5d2bd
 {
f5d2bd
 	struct btf *mod_btf;
f5d2bd
-	int err;
f5d2bd
 
f5d2bd
 	p_debug("getting BTF for %s",
f5d2bd
 		name && strlen(name) > 0 ? name : "vmlinux");
f5d2bd
 
f5d2bd
 	if (!vmlinux_btf) {
f5d2bd
 		vmlinux_btf = btf__load_vmlinux_btf();
f5d2bd
-		if (!vmlinux_btf) {
f5d2bd
-			err = -errno;
f5d2bd
-			p_err("No BTF, cannot determine type info: %s", strerror(-err));
f5d2bd
+		if (libbpf_get_error(vmlinux_btf)) {
f5d2bd
+			p_err("No BTF, cannot determine type info: %s",
f5d2bd
+			      libbpf_errstr(vmlinux_btf));
f5d2bd
 			return NULL;
f5d2bd
 		}
f5d2bd
 	}
f5d2bd
@@ -358,9 +360,9 @@ static struct btf *get_btf(const char *name)
f5d2bd
 		return vmlinux_btf;
f5d2bd
 
f5d2bd
 	mod_btf = btf__load_module_btf(name, vmlinux_btf);
f5d2bd
-	if (!mod_btf) {
f5d2bd
-		err = -errno;
f5d2bd
-		p_err("No BTF for module '%s': %s", name, strerror(-err));
f5d2bd
+	if (libbpf_get_error(mod_btf)) {
f5d2bd
+		p_err("No BTF for module '%s': %s",
f5d2bd
+		      name, libbpf_errstr(mod_btf));
f5d2bd
 		return NULL;
f5d2bd
 	}
f5d2bd
 	return mod_btf;
f5d2bd
@@ -394,11 +396,11 @@ static char *type_id_to_str(struct btf *btf, __s32 type_id, char *str)
f5d2bd
 	default:
f5d2bd
 		do {
f5d2bd
 			type = btf__type_by_id(btf, type_id);
f5d2bd
-			if (!type) {
f5d2bd
+
f5d2bd
+			if (libbpf_get_error(type)) {
f5d2bd
 				name = "?";
f5d2bd
 				break;
f5d2bd
 			}
f5d2bd
-
f5d2bd
 			switch (BTF_INFO_KIND(type->info)) {
f5d2bd
 			case BTF_KIND_CONST:
f5d2bd
 			case BTF_KIND_VOLATILE:
f5d2bd
@@ -553,17 +555,16 @@ static int parse_trace(char *str, struct trace *trace)
f5d2bd
 		return ret;
f5d2bd
 	}
f5d2bd
 	trace->btf = get_btf(func->mod);
f5d2bd
-	if (!trace->btf) {
f5d2bd
-		ret = -errno;
f5d2bd
+	if (libbpf_get_error(trace->btf)) {
f5d2bd
 		p_err("could not get BTF for '%s': %s",
f5d2bd
 		      strlen(func->mod) ? func->mod : "vmlinux",
f5d2bd
-		      strerror(-ret));
f5d2bd
+		      libbpf_errstr(trace->btf));
f5d2bd
 		return -ENOENT;
f5d2bd
 	}
f5d2bd
 	trace->dump = btf_dump__new(trace->btf, NULL, &opts, trace_printf);
f5d2bd
-	if (!trace->dump) {
f5d2bd
-		ret = -errno;
f5d2bd
-		p_err("could not create BTF dump : %n", strerror(-ret));
f5d2bd
+	if (libbpf_get_error(trace->dump)) {
f5d2bd
+		p_err("could not create BTF dump : %n",
f5d2bd
+		      libbpf_errstr(trace->btf));
f5d2bd
 		return -EINVAL;
f5d2bd
 	}
f5d2bd
 
f5d2bd
@@ -823,20 +824,20 @@ static int attach_traces(struct ksnoop_bpf *skel, struct trace *traces,
f5d2bd
 			bpf_program__attach_kprobe(skel->progs.kprobe_entry,
f5d2bd
 						   false,
f5d2bd
 						   traces[i].func.name);
f5d2bd
-		if (!traces[i].links[0]) {
f5d2bd
-			ret = -errno;
f5d2bd
+		ret = libbpf_get_error(traces[i].links[0]);
f5d2bd
+		if (ret) {
f5d2bd
 			p_err("Could not attach kprobe to '%s': %s",
f5d2bd
 			      traces[i].func.name, strerror(-ret));
f5d2bd
 				return ret;
f5d2bd
-		}
f5d2bd
+			}
f5d2bd
 		p_debug("Attached kprobe for '%s'", traces[i].func.name);
f5d2bd
 
f5d2bd
 		traces[i].links[1] =
f5d2bd
 			bpf_program__attach_kprobe(skel->progs.kprobe_return,
f5d2bd
 						   true,
f5d2bd
 						   traces[i].func.name);
f5d2bd
-		if (!traces[i].links[1]) {
f5d2bd
-			ret = -errno;
f5d2bd
+		ret = libbpf_get_error(traces[i].links[1]);
f5d2bd
+		if (ret) {
f5d2bd
 			p_err("Could not attach kretprobe to '%s': %s",
f5d2bd
 			      traces[i].func.name, strerror(-ret));
f5d2bd
 			return ret;
f5d2bd
@@ -848,6 +849,7 @@ static int attach_traces(struct ksnoop_bpf *skel, struct trace *traces,
f5d2bd
 
f5d2bd
 static int cmd_trace(int argc, char **argv)
f5d2bd
 {
f5d2bd
+	struct perf_buffer_opts pb_opts = {};
f5d2bd
 	struct bpf_map *perf_map, *func_map;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct ksnoop_bpf *skel;
f5d2bd
@@ -860,8 +862,7 @@ static int cmd_trace(int argc, char **argv)
f5d2bd
 
f5d2bd
 	skel = ksnoop_bpf__open_and_load();
f5d2bd
 	if (!skel) {
f5d2bd
-		ret = -errno;
f5d2bd
-		p_err("Could not load ksnoop BPF: %s", strerror(-ret));
f5d2bd
+		p_err("Could not load ksnoop BPF: %s", libbpf_errstr(skel));
f5d2bd
 		return 1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
@@ -886,11 +887,12 @@ static int cmd_trace(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	pb = perf_buffer__new(bpf_map__fd(perf_map), pages,
f5d2bd
-			      trace_handler, lost_handler, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		ret = -errno;
f5d2bd
-		p_err("Could not create perf buffer: %s", strerror(-ret));
f5d2bd
+	pb_opts.sample_cb = trace_handler;
f5d2bd
+	pb_opts.lost_cb = lost_handler;
f5d2bd
+	pb = perf_buffer__new(bpf_map__fd(perf_map), pages, &pb_opts);
f5d2bd
+	if (libbpf_get_error(pb)) {
f5d2bd
+		p_err("Could not create perf buffer: %s",
f5d2bd
+		      libbpf_errstr(pb));
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
@@ -904,8 +906,8 @@ static int cmd_trace(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		ret = perf_buffer__poll(pb, 1);
f5d2bd
-		if (ret < 0 && ret != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-ret));
f5d2bd
+		if (ret < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset ret to return 0 if exiting */
f5d2bd
@@ -1005,7 +1007,6 @@ int main(int argc, char *argv[])
f5d2bd
 	if (argc < 0)
f5d2bd
 		usage();
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	return cmd_select(argc, argv);
f5d2bd
diff --git a/libbpf-tools/llcstat.bpf.c b/libbpf-tools/llcstat.bpf.c
f5d2bd
index a36fc2df..fbd5b6c4 100644
f5d2bd
--- a/libbpf-tools/llcstat.bpf.c
f5d2bd
+++ b/libbpf-tools/llcstat.bpf.c
f5d2bd
@@ -36,13 +36,13 @@ int trace_event(__u64 sample_period, bool miss)
f5d2bd
 	return 0;
f5d2bd
 }
f5d2bd
 
f5d2bd
-SEC("perf_event")
f5d2bd
+SEC("perf_event/1")
f5d2bd
 int on_cache_miss(struct bpf_perf_event_data *ctx)
f5d2bd
 {
f5d2bd
 	return trace_event(ctx->sample_period, true);
f5d2bd
 }
f5d2bd
 
f5d2bd
-SEC("perf_event")
f5d2bd
+SEC("perf_event/2")
f5d2bd
 int on_cache_ref(struct bpf_perf_event_data *ctx)
f5d2bd
 {
f5d2bd
 	return trace_event(ctx->sample_period, false);
f5d2bd
diff --git a/libbpf-tools/llcstat.c b/libbpf-tools/llcstat.c
f5d2bd
index be437bc2..150dd38b 100644
f5d2bd
--- a/libbpf-tools/llcstat.c
f5d2bd
+++ b/libbpf-tools/llcstat.c
f5d2bd
@@ -106,8 +106,10 @@ static int open_and_attach_perf_event(__u64 config, int period,
f5d2bd
 			return -1;
f5d2bd
 		}
f5d2bd
 		links[i] = bpf_program__attach_perf_event(prog, fd);
f5d2bd
-		if (!links[i]) {
f5d2bd
-			fprintf(stderr, "failed to attach perf event on cpu: %d\n", i);
f5d2bd
+		if (libbpf_get_error(links[i])) {
f5d2bd
+			fprintf(stderr, "failed to attach perf event on cpu: "
f5d2bd
+				"%d\n", i);
f5d2bd
+			links[i] = NULL;
f5d2bd
 			close(fd);
f5d2bd
 			return -1;
f5d2bd
 		}
f5d2bd
@@ -182,9 +184,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	nr_cpus = libbpf_num_possible_cpus();
f5d2bd
 	if (nr_cpus < 0) {
f5d2bd
 		fprintf(stderr, "failed to get # of possible cpus: '%s'!\n",
f5d2bd
diff --git a/libbpf-tools/mountsnoop.c b/libbpf-tools/mountsnoop.c
f5d2bd
index ac2acc45..0955f59e 100644
f5d2bd
--- a/libbpf-tools/mountsnoop.c
f5d2bd
+++ b/libbpf-tools/mountsnoop.c
f5d2bd
@@ -249,6 +249,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct mountsnoop_bpf *obj;
f5d2bd
 	int err;
f5d2bd
@@ -257,7 +258,11 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	obj = mountsnoop_bpf__open();
f5d2bd
@@ -280,10 +285,11 @@ int main(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
+	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES, &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -302,8 +308,8 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/numamove.c b/libbpf-tools/numamove.c
f5d2bd
index 0747f841..66a53ed6 100644
f5d2bd
--- a/libbpf-tools/numamove.c
f5d2bd
+++ b/libbpf-tools/numamove.c
f5d2bd
@@ -80,9 +80,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = numamove_bpf__open_and_load();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open and/or load BPF object\n");
f5d2bd
@@ -102,15 +107,18 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	signal(SIGINT, sig_handler);
f5d2bd
 
f5d2bd
-	printf("%-10s %18s %18s\n", "TIME", "NUMA_migrations", "NUMA_migrations_ms");
f5d2bd
+	printf("%-10s %18s %18s\n", "TIME", "NUMA_migrations",
f5d2bd
+		"NUMA_migrations_ms");
f5d2bd
 	while (!exiting) {
f5d2bd
 		sleep(1);
f5d2bd
 		time(&t);
f5d2bd
 		tm = localtime(&t);
f5d2bd
 		strftime(ts, sizeof(ts), "%H:%M:%S", tm);
f5d2bd
 		printf("%-10s %18lld %18lld\n", ts,
f5d2bd
-			__atomic_exchange_n(&obj->bss->num, 0, __ATOMIC_RELAXED),
f5d2bd
-			__atomic_exchange_n(&obj->bss->latency, 0, __ATOMIC_RELAXED));
f5d2bd
+			__atomic_exchange_n(&obj->bss->num, 0,
f5d2bd
+					__ATOMIC_RELAXED),
f5d2bd
+			__atomic_exchange_n(&obj->bss->latency, 0,
f5d2bd
+					__ATOMIC_RELAXED));
f5d2bd
 	}
f5d2bd
 
f5d2bd
 cleanup:
f5d2bd
diff --git a/libbpf-tools/offcputime.c b/libbpf-tools/offcputime.c
f5d2bd
index 37a8ec2c..0582b158 100644
f5d2bd
--- a/libbpf-tools/offcputime.c
f5d2bd
+++ b/libbpf-tools/offcputime.c
f5d2bd
@@ -279,9 +279,14 @@ int main(int argc, char **argv)
f5d2bd
 		return 1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = offcputime_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/opensnoop.c b/libbpf-tools/opensnoop.c
f5d2bd
index 557a63cd..5cdac0e5 100644
f5d2bd
--- a/libbpf-tools/opensnoop.c
f5d2bd
+++ b/libbpf-tools/opensnoop.c
f5d2bd
@@ -219,6 +219,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct opensnoop_bpf *obj;
f5d2bd
 	__u64 time_end = 0;
f5d2bd
@@ -228,9 +229,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = opensnoop_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -276,10 +282,13 @@ int main(int argc, char **argv)
f5d2bd
 	printf("%s\n", "PATH");
f5d2bd
 
f5d2bd
 	/* setup event callbacks */
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
 	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+			      &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
 		fprintf(stderr, "failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -297,8 +306,8 @@ int main(int argc, char **argv)
f5d2bd
 	/* main: poll */
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		if (env.duration && get_ktime_ns() > time_end)
f5d2bd
diff --git a/libbpf-tools/readahead.c b/libbpf-tools/readahead.c
f5d2bd
index 17079389..77986011 100644
f5d2bd
--- a/libbpf-tools/readahead.c
f5d2bd
+++ b/libbpf-tools/readahead.c
f5d2bd
@@ -109,9 +109,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = readahead_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/runqlat.c b/libbpf-tools/runqlat.c
f5d2bd
index 5a60b874..249bf794 100644
f5d2bd
--- a/libbpf-tools/runqlat.c
f5d2bd
+++ b/libbpf-tools/runqlat.c
f5d2bd
@@ -193,9 +193,14 @@ int main(int argc, char **argv)
f5d2bd
 		return 1;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = runqlat_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/runqlen.c b/libbpf-tools/runqlen.c
f5d2bd
index 9cbbc739..2f6c5789 100644
f5d2bd
--- a/libbpf-tools/runqlen.c
f5d2bd
+++ b/libbpf-tools/runqlen.c
f5d2bd
@@ -145,8 +145,10 @@ static int open_and_attach_perf_event(int freq, struct bpf_program *prog,
f5d2bd
 			return -1;
f5d2bd
 		}
f5d2bd
 		links[i] = bpf_program__attach_perf_event(prog, fd);
f5d2bd
-		if (!links[i]) {
f5d2bd
-			fprintf(stderr, "failed to attach perf event on cpu: %d\n", i);
f5d2bd
+		if (libbpf_get_error(links[i])) {
f5d2bd
+			fprintf(stderr, "failed to attach perf event on cpu: "
f5d2bd
+				"%d\n", i);
f5d2bd
+			links[i] = NULL;
f5d2bd
 			close(fd);
f5d2bd
 			return -1;
f5d2bd
 		}
f5d2bd
@@ -229,9 +231,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	nr_cpus = libbpf_num_possible_cpus();
f5d2bd
 	if (nr_cpus < 0) {
f5d2bd
 		printf("failed to get # of possible cpus: '%s'!\n",
f5d2bd
diff --git a/libbpf-tools/runqslower.c b/libbpf-tools/runqslower.c
f5d2bd
index b038173e..b21894ca 100644
f5d2bd
--- a/libbpf-tools/runqslower.c
f5d2bd
+++ b/libbpf-tools/runqslower.c
f5d2bd
@@ -145,6 +145,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct runqslower_bpf *obj;
f5d2bd
 	int err;
f5d2bd
@@ -153,9 +154,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = runqslower_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -185,10 +191,12 @@ int main(int argc, char **argv)
f5d2bd
 	else
f5d2bd
 		printf("%-8s %-16s %-6s %14s\n", "TIME", "COMM", "TID", "LAT(us)");
f5d2bd
 
f5d2bd
-	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), 64,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
+	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), 64, &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
 		fprintf(stderr, "failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -201,8 +209,8 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, 100);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/softirqs.c b/libbpf-tools/softirqs.c
f5d2bd
index 34cfdb77..f1678d4c 100644
f5d2bd
--- a/libbpf-tools/softirqs.c
f5d2bd
+++ b/libbpf-tools/softirqs.c
f5d2bd
@@ -195,9 +195,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = softirqs_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/solisten.c b/libbpf-tools/solisten.c
f5d2bd
index adaa668d..e5812f0c 100644
f5d2bd
--- a/libbpf-tools/solisten.c
f5d2bd
+++ b/libbpf-tools/solisten.c
f5d2bd
@@ -137,6 +137,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct solisten_bpf *obj;
f5d2bd
 	int err;
f5d2bd
@@ -145,7 +146,11 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
 	obj = solisten_bpf__open();
f5d2bd
@@ -175,10 +180,11 @@ int main(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
+	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES, &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -196,8 +202,8 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			warn("error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			warn("error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/statsnoop.c b/libbpf-tools/statsnoop.c
f5d2bd
index 3f8f5c58..76779da6 100644
f5d2bd
--- a/libbpf-tools/statsnoop.c
f5d2bd
+++ b/libbpf-tools/statsnoop.c
f5d2bd
@@ -127,6 +127,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct statsnoop_bpf *obj;
f5d2bd
 	int err;
f5d2bd
@@ -135,9 +136,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+
f5d2bd
 	obj = statsnoop_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		warn("failed to open BPF object\n");
f5d2bd
@@ -159,10 +165,12 @@ int main(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
 	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+			      &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -180,8 +188,8 @@ int main(int argc, char **argv)
f5d2bd
 
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			warn("error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			warn("error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/syscount.c b/libbpf-tools/syscount.c
f5d2bd
index 2d687573..35c0e095 100644
f5d2bd
--- a/libbpf-tools/syscount.c
f5d2bd
+++ b/libbpf-tools/syscount.c
f5d2bd
@@ -390,9 +390,14 @@ int main(int argc, char **argv)
f5d2bd
 		goto free_names;
f5d2bd
 	}
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %s\n", strerror(errno));
f5d2bd
+		goto free_names;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = syscount_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		warn("failed to open BPF object\n");
f5d2bd
@@ -418,15 +423,16 @@ int main(int argc, char **argv)
f5d2bd
 	}
f5d2bd
 
f5d2bd
 	obj->links.sys_exit = bpf_program__attach(obj->progs.sys_exit);
f5d2bd
-	if (!obj->links.sys_exit) {
f5d2bd
-		err = -errno;
f5d2bd
-		warn("failed to attach sys_exit program: %s\n", strerror(-err));
f5d2bd
+	err = libbpf_get_error(obj->links.sys_exit);
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to attach sys_exit program: %s\n",
f5d2bd
+		     strerror(-err));
f5d2bd
 		goto cleanup_obj;
f5d2bd
 	}
f5d2bd
 	if (env.latency) {
f5d2bd
 		obj->links.sys_enter = bpf_program__attach(obj->progs.sys_enter);
f5d2bd
-		if (!obj->links.sys_enter) {
f5d2bd
-			err = -errno;
f5d2bd
+		err = libbpf_get_error(obj->links.sys_enter);
f5d2bd
+		if (err) {
f5d2bd
 			warn("failed to attach sys_enter programs: %s\n",
f5d2bd
 			     strerror(-err));
f5d2bd
 			goto cleanup_obj;
f5d2bd
diff --git a/libbpf-tools/tcpconnect.c b/libbpf-tools/tcpconnect.c
f5d2bd
index 101cf72b..82b2bebb 100644
f5d2bd
--- a/libbpf-tools/tcpconnect.c
f5d2bd
+++ b/libbpf-tools/tcpconnect.c
f5d2bd
@@ -324,13 +324,17 @@ static void handle_lost_events(void *ctx, int cpu, __u64 lost_cnt)
f5d2bd
 
f5d2bd
 static void print_events(int perf_map_fd)
f5d2bd
 {
f5d2bd
-	struct perf_buffer *pb;
f5d2bd
+	struct perf_buffer_opts pb_opts = {
f5d2bd
+		.sample_cb = handle_event,
f5d2bd
+		.lost_cb = handle_lost_events,
f5d2bd
+	};
f5d2bd
+	struct perf_buffer *pb = NULL;
f5d2bd
 	int err;
f5d2bd
 
f5d2bd
-	pb = perf_buffer__new(perf_map_fd, 128,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		err = -errno;
f5d2bd
+	pb = perf_buffer__new(perf_map_fd, 128, &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
 		warn("failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
@@ -338,8 +342,8 @@ static void print_events(int perf_map_fd)
f5d2bd
 	print_events_header();
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, 100);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			warn("error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			warn("error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
@@ -365,9 +369,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		warn("failed to increase rlimit: %s\n", strerror(errno));
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = tcpconnect_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		warn("failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/tcpconnlat.c b/libbpf-tools/tcpconnlat.c
f5d2bd
index 8eae76ae..3cab2115 100644
f5d2bd
--- a/libbpf-tools/tcpconnlat.c
f5d2bd
+++ b/libbpf-tools/tcpconnlat.c
f5d2bd
@@ -161,6 +161,7 @@ int main(int argc, char **argv)
f5d2bd
 		.parser = parse_arg,
f5d2bd
 		.doc = argp_program_doc,
f5d2bd
 	};
f5d2bd
+	struct perf_buffer_opts pb_opts;
f5d2bd
 	struct perf_buffer *pb = NULL;
f5d2bd
 	struct tcpconnlat_bpf *obj;
f5d2bd
 	int err;
f5d2bd
@@ -169,9 +170,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = tcpconnlat_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
@@ -193,10 +199,15 @@ int main(int argc, char **argv)
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
+	pb_opts.sample_cb = handle_event;
f5d2bd
+
f5d2bd
+	pb_opts.lost_cb = handle_lost_events;
f5d2bd
 	pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
f5d2bd
-			      handle_event, handle_lost_events, NULL, NULL);
f5d2bd
-	if (!pb) {
f5d2bd
-		fprintf(stderr, "failed to open perf buffer: %d\n", errno);
f5d2bd
+			      &pb_opts);
f5d2bd
+	err = libbpf_get_error(pb);
f5d2bd
+	if (err) {
f5d2bd
+		pb = NULL;
f5d2bd
+		fprintf(stderr, "failed to open perf buffer: %d\n", err);
f5d2bd
 		goto cleanup;
f5d2bd
 	}
f5d2bd
 
f5d2bd
@@ -211,6 +222,7 @@ int main(int argc, char **argv)
f5d2bd
 			"PID", "COMM", "IP", "SADDR", "DADDR", "DPORT", "LAT(ms)");
f5d2bd
 	}
f5d2bd
 
f5d2bd
+
f5d2bd
 	if (signal(SIGINT, sig_int) == SIG_ERR) {
f5d2bd
 		fprintf(stderr, "can't set signal handler: %s\n", strerror(errno));
f5d2bd
 		err = 1;
f5d2bd
@@ -220,8 +232,8 @@ int main(int argc, char **argv)
f5d2bd
 	/* main: poll */
f5d2bd
 	while (!exiting) {
f5d2bd
 		err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
f5d2bd
-		if (err < 0 && err != -EINTR) {
f5d2bd
-			fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
f5d2bd
+		if (err < 0 && errno != EINTR) {
f5d2bd
+			fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
f5d2bd
 			goto cleanup;
f5d2bd
 		}
f5d2bd
 		/* reset err to return 0 if exiting */
f5d2bd
diff --git a/libbpf-tools/tcprtt.c b/libbpf-tools/tcprtt.c
f5d2bd
index bed6efa7..bdff55bb 100644
f5d2bd
--- a/libbpf-tools/tcprtt.c
f5d2bd
+++ b/libbpf-tools/tcprtt.c
f5d2bd
@@ -225,9 +225,14 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %d\n", err);
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	obj = tcprtt_bpf__open();
f5d2bd
 	if (!obj) {
f5d2bd
 		fprintf(stderr, "failed to open BPF object\n");
f5d2bd
diff --git a/libbpf-tools/trace_helpers.c b/libbpf-tools/trace_helpers.c
f5d2bd
index 322b3c4f..f37015e7 100644
f5d2bd
--- a/libbpf-tools/trace_helpers.c
f5d2bd
+++ b/libbpf-tools/trace_helpers.c
f5d2bd
@@ -967,6 +967,16 @@ unsigned long long get_ktime_ns(void)
f5d2bd
 	return ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec;
f5d2bd
 }
f5d2bd
 
f5d2bd
+int bump_memlock_rlimit(void)
f5d2bd
+{
f5d2bd
+	struct rlimit rlim_new = {
f5d2bd
+		.rlim_cur	= RLIM_INFINITY,
f5d2bd
+		.rlim_max	= RLIM_INFINITY,
f5d2bd
+	};
f5d2bd
+
f5d2bd
+	return setrlimit(RLIMIT_MEMLOCK, &rlim_new);
f5d2bd
+}
f5d2bd
+
f5d2bd
 bool is_kernel_module(const char *name)
f5d2bd
 {
f5d2bd
 	bool found = false;
f5d2bd
@@ -997,22 +1007,20 @@ bool fentry_exists(const char *name, const char *mod)
f5d2bd
 	const struct btf_type *type;
f5d2bd
 	const struct btf_enum *e;
f5d2bd
 	char sysfs_mod[80];
f5d2bd
-	int id = -1, i, err;
f5d2bd
+	int id = -1, i;
f5d2bd
 
f5d2bd
 	base = btf__parse(sysfs_vmlinux, NULL);
f5d2bd
-	if (!base) {
f5d2bd
-		err = -errno;
f5d2bd
+	if (libbpf_get_error(base)) {
f5d2bd
 		fprintf(stderr, "failed to parse vmlinux BTF at '%s': %s\n",
f5d2bd
-			sysfs_vmlinux, strerror(-err));
f5d2bd
+			sysfs_vmlinux, strerror(-libbpf_get_error(base)));
f5d2bd
 		goto err_out;
f5d2bd
 	}
f5d2bd
 	if (mod && module_btf_exists(mod)) {
f5d2bd
 		snprintf(sysfs_mod, sizeof(sysfs_mod), "/sys/kernel/btf/%s", mod);
f5d2bd
 		btf = btf__parse_split(sysfs_mod, base);
f5d2bd
-		if (!btf) {
f5d2bd
-			err = -errno;
f5d2bd
+		if (libbpf_get_error(btf)) {
f5d2bd
 			fprintf(stderr, "failed to load BTF from %s: %s\n",
f5d2bd
-				sysfs_mod, strerror(-err));
f5d2bd
+				sysfs_mod, strerror(-libbpf_get_error(btf)));
f5d2bd
 			btf = base;
f5d2bd
 			base = NULL;
f5d2bd
 		}
f5d2bd
diff --git a/libbpf-tools/trace_helpers.h b/libbpf-tools/trace_helpers.h
f5d2bd
index 98fd640f..61cbe433 100644
f5d2bd
--- a/libbpf-tools/trace_helpers.h
f5d2bd
+++ b/libbpf-tools/trace_helpers.h
f5d2bd
@@ -58,6 +58,7 @@ void print_linear_hist(unsigned int *vals, int vals_size, unsigned int base,
f5d2bd
 		unsigned int step, const char *val_type);
f5d2bd
 
f5d2bd
 unsigned long long get_ktime_ns(void);
f5d2bd
+int bump_memlock_rlimit(void);
f5d2bd
 
f5d2bd
 bool is_kernel_module(const char *name);
f5d2bd
 
f5d2bd
diff --git a/libbpf-tools/vfsstat.c b/libbpf-tools/vfsstat.c
f5d2bd
index 5519c366..3a8a51d8 100644
f5d2bd
--- a/libbpf-tools/vfsstat.c
f5d2bd
+++ b/libbpf-tools/vfsstat.c
f5d2bd
@@ -150,9 +150,15 @@ int main(int argc, char **argv)
f5d2bd
 	if (err)
f5d2bd
 		return err;
f5d2bd
 
f5d2bd
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
f5d2bd
 	libbpf_set_print(libbpf_print_fn);
f5d2bd
 
f5d2bd
+	err = bump_memlock_rlimit();
f5d2bd
+	if (err) {
f5d2bd
+		fprintf(stderr, "failed to increase rlimit: %s\n",
f5d2bd
+				strerror(errno));
f5d2bd
+		return 1;
f5d2bd
+	}
f5d2bd
+
f5d2bd
 	skel = vfsstat_bpf__open();
f5d2bd
 	if (!skel) {
f5d2bd
 		fprintf(stderr, "failed to open BPF skelect\n");
f5d2bd
-- 
f5d2bd
2.35.1
f5d2bd