aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-02-07 16:46:33 -0500
committerRuss Cox <rsc@golang.org>2012-02-07 16:46:33 -0500
commite3755434b8790288a1d48ae3ebf9f4e49c881849 (patch)
tree808cb138d20a3bcac7d95702de005cfeb2dee5e2
parent2cc58e93d6f663af52bcdd4974d319ebe843f764 (diff)
downloadgo-e3755434b8790288a1d48ae3ebf9f4e49c881849.tar.gz
go-e3755434b8790288a1d48ae3ebf9f4e49c881849.zip
5l, 6l, 8l: implement -X flag
R=golang-dev, iant CC=golang-dev https://golang.org/cl/5643050
-rw-r--r--src/cmd/5l/doc.go32
-rw-r--r--src/cmd/5l/obj.c10
-rw-r--r--src/cmd/6l/doc.go45
-rw-r--r--src/cmd/6l/obj.c9
-rw-r--r--src/cmd/8l/doc.go47
-rw-r--r--src/cmd/8l/obj.c9
-rw-r--r--src/cmd/ld/data.c19
-rw-r--r--src/cmd/ld/doc.go46
-rw-r--r--src/cmd/ld/lib.h1
-rw-r--r--test/linkx.go15
10 files changed, 103 insertions, 130 deletions
diff --git a/src/cmd/5l/doc.go b/src/cmd/5l/doc.go
index aa7ccebfc9..969f502a7b 100644
--- a/src/cmd/5l/doc.go
+++ b/src/cmd/5l/doc.go
@@ -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
diff --git a/src/cmd/5l/obj.c b/src/cmd/5l/obj.c
index 03b106d4f0..0cc84d0eaf 100644
--- a/src/cmd/5l/obj.c
+++ b/src/cmd/5l/obj.c
@@ -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;
diff --git a/src/cmd/6l/doc.go b/src/cmd/6l/doc.go
index c18b0f29d5..4d94b209bc 100644
--- a/src/cmd/6l/doc.go
+++ b/src/cmd/6l/doc.go
@@ -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
diff --git a/src/cmd/6l/obj.c b/src/cmd/6l/obj.c
index d258f05c9c..5305c4b797 100644
--- a/src/cmd/6l/obj.c
+++ b/src/cmd/6l/obj.c
@@ -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;
diff --git a/src/cmd/8l/doc.go b/src/cmd/8l/doc.go
index edd683823f..12301d4f2e 100644
--- a/src/cmd/8l/doc.go
+++ b/src/cmd/8l/doc.go
@@ -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
diff --git a/src/cmd/8l/obj.c b/src/cmd/8l/obj.c
index 1d0f1ec0fc..affdb57b7b 100644
--- a/src/cmd/8l/obj.c
+++ b/src/cmd/8l/obj.c
@@ -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;
diff --git a/src/cmd/ld/data.c b/src/cmd/ld/data.c
index d34d23c770..b5f1b99312 100644
--- a/src/cmd/ld/data.c
+++ b/src/cmd/ld/data.c
@@ -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)
{
diff --git a/src/cmd/ld/doc.go b/src/cmd/ld/doc.go
index 972e2a32c9..4728fccb8b 100644
--- a/src/cmd/ld/doc.go
+++ b/src/cmd/ld/doc.go
@@ -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
diff --git a/src/cmd/ld/lib.h b/src/cmd/ld/lib.h
index bbaa52d43c..188ff9f928 100644
--- a/src/cmd/ld/lib.h
+++ b/src/cmd/ld/lib.h
@@ -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
index 0000000000..caa815a391
--- /dev/null
+++ b/test/linkx.go
@@ -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)
+ }
+}