[DTrace-devel] [PATCH 4/4] Remove the string length prefix

Kris Van Hees kris.van.hees at oracle.com
Wed Jan 26 16:29:07 UTC 2022


This is the final stage of discontinuing the string length prefix code.
It removes the actual storage allocation for the 2-byte string length
prefix, and updates all code that adjusted pointers because of the
prefix.  The dt_strlen_store() function is gone.

This change affects the offset calculation for variab;e storage when a
string is involved.  Test results for gvar/tst.undecl-offset.r are
updated to reflect this.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 bpf/basename.S                                | 28 +++++------------
 bpf/dirname.S                                 | 28 +++++------------
 bpf/index.S                                   | 11 +------
 bpf/lltostr.S                                 | 12 +------
 bpf/rindex.S                                  | 11 +------
 bpf/strchr.S                                  | 25 +++------------
 bpf/strcmp.S                                  | 18 +++--------
 bpf/strjoin.S                                 | 31 ++++---------------
 bpf/strlen.c                                  | 12 +------
 bpf/strrchr.S                                 | 29 +++++------------
 bpf/strtok.S                                  | 25 ++++-----------
 bpf/substr.S                                  | 27 +++-------------
 libdtrace/dt_bpf.c                            |  8 ++---
 libdtrace/dt_cg.c                             | 10 +-----
 libdtrace/dt_dctx.h                           |  8 +++--
 libdtrace/dt_ident.c                          |  6 +---
 libdtrace/dt_string.c                         | 11 +------
 libdtrace/dt_string.h                         |  5 +--
 libdtrace/dt_strtab.c                         | 19 +++++-------
 libdtrace/dt_subr.c                           |  4 +--
 .../variables/gvar/tst.undecl-offset.r        |  2 +-
 21 files changed, 77 insertions(+), 253 deletions(-)

diff --git a/bpf/basename.S b/bpf/basename.S
index 2839614c..6bb96b70 100644
--- a/bpf/basename.S
+++ b/bpf/basename.S
@@ -1,10 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read_str	45
 
 /*
@@ -24,9 +22,6 @@ dt_basename :
 	mov	SRC, %r1
 	mov	DST, %r2
 
-	/* ignore the string-length prefix */
-	add	SRC, DT_STRLEN_BYTES
-
 	/* r0 = bpf_probe_read_str(dst, STRSZ + 1, src) */
 	mov	%r1, DST
 	lddw	%r2, STRSZ
@@ -83,21 +78,14 @@ dt_basename :
 	mov	LEN, 0
 	/* bgn++ */
 	add	BGN, 1
-	/* bpf_probe_read_str(dst + DT_STRLEN_BYTES, len + 1, &src[bgn]) */
+	/* bpf_probe_read_str(dst, len + 1, &src[bgn]) */
 	mov	%r1, DST
-	add	%r1, DT_STRLEN_BYTES
 	mov	%r2, LEN
 	add	%r2, 1
 	mov	%r3, SRC
 	add	%r3, BGN
 	call	BPF_FUNC_probe_read_str
 
-.Lcoda:
-	/* dt_strlen_store(len, dst) */
-	mov	%r1, LEN
-	mov	%r2, DST
-	call	dt_strlen_store
-
 	/* return */
 	exit
 
@@ -106,18 +94,18 @@ dt_basename :
 	 * The output string is simply ".\0".
 	 */
 	mov	LEN, 1
-	stb	[DST+DT_STRLEN_BYTES], '.'
-	stb	[DST+(DT_STRLEN_BYTES+1)], 0
-	ja	.Lcoda
+	stb	[DST+0], '.'
+	stb	[DST+1], 0
+	exit
 
 .Lslash:
 	/*
 	 * The output string is simply "/\0".
 	 */
 	mov	LEN, 1
-	stb	[DST+DT_STRLEN_BYTES], '/'
-	stb	[DST+(DT_STRLEN_BYTES+1)], 0
-	ja	.Lcoda
+	stb	[DST+0], '/'
+	stb	[DST+1], 0
+	exit
 #undef SRC
 #undef DST
 #undef BGN
diff --git a/bpf/dirname.S b/bpf/dirname.S
index 908fa68a..e5795f06 100644
--- a/bpf/dirname.S
+++ b/bpf/dirname.S
@@ -1,10 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read_str	45
 
 /*
@@ -23,9 +21,6 @@ dt_dirname :
 	mov	SRC, %r1
 	mov	DST, %r2
 
-	/* ignore the string-length prefix */
-	add	SRC, DT_STRLEN_BYTES
-
 	/* r0 = bpf_probe_read_str(dst, STRSZ + 1, src) */
 	mov	%r1, DST
 	lddw	%r2, STRSZ
@@ -100,20 +95,13 @@ dt_dirname :
 	 * The output string is up to the end of the dirname.
 	 */
 
-	/* bpf_probe_read_str(dst + DT_STRLEN_BYTES, len + 1, src) */
+	/* bpf_probe_read_str(dst, len + 1, src) */
 	mov	%r1, DST
-	add	%r1, DT_STRLEN_BYTES
 	mov	%r2, LEN
 	add	%r2, 1
 	mov	%r3, SRC
 	call	BPF_FUNC_probe_read_str
 
