> Date: Wed, 4 Jan 2017 17:46:23 +0100
> From: Patrick Wildt <[email protected]>
> 
> Hi,
> 
> with GCC as cross-compiler the PREFIX define (which is set to the
> CROSSDIR) makes sure that the linker includes the correct dirs.
> Otherwise the cross-build will only find the host libraries, which
> does not really work well.
> 
> Our clang doesn't do this so far.  The changes in clang make sure that
> 
>   * the library paths are passed to ld(1) and
>   * the library path /usr/lib is prefixed with the sysroot.

This will also help aoption of lld, so ok kettenis@

> Then we need to make sure to invoke our cross-clang with --sysroot
> ${CROSSDIR}.  For this, simply replace the cc and c++ binary with
> a wrapper that calls clang with the correct mode and options.

I think that's a reasonable thing to do.

ok kettenis@

> diff --git a/Makefile.cross b/Makefile.cross
> index 01c1c843953..9c5dbe8b5a5 100644
> --- a/Makefile.cross
> +++ b/Makefile.cross
> @@ -238,10 +238,13 @@ ${CROSSGCC}:            ${CROSSBINUTILS}
>           ${MAKE} install)
>       mv ${CROSSDIR}/usr/bin/clang ${CROSSDIR}/usr/bin/${TARGET_CANON}-clang
>       mv ${CROSSDIR}/usr/bin/clang++ 
> ${CROSSDIR}/usr/bin/${TARGET_CANON}-clang++
> -     cp -f ${CROSSDIR}/usr/bin/${TARGET_CANON}-clang 
> ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-cc
> -     cp -f ${CROSSDIR}/usr/bin/${TARGET_CANON}-clang++ 
> ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-c++
> +     cp -f ${CROSSDIR}/usr/bin/${TARGET_CANON}-clang 
> ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-clang
>       ln -sf ${TARGET_CANON}-cc ${CROSSDIR}/usr/${TARGET_CANON}/bin/cc
>       ln -sf ${TARGET_CANON}-c++ ${CROSSDIR}/usr/${TARGET_CANON}/bin/c++
> +     echo  
> "#!/bin/sh\n${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-clang 
> --sysroot ${CROSSDIR} \"$$""@\"" > 
> ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-cc; \
> +     chmod +x ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-cc;
> +     echo  
> "#!/bin/sh\n${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-clang 
> --driver-mode=g++ --sysroot ${CROSSDIR} \"$$""@\"" > 
> ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-c++; \
> +     chmod +x ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-c++;
>  .elif ${COMPILER_VERSION:L} == "gcc3"
>       (cd ${.CURDIR}/gnu/usr.bin/gcc; \
>           MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
> diff --git a/gnu/llvm/tools/clang/lib/Driver/ToolChains.cpp 
> b/gnu/llvm/tools/clang/lib/Driver/ToolChains.cpp
> index 45622b22ab5..7ba8f25efdd 100644
> --- a/gnu/llvm/tools/clang/lib/Driver/ToolChains.cpp
> +++ b/gnu/llvm/tools/clang/lib/Driver/ToolChains.cpp
> @@ -2977,7 +2977,7 @@ OpenBSD::OpenBSD(const Driver &D, const llvm::Triple 
> &Triple,
>                   const ArgList &Args)
>      : Generic_ELF(D, Triple, Args) {
>    getFilePaths().push_back(getDriver().Dir + "/../lib");
> -  getFilePaths().push_back("/usr/lib");
> +  getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
>  }
>  
>  Tool *OpenBSD::buildAssembler() const {
> diff --git a/gnu/llvm/tools/clang/lib/Driver/Tools.cpp 
> b/gnu/llvm/tools/clang/lib/Driver/Tools.cpp
> index 656a8fbbdaf..34cbd620b4b 100644
> --- a/gnu/llvm/tools/clang/lib/Driver/Tools.cpp
> +++ b/gnu/llvm/tools/clang/lib/Driver/Tools.cpp
> @@ -7623,8 +7623,10 @@ void openbsd::Linker::ConstructJob(Compilation &C, 
> const JobAction &JA,
>      }
>    }
>  
> -  Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
> -                            options::OPT_e, options::OPT_s, options::OPT_t,
> +  Args.AddAllArgs(CmdArgs, options::OPT_L);
> +  getToolChain().AddFilePathLibArgs(Args, CmdArgs);
> +  Args.AddAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_e,
> +                            options::OPT_s, options::OPT_t,
>                              options::OPT_Z_Flag, options::OPT_r});
>  
>    AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
> 
> 

Reply via email to