LLVM bitcode for almost the whole source tree

Change-Id: Ibc6f89de112e0649c3a3bfe49c2baa2ed0746212
This commit is contained in:
Anton Kuijsten 2013-06-17 14:51:49 +00:00 committed by Lionel Sambuc
parent ba92d5219d
commit 2e3046757a
17 changed files with 139 additions and 10 deletions

View file

@ -987,6 +987,7 @@
./usr/include/zconf.h minix-sys
./usr/include/zlib.h minix-sys
./usr/lib minix-sys
./usr/lib/bc minix-sys
./usr/lib/cawf minix-sys
./usr/lib/cawf/common minix-sys
./usr/lib/cawf/device.cf minix-sys

View file

@ -2,6 +2,8 @@
.include <bsd.own.mk>
USE_BITCODE:=no
PROG= memory
SRCS= memory.c imgrd.mfs
OBJS= ${SRCS:N*.h:R:S/$/.o/g}

View file

@ -2,6 +2,8 @@
.include <bsd.own.mk>
USE_BITCODE:=no
install:
all:

View file

@ -68,6 +68,7 @@
./usr/include/ufs/mfs
./usr/include/ufs/ufs
./usr/lib
./usr/lib/bc
./usr/lib/cawf
./usr/lib/dict
./usr/lib/flex

View file

@ -1,6 +1,8 @@
# Makefile for kernel
.include <bsd.own.mk>
USE_BITCODE:=no
BINDIR= /usr/sbin
MAN=
PROG= kernel

View file

@ -81,7 +81,7 @@ SUBDIR+= pkgconfig
.include "${.CURDIR}/net/Makefile.inc"
.include "${.CURDIR}/nameser/Makefile.inc"
.include "${.CURDIR}/nls/Makefile.inc"
.if (${MACHINE_ARCH} != "alpha") && (${ARCHSUBDIR} != "sparc64")
.if (${MACHINE_ARCH} != "alpha") && (${ARCHSUBDIR} != "sparc64") && ${USE_BITCODE:Uno} != "yes"
.include "${.CURDIR}/quad/Makefile.inc"
.endif
.if (${USE_LIBTRE} == "yes")

View file

@ -3,6 +3,8 @@
# NOTE: when changing ld.so, ensure that ldd still compiles.
#
USE_BITCODE=no
WARNS?=4
# Minix Clang binaries references /libexec/ld.elf_so

View file