-.Lcoda:
-	/* dt_strlen_store(len, dst) */
-	mov	%r1, LEN
-	mov	%r2, DST
-	call	dt_strlen_store
-
 	/* return */
 	exit
 
@@ -122,18 +110,18 @@ dt_dirname :
 	 * The output string is simply ".".
 	 */
 	mov	LEN, 1
-	stb	[DST+DT_STRLEN_BYTES], '.'
-	stb	[DST+(DT_STRLEN_BYTES+1)], 0
-	ja	.Lcoda
+	stb	[DST+0], '.'
+	stb	[DST+1], 0
+	exit
 
 .Lslash:
 	/*
 	 * The output string is simply "/".
 	 */
 	mov	LEN, 1
-	stb	[DST+DT_STRLEN_BYTES], '/'
-	stb	[DST+(DT_STRLEN_BYTES+1)], 0
-	ja	.Lcoda
+	stb	[DST+0], '/'
+	stb	[DST+1], 0
+	exit
 #undef SRC
 #undef DST
 #undef LEN
diff --git a/bpf/index.S b/bpf/index.S
index 1d484256..f64a24dd 100644
--- a/bpf/index.S
+++ b/bpf/index.S
@@ -1,10 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read	4
 #define BPF_FUNC_probe_read_str	45
 
@@ -84,10 +82,6 @@ dt_index_match:
  *     uint64_t r0, tlen;
  *     uint64_t buflen;
  *
- *     // ignore length prefix
- *     s += DT_STRLEN_BYTES;
- *     t += DT_STRLEN_BYTES;
- *
  *     // determine actual start index
  *     if (start < 0) start = 0;
  *
@@ -135,9 +129,6 @@ dt_index_match:
 	.global	dt_index
 	.type	dt_index, @function
 dt_index:
-	add	%r1, DT_STRLEN_BYTES		/* s += DT_STRLEN_BYTES */
-	add	%r2, DT_STRLEN_BYTES		/* t += DT_STRLEN_BYTES */
-
 	jsge	%r3, 0, 1
 	mov	%r3, 0				/* if (start < 0) start = 0 */
 
diff --git a/bpf/lltostr.S b/bpf/lltostr.S
index 6b600264..606b277a 100644
--- a/bpf/lltostr.S
+++ b/bpf/lltostr.S
@@ -1,9 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
 #define BPF_FUNC_probe_read	4
 #define MAXCHARS		19
 
@@ -46,9 +45,6 @@
  *
  *     LEN = min(IDX, STRSZ)
  *
- *     dt_strlen_store(LEN, STR)
- *     STR += DT_STRLEN_BYTES
- *
  *     // copy to output string
  *     bpf_probe_read(STR, LEN, %fp + -IDX)
  *
@@ -140,12 +136,6 @@ dt_lltostr:
 	jle	LEN, %r1, 1
 	mov	LEN, %r1			/* LEN = min(IDX, STRSZ) */
 
-	mov	%r1, LEN
-	mov	%r2, STR
-	call	dt_strlen_store			/* dt_strlen_store(LEN, STR) */
-
-	add	STR, DT_STRLEN_BYTES		/* STR += DT_STRLEN_BYTES */
-
 	mov	%r1, STR
 	mov	%r2, LEN
 	mov	%r3, %fp
diff --git a/bpf/rindex.S b/bpf/rindex.S
index d77257c3..bd5e4574 100644
--- a/bpf/rindex.S
+++ b/bpf/rindex.S
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -17,8 +17,6 @@
  *   - In the call to rindex.S, start<0 means to use the default.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read	4
 #define BPF_FUNC_probe_read_str	45
 
@@ -29,10 +27,6 @@
  *     uint64_t r0, tlen;
  *     uint64_t buflen;
  *
- *     // ignore length prefix
- *     s += DT_STRLEN_BYTES;
- *     t += DT_STRLEN_BYTES;
- *
  *     // round buflen for dt_index_match()
  *     buflen = STRSZ rounded up to multiple of 8;
  *
@@ -82,9 +76,6 @@
 	.global	dt_rindex
 	.type	dt_rindex, @function
 dt_rindex:
-	add	%r1, DT_STRLEN_BYTES		/* s += DT_STRLEN_BYTES */
-	add	%r2, DT_STRLEN_BYTES		/* t += DT_STRLEN_BYTES */
-
 	lddw	%r6, STRSZ
 	add	%r6, 7
 	and	%r6, -8
diff --git a/bpf/strchr.S b/bpf/strchr.S
index 028c8f82..2777f3a7 100644
--- a/bpf/strchr.S
+++ b/bpf/strchr.S
@@ -1,10 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read	4
 #define BPF_FUNC_probe_read_str	45
 
@@ -24,7 +22,7 @@
  *     [%fp-32]=tmp
  *
  *     // make temporary copy of string and get string length
- *     r6 = bpf_probe_read_str(dst, STRSZ, src + DT_STRLEN_BYTES);
+ *     r6 = bpf_probe_read_str(dst, STRSZ, src);
  *     r6--;
  *
  *     // xor the char with every byte;  a match results in NULL byte
