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 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 and progressing GCC 10 gnat testsuite user mode QEMU emulation results from: === gnat Summary === # of expected passes 2179 # of unexpected failures 719 # of expected failures 23 # of unsupported tests 28 to: === gnat Summary === # of expected passes 3235 # of unexpected failures 6 # of expected failures 23 # of unsupported tests 28 with the `riscv64-linux-gnu' target and the `x86_64-linux-gnu' host. * lib/target.exp (default_target_compile): Wrap linker flags into `-largs'/`-margs' for Ada. Signed-off-by: Maciej W. Rozycki <ma...@wdc.com> --- Hi, This is a repost of a change originally proposed as a part of a series: <https://lists.gnu.org/archive/html/dejagnu/2019-05/msg00001.html> for an issue where additional linker flags are defined in the target board have not been correctly passed to `gnatmake'. The GCC pieces of the series have all been since included upstream. Jacob, please let me know if you want this issue resolved differently. Otherwise, Rob, please apply this change. Maciej Changes from v1: - commit description updated with test results now that complementing GCC changes went upstream. --- lib/target.exp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) dejagnu-target-ada-ldflags.diff Index: dejagnu/lib/target.exp =================================================================== --- dejagnu.orig/lib/target.exp +++ dejagnu/lib/target.exp @@ -518,11 +518,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. @@ -530,16 +531,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]} { @@ -561,7 +569,11 @@ proc default_target_compile {source dest } if { $type eq "executable" } { - append add_flags " $ldflags" + if { $compiler_type eq "ada" } { + append add_flags " -largs $ldflags -margs" + } else { + append add_flags " $ldflags" + } foreach x $libs { if {[file exists $x]} { append source " $x"