Unrecognized `gnatmake' switches are not implicitly passed on to the linker, so just pasting board `ldflags' and any other linker flags verbatim into `add_flags' to use for the invocation line of `gnatmake' will make them ignored at best.
For example in a GCC test environment that has: set_board_info ldflags "-Wl,-dynamic-linker,.../sysroot/lib/ld-linux-riscv64-lp64d.so.1 -Wl,-rpath,.../sysroot/lib64/lp64d -Wl,-rpath,.../sysroot/usr/lib64/lp64d" so that sysroot paths are correctly embedded with the binaries linked for use with the dynamic loader and shared library dependencies, the setting will be ignored for the GNAT test suite making all the execution tests fail, e.g.: PASS: gnat.dg/abstract_with_anonymous_result.adb (test for excess errors) spawn qemu-riscv64 ./abstract_with_anonymous_result.exe /lib/ld-linux-riscv64-lp64d.so.1: No such file or directory FAIL: gnat.dg/abstract_with_anonymous_result.adb execution test For `gnatmake' to pass switches on to the linker the `-largs' switch has to be used, which affects all the switches that follow until a switch is seen that changes the selection, like `-margs', which resets to the initial state of the switch interpretation machine. Wrap linker flags into `-largs'/`-margs' for Ada then, carefully preserving the place these flags are placed at within `add_flags', as surely someone will have depended on that, correcting test failures like above: PASS: gnat.dg/abstract_with_anonymous_result.adb (test for excess errors) spawn qemu-riscv64 ./abstract_with_anonymous_result.exe PASS: gnat.dg/abstract_with_anonymous_result.adb execution test Pass multilib flags both to the compiler and to the linker as both build stages interpret them. Update the testsuite accordingly. * lib/target.exp (default_target_compile): Wrap linker flags into `-largs'/`-margs' for Ada. * testsuite/runtest.libs/target.test (compile_test): Update accordingly. Signed-off-by: Maciej W. Rozycki <ma...@wdc.com> --- Hi, Verified with the DejaGnu test suite and with the GCC `gnat' test suite, with the `riscv64-linux-gnu' target and the `x86_64-linux-gnu' host. For a reference, since it's been a while, v1 is available here: <https://lists.gnu.org/archive/html/dejagnu/2019-05/msg00000.html>. Please apply. Maciej Changes from v1: - Also pass libraries, linker scripts, random linker flags to the linker rather the compiler, and pass multilib flags to both the compiler and the linker. - Update the testsuite according to the changes made. --- lib/target.exp | 50 ++++++++++++++++++++++++++----------- testsuite/runtest.libs/target.test | 32 +++++++++++------------ 2 files changed, 52 insertions(+), 30 deletions(-) dejagnu-target-ada-ldflags.diff Index: dejagnu/lib/target.exp =================================================================== --- dejagnu.orig/lib/target.exp +++ dejagnu/lib/target.exp @@ -522,11 +522,12 @@ proc default_target_compile {source dest } if { $type eq "executable" } { + set extra_ldflags "" if {[board_info $dest exists ldflags]} { - append add_flags " [board_info $dest ldflags]" + append extra_ldflags " [board_info $dest ldflags]" } if { $compiler_type eq "c++" } { - append add_flags " [g++_link_flags]" + append extra_ldflags " [g++_link_flags]" } if {[isnative]} { # This is a lose. @@ -534,16 +535,23 @@ proc default_target_compile {source dest if { $tmp ne "" } { if {[regexp ".*solaris2.*" $target_triplet]} { # Solaris 2 - append add_flags " -R$tool_root_dir/libstdc++" + append extra_ldflags " -R$tool_root_dir/libstdc++" } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} { # OSF/1 or IRIX 5 - append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++" + append extra_ldflags " -Wl,-rpath,$tool_root_dir/libstdc++" } elseif {[regexp ".*hppa.*" $target_triplet]} { # HP-UX - append add_flags " -Wl,-a,shared_archive" + append extra_ldflags " -Wl,-a,shared_archive" } } } + if { $extra_ldflags ne "" } { + if { $compiler_type eq "ada" } { + append add_flags " -largs $extra_ldflags -margs" + } else { + append add_flags " $extra_ldflags" + } + } } if {![info exists ldscript]} { @@ -565,17 +573,17 @@ proc default_target_compile {source dest } if { $type eq "executable" } { - append add_flags " $ldflags" + set extra_ldflags "$ldflags" foreach x $libs { if {[file exists $x]} { append source " $x" } else { - append add_flags " $x" + append extra_ldflags " $x" } } if {[board_info $dest exists libs]} { - append add_flags " [board_info $dest libs]" + append extra_ldflags " [board_info $dest libs]" } # This probably isn't such a good idea, but it avoids nasty @@ -584,25 +592,39 @@ proc default_target_compile {source dest # library is linked in by the linker script, so this must be before # the linker script. if {[board_info $dest exists mathlib]} { - append add_flags " [board_info $dest mathlib]" + append extra_ldflags " [board_info $dest mathlib]" } else { - append add_flags " -lm" + append extra_ldflags " -lm" } # This must be added here. - append add_flags " $ldscript" + append extra_ldflags " $ldscript" if {[board_info $dest exists remote_link]} { # Relink option. - append add_flags " -Wl,-r" + append extra_ldflags " -Wl,-r" } if {[board_info $dest exists output_format]} { - append add_flags " -Wl,-oformat,[board_info $dest output_format]" + append extra_ldflags " -Wl,-oformat,[board_info $dest \ + output_format]" + } + if { $extra_ldflags ne "" } { + if { $compiler_type eq "ada" } { + append add_flags " -largs $extra_ldflags -margs" + } else { + append add_flags " $extra_ldflags" + } } } if {[board_info $dest exists multilib_flags]} { - set add_flags "[board_info $dest multilib_flags] $add_flags" + set multilib_flags [board_info $dest multilib_flags] + if { $compiler_type eq "ada" } { + set add_flags "$multilib_flags -largs $multilib_flags -margs\ + $add_flags" + } else { + set add_flags "$multilib_flags $add_flags" + } } verbose "doing compile" Index: dejagnu/testsuite/runtest.libs/target.test =================================================================== --- dejagnu.orig/testsuite/runtest.libs/target.test +++ dejagnu/testsuite/runtest.libs/target.test @@ -620,8 +620,8 @@ eval_tests compile_test { "find_gcc" ! {} "find_gnatmake" ! {} "remote_exec host" U - { 2 {m68k-unknown-aout-gnatmake foo.adb -midp -fada - -E -I/usr/gnemul/idp/include} } + { 2 {m68k-unknown-aout-gnatmake foo.adb -midp -largs -midp -margs + -fada -E -I/usr/gnemul/idp/include} } } } { "compile Ada to assembly with target compiler" @@ -630,8 +630,8 @@ eval_tests compile_test { "find_gcc" ! {} "find_gnatmake" ! {} "remote_exec host" U - { 2 {m68k-unknown-aout-gnatmake foo.adb -midp -fada - -S -I/usr/gnemul/idp/include -o foo.s} } + { 2 {m68k-unknown-aout-gnatmake foo.adb -midp -largs -midp -margs + -fada -S -I/usr/gnemul/idp/include -o foo.s} } } } { "compile Ada to object with target compiler" @@ -640,7 +640,7 @@ eval_tests compile_test { "find_gcc" ! {} "find_gnatmake" ! {} "remote_exec host" U - { 2 {m68k-unknown-aout-gnatmake -midp -fada + { 2 {m68k-unknown-aout-gnatmake -midp -largs -midp -margs -fada -c -I/usr/gnemul/idp/include -o foo.o foo.adb} } } @@ -651,9 +651,9 @@ eval_tests compile_test { "find_gcc" ! {} "find_gnatmake" ! {} "remote_exec host" U - { 2 {m68k-unknown-aout-gnatmake foo.adb -midp -fada - -I/usr/gnemul/idp/include -L/usr/gnemul/idp/lib - -lidpsup -lm_idp -Tidp.ld -o foo} } + { 2 {m68k-unknown-aout-gnatmake foo.adb -midp -largs -midp -margs + -fada -I/usr/gnemul/idp/include -largs -L/usr/gnemul/idp/lib + -margs -largs -lidpsup -lm_idp -Tidp.ld -margs -o foo} } } } @@ -666,7 +666,7 @@ eval_tests compile_test { "find_gcc" ! {} "find_gnatmake" ! {} "remote_exec host" U - { 2 {target-gnatmake foo.adb -midp -fada + { 2 {target-gnatmake foo.adb -midp -largs -midp -margs -fada -E -I/usr/gnemul/idp/include} } } } @@ -676,7 +676,7 @@ eval_tests compile_test { "find_gcc" ! {} "find_gnatmake" ! {} "remote_exec host" U - { 2 {target-gnatmake foo.adb -midp -fada + { 2 {target-gnatmake foo.adb -midp -largs -midp -margs -fada -S -I/usr/gnemul/idp/include -o foo.s} } } } @@ -686,7 +686,7 @@ eval_tests compile_test { "find_gcc" ! {} "find_gnatmake" ! {} "remote_exec host" U - { 2 {target-gnatmake -midp -fada + { 2 {target-gnatmake -midp -largs -midp -margs -fada -c -I/usr/gnemul/idp/include -o foo.o foo.adb} } } @@ -697,9 +697,9 @@ eval_tests compile_test { "find_gcc" ! {} "find_gnatmake" ! {} "remote_exec host" U - { 2 {target-gnatmake foo.adb -midp -fada - -I/usr/gnemul/idp/include -L/usr/gnemul/idp/lib - -lidpsup -lm_idp -Tidp.ld -o foo} } + { 2 {target-gnatmake foo.adb -midp -largs -midp -margs -fada + -I/usr/gnemul/idp/include -largs -L/usr/gnemul/idp/lib -margs + -largs -lidpsup -lm_idp -Tidp.ld -margs -o foo} } } } { "clean up GNATMAKE_FOR_TARGET" @@ -712,7 +712,7 @@ eval_tests compile_test { } } check_calls { "remote_exec host" U - { 2 {found-gnatmake foo.adb -lm -Tmvme.ld -o foo} } + { 2 {found-gnatmake foo.adb -largs -lm -Tmvme.ld -margs -o foo} } } } { "override destination to host and compile and link Ada with host-gnatmake" @@ -721,7 +721,7 @@ eval_tests compile_test { } } check_calls { "remote_exec host" U - { 2 {host-gnatmake foo.adb -lm -Tmvme.ld -o foo} } + { 2 {host-gnatmake foo.adb -largs -lm -Tmvme.ld -margs -o foo} } } }