@@ -40,12 +38,9 @@
  *     // determine length of output string
  *     r6 -= r8;
  *     if (r6 <= 0) return -1;
- *     dt_strlen_store(r6, dst);
  *
  *     // write output string
- *     r8 += DT_STRLEN_BYTES;
- *     bpf_probe_read(dst + DT_STRLEN_BYTES, r6, src + r8);
- *     r6 += DT_STRLEN_BYTES;
+ *     bpf_probe_read(dst, r6, src + r8);
  *     dst[r6] = '\0';
  *
  *     return 0;
@@ -75,8 +70,7 @@ dt_strchr :
 	ldxdw	%r1, [%fp+-24]
 	lddw	%r2, STRSZ
 	ldxdw	%r3, [%fp+-8]
-	add	%r3, DT_STRLEN_BYTES
-	call	BPF_FUNC_probe_read_str	/* r6 = bpf_probe_read_str(dst, STRSZ, src + DT_STRLEN_BYTES) */
+	call	BPF_FUNC_probe_read_str	/* r6 = bpf_probe_read_str(dst, STRSZ, src) */
 	mov	%r6, %r0
 
 	jsle	%r6, 0, .Lerror
@@ -119,20 +113,11 @@ dt_strchr :
 
 	jsle	%r6, 0, .Lerror		/* if (r6 <= 0) return -1 */
 
-	mov	%r1, %r6
-	ldxdw	%r2, [%fp+-24]
-	call	dt_strlen_store		/* dt_strlen_store(r6, dst) */
-
-	add	%r8, DT_STRLEN_BYTES	/* r8 += DT_STRLEN_BYTES */
-
 	ldxdw	%r1, [%fp+-24]
-	add	%r1, DT_STRLEN_BYTES
 	mov	%r2, %r6
 	ldxdw	%r3, [%fp+-8]
 	add	%r3, %r8
-	call	BPF_FUNC_probe_read	/* bpf_probe_read(dst + DT_STRLEN_BYTES, r6, src + r8) */
-
-	add	%r6, DT_STRLEN_BYTES	/* r6 += DT_STRLEN_BYTES */
+	call	BPF_FUNC_probe_read	/* bpf_probe_read(dst, r6, src + r8) */
 
 	ldxdw	%r1, [%fp+-24]
 	add	%r1, %r6		/* dst[r6] = '\0' */
diff --git a/bpf/strcmp.S b/bpf/strcmp.S
index 11219eda..75177469 100644
--- a/bpf/strcmp.S
+++ b/bpf/strcmp.S
@@ -1,10 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read	4
 #define BPF_FUNC_probe_read_str	45
 
@@ -70,8 +68,8 @@ dt_strcmp_not :
  *     r8 = STRSZ
  *
  *     // make temporary copies of strings
- *     r6 = bpf_probe_read_str(tmp1, STRSZ, s + DT_STRLEN_BYTES);
- *     r7 = bpf_probe_read_str(tmp2, STRSZ, t + DT_STRLEN_BYTES);
+ *     r6 = bpf_probe_read_str(tmp1, STRSZ, s);
+ *     r7 = bpf_probe_read_str(tmp2, STRSZ, t);
  *     tmp1[r6] = '\0';
  *     tmp2[r7] = '\0';
  *
@@ -88,7 +86,6 @@ dt_strcmp_not :
  *     // based on this location, judge if the strings are >, <, or ==
  *     if (r0 > r6) goto Lsame;
  *     if (r0 > r7) goto Lsame;
- *     r0 += DT_STRLEN_BYTES;
  *     if (s[r0] > t[r0]) return +1;
  *     if (s[r0] < t[r0]) return +1;
  *
@@ -114,8 +111,7 @@ dt_strcmp :
 	ldxdw	%r1, [%fp+-24]
 	mov	%r2, %r8
 	ldxdw	%r3, [%fp+-8]
-	add	%r3, DT_STRLEN_BYTES
-	call	BPF_FUNC_probe_read_str	/* r6 = bpf_probe_read_str(tmp1, STRSZ, s + DT_STRLEN_BYTES) */
+	call	BPF_FUNC_probe_read_str	/* r6 = bpf_probe_read_str(tmp1, STRSZ, s) */
 	mov	%r6, %r0
 	jle	%r6, %r8, 1
 	mov	%r6, %r8
@@ -123,8 +119,7 @@ dt_strcmp :
 	ldxdw	%r1, [%fp+-32]
 	mov	%r2, %r8
 	ldxdw	%r3, [%fp+-16]
-	add	%r3, DT_STRLEN_BYTES
-	call	BPF_FUNC_probe_read_str	/* r7 = bpf_probe_read_str(tmp2, STRSZ, t + DT_STRLEN_BYTES) */
+	call	BPF_FUNC_probe_read_str	/* r7 = bpf_probe_read_str(tmp2, STRSZ, t) */
 	mov	%r7, %r0
 	jle	%r7, %r8, 1
 	mov	%r7, %r8
@@ -155,7 +150,6 @@ dt_strcmp :
 
 	jsle	%r0, 0, .L0		/* help the BPF verifier */
 	lddw	%r8, STRSZ
