]> Cypherpunks repositories - gostls13.git/commitdiff
5l, 6l, 8l: implement -X flag
authorRuss Cox <rsc@golang.org>
Tue, 7 Feb 2012 21:46:33 +0000 (16:46 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 7 Feb 2012 21:46:33 +0000 (16:46 -0500)
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5643050

src/cmd/5l/doc.go
src/cmd/5l/obj.c
src/cmd/6l/doc.go
src/cmd/6l/obj.c
src/cmd/8l/doc.go
src/cmd/8l/obj.c
src/cmd/ld/data.c
src/cmd/ld/doc.go
src/cmd/ld/lib.h
test/linkx.go [new file with mode: 0644]

index aa7ccebfc935c4bdd09e220349d9a806e0a4dd21..969f502a7b4e614ca7c5bd3450d565e39f1bde54 100644 (file)
@@ -4,36 +4,10 @@
 
 /*
 
-5l is a modified version of the Plan 9 linker.  The original is documented at
+5l is the linker for the ARM.
+The $GOARCH for these tools is arm.
 
-       http://plan9.bell-labs.com/magic/man2html/1/2l
-
-Its target architecture is the ARM, referred to by these tools as arm.
-It reads files in .5 format generated by 5g, 5c, and 5a and emits
-a binary called 5.out by default.
-
-Major changes include:
-       - support for segmented stacks (this feature is implemented here, not in the compilers).
-
-
-Original options are listed in the link above.
-
-Options new in this version:
-
--F
-       Force use of software floating point.
-       Also implied by setting GOARM=5 in the environment.
--Hlinux
-       Write Linux ELF binaries (default when $GOOS is linux)
--I interpreter
-       Set the ELF dynamic linker to use.
--L dir1 -L dir2
-       Search for libraries (package files) in dir1, dir2, etc.
-       The default is the single location $GOROOT/pkg/$GOOS_arm.
--r dir1:dir2:...
-       Set the dynamic linker search path when using ELF.
--V
-       Print the linker version.
+The flags are documented in ../ld/doc.go.
 
 */
 package documentation
index 03b106d4f0f7410f6e1002119ec2f2fa4ab74ce9..0cc84d0eaf97035b79eb9cc18a105ad072ec61b7 100644 (file)
@@ -81,7 +81,7 @@ void
 main(int argc, char *argv[])
 {
        int c, i;
-       char *p;
+       char *p, *name, *val;
 
        Binit(&bso, 1, OWRITE);
        listinit();
@@ -92,6 +92,7 @@ main(int argc, char *argv[])
        INITDAT = -1;
        INITRND = -1;
        INITENTRY = 0;
+       nuxiinit();
        
        p = getenv("GOARM");
        if(p != nil && strcmp(p, "5") == 0)
@@ -137,9 +138,9 @@ main(int argc, char *argv[])
                print("%cl version %s\n", thechar, getgoversion());
                errorexit();
        case 'X':
-               // TODO: golang.org/issue/2676
-               EARGF(usage());
-               EARGF(usage());
+               name = EARGF(usage());
+               val = EARGF(usage());
+               addstrdata(name, val);
                break;
        } ARGEND
 
@@ -240,7 +241,6 @@ main(int argc, char *argv[])
        histgen = 0;
        pc = 0;
        dtype = 4;
-       nuxiinit();
 
        version = 0;
        cbp = buf.cbuf;
index c18b0f29d553eb44fd2ec61ee691233edaf7232f..4d94b209bc0a13fd3b7ca19451ded201e0d23e05 100644 (file)
@@ -4,49 +4,10 @@
 
 /*
 
-6l is a modified version of the Plan 9 linker.  The original is documented at
-
-       http://plan9.bell-labs.com/magic/man2html/1/2l
-
-Its target architecture is the x86-64, referred to by these tools as amd64.
-It reads files in .6 format generated by 6g, 6c, and 6a and emits
-a binary called 6.out by default.
-
-Major changes include:
-       - support for ELF and Mach-O binary files
-       - support for segmented stacks (this feature is implemented here, not in the compilers).
-
-
-Original options are listed in the link above.
-
-Options new in this version:
-
--d
-       Elide the dynamic linking header.  With this option, the binary
-       is statically linked and does not refer to dynld.  Without this option
-       (the default), the binary's contents are identical but it is loaded with dynld.
--Hdarwin
-       Write Apple Mach-O binaries (default when $GOOS is darwin)
--Hlinux
-       Write Linux ELF binaries (default when $GOOS is linux)
--Hfreebsd
-       Write FreeBSD ELF binaries (default when $GOOS is freebsd)
--Hnetbsd
-       Write NetBSD ELF binaries (default when $GOOS is netbsd)
--Hopenbsd
-       Write OpenBSD ELF binaries (default when $GOOS is openbsd)
--Hwindows
-       Write Windows PE32+ binaries (default when $GOOS is windows)
--I interpreter
-       Set the ELF dynamic linker to use.
--L dir1 -L dir2
-       Search for libraries (package files) in dir1, dir2, etc.
-       The default is the single location $GOROOT/pkg/$GOOS_amd64.
--r dir1:dir2:...
-       Set the dynamic linker search path when using ELF.
--V
-       Print the linker version.
+6l is the linker for the x86-64.
+The $GOARCH for these tools is amd64.
 
+The flags are documented in ../ld/doc.go.
 
 */
 package documentation
index d258f05c9cea3056de5e129f8e10a425787d0f9f..5305c4b7971cfbdf85c80cf086afe7cde15b756c 100644 (file)
@@ -82,6 +82,7 @@ void
 main(int argc, char *argv[])
 {
        int c;
+       char *name, *val;
 
        Binit(&bso, 1, OWRITE);
        listinit();
@@ -93,6 +94,7 @@ main(int argc, char *argv[])
        INITDAT = -1;
        INITRND = -1;
        INITENTRY = 0;
+       nuxiinit();
 
        ARGBEGIN {
        default:
@@ -133,9 +135,9 @@ main(int argc, char *argv[])
                print("%cl version %s\n", thechar, getgoversion());
                errorexit();
        case 'X':
-               // TODO: golang.org/issue/2676
-               EARGF(usage());
-               EARGF(usage());
+               name = EARGF(usage());
+               val = EARGF(usage());
+               addstrdata(name, val);
                break;
        } ARGEND
 
@@ -253,7 +255,6 @@ main(int argc, char *argv[])
        zprg.mode = 64;
 
        pcstr = "%.6llux ";
-       nuxiinit();
        histgen = 0;
        pc = 0;
        dtype = 4;
index edd683823f55324b94022ee47c7dbf84f80c401a..12301d4f2ebc0cde1f8d11a5749c0d887afe73c3 100644 (file)
@@ -4,51 +4,10 @@
 
 /*
 
-8l is a modified version of the Plan 9 linker.  The original is documented at
-
-       http://plan9.bell-labs.com/magic/man2html/1/2l
-
-Its target architecture is the x86, referred to by these tools for historical reasons as 386.
-It reads files in .8 format generated by 8g, 8c, and 8a and emits
-a binary called 8.out by default.
-
-Major changes include:
-       - support for ELF and Mach-O binary files
-       - support for segmented stacks (this feature is implemented here, not in the compilers).
-
-
-Original options are listed in the link above.
-
-Options new in this version:
-
--d
-       Elide the dynamic linking header.  With this option, the binary
-       is statically linked and does not refer to dynld.  Without this option
-       (the default), the binary's contents are identical but it is loaded with dynld.
--Hplan9
-       Write Plan 9 32-bit format binaries (default when $GOOS is plan9)
--Hdarwin
-       Write Apple Mach-O binaries (default when $GOOS is darwin)
--Hlinux
-       Write Linux ELF binaries (default when $GOOS is linux)
--Hfreebsd
-       Write FreeBSD ELF binaries (default when $GOOS is freebsd)
--Hnetbsd
-       Write NetBSD ELF binaries (default when $GOOS is netbsd)
--Hopenbsd
-       Write OpenBSD ELF binaries (default when $GOOS is openbsd)
--Hwindows
-       Write Windows PE32 binaries (default when $GOOS is windows)
--I interpreter
-       Set the ELF dynamic linker to use.
--L dir1 -L dir2
-       Search for libraries (package files) in dir1, dir2, etc.
-       The default is the single location $GOROOT/pkg/$GOOS_386.
--r dir1:dir2:...
-       Set the dynamic linker search path when using ELF.
--V
-       Print the linker version.
+8l is the linker for the 32-bit x86.
+The $GOARCH for these tools is 386.
 
+The flags are documented in ../ld/doc.go.
 
 */
 package documentation
index 1d0f1ec0fce070bbf5cbe76a17f5fb0089532e2b..affdb57b7be029d1bf31f40d48ff1b0bdb2ca5e1 100644 (file)
@@ -87,6 +87,7 @@ void
 main(int argc, char *argv[])
 {
        int c;
+       char *name, *val;
 
        Binit(&bso, 1, OWRITE);
        listinit();
@@ -98,6 +99,7 @@ main(int argc, char *argv[])
        INITDAT = -1;
        INITRND = -1;
        INITENTRY = 0;
+       nuxiinit();
 
        ARGBEGIN {
        default:
@@ -138,9 +140,9 @@ main(int argc, char *argv[])
                print("%cl version %s\n", thechar, getgoversion());
                errorexit();
        case 'X':
-               // TODO: golang.org/issue/2676
-               EARGF(usage());
-               EARGF(usage());
+               name = EARGF(usage());
+               val = EARGF(usage());
+               addstrdata(name, val);
                break;
        } ARGEND
 
@@ -280,7 +282,6 @@ main(int argc, char *argv[])
        zprg.to = zprg.from;
 
        pcstr = "%.6ux ";
-       nuxiinit();
        histgen = 0;
        pc = 0;
        dtype = 4;
index d34d23c7702875457d38e7068acb60a30f4e4184..b5f1b99312c6b62ee713369b62501d8c29250ab9 100644 (file)
@@ -589,6 +589,25 @@ strnput(char *s, int n)
        }
 }
 
+void
+addstrdata(char *name, char *value)
+{
+       Sym *s, *sp;
+       char *p;
+       
+       p = smprint("%s.str", name);
+       sp = lookup(p, 0);
+       free(p);
+       addstring(sp, value);
+
+       s = lookup(name, 0);
+       s->dupok = 1;
+       addaddr(s, sp);
+       adduint32(s, strlen(value));
+       if(PtrSize == 8)
+               adduint32(s, 0);  // round struct to pointer width
+}
+
 vlong
 addstring(Sym *s, char *str)
 {
index 972e2a32c951171ad90cd94241d3f9d07a1d47b8..4728fccb8b43fc1da8cd322a448504c17040cfd7 100644 (file)
@@ -4,8 +4,50 @@
 
 /*
 
-This directory contains the portable section of the Plan 9 C linkers.
-See ../6l, ../8l, and ../5l for more information.
+Ld is the portable code for a modified version of the Plan 9 linker.  The original is documented at
+
+       http://plan9.bell-labs.com/magic/man2html/1/2l
+
+It reads object files (.5, .6, or .8 files) and writes a binary named for the
+architecture (5.out, 6.out, 8.out) by default.
+
+Major changes include:
+       - support for ELF and Mach-O binary files
+       - support for segmented stacks (this feature is implemented here, not in the compilers).
+
+Original options are listed on the manual page linked above.
+
+Options new in this version:
+
+-d
+       Elide the dynamic linking header.  With this option, the binary
+       is statically linked and does not refer to dynld.  Without this option
+       (the default), the binary's contents are identical but it is loaded with dynld.
+-Hdarwin
+       Write Apple Mach-O binaries (default when $GOOS is darwin)
+-Hlinux
+       Write Linux ELF binaries (default when $GOOS is linux)
+-Hfreebsd
+       Write FreeBSD ELF binaries (default when $GOOS is freebsd)
+-Hnetbsd
+       Write NetBSD ELF binaries (default when $GOOS is netbsd)
+-Hopenbsd
+       Write OpenBSD ELF binaries (default when $GOOS is openbsd)
+-Hwindows
+       Write Windows PE32+ binaries (default when $GOOS is windows)
+-I interpreter
+       Set the ELF dynamic linker to use.
+-L dir1 -L dir2
+       Search for libraries (package files) in dir1, dir2, etc.
+       The default is the single location $GOROOT/pkg/$GOOS_amd64.
+-r dir1:dir2:...
+       Set the dynamic linker search path when using ELF.
+-V
+       Print the linker version.
+-X symbol value
+       Set the value of an otherwise uninitialized string variable.
+       The symbol name should be of the form importpath.name,
+       as displayed in the symbol table printed by "go tool nm".
 
 */
 package documentation
index bbaa52d43c0b1dd7d6320d1d19ce29832fc513dc..188ff9f928767bbc250ac23a4584134bec9bc3df 100644 (file)
@@ -179,6 +179,7 @@ void        reloc(void);
 void   relocsym(Sym*);
 void   savedata(Sym*, Prog*, char*);
 void   symgrow(Sym*, int32);
+void   addstrdata(char*, char*);
 vlong  addstring(Sym*, char*);
 vlong  adduint32(Sym*, uint32);
 vlong  adduint64(Sym*, uint64);
diff --git a/test/linkx.go b/test/linkx.go
new file mode 100644 (file)
index 0000000..caa815a
--- /dev/null
@@ -0,0 +1,15 @@
+// $G $D/$F.go && $L -X main.tbd hello $F.$A && ./$A.out
+
+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+var tbd string
+
+func main() {
+       if tbd != "hello" {
+               println("BUG: test/linkx", len(tbd), tbd)
+       }
+}