Bug 227920 - [PATCH] fix for Makefile.libcompat to use external cross-compiler
Summary: [PATCH] fix for Makefile.libcompat to use external cross-compiler
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 11.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-05-02 12:08 UTC by Kenneth Salerno
Modified: 2018-08-05 04:35 UTC (History)
2 users (show)

See Also:


Attachments
patch to set -target and -B for external cross-compilers (470 bytes, patch)
2018-05-02 12:08 UTC, Kenneth Salerno
no flags Details | Diff
patch to set -target for external cross-compilers (383 bytes, patch)
2018-05-06 19:45 UTC, Kenneth Salerno
no flags Details | Diff
patch to set -target for clang as an external cross-compiler (414 bytes, patch)
2018-05-07 02:21 UTC, Kenneth Salerno
no flags Details | Diff
patch to set -target for external cross-compilers (416 bytes, patch)
2018-05-07 12:32 UTC, Kenneth Salerno
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Salerno 2018-05-02 12:08:50 UTC
Created attachment 192992 [details]
patch to set -target and -B for external cross-compilers

When using devel/llvm60 as a cross-compiler, it is necessary to set -B and -target in Makefile.libcompat just as it was in Makefile.inc1.

This patch is just a starting point to get it to build correctly, probably need a check if using clang etc. to not affect unrelated build environments.
Comment 1 Bryan Drewery freebsd_committer 2018-05-04 23:25:54 UTC
This isn't complete as GCC does not support -target. But it seems wrong to me
to need -target. I've never had problems cross-compiling with the external
compilers so far, though I may not have tried with clang.




LIB32CFLAGS+=	-B${CROSS_BINUTILS_PREFIX}

This -B flag is already being added via ${BFLAGS}.

Makefile.inc1:

.if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX})
# In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a
# directory, but the compiler will look in the right place for its
# tools so we don't need to tell it where to look.
BFLAGS+=        -B${CROSS_BINUTILS_PREFIX}
.endif

Makefile.libcompat:

LIBCOMPATCFLAGS+=       ${LIBCOMPATCPUFLAGS} \                 
                        -L${LIBCOMPATTMP}/usr/lib${libcompat} \
                        --sysroot=${LIBCOMPATTMP} \            
                        ${BFLAGS}                              
                       ^^^^^^^^^^