@ -30,6 +30,11 @@ __DPSRCS.all+= ${SRCS:C/\.(c|m|s|S|C|cc|cpp|cxx)$/.d/} \
__DPSRCS.d= ${__DPSRCS.all:O:u:M*.d}
__DPSRCS.notd= ${__DPSRCS.all:O:u:N*.d}
.if defined(__MINIX)
__DPSRCS.bcd= ${"${USE_BITCODE:Uno}" == "yes":? ${SRCS:M*.c:O:u:.c=.bcd}:}
__DPSRCS.d+= ${__DPSRCS.bcd}
.endif # defined(__MINIX)
.NOPATH: .depend ${__DPSRCS.d}
.if !empty(__DPSRCS.d) # {
@ -41,7 +46,15 @@ ${__DPSRCS.d}: ${__DPSRCS.notd} ${DPSRCS}
rm -f .depend
${MKDEP} -d -f ${.TARGET} -s ${MKDEP_SUFFIXES:Q} ${__DPSRCS.d}
.SUFFIXES: .d .s .S .c .C .cc .cpp .cxx .m
.SUFFIXES: .bcd .d .s .S .c .C .cc .cpp .cxx .m
.if ${USE_BITCODE:Uno} == "yes"
.c.bcd:
${_MKTARGET_CREATE}
${MKDEP} -f ${.TARGET} -s .bc -- ${MKDEPFLAGS} \
${CFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
${CPPFLAGS} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
.endif
.c.d:
${_MKTARGET_CREATE}

View file

@ -210,6 +210,16 @@ CTFFLAGS+= -g
.endif
.endif
.if ${USE_BITCODE:Uno} == "yes"
.S.bc: ${.TARGET:.bc=.o}
rm -f ${.TARGET}
ln ${.TARGET:.bc=.o} ${.TARGET}
.c.bc:
${_MKTARGET_COMPILE}
${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o - -Qunused-arguments -E -D"__weak_alias(X, Y)=__weak_alias2( __WEAK__ ## X, __WEAK__ ## Y)" \
| sed 's/__WEAK__//g' \
| ${COMPILE.c} -flto ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -x c - -o ${.TARGET} -D"STRINGIFY(a)=#a" -D"__weak_alias2(X, Y)=_Pragma(STRINGIFY(weak X = Y))"
.endif # ${USE_BITCODE:Uno} == "yes"
.c.o:
${_MKTARGET_COMPILE}
${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
@ -491,6 +501,10 @@ SOBJS=
_YLSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
.if ${USE_BITCODE:Uno} == "yes"
_LIBS+=lib${LIB}_bc.a
.endif
.NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.debug}
@ -532,6 +546,14 @@ CLEANFILES+= ${_YLSRCS}
${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
.if ${USE_BITCODE:Uno} == "yes"
BCOBJS+=${OBJS:.o=.bc}
lib${LIB}_bc.a:: ${BCOBJS}
${_MKTARGET_BUILD}
rm -f ${.TARGET}
${AR} ${_ARFL} ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*bc} | ${TSORT}`
.endif
lib${LIB}.a:: ${STOBJS} __archivebuild
lib${LIB}_p.a:: ${POBJS} __archivebuild
@ -588,7 +610,8 @@ lib${LIB}.so.${SHLIB_FULLVERSION}: ${SOLIB} ${DPADD} ${DPLIBC} \
rm -f lib${LIB}.so.${SHLIB_FULLVERSION}
${LIBCC} ${LDLIBC} -Wl,-x -shared ${SHLIB_SHFLAGS} ${_LDFLAGS.lib${LIB}} \
-o ${.TARGET} ${_LIBLDOPTS} \
-Wl,--whole-archive ${SOLIB} -Wl,--no-whole-archive ${_LDADD.lib${LIB}}
-Wl,--whole-archive ${SOLIB} -Wl,--no-whole-archive ${_LDADD.lib${LIB}} \
${${USE_BITCODE:Uno} == "yes":? -Wl,-plugin=/usr/pkg/lib/bfd-plugins/LLVMgold.so -Wl,-plugin-opt=-disable-opt:}
# We don't use INSTALL_SYMLINK here because this is just
# happening inside the build directory/objdir. XXX Why does
# this spend so much effort on libraries that aren't live??? XXX
@ -637,16 +660,18 @@ lint: ${LOBJS}
# use it here mimics the way it's used by the clean target in
# bsd.clean.mk.
#
clean: libclean1 libclean2 libclean3 libclean4 libclean5
clean: libclean1 libclean2 libclean3 libclean4 libclean5 libclean6
libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1
libclean2: .PHONY .MADE __cleanuse LIBCLEANFILES2
libclean3: .PHONY .MADE __cleanuse LIBCLEANFILES3
libclean4: .PHONY .MADE __cleanuse LIBCLEANFILES4
libclean5: .PHONY .MADE __cleanuse LIBCLEANFILES5
libclean6: .PHONY .MADE __cleanuse LIBCLEANFILES6
CLEANFILES+= a.out [Ee]rrs mklog *.core
# core conflicts with core/ in lib/liblwip
.if !defined(__MINIX)
CLEANFILES+=core
LIBCLEANFILES6+= lib${LIB}_bc.a ${BCOBJS} ${BCOBJS:=.tmp}
.endif
LIBCLEANFILES1+= lib${LIB}.a ${STOBJS} ${STOBJS:=.tmp}
LIBCLEANFILES2+= lib${LIB}_p.a ${POBJS} ${POBJS:=.tmp}
@ -659,6 +684,23 @@ LIBCLEANFILES5+= llib-l${LIB}.ln ${LOBJS}
# Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
libinstall::
.if ${USE_BITCODE:Uno} == "yes"
libinstall:: ${DESTDIR}${LIBDIR}/bc/lib${LIB}.a
.PRECIOUS: ${DESTDIR}${LIBDIR}/bc/lib${LIB}.a
.if ${MKUPDATE} == "no"
.if !defined(BUILD) && !make(all) && !make(lib${LIB}_bc.a)
${DESTDIR}${LIBDIR}/bc/lib${LIB}.a! .MADE
.endif
${DESTDIR}${LIBDIR}/bc/lib${LIB}.a! lib${LIB}_bc.a __archiveinstall
.else
.if !defined(BUILD) && !make(all) && !make(lib${LIB}_bc.a)
${DESTDIR}${LIBDIR}/bc/lib${LIB}.a: .MADE
.endif
${DESTDIR}${LIBDIR}/bc/lib${LIB}.a: lib${LIB}_bc.a __archiveinstall
.endif
.endif # ${USE_BITCODE:Uno} == "yes"
.if ${MKLINKLIB} != "no" && ${MKSTATICLIB} != "no"
libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
.PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a

View file

@ -56,6 +56,8 @@ USETOOLS?= never
HAVE_GOLD?= ${_HAVE_GOLD}
CFLAGS+= -DHAVE_GOLD=${_HAVE_GOLD}
AFLAGS+= -DHAVE_GOLD=${_HAVE_GOLD}
. else
MKBITCODE:=no
. endif
. endif # ${_HAVE_GOLD:U} == ""
. endif # ${USETOOLS:Uno} != "yes"
@ -984,7 +986,7 @@ _MKVARS.no= \
#MINIX-specific vars
_MKVARS.no+= \
MKIMAGEONLY MKSMALL
MKIMAGEONLY MKSMALL MKBITCODE
.if (${MACHINE_ARCH} == "earm")
_MKVARS.no+= \
MKWATCHDOG MKACPI MKAPIC MKDEBUGREG MKINSTALLBOOT MKPCI
@ -1141,7 +1143,7 @@ ${var}?= yes
#MINIX-specific vars
.for var in \
USE_WATCHDOG USE_ACPI USE_APIC USE_MCONTEXT USE_DEBUGREG USE_SYSDEBUG \
USE_LIVEUPDATE USE_STATECTL USE_TRACE USE_PCI
USE_LIVEUPDATE USE_STATECTL USE_TRACE USE_PCI USE_BITCODE
.if (${${var:S/USE_/MK/}} == "no")
${var}:= no
.else

View file

@ -315,9 +315,15 @@ _CCLINK.${_P}= ${CXX} ${_CCLINKFLAGS}
.endfor
# Language-independent definitions.
.if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
CFLAGS+= -flto
.endif
.for _P in ${PROGS} ${PROGS_CXX} # {
.if defined(__MINIX) && ${HAVE_GOLD:U} != ""
. if ${LD_STATIC:U} != "-static"
GOLDLINKERSCRIPT?= ${LDS_DYNAMIC_BIN}
. else
@ -418,13 +424,57 @@ CLEANFILES+= ${_P}.d
${OBJS.${_P}} ${LOBJS.${_P}}: ${DPSRCS}
${_P}: .gdbinit ${LIBCRT0} ${OBJS.${_P}} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${_DPADD.${_P}}
.if defined(__MINIX)
CLEANFILES+= ${_P}.opt.bcl ${_P}.bcl ${_P}.bcl.o
.endif # defined(__MINIX)
.if !commands(${_P})
.if ${USE_BITCODE:Uno} == "yes"
.if ${LLVM_PASS:UNO_PASS} != "NO_PASS"
_LLVM_PASS_ARGS= -load ${LLVM_PASS} ${LLVM_PASS_ARGS}
_TARGET_BCL= ${_P}.opt.bcl
.else
_TARGET_BCL= ${_P}.bcl
.endif # ${LLVM_PASS:UNO_PASS} != "NO_PASS"
${_P}.bcl: .gdbinit ${LIBCRT0} ${OBJS.${_P}} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${_DPADD.${_P}}
${_MKTARGET_LINK}
${_CCLINK.${_P}} \
-o ${.TARGET} \
-nostartfiles \
-L/usr/lib/bc \
${OBJS.${_P}} ${LLVM_LINK_ARGS} ${_LDADD.${_P}:N-shared} \
${_LDSTATIC.${_P}} \
-Wl,-r \
-Wl,-plugin=/usr/pkg/lib/bfd-plugins/LLVMgold.so,-plugin-opt=-disable-opt,-plugin-opt=-disable-inlining,-plugin-opt=emit-llvm
${_P}.opt.bcl: ${_P}.bcl ${LLVM_PASS}
${_MKTARGET_LINK}
opt -disable-opt ${_LLVM_PASS_ARGS} -o ${.TARGET} ${_P}.bcl
${_P}.bcl.o: ${_TARGET_BCL}
${_MKTARGET_LINK}
llc -O1 -filetype=obj -o ${.TARGET} ${.ALLSRC}
${_P}: ${_P}.bcl.o
${_MKTARGET_LINK}
${_CCLINK.${_P}} \
-o ${.TARGET} \
-L/usr/lib/bc \
${.TARGET}.bcl.o ${_LDADD.${_P}} \
${_LDSTATIC.${_P}} \
-Wl,--script,${GOLDLINKERSCRIPT.${_P}} \
-Wl,-plugin=/usr/pkg/lib/bfd-plugins/LLVMgold.so,-plugin-opt=-disable-opt,-plugin-opt=-disable-inlining
.else
${_P}: .gdbinit ${LIBCRT0} ${OBJS.${_P}} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${_DPADD.${_P}}
${_MKTARGET_LINK}
${_CCLINK.${_P}} \
${_LDFLAGS.${_P}} ${_LDSTATIC.${_P}} -o ${.TARGET} \
${OBJS.${_P}} ${_LDADD.${_P}} \
${_PROGLDOPTS}
.endif # ${USE_BITCODE:Uno} == "yes"
.if defined(CTFMERGE)
${CTFMERGE} ${CTFMFLAGS} -o ${.TARGET} ${OBJS.${_P}}
.endif
@ -434,6 +484,8 @@ ${_P}: .gdbinit ${LIBCRT0} ${OBJS.${_P}} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${_
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
.else
${_P}: .gdbinit ${LIBCRT0} ${OBJS.${_P}} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${_DPADD.${_P}}
.endif # !commands(${_P})
.endif # USE_COMBINE

View file

@ -16,7 +16,7 @@ CPP?= /usr/lib/cpp
.endif # defined(__MINIX)
unix?= We run NetBSD.
.SUFFIXES: .a .o .ln .s .S .c .cc .cpp .cxx .C .f .F .r .p .l .y .sh
.SUFFIXES: .a .o .bc .ln .s .S .c .cc .cpp .cxx .C .f .F .r .p .l .y .sh
.LIBS: .a

View file

@ -124,6 +124,7 @@ LIBKERN= ${KERNLIB}
# When using gold linker, specify the linker script
GOLDLINKERSCRIPT?= ${LDS_N}
USE_BITCODE=no
# use MINIX minc
LIBKERN= ${DESTDIR}/usr/lib/libminc.a

View file

@ -129,6 +129,7 @@ LIBKERN= ${KERNLIB}
# When using gold linker, specify the linker script
GOLDLINKERSCRIPT?= ${LDS_N}
USE_BITCODE=no
# use MINIX minc
LIBKERN= ${DESTDIR}/usr/lib/libminc.a

View file

@ -13,6 +13,8 @@
# building. See library's Makefile for more details about
# supported flags and their default values.
USE_BITCODE=no
# Default values:
I386DST?= ${.OBJDIR}/lib/i386

View file

@ -56,9 +56,11 @@
__asm(".global " _C_LABEL_STRING(#alias) "\n" \
_C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
#if defined(__minix) && !defined(__weak_alias) /* For bitcode support */
#define __weak_alias(alias,sym) \
__asm(".weak " _C_LABEL_STRING(#alias) "\n" \
_C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
#endif
/* Do not use __weak_extern, use __weak_reference instead */
#define __weak_extern(sym) \

View file

@ -39,7 +39,8 @@ LDADD.test72+= -lminixfs
PROGS += testvm
OBJS.testvm+= testcache.o
LDADD.testvm+= -lsys -ltimers -lminlib -static
LDFLAGS.testvm+= -static
LDADD.testvm+= -lsys -ltimers -lminlib
FILES += testvm.conf
@ -79,7 +80,10 @@ LDSTATIC= -dynamic
# use the shared linkerscript for mod when using the gold linker
GOLDLINKERSCRIPT.mod?= ${${HAVE_GOLD:Uno} != "no":? ${LDS_SHARED_LIB} :}
GOLDLINKERSCRIPT=
LDADD.mod+= ${${USE_BITCODE:Uno} != "no":? -shared:}
# test57loop.S is not linked into the .bcl file.
# This way, we can link it in when linking the final binary
LDADD.test57+= ${${USE_BITCODE:Uno} != "no":? test57loop.o -Wl,-allow-multiple-definition:}
# Add test that must be linked dynamically, and its dynamically loaded
# module