Add rules to build LLVM IR binaries and libraries.

Running `make libfoo.ll` or `make libfoo.bc` within a library directory
will now give us an LLVM IR version of the library, and `make foo.full.ll`
or `make foo.full.bc` will give us an IR version of a binary.

As part of this change, we add an LLVM_LINK variable to sys.mk that can be
specified/overridden using an external toolchain.

Reviewed by:	bdrewery, brooks
Approved by:	rwatson (mentor)
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D8388
This commit is contained in:
Jonathan Anderson 2016-11-01 21:27:42 +00:00
parent e04310d59b
commit e4195e2e12
4 changed files with 34 additions and 7 deletions

View File

@ -543,8 +543,8 @@ HMAKE+= PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT
CROSSENV+= CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCXXFLAGS} ${XCFLAGS}" \
CPP="${XCPP} ${XCFLAGS}" \
AS="${XAS}" AR="${XAR}" LD="${XLD}" NM=${XNM} \
OBJCOPY="${XOBJCOPY}" \
AS="${XAS}" AR="${XAR}" LD="${XLD}" LLVM_LINK="${XLLVM_LINK}" \
NM=${XNM} OBJCOPY="${XOBJCOPY}" \
RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \
SIZE="${XSIZE}"

View File

@ -78,7 +78,7 @@ CTFFLAGS+= -g
# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
# .pico used for PIC object files
.SUFFIXES: .out .o .po .pico .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
.SUFFIXES: .out .o .bc .ll .po .pico .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
.if !defined(PICFLAG)
.if ${MACHINE_CPUARCH} == "sparc64"
@ -199,6 +199,18 @@ lib${LIB_PRIVATE}${LIB}_p.a: ${POBJS}
${RANLIB} ${RANLIBFLAGS} ${.TARGET}
.endif
.if defined(LLVM_LINK)
BCOBJS= ${OBJS:.o=.bco} ${STATICOBJS:.o=.bco}
LLOBJS= ${OBJS:.o=.llo} ${STATICOBJS:.o=.llo}
CLEANFILES+= ${BCOBJS} ${LLOBJS}
lib${LIB_PRIVATE}${LIB}.bc: ${BCOBJS}
${LLVM_LINK} -o ${.TARGET} ${BCOBJS}
lib${LIB_PRIVATE}${LIB}.ll: ${LLOBJS}
${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS}
.endif
.if defined(SHLIB_NAME) || \
defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
SOBJS+= ${OBJS:.o=.pico}

View File

@ -4,7 +4,7 @@
.include <bsd.init.mk>
.include <bsd.compiler.mk>
.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
.SUFFIXES: .out .o .bc .c .cc .cpp .cxx .C .m .y .l .ll .ln .s .S .asm
# XXX The use of COPTS in modern makefiles is discouraged.
.if defined(COPTS)
@ -147,6 +147,19 @@ ${PROGNAME}.debug: ${PROG_FULL}
${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
.endif
.if defined(LLVM_LINK)
# LLVM bitcode / textual IR representations of the program
BCOBJS= ${OBJS:.o=.bco}
LLOBJS= ${OBJS:.o=.llo}
${PROG_FULL}.bc: ${BCOBJS}
${LLVM_LINK} -o ${.TARGET} ${BCOBJS}
${PROG_FULL}.ll: ${LLOBJS}
${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS}
.endif # defined(LLVM_LINK)
.if ${MK_MAN} != "no" && !defined(MAN) && \
!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
@ -166,14 +179,14 @@ all: all-man
.endif
.if defined(PROG)
CLEANFILES+= ${PROG}
CLEANFILES+= ${PROG} ${PROG}.bc ${PROG}.ll
.if ${MK_DEBUG_FILES} != "no"
CLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug
CLEANFILES+= ${PROG_FULL} ${PROG_FULL}.bc ${PROGNAME}.debug ${PROG_FULL}.ll
.endif
.endif
.if defined(OBJS)
CLEANFILES+= ${OBJS}
CLEANFILES+= ${OBJS} ${BCOBJS} ${LLOBJS}
.endif
.include <bsd.libnames.mk>

View File

@ -231,6 +231,8 @@ LINTLIBFLAGS ?= -cghapbxu -C ${LIB}
MAKE ?= make
.if !defined(%POSIX)
LLVM_LINK ?= llvm-link
LORDER ?= lorder
NM ?= nm