Comment 2 Kenneth Salerno 2018-05-05 11:02:50 UTC
(In reply to Bryan Drewery from comment #1)
Hi, Bryan.

You are correct that I did not finish adding checks for other compilers, please see my original comment at the top of this submission.

The reason -target is needed is because I am cross-compiling on amd64 for ppc64. Makefile.inc1 is adding -target, but Makefile.libcompat does not today.

I also needed to add -B because this: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227918
Comment 3 Kenneth Salerno 2018-05-06 19:45:32 UTC
Created attachment 193110 [details]
patch to set -target for external cross-compilers

To Bryan's point, do not need to set -B since BFLAGS is being pulled in from Makefile.inc1 (if my other patch is approved for bug https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227918)
Comment 4 Kenneth Salerno 2018-05-07 02:21:46 UTC
Created attachment 193126 [details]
patch to set -target for clang as an external cross-compiler

Added a check for clang compilers only.
Comment 5 Kenneth Salerno 2018-05-07 12:32:15 UTC
Created attachment 193145 [details]
patch to set -target for external cross-compilers

ok that didn't work, need to use X_COMPILER_TYPE here.
Comment 6 Mark Millard 2018-05-11 23:13:39 UTC
(In reply to Kenneth Salerno from comment #5)

The patch's use of exactly "freebsd11.1" in

+LIB32CFLAGS+=	-target ${TARGET}-unknown-freebsd11.1

means it can not be directly used everywhere but does indicate
a direction.
Comment 7 Kenneth Salerno 2018-05-12 00:23:15 UTC
(In reply to Mark Millard from comment #6)
That's how I found it in Makefile.inc1 so I guess it just gets updated with each release, but if we can use OSREL instead it would be better obviously.
Comment 8 Mark Millard 2018-05-12 05:04:26 UTC
(In reply to Kenneth Salerno from comment #7)

Yep, I see on looking (using head's /usr/src/ ):

# grep -ir freebsd12 Makefile* share/mk/* | more
Makefile.inc1:MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/hf$//:S/mipsn32/mips64/}-${MACHINE_ABI}-freebsd12.0
Makefile.inc1:TARGET_TRIPLE?=   ${TARGET_ARCH:S/amd64/x86_64/:C/hf$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd12.0
Makefile.libcompat:LIB32CPUFLAGS=  -target mipsel-unknown-freebsd12.0
Makefile.libcompat:LIB32CPUFLAGS=  -target mips-unknown-freebsd12.0

(Of course _HOST_OSREL would not be right in all cases.)
Comment 9 Mark Millard 2018-05-14 02:24:17 UTC
(In reply to Bryan Drewery from comment #1)

For handling WITH_LIB32= in a cross compile (such as
amd64 -> powerpc64 as the overall context), clang has
to be told an appropriate -target or it tries to use
amd64's assembler on the powerpc .S assembler files.
This leads to build failures for rejected notation.

-mcpu=powerpc -m32 without the -target is not sufficient.
(And it what currently happens on the command line.)
With multiple ABI's around, -target is the only
option that specifies that much context as far as
I know.

clang does take a powerpc64 -target and a -m32 and
end up with a powerpc target according to my
experiments. But I've not checked that the 32-bit
ABI implicitly picked is appropriate to FreeBSD's
ABI choices, which are rather distinct for 32-bit
vs. 64-bit for the powerpc families.
Comment 10 Mark Millard 2018-05-14 02:43:20 UTC
(In reply to Kenneth Salerno from comment #5)

There is a possible future problem with:

+LIB32CFLAGS+=	-target ${TARGET}-unknown-freebsd11.1

in that TARGET is not always the right thing to have a
32 bit variant of TARGET_ARCH, taking an example
(replacing 11.1 with * to avoid being that specific
here as well):

arm64/aarch64 would likely want something like armv7-unknown-freebsd*
if aarch64 ends up with lib32 support.

So more conditional logic might be needed eventually.
Comment 11 Mark Millard 2018-05-18 04:18:44 UTC
(In reply to Mark Millard from comment #10)

Looks to me like it might be an issue now in mips land,
presuming these have lib32 possible (32-bit TARGET/TARGET_ARCH
naming on the right side of "->"):

    mips/mips64el   -> mips/mipsel
    mips/mips64elhf -> mips/mipselhf
    mips/mips64hf   -> mips/mipshf

There is a:

    mips/mips64     -> mips/mips

which appears to happen to work.

But I do not know mips specifics, so the above could
involve some bad guess work on my part.
Comment 12 Mark Millard 2018-05-19 23:04:05 UTC
(In reply to Kenneth Salerno from comment #5)

Summary of a failure:

When a clang-based environment tries to build a target
by building gcc 4.2.1 as the boottrap compiler, it looks
like LIB32CFLAGS ends up being used on the bootstrap
compiler's cpp line: it ends up being rejected by the
gcc 4.2.1 related cpp.

More detailed evidence:

I tried to cross build amd64 -> powerpc64 where the
cross build built gcc 4.2.1 to do the later build stages.
I used the Makefile.libcompat patch variant below:

# svnlite diff /usr/src/Makefile.libcompat
Index: /usr/src/Makefile.libcompat
===================================================================
--- /usr/src/Makefile.libcompat (revision 333863)
+++ /usr/src/Makefile.libcompat (working copy)
@@ -63,6 +63,14 @@


 LIB32CFLAGS=   -DCOMPAT_32BIT
+.if ${TARGET_ARCH} == "powerpc64"
+# TARGET happens to have the right 32-bit name to use in -target
+# clang uses -target to figure out which assembler notation to
+# process.
+.if ${TARGET} != ${MACHINE} && ${X_COMPILER_TYPE} == "clang"
+LIB32CFLAGS+=  -target ${TARGET}-unknown-freebsd12.0
+.endif
+.endif
 LIB32DTRACE=   ${DTRACE} -32
 LIB32WMAKEFLAGS+=      -DCOMPAT_32BIT


This appears to contribute to /usr/src/include/rpc/Makefile 's:

RPCCOM= RPCGEN_CPP=${CPP:Q} rpcgen -C

and ends up feeding the relevant cpp a -target, which is then
rejected:

===> include/rpc (includes)
Building /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpc/rpcb_prot.h
--- rpcb_prot.h ---
cpp: powerpc-unknown-freebsd12.0: No such file or directory
cpp: warning: '-x c' after last input file has no effect
cpp: unrecognized option '-target'
cpp: No input files specified
--- includes_subdir_include/rpcsvc ---
Building /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpcsvc/rstat.h
Building /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpcsvc/rwall.h
Building /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpcsvc/sm_inter.h
Building /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpcsvc/spray.h
Building /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpcsvc/yppasswd.h
Building /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpcsvc/yp.h
Building /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpcsvc/ypxfrd.h
--- includes_subdir_include/rpc ---
*** [rpcb_prot.h] Error code 1

make[3]: stopped in /usr/src/include/rpc
.ERROR_TARGET='rpcb_prot.h'
.ERROR_META_FILE='/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpc/rpcb_prot.h.meta'
.MAKE.LEVEL='3'
MAKEFILE=''
.MAKE.MODE='meta missing-filemon=yes missing-meta=yes silent=yes verbose'
_ERROR_CMD='RPCGEN_CPP=cpp\ -DCOMPAT_32BIT\ -target\ powerpc-unknown-freebsd12.0\ -mcpu=powerpc\ -m32\ \ -L/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/tmp/usr/lib32\ \ --sysroot=/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/tmp\ \ -B/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/usr/bin\ -B/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/tmp/usr/lib32\ -isystem\ /usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/tmp/usr/include rpcgen -C -h -DWANT_NFS3 /usr/src/include/rpc/rpcb_prot.x -o rpcb_prot.h;'
.CURDIR='/usr/src/include/rpc'
.MAKE='make'
.OBJDIR='/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/include/rpc'
.TARGETS='includes'
DESTDIR='/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32/tmp'
LD_LIBRARY_PATH=''
MACHINE='powerpc'
MACHINE_ARCH='powerpc'
MAKEOBJDIRPREFIX=''
MAKESYSPATH='/usr/src/share/mk'
MAKE_VERSION='20180512'
PATH='/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/legacy/usr/sbin:/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/legacy/usr/bin:/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/legacy/bin:/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/usr/sbin:/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/tmp/usr/bin:/sbin:/bin:/usr/sbin:/usr/bin'
SRCTOP='/usr/src'
OBJTOP='/usr/obj/powerpc64vtsc_clang_gcc421/powerpc.powerpc64/usr/src/powerpc.powerpc64/obj-lib32'
.MAKE.MAKEFILES='/usr/src/share/mk/sys.mk /usr/src/share/mk/local.sys.env.mk /usr/src/share/mk/src.sys.env.mk /root/src.configs/src.conf.powerpc64-gcc421-bootstrap-clang.amd64-host /usr/src/share/mk/bsd.mkopt.mk /usr/src/share/mk/src.sys.obj.mk /usr/src/share/mk/auto.obj.mk /usr/src/share/mk/bsd.suffixes.mk /usr/src/share/mk/local.sys.mk /usr/src/share/mk/src.sys.mk /dev/null /usr/src/include/rpc/Makefile /usr/src/share/mk/bsd.prog.mk /usr/src/share/mk/bsd.init.mk /usr/src/share/mk/bsd.opts.mk /usr/src/share/mk/bsd.cpu.mk /usr/src/share/mk/local.init.mk /usr/src/share/mk/src.init.mk /usr/src/share/mk/bsd.own.mk /usr/src/share/mk/bsd.compiler.mk /usr/src/share/mk/bsd.linker.mk /usr/src/share/mk/bsd.libnames.mk /usr/src/share/mk/src.libnames.mk /usr/src/share/mk/src.opts.mk /usr/src/share/mk/bsd.nls.mk /usr/src/share/mk/bsd.confs.mk /usr/src/share/mk/bsd.files.mk /usr/src/share/mk/bsd.incs.mk /usr/src/share/mk/bsd.links.mk /usr/src/share/mk/bsd.dep.mk /usr/src/share/mk/bsd.clang-analyze.mk /usr/src/share/mk/bsd.obj.mk /usr/src/share/mk/bsd.subdir.mk /usr/src/share/mk/bsd.sys.mk'
.PATH='. /usr/src/include/rpc'
1 error
-