static seh_context *seh_ctx_cur = NULL;
/* Write xdata for arm, sh3, sh4, and ppc. */
+
static void
seh_write_text_eh_data (const char *hnd, const char *hnd_data)
{
valueT func_len = 0;
valueT prolog_len = 0;
valueT start_len = 0;
+
func_len = resolve_symbol_value (c->end_addr);
start_len = resolve_symbol_value (c->start_addr);
if (c->endprologue_addr)
bfd *abfd = stdoutput;
h = seh_ctx_root;
- if (h->done)
+ if (h == NULL || h->done)
return;
while (h != NULL)
{
seh_x64_make_prologue_element (int kind, int reg, bfd_vma off)
{
seh_prologue_element *n;
+
if (seh_ctx_cur == NULL)
return;
if (seh_ctx_cur->elems_count == seh_ctx_cur->elems_max)
{
seh_ctx_cur->elems = (seh_prologue_element *)
xrealloc (seh_ctx_cur->elems,
- ((seh_ctx_cur->elems_max + 8) * sizeof (seh_prologue_element)));
+ ((seh_ctx_cur->elems_max + 8) * sizeof (seh_prologue_element)));
seh_ctx_cur->elems_max += 8;
}
n = &seh_ctx_cur->elems[seh_ctx_cur->elems_count];
seh_x64_read_reg (const char *tok, int kind, int *regno)
{
static const char *frame_regs[16] =
- { "cfa", "rcx", "rdx", "rbx", "rsp", "rbp","rsi","rdi",
- "r8","r9","r10","r11","r12","r13","r14","r15" };
+ { "cfa", "rcx", "rdx", "rbx", "rsp", "rbp","rsi","rdi",
+ "r8","r9","r10","r11","r12","r13","r14","r15" };
static const char *int_regs[16] =
- { "rax", "rcx", "rdx", "rbx", "rsp", "rbp","rsi","rdi",
- "r8","r9","r10","r11","r12","r13","r14","r15" };
+ { "rax", "rcx", "rdx", "rbx", "rsp", "rbp","rsi","rdi",
+ "r8","r9","r10","r11","r12","r13","r14","r15" };
static const char *xmm_regs[16] =
- { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
- "xmm8", "xmm9", "xmm10","xmm11","xmm12","xmm13","xmm14","xmm15" };
+ { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
+ "xmm8", "xmm9", "xmm10","xmm11","xmm12","xmm13","xmm14","xmm15" };
static const char *mm_regs[16] =
- { "xmm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
- "xmm8", "mm9", "mm10","mm11","mm12","mm13","mm14","mm15" };
+ { "xmm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
+ "xmm8", "mm9", "mm10","mm11","mm12","mm13","mm14","mm15" };
const char **p = NULL;
char name_end;
char *symbol_name = NULL;
while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
input_line_pointer++;
switch (kind)
- {
- case 0:
- p = frame_regs;
- break;
- case 1:
- p = int_regs;
- break;
- case 2:
- p = mm_regs;
- break;
- case 3:
- p = xmm_regs;
- break;
- default:
- abort ();
- }
+ {
+ case 0:
+ p = frame_regs;
+ break;
+ case 1:
+ p = int_regs;
+ break;
+ case 2:
+ p = mm_regs;
+ break;
+ case 3:
+ p = xmm_regs;
+ break;
+ default:
+ abort ();
+ }
+
if (*input_line_pointer == 0 || *input_line_pointer == '\n')
- {
return 0;
- }
+
if (*input_line_pointer == '%')
++input_line_pointer;
symbol_name = input_line_pointer;
name_end = get_symbol_end ();
+
for (i = 0; i < 16; i++)
- {
if (! strcasecmp (p[i], symbol_name))
break;
- }
+
if (i == 16)
- {
as_warn (_("In %s we found the invalid register name %s.\n"),
- tok, symbol_name);
- }
+ tok, symbol_name);
+
*input_line_pointer = name_end;
while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
input_line_pointer++;
while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
input_line_pointer++;
if (*input_line_pointer == '0')
- {
- ++input_line_pointer;
- had_one = 1;
- base = 8;
- switch ((*input_line_pointer))
{
- case 'x':
- case 'X':
- base = 16;
++input_line_pointer;
- break;
- case 'd':
- case 'D':
- base = 10;
- input_line_pointer++;
- break;
- case 'o':
- case 'O':
+ had_one = 1;
base = 8;
- input_line_pointer++;
- break;
+ switch ((*input_line_pointer))
+ {
+ case 'x':
+ case 'X':
+ base = 16;
+ ++input_line_pointer;
+ break;
+ case 'd':
+ case 'D':
+ base = 10;
+ input_line_pointer++;
+ break;
+ case 'o':
+ case 'O':
+ base = 8;
+ input_line_pointer++;
+ break;
+ }
}
- }
while (*input_line_pointer != 0)
- {
- if (input_line_pointer[0] >= '0' && input_line_pointer[0] <='9')
- r = (bfd_vma) (input_line_pointer[0] - '0');
- else if (base == 16 && input_line_pointer[0] >= 'a' && input_line_pointer[0] <='f')
- r = (bfd_vma) ((input_line_pointer[0] - 'a') + 10);
- else if (base == 16 && input_line_pointer[0] >= 'A' && input_line_pointer[0] <='F')
- r = (bfd_vma) ((input_line_pointer[0] - 'A') + 10);
- else
- break;
- input_line_pointer++;
- v *= base;
- v += r;
- had_one = 1;
- }
+ {
+ if (input_line_pointer[0] >= '0' && input_line_pointer[0] <='9')
+ r = (bfd_vma) (input_line_pointer[0] - '0');
+ else if (base == 16 && input_line_pointer[0] >= 'a' && input_line_pointer[0] <='f')
+ r = (bfd_vma) ((input_line_pointer[0] - 'a') + 10);
+ else if (base == 16 && input_line_pointer[0] >= 'A' && input_line_pointer[0] <='F')
+ r = (bfd_vma) ((input_line_pointer[0] - 'A') + 10);
+ else
+ break;
+ input_line_pointer++;
+ v *= base;
+ v += r;
+ had_one = 1;
+ }
*off = v;
if (had_one == 0)
- {
- as_warn (_("In %s we expect a number.\n"),
- tok);
- }
+ {
+ as_warn (_("In %s we expect a number.\n"),
+ tok);
+ }
while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
input_line_pointer++;
if (*input_line_pointer == ',')
char name_end;
if (seh_ctx_cur != NULL)
- {
- as_warn (_(".seh_proc has to be closed by .seh_endprog\n"));
- obj_coff_seh_endproc (0);
- }
+ {
+ as_warn (_(".seh_proc has to be closed by .seh_endprog\n"));
+ obj_coff_seh_endproc (0);
+ }
if (*input_line_pointer == 0 || *input_line_pointer == '\n')
{
obj_coff_seh_endproc (int what ATTRIBUTE_UNUSED)
{
if (seh_ctx_cur == NULL)
- {
- as_warn (_(".seh_endprog without prior .seh_proc (ignored)\n"));
- demand_empty_rest_of_line ();
- return;
- }
+ {
+ as_warn (_(".seh_endprog without prior .seh_proc (ignored)\n"));
+ demand_empty_rest_of_line ();
+ return;
+ }
seh_ctx->end_symbol = make_seh_text_label (seh_ctx, &(seh_ctx->end_addr));
seh_ctx->xdata_first = seh_make_xlbl_name (seh_ctx);
make_function_entry_pdata (seh_ctx);
{
int reg = 0;
int kind = -1;
+
if (seh_ctx_cur == NULL)
- {
- as_warn (_(".seh_push used outside of .seh_proc block.\n"));
- demand_empty_rest_of_line ();
- return;
- }
- /* what 0:reg, 1:pushframe. */
+ {
+ as_warn (_(".seh_push used outside of .seh_proc block.\n"));
+ demand_empty_rest_of_line ();
+ return;
+ }
+ /* What 0:reg, 1:pushframe. */
switch (what)
- {
- case 0:
- if (seh_x64_read_reg (".seh_push", 1, ®))
- kind = UWOP_PUSH_NONVOL;
- else
- as_warn (_(".seh_pushreg expects register argument."));
- break;
- case 1:
- kind = UWOP_PUSH_MACHFRAME;
- break;
- default:
- abort ();
- }
+ {
+ case 0:
+ if (seh_x64_read_reg (".seh_push", 1, ®))
+ kind = UWOP_PUSH_NONVOL;
+ else
+ as_warn (_(".seh_pushreg expects register argument."));
+ break;
+ case 1:
+ kind = UWOP_PUSH_MACHFRAME;
+ break;
+ default:
+ abort ();
+ }
if (seh_get_target_kind () != seh_kind_x64)
as_warn (_(".seh_save... is ignored for this target.\n"));
else if (kind != -1)
/* what 0:reg, 1:mm, 2:xmm. */
switch (what)
- {
- case 0:
- ok &= seh_x64_read_reg (".seh_savereg", 1, ®);
- kind = UWOP_SAVE_NONVOL;
- break;
- case 1:
- ok &= seh_x64_read_reg (".seh_savemm", 2, ®);
- kind = UWOP_SAVE_XMM;
- break;
- case 2:
- ok &= seh_x64_read_reg (".seh_savexmm", 3, ®);
- kind = UWOP_SAVE_XMM128;
- break;
- default:
- abort ();
- }
+ {
+ case 0:
+ ok &= seh_x64_read_reg (".seh_savereg", 1, ®);
+ kind = UWOP_SAVE_NONVOL;
+ break;
+ case 1:
+ ok &= seh_x64_read_reg (".seh_savemm", 2, ®);
+ kind = UWOP_SAVE_XMM;
+ break;
+ case 2:
+ ok &= seh_x64_read_reg (".seh_savexmm", 3, ®);
+ kind = UWOP_SAVE_XMM128;
+ break;
+ default:
+ abort ();
+ }
ok &= seh_read_offset (".seh_save", &off);
if (seh_ctx_cur == NULL)
- {
- as_warn (_(".seh_save used outside of .seh_proc block.\n"));
- demand_empty_rest_of_line ();
- return;
- }
+ {
+ as_warn (_(".seh_save used outside of .seh_proc block.\n"));
+ demand_empty_rest_of_line ();
+ return;
+ }
if (seh_get_target_kind () != seh_kind_x64)
as_warn (_(".seh_save... is ignored for this target.\n"));
else
obj_coff_seh_endprologue (int what ATTRIBUTE_UNUSED)
{
if (seh_ctx_cur == NULL)
- {
- as_warn (_(".seh_endprologue used outside of .seh_proc block.\n"));
- demand_empty_rest_of_line ();
- return;
- }
+ {
+ as_warn (_(".seh_endprologue used outside of .seh_proc block.\n"));
+ demand_empty_rest_of_line ();
+ return;
+ }
if (seh_ctx_cur->endprologue_symbol != NULL)
as_warn (_(".seh_endprologue used more then once in .seh_proc block.\n"));
else
obj_coff_seh_stack_alloc (int what ATTRIBUTE_UNUSED)
{
bfd_vma size;
+
if (seh_ctx_cur == NULL)
- {
- as_warn (_(".seh_stackalloc used outside of .seh_proc block.\n"));
- demand_empty_rest_of_line ();
- return;
- }
+ {
+ as_warn (_(".seh_stackalloc used outside of .seh_proc block.\n"));
+ demand_empty_rest_of_line ();
+ return;
+ }
if (seh_read_offset (".seh_stackalloc", &size))
{
if (seh_get_target_kind () != seh_kind_x64)
ok &= seh_x64_read_reg (".seh_setframe", 0, ®);
ok &= seh_read_offset (".seh_setframe", &off);
if (seh_ctx_cur == NULL)
- {
- as_warn (_(".seh_setframe used outside of .seh_proc block.\n"));
- demand_empty_rest_of_line ();
- return;
- }
+ {
+ as_warn (_(".seh_setframe used outside of .seh_proc block.\n"));
+ demand_empty_rest_of_line ();
+ return;
+ }
if (ok)
- {
- seh_ctx_cur->framereg = reg;
- seh_ctx_cur->frameoff = off;
- }
+ {
+ seh_ctx_cur->framereg = reg;
+ seh_ctx_cur->frameoff = off;
+ }
if (seh_get_target_kind () != seh_kind_x64)
as_warn (_(".seh_setframe is ignored for this target.\n"));
demand_empty_rest_of_line ();
seh_symbol_init (bfd *abfd, unsigned int added)
{
unsigned int oldcount;
+
oldcount = bfd_get_symcount (abfd);
symptr = oldcount;
symtab = xmalloc ((oldcount + added + 6) * sizeof (asymbol *));
asymbol *sym;
char *name = xmalloc (strlen (n1) + strlen (n2) + strlen (n3) + 1);
int ret = symptr;
+
strcpy (name, n1);
strcat (name, n2);
strcat (name, n3);
{
asection *sec;
asymbol *sym;
+
sec = seh_make_section2 (name, flags);
bfd_set_section_alignment (abfd, sec, align);
/* Remember to undo this before trying to link internally! */
sec = subseg_new (name, (subsegT) 0);
bfd_set_section_flags (stdoutput, sec,
- ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA | flags)
- & bfd_applicable_section_flags (stdoutput)));
+ ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA | flags)
+ & bfd_applicable_section_flags (stdoutput)));
return sec;
}
{
size_t len = strlen (".seh_xlbl_") + strlen (c->func_name) + 9 + 1;
char *ret = (char*) xmalloc (len);
+
if (!ret)
as_fatal (_("Out of memory for xdata lable for %s"), c->func_name);
else
{
char *sym_name;
size_t len = strlen (".seh_tlbl_") + strlen (c->func_name) + 9 + 1;
+
sym_name = (char *) xmalloc (len);
if (!sym_name)
as_fatal (_("Allocating memory for SEH's text symbol for %s failed"), c->func_name);
sprintf (sym_name, ".seh_tlbl_%s_%x", c->func_name, c->tlbl_count);
c->tlbl_count += 1;
if (addr)
- {
- seh_make_globl (sym_name);
- *addr = colon (sym_name);
- }
+ {
+ seh_make_globl (sym_name);
+ *addr = colon (sym_name);
+ }
return sym_name;
}
valueT start_off = resolve_symbol_value (c->start_addr);
valueT un_off;
seh_prologue_element *e = c->elems;
+
names[0] = c->start_symbol;
idx[0] = 0;
if (c->elems_count == 0)
return;
for (i = 0; i < c->elems_count; i++)
- {
- un_off = resolve_symbol_value (e[i].pc_addr);
- if ((un_off - start_off) > 255)
{
- names[count] = e[i].pc_symbol;
- idx[count] = (int) i;
- count++;
- start_off = un_off;
+ un_off = resolve_symbol_value (e[i].pc_addr);
+ if ((un_off - start_off) > 255)
+ {
+ names[count] = e[i].pc_symbol;
+ idx[count] = (int) i;
+ count++;
+ start_off = un_off;
+ }
}
- }
}
static int
valueT start_off = resolve_symbol_value (c->start_addr);
valueT un_off;
seh_prologue_element *e = c->elems;
+
if (c->elems_count == 0)
return count;
for (i = 0; i < c->elems_count; i++)
- {
- un_off = resolve_symbol_value (e[i].pc_addr);
- if ((un_off - start_off) > 255)
{
- count++;
- start_off = un_off;
+ un_off = resolve_symbol_value (e[i].pc_addr);
+ if ((un_off - start_off) > 255)
+ {
+ count++;
+ start_off = un_off;
+ }
}
- }
return count;
}
seh_getelm_data_size (const seh_context *c, int elm_start, int elm_end)
{
size_t ret = PEX64_UWI_SIZEOF_UWCODE_ARRAY (elm_end - elm_start);
+
while (elm_start < elm_end)
{
switch (c->elems[elm_start].kind)
case UWOP_SAVE_XMM:
case UWOP_SAVE_XMM128:
if ((c->elems[elm_start].offset & 7) != 0 ||
- ((c->elems[elm_start].offset / 8) > 0xffff))
+ ((c->elems[elm_start].offset / 8) > 0xffff))
ret += 6;
else
ret += 4;
seh_getsize_of_unwind_entry (seh_context *c, int elm_start, int elm_end, int bechain)
{
size_t ret = seh_getelm_data_size(c, elm_start, elm_end);
+
c->count_syms += 1;
if (bechain)
{
if (bechain)
{
char n[100];
+
sprintf (n,"%x", no);
idx = seh_symbol (c->abfd, ".xdata_fct", c->func_name, n, UNDSEC, BSF_GLOBAL, (int) off);
seh_reloc (c->abfd, off, BFD_RELOC_RVA, idx);
c->count_syms += 5 * need;
xdata_sz += (seh_getsize_of_unwind_entry (c, elm_start[0], elm_start[1], 1 != need) + 7) & ~7;
for (i = 1; i < need; i++)
- {
xdata_sz += (seh_getsize_of_unwind_entry (c, elm_start[i], elm_start[i + 1], 1 != need) + 7) & ~7;
- }
/* Create lable names for .xdata unwind info. */
names[0] = c->xdata_first;
int *elm_start = c->xdata_elm_start;
for (i = 1; i < need; i++)
- {
- seh_make_function_entry_xdata (c, pc_syms[i], c->end_symbol, names[i], data, &offs, i);
- }
+ seh_make_function_entry_xdata (c, pc_syms[i], c->end_symbol, names[i], data, &offs, i);
+
/* Generate the function entry. Remark, that just
first is in .pdata section and already emitted. */
seh_make_unwind_entry (c, c->xdata_first, elm_start[0], elm_start[1], 1 != need, data, &offs, 1);
for (i = 1; i < need; i++)
- {
- seh_make_unwind_entry (c, names[i], elm_start[i], elm_start[i + 1], (i + 1) != need, data, &offs, i + 1);
- }
+ seh_make_unwind_entry (c, names[i], elm_start[i], elm_start[i + 1], (i + 1) != need, data, &offs, i + 1);
+
for (i = 1; i < need; i++)
free (names[i]);
free (names);
bfd_vma addr = (bfd_vma) *poffs;
int idx;
char s[100];
+
if (!data)
return;
sprintf (s,"%x",no);
const char *handler, const char *jmp)
{
seh_scope_elem *r;
+
if (!end || !begin)
return NULL;
if (c->scope_count >= c->scope_max)