* Linker --sort-section name is broken
@ 2006-08-07 18:10 H. J. Lu
2006-08-07 21:44 ` Sonal Santan
0 siblings, 1 reply; 3+ messages in thread
From: H. J. Lu @ 2006-08-07 18:10 UTC (permalink / raw)
To: binutils; +Cc: sonal.santan
Hi Sonal,
Your linker patch breaks --sort-section name. In wild (), you hae
if (s->handler_data[0]
&& s->handler_data[0]->spec.sorted == by_name
&& !s->filenames_sorted)
{
lang_section_bst_type *tree;
walk_wild (s, output_section_callback_fast, output);
tree = (lang_section_bst_type *) s->handler_data[1];
if (tree)
output_section_callback_tree_to_list (s, tree, output);
s->handler_data[1] = NULL;
}
With "--sort-section name" on
*(.text .text.*)
handler_data[1] is a wildcard spec. But you use it for BST in
wild_sort_fast. I don't see how it can work. I really don't like
tree = (lang_section_bst_type **) &wild->handler_data[1];
It is hard to check if it is really valid.
H.J.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Linker --sort-section name is broken
2006-08-07 18:10 Linker --sort-section name is broken H. J. Lu
@ 2006-08-07 21:44 ` Sonal Santan
2006-08-07 21:56 ` PATCH ld/3006: " H. J. Lu
0 siblings, 1 reply; 3+ messages in thread
From: Sonal Santan @ 2006-08-07 21:44 UTC (permalink / raw)
To: H. J. Lu; +Cc: binutils
Hello H.J.
Looks like ld lacks the kind of examples you tried in its testsuite. I
can think of the following two ways to fix this:
[1] A quick fix would be to change the logic which triggers BST sorting
in wild() to the following--
if (s->handler_data[0]
&& s->handler_data[0]->spec.sorted == by_name
&& !s->filenames_sorted
&& !handler_data[1])
{...
[2] A better fix would be grow the handler_data[] array in struct
lang_wild_statement_struct to size 5. Make the BST logic exclusively use
handler_data[4] for all its needs.
What do you think?
Sonal
H. J. Lu wrote:
> Hi Sonal,
>
> Your linker patch breaks --sort-section name. In wild (), you hae
>
> if (s->handler_data[0]
> && s->handler_data[0]->spec.sorted == by_name
> && !s->filenames_sorted)
> {
> lang_section_bst_type *tree;
>
> walk_wild (s, output_section_callback_fast, output);
>
> tree = (lang_section_bst_type *) s->handler_data[1];
> if (tree)
> output_section_callback_tree_to_list (s, tree, output);
> s->handler_data[1] = NULL;
> }
>
> With "--sort-section name" on
>
> *(.text .text.*)
>
> handler_data[1] is a wildcard spec. But you use it for BST in
> wild_sort_fast. I don't see how it can work. I really don't like
>
> tree = (lang_section_bst_type **) &wild->handler_data[1];
>
> It is hard to check if it is really valid.
>
>
> H.J.
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* PATCH ld/3006: Linker --sort-section name is broken
2006-08-07 21:44 ` Sonal Santan
@ 2006-08-07 21:56 ` H. J. Lu
0 siblings, 0 replies; 3+ messages in thread
From: H. J. Lu @ 2006-08-07 21:56 UTC (permalink / raw)
To: Sonal Santan; +Cc: binutils
On Mon, Aug 07, 2006 at 02:46:11PM -0700, Sonal Santan wrote:
> Hello H.J.
>
> Looks like ld lacks the kind of examples you tried in its testsuite. I
> can think of the following two ways to fix this:
>
> [1] A quick fix would be to change the logic which triggers BST sorting
> in wild() to the following--
> if (s->handler_data[0]
> && s->handler_data[0]->spec.sorted == by_name
> && !s->filenames_sorted
> && !handler_data[1])
> {...
> [2] A better fix would be grow the handler_data[] array in struct
> lang_wild_statement_struct to size 5. Make the BST logic exclusively use
> handler_data[4] for all its needs.
>
> What do you think?
>
I would prefer to add a new field for BST. Casting may hide problems.
This patch seems to work for me.
Also in wild ():
tree = (lang_section_bst_type *) s->handler_data[1];
if (tree)
output_section_callback_tree_to_list (s, tree, output);
s->handler_data[1] = NULL;
we don't need to set s->handler_data[1] to NULL when it is NULL to
begin with.
H.J.
----
2007-08-07 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3006
* ldlang.c (lang_section_bst_type): Moved to ...
* ldlang.h: Here.
* ldlang.h (lang_wild_statement_struct): Add a tree field.
* ldlang.c (wild_sort_fast): Use the tree field for BST.
(wild): Likeise.
(analyze_walk_wild_section_handler): Initialize the tree field.
--- ld/ldlang.c.bst 2006-08-07 14:09:12.000000000 -0700
+++ ld/ldlang.c 2006-08-07 14:41:04.000000000 -0700
@@ -45,15 +45,6 @@
#define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER))
#endif
-/* Binary search tree structure to
- efficiently sort sections by name. */
-typedef struct lang_section_bst
-{
- asection *section;
- struct lang_section_bst *left;
- struct lang_section_bst *right;
-} lang_section_bst_type;
-
/* Locals variables. */
static struct obstack stat_obstack;
static struct obstack map_obstack;
@@ -377,7 +368,7 @@ wild_sort_fast (lang_wild_statement_type
{
lang_section_bst_type **tree;
- tree = (lang_section_bst_type **) &wild->handler_data[1];
+ tree = &wild->tree;
if (!wild->filenames_sorted
&& (sec == NULL || sec->spec.sorted == none))
{
@@ -674,6 +665,7 @@ analyze_walk_wild_section_handler (lang_
ptr->handler_data[1] = NULL;
ptr->handler_data[2] = NULL;
ptr->handler_data[3] = NULL;
+ ptr->tree = NULL;
/* Count how many wildcard_specs there are, and how many of those
actually use wildcards in the name. Also, bail out if any of the
@@ -2553,10 +2545,12 @@ wild (lang_wild_statement_type *s,
walk_wild (s, output_section_callback_fast, output);
- tree = (lang_section_bst_type *) s->handler_data[1];
+ tree = s->tree;
if (tree)
- output_section_callback_tree_to_list (s, tree, output);
- s->handler_data[1] = NULL;
+ {
+ output_section_callback_tree_to_list (s, tree, output);
+ s->tree = NULL;
+ }
}
else
walk_wild (s, output_section_callback, output);
--- ld/ldlang.h.bst 2006-08-07 08:46:00.000000000 -0700
+++ ld/ldlang.h 2006-08-07 14:38:15.000000000 -0700
@@ -305,6 +305,15 @@ typedef void (*walk_wild_section_handler
typedef bfd_boolean (*lang_match_sec_type_func) (bfd *, const asection *,
bfd *, const asection *);
+/* Binary search tree structure to efficiently sort sections by
+ name. */
+typedef struct lang_section_bst
+{
+ asection *section;
+ struct lang_section_bst *left;
+ struct lang_section_bst *right;
+} lang_section_bst_type;
+
struct lang_wild_statement_struct
{
lang_statement_header_type header;
@@ -316,6 +325,7 @@ struct lang_wild_statement_struct
walk_wild_section_handler_t walk_wild_section_handler;
struct wildcard_list *handler_data[4];
+ lang_section_bst_type *tree;
};
typedef struct lang_address_statement_struct
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-08-07 21:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-07 18:10 Linker --sort-section name is broken H. J. Lu
2006-08-07 21:44 ` Sonal Santan
2006-08-07 21:56 ` PATCH ld/3006: " H. J. Lu
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).