1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-14 04:18:11 +01:00

Change dwarf_reg_state from an array of pairs of differently-sized objects

to a pair of arrays, to reduce internal fragmentation.  Reduces storage
use by 37.5% on x86_64.
This commit is contained in:
Doug Moore 2017-05-16 17:40:58 -05:00
parent 2b692db23f
commit 028a60f064
5 changed files with 118 additions and 124 deletions

View file

@ -236,13 +236,6 @@ typedef enum
}
dwarf_where_t;
typedef struct
{
dwarf_where_t where; /* how is the register saved? */
unw_word_t val; /* where it's saved */
}
dwarf_save_loc_t;
/* For uniformity, we'd like to treat the CFA save-location like any
other register save-location, but this doesn't quite work, because
the CFA can be expressed as a (REGISTER,OFFSET) pair. To handle
@ -258,7 +251,8 @@ dwarf_save_loc_t;
typedef struct dwarf_reg_state
{
dwarf_save_loc_t reg[DWARF_NUM_PRESERVED_REGS + 2];
char where[DWARF_NUM_PRESERVED_REGS + 2]; /* how is the register saved? */
unw_word_t val[DWARF_NUM_PRESERVED_REGS + 2]; /* where it's saved */
}
dwarf_reg_state_t;

View file

@ -36,13 +36,13 @@ tdep_stash_frame (struct dwarf_cursor *d, struct dwarf_reg_state *rs)
" ra=0x%lx fp [where=%d val=%ld @0x%lx] lr [where=%d val=%ld @0x%lx] "
"sp [where=%d val=%ld @0x%lx]\n",
d->ip, d->cfa, f->frame_type,
rs->reg[DWARF_CFA_REG_COLUMN].where,
rs->reg[DWARF_CFA_REG_COLUMN].val,
rs->reg[DWARF_CFA_OFF_COLUMN].val,
rs->where[DWARF_CFA_REG_COLUMN],
rs->val[DWARF_CFA_REG_COLUMN],
rs->val[DWARF_CFA_OFF_COLUMN],
DWARF_GET_LOC(d->loc[d->ret_addr_column]),
rs->reg[FP].where, rs->reg[FP].val, DWARF_GET_LOC(d->loc[FP]),
rs->reg[LR].where, rs->reg[LR].val, DWARF_GET_LOC(d->loc[LR]),
rs->reg[SP].where, rs->reg[SP].val, DWARF_GET_LOC(d->loc[SP]));
rs->where[FP], rs->val[FP], DWARF_GET_LOC(d->loc[FP]),
rs->where[LR], rs->val[LR], DWARF_GET_LOC(d->loc[LR]),
rs->where[SP], rs->val[SP], DWARF_GET_LOC(d->loc[SP]));
/* A standard frame is defined as:
- CFA is register-relative offset off FP or SP;
@ -51,37 +51,37 @@ tdep_stash_frame (struct dwarf_cursor *d, struct dwarf_reg_state *rs)
- LR is unsaved or saved at CFA+offset, offset != -1;
- SP is unsaved or saved at CFA+offset, offset != -1. */
if (f->frame_type == UNW_AARCH64_FRAME_OTHER
&& (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_REG)
&& (rs->reg[DWARF_CFA_REG_COLUMN].val == FP
|| rs->reg[DWARF_CFA_REG_COLUMN].val == SP)
&& labs(rs->reg[DWARF_CFA_OFF_COLUMN].val) < (1 << 29)
&& (rs->where[DWARF_CFA_REG_COLUMN] == DWARF_WHERE_REG)
&& (rs->val[DWARF_CFA_REG_COLUMN] == FP
|| rs->val[DWARF_CFA_REG_COLUMN] == SP)
&& labs(rs->val[DWARF_CFA_OFF_COLUMN]) < (1 << 29)
&& d->ret_addr_column == LR
&& (rs->reg[FP].where == DWARF_WHERE_UNDEF
|| rs->reg[FP].where == DWARF_WHERE_SAME
|| (rs->reg[FP].where == DWARF_WHERE_CFAREL
&& labs(rs->reg[FP].val) < (1 << 29)
&& rs->reg[FP].val+1 != 0))
&& (rs->reg[LR].where == DWARF_WHERE_UNDEF
|| rs->reg[LR].where == DWARF_WHERE_SAME
|| (rs->reg[LR].where == DWARF_WHERE_CFAREL
&& labs(rs->reg[LR].val) < (1 << 29)
&& rs->reg[LR].val+1 != 0))
&& (rs->reg[SP].where == DWARF_WHERE_UNDEF
|| rs->reg[SP].where == DWARF_WHERE_SAME
|| (rs->reg[SP].where == DWARF_WHERE_CFAREL
&& labs(rs->reg[SP].val) < (1 << 29)
&& rs->reg[SP].val+1 != 0)))
&& (rs->where[FP] == DWARF_WHERE_UNDEF
|| rs->where[FP] == DWARF_WHERE_SAME
|| (rs->where[FP] == DWARF_WHERE_CFAREL
&& labs(rs->val[FP]) < (1 << 29)
&& rs->val[FP]+1 != 0))
&& (rs->where[LR] == DWARF_WHERE_UNDEF
|| rs->where[LR] == DWARF_WHERE_SAME
|| (rs->where[LR] == DWARF_WHERE_CFAREL
&& labs(rs->val[LR]) < (1 << 29)
&& rs->val[LR]+1 != 0))
&& (rs->where[SP] == DWARF_WHERE_UNDEF
|| rs->where[SP] == DWARF_WHERE_SAME
|| (rs->where[SP] == DWARF_WHERE_CFAREL
&& labs(rs->val[SP]) < (1 << 29)
&& rs->val[SP]+1 != 0)))
{
/* Save information for a standard frame. */
f->frame_type = UNW_AARCH64_FRAME_STANDARD;
f->cfa_reg_sp = (rs->reg[DWARF_CFA_REG_COLUMN].val == SP);
f->cfa_reg_offset = rs->reg[DWARF_CFA_OFF_COLUMN].val;
if (rs->reg[FP].where == DWARF_WHERE_CFAREL)
f->fp_cfa_offset = rs->reg[FP].val;
if (rs->reg[LR].where == DWARF_WHERE_CFAREL)
f->lr_cfa_offset = rs->reg[LR].val;
if (rs->reg[SP].where == DWARF_WHERE_CFAREL)
f->sp_cfa_offset = rs->reg[SP].val;
f->cfa_reg_sp = (rs->val[DWARF_CFA_REG_COLUMN] == SP);
f->cfa_reg_offset = rs->val[DWARF_CFA_OFF_COLUMN];
if (rs->where[FP] == DWARF_WHERE_CFAREL)
f->fp_cfa_offset = rs->val[FP];
if (rs->where[LR] == DWARF_WHERE_CFAREL)
f->lr_cfa_offset = rs->val[LR];
if (rs->where[SP] == DWARF_WHERE_CFAREL)
f->sp_cfa_offset = rs->val[SP];
Debug (4, " standard frame\n");
}
else

