From fbbb9ac52fc2cca745356239a4a1e7cd11539c11 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Thu, 17 Feb 2005 20:57:01 +0000 Subject: [PATCH] * ldexp.c (assigning_to_dot): New global flag. (fold_name): If assigning_to_dot is true, object immediately to an undefined symbol. (exp_fold_tree): Set and clear assigning_to_dot around the recursive call to exp_fold_tree to process the right-hand side of an assignment to the location counter. testsuite: * ld-scripts/align.exp: Rename existing "ALIGN" test to "align1". Add dump tests "align2a", "align2b", "align2c". * ld-scripts/align2.t, ld-scripts/align2a.s, ld-scripts/align2a.d * ld-scripts/align2b.s, ld-scripts/align2b.d * ld-scripts/align2c.s, ld-scripts/align2c.d: New files. --- ld/ChangeLog | 13 +++++++++++-- ld/ldexp.c | 13 ++++++++++--- ld/testsuite/ChangeLog | 12 ++++++++++-- ld/testsuite/ld-scripts/align.exp | 6 +++++- ld/testsuite/ld-scripts/align2.t | 6 ++++++ ld/testsuite/ld-scripts/align2a.d | 13 +++++++++++++ ld/testsuite/ld-scripts/align2a.s | 4 ++++ ld/testsuite/ld-scripts/align2b.d | 13 +++++++++++++ ld/testsuite/ld-scripts/align2b.s | 4 ++++ ld/testsuite/ld-scripts/align2c.d | 2 ++ ld/testsuite/ld-scripts/align2c.s | 4 ++++ 11 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 ld/testsuite/ld-scripts/align2.t create mode 100644 ld/testsuite/ld-scripts/align2a.d create mode 100644 ld/testsuite/ld-scripts/align2a.s create mode 100644 ld/testsuite/ld-scripts/align2b.d create mode 100644 ld/testsuite/ld-scripts/align2b.s create mode 100644 ld/testsuite/ld-scripts/align2c.d create mode 100644 ld/testsuite/ld-scripts/align2c.s diff --git a/ld/ChangeLog b/ld/ChangeLog index 10f2c952f8f..8214cfc513b 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2005-02-17 Zack Weinberg + + * ldexp.c (assigning_to_dot): New global flag. + (fold_name): If assigning_to_dot is true, object immediately to + an undefined symbol. + (exp_fold_tree): Set and clear assigning_to_dot around the + recursive call to exp_fold_tree to process the right-hand side + of an assignment to the location counter. + 2005-02-17 Paul Brook * scripttempl/armbpabi.sc: Add dummy name to version block. @@ -14,7 +23,7 @@ not defined. (gld${EMULATION_NAME}_parse_ld_so_conf_include): Do not use glob if HAVE_GLOB is not defined. - + 2005-02-16 Kaz Kojima * emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Define @@ -32,7 +41,7 @@ * ldlex.l (YY_NO_UNPUT): Define so that the yy_unput function is not declared. It is not used and its presence causes a compile time warning. - + 2005-02-11 Zack Weinberg * emultempl/elf32.em (gld${EMULATION_NAME}_stat_needed): diff --git a/ld/ldexp.c b/ld/ldexp.c index 3335e37dc37..5ac1162ffc9 100644 --- a/ld/ldexp.c +++ b/ld/ldexp.c @@ -50,6 +50,9 @@ struct exp_data_seg exp_data_seg; segment_type *segments; +/* Principally used for diagnostics. */ +static bfd_boolean assigning_to_dot = FALSE; + /* Print the string representation of the given token. Surround it with spaces if INFIX_P is TRUE. */ @@ -596,7 +599,8 @@ fold_name (etree_type *tree, } } } - else if (allocation_done == lang_final_phase_enum) + else if (allocation_done == lang_final_phase_enum + || assigning_to_dot) einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"), tree->name.name); else if (h->type == bfd_link_hash_new) @@ -755,10 +759,13 @@ exp_fold_tree (etree_type *tree, || (allocation_done == lang_final_phase_enum && current_section == abs_output_section)) { + /* Notify the folder that this is an assignment to dot. */ + assigning_to_dot = TRUE; result = exp_fold_tree (tree->assign.src, current_section, - allocation_done, dot, - dotp); + allocation_done, dot, dotp); + assigning_to_dot = FALSE; + if (! result.valid_p) einfo (_("%F%S invalid assignment to location counter\n")); else diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 376e44dc8e3..a827a376828 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2005-02-17 Zack Weinberg + + * ld-scripts/align.exp: Rename existing "ALIGN" test to "align1". + Add dump tests "align2a", "align2b", "align2c". + * ld-scripts/align2.t, ld-scripts/align2a.s, ld-scripts/align2a.d + * ld-scripts/align2b.s, ld-scripts/align2b.d + * ld-scripts/align2c.s, ld-scripts/align2c.d: New files. + 2005-02-17 Alexandre Oliva * ld-frv/fdpic-static-6.d: Update. @@ -5,7 +13,7 @@ spelling of errors and warnings. 2005-02-15 Nigel Stephens - Maciej W. Rozycki + Maciej W. Rozycki * ld-mips-elf/mips16-hilo.d: New test for the R_MIPS16_HI16 and R_MIPS16_LO16 relocs. @@ -216,7 +224,7 @@ 2004-12-21 Tomer Levi - * ld-crx/reloc-abs32.d: Update reference file according + * ld-crx/reloc-abs32.d: Update reference file according to disassembler printing method. * ld-crx/reloc-rel16.d: Likewise. * ld-crx/reloc-rel24.d: Likewise. diff --git a/ld/testsuite/ld-scripts/align.exp b/ld/testsuite/ld-scripts/align.exp index f7664ca4e61..dbaaaf363a1 100644 --- a/ld/testsuite/ld-scripts/align.exp +++ b/ld/testsuite/ld-scripts/align.exp @@ -22,7 +22,7 @@ if [istarget "rs6000-*-aix*"] { return } -set testname "ALIGN" +set testname "align1" if ![ld_assemble $as $srcdir/$subdir/align.s tmpdir/align.o] { unresolved $testname @@ -34,3 +34,7 @@ if ![ld_simple_link $ld tmpdir/align "-T $srcdir/$subdir/align.t tmpdir/align.o" } else { pass $testname } + +run_dump_test align2a +run_dump_test align2b +run_dump_test align2c diff --git a/ld/testsuite/ld-scripts/align2.t b/ld/testsuite/ld-scripts/align2.t new file mode 100644 index 00000000000..73818a8f163 --- /dev/null +++ b/ld/testsuite/ld-scripts/align2.t @@ -0,0 +1,6 @@ +SECTIONS +{ + .text : {*(.text)} + . = ALIGN(data_align); + .data : {*(.data)} +} diff --git a/ld/testsuite/ld-scripts/align2a.d b/ld/testsuite/ld-scripts/align2a.d new file mode 100644 index 00000000000..2c5df455cbf --- /dev/null +++ b/ld/testsuite/ld-scripts/align2a.d @@ -0,0 +1,13 @@ +# ld: --defsym data_align=16 -T align2.t +# objdump: --section-headers + +[^:]+: +file format.* + +Sections: +Idx +Name +Size +VMA +LMA +File +off +Algn + +0 +\.text +00000004 +00000000 +00000000 +00001000 +2\*\*2 + +CONTENTS, +ALLOC, +LOAD, +READONLY, +CODE + +1 +\.data +00000004 +00000010 +00000010 +00001010 +2\*\*2 + +CONTENTS, +ALLOC, +LOAD, +DATA + +2 +\.bss +00000000 +00000014 +00000014 +00001014 +2\*\*2 + +ALLOC diff --git a/ld/testsuite/ld-scripts/align2a.s b/ld/testsuite/ld-scripts/align2a.s new file mode 100644 index 00000000000..4e56d4a8e53 --- /dev/null +++ b/ld/testsuite/ld-scripts/align2a.s @@ -0,0 +1,4 @@ + .text + .long 0 + .data + .long 0x12345678 diff --git a/ld/testsuite/ld-scripts/align2b.d b/ld/testsuite/ld-scripts/align2b.d new file mode 100644 index 00000000000..c74d3ab5dcf --- /dev/null +++ b/ld/testsuite/ld-scripts/align2b.d @@ -0,0 +1,13 @@ +# ld: --defsym data_align=32 -T align2.t +# objdump: --section-headers + +[^:]+: +file +format.* + +Sections: +Idx +Name +Size +VMA +LMA +File off +Algn + +0 +\.text +00000004 +00000000 +00000000 +00001000 +2\*\*2 + +CONTENTS, +ALLOC, +LOAD, +READONLY, +CODE + +1 +\.data +00000004 +00000020 +00000020 +00001020 +2\*\*2 + +CONTENTS, +ALLOC, +LOAD, +DATA + +2 +\.bss +00000000 +00000024 +00000024 +00001024 +2\*\*2 + +ALLOC diff --git a/ld/testsuite/ld-scripts/align2b.s b/ld/testsuite/ld-scripts/align2b.s new file mode 100644 index 00000000000..4e56d4a8e53 --- /dev/null +++ b/ld/testsuite/ld-scripts/align2b.s @@ -0,0 +1,4 @@ + .text + .long 0 + .data + .long 0x12345678 diff --git a/ld/testsuite/ld-scripts/align2c.d b/ld/testsuite/ld-scripts/align2c.d new file mode 100644 index 00000000000..16a4245be90 --- /dev/null +++ b/ld/testsuite/ld-scripts/align2c.d @@ -0,0 +1,2 @@ +# ld: -T align2.t +# error: undefined symbol.*in expression diff --git a/ld/testsuite/ld-scripts/align2c.s b/ld/testsuite/ld-scripts/align2c.s new file mode 100644 index 00000000000..4e56d4a8e53 --- /dev/null +++ b/ld/testsuite/ld-scripts/align2c.s @@ -0,0 +1,4 @@ + .text + .long 0 + .data + .long 0x12345678 -- 2.30.2