aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ld
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 /src/cmd/ld
parent2cc58e93d6f663af52bcdd4974d319ebe843f764 (diff)
downloadgo-e3755434b8790288a1d48ae3ebf9f4e49c881849.tar.xz
5l, 6l, 8l: implement -X flag
R=golang-dev, iant CC=golang-dev https://golang.org/cl/5643050
Diffstat (limited to 'src/cmd/ld')
-rw-r--r--src/cmd/ld/data.c19
-rw-r--r--src/cmd/ld/doc.go46
-rw-r--r--src/cmd/ld/lib.h1
3 files changed, 64 insertions, 2 deletions
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);