Skip to content

Commit

Permalink
Remove the string length prefix
Browse files Browse the repository at this point in the history
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@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Feb 8, 2022
1 parent ddf1f49 commit 29e3f42
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 263 deletions.
28 changes: 8 additions & 20 deletions bpf/basename.S
Original file line number Diff line number Diff line change
@@ -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

/*
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
28 changes: 8 additions & 20 deletions bpf/dirname.S
Original file line number Diff line number Diff line change
@@ -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

/*
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
11 changes: 1 addition & 10 deletions bpf/index.S
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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;
*
Expand Down Expand Up @@ -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 */

Expand Down
12 changes: 1 addition & 11 deletions bpf/lltostr.S
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
*
Expand Down Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions bpf/rindex.S
Original file line number Diff line number Diff line change
@@ -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.
*/

/*
Expand All @@ -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

Expand All @@ -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;
*
Expand Down Expand Up @@ -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
Expand Down
25 changes: 5 additions & 20 deletions bpf/strchr.S
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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' */
Expand Down
18 changes: 5 additions & 13 deletions bpf/strcmp.S
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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';
*
Expand All @@ -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;
*
Expand All @@ -114,17 +111,15 @@ 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

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
Expand Down Expand Up @@ -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

Expand All @@ -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] */
Expand Down

0 comments on commit 29e3f42

Please sign in to comment.