]> granicus.if.org Git - strace/commitdiff
Optimize code if we have only one personality
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 19 Mar 2012 08:36:42 +0000 (09:36 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 19 Mar 2012 08:36:42 +0000 (09:36 +0100)
On i386:
   text    data     bss     dec     hex filename
 238025     672   18980  257677   3ee8d strace.before
 237389     704   18944  257037   3ec0d strace

* defs.h: Define PERSONALITY0_WORDSIZE as sizeof(long) if not defined.
Introduce new define, current_wordsize as
(personality_wordsize[current_personality]).
Make set_personality() no-op, current_personality constant zero,
current_wordsize as PERSONALITY0_WORDSIZE if we have only one personality.
* count.c (call_summary): Use current_wordsize instead of
personality_wordsize[current_personality].
* desc.c (printflock): Likewise.
* file.c (sys_utime): Likewise.
* io.c (tprint_iov): Likewise.
* process.c (printargv): Likewise.
* resource.c (decode_rlimit): Likewise.
* signal.c (sys_kill): Likewise.
(sys_rt_sigaction): Likewise.
* time.c (sprinttv): Likewise.
(sprint_timespec): Likewise.
(printitv_bitness): Likewise.
(tprint_timex): Likewise.
(printsigevent): Likewise.
* util.c (dumpiov): Likewise.
(umoven): Likewise.
(umovestr): Likewise.
* syscall.c: Initialize sysent to sysent0 etc.
Make current_personality, personality_wordsize[], set_personality()
conditional on SUPPORTED_PERSONALITIES > 1.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
count.c
defs.h
desc.c
file.c
io.c
process.c
resource.c
signal.c
syscall.c
time.c
util.c

diff --git a/count.c b/count.c
index 29773537b99735683a2dec95b38d5a794c5c0e0e..d05ec60fc3875c59b5413531963f7faa463a7c21 100644 (file)
--- a/count.c
+++ b/count.c
@@ -220,7 +220,7 @@ call_summary(FILE *outf)
                if (i)
                        fprintf(outf,
                                "System call usage summary for %u bit mode:\n",
-                               personality_wordsize[current_personality] * 8);
+                               current_wordsize * 8);
                call_summary_pers(outf);
        }
 
diff --git a/defs.h b/defs.h
index 87503223d25ad5fbe27835952f97a0a71bea9d0d..d327128a4b60f2a34418d28bddb9472a7349b3b0 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -228,6 +228,10 @@ extern long ptrace(int, int, char *, long);
 # define PERSONALITY1_WORDSIZE 4
 #endif
 
+#ifndef PERSONALITY0_WORDSIZE
+# define PERSONALITY0_WORDSIZE sizeof(long)
+#endif
+
 #if !HAVE_DECL_PTRACE_SETOPTIONS
 # define PTRACE_SETOPTIONS     0x4200
 #endif
