Optimize code if we have only one personality

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>
This commit is contained in:
Denys Vlasenko 2012-03-19 09:36:42 +01:00
parent 1be02798f5
commit 9fd4f96d2a
11 changed files with 53 additions and 57 deletions

View File

@ -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);
}

13
defs.h
View File

@ -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;

6
desc.c
View File

@ -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

2
file.c
View File

@ -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]);

9
io.c
View File

@ -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)

View File

@ -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) {

View 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);

View File

@ -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) {

View File

@ -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;
}

10
time.c
View File

@ -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;
}

17
util.c
View File

@ -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) {