diff options
author | John Levon <john.levon@joyent.com> | 2018-08-31 15:22:38 +0000 |
---|---|---|
committer | Dan McDonald <danmcd@joyent.com> | 2018-10-03 20:34:40 -0400 |
commit | aa9ef484c6f8ecee85dfefdb4970c50cfa2db302 (patch) | |
tree | 784f6d1dc71a84c6409cb09a0fbfd17adaee779e | |
parent | bdc560ab289d67ddebad9a2146fd36c2662d88b1 (diff) | |
download | illumos-joyent-aa9ef484c6f8ecee85dfefdb4970c50cfa2db302.tar.gz |
9128 cw(1onbld) should be able to run multiple shadows
9129 file-locking tests shouldn't build multiple source files in one compiler invocation
9130 DTrace tst.gcc.d isn't useful
9132 cw(1onbld) shouldn't shadow pure preprocessing
Portions contributed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Andy Fiddaman <omnios@citrus-it.net>
Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r-- | usr/src/Makefile | 43 | ||||
-rw-r--r-- | usr/src/Makefile.master | 90 | ||||
-rw-r--r-- | usr/src/Makefile.master.64 | 3 | ||||
-rw-r--r-- | usr/src/cmd/dtrace/test/tst/common/Makefile | 6 | ||||
-rw-r--r-- | usr/src/cmd/dtrace/test/tst/common/pid/tst.gcc.c | 63 | ||||
-rw-r--r-- | usr/src/cmd/dtrace/test/tst/common/pid/tst.gcc.d | 52 | ||||
-rw-r--r-- | usr/src/common/mapfiles/gen/Makefile | 16 | ||||
-rw-r--r-- | usr/src/pkg/manifests/system-dtrace-tests.mf | 2 | ||||
-rw-r--r-- | usr/src/test/os-tests/tests/file-locking/Makefile | 18 | ||||
-rw-r--r-- | usr/src/tools/cw/Makefile | 19 | ||||
-rw-r--r-- | usr/src/tools/cw/cw.1onbld | 386 | ||||
-rw-r--r-- | usr/src/tools/cw/cw.c | 465 | ||||
-rw-r--r-- | usr/src/tools/env/illumos.sh | 35 | ||||
-rw-r--r-- | usr/src/tools/scripts/nightly.sh | 2 |
14 files changed, 525 insertions, 675 deletions
diff --git a/usr/src/Makefile b/usr/src/Makefile index ab1aedfc46..56dbdff6b0 100644 --- a/usr/src/Makefile +++ b/usr/src/Makefile @@ -25,7 +25,7 @@ # Copyright 2014 Garrett D'Amore <garrett@damore.org> # Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. # Copyright 2016 Toomas Soome <tsoome@me.com> -# Copyright 2017 Joyent, Inc. +# Copyright 2018 Joyent, Inc. # Copyright 2018 OmniOS Community Edition (OmniOSce) Association. # @@ -237,47 +237,12 @@ cscope.out tags: FRC FRC: -# -# Targets for reporting compiler versions; nightly uses these. -# - +# used by nightly cc-version: - @if $($(MACH)_CC) -_versions >/dev/null 2>/dev/null; then \ - $(ECHO) 32-bit compiler; \ - $(ECHO) $($(MACH)_CC); \ - $($(MACH)_CC) -_versions 2>&1 | \ - $(EGREP) '^(cw|cc|gcc|primary|shadow)'; \ - else \ - __COMPILER=`$($(MACH)_CC) -_compiler 2>/dev/null || $(TRUE)`;\ - if [ -z "$$__COMPILER" ]; then \ - $(ECHO) No 32-bit compiler found; \ - exit 1; \ - else \ - $(ECHO) 32-bit compiler; \ - $(ECHO) $($(MACH)_CC); \ - $(ECHO) $$__COMPILER; \ - $($(MACH)_CC) -V 2>&1 | head -1; \ - fi; \ - fi + @$(CW) --versions $(CW_CC_COMPILERS) 2>&1 +# for older nightlies cc64-version: - @if $($(MACH64)_CC) -_versions >/dev/null 2>/dev/null; then \ - $(ECHO) 64-bit compiler; \ - $(ECHO) $($(MACH64)_CC); \ - $($(MACH64)_CC) -_versions 2>&1 | \ - $(EGREP) '^(cw|cc|gcc|primary|shadow)'; \ - else \ - __COMPILER=`$($(MACH64)_CC) -_compiler 2>/dev/null || $(TRUE)`;\ - if [ -z "$$__COMPILER" ]; then \ - $(ECHO) No 64-bit compiler found; \ - exit 1; \ - else \ - $(ECHO) 64-bit compiler; \ - $(ECHO) $($(MACH64)_CC); \ - $(ECHO) $$__COMPILER; \ - $($(MACH64)_CC) -V 2>&1 | head -1; \ - fi; \ - fi java-version: @if [ -x "$(JAVAC)" ]; then \ diff --git a/usr/src/Makefile.master b/usr/src/Makefile.master index 1cada73cd5..3d9cf145b1 100644 --- a/usr/src/Makefile.master +++ b/usr/src/Makefile.master @@ -489,15 +489,13 @@ CTF_FLAGS = $(CTF_FLAGS_32) # # Flags used with genoffsets # -GOFLAGS = -_noecho \ - $(CALLSYMS) \ - $(CDWARFSTR) +GOFLAGS = $(CALLSYMS) $(CDWARFSTR) OFFSETS_CREATE = $(GENOFFSETS) -s $(CTFSTABS) -r $(CTFCONVERT) \ - $(CC) $(GOFLAGS) $(CFLAGS) $(CPPFLAGS) + $(CW) --noecho $(CW_CC_COMPILERS) -- $(GOFLAGS) $(CFLAGS) $(CPPFLAGS) OFFSETS_CREATE64 = $(GENOFFSETS) -s $(CTFSTABS) -r $(CTFCONVERT) \ - $(CC) $(GOFLAGS) $(CFLAGS64) $(CPPFLAGS) + $(CW) --noecho $(CW_CC_COMPILERS) -- $(GOFLAGS) $(CFLAGS64) $(CPPFLAGS) # # tradeoff time for space (smaller is better) @@ -693,7 +691,7 @@ MAPFILE.INT = mapfile-intf # LDLIBS32 = $(ENVLDLIBS1) $(ENVLDLIBS2) $(ENVLDLIBS3) LDLIBS32 += $(ADJUNCT_PROTO:%=-L%/usr/lib -L%/lib) -LDLIBS.cmd = $(LDLIBS32) +LDLIBS.cmd = $(LDLIBS32) LDLIBS.lib = $(LDLIBS32) LDLIBS64 = $(ENVLDLIBS1:%=%/$(MACH64)) \ @@ -786,6 +784,15 @@ SPRO_ROOT= $(BUILD_TOOLS)/SUNWspro SPRO_VROOT= $(SPRO_ROOT)/SS12 GNU_ROOT= /usr +$(__GNUC)PRIMARY_CC= gcc4,$(GNUC_ROOT)/bin/gcc,gnu +$(__SUNC)PRIMARY_CC= studio12,$(SPRO_VROOT)/bin/cc,sun +$(__GNUC)PRIMARY_CCC= gcc4,$(GNUC_ROOT)/bin/g++,gnu +$(__SUNC)PRIMARY_CCC= studio12,$(SPRO_VROOT)/bin/CC,sun + +CW_CC_COMPILERS= $(PRIMARY_CC:%=--primary %) $(SHADOW_CCS:%=--shadow %) +CW_CCC_COMPILERS= $(PRIMARY_CCC:%=--primary %) $(SHADOW_CCCS:%=--shadow %) + + # Till SS12u1 formally becomes the NV CBE, LINT is hard # coded to be picked up from the $SPRO_ROOT/sunstudio12.1/ # location. Impacted variables are sparc_LINT, sparcv9_LINT, @@ -796,42 +803,31 @@ GNU_ROOT= /usr # Specify platform compiler versions for languages # that we use (currently only c and c++). # -sparc_CC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_cc -$(__GNUC)sparc_CC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc -sparc_CCC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_CC -$(__GNUC)sparc_CCC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_g++ -sparc_CPP= /usr/ccs/lib/cpp +CW= $(ONBLD_TOOLS)/bin/$(MACH)/cw + +BUILD_CC= $(CW) $(CW_CC_COMPILERS) -- +BUILD_CCC= $(CW) -C $(CW_CCC_COMPILERS) -- +BUILD_CPP= /usr/ccs/lib/cpp +BUILD_LD= /usr/ccs/bin/ld +BUILD_LINT= $(SPRO_ROOT)/sunstudio12.1/bin/lint + +$(MACH)_CC= $(BUILD_CC) +$(MACH)_CCC= $(BUILD_CCC) +$(MACH)_CPP= $(BUILD_CPP) +$(MACH)_LD= $(BUILD_LD) +$(MACH)_LINT= $(BUILD_LINT) +$(MACH64)_CC= $(BUILD_CC) +$(MACH64)_CCC= $(BUILD_CCC) +$(MACH64)_CPP= $(BUILD_CPP) +$(MACH64)_LD= $(BUILD_LD) +$(MACH64)_LINT= $(BUILD_LINT) + sparc_AS= /usr/ccs/bin/as -xregsym=no -sparc_LD= /usr/ccs/bin/ld -sparc_LINT= $(SPRO_ROOT)/sunstudio12.1/bin/lint - -sparcv9_CC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_cc -$(__GNUC64)sparcv9_CC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc -sparcv9_CCC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_CC -$(__GNUC64)sparcv9_CCC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_g++ -sparcv9_CPP= /usr/ccs/lib/cpp -sparcv9_AS= /usr/ccs/bin/as -xregsym=no -sparcv9_LD= /usr/ccs/bin/ld -sparcv9_LINT= $(SPRO_ROOT)/sunstudio12.1/bin/lint - -i386_CC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_cc -$(__GNUC)i386_CC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc -i386_CCC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_CC -$(__GNUC)i386_CCC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_g++ -i386_CPP= /usr/ccs/lib/cpp +sparcv9_AS= $($(MACH)_AS) + i386_AS= /usr/ccs/bin/as $(__GNUC)i386_AS= $(ONBLD_TOOLS)/bin/$(MACH)/aw -i386_LD= /usr/ccs/bin/ld -i386_LINT= $(SPRO_ROOT)/sunstudio12.1/bin/lint - -amd64_CC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_cc -$(__GNUC64)amd64_CC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc -amd64_CCC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_CC -$(__GNUC64)amd64_CCC= $(ONBLD_TOOLS)/bin/$(MACH)/cw -_g++ -amd64_CPP= /usr/ccs/lib/cpp amd64_AS= $(ONBLD_TOOLS)/bin/$(MACH)/aw -amd64_LD= /usr/ccs/bin/ld -amd64_LINT= $(SPRO_ROOT)/sunstudio12.1/bin/lint NATIVECC= $($(NATIVE_MACH)_CC) NATIVECCC= $($(NATIVE_MACH)_CCC) @@ -850,12 +846,6 @@ AS= $(NATIVEAS) LD= $(NATIVELD) LINT= $(NATIVELINT) -# The real compilers used for this build -CW_CC_CMD= $(CC) -_compiler -CW_CCC_CMD= $(CCC) -_compiler -REAL_CC= $(CW_CC_CMD:sh) -REAL_CCC= $(CW_CCC_CMD:sh) - # Pass -Y flag to cpp (method of which is release-dependent) CCYFLAG= -Y I, @@ -911,8 +901,8 @@ C_BIGPICFLAGS64 = $($(MACH64)_C_BIGPICFLAGS) # CC requires there to be no space between '-K' and 'pic' or 'PIC'. sparc_CC_PICFLAGS = -Kpic sparcv9_CC_PICFLAGS = -KPIC -i386_CC_PICFLAGS = -Kpic -amd64_CC_PICFLAGS = -Kpic +i386_CC_PICFLAGS = -Kpic +amd64_CC_PICFLAGS = -Kpic CC_PICFLAGS = $($(MACH)_CC_PICFLAGS) CC_PICFLAGS64 = $($(MACH64)_CC_PICFLAGS) @@ -964,7 +954,7 @@ CTFCONVERT_O = $(CTFCONVERT) $(CTFCVTFLAGS) $@ # The following list of macros are used in the definition of RELEASE_CM # which is used to label all binaries in the build: # -# RELEASE Specific release of the build, eg: 5.2 +# RELEASE Specific release of the build, eg: 5.2 # RELEASE_MAJOR Major version number part of $(RELEASE) # RELEASE_MINOR Minor version number part of $(RELEASE) # VERSION Version of the build (alpha, beta, Generic) @@ -991,7 +981,7 @@ $(RELEASE_BUILD)PROCESS_COMMENT= @?${MCS} -d -a $(RELEASE_CM) STRIP_STABS= $(STRIP) -x $@ $(SRCDBGBLD)STRIP_STABS= : -POST_PROCESS_O= +POST_PROCESS_O= POST_PROCESS_A= POST_PROCESS_SO= $(PROCESS_COMMENT) $@ ; $(STRIP_STABS) ; \ $(ELFSIGN_OBJECT) @@ -1090,8 +1080,8 @@ PKGPUBLISHER_NONREDIST= on-extra # build the catalogue with awk(1). .sh.po .ksh.po: - $(SED) -n -e ":a" \ - -e "h" \ + $(SED) -n -e ":a" \ + -e "h" \ -e "s/.*gettext *\(\"[^\"]*\"\).*/\1/p" \ -e "x" \ -e "s/\(.*\)gettext *\"[^\"]*\"\(.*\)/\1\2/" \ diff --git a/usr/src/Makefile.master.64 b/usr/src/Makefile.master.64 index f671406fef..a06525bd6d 100644 --- a/usr/src/Makefile.master.64 +++ b/usr/src/Makefile.master.64 @@ -63,9 +63,6 @@ AS= $($(MACH64)_AS) LD= $($(MACH64)_LD) LINT= $($(MACH64)_LINT) -REAL_CC= $(CW_CC_CMD:sh) -REAL_CCC= $(CW_CCC_CMD:sh) - BUILD.SO= $(CC) $(CFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \ $(PICS) $(EXTPICS) -L $(ROOTLIBDIR64) $(LDLIBS) diff --git a/usr/src/cmd/dtrace/test/tst/common/Makefile b/usr/src/cmd/dtrace/test/tst/common/Makefile index d7ed139203..808d0e4e8e 100644 --- a/usr/src/cmd/dtrace/test/tst/common/Makefile +++ b/usr/src/cmd/dtrace/test/tst/common/Makefile @@ -57,8 +57,6 @@ sysevent/tst.post_chan.exe := LDLIBS += -lsysevent ustack/tst.bigstack.exe := COPTFLAG += -xO1 -GCC = $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc - nfs/%.o: $(SNOOPDIR)/%.c $(COMPILE.c) -o $@ $< -I$(SNOOPDIR) $(POST_PROCESS_O) @@ -75,10 +73,6 @@ nfs/tst.call3.exe: nfs/tst.call3.o nfs/$(RPCSVCOBJS) $(LDLIBS) -lnsl -lrpcsvc $(POST_PROCESS) ; $(STRIP_STABS) -pid/tst.gcc.exe: pid/tst.gcc.c - $(GCC) -o pid/tst.gcc.exe pid/tst.gcc.c $(LDFLAGS) $(LDLIBS) - $(POST_PROCESS) ; $(STRIP_STABS) - json/tst.usdt.o: json/usdt.h json/usdt.h: json/usdt.d diff --git a/usr/src/cmd/dtrace/test/tst/common/pid/tst.gcc.c b/usr/src/cmd/dtrace/test/tst/common/pid/tst.gcc.c deleted file mode 100644 index 4fe7bb45cb..0000000000 --- a/usr/src/cmd/dtrace/test/tst/common/pid/tst.gcc.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#include <spawn.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/wait.h> - -void -go(void) -{ - pid_t pid; - - (void) posix_spawn(&pid, "/usr/bin/ls", NULL, NULL, NULL, NULL); - - (void) waitpid(pid, NULL, 0); -} - -void -intr(int sig) -{ -} - -int -main(int argc, char **argv) -{ - struct sigaction sa; - - sa.sa_handler = intr; - sigfillset(&sa.sa_mask); - sa.sa_flags = 0; - - (void) sigaction(SIGUSR1, &sa, NULL); - - for (;;) { - go(); - } - - return (0); -} diff --git a/usr/src/cmd/dtrace/test/tst/common/pid/tst.gcc.d b/usr/src/cmd/dtrace/test/tst/common/pid/tst.gcc.d deleted file mode 100644 index f119098f03..0000000000 --- a/usr/src/cmd/dtrace/test/tst/common/pid/tst.gcc.d +++ /dev/null @@ -1,52 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * ASSERTION: test that we can trace every instruction safely for gcc - * compiled apps. - * - * SECTION: pid provider - * - */ - -BEGIN -{ - /* - * Let's just do this for 2 seconds. - */ - timeout = timestamp + 2000000000; -} - -pid$1:a.out:: -{} - -profile:::tick-4 -/timestamp > timeout/ -{ - exit(0); -} diff --git a/usr/src/common/mapfiles/gen/Makefile b/usr/src/common/mapfiles/gen/Makefile index 6990ae59f9..6b22b34116 100644 --- a/usr/src/common/mapfiles/gen/Makefile +++ b/usr/src/common/mapfiles/gen/Makefile @@ -27,13 +27,12 @@ include $(SRC)/Makefile.master -FILES= \ - $(MACH)_cc_map.noexeglobs \ - $(MACH)_gcc_map.noexeglobs -$(BUILD64)FILES += \ - $(MACH64)_cc_map.noexeglobs \ - $(MACH64)_gcc_map.noexeglobs +$(__GNUC)FILES= $(MACH)_gcc_map.noexeglobs +$(__SUNC)FILES= $(MACH)_cc_map.noexeglobs + +$(__GNUC)$(BUILD64)FILES += $(MACH64)_gcc_map.noexeglobs +$(__SUNC)$(BUILD64)FILES += $(MACH64)_cc_map.noexeglobs SYMS1= syms.1 SYMS2= syms.2 @@ -73,12 +72,9 @@ clobber: clean $(MACH)_cc_map.noexeglobs := LINK = $(LINK.c) $(MACH64)_cc_map.noexeglobs := LINK = $(LINK64.c) - -$(MACH)_gcc_map.noexeglobs := CC = $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc $(MACH)_gcc_map.noexeglobs := LINK = $(LINK.c) -$(MACH64)_gcc_map.noexeglobs := CC = $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc $(MACH64)_gcc_map.noexeglobs := LINK = $(LINK64.c) - + # This generic target creates two dynamic executables from an empty "main" # program. These objects are not executed, but are analyzed to determine the # global symbols each provides. diff --git a/usr/src/pkg/manifests/system-dtrace-tests.mf b/usr/src/pkg/manifests/system-dtrace-tests.mf index 2fc1affe39..4dee59e903 100644 --- a/usr/src/pkg/manifests/system-dtrace-tests.mf +++ b/usr/src/pkg/manifests/system-dtrace-tests.mf @@ -1154,8 +1154,6 @@ file path=opt/SUNWdtrt/tst/common/pid/tst.float.d mode=0444 file path=opt/SUNWdtrt/tst/common/pid/tst.float.exe mode=0555 file path=opt/SUNWdtrt/tst/common/pid/tst.fork.d mode=0444 file path=opt/SUNWdtrt/tst/common/pid/tst.fork.exe mode=0555 -file path=opt/SUNWdtrt/tst/common/pid/tst.gcc.d mode=0444 -file path=opt/SUNWdtrt/tst/common/pid/tst.gcc.exe mode=0555 file path=opt/SUNWdtrt/tst/common/pid/tst.killonerror.ksh mode=0444 file path=opt/SUNWdtrt/tst/common/pid/tst.main.ksh mode=0444 file path=opt/SUNWdtrt/tst/common/pid/tst.manypids.ksh mode=0444 diff --git a/usr/src/test/os-tests/tests/file-locking/Makefile b/usr/src/test/os-tests/tests/file-locking/Makefile index aecf20edb4..2f8c6762ad 100644 --- a/usr/src/test/os-tests/tests/file-locking/Makefile +++ b/usr/src/test/os-tests/tests/file-locking/Makefile @@ -16,7 +16,7 @@ include $(SRC)/cmd/Makefile.cmd include $(SRC)/test/Makefile.com -UTILS = util.c +OBJECTS=util.o runtests.32.o runtests.64.o acquire-lock.32.o acquire-lock.64.o PROGS = \ runtests \ @@ -24,7 +24,7 @@ PROGS = \ CSTD = $(CSTD_GNU99) -SRCS = $(PROGS:%=%.c) $(UTILS) +SRCS = $(PROGS:%=%.c) $(UTILS:%.o=%.c) PROGS32 = $(PROGS:%=%.32) PROGS64 = $(PROGS:%=%.64) @@ -61,12 +61,18 @@ $(ROOTOPTDIR)/%: %.ksh %.ln: %.c $(LINT.c) $< $(UTILS) $(LDLIBS) -%.64: %.c - $(LINK64.c) -o $@ $< $(UTILS) $(LDLIBS64) +%.64.o: %.c + $(COMPILE64.c) $< -o $@ + +%.32.o: %.c + $(COMPILE.c) $< -o $@ + +%.64: %.64.o util.64.o + $(LINK64.c) -o $@ $< util.64.o $(LDLIBS64) $(POST_PROCESS) -%.32: %.c - $(LINK.c) -o $@ $< $(UTILS) $(LDLIBS) +%.32: %.32.o util.32.o + $(LINK.c) -o $@ $< util.32.o $(LDLIBS) $(POST_PROCESS) clobber: diff --git a/usr/src/tools/cw/Makefile b/usr/src/tools/cw/Makefile index 8764d1cd18..e5100189d2 100644 --- a/usr/src/tools/cw/Makefile +++ b/usr/src/tools/cw/Makefile @@ -22,6 +22,7 @@ # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # +# Copyright 2018 Joyent, Inc. PROG = cw @@ -39,18 +40,13 @@ CFLAGS += $(CCVERBOSE) # Override CFLAGS. This is needed only for bootstrap of cw. $(__GNUC)CFLAGS= -O -D__sun -Wall -Wno-unknown-pragmas -Werror \ - -std=gnu89 -nodefaultlibs -$(__SUNC)CFLAGS= -xspace -Xa -xildoff -errtags=yes -errwarn=%all \ - -xc99=%none -W0,-xglobalstatic -v + -std=gnu99 -nodefaultlibs +$(__SUNC)CFLAGS= -xspace -Xa -xildoff -errtags=yes -errwarn=%all \ + -xc99=%all -W0,-xglobalstatic -v $(__GNUC)LDLIBS += -lc -$(__GNUC)LDFLAGS= $(MAPFILE.NES:%=-Wl,-M%) - -CPPFLAGS += -DDEFAULT_CC_DIR='"$(SPRO_VROOT)/bin"' -CPPFLAGS += -DDEFAULT_GCC_DIR='"$(GNUC_ROOT)/bin"' -CPPFLAGS += -DDEFAULT_CPLUSPLUS_DIR='"$(SPRO_VROOT)/bin"' -CPPFLAGS += -DDEFAULT_GPLUSPLUS_DIR='"$(GNUC_ROOT)/bin"' +$(__GNUC)LDFLAGS= $(MAPFILE.NES:%=-Wl,-M%) $(ROOTONBLDMAN1ONBLDFILES) := FILEMODE= 644 @@ -67,4 +63,9 @@ lint: lint_PROG clean: +# +# Not run by default: bootstrap... +check: + $(ROOTONBLDBINMACH)/mandoc -Tlint -Wwarning $(MAN1ONBLDFILES) + include ../Makefile.targ diff --git a/usr/src/tools/cw/cw.1onbld b/usr/src/tools/cw/cw.1onbld index 86923029d2..da3f224cd2 100644 --- a/usr/src/tools/cw/cw.1onbld +++ b/usr/src/tools/cw/cw.1onbld @@ -21,215 +21,201 @@ .\" Copyright 2010 Sun Microsystems, Inc. All rights reserved. .\" Use is subject to license terms. .\" -.TH CW 1ONBLD "August 16, 2018" -.SH NAME -.I cw -\- invoke one or more compilers with argument translation -.SH SYNOPSIS -\fBcw {-_cc|-_gcc|-_CC|-_g++} [options] [compiler args...]\fP -.SH DESCRIPTION -.LP -.I cw -is a facility for invoking one or more compilers, providing -translation from Sun Studio arguments as appropriate. This allows -the use of arbitrary compilers without the need to alter large -numbers of makefiles. A mode called shadow compilation, the default, -invokes two different compilers so that warnings and errors may be -obtained from both. See SHADOW COMPILATION for details. This version -of cw supports Sun Studio 10 and 11 and gcc 3.4.3 as shipped in -Solaris. -.SH ARGUMENTS -.LP -Exactly one of the following arguments is required, and must appear -immediately following \fBcw\fP in the argument list: -.TP 4 -.B \-_cc -Select Sun Studio C (cc) as the primary compiler. -.TP 4 -.B \-_gcc -Select GNU C (gcc) as the primary compiler. -.TP 4 -.B \-_CC -Select Sun Studio C++ (CC) as the primary compiler. -.TP 4 -.B \-_g++ -Select GNU C++ (g++) as the primary compiler. -.SH OPTIONS -.LP -The following options are supported: -.TP 4 -.B \-_compiler -Do not invoke any compiler; instead, write to standard output the -full path to the primary compiler that would be invoked. If this -option is given, it must appear immediately following the compiler -selection argument, and all other options will be disregarded. -.TP 4 -.B \-_versions -Print the cw version, followed in turn by the path to and versions -of each compiler which would be invoked. If this option is given, -it must appear immediately following the compiler selection argument, -and all other options will be disregarded. -.TP 4 -.B \-_noecho -Normally, cw writes to standard error the actual compiler commands -invoked, each prefixed with '+'. This option suppresses these -messages. -.TP 4 -.B \-_cc=,\-_gcc=,\-_CC=,\-g++= -Pass compiler-dependent options. See ARGUMENT TRANSLATION. -.SH SHADOW COMPILATION -.LP -Unless otherwise directed by environment variables (see ENVIRONMENT), -\fBcw\fP will invoke both the compiler specified by its first argument -(primary) and a designated alternate compiler (shadow). The primary -compiler will be invoked with the arguments given to cw, translated -as described in ARGUMENT TRANSLATION. The secondary compiler will be -invoked in parallel with the primary (but see ENVIRONMENT); its -arguments will likewise be translated. However, the shadow compiler's -arguments will also be modified as follows: -.TP 4 -.B 1. -If none of \fI-c\fP, \fI-E\fP, \fI-P\fP, or \fI-S\fP appears in the -argument list (that is, linking is attempted), the shadow compiler -will not be invoked. This is because the objects built with that -compiler which would be linked have been previously discarded. -.TP 4 -.B 2. -If an option of the form \fI-ofilename\fP was provided, it will be -replaced by two options of the form \fI-o\fP \fItempfile\fP. -.TP 4 -.B 3. -If the option \fI-o\fP was provided, its following argument will be -replaced by \fItempfile\fP. -.TP 4 -.B 4. -If neither of the above options was provided, two options of the -form \fI-o\fP \fItempfile\fP will be added to the end of the argument -list used to invoke the shadow compiler. -.LP -In all three cases, \fItempfile\fP is the name of a temporary file -which will be removed by \fBcw\fP before it terminates. -.LP -When shadow compilation is in effect, \fBcw\fP writes to standard error -each compiler's standard error output following its argument list. -Messages from the two compilers will not be interleaved. If \fBcw\fP +.\" Copyright 2018 Joyent, Inc. +.\" +.Dd September 4, 2018 +.Dt CW 1ONBLD +.Os +.Sh NAME +.Nm cw +.Nd invoke one or more compilers with argument translation +.Sh SYNOPSIS +.Nm cw +.Op Fl C +.Op Fl -versions +.Op Fl -noecho +.Fl -primary Ar compiler +.Op Fl -shadow Ar compiler ... +.Fl - +.Ar compiler args ... +.Sh DESCRIPTION +.Nm cw +is a facility for invoking one or more compilers, providing translation from +Sun style arguments as appropriate. +This allows the use of arbitrary compilers without the need to alter large +numbers of makefiles. +A mode called shadow compilation invokes multiple compilers so that warnings +and errors may be obtained from all of them. +See +.Sx SHADOW COMPILATION +for details. +This version of cw supports compilers with both Sun Studio 12 and GCC-style +command lines. +.Sh ARGUMENTS +Both the +.Fl -primary +and +.Fl -shadow +parameters take a +.Em compiler specification . +This is a comma-separated list of the form +.Ar name,executable,style +Where +.Ar name +is a name for the compiler, +.Ar executable +is the full path to the compiler executable, and +.Ar style +is the style of command-line options the compiler expects, either +.Em sun +or +.Em gnu . +.Bl -tag -width indent +.It Fl -primary Ar compiler +Specify the compiler to be used primarily (that which is used for link-editing +and pre-processing, and whos objects we deliver). +.It Fl -shadow Ar compiler +Specify a shadow compiler, which builds sources for the sake of checking code +quality and compatibility, but has its output discarded. +.It Fl -noecho +Do not echo the actual command line of any compilers invoked. +.It Fl -versions +Request from each configured primary and shadow compiler its version +information. +.It Fl C +The sources being compiled are C++. This is necessary as it affects the +translation of compiler arguments. +.It Fl - +Arguments intended for the compilers themselves must be separated from those +of +.Nm cw +by a +.Fl - . +.It Fl _name= +.It Fl _style= +Parameters intended for the compiler be guarded with options of the form +.Fl _name= +and +.Fl _style= +Where +.Em name +and +.Em style +are those passed to +.Fl -primary +and +.Fl -shadow +this allows certain flags to be passed only to certain classes of compiler. +.Pp +For historical reasons, the +.Fl _style= +option is also translated such that a style of +.Em sun +may use the flag +.Fl _cc= +and a style of +.Em gnu +may use the flag +.Fl _gcc= , +and when the +.Fl C +option is given and C++ is in use the style of +.Em sun +may use the flag +.Fl _CC= +and the style of +.Em gnu +may use the flag +.Fl _g++= . +.El +.Sh SHADOW COMPILATION +If +.Fl -shadow +compilers are specified +.Nm cw +will invoke each shadow compiler, with the outputs modified (as well as any +translation for compiler style) as follows: +.Bl -enum +.It +If neither of +.Fl c , +.Fl S +appears in the argument list (that is, linking is attempted or only the +pre-processor is invoked), the shadow compilers will not be invoked. +.It +If the +.Fl o Ar filename +option was provided, with or without a separating space, it will be replaced with +.Fl o Ar tempfile +.It +If the option +.Fl o +was not provided, +.Fl o Ar tempfile +will be added to the end of the argument list used to invoke +the shadow compilers. +.El +When shadow compilation is in effect, +.Nm cw +writes to standard error each compiler's standard error output following its +argument list. +Messages from the compilers will not be interleaved. +If +.Nm cw is used to invoke the preprocessor and no output location is specified, -\fBcw\fP will write to standard output the primary compiler's -standard output, and the secondary compiler's standard output will -be discarded. -.LP -Because the Studio compilers write intermediate objects to fixed +.Nm cw +will write to standard output the primary compiler's standard output. +.Pp +Because the Sun compilers write intermediate objects to fixed filenames in the current directory when instructed to compile and link multiple source files via a single command line, it would be -unsafe to invoke more than one compiler in this fashion. Therefore -\fBcw\fP does not accept multiple source files unless the -preprocessor is to be invoked. An attempt to invoke \fBcw\fP in -this manner will result in an error. -.SH ARGUMENT TRANSLATION -.LP -The arguments provided to \fBcw\fP will be passed through to each -compiler invoked, altered as follows: -.TP 4 -.B 1. -Options intended for \fBcw\fP itself are removed. -.TP 4 -.B 2. -The shadow compiler's arguments are modified as described in -SHADOW COMPILATION so that its output is discarded. -.TP 4 -.B 3. -If the compiler to be invoked is a GNU C or C++ compiler, a set of +unsafe to invoke more than one compiler in this fashion. +Therefore +.Nm cw +does not accept multiple source files unless the preprocessor is to be +invoked. +An attempt to invoke +.Nm cw +in this manner will result in an error. +.Sh ARGUMENT TRANSLATION +If the compiler to be invoked is a GNU-style C or C++ compiler, a set of default flags is added to the beginning of the argument list, and the remaining arguments are translated to their closest appropriate semantic equivalents and passed in the same order as their -counterparts given to \fBcw\fP. Arguments which begin with -\fI-_gcc=\fP or \fI-_g++=\fP will be passed in place with the -leading portion removed. Arguments which begin with \fI-_cc=\fP or -\fI-_CC=\fP will be discarded. See the comments at the head of -\fIusr/src/tools/cw/cw.c\fP for a detailed list of translations. -.TP 4 -.B 4. -If the compiler to be invoked is a Studio C or C++ compiler, the -remaining arguments are passed unmodified and in the same order as -given to \fBcw\fP. Arguments which begin with \fI-_cc=\fP or -\fI-_CC=\fP will be passed in place with the leading portion removed. -Arguments which begin with \fI-_gcc=\fP or \fI-_g++=\fP will be -discarded. -.SH ENVIRONMENT -.TP 4 -.B CW_NO_SHADOW -If this variable is set in the environment, invoke only the -primary compiler. -.TP 4 -.B CW_SHADOW_SERIAL -If this variable is set in the environment, invoke the primary compiler, -wait for it to complete, then invoke the shadow compiler. Normally -the two compilers are invoked in parallel. If CW_NO_SHADOW is set, -this has no effect. -.TP 4 -.B CW_NO_EXEC -If this variable is set in the environment, write the usual output to -standard error but do not actually invoke any compiler. This is -useful for debugging the translation engine. -.TP 4 -.B CW_CC, CW_CPLUSPLUS -If these variables are set in the environment, they specify the full -pathname for the Studio C and C++ compilers, respectively. -.TP 4 -.B CW_CC_DIR, CW_CPLUSPLUS_DIR, SPRO_VROOT, SPRO_ROOT, BUILD_TOOLS -If CW_CC or CW_CPLUSPLUS are not set, -these variables define the search path for Studio compilers as -follows: -.B -If CW_CC_DIR is set, the Studio C compiler in \fI$CW_CC_DIR\fP -will be used. Likewise, if CW_CPLUSPLUS_DIR is set, the Studio C++ -compiler in \fI$CW_CPLUSPLUS_DIR\fP will be used. -Otherwise, if SPRO_VROOT is set, the Studio C and C++ compilers -in \fI$SPRO_VROOT/bin\fP will be used. -Otherwise, if SPRO_ROOT is set, the Studio C and C++ compilers -in \fI$SPRO_ROOT/SS12/bin\fP will be used. -Otherwise, if BUILD_TOOLS is set, the Studio C and C++ compilers -in \fI$BUILD_TOOLS/SUNWspro/SS12/bin\fP will be used. -Otherwise, the Studio compilers in a predefined default location -will be used. -.TP 4 -.B CW_GCC, CW_GPLUSPLUS -If these variables are set in the environment, they specify the full -pathname for the GNU C and C++ compilers, respectively. -.TP 4 -.B CW_GCC_DIR, CW_GPLUSPLUS_DIR, GNUC_ROOT -If CW_GCC or CW_GPLUSPLUS are not set, -these variables alter the search path for GNU compilers in a manner -similar to that described above for the Studio compilers. Specifically: -.LP -If CW_GCC_DIR is set, the GNU C compiler in \fI$CW_GCC_DIR\fP -will be used. Likewise, if CW_GPLUSPLUS_DIR is set, the GNU C++ -compiler in \fI$CW_GPLUSPLUS_DIR\fP will be used. -Otherwise, if GNUC_ROOT is set, the GNU C and C++ compilers -in \fI$GNUC_ROOT/bin\fP will be used. Previously \fI$GCC_ROOT\fP was -used to in place of \fI$GNUC_ROOT\fP; however, because that environment -variable has special meaning to gcc, if it is encountered in bldenv or -nightly(1ONBLD), it will be translated to \fI$GNUC_ROOT\fP. -.LP -If none of the aforementioned environment variables are set, the GNU -compilers in a predefined default location will be used. -.SH EXIT STATUS -.LP +counterparts given to +.Nm cw . +See the comments at the head of +.Pa usr/src/tools/cw/cw.c +for a detailed list of translations. +.Sh ENVIRONMENT +.Bl -tag -width indent +.It CW_SHADOW_SERIAL +If this variable is set in the environment, invoke the primary compiler, wait +for it to complete, then invoke the shadow compilers. +Normally the primary and shadow compilers are invoked in parallel. +.It CW_NO_EXEC +f this variable is set in the environment, write the usual output to +standard error but do not actually invoke any compiler. +This is useful for debugging the translation engine. +.El +.Sh EXIT STATUS The following exit status values are returned: -.IP "\fB0\fR" 4 -The primary compiler, and shadow compiler if invoked, both completed +.Bl -tag -width indent +.It 0 +The primary compiler, and shadow compilers if invoked, all completed successfully. -.IP "\fB>0\fR" 4 +.It >0 A usage error occurred, or one or more compilers returned a nonzero exit status. -.SH BUGS -.LP -The translations provided for gcc are not always exact and in some -cases reflect local ON policy rather than actual equivalence. -.LP +.El +.Sh SEE ALSO +.Xr cc 1 , +.Xr CC 1 , +.Xr gcc 1 +.Sh BUGS +The translations provided for gcc are not always exact and in some cases +reflect local policy rather than actual equivalence. +.Pp Additional compiler types should be supported. -.LP +.Pp The translation engine is hacky. -.SH SEE ALSO -.LP -cc(1), CC(1), gcc(1) diff --git a/usr/src/tools/cw/cw.c b/usr/src/tools/cw/cw.c index 33a23ddee8..a8c2cfb4f3 100644 --- a/usr/src/tools/cw/cw.c +++ b/usr/src/tools/cw/cw.c @@ -1,3 +1,4 @@ + /* * CDDL HEADER START * @@ -20,7 +21,7 @@ */ /* - * Copyright 2011, Richard Lowe. + * Copyright 2018, Richard Lowe. */ /* * Copyright 2010 Sun Microsystems, Inc. All rights reserved. @@ -36,7 +37,7 @@ */ /* If you modify this file, you must increment CW_VERSION */ -#define CW_VERSION "1.30" +#define CW_VERSION "2.0" /* * -# Verbose mode @@ -291,20 +292,21 @@ * -YS,<dir> error */ -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> #include <ctype.h> -#include <fcntl.h> +#include <err.h> #include <errno.h> -#include <stdarg.h> -#include <sys/utsname.h> +#include <fcntl.h> +#include <getopt.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + #include <sys/param.h> -#include <sys/isa_defs.h> -#include <sys/wait.h> #include <sys/stat.h> +#include <sys/types.h> +#include <sys/utsname.h> +#include <sys/wait.h> #define CW_F_CXX 0x01 #define CW_F_SHADOW 0x02 @@ -313,29 +315,6 @@ #define CW_F_XLATE 0x10 #define CW_F_PROG 0x20 -typedef enum cw_compiler { - CW_C_CC = 0, - CW_C_GCC -} cw_compiler_t; - -static const char *cmds[] = { - "cc", "CC", - "gcc", "g++" -}; - -static char default_dir[2][MAXPATHLEN] = { - DEFAULT_CC_DIR, - DEFAULT_GCC_DIR, -}; - -#define CC(ctx) \ - (((ctx)->i_flags & CW_F_SHADOW) ? \ - ((ctx)->i_compiler == CW_C_CC ? CW_C_GCC : CW_C_CC) : \ - (ctx)->i_compiler) - -#define CIDX(compiler, flags) \ - ((int)(compiler) << 1) + ((flags) & CW_F_CXX ? 1 : 0) - typedef enum cw_op { CW_O_NONE = 0, CW_O_PREPROCESS, @@ -351,8 +330,20 @@ struct aelist { int ael_argc; }; +typedef enum { + GNU, + SUN +} compiler_style_t; + +typedef struct { + char *c_name; + char *c_path; + compiler_style_t c_style; +} cw_compiler_t; + typedef struct cw_ictx { - cw_compiler_t i_compiler; + struct cw_ictx *i_next; + cw_compiler_t *i_compiler; struct aelist *i_ae; uint32_t i_flags; int i_oldargc; @@ -390,7 +381,7 @@ typedef struct xarch_table { */ static const xarch_table_t xtbl[] = { #if defined(__x86) - { "generic", SS11 }, + { "generic", SS11, {NULL} }, { "generic64", (SS11|M64), { "-m64", "-mtune=opteron" } }, { "amd64", (SS11|M64), { "-m64", "-mtune=opteron" } }, { "386", SS11, { "-march=i386" } }, @@ -417,8 +408,6 @@ static const xarch_table_t xtbl[] = { static int xtbl_size = sizeof (xtbl) / sizeof (xarch_table_t); -static const char *progname; - static const char *xchip_tbl[] = { #if defined(__x86) "386", "-mtune=i386", NULL, @@ -464,23 +453,7 @@ static const char *xregs_tbl[] = { static void nomem(void) { - (void) fprintf(stderr, "%s: error: out of memory\n", progname); - exit(1); -} - -static void -cw_perror(const char *fmt, ...) -{ - va_list ap; - int saved_errno = errno; - - (void) fprintf(stderr, "%s: error: ", progname); - - va_start(ap, fmt); - (void) vfprintf(stderr, fmt, ap); - va_end(ap); - - (void) fprintf(stderr, " (%s)\n", strerror(saved_errno)); + errx(1, "out of memory"); } static void @@ -515,9 +488,7 @@ newictx(void) static void error(const char *arg) { - (void) fprintf(stderr, - "%s: error: mapping failed at or near arg '%s'\n", progname, arg); - exit(2); + errx(2, "error: mapping failed at or near arg '%s'", arg); } /* @@ -551,7 +522,7 @@ optim_disable(struct aelist *h, int level) /* ARGSUSED */ static void -Xamode(struct aelist *h) +Xamode(struct aelist __unused *h) { } @@ -582,9 +553,15 @@ Xsmode(struct aelist *h) static void usage() { + extern char *__progname; (void) fprintf(stderr, - "usage: %s { -_cc | -_gcc | -_CC | -_g++ } [ -_compiler | ... ]\n", - progname); + "usage: %s [-C] [--versions] --primary <compiler> " + "[--shadow <compiler>]... -- cflags...\n", + __progname); + (void) fprintf(stderr, "compilers take the form: name,path,style\n" + " - name: a unique name usable in flag specifiers\n" + " - path: path to the compiler binary\n" + " - style: the style of flags expected: either sun or gnu\n"); exit(2); } @@ -643,6 +620,7 @@ do_gcc(cw_ictx_t *ctx) int in_output = 0, seen_o = 0, c_files = 0; cw_op_t op = CW_O_LINK; char *model = NULL; + char *nameflag; int mflag = 0; if (ctx->i_flags & CW_F_PROG) { @@ -679,10 +657,12 @@ do_gcc(cw_ictx_t *ctx) */ newae(ctx->i_ae, "-D__sun"); + if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1) + nomem(); + /* * Walk the argument list, translating as we go .. */ - while (--ctx->i_oldargc > 0) { char *arg = *++ctx->i_oldargv; size_t arglen = strlen(arg); @@ -718,6 +698,10 @@ do_gcc(cw_ictx_t *ctx) } if (ctx->i_flags & CW_F_CXX) { + if (strncmp(arg, "-_g++=", 6) == 0) { + newae(ctx->i_ae, strchr(arg, '=') + 1); + continue; + } if (strncmp(arg, "-compat=", 8) == 0) { /* discard -compat=4 and -compat=5 */ continue; @@ -772,16 +756,11 @@ do_gcc(cw_ictx_t *ctx) switch ((c = arg[1])) { case '_': - if (strcmp(arg, "-_noecho") == 0) - ctx->i_flags &= ~CW_F_ECHO; - else if (strncmp(arg, "-_cc=", 5) == 0 || - strncmp(arg, "-_CC=", 5) == 0) - /* EMPTY */; - else if (strncmp(arg, "-_gcc=", 6) == 0 || - strncmp(arg, "-_g++=", 6) == 0) - newae(ctx->i_ae, arg + 6); - else - error(arg); + if ((strncmp(arg, nameflag, strlen(nameflag)) == 0) || + (strncmp(arg, "-_gcc=", 6) == 0) || + (strncmp(arg, "-_gnu=", 6) == 0)) { + newae(ctx->i_ae, strchr(arg, '=') + 1); + } break; case '#': if (arglen == 1) { @@ -1421,11 +1400,12 @@ do_gcc(cw_ictx_t *ctx) } } + free(nameflag); + if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) && op != CW_O_PREPROCESS) { - (void) fprintf(stderr, "%s: error: multiple source files are " - "allowed only with -E or -P\n", progname); - exit(2); + errx(2, "multiple source files are " + "allowed only with -E or -P"); } /* @@ -1434,9 +1414,8 @@ do_gcc(cw_ictx_t *ctx) * used. */ if ((mflag & (SS11|SS12)) == (SS11|SS12)) { - (void) fprintf(stderr, + errx(2, "Conflicting \"-xarch=\" flags (both Studio 11 and 12)\n"); - exit(2); } switch (mflag) { @@ -1491,7 +1470,9 @@ do_gcc(cw_ictx_t *ctx) "Incompatible -xarch= and/or -m32/-m64 options used.\n"); exit(2); } - if (op == CW_O_LINK && (ctx->i_flags & CW_F_SHADOW)) + + if ((op == CW_O_LINK || op == CW_O_PREPROCESS) && + (ctx->i_flags & CW_F_SHADOW)) exit(0); if (model && !pic) @@ -1509,15 +1490,24 @@ do_cc(cw_ictx_t *ctx) { int in_output = 0, seen_o = 0; cw_op_t op = CW_O_LINK; + char *nameflag; if (ctx->i_flags & CW_F_PROG) { newae(ctx->i_ae, "-V"); return; } + if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1) + nomem(); + while (--ctx->i_oldargc > 0) { char *arg = *++ctx->i_oldargv; + if (strncmp(arg, "-_CC=", 5) == 0) { + newae(ctx->i_ae, strchr(arg, '=') + 1); + continue; + } + if (*arg != '-') { if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) { newae(ctx->i_ae, arg); @@ -1529,19 +1519,13 @@ do_cc(cw_ictx_t *ctx) } switch (*(arg + 1)) { case '_': - if (strcmp(arg, "-_noecho") == 0) { - ctx->i_flags &= ~CW_F_ECHO; - } else if (strncmp(arg, "-_cc=", 5) == 0 || - strncmp(arg, "-_CC=", 5) == 0) { - newae(ctx->i_ae, arg + 5); - } else if (strncmp(arg, "-_gcc=", 6) != 0 && - strncmp(arg, "-_g++=", 6) != 0) { - (void) fprintf(stderr, - "%s: invalid argument '%s'\n", progname, - arg); - exit(2); + if ((strncmp(arg, nameflag, strlen(nameflag)) == 0) || + (strncmp(arg, "-_cc=", 5) == 0) || + (strncmp(arg, "-_sun=", 6) == 0)) { + newae(ctx->i_ae, strchr(arg, '=') + 1); } break; + case 'V': ctx->i_flags &= ~CW_F_ECHO; newae(ctx->i_ae, arg); @@ -1574,6 +1558,8 @@ do_cc(cw_ictx_t *ctx) } } + free(nameflag); + if ((op == CW_O_LINK || op == CW_O_PREPROCESS) && (ctx->i_flags & CW_F_SHADOW)) exit(0); @@ -1587,55 +1573,22 @@ do_cc(cw_ictx_t *ctx) static void prepctx(cw_ictx_t *ctx) { - const char *dir = NULL, *cmd; - char *program = NULL; - size_t len; - - switch (CIDX(CC(ctx), ctx->i_flags)) { - case CIDX(CW_C_CC, 0): - program = getenv("CW_CC"); - dir = getenv("CW_CC_DIR"); - break; - case CIDX(CW_C_CC, CW_F_CXX): - program = getenv("CW_CPLUSPLUS"); - dir = getenv("CW_CPLUSPLUS_DIR"); - break; - case CIDX(CW_C_GCC, 0): - program = getenv("CW_GCC"); - dir = getenv("CW_GCC_DIR"); - break; - case CIDX(CW_C_GCC, CW_F_CXX): - program = getenv("CW_GPLUSPLUS"); - dir = getenv("CW_GPLUSPLUS_DIR"); - break; - } - - if (program == NULL) { - if (dir == NULL) - dir = default_dir[CC(ctx)]; - cmd = cmds[CIDX(CC(ctx), ctx->i_flags)]; - len = strlen(dir) + strlen(cmd) + 2; - if ((program = malloc(len)) == NULL) - nomem(); - (void) snprintf(program, len, "%s/%s", dir, cmd); - } - - newae(ctx->i_ae, program); + newae(ctx->i_ae, ctx->i_compiler->c_path); if (ctx->i_flags & CW_F_PROG) { (void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ? - "shadow" : "primary", program); + "shadow" : "primary", ctx->i_compiler->c_path); (void) fflush(stdout); } if (!(ctx->i_flags & CW_F_XLATE)) return; - switch (CC(ctx)) { - case CW_C_CC: + switch (ctx->i_compiler->c_style) { + case SUN: do_cc(ctx); break; - case CW_C_GCC: + case GNU: do_gcc(ctx); break; } @@ -1672,19 +1625,22 @@ invoke(cw_ictx_t *ctx) return (0); /* - * We must fix up the environment here so that the - * dependency files are not trampled by the shadow compiler. + * We must fix up the environment here so that the dependency files are + * not trampled by the shadow compiler. Also take care of GCC + * environment variables that will throw off gcc. This assumes a primary + * gcc. */ if ((ctx->i_flags & CW_F_SHADOW) && (unsetenv("SUNPRO_DEPENDENCIES") != 0 || - unsetenv("DEPENDENCIES_OUTPUT") != 0)) { + unsetenv("DEPENDENCIES_OUTPUT") != 0 || + unsetenv("GCC_ROOT") != 0)) { (void) fprintf(stderr, "error: environment setup failed: %s\n", strerror(errno)); return (-1); } (void) execv(newargv[0], newargv); - cw_perror("couldn't run %s", newargv[0]); + warn("couldn't run %s", newargv[0]); return (-1); } @@ -1704,7 +1660,7 @@ reap(cw_ictx_t *ctx) do { if (waitpid(ctx->i_pid, &status, 0) < 0) { - cw_perror("cannot reap child"); + warn("cannot reap child"); return (-1); } if (status != 0) { @@ -1721,7 +1677,7 @@ reap(cw_ictx_t *ctx) (void) unlink(ctx->i_discard); if (stat(ctx->i_stderr, &s) < 0) { - cw_perror("stat failed on child cleanup"); + warn("stat failed on child cleanup"); return (-1); } if (s.st_size != 0) { @@ -1774,26 +1730,23 @@ exec_ctx(cw_ictx_t *ctx, int block) (void) fclose(stderr); if ((fd = open(ctx->i_stderr, O_WRONLY | O_CREAT | O_EXCL, 0666)) < 0) { - cw_perror("open failed for standard error"); - exit(1); + err(1, "open failed for standard error"); } if (dup2(fd, 2) < 0) { - cw_perror("dup2 failed for standard error"); - exit(1); + err(1, "dup2 failed for standard error"); } if (fd != 2) (void) close(fd); if (freopen("/dev/fd/2", "w", stderr) == NULL) { - cw_perror("freopen failed for /dev/fd/2"); - exit(1); + err(1, "freopen failed for /dev/fd/2"); } + prepctx(ctx); exit(invoke(ctx)); } if (ctx->i_pid < 0) { - cw_perror("fork failed"); - return (1); + err(1, "fork failed"); } if (block) @@ -1802,115 +1755,169 @@ exec_ctx(cw_ictx_t *ctx, int block) return (0); } -int -main(int argc, char **argv) +static void +parse_compiler(const char *spec, cw_compiler_t *compiler) { - cw_ictx_t *ctx = newictx(); - cw_ictx_t *ctx_shadow = newictx(); - const char *dir; - int do_serial, do_shadow; - int ret = 0; + char *tspec, *token; - if ((progname = strrchr(argv[0], '/')) == NULL) - progname = argv[0]; - else - progname++; - - if (ctx == NULL || ctx_shadow == NULL) + if ((tspec = strdup(spec)) == NULL) nomem(); - ctx->i_flags = CW_F_ECHO|CW_F_XLATE; + if ((token = strsep(&tspec, ",")) == NULL) + errx(1, "Compiler is missing a name: %s", spec); + compiler->c_name = token; - /* - * Figure out where to get our tools from. This depends on - * the environment variables set at run time. - */ - if ((dir = getenv("SPRO_VROOT")) != NULL) { - (void) snprintf(default_dir[CW_C_CC], MAXPATHLEN, - "%s/bin", dir); - } else if ((dir = getenv("SPRO_ROOT")) != NULL) { - (void) snprintf(default_dir[CW_C_CC], MAXPATHLEN, - "%s/SS12/bin", dir); - } else if ((dir = getenv("BUILD_TOOLS")) != NULL) { - (void) snprintf(default_dir[CW_C_CC], MAXPATHLEN, - "%s/SUNWspro/SS12/bin", dir); - } + if ((token = strsep(&tspec, ",")) == NULL) + errx(1, "Compiler is missing a path: %s", spec); + compiler->c_path = token; - if ((dir = getenv("GNUC_ROOT")) != NULL) { - (void) snprintf(default_dir[CW_C_GCC], MAXPATHLEN, - "%s/bin", dir); - } + if ((token = strsep(&tspec, ",")) == NULL) + errx(1, "Compiler is missing a style: %s", spec); - do_shadow = (getenv("CW_NO_SHADOW") ? 0 : 1); - do_serial = (getenv("CW_SHADOW_SERIAL") ? 1 : 0); + if ((strcasecmp(token, "gnu") == 0) || + (strcasecmp(token, "gcc") == 0)) + compiler->c_style = GNU; + else if ((strcasecmp(token, "sun") == 0) || + (strcasecmp(token, "cc") == 0)) + compiler->c_style = SUN; + else + errx(1, "unknown compiler style: %s", token); - if (getenv("CW_NO_EXEC") == NULL) - ctx->i_flags |= CW_F_EXEC; + if (tspec != NULL) + errx(1, "Excess tokens in compiler: %s", spec); +} - /* - * The first argument must be one of "-_cc", "-_gcc", "-_CC", or "-_g++" - */ - if (argc == 1) +int +main(int argc, char **argv) +{ + int ch; + cw_compiler_t primary = { NULL, NULL, 0 }; + cw_compiler_t shadows[10]; + int nshadows = 0; + int ret = 0; + boolean_t do_serial = B_FALSE; + boolean_t do_exec = B_FALSE; + boolean_t vflg = B_FALSE; + boolean_t Cflg = B_FALSE; + boolean_t cflg = B_FALSE; + boolean_t nflg = B_FALSE; + + cw_ictx_t *main_ctx; + + static struct option longopts[] = { + { "compiler", no_argument, NULL, 'c' }, + { "noecho", no_argument, NULL, 'n' }, + { "primary", required_argument, NULL, 'p' }, + { "shadow", required_argument, NULL, 's' }, + { "versions", no_argument, NULL, 'v' }, + { NULL, 0, NULL, 0 }, + }; + + + if ((main_ctx = newictx()) == NULL) + nomem(); + + while ((ch = getopt_long(argc, argv, "C", longopts, NULL)) != -1) { + switch (ch) { + case 'c': + cflg = B_TRUE; + break; + case 'C': + Cflg = B_TRUE; + break; + case 'n': + nflg = B_TRUE; + break; + case 'p': + if (primary.c_path != NULL) { + warnx("Only one primary compiler may " + "be specified"); + usage(); + } + + parse_compiler(optarg, &primary); + break; + case 's': + if (nshadows >= 10) + errx(1, "May only use 10 shadows at " + "the moment"); + parse_compiler(optarg, &shadows[nshadows]); + nshadows++; + break; + case 'v': + vflg = B_TRUE; + break; + default: + (void) fprintf(stderr, "Did you forget '--'?\n"); + usage(); + } + } + + if (primary.c_path == NULL) { + warnx("A primary compiler must be specified"); usage(); - argc--; - argv++; - if (strcmp(argv[0], "-_cc") == 0) { - ctx->i_compiler = CW_C_CC; - } else if (strcmp(argv[0], "-_gcc") == 0) { - ctx->i_compiler = CW_C_GCC; - } else if (strcmp(argv[0], "-_CC") == 0) { - ctx->i_compiler = CW_C_CC; - ctx->i_flags |= CW_F_CXX; - } else if (strcmp(argv[0], "-_g++") == 0) { - ctx->i_compiler = CW_C_GCC; - ctx->i_flags |= CW_F_CXX; - } else { - /* assume "-_gcc" by default */ - argc++; - argv--; - ctx->i_compiler = CW_C_GCC; } - /* - * -_compiler - tell us the path to the primary compiler only - */ - if (argc > 1 && strcmp(argv[1], "-_compiler") == 0) { - ctx->i_flags &= ~CW_F_XLATE; - prepctx(ctx); - (void) printf("%s\n", ctx->i_ae->ael_head->ae_arg); - return (0); + do_serial = (getenv("CW_SHADOW_SERIAL") == NULL) ? B_FALSE : B_TRUE; + do_exec = (getenv("CW_NO_EXEC") == NULL) ? B_TRUE : B_FALSE; + + /* Leave room for argv[0] */ + argc -= (optind - 1); + argv += (optind - 1); + + main_ctx->i_oldargc = argc; + main_ctx->i_oldargv = argv; + main_ctx->i_flags = CW_F_XLATE; + if (nflg == 0) + main_ctx->i_flags |= CW_F_ECHO; + if (do_exec) + main_ctx->i_flags |= CW_F_EXEC; + if (Cflg) + main_ctx->i_flags |= CW_F_CXX; + main_ctx->i_compiler = &primary; + + if (cflg) { + (void) fputs(primary.c_path, stdout); } - /* - * -_versions - tell us the cw version, paths to all compilers, and - * ask each for its version if we know how. - */ - if (argc > 1 && strcmp(argv[1], "-_versions") == 0) { - (void) printf("cw version %s", CW_VERSION); - if (!do_shadow) - (void) printf(" (SHADOW MODE DISABLED)"); - (void) printf("\n"); + if (vflg) { + (void) printf("cw version %s\n", CW_VERSION); (void) fflush(stdout); - ctx->i_flags &= ~CW_F_ECHO; - ctx->i_flags |= CW_F_PROG|CW_F_EXEC; - argc--; - argv++; + main_ctx->i_flags &= ~CW_F_ECHO; + main_ctx->i_flags |= CW_F_PROG | CW_F_EXEC; do_serial = 1; } - ctx->i_oldargc = argc; - ctx->i_oldargv = argv; + ret |= exec_ctx(main_ctx, do_serial); - ret |= exec_ctx(ctx, do_serial); + for (int i = 0; i < nshadows; i++) { + int r; + cw_ictx_t *shadow_ctx; - if (do_shadow) { - (void) memcpy(ctx_shadow, ctx, sizeof (cw_ictx_t)); - ctx_shadow->i_flags |= CW_F_SHADOW; - ret |= exec_ctx(ctx_shadow, 1); + if ((shadow_ctx = newictx()) == NULL) + nomem(); + + memcpy(shadow_ctx, main_ctx, sizeof (cw_ictx_t)); + + shadow_ctx->i_flags |= CW_F_SHADOW; + shadow_ctx->i_compiler = &shadows[i]; + + r = exec_ctx(shadow_ctx, do_serial); + if (r == 0) { + shadow_ctx->i_next = main_ctx->i_next; + main_ctx->i_next = shadow_ctx; + } + ret |= r; } - if (!do_serial) - ret |= reap(ctx); + if (!do_serial) { + cw_ictx_t *next = main_ctx; + while (next != NULL) { + cw_ictx_t *toreap = next; + next = next->i_next; + ret |= reap(toreap); + } + } return (ret); } diff --git a/usr/src/tools/env/illumos.sh b/usr/src/tools/env/illumos.sh index 9c911632c0..6994e3f8a4 100644 --- a/usr/src/tools/env/illumos.sh +++ b/usr/src/tools/env/illumos.sh @@ -40,7 +40,7 @@ # checks for changes in ELF runpaths (-r) # build and use this workspace's tools in $SRC/tools (-t) # -# - This file is sourced by "bldenv.sh" and "nightly.sh" and should not +# - This file is sourced by "bldenv.sh" and "nightly.sh" and should not # be executed directly. # - This script is only interpreted by ksh93 and explicitly allows the # use of ksh93 language extensions. @@ -61,7 +61,7 @@ function maxjobs ncpu=$(builtin getconf ; getconf 'NPROCESSORS_ONLN') (( maxjobs=ncpu + 2 )) - + # Throttle number of parallel jobs launched by dmake to a value which # gurantees that all jobs have enough memory. This was added to avoid # excessive paging/swapping in cases of virtual machine installations @@ -76,7 +76,7 @@ function maxjobs # the value matched by ([[:digit:]]+), i.e. the amount of # memory installed physical_memory="10#${.sh.match[1]}" - + (( max_jobs_per_memory=round(physical_memory/min_mem_per_job) , maxjobs=fmax(2, fmin(maxjobs, max_jobs_per_memory)) @@ -196,8 +196,33 @@ export BUILD_TOOLS='/opt' export SPRO_ROOT='/opt/SUNWspro' export SPRO_VROOT="$SPRO_ROOT" -# Disable shadow compilation by default. -export CW_NO_SHADOW='1' +# Compilers may be specified using the following variables: +# PRIMARY_CC - primary C compiler +# PRIMARY_CCC - primary C++ compiler +# +# SHADOW_CCS - list of shadow C compilers +# SHADOW_CCCS - list of shadow C++ compilers +# +# Each entry has the form <name>,<path to binary>,<style> where name is a +# free-form name (possibly used in the makefiles to guard options), path is +# the path to the executable. style is the 'style' of command line taken by +# the compiler, currently either gnu (or gcc) or sun (or cc), which is also +# used by Makefiles to guard options. +# +# __SUNC and __GNUC must still be set to reflect the style of the primary +# compiler (and to influence the default primary, otherwise) +# +# for example: +# export PRIMARY_CC=gcc4,/opt/gcc/4.4.4/bin/gcc,gnu +# export PRIMARY_CCC=gcc4,/opt/gcc/4.4.4/bin/g++,gnu +# export SHADOW_CCS=studio12,/opt/SUNWspro/bin/cc,sun +# export SHADOW_CCCS=studio12,/opt/SUNWspro/bin/CC,sun +# +# There can be several space-separated entries in SHADOW_* to run multiple +# shadow compilers. +# +# To disable shadow compilation, unset SHADOW_* or set them to the empty string. +# # This goes along with lint - it is a series of the form "A [y|n]" which # means "go to directory A and run 'make lint'" Then mail me (y) the diff --git a/usr/src/tools/scripts/nightly.sh b/usr/src/tools/scripts/nightly.sh index dc7edfcebf..93a419eb84 100644 --- a/usr/src/tools/scripts/nightly.sh +++ b/usr/src/tools/scripts/nightly.sh @@ -1673,7 +1673,7 @@ if [[ ! -f $SRC/Makefile ]]; then fi ( cd $SRC - for target in cc-version cc64-version java-version openssl-version; do + for target in cc-version java-version openssl-version; do echo # # Put statefile somewhere we know we can write to rather than trip |