From: Shenghou Ma Date: Fri, 2 Mar 2012 20:14:31 +0000 (+0800) Subject: ld: allow more -L options X-Git-Tag: weekly.2012-03-04~26 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5aea33742a946b177590d44e6942ff781a18f111;p=gostls13.git ld: allow more -L options Dynamically allocate the libdir array, so we won't need to bother it again. Enhances CL 5727043. R=rsc CC=golang-dev https://golang.org/cl/5731043 --- diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c index 34440b8758..94ad3504db 100644 --- a/src/cmd/ld/lib.c +++ b/src/cmd/ld/lib.c @@ -39,8 +39,9 @@ int iconv(Fmt*); char symname[] = SYMDEF; char pkgname[] = "__.PKGDEF"; -char* libdir[16]; +char** libdir; int nlibdir = 0; +static int maxlibdir = 0; static int cout = -1; char* goroot; @@ -51,9 +52,19 @@ char* theline; void Lflag(char *arg) { - if(nlibdir >= nelem(libdir)-1) { - print("too many -L's: %d\n", nlibdir); - usage(); + char **p; + + if(nlibdir >= maxlibdir) { + if (maxlibdir == 0) + maxlibdir = 8; + else + maxlibdir *= 2; + p = realloc(libdir, maxlibdir); + if (p == nil) { + print("too many -L's: %d\n", nlibdir); + usage(); + } + libdir = p; } libdir[nlibdir++] = arg; } @@ -69,7 +80,7 @@ libinit(void) print("goarch is not known: %s\n", goarch); // add goroot to the end of the libdir list. - libdir[nlibdir++] = smprint("%s/pkg/%s_%s", goroot, goos, goarch); + Lflag(smprint("%s/pkg/%s_%s", goroot, goos, goarch)); // Unix doesn't like it when we write to a running (or, sometimes, // recently run) binary, so remove the output file before writing it. diff --git a/src/cmd/ld/lib.h b/src/cmd/ld/lib.h index 9e39c74703..02dac6e1c8 100644 --- a/src/cmd/ld/lib.h +++ b/src/cmd/ld/lib.h @@ -103,7 +103,7 @@ struct Section }; extern char symname[]; -extern char *libdir[]; +extern char **libdir; extern int nlibdir; EXTERN char* INITENTRY;