View file

@ -36,13 +36,13 @@ tdep_stash_frame (struct dwarf_cursor *d, struct dwarf_reg_state *rs)
" ra=0x%x r7 [where=%d val=%d @0x%x] lr [where=%d val=%d @0x%x] "
"sp [where=%d val=%d @0x%x]\n",
d->ip, d->cfa, f->frame_type,
rs->reg[DWARF_CFA_REG_COLUMN].where,
rs->reg[DWARF_CFA_REG_COLUMN].val,
rs->reg[DWARF_CFA_OFF_COLUMN].val,
rs->where[DWARF_CFA_REG_COLUMN],
rs->val[DWARF_CFA_REG_COLUMN],
rs->val[DWARF_CFA_OFF_COLUMN],
DWARF_GET_LOC(d->loc[d->ret_addr_column]),
rs->reg[R7].where, rs->reg[R7].val, DWARF_GET_LOC(d->loc[R7]),
rs->reg[LR].where, rs->reg[LR].val, DWARF_GET_LOC(d->loc[LR]),
rs->reg[SP].where, rs->reg[SP].val, DWARF_GET_LOC(d->loc[SP]));
rs->where[R7], rs->val[R7], DWARF_GET_LOC(d->loc[R7]),
rs->where[LR], rs->val[LR], DWARF_GET_LOC(d->loc[LR]),
rs->where[SP], rs->val[SP], DWARF_GET_LOC(d->loc[SP]));
/* A standard frame is defined as:
- CFA is register-relative offset off R7 or SP;
@ -51,37 +51,37 @@ tdep_stash_frame (struct dwarf_cursor *d, struct dwarf_reg_state *rs)
- LR is unsaved or saved at CFA+offset, offset != -1;
- SP is unsaved or saved at CFA+offset, offset != -1. */
if (f->frame_type == UNW_ARM_FRAME_OTHER
&& (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_REG)
&& (rs->reg[DWARF_CFA_REG_COLUMN].val == R7
|| rs->reg[DWARF_CFA_REG_COLUMN].val == SP)
&& labs(rs->reg[DWARF_CFA_OFF_COLUMN].val) < (1 << 29)
&& (rs->where[DWARF_CFA_REG_COLUMN] == DWARF_WHERE_REG)
&& (rs->val[DWARF_CFA_REG_COLUMN] == R7
|| rs->val[DWARF_CFA_REG_COLUMN] == SP)
&& labs(rs->val[DWARF_CFA_OFF_COLUMN]) < (1 << 29)
&& d->ret_addr_column == LR
&& (rs->reg[R7].where == DWARF_WHERE_UNDEF
|| rs->reg[R7].where == DWARF_WHERE_SAME
|| (rs->reg[R7].where == DWARF_WHERE_CFAREL
&& labs(rs->reg[R7].val) < (1 << 29)
&& rs->reg[R7].val+1 != 0))
&& (rs->reg[LR].where == DWARF_WHERE_UNDEF
|| rs->reg[LR].where == DWARF_WHERE_SAME
|| (rs->reg[LR].where == DWARF_WHERE_CFAREL
&& labs(rs->reg[LR].val) < (1 << 29)
&& rs->reg[LR].val+1 != 0))
&& (rs->reg[SP].where == DWARF_WHERE_UNDEF
|| rs->reg[SP].where == DWARF_WHERE_SAME
|| (rs->reg[SP].where == DWARF_WHERE_CFAREL
&& labs(rs->reg[SP].val) < (1 << 29)
&& rs->reg[SP].val+1 != 0)))
&& (rs->where[R7] == DWARF_WHERE_UNDEF
|| rs->where[R7] == DWARF_WHERE_SAME
|| (rs->where[R7] == DWARF_WHERE_CFAREL
&& labs(rs->val[R7]) < (1 << 29)
&& rs->val[R7]+1 != 0))
&& (rs->where[LR] == DWARF_WHERE_UNDEF
|| rs->where[LR] == DWARF_WHERE_SAME
|| (rs->where[LR] == DWARF_WHERE_CFAREL
&& labs(rs->val[LR]) < (1 << 29)
&& rs->val[LR]+1 != 0))
&& (rs->where[SP] == DWARF_WHERE_UNDEF
|| rs->where[SP] == DWARF_WHERE_SAME
|| (rs->where[SP] == DWARF_WHERE_CFAREL
&& labs(rs->val[SP]) < (1 << 29)
&& rs->val[SP]+1 != 0)))
{
/* Save information for a standard frame. */
f->frame_type = UNW_ARM_FRAME_STANDARD;
f->cfa_reg_sp = (rs->reg[DWARF_CFA_REG_COLUMN].val == SP);
f->cfa_reg_offset = rs->reg[DWARF_CFA_OFF_COLUMN].val;
if (rs->reg[R7].where == DWARF_WHERE_CFAREL)
f->r7_cfa_offset = rs->reg[R7].val;
if (rs->reg[LR].where == DWARF_WHERE_CFAREL)
f->lr_cfa_offset = rs->reg[LR].val;
if (rs->reg[SP].where == DWARF_WHERE_CFAREL)
f->sp_cfa_offset = rs->reg[SP].val;
f->cfa_reg_sp = (rs->val[DWARF_CFA_REG_COLUMN] == SP);
f->cfa_reg_offset = rs->val[DWARF_CFA_OFF_COLUMN];
if (rs->where[R7] == DWARF_WHERE_CFAREL)
f->r7_cfa_offset = rs->val[R7];
if (rs->where[LR] == DWARF_WHERE_CFAREL)
f->lr_cfa_offset = rs->val[LR];
if (rs->where[SP] == DWARF_WHERE_CFAREL)
f->sp_cfa_offset = rs->val[SP];
Debug (4, " standard frame\n");
}
else

