* [patch bfd]: Follow-up for dump of xdata SEH
@ 2010-10-08 9:58 Kai Tietz
2010-10-08 15:39 ` Richard Henderson
2010-10-08 15:42 ` Richard Henderson
0 siblings, 2 replies; 6+ messages in thread
From: Kai Tietz @ 2010-10-08 9:58 UTC (permalink / raw)
To: Binutils; +Cc: Richard Henderson
[-- Attachment #1: Type: text/plain, Size: 733 bytes --]
Hello,
this patch replace the quadratic search of end address in xdata for a
given xdata-start address by a binary search. Additionally it changes
the misleading term "CFA" by "none".
2010-10-08 Kai Tietz
* pei-x86_64.c (find_next_xdata_or_end): Removed.
(pex64_dump_xdata): Remove arguments stop, onaline,
and pdata. New argument endx. Print term "none"
instead of misleading "CFA".
(sort_xdata_arr): New function.
(pex64_bfd_print_pdata): Use binary search/sort for unwind-RVAs
instead of searching quadratic.
Tested for x86_64-w64-mingw32. Ok for apply?
Regards,
Kai
--
| (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination
[-- Attachment #2: speed_xdatadmp.diff --]
[-- Type: application/octet-stream, Size: 4733 bytes --]
Index: src/bfd/pei-x86_64.c
===================================================================
--- src.orig/bfd/pei-x86_64.c 2010-09-20 18:54:46.000000000 +0200
+++ src/bfd/pei-x86_64.c 2010-10-08 11:48:47.761510600 +0200
@@ -303,41 +303,9 @@ pex64_get_section_by_rva (bfd *abfd, bfd
return section;
}
-static bfd_vma
-find_next_xdata_or_end (bfd *abfd, bfd_byte *pdata, bfd_size_type stop,
- int onaline, bfd_vma cur_address, bfd_vma max_size)
-{
- bfd_size_type i;
- bfd_vma ret = 0;
-
- for (i = 0; i < stop; i += onaline)
- {
- struct pex64_runtime_function rf;
-
- if (i + PDATA_ROW_SIZE > stop)
- break;
- pex64_get_runtime_function (abfd, &rf, &pdata[i]);
-
- if (rf.rva_BeginAddress == 0 && rf.rva_EndAddress == 0
- && rf.rva_UnwindData == 0)
- /* We are probably into the padding of the section now. */
- break;
- if (rf.rva_UnwindData != 0 && !rf.isChained)
- {
- if (!ret && rf.rva_UnwindData > cur_address)
- ret = rf.rva_UnwindData;
- else if (rf.rva_UnwindData > cur_address && ret > rf.rva_UnwindData)
- ret = rf.rva_UnwindData;
- }
- }
- if (!ret)
- return max_size;
- return ret;
-}
-
static void
pex64_dump_xdata (FILE *file, bfd *abfd, bfd_vma addr, bfd_vma pc_addr,
- bfd_size_type stop, int onaline, bfd_byte *pdata)
+ bfd_vma *endx)
{
asection *section = pex64_get_section_by_rva (abfd, addr, ".rdata");
bfd_vma vsize;
@@ -364,10 +332,11 @@ pex64_dump_xdata (FILE *file, bfd *abfd,
vsize = section->vma - pe_data (abfd)->pe_opthdr.ImageBase;
addr -= vsize;
- end_addr = find_next_xdata_or_end (abfd, pdata, stop, onaline, addr + vsize,
- vsize + (section->rawsize != 0 ? section->rawsize : section->size));
+ if (endx)
+ end_addr = endx[0] - vsize;
+ else
+ end_addr = (section->rawsize != 0 ? section->rawsize : section->size);
- end_addr -= vsize;
if (bfd_malloc_and_get_section (abfd, section, &data))
{
struct pex64_unwind_info ui;
@@ -411,7 +380,7 @@ pex64_dump_xdata (FILE *file, bfd *abfd,
fprintf (file, "\tPrologue size: %u, Frame offset = 0x%x.\n",
(unsigned int) ui.SizeOfPrologue, (unsigned int) ui.FrameOffset);
fprintf (file, "\tFrame register is %s.\n",
- ui.FrameRegister == 0 ? "CFA"
+ ui.FrameRegister == 0 ? "none"
: pex_regs[(unsigned int) ui.FrameRegister]);
pex64_xdata_print_uwd_codes (file, &ui, pc_addr);
@@ -438,6 +407,17 @@ pex64_dump_xdata (FILE *file, bfd *abfd,
free (data);
}
+static int
+sort_xdata_arr (const void *l, const void *r)
+{
+ const bfd_vma *lp = (const bfd_vma *) l;
+ const bfd_vma *rp = (const bfd_vma *) r;
+
+ if (*lp == *rp)
+ return 0;
+ return (*lp < *rp ? -1 : 1);
+}
+
static bfd_boolean
pex64_bfd_print_pdata (bfd *abfd, void *vfile)
{
@@ -450,6 +430,8 @@ pex64_bfd_print_pdata (bfd *abfd, void *
bfd_vma prev_beginaddress = 0;
int onaline = PDATA_ROW_SIZE;
int seen_error = 0;
+ bfd_vma *xdata_arr;
+ int xdata_arr_cnt;
if (section == NULL
|| coff_section_data (abfd, section) == NULL
@@ -478,6 +460,8 @@ pex64_bfd_print_pdata (bfd *abfd, void *
return FALSE;
}
+ xdata_arr = (bfd_vma *) xmalloc (sizeof (bfd_vma) * ((stop / onaline) + 1));
+ xdata_arr_cnt = 0;
/* Do sanity check of pdata. */
for (i = 0; i < stop; i += onaline)
{
@@ -523,14 +507,26 @@ pex64_bfd_print_pdata (bfd *abfd, void *
seen_error = 1;
fprintf (file, " has negative unwind address\n");
}
+ if (rf.rva_UnwindData && !rf.isChained)
+ xdata_arr[xdata_arr_cnt++] = rf.rva_UnwindData;
}
if (seen_error)
{
free (data);
+ free (xdata_arr);
return TRUE;
}
+
+ /* Add end of list marker. */
+ xdata_arr[xdata_arr_cnt++] = ~((bfd_vma) 0);
+
+ /* Sort start RVAs of xdata. */
+ if (xdata_arr_cnt > 1)
+ qsort (xdata_arr, (size_t) xdata_arr_cnt, sizeof (bfd_vma),
+ sort_xdata_arr);
+
/* Do dump of pdata related xdata. */
for (i = 0; i < stop; i += onaline)
@@ -563,12 +559,27 @@ pex64_bfd_print_pdata (bfd *abfd, void *
fprintf (file, ".\n");
}
else
- pex64_dump_xdata (file, abfd, rf.rva_UnwindData, rf.rva_BeginAddress,
- stop, onaline, data);
+ {
+ bfd_vma *p;
+ p = (bfd_vma *)
+ bsearch (&rf.rva_UnwindData, xdata_arr,
+ (size_t) xdata_arr_cnt, sizeof (bfd_vma),
+ sort_xdata_arr);
+ if (p != NULL)
+ {
+ while (p[0] <= rf.rva_UnwindData)
+ ++p;
+ if (p[0] == ~((bfd_vma) 0))
+ p = NULL;
+ }
+ pex64_dump_xdata (file, abfd, rf.rva_UnwindData,
+ rf.rva_BeginAddress, p);
+ }
}
}
free (data);
+ free (xdata_arr);
return TRUE;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch bfd]: Follow-up for dump of xdata SEH
2010-10-08 9:58 [patch bfd]: Follow-up for dump of xdata SEH Kai Tietz
@ 2010-10-08 15:39 ` Richard Henderson
2010-10-08 15:42 ` Richard Henderson
1 sibling, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2010-10-08 15:39 UTC (permalink / raw)
To: Kai Tietz; +Cc: Binutils
On 10/08/2010 02:58 AM, Kai Tietz wrote:
I'd like to see a little more commentary here. It took me a minute
or three to convince myself that all of this is ok.
/* Search for the current entry in the sorted array. */
> + p = (bfd_vma *)
> + bsearch (&rf.rva_UnwindData, xdata_arr,
> + (size_t) xdata_arr_cnt, sizeof (bfd_vma),
> + sort_xdata_arr);
Null check impossible? We're searching for an entry that we
know we added.
> + if (p != NULL)
> + {
/* Advance to the next pointer into the xdata section. We may
have shared xdata entries, which will result in a string of
identical pointers in the array; advance past all of them. */
> + while (p[0] <= rf.rva_UnwindData)
> + ++p;
> + if (p[0] == ~((bfd_vma) 0))
> + p = NULL;
> + }
Otherwise ok.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch bfd]: Follow-up for dump of xdata SEH
2010-10-08 9:58 [patch bfd]: Follow-up for dump of xdata SEH Kai Tietz
2010-10-08 15:39 ` Richard Henderson
@ 2010-10-08 15:42 ` Richard Henderson
2010-10-08 15:48 ` Kai Tietz
1 sibling, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2010-10-08 15:42 UTC (permalink / raw)
To: Kai Tietz; +Cc: Binutils
Actually, one other thing:
> + /* Add end of list marker. */
> + xdata_arr[xdata_arr_cnt++] = ~((bfd_vma) 0);
> +
A wiser choice of end marker, namely
> + end_addr = (section->rawsize != 0 ? section->rawsize : section->size);
means that you can eliminate the endx == NULL case entirely.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch bfd]: Follow-up for dump of xdata SEH
2010-10-08 15:42 ` Richard Henderson
@ 2010-10-08 15:48 ` Kai Tietz
2010-10-08 15:55 ` Richard Henderson
0 siblings, 1 reply; 6+ messages in thread
From: Kai Tietz @ 2010-10-08 15:48 UTC (permalink / raw)
To: Richard Henderson; +Cc: Binutils
2010/10/8 Richard Henderson <rth@redhat.com>:
> Actually, one other thing:
>
>> + /* Add end of list marker. */
>> + xdata_arr[xdata_arr_cnt++] = ~((bfd_vma) 0);
>> +
>
> A wiser choice of end marker, namely
>
>> + end_addr = (section->rawsize != 0 ? section->rawsize : section->size);
>
> means that you can eliminate the endx == NULL case entirely.
>
>
> r~
>
No, I can't use pdata for xdata section. Section containing xdata gets
mapped in pex64_dump_xdata and not in pdata-block function. This is
caused by the fact that xdata can be in separate '.xdata' section
and/or in any other rdonly section.
Regards,
Kai
--
| (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch bfd]: Follow-up for dump of xdata SEH
2010-10-08 15:48 ` Kai Tietz
@ 2010-10-08 15:55 ` Richard Henderson
2010-10-08 16:02 ` Kai Tietz
0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2010-10-08 15:55 UTC (permalink / raw)
To: Kai Tietz; +Cc: Binutils
On 10/08/2010 08:47 AM, Kai Tietz wrote:
>> A wiser choice of end marker, namely
>>
>>> + end_addr = (section->rawsize != 0 ? section->rawsize : section->size);
>>
>> means that you can eliminate the endx == NULL case entirely.
>>
>>
>> r~
>>
>
> No, I can't use pdata for xdata section. Section containing xdata gets
> mapped in pex64_dump_xdata and not in pdata-block function. This is
> caused by the fact that xdata can be in separate '.xdata' section
> and/or in any other rdonly section.
Ah, I see. Well, that's unfortunate.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch bfd]: Follow-up for dump of xdata SEH
2010-10-08 15:55 ` Richard Henderson
@ 2010-10-08 16:02 ` Kai Tietz
0 siblings, 0 replies; 6+ messages in thread
From: Kai Tietz @ 2010-10-08 16:02 UTC (permalink / raw)
To: Richard Henderson; +Cc: Binutils
2010/10/8 Richard Henderson <rth@redhat.com>:
> On 10/08/2010 08:47 AM, Kai Tietz wrote:
>>> A wiser choice of end marker, namely
>>>
>>>> + end_addr = (section->rawsize != 0 ? section->rawsize : section->size);
>>>
>>> means that you can eliminate the endx == NULL case entirely.
>>>
>>>
>>> r~
>>>
>>
>> No, I can't use pdata for xdata section. Section containing xdata gets
>> mapped in pex64_dump_xdata and not in pdata-block function. This is
>> caused by the fact that xdata can be in separate '.xdata' section
>> and/or in any other rdonly section.
>
> Ah, I see. Well, that's unfortunate.
>
>
> r~
>
Applied with suggested changes.
Regards,
Kai
--
| (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-10-08 16:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-08 9:58 [patch bfd]: Follow-up for dump of xdata SEH Kai Tietz
2010-10-08 15:39 ` Richard Henderson
2010-10-08 15:42 ` Richard Henderson
2010-10-08 15:48 ` Kai Tietz
2010-10-08 15:55 ` Richard Henderson
2010-10-08 16:02 ` Kai Tietz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).