]> Cypherpunks repositories - gostls13.git/commitdiff
ld: allow more -L options
authorShenghou Ma <minux.ma@gmail.com>
Fri, 2 Mar 2012 20:14:31 +0000 (04:14 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Fri, 2 Mar 2012 20:14:31 +0000 (04:14 +0800)
        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

src/cmd/ld/lib.c
src/cmd/ld/lib.h

index 34440b8758be7bce0ecd7e5bcf9d8ae7939b95b0..94ad3504db6c53b8765b4e74137bac9b91a2b5ee 100644 (file)
@@ -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.
index 9e39c74703d744c6665982a85b1e387e7e5026d2..02dac6e1c89b3914aca5e05a5139b45e4a6706c1 100644 (file)
@@ -103,7 +103,7 @@ struct Section
 };
 
 extern char    symname[];
-extern char    *libdir[];
+extern char    **libdir;
 extern int     nlibdir;
 
 EXTERN char*   INITENTRY;