SCO externs ... too many?

Fred Fish fnf at estinc.UUCP
Thu May 4 12:38:52 AEST 1989


In article <631 at jc3b21.UUCP> davis at jc3b21.UUCP (William J Davis) writes:
>
>Experimentation further proved that if the number of externs was reduced
>past some unknown threshold, suddenly the problem would vanish! ;-(
>
>I have a call into SCO, but they say they can't
>help unless they can replicate the problem, short of me sending them
>5 meg of libraries ( yes, I said 5 meg!)  ;-(

This aroused my curiosity about what the limits were for the SCO 2.3.1
compiler and linker (actually the 2.2 development system, which is shipped
with 2.3.1).  This program found that I could have up to 4093 of my own
external symbols before overflowing the internal linker table (this is 
suspiciously close to 4096, but then we don't take into account "main"
and library symbols).

======================================================================

/*
 *	A quick hack to check for limits on the number of external
 *	symbols allowed by the compiler or linker.
 *
 *	Does a binary search from 1 to LIMIT to determine the number
 *	of acceptable symbols.  Set LIMIT higher if necessary.
 *	
 *	This only checks for limits in a single module.  To test for
 *	aggregate limits, it is a straightforward extension to create
 *	and use multiple files once the limit for a single file is
 *	found.
 *
 *	Fred Fish  3-May-89
 */

#include <stdio.h>

#define LIMIT 10000

main ()
{
	int low;
	int high;
	int test;

	low = 1;
	high = LIMIT;
	while (high - low > 1) {
		test = low / 2 + high / 2;
		if (test == low) {
			test++;		/* sneak up on it... */
		}
		if (linkcheck (test) == 0) {
			low = test;
		} else {
			high = test;
		}
	}
	printf ("Maximum of %d syms per file\n", low);
	/* Add code here to write multiple files */
	exit (0);
}

int linkcheck (count)
int count;
{
	register int value;
	FILE *file1;
	FILE *file2;

	printf ("Try %d syms,", count);
	fflush (stdout);
	file1 = fopen ("linktest1.c", "w");
	file2 = fopen ("linktest2.c", "w");
	if (file1 == NULL || file2 == NULL) {
		fprintf ("can't open files\n");
		exit (1);
	}
	printf (" writing decls,");
	fflush (stdout);
	for (value = 1; value <= count; value++) {
		fprintf (file1, "extern int v%d;\n", value);
	}
	printf (" writing defs and asgns,");
	fflush (stdout);
	fprintf (file1, "main () {\n");
	for (value = 1; value <= count; value++) {
		fprintf (file1, "v%d = %d;\n", value, value);
		fprintf (file2, "int v%d;\n", value);
	}
	fprintf (file1, "}\n");
	fclose (file1);
	fclose (file2);
	printf (" compiling and linking\n");
	fflush (stdout);
	return (system ("cc -o linktest linktest1.c linktest2.c"));
}

======================================================================
-- 
# Fred Fish, 1835 E. Belmont Drive, Tempe, AZ 85284,  USA
# 1-602-491-0048           asuvax!{nud,mcdphx}!estinc!fnf



More information about the Comp.unix.xenix mailing list