-	sub	%r8, DT_STRLEN_BYTES
 	jlt	%r0, %r8, 1
 	mov	%r0, %r8
 
@@ -164,8 +158,6 @@ dt_strcmp :
 	jgt	%r0, %r6, .Lsame	/* if (r0 > r6) goto Lsame */
 	jgt	%r0, %r8, .Lsame	/* if (r0 > r8) goto Lsame */
 
-	add	%r0, DT_STRLEN_BYTES	/* r0 += DT_STRLEN_BYTES */
-
 	ldxdw	%r4, [%fp+-8]
 	add	%r4, %r0
 	ldxb	%r4, [%r4+0]		/* s[r0] */
diff --git a/bpf/strjoin.S b/bpf/strjoin.S
index 4e8d3718..efeab029 100644
--- a/bpf/strjoin.S
+++ b/bpf/strjoin.S
@@ -1,10 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read_str	45
 
 /*
@@ -22,43 +20,26 @@ dt_strjoin:
 	lddw	%r6, STRSZ
 	add	%r6, 1			/* cnt = STRSZ + 1 */
 
-	add	%r1, DT_STRLEN_BYTES	/* dst is in %r1 already */
 	mov	%r2, %r6
 	mov	%r3, %r7
-	add	%r3, DT_STRLEN_BYTES
-	call	BPF_FUNC_probe_read_str	/*
-					 * rc = probe_read_str(
-					 *	  &dst[DT_STRLEN_BYTES],
-					 *	  cnt,
-					 *	  &s1[DT_STRLEN_BYTES]);
-					 */
+	call	BPF_FUNC_probe_read_str	/* rc = probe_read_str(dst, cnt, s1); */
 	jsle	%r0, 0, .Lexit		/* if (rc s<= 0) goto .Lexit; */
 	mov	%r7, %r0		/* len = rc */
-	jeq	%r7, %r6, .Lset_len	/* if (len == cnt) goto .Lset_len; */
+	jeq	%r7, %r6, .Lexit	/* if (len == cnt) goto .Lexit; */
 	sub	%r7, 1			/* len-- */
 
 	mov	%r1, %r9
-	add	%r1, DT_STRLEN_BYTES
 	add	%r1, %r7
 	mov	%r2, %r6
 	sub	%r2, %r7
 	mov	%r3, %r8
-	add	%r3, DT_STRLEN_BYTES
 	call	BPF_FUNC_probe_read_str	/*
-					 * rc = probe_read_str(
-					 *	  &dst[DT_STRLEN_BYTES + len],
-					 *	  cnt - len,
-					 *	  &s2[DT_STRLEN_BYTES]);
+					 * rc = probe_read_str(dst, cnt - len,
+					 *		       s2);
 					 */
-	jsle	%r0, 0, .Lexit		/* if (rc s<= 0) goto .Lset_len; */
+	jsle	%r0, 0, .Lexit		/* if (rc s<= 0) goto .Lexit */
 	add	%r7, %r0		/* len += rc */
 
-.Lset_len:
-	sub	%r7, 1			/* len-- */
-	mov	%r1, %r7
-	mov	%r2, %r9
-	call	dt_strlen_store		/* dt_strlen_store(len - 1, dst) */
-
 .Lexit:
 	exit
 	.size	dt_strjoin, .-dt_strjoin
diff --git a/bpf/strlen.c b/bpf/strlen.c
index 889b2949..71ddbca4 100644
--- a/bpf/strlen.c
+++ b/bpf/strlen.c
@@ -8,8 +8,6 @@
 #include <dt_dctx.h>
 #include <bpf-lib.h>
 
-#define DT_STRLEN_BYTES	2
-
 #ifndef noinline
 # define noinline	__attribute__((noinline))
 #endif
@@ -17,20 +15,12 @@
 extern uint64_t STBSZ;
 extern uint64_t STRSZ;
 
