[m-dev.] diff: fix name mangling bug in util/mkinit.c

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Oct 29 16:20:32 AEST 1999


Estimated hours taken: 0.75

Fix a bug that caused an undefined symbol error when compiling modules
whose name started with `f_' in certain grades, e.g. --debug.

util/mkinit.c:
	Ensure that the module names in `mercury__<module>__init' symbols
	are properly mangled according to the same algorithm used by
	llds_out__name_mangle/2 in compiler/llds_out.m.
	For simplicity, I didn't bother to handle the case where the
	module name contains special symbols; it just checks for that
	case and aborts.  But I added new code to handle the case
	where the module name starts with `f_'.

Workspace: /home/mercury0/fjh/mercury
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.54
diff -u -d -r1.54 mkinit.c
--- mkinit.c	1999/09/23 11:25:26	1.54
+++ mkinit.c	1999/10/29 04:30:11
@@ -567,6 +567,7 @@
 {
 	char func_name[1000];
 	char *position;
+	int i;
 
 	/* remove the directory name, if any */
 	if ((position = strrchr(filename, '/')) != NULL) {
@@ -575,19 +576,44 @@
 
 	/*
 	** The func name is "mercury__<modulename>__init",
-	** where <modulename> is the base filename with all
-	** `.'s replaced with `__'.
+	** where <modulename> is the base filename with
+	** all `.'s replaced with `__', and with each
+	** component of the module name mangled according
+	** to the algorithm in llds_out__name_mangle/2
+	** in compiler/llds_out.m. 
+	**
+	** XXX We don't handle the full name mangling algorithm here;
+	** instead we use a simplified version:
+	** - if there are no special charaters, but the
+	**   name starts with `f_', then replace the leading
+	**   `f_' with `f__'
+	** - if there are any special characters, give up
 	*/
+
+	/* check for special characters */
+	for (i = 0; filename[i] != '\0'; i++) {
+		if (filename[i] != '.' && !MR_isalnumunder(filename[i])) {
+			fprintf(stderr, "mkinit: sorry, file names containing "
+				"special characters are not supported.\n");
+			fprintf(stderr, "File name `%s' contains special "
+				"character `%c'.\n", filename, filename[i]);
+			exit(1);
+		}
+	}
 	strcpy(func_name, "mercury");
 	while ((position = strchr(filename, '.')) != NULL) {
 		strcat(func_name, "__");
+		/* replace `f_' with `f__' */
+		if (strncmp(filename, "f_", 2) == 0) {
+			strcat(func_name, "f__");
+			filename += 2;
+		}
 		strncat(func_name, filename, position - filename);
 		filename = position + 1;
 	}
 	/*
 	** The trailing stuff after the last `.' should just be the `c' suffix.
 	*/
-
 	strcat(func_name, "__init");
 
 	output_init_function(func_name);

-- 
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