This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PR 12001, --defsym
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Mon, 20 Dec 2010 17:00:57 +1030
- Subject: PR 12001, --defsym
This patch reverts Nick's support for early --defsym symbol creation,
and instead implements the same in open_input_bfds. This is quite a
lot simpler, but the main reason for this patch is that I want to run
a pass over assignments early. The idea being to control ld
expression behaviour by a magic assignment in a linker script. One of
the benefits is that --defsym is restored to acting at the point it is
used on the command line, for example
--defsym x=1 some_script --defsym x=2 some_script
could control actions in "some_script". This positional behaviour
will also affect extraction of objects from archives.
ld/
PR ld/12001
Revert 2010-11-03 Nick Clifton
* ldlang.c (ldlang_def_chain_list): Delete.
(insert_defined, ldlang_add_def, lang_place_defineds): Delete.
(lang_process): Don't call lang_place_defineds.
(lang_add_assignment): Don't do anything special for --defsym.
* ldexp.h (struct ldexp_control): Add uses_defined.
(exp_fold_tree_no_dot): Declare.
* ldexp.c (exp_fold_tree): Clear uses_defined.
(exp_fold_tree_no_dot): Likewise. Make global.
(fold_name <DEFINED>): Set uses_defined.
(exp_fold_tree_1 <etree_assign>): Define symbol during first phase
even when the value being assigned isn't valid.
* ldlang.c (open_input_bfds): Process assignment statements.
(lang_process): Bump lang_statement_iteration.
(scan_for_self_assignment): Formatting.
(print_assignment): Style.
ld/testsuite/
* ld-scripts/default-script2.d: Revert 2010-11-03 change.
Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.87
diff -u -p -r1.87 ldexp.c
--- ld/ldexp.c 1 Oct 2010 08:15:41 -0000 1.87
+++ ld/ldexp.c 20 Dec 2010 04:44:33 -0000
@@ -44,7 +44,6 @@
#include "safe-ctype.h"
static void exp_fold_tree_1 (etree_type *);
-static void exp_fold_tree_no_dot (etree_type *);
static bfd_vma align_n (bfd_vma, bfd_vma);
segment_type *segments;
@@ -504,6 +503,7 @@ fold_name (etree_type *tree)
break;
case DEFINED:
+ expld.uses_defined = TRUE;
if (expld.phase == lang_first_phase_enum)
lang_track_definedness (tree->name.name);
else
@@ -802,7 +802,9 @@ exp_fold_tree_1 (etree_type *tree)
}
exp_fold_tree_1 (tree->assign.src);
- if (expld.result.valid_p)
+ if (expld.result.valid_p
+ || (expld.phase == lang_first_phase_enum
+ && !expld.uses_defined))
{
if (h == NULL)
{
@@ -872,15 +874,17 @@ exp_fold_tree (etree_type *tree, asectio
expld.dot = *dotp;
expld.dotp = dotp;
expld.section = current_section;
+ expld.uses_defined = FALSE;
exp_fold_tree_1 (tree);
}
-static void
+void
exp_fold_tree_no_dot (etree_type *tree)
{
expld.dot = 0;
expld.dotp = NULL;
expld.section = bfd_abs_section_ptr;
+ expld.uses_defined = FALSE;
exp_fold_tree_1 (tree);
}
Index: ld/ldexp.h
===================================================================
RCS file: /cvs/src/src/ld/ldexp.h,v
retrieving revision 1.23
diff -u -p -r1.23 ldexp.h
--- ld/ldexp.h 11 Sep 2009 15:27:35 -0000 1.23
+++ ld/ldexp.h 20 Dec 2010 04:44:33 -0000
@@ -127,6 +127,7 @@ struct ldexp_control {
/* Working results. */
etree_value_type result;
bfd_vma dot;
+ bfd_boolean uses_defined;
/* Current dot and section passed to ldexp folder. */
bfd_vma *dotp;
@@ -173,6 +174,8 @@ etree_type *exp_relop
(asection *, bfd_vma);
void exp_fold_tree
(etree_type *, asection *, bfd_vma *);
+void exp_fold_tree_no_dot
+ (etree_type *);
etree_type *exp_binop
(int, etree_type *, etree_type *);
etree_type *exp_trinop
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.353
diff -u -p -r1.353 ldlang.c
--- ld/ldlang.c 15 Dec 2010 14:56:37 -0000 1.353
+++ ld/ldlang.c 20 Dec 2010 04:44:36 -0000
@@ -3249,6 +3249,9 @@ open_input_bfds (lang_statement_union_ty
}
}
break;
+ case lang_assignment_statement_enum:
+ exp_fold_tree_no_dot (s->assignment_statement.exp);
+ break;
default:
break;
}
@@ -3395,65 +3398,6 @@ lang_place_undefineds (void)
insert_undefined (ptr->name);
}
-typedef struct bfd_sym_chain ldlang_def_chain_list_type;
-
-static ldlang_def_chain_list_type ldlang_def_chain_list_head;
-
-/* Insert NAME as defined in the symbol table. */
-
-static void
-insert_defined (const char *name)
-{
- struct bfd_link_hash_entry *h;
-
- h = bfd_link_hash_lookup (link_info.hash, name, TRUE, FALSE, TRUE);
- if (h == NULL)
- einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
- if (h->type == bfd_link_hash_new
- || h->type == bfd_link_hash_undefined
- || h->type == bfd_link_hash_undefweak)
- {
- h->type = bfd_link_hash_defined;
- h->u.def.section = bfd_abs_section_ptr;
- h->u.def.value = 0;
- }
-}
-
-/* Like lang_add_undef, but this time for symbols defined on the
- command line. */
-
-static void
-ldlang_add_def (const char *const name)
-{
- if (link_info.output_bfd != NULL)
- insert_defined (xstrdup (name));
- else
- {
- ldlang_def_chain_list_type *new_def;
-
- new_def = (ldlang_def_chain_list_type *) stat_alloc (sizeof (*new_def));
- new_def->next = ldlang_def_chain_list_head.next;
- ldlang_def_chain_list_head.next = new_def;
-
- new_def->name = xstrdup (name);
- }
-}
-
-/* Run through the list of defineds created above and place them
- into the linker hash table as defined symbols belonging to the
- script file. */
-
-static void
-lang_place_defineds (void)
-{
- ldlang_def_chain_list_type *ptr;
-
- for (ptr = ldlang_def_chain_list_head.next;
- ptr != NULL;
- ptr = ptr->next)
- insert_defined (ptr->name);
-}
-
/* Check for all readonly or some readwrite sections. */
static void
@@ -3982,12 +3926,12 @@ scan_for_self_assignment (const char * d
switch (rhs->type.node_class)
{
case etree_binary:
- return scan_for_self_assignment (dst, rhs->binary.lhs)
- || scan_for_self_assignment (dst, rhs->binary.rhs);
+ return (scan_for_self_assignment (dst, rhs->binary.lhs)
+ || scan_for_self_assignment (dst, rhs->binary.rhs));
case etree_trinary:
- return scan_for_self_assignment (dst, rhs->trinary.lhs)
- || scan_for_self_assignment (dst, rhs->trinary.rhs);
+ return (scan_for_self_assignment (dst, rhs->trinary.lhs)
+ || scan_for_self_assignment (dst, rhs->trinary.rhs));
case etree_assign:
case etree_provided:
@@ -4042,7 +3986,7 @@ print_assignment (lang_assignment_statem
is_dot = (dst[0] == '.' && dst[1] == 0);
tree = assignment->exp->assign.src;
- computation_is_valid = is_dot || (scan_for_self_assignment (dst, tree) == FALSE);
+ computation_is_valid = is_dot || !scan_for_self_assignment (dst, tree);
}
osec = output_section->bfd_section;
@@ -6461,7 +6405,6 @@ lang_process (void)
/* Add to the hash table all undefineds on the command line. */
lang_place_undefineds ();
- lang_place_defineds ();
if (!bfd_section_already_linked_table_init ())
einfo (_("%P%F: Failed to create hash table\n"));
@@ -6523,6 +6466,7 @@ lang_process (void)
/* Run through the contours of the script and attach input sections
to the correct output sections. */
+ lang_statement_iteration++;
map_input_to_output_sections (statement_list.head, NULL, NULL);
process_insert_statements ();
@@ -6746,10 +6690,6 @@ lang_add_assignment (etree_type *exp)
{
lang_assignment_statement_type *new_stmt;
- extern int parsing_defsym;
- if (parsing_defsym)
- ldlang_add_def (exp->assign.dst);
-
new_stmt = new_stat (lang_assignment_statement, stat_ptr);
new_stmt->exp = exp;
return new_stmt;
Index: ld/testsuite/ld-scripts/default-script2.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-scripts/default-script2.d,v
retrieving revision 1.4
diff -u -p -r1.4 default-script2.d
--- ld/testsuite/ld-scripts/default-script2.d 3 Nov 2010 17:18:22 -0000 1.4
+++ ld/testsuite/ld-scripts/default-script2.d 20 Dec 2010 04:44:38 -0000
@@ -5,5 +5,5 @@
#...
0*8000000 . _START
#...
-0*8000000 T text
+0*9000000 T text
#pass
--
Alan Modra
Australia Development Lab, IBM