shcc diffs
Roger Florkowski
roger at banzai.UUCP
Wed Feb 8 09:16:11 AEST 1989
Diffs to shcc.
The problem is in combining multiple .c files in a -c usage line. Example:
shcc -c -O -I/usr/local/include -Dunixpc file1.c file2.c file3.c file4.c
file1.c:
shcc: Can't find /lib/optim
file1.c:
file2.c:
shcc: Can't find /lib/optim
file1.c:
file2.c:
file3.c:
shcc: Can't find /lib/optim
file1.c:
file2.c:
file3.c:
file4.c:
shcc: Can't find /lib/optim
The cause:
shcc doesn't quarantee an ending 0 its argv vectors. Therefor the execp
line can end up with trailing garbage.
The Affected files.
load.c more verbose. Changes in call to callsys().
options.c Added room for trailing 0.
passes.c made it always call AddArg() when it is adding
arguments to internal argv arrays. This quarantees
that numarg for that argv will be correct.
Made changes in call to callsys().
shcc.c Added argc to callsys(). This tells us where to put
the trailing 0. Made it more verbose. It now shows
the programs it is execing and the arguments that it
is passing off.
==================== diffs start here ======================================
diff -c shcc.orig/load.c shcc/load.c
*** shcc.orig/load.c Tue Feb 7 17:12:09 1989
--- shcc/load.c Sat Jan 21 04:27:56 1989
***************
*** 49,56 ****
extern char *strcpy(), *strcat(), *tempnam();
extern int strlen(), unlink();
- if( verbose )
- (void) printf( "Loading ...\n" );
/*
* Finish of arguments on the tail end
--- 49,54 ----
***************
*** 60,65 ****
--- 58,65 ----
/*
* Only one ld(1) pass
*/
+ if( verbose )
+ (void) printf( "Loading ...\n" );
argc = FIRSTLD;
while( argc < ldinargc )
ldoutargv = AddArg( ldinargv[argc++], ldoutargv,
***************
*** 110,116 ****
path = stralloc( strlen(ldpath) + strlen(ld) );
(void) strcat( strcpy( path, ldpath ), ld );
! if( callsys( path, &ldoutargv[argc] ) )
exitstatus = 1;
} else {
--- 110,116 ----
path = stralloc( strlen(ldpath) + strlen(ld) );
(void) strcat( strcpy( path, ldpath ), ld );
! if( callsys( path, &ldoutargv[argc], ldoutargc - argc) )
exitstatus = 1;
} else {
***************
*** 118,123 ****
--- 118,125 ----
* Two pass version
*/
+ if( verbose )
+ (void) printf( "Loading first pass ...\n" );
if( debug )
ldinargv = AddArg( "-lg", ldinargv,
&ldinargc, &ldinmax );
***************
*** 148,159 ****
path = stralloc( strlen(ldpath) + strlen(ld) );
(void) strcat( strcpy( path, ldpath ), ld );
! if( callsys( path, &ldinargv[argc] ) ) {
exitstatus = 1;
} else {
/*
* Second ld(1) pass
*/
if( !givenifile ) {
tmp[ numtmp++ ] = ifile = tempnam( TMPDIR, TMPFX );
}
--- 150,163 ----
path = stralloc( strlen(ldpath) + strlen(ld) );
(void) strcat( strcpy( path, ldpath ), ld );
! if( callsys( path, &ldinargv[argc], ldinargc - argc ) ) {
exitstatus = 1;
} else {
/*
* Second ld(1) pass
*/
+ if( verbose )
+ (void) printf( "Resolving symbols ...\n" );
if( !givenifile ) {
tmp[ numtmp++ ] = ifile = tempnam( TMPDIR, TMPFX );
}
***************
*** 173,179 ****
}
ldoutargv[argc] = ld;
! if( callsys( path, &ldoutargv[argc] ) )
exitstatus = 1;
}
}
--- 177,183 ----
}
ldoutargv[argc] = ld;
! if( callsys( path, &ldoutargv[argc], ldoutargc - argc))
exitstatus = 1;
}
}
diff -c shcc.orig/options.c shcc/options.c
*** shcc.orig/options.c Tue Feb 7 17:12:04 1989
--- shcc/options.c Sat Jan 21 02:46:47 1989
***************
*** 271,284 ****
if( argv ) {
free( (char *) argv );
argv = (char **) realloc( (char *) argv,
! (*max * sizeof(char *)) );
} else {
! argv = (char **) malloc( (*max * sizeof(char *)) );
}
if( !argv )
fatal( 1, "out of memory(AddArg)" );
}
argv[ (*argc)++ ] = arg;
return( argv );
}
--- 271,285 ----
if( argv ) {
free( (char *) argv );
argv = (char **) realloc( (char *) argv,
! (*max * sizeof(char *)) + 1 );
} else {
! argv = (char **) malloc( (*max * sizeof(char *)) + 1 );
}
if( !argv )
fatal( 1, "out of memory(AddArg)" );
}
argv[ (*argc)++ ] = arg;
+ argv[ (*argc) ] = NULL; /* guarantee an ending zero */
return( argv );
}
diff -c shcc.orig/passes.c shcc/passes.c
*** shcc.orig/passes.c Tue Feb 7 17:12:07 1989
--- shcc/passes.c Sat Jan 21 04:27:33 1989
***************
*** 167,190 ****
*/
if( passes & COMPILE ) {
! if( fpu == 68881 )
! ccom = ccom2081;
! else if( cpu == 68020 )
! ccom = ccom20;
! ccomin = ccomargc++;
! ccomout = ccomargc++;
! if( profile )
! ccomargv = AddArg( "-XP", ccomargv, &ccomargc,
&ccommax );
! if( Kflag )
! ccomargv = AddArg( "-XK", ccomargv, &ccomargc,
&ccommax );
! ccomargv = AddArg( NULL, ccomargv, &ccomargc, &ccommax );
! ccomargv[ccomin] = cppargv[cppout];
! if( passes & (OPTIMIZE|ASSEMBLE) ) {
! ccomargv[ccomout] = tempnam( TMPDIR, TMPFX );
! tmp[ numtmp++ ] = ccomargv[ccomout];
! }
}
/*
--- 167,188 ----
*/
if( passes & COMPILE ) {
! if( fpu == 68881 )
! ccom = ccom2081;
! else if( cpu == 68020 )
! ccom = ccom20;
! if( profile )
! ccomargv = AddArg( "-XP", ccomargv, &ccomargc,
&ccommax );
! if( Kflag )
! ccomargv = AddArg( "-XK", ccomargv, &ccomargc,
&ccommax );
! ccomin = ccomargc;
! ccomargv = AddArg( cppargv[cppout], ccomargv, &ccomargc, &ccommax );
! ccomout = ccomargc;
! if( passes & (OPTIMIZE|ASSEMBLE) )
! ccomargv = AddArg ((tmp[numtmp++] = tempnam (TMPDIR, TMPFX)),
! ccomargv, &ccomargc, &ccommax);
}
/*
***************
*** 192,205 ****
*/
if( passes & OPTIMIZE ) {
! optimargv = AddArg( NULL, optimargv, &optimargc, &optimmax );
! optimin = 1;
! optimout = 2;
! optimargv[optimin] = ccomargv[ccomout];
! if( passes & ASSEMBLE ) {
! optimargv[optimout] = tempnam( TMPDIR, TMPFX );
! tmp[ numtmp++ ] = optimargv[optimout];
! }
}
/*
--- 190,202 ----
*/
if( passes & OPTIMIZE ) {
! optimin = optimargc;
! optimargv = AddArg( ccomargv[ccomout], optimargv,
! &optimargc, &optimmax );
! optimout = optimargc;
! if( passes & ASSEMBLE )
! optimargv = AddArg ((tmp[numtmp++] = tempnam (TMPDIR, TMPFX)),
! optimargv, &optimargc, &optimmax);
}
/*
***************
*** 273,279 ****
path = stralloc( strlen(cpppath) + strlen(cpp) );
(void) strcat( strcpy( path, cpppath ), cpp );
cppargv[0] = cpp;
! if( callsys( path, cppargv ) ) {
reqdpasses = 0;
passes &= ~LOAD;
exitstatus = 1;
--- 270,276 ----
path = stralloc( strlen(cpppath) + strlen(cpp) );
(void) strcat( strcpy( path, cpppath ), cpp );
cppargv[0] = cpp;
! if( callsys( path, cppargv, cppargc ) ) {
reqdpasses = 0;
passes &= ~LOAD;
exitstatus = 1;
***************
*** 293,299 ****
path = stralloc( strlen(ccompath) + strlen(ccom) );
(void) strcat( strcpy( path, ccompath ), ccom );
ccomargv[0] = ccom;
! if( callsys( path, ccomargv ) ) {
reqdpasses = 0;
passes &= ~LOAD;
exitstatus = 1;
--- 290,296 ----
path = stralloc( strlen(ccompath) + strlen(ccom) );
(void) strcat( strcpy( path, ccompath ), ccom );
ccomargv[0] = ccom;
! if( callsys( path, ccomargv, ccomargc ) ) {
reqdpasses = 0;
passes &= ~LOAD;
exitstatus = 1;
***************
*** 313,319 ****
path = stralloc( strlen(optimpath) + strlen(optim) );
(void) strcat( strcpy( path, optimpath ), optim );
optimargv[0] = optim;
! if( callsys( path, optimargv ) ) {
reqdpasses = 0;
passes &= ~LOAD;
exitstatus = 1;
--- 310,316 ----
path = stralloc( strlen(optimpath) + strlen(optim) );
(void) strcat( strcpy( path, optimpath ), optim );
optimargv[0] = optim;
! if( callsys( path, optimargv, optimargc ) ) {
reqdpasses = 0;
passes &= ~LOAD;
exitstatus = 1;
***************
*** 331,337 ****
path = stralloc( strlen(aspath) + strlen(as) );
(void) strcat( strcpy( path, aspath ), as );
asargv[0] = as;
! if( callsys( path, asargv ) ) {
reqdpasses = 0;
passes &= ~LOAD;
exitstatus = 1;
--- 328,334 ----
path = stralloc( strlen(aspath) + strlen(as) );
(void) strcat( strcpy( path, aspath ), as );
asargv[0] = as;
! if( callsys( path, asargv, asargc ) ) {
reqdpasses = 0;
passes &= ~LOAD;
exitstatus = 1;
diff -c shcc.orig/shcc.c shcc/shcc.c
*** shcc.orig/shcc.c Tue Feb 7 17:12:00 1989
--- shcc/shcc.c Sat Jan 21 04:16:06 1989
***************
*** 214,222 ****
*/
int
! callsys( path, argv )
char *path;
char **argv;
{
int pid;
int status;
--- 214,223 ----
*/
int
! callsys( path, argv, argc )
char *path;
char **argv;
+ int argc; /* the number of arguments we expect ot pass off */
{
int pid;
int status;
***************
*** 223,252 ****
extern int errno;
extern int fork(), execv(), wait();
if( display ) {
! status = 0;
! (void) printf( "callsys %s:", path );
! while(*argv)
! (void) printf( " '%s'", *argv++ );
! (void) putchar( '\n' );
! } else {
! pid = fork();
! switch( pid ) {
! case -1:
! fatal( 1, "No more processes" );
! break;
! case 0:
! (void) execv( path, argv );
! fatal( 1, "Can't find %s", path );
! break;
! default:
! status = 1;
! while( wait( &status ) == -1 && errno == EINTR )
! ;
! break;
! }
}
return( status );
}
--- 224,262 ----
extern int errno;
extern int fork(), execv(), wait();
+ argv[argc] = NULL; /* guarantee ending NULL */
if( display ) {
! status = 0;
! (void) printf( "callsys %s:", path );
! while(*argv)
! (void) printf( " '%s'", *argv++ );
! (void) putchar( '\n' );
! return(status);
}
+ if (verbose){
+ char **arg;
+ arg = argv + 1; /* increment past program name */
+ (void) printf ("\t%s", path);
+ while(*arg)
+ (void) printf ( " %s", *arg++ );
+ (void) putchar( '\n' );
+ }
+ pid = fork();
+ switch( pid ) {
+ case -1:
+ fatal( 1, "No more processes" );
+ break;
+ case 0:
+ (void) execv( path, argv );
+ fatal( 1, "Can't find %s", path );
+ break;
+ default:
+ status = 1;
+ while( wait( &status ) == -1 && errno == EINTR )
+ ;
+ break;
+ }
return( status );
}
--
Roger Florkowski {uunet!uvm-gen, attmail}!banzai!roger
The People's Computer Company `Revolutionary Programming'
More information about the Unix-pc.sources
mailing list