View file

@ -55,8 +55,8 @@ static inline void
set_reg (dwarf_state_record_t *sr, unw_word_t regnum, dwarf_where_t where,
unw_word_t val)
{
sr->rs_current.reg[regnum].where = where;
sr->rs_current.reg[regnum].val = val;
sr->rs_current.where[regnum] = where;
sr->rs_current.val[regnum] = val;
}
static inline int
@ -218,7 +218,8 @@ run_cfi_program (struct dwarf_cursor *c, dwarf_state_record_t *sr,
ret = -UNW_EINVAL;
break;
}
sr->rs_current.reg[regnum] = sr->rs_initial.reg[regnum];
sr->rs_current.where[regnum] = sr->rs_initial.where[regnum];
sr->rs_current.val[regnum] = sr->rs_initial.val[regnum];
Debug (15, "CFA_restore r%lu\n", (long) regnum);
break;
@ -232,7 +233,8 @@ run_cfi_program (struct dwarf_cursor *c, dwarf_state_record_t *sr,
ret = -UNW_EINVAL;
break;
}
sr->rs_current.reg[regnum] = sr->rs_initial.reg[regnum];
sr->rs_current.where[regnum] = sr->rs_initial.where[regnum];
sr->rs_current.val[regnum] = sr->rs_initial.val[regnum];
Debug (15, "CFA_restore_extended r%lu\n", (long) regnum);
break;
@ -276,8 +278,7 @@ run_cfi_program (struct dwarf_cursor *c, dwarf_state_record_t *sr,
ret = -UNW_ENOMEM;
break;
}
memcpy ((*rs_stack)->state.reg, sr->rs_current.reg,
sizeof (dwarf_reg_state_t))
memcpy (&(*rs_stack)->state, &sr->rs_current, sizeof (sr->rs_current))
Debug (15, "CFA_remember_state\n");
break;
@ -288,8 +289,7 @@ run_cfi_program (struct dwarf_cursor *c, dwarf_state_record_t *sr,
ret = -UNW_EINVAL;
break;
}
memcpy (&sr->rs_current.reg, &(*rs_stack)->state.reg,
sizeof (dwarf_reg_state_t));
memcpy (&sr->rs_current, &(*rs_stack)->state, sizeof (sr->rs_current));
pop_rstate_stack(rs_stack);
Debug (15, "CFA_restore_state\n");
break;
@ -790,32 +790,32 @@ apply_reg_state (struct dwarf_cursor *c, struct dwarf_reg_state *rs)
/* Evaluate the CFA first, because it may be referred to by other
expressions. */
if (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_REG)
if (rs->where[DWARF_CFA_REG_COLUMN] == DWARF_WHERE_REG)
{
/* CFA is equal to [reg] + offset: */
/* As a special-case, if the stack-pointer is the CFA and the
stack-pointer wasn't saved, popping the CFA implicitly pops
the stack-pointer as well. */
if ((rs->reg[DWARF_CFA_REG_COLUMN].val == UNW_TDEP_SP)
&& (UNW_TDEP_SP < ARRAY_SIZE(rs->reg))
&& (rs->reg[UNW_TDEP_SP].where == DWARF_WHERE_SAME))
if ((rs->val[DWARF_CFA_REG_COLUMN] == UNW_TDEP_SP)
&& (UNW_TDEP_SP < ARRAY_SIZE(rs->val))
&& (rs->where[UNW_TDEP_SP] == DWARF_WHERE_SAME))
cfa = c->cfa;
else
{
regnum = dwarf_to_unw_regnum (rs->reg[DWARF_CFA_REG_COLUMN].val);
regnum = dwarf_to_unw_regnum (rs->val[DWARF_CFA_REG_COLUMN]);
if ((ret = unw_get_reg ((unw_cursor_t *) c, regnum, &cfa)) < 0)
return ret;
}
cfa += rs->reg[DWARF_CFA_OFF_COLUMN].val;
cfa += rs->val[DWARF_CFA_OFF_COLUMN];
}
else
{
/* CFA is equal to EXPR: */
assert (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_EXPR);
assert (rs->where[DWARF_CFA_REG_COLUMN] == DWARF_WHERE_EXPR);
addr = rs->reg[DWARF_CFA_REG_COLUMN].val;
addr = rs->val[DWARF_CFA_REG_COLUMN];
if ((ret = eval_location_expr (c, as, a, addr, &cfa_loc, arg)) < 0)
return ret;
/* the returned location better be a memory location... */
@ -826,7 +826,7 @@ apply_reg_state (struct dwarf_cursor *c, struct dwarf_reg_state *rs)
for (i = 0; i < DWARF_NUM_PRESERVED_REGS; ++i)
{
switch ((dwarf_where_t) rs->reg[i].where)
switch ((dwarf_where_t) rs->where[i])
{
case DWARF_WHERE_UNDEF:
c->loc[i] = DWARF_NULL_LOC;
@ -836,21 +836,21 @@ apply_reg_state (struct dwarf_cursor *c, struct dwarf_reg_state *rs)
break;
case DWARF_WHERE_CFAREL:
c->loc[i] = DWARF_MEM_LOC (c, cfa + rs->reg[i].val);
c->loc[i] = DWARF_MEM_LOC (c, cfa + rs->val[i]);
break;
case DWARF_WHERE_REG:
c->loc[i] = DWARF_REG_LOC (c, dwarf_to_unw_regnum (rs->reg[i].val));
c->loc[i] = DWARF_REG_LOC (c, dwarf_to_unw_regnum (rs->val[i]));
break;
case DWARF_WHERE_EXPR:
addr = rs->reg[i].val;
addr = rs->val[i];
if ((ret = eval_location_expr (c, as, a, addr, c->loc + i, arg)) < 0)
return ret;
break;
case DWARF_WHERE_VAL_EXPR:
addr = rs->reg[i].val;
addr = rs->val[i];
if ((ret = eval_location_expr (c, as, a, addr, c->loc + i, arg)) < 0)
return ret;
c->loc[i] = DWARF_VAL_LOC (c, DWARF_GET_LOC (c->loc[i]));

View file

@ -34,20 +34,20 @@ tdep_stash_frame (struct dwarf_cursor *d, struct dwarf_reg_state *rs)
Debug (4, "ip=0x%lx cfa=0x%lx type %d cfa [where=%d val=%ld] cfaoff=%ld"
" ra=0x%lx rbp [where=%d val=%ld @0x%lx] rsp [where=%d val=%ld @0x%lx]\n",
d->ip, d->cfa, f->frame_type,
rs->reg[DWARF_CFA_REG_COLUMN].where,
rs->reg[DWARF_CFA_REG_COLUMN].val,
rs->reg[DWARF_CFA_OFF_COLUMN].val,
rs->where[DWARF_CFA_REG_COLUMN],
rs->val[DWARF_CFA_REG_COLUMN],
rs->val[DWARF_CFA_OFF_COLUMN],
DWARF_GET_LOC(d->loc[d->ret_addr_column]),
rs->reg[RBP].where, rs->reg[RBP].val, DWARF_GET_LOC(d->loc[RBP]),
rs->reg[RSP].where, rs->reg[RSP].val, DWARF_GET_LOC(d->loc[RSP]));
rs->where[RBP], rs->val[RBP], DWARF_GET_LOC(d->loc[RBP]),
rs->where[RSP], rs->val[RSP], DWARF_GET_LOC(d->loc[RSP]));
if (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_EXPR &&
rs->reg[RBP].where == DWARF_WHERE_EXPR) {
if (rs->where[DWARF_CFA_REG_COLUMN] == DWARF_WHERE_EXPR &&
rs->where[RBP] == DWARF_WHERE_EXPR) {
/* Check for GCC generated alignment frame for rsp. A simple
* def_cfa_expr that loads a constant offset from rbp, where the
* addres of the rip was pushed on the stack */
unw_word_t cfa_addr = rs->reg[DWARF_CFA_REG_COLUMN].val;
unw_word_t rbp_addr = rs->reg[RBP].val;
unw_word_t cfa_addr = rs->val[DWARF_CFA_REG_COLUMN];
unw_word_t rbp_addr = rs->val[RBP];
unw_word_t cfa_offset;
int ret = dwarf_stack_aligned(d, cfa_addr, rbp_addr, &cfa_offset);
@ -64,30 +64,30 @@ tdep_stash_frame (struct dwarf_cursor *d, struct dwarf_reg_state *rs)
- RBP is unsaved or saved at CFA+offset, offset != -1;
- RSP is unsaved or saved at CFA+offset, offset != -1. */
if (f->frame_type == UNW_X86_64_FRAME_OTHER
&& (rs->reg[DWARF_CFA_REG_COLUMN].where == DWARF_WHERE_REG)
&& (rs->reg[DWARF_CFA_REG_COLUMN].val == RBP
|| rs->reg[DWARF_CFA_REG_COLUMN].val == RSP)
&& labs((long) rs->reg[DWARF_CFA_OFF_COLUMN].val) < (1 << 28)
&& (rs->where[DWARF_CFA_REG_COLUMN] == DWARF_WHERE_REG)
&& (rs->val[DWARF_CFA_REG_COLUMN] == RBP
|| rs->val[DWARF_CFA_REG_COLUMN] == RSP)
&& labs((long) rs->val[DWARF_CFA_OFF_COLUMN]) < (1 << 28)
&& DWARF_GET_LOC(d->loc[d->ret_addr_column]) == d->cfa-8
&& (rs->reg[RBP].where == DWARF_WHERE_UNDEF
|| rs->reg[RBP].where == DWARF_WHERE_SAME
|| (rs->reg[RBP].where == DWARF_WHERE_CFAREL
&& labs((long) rs->reg[RBP].val) < (1 << 14)
&& rs->reg[RBP].val+1 != 0))
&& (rs->reg[RSP].where == DWARF_WHERE_UNDEF
|| rs->reg[RSP].where == DWARF_WHERE_SAME
|| (rs->reg[RSP].where == DWARF_WHERE_CFAREL
&& labs((long) rs->reg[RSP].val) < (1 << 14)
&& rs->reg[RSP].val+1 != 0)))
&& (rs->where[RBP] == DWARF_WHERE_UNDEF
|| rs->where[RBP] == DWARF_WHERE_SAME
|| (rs->where[RBP] == DWARF_WHERE_CFAREL
&& labs((long) rs->val[RBP]) < (1 << 14)
&& rs->val[RBP]+1 != 0))
&& (rs->where[RSP] == DWARF_WHERE_UNDEF
|| rs->where[RSP] == DWARF_WHERE_SAME
|| (rs->where[RSP] == DWARF_WHERE_CFAREL
&& labs((long) rs->val[RSP]) < (1 << 14)
&& rs->val[RSP]+1 != 0)))
{
/* Save information for a standard frame. */
f->frame_type = UNW_X86_64_FRAME_STANDARD;
f->cfa_reg_rsp = (rs->reg[DWARF_CFA_REG_COLUMN].val == RSP);
f->cfa_reg_offset = rs->reg[DWARF_CFA_OFF_COLUMN].val;
if (rs->reg[RBP].where == DWARF_WHERE_CFAREL)
f->rbp_cfa_offset = rs->reg[RBP].val;
if (rs->reg[RSP].where == DWARF_WHERE_CFAREL)
f->rsp_cfa_offset = rs->reg[RSP].val;
f->cfa_reg_rsp = (rs->val[DWARF_CFA_REG_COLUMN] == RSP);
f->cfa_reg_offset = rs->val[DWARF_CFA_OFF_COLUMN];
if (rs->where[RBP] == DWARF_WHERE_CFAREL)
f->rbp_cfa_offset = rs->val[RBP];
if (rs->where[RSP] == DWARF_WHERE_CFAREL)
f->rsp_cfa_offset = rs->val[RSP];
Debug (4, " standard frame\n");
}