-noinline void dt_strlen_store(uint64_t val, char *str)
-{
-	uint8_t		*buf = (uint8_t *)str;
-
-	buf[0] = (uint8_t)(val >> 8);
-	buf[1] = (uint8_t)(val & 0xff);
-}
-
 noinline uint64_t dt_strlen(const dt_dctx_t *dctx, const char *str)
 {
 	char	*tmp = dctx->strtab + (uint64_t)&STBSZ;
 	int64_t	len;
 
-	len = bpf_probe_read_str(tmp, (uint64_t)&STRSZ + 1, str + DT_STRLEN_BYTES);
+	len = bpf_probe_read_str(tmp, (uint64_t)&STRSZ + 1, str);
 	set_not_neg_bound(len);
 
 	return len - 1;		/* bpf_probe_read_str() never returns 0 */
diff --git a/bpf/strrchr.S b/bpf/strrchr.S
index 7547591a..8273b59c 100644
--- a/bpf/strrchr.S
+++ b/bpf/strrchr.S
@@ -1,10 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read	4
 #define BPF_FUNC_probe_read_str	45
 
@@ -17,13 +15,13 @@
  *     [%fp-16]=c
  *     [%fp-24]=dst
  *
- *     r6 = bpf_probe_read_str(dst, STRSZ, src + DT_STRLEN_BYTES);
+ *     r6 = bpf_probe_read_str(dst, STRSZ, src);
  *     r6--;
  *
  *     r8 = r6;
  * Lloop:
  *     r8--;
- *     r3 = src[DT_STRLEN_BYTES + r8];
+ *     r3 = src[r8];
  *     r3 <<= 56;
  *     if (r3 == c) goto Lfound;
  *     if (r8 > 0) goto Lloop;
@@ -33,11 +31,8 @@
  *
  * Lfound:
  *     r6 -= r8;
- *     dt_strlen_store(r6, dst);
- *     r8 += DT_STRLEN_BYTES;
- *     bpf_probe_read(dst + DT_STRLEN_BYTES, r6, src + r8);
+ *     bpf_probe_read(dst, r6, src + r8);
  *
- *     r6 += DT_STRLEN_BYTES;
  *     dst[r6] = '\0';
  *
  *     return 0;
@@ -57,8 +52,7 @@ dt_strrchr :
 	ldxdw	%r1, [%fp+-24]
 	lddw	%r2, STRSZ
 	ldxdw	%r3, [%fp+-8]
-	add	%r3, DT_STRLEN_BYTES
-	call	BPF_FUNC_probe_read_str	/* r6 = bpf_probe_read_str(dst, STRSZ, src + DT_STRLEN_BYTES) */
+	call	BPF_FUNC_probe_read_str	/* r6 = bpf_probe_read_str(dst, STRSZ, src) */
 	jsle	%r0, 0, .Lnone
 	mov	%r6, %r0
 
@@ -71,10 +65,9 @@ dt_strrchr :
 .Lloop:
 	sub	%r8, 1			/* r8-- */
 	mov	%r4, %r8
-	add	%r4, DT_STRLEN_BYTES
 	ldxdw	%r3, [%fp+-8]
 	add	%r3, %r4
-	ldxb	%r3, [%r3+0]		/* r3 = src[DT_STRLEN_BYTES+ r8] */
+	ldxb	%r3, [%r3+0]		/* r3 = src[r8] */
 	lsh	%r3, 56			/* r3 <<= 56 */
 	jeq	%r3, %r5, .Lfound	/* if (r3 == c) goto Lfound */
 	jgt	%r8, 0, .Lloop		/* if (r8 > 0) goto Lloop */
@@ -87,20 +80,12 @@ dt_strrchr :
 	sub	%r6, %r8		/* r6 -= r8 */
 	jsle	%r6, 0, .Lnone
 
-	mov	%r1, %r6
-	ldxdw	%r2, [%fp+-24]
-	call	dt_strlen_store		/* dt_strlen_store(r6, dst) */
-
-	add	%r8, DT_STRLEN_BYTES	/* r8 += DT_STRLEN_BYTES */
-
 	ldxdw	%r1, [%fp+-24]
-	add	%r1, DT_STRLEN_BYTES
 	mov	%r2, %r6
 	ldxdw	%r3, [%fp+-8]
 	add	%r3, %r8
-	call	BPF_FUNC_probe_read	/* bpf_probe_read(dst + DT_STRLEN_BYTES, r6, src + r8) */
+	call	BPF_FUNC_probe_read	/* bpf_probe_read(dst, r6, src + r8) */
 
-	add	%r6, DT_STRLEN_BYTES	/* r6 += DT_STRLEN_BYTES */
 	ldxdw	%r1, [%fp+-24]
 	add	%r1, %r6		/* dst[r6] = '\0' */
 	mov	%r2, 0
diff --git a/bpf/strtok.S b/bpf/strtok.S
index 9b2563e0..b745c2a3 100644
--- a/bpf/strtok.S
+++ b/bpf/strtok.S
@@ -1,10 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read	4
 #define BPF_FUNC_probe_read_str	45
 
@@ -291,8 +289,6 @@ dt_strtok_flip:
  * void dt_strtok(char *dst, char *str, const char *del, char *tmp)
  * {
  *     // discard delimiter length prefix; we look for the NULL terminator anyhow
- *     del += DT_STRLEN_BYTES
- *
  *     // len = roundup(STRSZ + 1, 8)
  *     len = ((STRSZ + 1) + 7) & -8
  *
@@ -336,9 +332,8 @@ dt_strtok_flip:
  *     bgn += *((uint64_t*)str)
  *
  *     // copy str + bgn to destination
- *     dt_strlen_store(len, dst)
- *     bpf_probe_read(dst + DT_STRLEN_BYTES, len, str + 8 + bgn)
- *     dst[DT_STRLEN_BYTES + len] = '\0'
+ *     bpf_probe_read(dst, len, str + 8 + bgn)
+ *     dst[len] = '\0'
  *
  *     // update the 8-byte prefix (strtok offset)
  *     bgn += len
@@ -371,9 +366,6 @@ dt_strtok:
 	mov	DEL, %r3
 	mov	TMP, %r4
 
-	/* discard delimiter length prefix; we look for the NULL terminator anyhow */
-	add	DEL, DT_STRLEN_BYTES	/* del += DT_STRLEN_BYTES */
-
 	/* len = roundup(STRSZ + 1, 8) */
 	lddw	LEN, STRSZ
 	add	LEN, 8
@@ -459,23 +451,18 @@ dt_strtok:
 	mov	BGN, 0
 
 	/* copy str + bgn to destination */
-	mov	%r1, LEN
-	ldxdw	%r2, DST_X
-	call	dt_strlen_store		/* dt_strlen_store(len, dst) */
-
 	ldxdw	%r1, DST_X
-	add	%r1, DT_STRLEN_BYTES
 	mov	%r2, LEN
 	mov	%r3, STR
 	add	%r3, 8
 	add	%r3, BGN
-	call	BPF_FUNC_probe_read	/* bpf_probe_read(dst + DT_STRLEN_BYTES, len, str + 8 + bgn) */
+	call	BPF_FUNC_probe_read	/* bpf_probe_read(dst, len, str + 8 + bgn) */
 
 	mov	%r1, 0
 	ldxdw	%r2, DST_X
 	add	%r2, LEN
-	stxb	[%r2+DT_STRLEN_BYTES], %r1
-					/* dst[DT_STRLEN_BYTES + len] = '\0' */
+	stxb	[%r2+0], %r1
+					/* dst[len] = '\0' */
 
 	/* update the 8-byte prefix (strtok offset) */
 	add	BGN, LEN		/* bgn += len */
diff --git a/bpf/substr.S b/bpf/substr.S
index a6cf5a57..6a8f4a22 100644
--- a/bpf/substr.S
+++ b/bpf/substr.S
@@ -3,8 +3,6 @@
  * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
-#define DT_STRLEN_BYTES		2
-
 #define BPF_FUNC_probe_read_str	45
 
 /*
@@ -49,13 +47,11 @@ dt_substr :
 	 * string length.)
 	 */
 	mov	%r3, %r2
-	add	%r3, DT_STRLEN_BYTES
 	mov	%r2, %r8
 	add	%r8, 1
 	call	BPF_FUNC_probe_read_str	/*
-					 * len = probe_read_str(
-					 *	   dst, STRSZ + 1,
-					 *	   &src[DT_STRLEN_BYTES]);
+					 * len = probe_read_str(dst, STRSZ + 1,
+					 *			src);
 					 */
 	jslt	%r0, 0, .Lempty		/* if (len < 0) goto Lempty; */
 	sub	%r0, 1			/* len--; */
@@ -111,11 +107,9 @@ dt_substr :
 .Lcopy:
 	/*
 	 * Use the probe_read_str() BPF helper to copy (cnt + 1) bytes from
-	 * &src[DT_STRLEN_BYTES + idx] to &dst[DT_STRLEN_BYTES].  We ensure
-	 * that cnt is capped at STRSZ.
+	 * &src[idx] to dst.  We ensure that cnt is capped at STRSZ.
 	 */
 	mov	%r1, %r9
-	add	%r1, DT_STRLEN_BYTES
 	mov	%r2, %r7
 	lddw	%r0, STRSZ
 	jle	%r2, %r0, .Lcnt_ok	/* if (cnt <= STRSZ) goto Lcnt_ok; */
@@ -123,27 +117,16 @@ dt_substr :
 .Lcnt_ok:
 	add	%r2, 1
 	ldxdw	%r3, [%fp+-8]
-	add	%r3, DT_STRLEN_BYTES
 	add	%r3, %r6
 	call	BPF_FUNC_probe_read_str	/*
-					 * rc = probe_read_str(
-					 *	&dst[DT_STRLEN_BYTES],
-					 *	cnt + 1,
-					 *	&src[DT_STRLEN_BYTES + idx]);
+					 * rc = probe_read_str(dst, cnt + 1,
+					 *		       &src[idx]);
 					 */
 
-	/* Store the result string length (rc - 1) at dst. */
-	mov	%r1, %r0
-	sub	%r1, 1
-	mov	%r2, %r9
-	call	dt_strlen_store		/* dt_strlen_store(rc - 1, dst) */
-
 	exit
 
 .Lempty:
 	/* Store the empty string in the destination. */
 	stb	[%r9+0], 0
-	stb	[%r9+1], 0
-	stb	[%r9+2], 0
 	exit
 	.size	dt_substr, .-dt_substr
diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index ccdce2c0..4fa447da 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -231,7 +231,7 @@ dt_bpf_gmap_create(dtrace_hdl_t *dtp)
 	size_t		strsize = dtp->dt_options[DTRACEOPT_STRSIZE];
 	uint8_t		*buf, *end;
 	char		*strtab;
-	size_t		strdatasz = P2ROUNDUP(DT_STRLEN_BYTES + strsize + 1, 8);
+	size_t		strdatasz = P2ROUNDUP(strsize + 1, 8);
 
 	/* If we already created the global maps, return success. */
 	if (dt_gmap_done)
@@ -329,12 +329,12 @@ dt_bpf_gmap_create(dtrace_hdl_t *dtp)
 	buf = (uint8_t *)strtab;
 	end = buf + dtp->dt_strlen;
 	while (buf < end) {
-		uint_t	len = strlen((char *)buf + DT_STRLEN_BYTES);
+		uint_t	len = strlen((char *)buf);
 
 		if (len > strsize)
-			buf[DT_STRLEN_BYTES + strsize] = '\0';
+			buf[strsize] = '\0';
 
-		buf += DT_STRLEN_BYTES + len + 1;
+		buf += len + 1;
 	}
 
 	st_mapfd = create_gmap(dtp, "strtab", BPF_MAP_TYPE_ARRAY,
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 78818c24..adf6cc40 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -779,8 +779,7 @@ dt_cg_tstring_reset(dtrace_hdl_t *dtp)
 {
 	int		i;
 	dt_tstring_t	*ts;
-	uint64_t	size = roundup(DT_STRLEN_BYTES +
-				       dtp->dt_options[DTRACEOPT_STRSIZE] + 1,
+	uint64_t	size = roundup(dtp->dt_options[DTRACEOPT_STRSIZE] + 1,
 				       8);
 
 	if (dtp->dt_tstrings == NULL) {
@@ -952,7 +951,6 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
 		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off));
 		emit(dlp, BPF_MOV_IMM(BPF_REG_2, strsize + 1));
 		emit(dlp, BPF_MOV_REG(BPF_REG_3, dnp->dn_reg));
-		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, DT_STRLEN_BYTES));
 		dt_regset_free(drp, dnp->dn_reg);
 		dt_cg_tstring_free(pcb, dnp);
 		dt_regset_xalloc(drp, BPF_REG_0);
@@ -2364,8 +2362,6 @@ dt_cg_store_var(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp,
 			 * size of the data being copied in.
 			 */
 			srcsz = dt_node_type_size(dnp->dn_right);
-			if (dt_node_is_string(dnp))
-				srcsz += DT_STRLEN_BYTES;
 			size = MIN(srcsz, idp->di_size);
 
 			dt_cg_memcpy(dlp, drp, reg, dnp->dn_reg, size);
@@ -2418,8 +2414,6 @@ dt_cg_store_var(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp,
 		 * size of the data being copied in.
 		 */
 		srcsz = dt_node_type_size(dnp->dn_right);
-		if (dt_node_is_string(dnp))
-			srcsz += DT_STRLEN_BYTES;
 		size = MIN(srcsz, size);
 
 		dt_cg_memcpy(dlp, drp, reg, dnp->dn_reg, size);
@@ -2910,7 +2904,6 @@ dt_cg_ternary_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
 		emit(dlp,  BPF_ALU64_IMM(BPF_ADD, dnp->dn_reg, dnp->dn_tstring->dn_value));
 
 		dt_cg_memcpy(dlp, drp, dnp->dn_reg, BPF_REG_0,
-			     DT_STRLEN_BYTES +
 			     yypcb->pcb_hdl->dt_options[DTRACEOPT_STRSIZE]);
 
 		dt_cg_tstring_free(yypcb, dnp->dn_left);
@@ -3933,7 +3926,6 @@ dt_cg_subr_strtok(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
 		dt_regset_free(drp, str->dn_reg);
 		if (str->dn_tstring)
 			dt_cg_tstring_free(yypcb, str);
-		emit(dlp,  BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, DT_STRLEN_BYTES));
 		dt_regset_xalloc(drp, BPF_REG_0);
 		emit(dlp,  BPF_CALL_HELPER(BPF_FUNC_probe_read_str));
 		dt_regset_free(drp, BPF_REG_0);
diff --git a/libdtrace/dt_dctx.h b/libdtrace/dt_dctx.h
index 945f228e..178f4dd6 100644
--- a/libdtrace/dt_dctx.h
+++ b/libdtrace/dt_dctx.h
@@ -2,7 +2,7 @@
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  *
- * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
  */
 
 #ifndef _DT_DCTX_H
@@ -58,8 +58,10 @@ typedef struct dt_dctx {
 /*
  * Macro to determine the offset from mem to the strtok internal state.
  */
-#define DMEM_STRTOK	MAX(sizeof(uint64_t) * dtp->dt_options[DTRACEOPT_MAXFRAMES], \
-    DT_TSTRING_SLOTS * roundup(DT_STRLEN_BYTES + dtp->dt_options[DTRACEOPT_STRSIZE] + 1, 8))
+#define DMEM_STRTOK	MAX(sizeof(uint64_t) * \
+			    dtp->dt_options[DTRACEOPT_MAXFRAMES], \
+			    DT_TSTRING_SLOTS * \
+			    roundup(dtp->dt_options[DTRACEOPT_STRSIZE] + 1, 8))
 
 /*
  * Macro to determine the (negative) offset from the frame pointer (%fp) for
diff --git a/libdtrace/dt_ident.c b/libdtrace/dt_ident.c
index 96c086b2..78e11cc4 100644
--- a/libdtrace/dt_ident.c
+++ b/libdtrace/dt_ident.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -1012,10 +1012,6 @@ dt_ident_set_storage(dt_ident_t *idp, uint_t alignment, uint_t size)
 	dtrace_hdl_t	*dtp = yypcb->pcb_hdl;
 	dt_idhash_t	*dhp = idp->di_hash;
 
-	if (idp->di_ctfp == DT_STR_CTFP(dtp) &&
-	    idp->di_type == DT_STR_TYPE(dtp))
-		size += DT_STRLEN_BYTES;
-
 	if (!(idp->di_flags & DT_IDFLG_TLS)) {
 		idp->di_offset = (dhp->dh_nextoff + (alignment - 1)) &
 				 ~(alignment - 1);
diff --git a/libdtrace/dt_string.c b/libdtrace/dt_string.c
index e9eccb94..23168483 100644
--- a/libdtrace/dt_string.c
+++ b/libdtrace/dt_string.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -332,15 +332,6 @@ char *strrstr(const char *haystack, const char *needle)
 	return (char *)prev_s;
 }
 
-void
-dt_strlen_store(uint64_t val, char *str)
-{
-	uint8_t	*buf = (uint8_t *)str;
-
-	buf[0] = (uint8_t)(val >> 8);
-	buf[1] = (uint8_t)(val & 0xff);
-}
-
 uint64_t
 dt_strlen(const char *str)
 {
diff --git a/libdtrace/dt_string.h b/libdtrace/dt_string.h
index 83af7551..f905097f 100644
--- a/libdtrace/dt_string.h
+++ b/libdtrace/dt_string.h
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -27,9 +27,6 @@ extern char *strhyphenate(char *);
 extern char *strrstr(const char *, const char *);
 #endif
 
-#define DT_STRLEN_BYTES	2
-
-extern void dt_strlen_store(uint64_t val, char *str);
 extern uint64_t dt_strlen(const char *str);
 
 /*
diff --git a/libdtrace/dt_strtab.c b/libdtrace/dt_strtab.c
index 9362f722..dcf5aa14 100644
--- a/libdtrace/dt_strtab.c
+++ b/libdtrace/dt_strtab.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -71,10 +71,8 @@ dt_strtab_create(size_t bufsz)
 	 * at offset 0.  We use this guarantee in dt_strtab_insert() and
 	 * dt_strtab_index().
 	 */
-	dt_strlen_store(0, sp->str_ptr);
-	sp->str_ptr += DT_STRLEN_BYTES;
 	*sp->str_ptr++ = '\0';
-	sp->str_size = DT_STRLEN_BYTES + 1;
+	sp->str_size = 1;
 	sp->str_nstrs = 1;
 
 	return sp;
@@ -202,15 +200,14 @@ dt_strtab_index(dt_strtab_t *sp, const char *str)
 		return 0;	/* The empty string is always at offset 0. */
 
 	slen = strlen(str);
-	s = malloc(DT_STRLEN_BYTES + slen + 1);
+	s = malloc(slen + 1);
 	if (s == NULL)
 		return -1L;
 
-	dt_strlen_store(slen, s);
-	memcpy(s + DT_STRLEN_BYTES, str, slen + 1);
+	memcpy(s, str, slen + 1);
 
 	h = str2hval(str, slen) % sp->str_hashsz;
-	rc = dt_strtab_xindex(sp, s, DT_STRLEN_BYTES + slen, h);
+	rc = dt_strtab_xindex(sp, s, slen, h);
 	free(s);
 
 	return rc;
@@ -229,15 +226,13 @@ dt_strtab_insert(dt_strtab_t *sp, const char *str)
 		return 0;	/* The empty string is always at offset 0. */
 
 	slen = strlen(str);
-	s = malloc(DT_STRLEN_BYTES + slen + 1);
+	s = malloc(slen + 1);
 	if (s == NULL)
 		return -1L;
 
-	dt_strlen_store(slen, s);
-	memcpy(s + DT_STRLEN_BYTES, str, slen + 1);
+	memcpy(s, str, slen + 1);
 
 	h = str2hval(str, slen) % sp->str_hashsz;
-	slen += DT_STRLEN_BYTES;
 	off = dt_strtab_xindex(sp, s, slen, h);
 	if (off != -1) {
 		free(s);
diff --git a/libdtrace/dt_subr.c b/libdtrace/dt_subr.c
index 5f8ddb8f..8bf30aa7 100644
--- a/libdtrace/dt_subr.c
+++ b/libdtrace/dt_subr.c
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
@@ -743,7 +743,7 @@ dt_difo_getstr(const dtrace_difo_t *dp, ssize_t idx)
 {
 	assert(idx < dp->dtdo_strlen);
 
-	return &dp->dtdo_strtab[idx] + DT_STRLEN_BYTES;
+	return &dp->dtdo_strtab[idx];
 }
 
 /*
diff --git a/test/unittest/variables/gvar/tst.undecl-offset.r b/test/unittest/variables/gvar/tst.undecl-offset.r
index e59e576c..0f321d5a 100644
--- a/test/unittest/variables/gvar/tst.undecl-offset.r
+++ b/test/unittest/variables/gvar/tst.undecl-offset.r
@@ -1,3 +1,3 @@
 NAME             OFFSET KND SCP FLAG TYPE
 a                0      scl glb r/w  string (unknown) by ref (size 256)
-b                258    scl glb w    string (unknown) by ref (size 256)
+b                256    scl glb w    string (unknown) by ref (size 256)
-- 
2.34.1




More information about the DTrace-devel mailing list