From 88bd15396002102beedf49c87adee7b16c2bb409 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 20 Sep 2016 15:25:55 +0100 Subject: [PATCH] ld: Create test object files based on source file name When creating object files during testing, base the name of the object file on the name of the source file, rather than using dump0.o, dump1.o, etc. There's a few places where we have multiple source files with the same name but in different directories, in these cases, even after this change, we still add a numerical suffix to make the object file names unique. So if we have 'foo/src.s' and 'bar/src.s', we will create object files 'src.o' and 'src1.o'. Update the few tests that hard code the object file name into the expected test results. ld/ChangeLog: * testsuite/lib/ld-lib.exp (run_dump_test): Use object file names based on the original source file name. * testsuite/ld-discard/extern.d: Update object file names. * testsuite/ld-discard/start.d: Likewise. * testsuite/ld-discard/static.d: Likewise. * testsuite/ld-elf/orphan-8.map: Likewise. --- ld/ChangeLog | 9 +++++++++ ld/testsuite/ld-discard/extern.d | 2 +- ld/testsuite/ld-discard/start.d | 2 +- ld/testsuite/ld-discard/static.d | 2 +- ld/testsuite/ld-elf/orphan-8.map | 4 ++-- ld/testsuite/lib/ld-lib.exp | 22 ++++++++++++++++++++-- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 2d3bf34f3c7..3098b4cf75d 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2016-11-04 Andrew Burgess + + * testsuite/lib/ld-lib.exp (run_dump_test): Use object file names + based on the original source file name. + * testsuite/ld-discard/extern.d: Update object file names. + * testsuite/ld-discard/start.d: Likewise. + * testsuite/ld-discard/static.d: Likewise. + * testsuite/ld-elf/orphan-8.map: Likewise. + 2016-11-04 Andrew Burgess * testsuite/lib/ld-lib.exp (check_shared_lib_support): Add diff --git a/ld/testsuite/ld-discard/extern.d b/ld/testsuite/ld-discard/extern.d index 3075174c8e6..9932ebca440 100644 --- a/ld/testsuite/ld-discard/extern.d +++ b/ld/testsuite/ld-discard/extern.d @@ -1,6 +1,6 @@ #source: extern.s #ld: -T discard.ld -#error: .*data.* referenced in section `\.text' of tmpdir/dump0.o: defined in discarded section `\.data\.exit' of tmpdir/dump0.o +#error: .*data.* referenced in section `\.text' of tmpdir/extern.o: defined in discarded section `\.data\.exit' of tmpdir/extern.o #objdump: -p #xfail: d30v-*-* dlx-*-* i960-*-* pj*-*-* #xfail: m68hc12-*-* m6812-*-* diff --git a/ld/testsuite/ld-discard/start.d b/ld/testsuite/ld-discard/start.d index 8c4a43b6bda..d846bc736ae 100644 --- a/ld/testsuite/ld-discard/start.d +++ b/ld/testsuite/ld-discard/start.d @@ -1,7 +1,7 @@ #source: start.s #source: exit.s #ld: -T discard.ld -#error: `data' referenced in section `\.text' of tmpdir/dump0.o: defined in discarded section `\.data\.exit' of tmpdir/dump1.o +#error: `data' referenced in section `\.text' of tmpdir/start.o: defined in discarded section `\.data\.exit' of tmpdir/exit.o #objdump: -p #xfail: d30v-*-* dlx-*-* i960-*-* pj*-*-* #xfail: m68hc12-*-* m6812-*-* diff --git a/ld/testsuite/ld-discard/static.d b/ld/testsuite/ld-discard/static.d index 28ab9e804fe..3f61bb36f4a 100644 --- a/ld/testsuite/ld-discard/static.d +++ b/ld/testsuite/ld-discard/static.d @@ -1,6 +1,6 @@ #source: static.s #ld: -T discard.ld -#error: `(\.data\.exit|data)' referenced in section `\.text' of tmpdir/dump0.o: defined in discarded section `\.data\.exit' of tmpdir/dump0.o +#error: `(\.data\.exit|data)' referenced in section `\.text' of tmpdir/static.o: defined in discarded section `\.data\.exit' of tmpdir/static.o #objdump: -p #xfail: d30v-*-* dlx-*-* i960-*-* pj*-*-* #xfail: m68hc12-*-* m6812-*-* diff --git a/ld/testsuite/ld-elf/orphan-8.map b/ld/testsuite/ld-elf/orphan-8.map index 308d4277c20..57477906afa 100644 --- a/ld/testsuite/ld-elf/orphan-8.map +++ b/ld/testsuite/ld-elf/orphan-8.map @@ -1,7 +1,7 @@ #... .notbad 0x[0-9a-f]+ 0x4 - .notbad 0x[0-9a-f]+ 0x4 tmpdir/dump0.o + .notbad 0x[0-9a-f]+ 0x4 tmpdir/orphan.o #... .note.bar 0x[0-9a-f]+ 0x4 - .note.bar 0x[0-9a-f]+ 0x4 tmpdir/dump0.o + .note.bar 0x[0-9a-f]+ 0x4 tmpdir/orphan.o #... diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index 0f86fe63e45..a2be49b25f0 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -620,6 +620,7 @@ proc run_dump_test { name {extra_options {}} } { set dumpfile tmpdir/dump.out set run_ld 0 set run_objcopy 0 + set objfile_names {} set opts(as) {} set opts(ld) {} set opts(ld_after_inputfiles) {} @@ -666,6 +667,22 @@ proc run_dump_test { name {extra_options {}} } { } else { lappend asflags {} } + + # Create the object file name based on nothing but the source + # file name. + set new_objfile \ + [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]].o] + # But, sometimes, we have the exact same source filename in + # different directories (foo/src.s bar/src.s) which would lead + # us to try and create two src.o files. We detect this + # conflict here, and instead create src.o and src1.o. + set j 0 + while { [lsearch $objfile_names $new_objfile] != -1 } { + incr j + set new_objfile \ + [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]]${j}.o] + } + lappend objfile_names $new_objfile } default { if [string length $opts($opt_name)] { @@ -792,6 +809,7 @@ proc run_dump_test { name {extra_options {}} } { if { $opts(source) == "" } { set sourcefiles [list ${file}.s] set asflags [list ""] + set objfile_names [list tmpdir/[file tail ${file}].o] } else { set sourcefiles {} foreach sf $opts(source) { @@ -826,7 +844,7 @@ proc run_dump_test { name {extra_options {}} } { } regsub "RUN_OBJCOPY" $sourceasflags "" sourceasflags - set objfile "tmpdir/dump$i.o" + set objfile [lindex $objfile_names $i] catch "exec rm -f $objfile" exec_output lappend objfiles $objfile set cmd "$AS $ASFLAGS $opts(as) $sourceasflags -o $objfile $sourcefile" @@ -1014,7 +1032,7 @@ proc run_dump_test { name {extra_options {}} } { } } } else { - set objfile "tmpdir/dump0.o" + set objfile [lindex $objfiles 0] } # We must not have expected failure if we get here. -- 2.30.2