add compiler date/time chatter reduction tools
authorNorm Jacobs <Norm.Jacobs@Sun.COM>
Wed, 12 May 2010 00:32:41 -0500
changeset 6 20f80c019d73
parent 5 b0dcdd332e2c
child 7 d42300cb8715
add compiler date/time chatter reduction tools
components/Makefile
make-rules/configure.mk
make-rules/shared-macros.mk
tools/time.c
--- a/components/Makefile	Wed May 12 00:29:30 2010 -0500
+++ b/components/Makefile	Wed May 12 00:32:41 2010 -0500
@@ -35,6 +35,7 @@
 validate:	TARGET = validate
 clean:		TARGET = clean
 clobber:	TARGET = clobber
+prep build install publish:		LOG =	>$(WS_LOGS)/$(TARGET):[email protected] 2>&1
 
 .DEFAULT:	publish
 
@@ -47,7 +48,7 @@
 	$(RM) -r $(PKG_REPO:file://%=%) $(WS_LOGS)
 endif
 
-setup:	$(WS_LOGS) repo
+setup:	$(WS_LOGS) repo tools
 
 $(WS_LOGS):
 	$(MKDIR) $@
@@ -56,8 +57,11 @@
 	$(PKGSEND) -s $(PKG_REPO) create-repository \
 		--set-property publisher.prefix=$(PUBLISHER)
 
+tools:
+	@cd ../tools ; echo "building tools..." ; $(GMAKE) setup
+
 $(COMPONENT_DIRS):	FORCE
 	@cd $@ ; echo "$(TARGET) \c" ; pwd ; \
-	 $(GMAKE) $(TARGET) >$(WS_LOGS)/$(TARGET):[email protected] 2>&1
+	 $(GMAKE) $(TARGET) $(LOG)
 
 FORCE:
--- a/make-rules/configure.mk	Wed May 12 00:29:30 2010 -0500
+++ b/make-rules/configure.mk	Wed May 12 00:32:41 2010 -0500
@@ -78,13 +78,14 @@
 # build the configured source
 $(COMPONENT_SRC)/build-%/.built:	$(COMPONENT_SRC)/build-%/.configured
 	$(COMPONENT_PRE_BUILD_ACTION)
-	(cd $(@D) ; $(GMAKE) $(COMPONENT_BUILD_TARGETS))
+	(cd $(@D) ; $(COMPONENT_BUILD_ENV) $(GMAKE) $(COMPONENT_BUILD_TARGETS))
 	$(COMPONENT_POST_BUILD_ACTION)
 	$(TOUCH) $@
 
 # install the built source into a prototype area
 $(COMPONENT_SRC)/build-%/.installed:	$(COMPONENT_SRC)/build-%/.built
 	$(COMPONENT_PRE_INSTALL_ACTION)
-	(cd $(@D) ; $(GMAKE) DESTDIR=$(PROTO_DIR)  $(COMPONENT_INSTALL_TARGETS))
+	(cd $(@D) ; $(COMPONENT_INSTALL_ENV) $(GMAKE) \
+			DESTDIR=$(PROTO_DIR) $(COMPONENT_INSTALL_TARGETS))
 	$(COMPONENT_POST_INSTALL_ACTION)
 	$(TOUCH) $@
--- a/make-rules/shared-macros.mk	Wed May 12 00:29:30 2010 -0500
+++ b/make-rules/shared-macros.mk	Wed May 12 00:32:41 2010 -0500
@@ -26,6 +26,7 @@
 BUILD_VERSION =	5.11-0.140
 
 COMPILER =		studio
+BITS =			32
 PYTHON_VERSION =	2.6
 
 TOOLS =		$(WS_TOP)/tools
@@ -35,6 +36,8 @@
 PKG_REPO =	file://$(WS_TOP)/repo
 PROTO_DIR =	$(shell pwd)/$(COMPONENT_SRC)/installed-prototype
 
+CONSTANT_TIME =	LD_PRELOAD=$(TOOLS)/time.o
+
 MACH64 =	$(shell isainfo -k)
 
 SPRO_ROOT =	/opt/sunstudio12.1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/time.c	Wed May 12 00:32:41 2010 -0500
@@ -0,0 +1,116 @@
+/*
+ * 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 (c) 2010, Oracle and/or it's affiliates.  All rights reserved.
+ */
+
+/*
+ * This compiles to a module that can be preloaded during a build.  If this
+ * is preloaded, it interposes on time(2) and returns a constant value when
+ * the execname matches one of the desired "programs" and TIME_CONSTANT
+ * contains an integer value to be returned.
+ */
+
+#include <stdlib.h>
+#include <ucontext.h>
+#include <dlfcn.h>
+#include <strings.h>
+
+/* The list of programs that we want to use a constant time. */
+static char *programs[] = { "date", "cpp", "cc1", "perl", NULL };
+
+static int
+stack_info(uintptr_t pc, int signo, void *arg)
+{
+	Dl_info info;
+	void *sym;
+
+	if (dladdr1((void *)pc, &info, &sym, RTLD_DL_SYMENT) != NULL) {
+		*(char **)arg = (char *)info.dli_fname;
+	}
+
+	return (0);
+}
+
+static char *
+my_execname()
+{
+	static char *execname;
+
+	if (execname == NULL) {
+		ucontext_t ctx;
+
+		if (getcontext(&ctx) == 0)
+			walkcontext(&ctx, stack_info, &execname);
+
+		if (execname != NULL) {
+			char *s = strrchr(execname, '/');
+
+			if (s != NULL)
+				execname = ++s;
+		}
+	}
+
+	return (execname);
+}
+
+static time_t
+intercept()
+{
+	char *execname = my_execname();
+	time_t result = -1;
+
+	if (execname != NULL) {
+		int i;
+
+		for (i = 0; programs[i] != NULL; i++)
+			if (strcmp(execname, programs[i]) == 0) {
+				static char *time_constant;
+
+				if (time_constant == NULL)
+					time_constant = getenv("TIME_CONSTANT");
+
+				if (time_constant != NULL)
+					result = atoll(time_constant);
+
+				break;
+			}
+	}
+
+	return (result);
+}
+
+time_t
+time(time_t *ptr)
+{
+	time_t result = intercept();
+
+	if (result == (time_t)-1) {
+		static time_t (*fptr)(time_t *);
+
+		if (fptr == NULL)
+			fptr = (time_t (*)(time_t *))dlsym(RTLD_NEXT, "time");
+
+		result = (fptr)(ptr);
+	} else if (ptr != NULL)
+			*ptr = result;
+
+	return (result);
+}