From 0786bd3c43fc3e8860f09fe5af7a9b3cf2564f58 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Wed, 22 Feb 2012 16:27:31 +0000 Subject: [PATCH] PR ld/13683 * ldlang.c (lang_process): Rerun lang_do_assignments before starting garbage collection. * ldexp.c (fold_name): Generate a reloc for defined symbols found without an associated output section during the mark phase. (exp_fold_tree_1): Continue processing an expression, even if we are unable to fold it, if we are in the first two evaluation phases. * ldexp.h (enum lang_phase_type): Add descriptions of the phases. * ld-gc/pr13683.c: New test source file. * ld-gc/pr13683.d: New test control and output file. * ld-gc/gc.exp: Run the pr13683 test. * ld-cris/tls-gc-68: Update expected symbol table dump. * ld-cris/tls-gc-69: Likewise. * ld-cris/tls-gc-70: Likewise. * ld-cris/tls-gc-71: Likewise. * ld-cris/tls-gc-75: Likewise. * ld-cris/tls-gc-76.d: Likewise. * ld-cris/tls-gc-79.d: Likewise. --- ld/ChangeLog | 9 +++++++++ ld/ldexp.c | 6 ++++-- ld/ldexp.h | 10 +++++++++- ld/ldlang.c | 5 +++++ ld/testsuite/ChangeLog | 15 +++++++++++++++ ld/testsuite/ld-cris/tls-gc-68.d | 6 +++--- ld/testsuite/ld-cris/tls-gc-69.d | 6 +++--- ld/testsuite/ld-cris/tls-gc-70.d | 6 +++--- ld/testsuite/ld-cris/tls-gc-71.d | 6 +++--- ld/testsuite/ld-cris/tls-gc-75.d | 6 +++--- ld/testsuite/ld-cris/tls-gc-76.d | 6 +++--- ld/testsuite/ld-cris/tls-gc-79.d | 6 +++--- ld/testsuite/ld-gc/gc.exp | 5 +++++ ld/testsuite/ld-gc/pr13683.c | 28 ++++++++++++++++++++++++++++ ld/testsuite/ld-gc/pr13683.d | 12 ++++++++++++ 15 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 ld/testsuite/ld-gc/pr13683.c create mode 100644 ld/testsuite/ld-gc/pr13683.d diff --git a/ld/ChangeLog b/ld/ChangeLog index 60b9d4a08..1554e3538 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2012-02-22 Alan Modra + + PR ld/13683 + * ldlang.c (lang_process): Rerun lang_do_assignments before + starting garbage collection. + * ldexp.c (fold_name): Generate a reloc for defined symbols + found without an associated output section during the mark phase. + * ldexp.h (enum lang_phase_type): Add descriptions of the phases. + 2012-02-19 Kai Tietz * deffilep.y (cmp_import_elem): Sort first by module name. diff --git a/ld/ldexp.c b/ld/ldexp.c index 293d28a98..bf0e00b17 100644 --- a/ld/ldexp.c +++ b/ld/ldexp.c @@ -590,7 +590,9 @@ fold_name (etree_type *tree) output_section = h->u.def.section->output_section; if (output_section == NULL) { - if (expld.phase != lang_mark_phase_enum) + if (expld.phase == lang_mark_phase_enum) + new_rel (h->u.def.value, h->u.def.section); + else einfo (_("%X%S: unresolvable symbol `%s'" " referenced in expression\n"), tree, tree->name.name); @@ -882,7 +884,7 @@ exp_fold_tree_1 (etree_type *tree) exp_fold_tree_1 (tree->assign.src); if (expld.result.valid_p - || (expld.phase == lang_first_phase_enum + || (expld.phase <= lang_mark_phase_enum && tree->type.node_class == etree_assign && tree->assign.hidden)) { diff --git a/ld/ldexp.h b/ld/ldexp.h index fc7485fc5..586dd13f6 100644 --- a/ld/ldexp.h +++ b/ld/ldexp.h @@ -94,11 +94,19 @@ typedef union etree_union { } assert_s; } etree_type; -typedef enum { +/* Expression evaluation control. */ +typedef enum +{ + /* Parsing linker script. Will only return "valid" for expressions + that evaluate to a constant. */ lang_first_phase_enum, + /* Prior to section sizing. */ lang_mark_phase_enum, + /* During section sizing. */ lang_allocating_phase_enum, + /* During assignment of symbol values when relaxation in progress. */ lang_assigning_phase_enum, + /* Final assignment of symbol values. */ lang_final_phase_enum } lang_phase_type; diff --git a/ld/ldlang.c b/ld/ldlang.c index 5f064182d..1bffa937c 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -6650,6 +6650,11 @@ lang_process (void) files. */ ldctor_build_sets (); + /* PR 13683: We must rerun the assignments prior to running garbage + collection in order to make sure that all symbol aliases are resolved. */ + lang_do_assignments (lang_mark_phase_enum); + expld.phase = lang_first_phase_enum; + /* Remove unreferenced sections if asked to. */ lang_gc_sections (); diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 260a20170..5845e8c57 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,18 @@ +2012-02-22 Nick Clifton + + PR ld/13683 + * ld-gc/pr13683.c: New test source file. + * ld-gc/pr13683.d: New test control and output file. + * ld-gc/gc.exp: Run the pr13683 test. + + * ld-cris/tls-gc-68: Update expected symbol table dump. + * ld-cris/tls-gc-69: Likewise. + * ld-cris/tls-gc-70: Likewise. + * ld-cris/tls-gc-71: Likewise. + * ld-cris/tls-gc-75: Likewise. + * ld-cris/tls-gc-76.d: Likewise. + * ld-cris/tls-gc-79.d: Likewise. + 2012-02-20 Thomas Schwinge * ld-elf/comm-data.exp: Run for *-*-gnu*. diff --git a/ld/testsuite/ld-cris/tls-gc-68.d b/ld/testsuite/ld-cris/tls-gc-68.d index 60fcc3be1..4b639913c 100644 --- a/ld/testsuite/ld-cris/tls-gc-68.d +++ b/ld/testsuite/ld-cris/tls-gc-68.d @@ -21,11 +21,11 @@ private flags = 0: SYMBOL TABLE: 0+80074 l d .text 0+ .text 0+82078 l d .got 0+ .got +0+82084 l \*ABS\* 0+ __bss_start +0+82084 l \*ABS\* 0+ _edata 0+82078 l O .got 0+ _GLOBAL_OFFSET_TABLE_ +0+820a0 l \*ABS\* 0+ _end 0+80074 g .text 0+ _start -0+82084 g \*ABS\* 0+ __bss_start -0+82084 g \*ABS\* 0+ _edata -0+820a0 g \*ABS\* 0+ _end Contents of section .text: 80074 41b20+ .* diff --git a/ld/testsuite/ld-cris/tls-gc-69.d b/ld/testsuite/ld-cris/tls-gc-69.d index e547ba4aa..f14deec52 100644 --- a/ld/testsuite/ld-cris/tls-gc-69.d +++ b/ld/testsuite/ld-cris/tls-gc-69.d @@ -22,11 +22,11 @@ private flags = 0: SYMBOL TABLE: 0+80074 l d .text 0+ .text 0+82078 l d .got 0+ .got +0+82084 l \*ABS\* 0+ __bss_start +0+82084 l \*ABS\* 0+ _edata 0+82078 l O .got 0+ _GLOBAL_OFFSET_TABLE_ +0+820a0 l \*ABS\* 0+ _end 0+80074 g .text 0+ _start -0+82084 g \*ABS\* 0+ __bss_start -0+82084 g \*ABS\* 0+ _edata -0+820a0 g \*ABS\* 0+ _end Contents of section .text: 80074 41b20+ .* diff --git a/ld/testsuite/ld-cris/tls-gc-70.d b/ld/testsuite/ld-cris/tls-gc-70.d index d8d5324f5..dbeb9d070 100644 --- a/ld/testsuite/ld-cris/tls-gc-70.d +++ b/ld/testsuite/ld-cris/tls-gc-70.d @@ -22,11 +22,11 @@ private flags = 0: SYMBOL TABLE: 0+80074 l d .text 0+ .text 0+82078 l d .got 0+ .got +0+82084 l \*ABS\* 0+ __bss_start +0+82084 l \*ABS\* 0+ _edata 0+82078 l O .got 0+ _GLOBAL_OFFSET_TABLE_ +0+820a0 l \*ABS\* 0+ _end 0+80074 g .text 0+ _start -0+82084 g \*ABS\* 0+ __bss_start -0+82084 g \*ABS\* 0+ _edata -0+820a0 g \*ABS\* 0+ _end Contents of section .text: 80074 41b20+ .* diff --git a/ld/testsuite/ld-cris/tls-gc-71.d b/ld/testsuite/ld-cris/tls-gc-71.d index 3ee73fc3a..29745de73 100644 --- a/ld/testsuite/ld-cris/tls-gc-71.d +++ b/ld/testsuite/ld-cris/tls-gc-71.d @@ -17,11 +17,11 @@ DYNAMIC SYMBOL TABLE: 0+18e l d .text 0+ .text 0+2194 l d .tdata 0+ .tdata +0+2280 l D \*ABS\* 0+ __bss_start +0+2280 l D \*ABS\* 0+ _edata +0+2280 l D \*ABS\* 0+ _end 0+18e g DF .text 0+2 _init -0+2280 g D \*ABS\* 0+ __bss_start 0+ g D .tdata 0+80 tls128 -0+2280 g D \*ABS\* 0+ _edata -0+2280 g D \*ABS\* 0+ _end DYNAMIC RELOCATION RECORDS \(none\) #... diff --git a/ld/testsuite/ld-cris/tls-gc-75.d b/ld/testsuite/ld-cris/tls-gc-75.d index 2f4257e16..b1c77bfc6 100644 --- a/ld/testsuite/ld-cris/tls-gc-75.d +++ b/ld/testsuite/ld-cris/tls-gc-75.d @@ -24,11 +24,11 @@ private flags = 0: SYMBOL TABLE: 0+80074 l d .text 0+ .text 0+82078 l d .got 0+ .got +0+82084 l \*ABS\* 0+ __bss_start +0+82084 l \*ABS\* 0+ _edata 0+82078 l O .got 0+ _GLOBAL_OFFSET_TABLE_ +0+820a0 l \*ABS\* 0+ _end 0+80074 g .text 0+ _start -0+82084 g \*ABS\* 0+ __bss_start -0+82084 g \*ABS\* 0+ _edata -0+820a0 g \*ABS\* 0+ _end Contents of section .text: 80074 41b20+ .* diff --git a/ld/testsuite/ld-cris/tls-gc-76.d b/ld/testsuite/ld-cris/tls-gc-76.d index f3c78df68..52387275e 100644 --- a/ld/testsuite/ld-cris/tls-gc-76.d +++ b/ld/testsuite/ld-cris/tls-gc-76.d @@ -23,11 +23,11 @@ SYMBOL TABLE: 0+82080 l d .got 0+ .got 0+82090 l d .data 0+ .data 0+82090 l O .data 0+4 gc76var +0+82094 l \*ABS\* 0+ __bss_start +0+82094 l \*ABS\* 0+ _edata 0+82080 l O .got 0+ _GLOBAL_OFFSET_TABLE_ +0+820a0 l \*ABS\* 0+ _end 0+80074 g .text 0+ _start -0+82094 g \*ABS\* 0+ __bss_start -0+82094 g \*ABS\* 0+ _edata -0+820a0 g \*ABS\* 0+ _end 0+80078 g F .text 0+6 gc76fn Contents of section .text: diff --git a/ld/testsuite/ld-cris/tls-gc-79.d b/ld/testsuite/ld-cris/tls-gc-79.d index 210f4789e..eb3646d65 100644 --- a/ld/testsuite/ld-cris/tls-gc-79.d +++ b/ld/testsuite/ld-cris/tls-gc-79.d @@ -22,11 +22,11 @@ private flags = 0: SYMBOL TABLE: 0+80074 l d .text 0+ .text 0+82078 l d .got 0+ .got +0+82084 l \*ABS\* 0+ __bss_start +0+82084 l \*ABS\* 0+ _edata 0+82078 l O .got 0+ _GLOBAL_OFFSET_TABLE_ +0+820a0 l \*ABS\* 0+ _end 0+80074 g .text 0+ _start -0+82084 g \*ABS\* 0+ __bss_start -0+82084 g \*ABS\* 0+ _edata -0+820a0 g \*ABS\* 0+ _end Contents of section .text: 80074 41b20+ .* diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp index 57f0ec3f7..d8d34fa6e 100644 --- a/ld/testsuite/ld-gc/gc.exp +++ b/ld/testsuite/ld-gc/gc.exp @@ -120,3 +120,8 @@ if { [is_remote host] || [which $CC] != 0 } { run_dump_test "pr11218" } } + +if { [is_remote host] || [which $CC] != 0 } { + ld_compile "$CC $CFLAGS $cflags" $srcdir/$subdir/pr13683.c tmpdir/pr13683.o + run_dump_test "pr13683" +} diff --git a/ld/testsuite/ld-gc/pr13683.c b/ld/testsuite/ld-gc/pr13683.c new file mode 100644 index 000000000..c585e06db --- /dev/null +++ b/ld/testsuite/ld-gc/pr13683.c @@ -0,0 +1,28 @@ +void foo(void); + +int main(void) +{ + foo (); + + for (;;) + ; +} + +int a; + +void foo1(void) +{ + a = 1; +} + +void foo2(void) +{ + a = 2; +} + +void foo3(void) +{ + a = 3; +} + + diff --git a/ld/testsuite/ld-gc/pr13683.d b/ld/testsuite/ld-gc/pr13683.d new file mode 100644 index 000000000..31aaee4d4 --- /dev/null +++ b/ld/testsuite/ld-gc/pr13683.d @@ -0,0 +1,12 @@ +#name: --gc-sections with --defsym +#source: dummy.s +#ld: --gc-sections -e main --defsym foo=foo2 tmpdir/pr13683.o +#nm: --format=bsd +#xfail: sh64*-*-* iq2000-*-* lm32-*-* epiphany-*-* mips64vr-*-* frv-*-* m32c-*-* rl78-*-* rx-*-* sh-*-* + +# Note - look for both "foo" and "foo2" being defined, non-zero function symbols + +#... +0+[1-9a-f]+[0-9a-f]*[ ]T[ ]_*foo +0+[1-9a-f]+[0-9a-f]*[ ]T[ ]_*foo2 +#... -- 2.11.4.GIT