• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisãocd5b2babea487b0a71a14b593af98330efd8d73e (tree)
Hora2017-11-28 21:26:59
AutorAlan Modra <amodra@gmai...>
CommiterAlan Modra

Mensagem de Log

Copying symbol type in ld script assignments

There is a call to update_definedness between code that evaluates an
assignment expression value and code that transfers symbol
attributes. When script assignment expressions contain DEFINED, that
can mean the wrong symbol type is copied. This patch tracks symbols
read during expression evaluation, rather than examining the
expression and re-evaluating conditionals. Not only does this
simplify the code, it also means ld can now copy symbol types in more
complex expressions.

An unfortunate side effect of copying symbol type for more complex
expressions affects mmix, which uses

PROVIDE (Main = DEFINED (Main) ? Main : (DEFINED (_start) ? _start : _start.));

in a default script. So now _start or _start. symbol type may be
copied, losing the function type specially set up for Main. This can
be avoided by making bfd_copy_link_hash_symbol_type do nothing for
mmix.

bfd/
* elf64-mmix.c (bfd_elf64_bfd_copy_link_hash_symbol_type): Define.
ld/
* ldexp.h (struct ldexp_control): Add "assign_src".
* ldexp.c (fold_trinary): Save and restore assign_src around
condition evaluation.
(fold_name <NAME>): Set expld.assign_src.
(try_copy_symbol_type): Delete.
(exp_fold_tree_1): Set symbol type using expld.assign_src.

Mudança Sumário

Diff

--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,7 @@
1+2017-11-28 Alan Modra <amodra@gmail.com>
2+
3+ * elf64-mmix.c (bfd_elf64_bfd_copy_link_hash_symbol_type): Define.
4+
15 2017-11-28 H.J. Lu <hongjiu.lu@intel.com>
26
37 PR ld/22502
--- a/bfd/elf64-mmix.c
+++ b/bfd/elf64-mmix.c
@@ -2908,6 +2908,9 @@ mmix_elf_relax_section (bfd *abfd,
29082908 #define elf_backend_omit_section_dynsym \
29092909 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
29102910
2911+#define bfd_elf64_bfd_copy_link_hash_symbol_type \
2912+ _bfd_generic_copy_link_hash_symbol_type
2913+
29112914 #define bfd_elf64_bfd_is_local_label_name \
29122915 mmix_elf_is_local_label_name
29132916
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
1+2017-11-28 Alan Modra <amodra@gmail.com>
2+
3+ * ldexp.h (struct ldexp_control): Add "assign_src".
4+ * ldexp.c (fold_trinary): Save and restore assign_src around
5+ condition evaluation.
6+ (fold_name <NAME>): Set expld.assign_src.
7+ (try_copy_symbol_type): Delete.
8+ (exp_fold_tree_1): Set symbol type using expld.assign_src.
9+
110 2017-11-28 H.J. Lu <hongjiu.lu@intel.com>
211
312 PR ld/22502
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -673,7 +673,10 @@ fold_binary (etree_type *tree)
673673 static void
674674 fold_trinary (etree_type *tree)
675675 {
676+ struct bfd_link_hash_entry *save = expld.assign_src;
677+
676678 exp_fold_tree_1 (tree->trinary.cond);
679+ expld.assign_src = save;
677680 if (expld.result.valid_p)
678681 exp_fold_tree_1 (expld.result.value
679682 ? tree->trinary.lhs
@@ -790,6 +793,10 @@ fold_name (etree_type *tree)
790793 if (h->u.undef.next == NULL && h != link_info.hash->undefs_tail)
791794 bfd_link_add_undef (link_info.hash, h);
792795 }
796+ if (expld.assign_src == NULL)
797+ expld.assign_src = h;
798+ else
799+ expld.assign_src = (struct bfd_link_hash_entry *) 0 - 1;
793800 }
794801 break;
795802
@@ -1001,19 +1008,6 @@ is_align_conditional (const etree_type *tree)
10011008 return FALSE;
10021009 }
10031010
1004-/* Subroutine of exp_fold_tree_1 for copying a symbol type. */
1005-
1006-static void
1007-try_copy_symbol_type (struct bfd_link_hash_entry *h, etree_type *src)
1008-{
1009- struct bfd_link_hash_entry *hsrc;
1010-
1011- hsrc = bfd_link_hash_lookup (link_info.hash, src->name.name,
1012- FALSE, FALSE, TRUE);
1013- if (hsrc != NULL)
1014- bfd_copy_link_hash_symbol_type (link_info.output_bfd, h, hsrc);
1015-}
1016-
10171011 static void
10181012 exp_fold_tree_1 (etree_type *tree)
10191013 {
@@ -1162,6 +1156,7 @@ exp_fold_tree_1 (etree_type *tree)
11621156 }
11631157
11641158 expld.assign_name = tree->assign.dst;
1159+ expld.assign_src = NULL;
11651160 exp_fold_tree_1 (tree->assign.src);
11661161 /* expld.assign_name remaining equal to tree->assign.dst
11671162 below indicates the evaluation of tree->assign.src did
@@ -1209,27 +1204,15 @@ exp_fold_tree_1 (etree_type *tree)
12091204 if (tree->type.node_class == etree_provide)
12101205 tree->type.node_class = etree_provided;
12111206
1212- /* Copy the symbol type if this is a simple assignment of
1213- one symbol to another. Also, handle the case of a foldable
1214- ternary conditional with names on either side. */
1215- if (tree->assign.src->type.node_class == etree_name)
1216- try_copy_symbol_type (h, tree->assign.src);
1217- else if (tree->assign.src->type.node_class == etree_trinary)
1218- {
1219- exp_fold_tree_1 (tree->assign.src->trinary.cond);
1220- if (expld.result.valid_p)
1221- {
1222- if (expld.result.value
1223- && tree->assign.src->trinary.lhs->type.node_class
1224- == etree_name)
1225- try_copy_symbol_type (h, tree->assign.src->trinary.lhs);
1226-
1227- if (!expld.result.value
1228- && tree->assign.src->trinary.rhs->type.node_class
1229- == etree_name)
1230- try_copy_symbol_type (h, tree->assign.src->trinary.rhs);
1231- }
1232- }
1207+ /* Copy the symbol type if this is an expression only
1208+ referencing a single symbol. (If the expression
1209+ contains ternary conditions, ignoring symbols on
1210+ false branches.) */
1211+ if (expld.result.valid_p
1212+ && expld.assign_src != NULL
1213+ && expld.assign_src != (struct bfd_link_hash_entry *) 0 - 1)
1214+ bfd_copy_link_hash_symbol_type (link_info.output_bfd, h,
1215+ expld.assign_src);
12331216 }
12341217 else if (expld.phase == lang_final_phase_enum)
12351218 {
--- a/ld/ldexp.h
+++ b/ld/ldexp.h
@@ -163,6 +163,11 @@ struct ldexp_control {
163163 does the false branch of a trinary expression. */
164164 const char *assign_name;
165165
166+ /* If evaluating an assignment, the source if it is an expression
167+ referencing single etree_name NAME, or a trinary expression where
168+ the true branch references a single etree_name NAME. */
169+ struct bfd_link_hash_entry *assign_src;
170+
166171 /* Working results. */
167172 etree_value_type result;
168173 bfd_vma dot;