]> Zhao Yanbai Git Server - minix.git/commitdiff
LLVM bitcode for almost the whole source tree 55/655/3
authorAnton Kuijsten <anton@kuijsten.info>
Mon, 17 Jun 2013 14:51:49 +0000 (14:51 +0000)
committerLionel Sambuc <lionel@minix3.org>
Tue, 18 Jun 2013 08:49:53 +0000 (10:49 +0200)
Change-Id: Ibc6f89de112e0649c3a3bfe49c2baa2ed0746212

17 files changed:
distrib/sets/lists/minix/mi
drivers/memory/Makefile
drivers/ramdisk/Makefile
etc/mtree/NetBSD.dist.base
kernel/Makefile
lib/libc/Makefile
libexec/ld.elf_so/Makefile
share/mk/bsd.dep.mk
share/mk/bsd.lib.mk
share/mk/bsd.own.mk
share/mk/bsd.prog.mk
share/mk/sys.mk
sys/arch/i386/stand/boot/Makefile.boot
sys/arch/i386/stand/bootxx/Makefile.bootxx
sys/arch/i386/stand/lib/Makefile.inc
sys/sys/cdefs_elf.h
test/Makefile

index 549c80ea6f887634bae778e2971ac717427c95fc..bd4a436e317c9647d5acbb74f62f58d0d3be98fd 100644 (file)
 ./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
index e8a6f5a27035f60816716f93a403b3cb3661a97a..4ca573381eb92a3e939caac74111942dfeb3dcb0 100644 (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}
index 280c770435809ce2dac0e7094efa98ea5a5b3e23..3c2e1759bf810d9db5487340e87b397d6600a0f1 100644 (file)
@@ -2,6 +2,8 @@
 
 .include <bsd.own.mk>
 
+USE_BITCODE:=no
+
 install:
 
 all:
index 675798897f40cc05e8898e07ee4716e16be27100..ff4712b85222b452eadf4b5961318a46c46a4ceb 100644 (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
index f7623664fca5bcbc78c8f5023118b99bd112fec4..c16eadcc93c18f68cbbfa8e3a9bbcf3f6bf4f1cf 100644 (file)
@@ -1,6 +1,8 @@
 # Makefile for kernel
 .include <bsd.own.mk>
 
+USE_BITCODE:=no
+
 BINDIR=        /usr/sbin
 MAN=
 PROG=  kernel
index 6c5bbf8ea9638f7c4bb117c8aaeff207cd9a865a..3d42587499f67cbf14443a3997c68c4da3b78106 100644 (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")
index 9c3551b62f1840c3107797dd48b34094aecb14cd..8a2a160774a24b440a159da1306412c7a96b09bc 100644 (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
index 71de88ecfb14ada157743d5a8ee3e5c80193b363..5101b1b85f06426917f77d1ebb75604eb843bd62 100644 (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}
index c951456f16d29c34ec6964f9bf49458658dddee8..1dc2433d5b2de21b8dc90870794ebbccf049b755 100644 (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
index 0e6dc81ed5d6afc49c7aa784774a41c20f15a5c3..b5a46c88bdf0fed148bda8f1491c23d5c426fbaa 100644 (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
index 237b9b85680e1171a5d6fbd87beb7c65dd9ed2cd..6587b1da13b64cefbe06e75679594a4c57647005 100644 (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
 
index 88a9ec20dcf76e89b3df09a2746a2ee135771a0c..8f1a4419ee3ad90f54a88058766994b9a10b56c5 100644 (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
 
index 5390ed184c5a1b6eeff2aa9a124f5f4e1d748066..ecf055221c7108202c96cc881f25b170fa68c6d6 100644 (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
index e5eaee559e35272d1c360b2a4c3609863d5d552c..3bf1916cbaa2f29a3a5b4c3198a4eb8a467a1f73 100644 (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
index 754a3852535348c4512ca57159dbd97f6b41a3f6..b4a4082443153808c60be926f09c373b1a36dc5a 100644 (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
 
index 96cec8e24bcec2737139022590d8030955a379f6..46e8a2532b90226393ffc48207f4fef5a20dfd1b 100644 (file)
     __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)                                              \
index 191c5acd2506578938dae3ce840c01c0ade39f7c..58a1f7add14d4f556f7605fe854db9f724a7c700 100644 (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