Carl Shapiro pushed to branch master at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • src/lisp/elf.c
    ... ... @@ -11,11 +11,11 @@
    11 11
      $Id: elf.c,v 1.32 2010/12/23 03:20:27 rtoy Exp $
    
    12 12
     */
    
    13 13
     
    
    14
    +#include <stddef.h>
    
    14 15
     #include <stdio.h>
    
    15 16
     #include <stdlib.h>
    
    16 17
     #include <string.h>
    
    17 18
     #include <fcntl.h>
    
    18
    -#include <sys/stat.h>
    
    19 19
     #include <sys/types.h>
    
    20 20
     #include <unistd.h>
    
    21 21
     
    
    ... ... @@ -319,59 +319,65 @@ write_space_object(const char *dir, int id, os_vm_address_t start, os_vm_address
    319 319
         return ret;
    
    320 320
     }
    
    321 321
     
    
    322
    +#ifdef UNICODE
    
    323
    +#define LISPCHAR unsigned short
    
    324
    +#else
    
    325
    +#define LISPCHAR char
    
    326
    +#endif
    
    327
    +
    
    328
    +static LISPCHAR *
    
    329
    +tokenize(LISPCHAR *str, LISPCHAR **end)
    
    330
    +{
    
    331
    +    LISPCHAR *ptr;
    
    332
    +
    
    333
    +    ptr = str;
    
    334
    +again:
    
    335
    +    while (*ptr != '\0' && *ptr != ':')
    
    336
    +	ptr++;
    
    337
    +    if (str == ptr && *ptr == ':') {
    
    338
    +	str = ++ptr;
    
    339
    +	goto again;
    
    340
    +    }
    
    341
    +    *end = ptr;
    
    342
    +    return str;
    
    343
    +}
    
    344
    +
    
    322 345
     int
    
    323 346
     obj_run_linker(long init_func_address, char *file)
    
    324 347
     {
    
    325 348
         lispobj libstring = SymbolValue(CMUCL_LIB);     /* Get library: */
    
    326 349
         struct vector *vec = (struct vector *)PTR(libstring);
    
    327
    -    char *paths;
    
    328
    -    char command[FILENAME_MAX + 1];
    
    329
    -    char command_line[FILENAME_MAX + FILENAME_MAX + 10];
    
    330
    -    char *strptr;
    
    331
    -    struct stat st;
    
    350
    +    char command[PATH_MAX];
    
    351
    +    char command_line[PATH_MAX * 2 + 10];
    
    352
    +    LISPCHAR *strptr, *end = (LISPCHAR *)vec->data;
    
    332 353
         int ret;
    
    333 354
         extern int debug_lisp_search;
    
    334
    -#ifndef UNICODE
    
    335
    -    paths = strdup((char *)vec->data);
    
    336
    -    if (paths == NULL) {
    
    337
    -	perror("strdup");
    
    338
    -	return -1;
    
    339
    -    }
    
    340
    -#else
    
    341
    -    /*
    
    342
    -     * What should we do here with 16-bit characters?  For now we just
    
    343
    -     * take the low 8-bits.
    
    344
    -     */
    
    345
    -    paths = malloc(vec->length);
    
    346
    -    if (paths == NULL) {
    
    347
    -	perror("malloc");
    
    348
    -	return -1;
    
    349
    -    } else {
    
    350
    -        int k;
    
    351
    -        unsigned short *data;
    
    352
    -        data = (unsigned short*) vec->data;
    
    353
    -        
    
    354
    -        for (k = 0; k < vec->length; ++k) {
    
    355
    -            paths[k] = data[k] & 0xff;
    
    356
    -        }
    
    357
    -    }
    
    358
    -#endif
    
    359
    -    strptr = strtok(paths, ":");
    
    360 355
     
    
    361 356
         if (debug_lisp_search) {
    
    362 357
             printf("Searching for linker.sh script\n");
    
    363 358
         }
    
    364 359
     
    
    365
    -    while(strptr != NULL) {
    
    366
    -        
    
    367
    -	sprintf(command, "%s/%s", strptr, LINKER_SCRIPT);
    
    360
    +    while ((strptr = tokenize(end, &end)) != end) {
    
    361
    +	ptrdiff_t len = end - strptr;
    
    362
    +	ptrdiff_t i;
    
    363
    +
    
    364
    +	if (len + strlen("/" LINKER_SCRIPT) > PATH_MAX)
    
    365
    +	    continue;
    
    366
    +
    
    367
    +	/*
    
    368
    +	 * What should we do here with 16-bit characters?  For now we just
    
    369
    +	 * take the low 8-bits.
    
    370
    +	 */
    
    371
    +	for (i = 0; i < len; i++)
    
    372
    +	    command[i] = strptr[i] & 0xFF;
    
    373
    +	command[i] = '\0';
    
    374
    +	strcat(command, "/" LINKER_SCRIPT);
    
    368 375
     
    
    369 376
             if (debug_lisp_search) {
    
    370 377
                 printf("  %s\n", command);
    
    371 378
             }
    
    372 379
             
    
    373
    -	if (stat(command, &st) == 0) {
    
    374
    -	    free(paths);
    
    380
    +	if (access(command, F_OK) == 0) {
    
    375 381
     	    printf("\t[%s: linking %s... \n", command, file);
    
    376 382
     	    fflush(stdout);
    
    377 383
     #if defined(__linux__) || defined(__FreeBSD__) || defined(SOLARIS) || defined(__NetBSD__)
    
    ... ... @@ -394,15 +400,14 @@ obj_run_linker(long init_func_address, char *file)
    394 400
     	    }
    
    395 401
     	    return ret;
    
    396 402
     	}
    
    397
    -	strptr = strtok(NULL, ":");
    
    398 403
         }
    
    399 404
     
    
    400 405
         fprintf(stderr,
    
    401 406
     	    "Can't find %s script in CMUCL library directory list.\n", LINKER_SCRIPT);
    
    402
    -    free(paths);
    
    403 407
         return -1;
    
    404 408
     }
    
    405 409
     
    
    410
    +#undef LISPCHAR
    
    406 411
     
    
    407 412
     /* Read the ELF header from a file descriptor and stuff it into a
    
    408 413
     	 structure.	 Make sure it is really an elf header etc. */