From 29745b41f5033ee82edd539d21a631086af919d2 Mon Sep 17 00:00:00 2001 From: Sam Elliott Date: Thu, 25 Jun 2020 12:32:53 +0100 Subject: [PATCH 1/2] [meson] Provide toolchain-specific flags when linking Signed-off-by: Sam Elliott --- generate-clang-meson-cross-file.sh | 21 ++++++++++++++------- generate-gcc-meson-cross-file.sh | 16 ++++++++++------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/generate-clang-meson-cross-file.sh b/generate-clang-meson-cross-file.sh index 3c888b4..40b2e9b 100755 --- a/generate-clang-meson-cross-file.sh +++ b/generate-clang-meson-cross-file.sh @@ -26,13 +26,18 @@ toolchain_dest="${2}" # Remaining cflags for build configurations toolchain_cflags=("${@:3}") -# Clang requires a `--gcc-toolchain=` argument to find some things -meson_cflags="'--gcc-toolchain=${toolchain_dest}'" +# Meson uses the driver when both compiling and linking, which may need flags to +# identify exactly how to set up paths and defaults for both. +# +# In particular, the clang driver requires a `--gcc-toolchain=` argument +# to find the right libraries if there are system versions of the risc-v +# toolchains installed. +meson_driver_flags="'--gcc-toolchain=${toolchain_dest}'" for flag in "${toolchain_cflags[@]}"; do - if [ -z "${meson_cflags}" ]; then - meson_cflags+="'${flag}'"; + if [ -z "${meson_driver_flags}" ]; then + meson_driver_flags+="'${flag}'"; else - meson_cflags+=", '${flag}'" + meson_driver_flags+=", '${flag}'" fi done @@ -69,8 +74,10 @@ strip = '${toolchain_dest}/bin/${toolchain_target}-strip' [properties] needs_exe_wrapper = true has_function_printf = false -c_args = [${meson_cflags}] -cpp_args = [${meson_cflags}] +c_args = [${meson_driver_flags}] +c_link_args = [${meson_driver_flags}] +cpp_args = [${meson_driver_flags}] +cpp_link_args = [${meson_driver_flags}] ${sysroot_config} [host_machine] diff --git a/generate-gcc-meson-cross-file.sh b/generate-gcc-meson-cross-file.sh index a050491..d6d3aff 100755 --- a/generate-gcc-meson-cross-file.sh +++ b/generate-gcc-meson-cross-file.sh @@ -26,12 +26,14 @@ toolchain_dest="${2}" # Remaining cflags for build configurations toolchain_cflags=("${@:3}") -meson_cflags="" +# Meson uses the driver when both compiling and linking, which may need flags to +# identify exactly how to set up paths and defaults for both. +meson_driver_flags="" for flag in "${toolchain_cflags[@]}"; do - if [ -z "${meson_cflags}" ]; then - meson_cflags+="'${flag}'"; + if [ -z "${meson_driver_flags}" ]; then + meson_driver_flags+="'${flag}'"; else - meson_cflags+=", '${flag}'" + meson_driver_flags+=", '${flag}'" fi done @@ -68,8 +70,10 @@ strip = '${toolchain_dest}/bin/${toolchain_target}-strip' [properties] needs_exe_wrapper = true has_function_printf = false -c_args = [${meson_cflags}] -cpp_args = [${meson_cflags}] +c_args = [${meson_driver_flags}] +c_link_args = [${meson_driver_flags}] +cpp_args = [${meson_driver_flags}] +cpp_link_args = [${meson_driver_flags}] ${sysroot_config} [host_machine] From 8da2bc75d447d7e44077a4ee5e83c0f08311101c Mon Sep 17 00:00:00 2001 From: Sam Elliott Date: Thu, 25 Jun 2020 12:32:53 +0100 Subject: [PATCH 2/2] [meson] Provide Language-specific Linker Definitions This is a new feature of meson v0.53.1 which chooses the linker in a language-specific manner. We just set the linker for C and C++ to explicitly be riscv32-unknown-elf-ld, the linker we normally use. In the clang builds, this will be passed with `clang -fuse-ld=` which should work correctly, but uses the clang driver to establish all the right arguments to pass down to the linker. Signed-off-by: Sam Elliott --- generate-clang-meson-cross-file.sh | 2 ++ generate-gcc-meson-cross-file.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/generate-clang-meson-cross-file.sh b/generate-clang-meson-cross-file.sh index 40b2e9b..cef9375 100755 --- a/generate-clang-meson-cross-file.sh +++ b/generate-clang-meson-cross-file.sh @@ -67,6 +67,8 @@ c = '${toolchain_dest}/bin/${toolchain_target}-clang' cpp = '${toolchain_dest}/bin/${toolchain_target}-clang++' ar = '${toolchain_dest}/bin/${toolchain_target}-ar' ld = '${toolchain_dest}/bin/${toolchain_target}-ld' +c_ld = '${toolchain_dest}/bin/${toolchain_target}-ld' +cpp_ld = '${toolchain_dest}/bin/${toolchain_target}-ld' objdump = '${toolchain_dest}/bin/${toolchain_target}-objdump' objcopy = '${toolchain_dest}/bin/${toolchain_target}-objcopy' strip = '${toolchain_dest}/bin/${toolchain_target}-strip' diff --git a/generate-gcc-meson-cross-file.sh b/generate-gcc-meson-cross-file.sh index d6d3aff..a36dc97 100755 --- a/generate-gcc-meson-cross-file.sh +++ b/generate-gcc-meson-cross-file.sh @@ -63,6 +63,8 @@ c = '${toolchain_dest}/bin/${toolchain_target}-gcc' cpp = '${toolchain_dest}/bin/${toolchain_target}-g++' ar = '${toolchain_dest}/bin/${toolchain_target}-ar' ld = '${toolchain_dest}/bin/${toolchain_target}-ld' +c_ld = '${toolchain_dest}/bin/${toolchain_target}-ld' +cpp_ld = '${toolchain_dest}/bin/${toolchain_target}-ld' objdump = '${toolchain_dest}/bin/${toolchain_target}-objdump' objcopy = '${toolchain_dest}/bin/${toolchain_target}-objcopy' strip = '${toolchain_dest}/bin/${toolchain_target}-strip'