[m-dev.] for review: improve linker error messages for mixing grades

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Sep 23 23:26:07 AEST 1999


Estimated hours taken: 1

Improve the error messages for linking objects compiled in different grades.

util/mdemangle.c:
	Check for `MR_grade_*' and `MR_runtime_grade', and if they are
	found, print out a message explaining the cause of the problem.
	But only do that if a new option `--explain-link-errors' is set,
	so that this message will only come out when you get a message
	from the linker, not when you invoke mdemangle manually e.g.
	via `nm *.o | mdemangle'.

scripts/ml.in:
	Pass the new `--explain-link-errors' option to mdemangle.

Workspace: /home/mercury0/fjh/mercury
Index: scripts/ml.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/ml.in,v
retrieving revision 1.65
diff -u -r1.65 ml.in
--- ml.in	1999/09/10 08:50:03	1.65
+++ ml.in	1999/09/23 12:32:04
@@ -575,7 +575,7 @@
 	    true)
 		echo $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT \
 			$ARCH_OPTS $LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS "|"
-		echo "$DEMANGLER"
+		echo "$DEMANGLER --explain-link-errors"
 		;;
 	esac
 	;;
@@ -605,7 +605,7 @@
 	$MKFIFO $PIPE
 		# execute the demangler in the background, with stdin 
 		# coming from the pipe and with stdout redirected to stderr
-	exec $DEMANGLER 1>&2 < $PIPE &
+	exec $DEMANGLER --explain-link-errors 1>&2 < $PIPE &
 		# redirect our stdout and stderr into the pipe
 	exec >$PIPE 2>&1
 		# now we can remove the pipe; since is an open file, it will
Index: util/mdemangle.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mdemangle.c,v
retrieving revision 1.35
diff -u -r1.35 mdemangle.c
--- mdemangle.c	1999/06/15 07:10:17	1.35
+++ mdemangle.c	1999/09/23 13:08:33
@@ -52,9 +52,46 @@
 #define memmove memcpy
 #endif
 
+/*
+** This option indicates whether we should output verbose
+** explanations of linker error messages.
+*/
+bool explain_link_errors = FALSE;
+
+/*
+** This variable gets set if the symbols MR_grade_* or MR_mercury_grade
+** were found.  If it gets set, then we print out the error message below.
+*/
+char *found_grade_symbol = NULL;
+const char probably_grade_error[] =
+  "Mercury Linker:\n"
+  "\tNote: the symbol `%s' was mentioned.\n"
+  "\tAny link errors are most likely due to linking together object\n"
+  "\tfiles compiled with different compilation model options.\n"
+  "\tTry doing `mmake clean' and then rebuilding.\n";
+
 int 
 main(int argc, char **argv)
 {
+	const char *progname = argv[0];
+
+	/* we should use getopt_long(), but for one option, that is overkill */
+	while (argc > 1 && argv[1][0] == '-') {
+		if (strcmp(argv[1], "-e") == 0 ||
+		    strcmp(argv[1], "--explain-link-errors") == 0)
+		{
+			explain_link_errors = TRUE;
+			argc--, argv++;
+		} else if (strcmp(argv[1], "--") == 0) {
+			argc--, argv++;
+			break;
+		} else {
+			fprintf(stderr, "%s: unknown option `%s'\n",
+				progname, argv[1]);
+			exit(1);
+		}
+	}
+
 	if (argc > 1) {
 		/*
 		** invoke demangle() on each command line argument
@@ -89,6 +126,12 @@
 			putchar(c);
 		}
 	}
+
+	if (explain_link_errors && found_grade_symbol) {
+		printf(probably_grade_error, found_grade_symbol);
+		free(found_grade_symbol);
+	}
+
 	return 0;
 }
 
@@ -128,6 +171,9 @@
 	static const char arity_string[] = "arity";
 	static const char underscores_arity_string[] = "__arity";
 
+	static const char MR_grade[] = "MR_grade_";
+	static const char MR_runtime_grade[] = "MR_runtime_grade";
+
 	static const char * trailing_context_1[] = {
 		introduced,
 		deforestation,
@@ -189,6 +235,21 @@
 	*/
 	if (*start == '_' && strncmp(start, entry, strlen(entry)) != 0) {
 		start++;
+	}
+
+	/*
+	** check for `MR_grade_*' and `MR_runtime_grade'.
+	*/
+	if (strncmp(start, MR_grade, strlen(MR_grade)) == 0 ||
+	    strcmp(start, MR_runtime_grade) == 0)
+	{
+		if (found_grade_symbol == NULL) {
+			found_grade_symbol = malloc(strlen(start) + 1);
+			if (found_grade_symbol != NULL) {
+				strcpy(found_grade_symbol, start);
+			}
+		}
+		goto wrong_format;
 	}
 
 	/*

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list