Bug#1042065: ltrace: [p]{read,write}[v]() handling, common *64() functions in modern glibc, [fl]seek[o]()/ftell[o](); requisite [u]llong; 20x speed optimisation in default config; format %b+bin() lens
Control: retitle -1 ltrace: [p]{read,write}[v]() handling, common *64() functions in modern glibc, [fl]seek[o]()/ftell[o](); requisite [u]llong; 20x speed optimisation in default config; format %b+bin() lens and %w[f]32x; splice/c_f_r/sendfile[64] formatting; useful __errno_location; %config lines not limited to 1kB; pipe[2]() with fds; sysconf(); %m[un]map[64](); operator new/delete; ; another ~10%; %*locale(); time.h functions; strto*l(); qsort_r() For demo see https://github.com/neomutt/neomutt/pull/3963 From: =?utf-8?b?0L3QsNCx?= Date: Tue, 8 Aug 2023 19:52:01 +0200 Subject: *locale(); time.h functions; strto*l(); qsort_r() --- etc/ltrace.conf | 26 +- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/etc/ltrace.conf b/etc/ltrace.conf index bd9a111..4ffb725 100644 --- a/etc/ltrace.conf +++ b/etc/ltrace.conf @@ -91,6 +91,10 @@ int _IO_putc(char,file); ; locale.h string setlocale(enum(LC_CTYPE=0, LC_NUMERIC=1, LC_TIME=2, LC_COLLATE=3, LC_MONETARY=4, LC_MESSAGES=5, LC_ALL=6, LC_PAPER=7, LC_NAME=8, LC_ADDRESS=9, LC_TELEPHONE=10, LC_MEASUREMENT=11, LC_IDENTIFICATION=12), string); +addr duplocale(addr); +addr uselocale(addr); +addr newlocale(bin(int),string,addr); +void freelocale(addr); ; mcheck.h void mtrace(); @@ -229,7 +233,13 @@ int rename(string,string); ; stdlib.h long __strtol_internal(string,addr,int); +llong __strtoll_internal(string,addr,int); ulong __strtoul_internal(string,addr,int); +ullong __strtoull_internal(string,addr,int); +long strtol(string,+string*,int); +llong strtoll(string,+string*,int); +ulong strtoul(string,+string*,int); +ullong strtoull(string,+string*,int); int atexit(addr); addr bsearch(string, addr, ulong, ulong, addr); addr calloc(ulong, ulong); @@ -241,7 +251,8 @@ int setenv(string,string,int); void unsetenv(string); addr malloc(ulong); void qsort(addr,ulong,ulong,addr); -int random(); +void qsort_r(addr,ulong,ulong,addr,addr); +long random(); addr realloc(addr,ulong); addr reallocarray(addr,ulong,ulong); void srandom(uint); @@ -313,12 +324,17 @@ int tcgetattr(int,addr); int tcsetattr(int,int,addr); ; time.h +typedef tm = struct(int,int,int,int,int,int,int,int,int,long,string); string ctime(addr); int gettimeofday(addr, addr); -addr gmtime(addr); -addr localtime(addr); -ulong strftime(+string2,ulong,string,addr); -long time(addr); +tm* gmtime(llong*); +tm* localtime(llong*); +tm* gmtime_r(llong*,addr); +tm* localtime_r(llong*,addr); +ulong strftime(+string2,ulong,string,tm*); +ulong strftime_l(+string2,ulong,string,tm*,addr); +llong time(addr); +llong mktime(tm*); ; unistd.h void _exit(int); signature.asc Description: PGP signature
Bug#1042065: ltrace: [p]{read,write}[v]() handling, common *64() functions in modern glibc, [fl]seek[o]()/ftell[o](); requisite [u]llong; 20x speed optimisation in default config; format %b+bin() lens
Control: retitle -1 ltrace: [p]{read,write}[v]() handling, common *64() functions in modern glibc, [fl]seek[o]()/ftell[o](); requisite [u]llong; 20x speed optimisation in default config; format %b+bin() lens and %w[f]32x; splice/c_f_r/sendfile[64] formatting; useful __errno_location; %config lines not limited to 1kB; pipe[2]() with fds; sysconf(); %m[un]map[64](); operator new/delete; ; another ~10% I'm attaching everything, since I fixed some documentation fucky-wuckies from the earlier ones. 0018-0021 are new, and turn $ grep pipe ll pipe2(0x7ffcd6d7baf0, 0x8, 0x7ffcd6d7bb70, 0x7ffcd6d7bb70) = 0 $ grep -e mmap -e sysconf ll sysconf(30, 0, 1, 0x393c) = 4096 mmap64(0, 0x3d3c, 1, 2) = 0x7fe67b29c000 into $ grep pipe ll pipe2([3, 4], 0x8) = 0 $ grep -e mmap -e sysconf ll sysconf(_SC_PAGE_SIZE) = 4096 mmap64(0, 15676, 0b1, 0x2, 0, 4096) = 0x7fa1b27ff000 regex.h suite looks like: regcomp(0x7fff5ee83120, ";", 0b100) = REG_OK regexec(0x7fff5ee83040, "\nint SYS_access(string,octal);"..., 1, [{0, 31}], 0b111) = REG_NOMATCH regexec(0x7fff5ee83040, ";\nint SYS_access(string,octal)"..., 1, [{0, 32}], 0b111) = REG_OK regcomp(0x7ffece59ee70, "\\(", 0b100) = REG_EPAREN regerror(REG_EPAREN, 0x7ffece59ee70, nil, 0) = 18 malloc(18) = 0x5604c35c2140 regerror(REG_EPAREN, 0x7ffece59ee70, "Unmatched ( or \\(", 18) = 18 And function lookups are sped up approximately ten-fold (3μs -> 300ns on a hit (depending on the access pattern, of course) and 12μs -> 600ns on a miss) which translates to an approximately 10% (roughly, maybe, it's difficult to measure) speed-up depending on the program: $ hyperfine '/bin/ltrace -o/dev/null -F /etc/ltrace.conf ls' \ './ltrace -o/dev/null -F /etc/ltrace.conf ls' Benchmark 1: /bin/ltrace -o/dev/null -F /etc/ltrace.conf ls Time (mean ± σ): 545.6 ms ± 75.8 ms[User: 153.6 ms, System: 350.1 ms] Range (min … max): 473.1 ms … 722.5 ms10 runs Benchmark 2: ./ltrace -o/dev/null -F /etc/ltrace.conf ls Time (mean ± σ): 447.1 ms ± 36.7 ms[User: 94.6 ms, System: 329.8 ms] Range (min … max): 412.8 ms … 516.4 ms10 runs Summary './ltrace -o/dev/null -F /etc/ltrace.conf ls' ran 1.22 ± 0.20 times faster than '/bin/ltrace -o/dev/null -F /etc/ltrace.conf ls' vs $ hyperfine '/bin/ltrace -F /etc/ltrace.conf -o/dev/null ~/code/voreutils/out/cmd/tac -rs \; < etc/ltrace.conf' \ './ltrace -F /etc/ltrace.conf -o/dev/null ~/code/voreutils/out/cmd/tac -rs \; < etc/ltrace.conf' Benchmark 1: /bin/ltrace -F /etc/ltrace.conf -o/dev/null ~/code/voreutils/out/cmd/tac -rs \; < etc/ltrace.conf Time (mean ± σ): 3.631 s ± 0.117 s[User: 1.087 s, System: 2.334 s] Range (min … max):3.516 s … 3.886 s10 runs Benchmark 2: ./ltrace -F /etc/ltrace.conf -o/dev/null ~/code/voreutils/out/cmd/tac -rs \; < etc/ltrace.conf Time (mean ± σ): 3.113 s ± 0.169 s[User: 0.659 s, System: 2.274 s] Range (min … max):2.934 s … 3.496 s10 runs Summary './ltrace -F /etc/ltrace.conf -o/dev/null ~/code/voreutils/out/cmd/tac -rs \; < etc/ltrace.conf' ran 1.17 ± 0.07 times faster than '/bin/ltrace -F /etc/ltrace.conf -o/dev/null ~/code/voreutils/out/cmd/tac -rs \; < etc/ltrace.conf' From: =?utf-8?b?0L3QsNCx?= Date: Tue, 25 Jul 2023 21:20:32 +0200 Subject: Add llong/ullong. Tested on i686/amd64 --- expr.c | 6 +++--- expr.h | 4 ++-- lens_default.c | 14 ++ printf.c | 10 +- read_config_file.c | 4 sysdeps/linux-gnu/ia64/fetch.c | 4 sysdeps/linux-gnu/m68k/fetch.c | 2 ++ sysdeps/linux-gnu/ppc/fetch.c | 2 ++ sysdeps/linux-gnu/ppc/trace.c | 6 ++ sysdeps/linux-gnu/s390/fetch.c | 2 ++ sysdeps/linux-gnu/s390/trace.c | 6 ++ sysdeps/linux-gnu/x86/fetch.c | 15 --- sysdeps/linux-gnu/x86/trace.c | 6 ++ type.c | 25 ++--- type.h | 2 ++ value.c| 16 value.h| 4 ++-- zero.c | 2 +- 18 files changed, 99 insertions(+), 31 deletions(-) diff --git a/expr.c b/expr.c index 32860fd..01ce4c6 100644 --- a/expr.c +++ b/expr.c @@ -246,7 +246,7 @@
Bug#1042065: ltrace: [p]{read,write}[v]() handling, common *64() functions in modern glibc, [fl]seek[o]()/ftell[o](); requisite [u]llong; 20x speed optimisation in default config; format %b+bin() lens
Control: retitle -1 ltrace: [p]{read,write}[v]() handling, common *64() functions in modern glibc, [fl]seek[o]()/ftell[o](); requisite [u]llong; 20x speed optimisation in default config; format %b+bin() lens and %w[f]32x; splice/c_f_r/sendfile[64] formatting; useful __errno_location Attaching two patches that turn splice(3, 0x7ffca660acd8, 1, 0) = -1 copy_file_range(3, 0x7ffca660acd8, 1, 0) = -1 sendfile64(1, 3, 0x7ffca660acd8, 0x40) = -1 pread64(3 error: maximum array length seems negative , "", 65536, -65536) = -1 __errno_location() = 0x7f5347bb86c0 __errno_location() = 0x7f5347bb86c0 strerror(22) = "Invalid argument" fprintf(0x7f5347d8e680, "%s: %s: %s\n", "out/cmd/tail", "5M", "Invalid argument") = 35 close(3) = 0 __cxa_finalize(0x561787e1efd8) = +++ exited (status 1) +++ into splice(3, -65536, 1, nil, 4194304, 0b101) = -1 copy_file_range(3, -65536, 1, nil, 4194304, 0) = -1 sendfile64(1, 3, -65536, 4194304) = -1 pread64(3 error: maximum array length seems negative , "", 65536, -65536) = -1 __errno_location() = 22 __errno_location() = 22 strerror(22) = "Invalid argument" fprintf(0x7f2b0401c680, "%s: %s: %s\n", "out/cmd/tail", "5M", "Invalid argument") = 35 close(3) = 0 __cxa_finalize(0x55ba48e1cfd8) = +++ exited (status 1) +++ From: =?utf-8?b?0L3QsNCx?= Date: Tue, 1 Aug 2023 17:09:11 +0200 Subject: Add splice()/copy_file_range()/sendfile[64]() Before: splice(3, 0x7ffd4b66f348, 1, 0)= -1 copy_file_range(3, 0x7ffd772bbf28, 1, 0) = -1 sendfile64(1, 3, 0x7ffd772bbf28, 0x40) = -1 pread64(3 error: maximum array length seems negative , "", 65536, -65536) = -1 After: splice(3, -65536, 1, nil, 4194304, 0b101) = -1 copy_file_range(3, -65536, 1, nil, 4194304, 0) = -1 sendfile64(1, 3, -65536, 4194304) = -1 pread64(3 error: maximum array length seems negative , "", 65536, -65536) = -1 --- etc/ltrace.conf | 6 ++ 1 file changed, 6 insertions(+) diff --git a/etc/ltrace.conf b/etc/ltrace.conf index 855d373..db914cb 100644 --- a/etc/ltrace.conf +++ b/etc/ltrace.conf @@ -60,6 +60,12 @@ int open(string,hex(int),octal); ; WARNING: 3rd argument may not be there int open64(string,hex(int),octal); ; WARNING: 3rd argument may not be there int openat(openat_fd,string,hex(int),octal); ; WARNING: 4th argument may not be there int openat64(openat_fd,string,hex(int),octal); ; WARNING: 4th argument may not be there +long splice(int,llong*,int,llong*,ulong,bin(uint)) +; unistd.h +long copy_file_range(int,llong*,int,llong*,ulong,bin(uint)) +; sys/sendfile.h +long sendfile(int,int,long*,ulong) +long sendfile64(int,int,llong*,ulong) ; fnmatch.h int fnmatch(string, string, int); From: =?utf-8?b?0L3QsNCx?= Date: Tue, 1 Aug 2023 17:30:15 +0200 Subject: __errno_location() returns an int*, not addr This means that before: __errno_location() = 0x7f2707f256c0 __errno_location() = 0x7f2707f256c0 __errno_location() = 0x7f2707f256c0 After: __errno_location() = 0 __errno_location() = 22 __errno_location() = 22 And this __errno_location() is made useful --- etc/ltrace.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/ltrace.conf b/etc/ltrace.conf index db914cb..3d4f5cd 100644 --- a/etc/ltrace.conf +++ b/etc/ltrace.conf @@ -52,7 +52,7 @@ addr dlsym(addr, string); int dlclose(addr); ; errno.h -addr __errno_location(); +int* __errno_location(); ;
Bug#1042065: ltrace: [p]{read,write}[v]() handling, common *64() functions in modern glibc, [fl]seek[o]()/ftell[o](); requisite [u]llong; 20x speed optimisation in default config; format %b+bin() lens
Control: retitle -1 ltrace: [p]{read,write}[v]() handling, common *64() functions in modern glibc, [fl]seek[o]()/ftell[o](); requisite [u]llong; 20x speed optimisation in default config; format %b+bin() lens and %w[f]32x Attaching (a) a fix for the pre-mapping patch that broke misaligned accesses instead of unbreaking them (sorry), and (b) format %b (already in bookworm glibc but now standard in C2x) + a free bin() lens, and (c) format %w[f]{digits}[formatspec] (new in C2x, glibc 2.38). Thus (with a ltrace.conf that has "long write(int, string3, bin(ulong))": $ cat qwe.c int main() { printf("%#b\n", 69); printf("%w64x %s\n", "gameing", (char *)0); write(1, "zupa\n", 5); } $ ./ltrace -F ./ltrace.conf ./qwe | tail printf("%#b\n", 0b1000101)= 10 printf("%w64x %s\n", 0x563ab86eb013, nil) = 14 write(1, "zupa\n", 0b101) = 5 +++ exited (status 0) +++ zupa 0b1000101 %w64x gameing Best, наб signature.asc Description: PGP signature