diff options
author | Shenghou Ma <minux.ma@gmail.com> | 2012-03-03 04:14:31 +0800 |
---|---|---|
committer | Shenghou Ma <minux.ma@gmail.com> | 2012-03-03 04:14:31 +0800 |
commit | 5aea33742a946b177590d44e6942ff781a18f111 (patch) | |
tree | 7634ed472fb642f72ce8d63d7140efaa6d2b881f | |
parent | 6474eda490bbac1d24822e04081ca0f16389ae9d (diff) | |
download | go-5aea33742a946b177590d44e6942ff781a18f111.tar.gz go-5aea33742a946b177590d44e6942ff781a18f111.zip |
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
-rw-r--r-- | src/cmd/ld/lib.c | 21 | ||||
-rw-r--r-- | src/cmd/ld/lib.h | 2 |
2 files changed, 17 insertions, 6 deletions
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; |