@@ -450,7 +454,6 @@ void error_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(pr
 void perror_msg_and_die(const char *fmt, ...) __attribute__ ((noreturn, format(printf, 1, 2)));
 void die_out_of_memory(void) __attribute__ ((noreturn));
 
-extern void set_personality(int personality);
 extern const char *xlookup(const struct xlat *, int);
 
 extern void set_sortby(const char *);
@@ -570,8 +573,16 @@ extern void tprints(const char *str);
 #define printtv_special(tcp, addr)     \
        printtv_bitness((tcp), (addr), BITNESS_CURRENT, 1)
 
+#if SUPPORTED_PERSONALITIES > 1
+extern void set_personality(int personality);
 extern int current_personality;
 extern const int personality_wordsize[];
+# define current_wordsize (personality_wordsize[current_personality])
+#else
+# define set_personality(personality) ((void)0)
+# define current_personality 0
+# define current_wordsize    PERSONALITY0_WORDSIZE
+#endif
 
 struct sysent {
        unsigned nargs;
diff --git a/desc.c b/desc.c
index be4d2a91918487b55e60954a2aaaddec1bfe16ac..884f143ce04e45298f1d246327af4506a0ff8376 100644 (file)
--- a/desc.c
+++ b/desc.c
@@ -230,8 +230,8 @@ printflock(struct tcb *tcp, long addr, int getlk)
        struct flock fl;
 
 #if SUPPORTED_PERSONALITIES > 1
-       if (personality_wordsize[current_personality] != sizeof(fl.l_start)) {
-               if (personality_wordsize[current_personality] == 4) {
+       if (current_wordsize != sizeof(fl.l_start)) {
+               if (current_wordsize == 4) {
                        /* 32-bit x86 app on x86_64 and similar cases */
                        struct {
                                short int l_type;
@@ -252,7 +252,7 @@ printflock(struct tcb *tcp, long addr, int getlk)
                } else {
                        /* let people know we have a problem here */
                        tprintf("{ <decode error: unsupported wordsize %d> }",
-                               personality_wordsize[current_personality]);
+                               current_wordsize);
                        return;
                }
        } else
diff --git a/file.c b/file.c
index 32d21229216cacfce3dc42b7261295df08c4a93f..1a448cde5dbcf63502c56c939ed19f9a4d6d8eab 100644 (file)
--- a/file.c
+++ b/file.c
@@ -2059,7 +2059,7 @@ sys_utime(struct tcb *tcp)
                long utl[2];
                int uti[2];
        } u;
-       unsigned wordsize = personality_wordsize[current_personality];
+       unsigned wordsize = current_wordsize;
 
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
diff --git a/io.c b/io.c
index b483c493864bdfd39384d5a47f30a03534a55416..a7f6c29e80be8fe422914915e60cc2128a9ae0cc 100644 (file)
--- a/io.c
+++ b/io.c
@@ -72,14 +72,11 @@ tprint_iov(struct tcb *tcp, unsigned long len, unsigned long addr, int decode_io
                struct { u_int64_t base; u_int64_t len; } iov64;
        } iov;
 #define sizeof_iov \
-  (personality_wordsize[current_personality] == 4 \
-   ? sizeof(iov.iov32) : sizeof(iov.iov64))
+       (current_wordsize == 4 ? sizeof(iov.iov32) : sizeof(iov.iov64))
 #define iov_iov_base \
-  (personality_wordsize[current_personality] == 4 \
-   ? (u_int64_t) iov.iov32.base : iov.iov64.base)
+       (current_wordsize == 4 ? (uint64_t) iov.iov32.base : iov.iov64.base)
 #define iov_iov_len \
-  (personality_wordsize[current_personality] == 4 \
-   ? (u_int64_t) iov.iov32.len : iov.iov64.len)
+       (current_wordsize == 4 ? (uint64_t) iov.iov32.len : iov.iov64.len)
 #else
        struct iovec iov;
 #define sizeof_iov sizeof(iov)
index 2239d4a1da261609eb1ce99795cb5ede14886e16..7035c2eec199508bd68c99a29be652bf36d86f6d 100644 (file)
--- a/process.c
+++ b/process.c
@@ -858,7 +858,7 @@ printargv(struct tcb *tcp, long addr)
        } cp;
        const char *sep;
        int n = 0;
-       unsigned wordsize = personality_wordsize[current_personality];
+       unsigned wordsize = current_wordsize;
 
        cp.p64 = 1;
        for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
index 77a94a29625c43e47d6748f6e7c85a7da1908ee9..d7a34ef3a368b2b1c57847315c719195a147bb52 100644 (file)
@@ -180,7 +180,7 @@ decode_rlimit(struct tcb *tcp, unsigned long addr)
 # if SIZEOF_RLIM_T == 4
                print_rlimit32(tcp, addr);
 # else
-               if (personality_wordsize[current_personality] == 4)
+               if (current_wordsize == 4)
                        print_rlimit32(tcp, addr);
                else
                        print_rlimit64(tcp, addr);
index 11b133debd105ab35efff425f8634ea582ee097d..ab7ae564065820f2e0f76f9465d2bad654709f0c 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -1226,7 +1226,7 @@ sys_kill(struct tcb *tcp)
                long pid = tcp->u_arg[0];
 #if SUPPORTED_PERSONALITIES > 1
                /* Sign-extend a 32-bit value when that's what it is. */
-               if (personality_wordsize[current_personality] < sizeof pid)
+               if (current_wordsize < sizeof pid)
                        pid = (long) (int) pid;
 #endif
                tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
@@ -1335,8 +1335,7 @@ sys_rt_sigaction(struct tcb *tcp)
        }
 #if SUPPORTED_PERSONALITIES > 1
 #if SIZEOF_LONG > 4
-       if (personality_wordsize[current_personality] != sizeof(sa.sa_flags)
-           && personality_wordsize[current_personality] == 4) {
+       if (current_wordsize != sizeof(sa.sa_flags) && current_wordsize == 4) {
                struct new_sigaction32 sa32;
                r = umove(tcp, addr, &sa32);
                if (r >= 0) {
index 3f157b2a957bf352385227e852d98dba941f4450..3ee44175d00805d3529a978816b3b31ca792c829 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -183,29 +183,25 @@ enum { nioctlents2 = ARRAY_SIZE(ioctlent2) };
 int qual_flags2[MAX_QUALS];
 #endif
 
-const struct sysent *sysent;
-const char *const *errnoent;
-const char *const *signalent;
-const struct ioctlent *ioctlent;
-unsigned nsyscalls;
-unsigned nerrnos;
-unsigned nsignals;
-unsigned nioctlents;
-int *qual_flags;
+const struct sysent *sysent = sysent0;
+const char *const *errnoent = errnoent0;
+const char *const *signalent = signalent0;
+const struct ioctlent *ioctlent = ioctlent0;
+unsigned nsyscalls = nsyscalls0;
+unsigned nerrnos = nerrnos0;
+unsigned nsignals = nsignals0;
+unsigned nioctlents = nioctlents0;
+int *qual_flags = qual_flags0;
 
+#if SUPPORTED_PERSONALITIES > 1
 int current_personality;
 
-#ifndef PERSONALITY0_WORDSIZE
-# define PERSONALITY0_WORDSIZE sizeof(long)
-#endif
 const int personality_wordsize[SUPPORTED_PERSONALITIES] = {
        PERSONALITY0_WORDSIZE,
-#if SUPPORTED_PERSONALITIES > 1
        PERSONALITY1_WORDSIZE,
-#endif
-#if SUPPORTED_PERSONALITIES > 2
+# if SUPPORTED_PERSONALITIES > 2
        PERSONALITY2_WORDSIZE,
-#endif
+# endif
 };
 
 void
@@ -224,7 +220,6 @@ set_personality(int personality)
                qual_flags = qual_flags0;
                break;
 
-#if SUPPORTED_PERSONALITIES >= 2
        case 1:
                errnoent = errnoent1;
                nerrnos = nerrnos1;
@@ -236,9 +231,8 @@ set_personality(int personality)
                nsignals = nsignals1;
                qual_flags = qual_flags1;
                break;
-#endif
 
-#if SUPPORTED_PERSONALITIES >= 3
+# if SUPPORTED_PERSONALITIES >= 3
        case 2:
                errnoent = errnoent2;
                nerrnos = nerrnos2;
@@ -250,13 +244,12 @@ set_personality(int personality)
                nsignals = nsignals2;
                qual_flags = qual_flags2;
                break;
-#endif
+# endif
        }
 
        current_personality = personality;
 }
 
-#if SUPPORTED_PERSONALITIES > 1
 static void
 update_personality(struct tcb *tcp, int personality)
 {
@@ -521,7 +514,7 @@ decode_socket_subcall(struct tcb *tcp)
        tcp->scno = SYS_socket_subcall + tcp->u_arg[0];
        addr = tcp->u_arg[1];
        tcp->u_nargs = sysent[tcp->scno].nargs;
-       size = personality_wordsize[current_personality];
+       size = current_wordsize;
        for (i = 0; i < tcp->u_nargs; ++i) {
                if (size == sizeof(int)) {
                        unsigned int arg;
@@ -685,8 +678,7 @@ static long r3;
  * other: error, trace_syscall() should print error indicator
  *    ("????" etc) and bail out.
  */
-static
-int
+static int
 get_scno(struct tcb *tcp)
 {
        long scno = 0;
@@ -1682,7 +1674,7 @@ is_negated_errno(unsigned long int val)
 {
        unsigned long int max = -(long int) nerrnos;
 #if SUPPORTED_PERSONALITIES > 1
-       if (personality_wordsize[current_personality] < sizeof(val)) {
+       if (current_wordsize < sizeof(val)) {
                val = (unsigned int) val;
                max = (unsigned int) max;
        }
diff --git a/time.c b/time.c
index 09d0f070fc788a72e7ad4b85f9b3bec544f94e7e..537265e048765eab66fbde58119c10096e2ab8ae 100644 (file)
--- a/time.c
+++ b/time.c
@@ -79,7 +79,7 @@ sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int spec
 
        if (bitness == BITNESS_32
 #if SUPPORTED_PERSONALITIES > 1
-           || personality_wordsize[current_personality] == 4
+           || current_wordsize == 4
 #endif
                )
        {
@@ -135,7 +135,7 @@ sprint_timespec(char *buf, struct tcb *tcp, long addr)
                int rc;
 
 #if SUPPORTED_PERSONALITIES > 1
-               if (personality_wordsize[current_personality] == 4) {
+               if (current_wordsize == 4) {
                        struct timeval32 tv;
 
                        rc = umove(tcp, addr, &tv);
@@ -288,7 +288,7 @@ printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
 
                if (bitness == BITNESS_32
 #if SUPPORTED_PERSONALITIES > 1
-                   || personality_wordsize[current_personality] == 4
+                   || current_wordsize == 4
 #endif
                        )
                {
@@ -542,7 +542,7 @@ tprint_timex(struct tcb *tcp, long addr)
        struct timex tx;
 
 #if SUPPORTED_PERSONALITIES > 1
-       if (personality_wordsize[current_personality] == 4)
+       if (current_wordsize == 4)
                return tprint_timex32(tcp, addr);
 #endif
        if (umove(tcp, addr, &tx) < 0)
@@ -746,7 +746,7 @@ printsigevent(struct tcb *tcp, long arg)
        struct sigevent sev;
 
 #if SUPPORTED_PERSONALITIES > 1
-       if (personality_wordsize[current_personality] == 4) {
+       if (current_wordsize == 4) {
                printsigevent32(tcp, arg);
                return;
        }
diff --git a/util.c b/util.c
index 4066bcb599a5ab2a1ea773587cd8239b336812ea..9a7770517b650f048a1d60931651530a99f2e1e4 100644 (file)
--- a/util.c
+++ b/util.c
@@ -631,14 +631,11 @@ dumpiov(struct tcb *tcp, int len, long addr)
        } iovu;
 #define iov iovu.iov64
 #define sizeof_iov \
-  (personality_wordsize[current_personality] == 4 \
-   ? sizeof(*iovu.iov32) : sizeof(*iovu.iov64))
+       (current_wordsize == 4 ? sizeof(*iovu.iov32) : sizeof(*iovu.iov64))
 #define iov_iov_base(i) \
-  (personality_wordsize[current_personality] == 4 \
-   ? (u_int64_t) iovu.iov32[i].base : iovu.iov64[i].base)
+       (current_wordsize == 4 ? (uint64_t) iovu.iov32[i].base : iovu.iov64[i].base)
 #define iov_iov_len(i) \
-  (personality_wordsize[current_personality] == 4 \
-   ? (u_int64_t) iovu.iov32[i].len : iovu.iov64[i].len)
+       (current_wordsize == 4 ? (uint64_t) iovu.iov32[i].len : iovu.iov64[i].len)
 #else
        struct iovec *iov;
 #define sizeof_iov sizeof(*iov)
@@ -783,8 +780,8 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
        } u;
 
 #if SUPPORTED_PERSONALITIES > 1
-       if (personality_wordsize[current_personality] < sizeof(addr))
-               addr &= (1ul << 8 * personality_wordsize[current_personality]) - 1;
+       if (current_wordsize < sizeof(addr))
+               addr &= (1ul << 8 * current_wordsize) - 1;
 #endif
 
        if (!process_vm_readv_not_supported) {
@@ -874,8 +871,8 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
        } u;
 
 #if SUPPORTED_PERSONALITIES > 1
-       if (personality_wordsize[current_personality] < sizeof(addr))
-               addr &= (1ul << 8 * personality_wordsize[current_personality]) - 1;
+       if (current_wordsize < sizeof(addr))
+               addr &= (1ul << 8 * current_wordsize) - 1;
 #endif
 
        if (!process_vm_readv_not_supported) {