Commit dca5f2e9 authored by Russ Cox's avatar Russ Cox

cmd/5l etc: replace C code with Go code

mv cmd/new5l cmd/5l and so on.

Minimal changes to cmd/dist and cmd/go to keep things building.
More can be deleted in followup CLs.

Change-Id: I1449eca7654ce2580d1f413a56dc4a75f3d4618b
Reviewed-on: https://go-review.googlesource.com/6361Reviewed-by: 's avatarRob Pike <r@golang.org>
parent 100d64b9
# 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.
include ../../Make.dist
This diff is collapsed.
// Copyright 2009 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.
// +build ignore
/*
5l is the linker for the ARM.
The $GOARCH for these tools is arm.
The flags are documented in ../ld/doc.go.
*/
package main
// Inferno utils/5l/l.h
// http://code.google.com/p/inferno-os/source/browse/utils/5l/l.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <link.h>
enum
{
thechar = '5',
PtrSize = 4,
IntSize = 4,
RegSize = 4,
MaxAlign = 8, // max data alignment
FuncAlign = 4, // single-instruction alignment
MINLC = 4,
};
#ifndef EXTERN
#define EXTERN extern
#endif
void adddynlib(char *lib);
void adddynrel(LSym *s, Reloc *r);
void adddynrela(LSym *rel, LSym *s, Reloc *r);
void adddynsym(Link *ctxt, LSym *s);
int archreloc(Reloc *r, LSym *s, vlong *val);
vlong archrelocvariant(Reloc *r, LSym *s, vlong t);
void asmb(void);
int elfreloc1(Reloc *r, vlong sectoff);
void elfsetupplt(void);
int machoreloc1(Reloc *r, vlong sectoff);
/* Used by ../ld/dwarf.c */
enum
{
DWARFREGSP = 13
};
// Inferno utils/5l/obj.c
// http://code.google.com/p/inferno-os/source/browse/utils/5l/obj.c
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// Reading object files.
#include "l.h"
#include "../ld/lib.h"
#include "../ld/elf.h"
#include "../ld/macho.h"
#include "../ld/dwarf.h"
#include <ar.h>
void
main(int argc, char **argv)
{
linkarchinit();
ldmain(argc, argv);
}
void
linkarchinit(void)
{
thestring = "arm";
thelinkarch = &linkarm;
thearch.thechar = thechar;
thearch.ptrsize = thelinkarch->ptrsize;
thearch.intsize = thelinkarch->ptrsize;
thearch.regsize = thelinkarch->regsize;
thearch.funcalign = FuncAlign;
thearch.maxalign = MaxAlign;
thearch.minlc = MINLC;
thearch.dwarfregsp = DWARFREGSP;
thearch.adddynlib = adddynlib;
thearch.adddynrel = adddynrel;
thearch.adddynsym = adddynsym;
thearch.archinit = archinit;
thearch.archreloc = archreloc;
thearch.archrelocvariant = archrelocvariant;
thearch.asmb = asmb;
thearch.elfreloc1 = elfreloc1;
thearch.elfsetupplt = elfsetupplt;
thearch.gentext = gentext;
thearch.machoreloc1 = machoreloc1;
thearch.lput = lputl;
thearch.wput = wputl;
thearch.vput = vputl;
thearch.linuxdynld = "/lib/ld-linux.so.3"; // 2 for OABI, 3 for EABI
thearch.freebsddynld = "/usr/libexec/ld-elf.so.1";
thearch.openbsddynld = "XXX";
thearch.netbsddynld = "/libexec/ld.elf_so";
thearch.dragonflydynld = "XXX";
thearch.solarisdynld = "XXX";
}
void
archinit(void)
{
LSym *s;
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash.
if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0)
linkmode = LinkInternal;
switch(HEADTYPE) {
default:
if(linkmode == LinkAuto)
linkmode = LinkInternal;
if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0)
sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
break;
case Hlinux:
case Hfreebsd:
case Hnacl:
case Hdarwin:
break;
}
switch(HEADTYPE) {
default:
diag("unknown -H option");
errorexit();
case Hplan9: /* plan 9 */
HEADR = 32L;
if(INITTEXT == -1)
INITTEXT = 4128;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hlinux: /* arm elf */
case Hfreebsd:
case Hnetbsd:
debug['d'] = 0; // with dynamic linking
elfinit();
HEADR = ELFRESERVE;
if(INITTEXT == -1)
INITTEXT = 0x10000 + HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hnacl:
elfinit();
HEADR = 0x10000;
funcalign = 16;
if(INITTEXT == -1)
INITTEXT = 0x20000;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 0x10000;
break;
case Hdarwin: /* apple MACH */
debug['w'] = 1; // disable DWARF generataion
machoinit();
HEADR = INITIAL_MACHO_HEADR;
if(INITTEXT == -1)
INITTEXT = 4096+HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
}
if(INITDAT != 0 && INITRND != 0)
print("warning: -D0x%ux is ignored because of -R0x%ux\n",
INITDAT, INITRND);
// embed goarm to runtime.goarm
s = linklookup(ctxt, "runtime.goarm", 0);
s->type = SRODATA;
adduint8(ctxt, s, ctxt->goarm);
}
# 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.
include ../../Make.dist
This diff is collapsed.
// Copyright 2009 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.
// +build ignore
/*
6l is the linker for the x86-64.
The $GOARCH for these tools is amd64.
The flags are documented in ../ld/doc.go.
*/
package main
// Inferno utils/6l/l.h
// http://code.google.com/p/inferno-os/source/browse/utils/6l/l.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <link.h>
#ifndef EXTERN
#define EXTERN extern
#endif
enum
{
thechar = '6',
MaxAlign = 32, // max data alignment
FuncAlign = 16
};
enum
{
MINLC = 1,
};
void adddynlib(char *lib);
void adddynrel(LSym *s, Reloc *r);
void adddynrela(LSym *rela, LSym *s, Reloc *r);
void adddynsym(Link *ctxt, LSym *s);
int archreloc(Reloc *r, LSym *s, vlong *val);
vlong archrelocvariant(Reloc *r, LSym *s, vlong t);
void asmb(void);
int elfreloc1(Reloc *r, vlong sectoff);
void elfsetupplt(void);
int machoreloc1(Reloc *r, vlong sectoff);
/* Used by ../ld/dwarf.c */
enum
{
DWARFREGSP = 7
};
// Inferno utils/6l/obj.c
// http://code.google.com/p/inferno-os/source/browse/utils/6l/obj.c
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// Reading object files.
#include "l.h"
#include "../ld/lib.h"
#include "../ld/elf.h"
#include "../ld/macho.h"
#include "../ld/dwarf.h"
#include "../ld/pe.h"
#include <ar.h>
void
main(int argc, char **argv)
{
linkarchinit();
ldmain(argc, argv);
}
void
linkarchinit(void)
{
thestring = "amd64";
thelinkarch = &linkamd64;
if(strcmp(getgoarch(), "amd64p32") == 0)
thelinkarch = &linkamd64p32;
thearch.thechar = thechar;
thearch.ptrsize = thelinkarch->ptrsize;
thearch.intsize = thelinkarch->ptrsize;
thearch.regsize = thelinkarch->regsize;
thearch.funcalign = FuncAlign;
thearch.maxalign = MaxAlign;
thearch.minlc = MINLC;
thearch.dwarfregsp = DWARFREGSP;
thearch.adddynlib = adddynlib;
thearch.adddynrel = adddynrel;
thearch.adddynsym = adddynsym;
thearch.archinit = archinit;
thearch.archreloc = archreloc;
thearch.archrelocvariant = archrelocvariant;
thearch.asmb = asmb;
thearch.elfreloc1 = elfreloc1;
thearch.elfsetupplt = elfsetupplt;
thearch.gentext = gentext;
thearch.machoreloc1 = machoreloc1;
thearch.lput = lputl;
thearch.wput = wputl;
thearch.vput = vputl;
thearch.linuxdynld = "/lib64/ld-linux-x86-64.so.2";
thearch.freebsddynld = "/libexec/ld-elf.so.1";
thearch.openbsddynld = "/usr/libexec/ld.so";
thearch.netbsddynld = "/libexec/ld.elf_so";
thearch.dragonflydynld = "/usr/libexec/ld-elf.so.2";
thearch.solarisdynld = "/lib/amd64/ld.so.1";
}
void
archinit(void)
{
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash.
if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0)
linkmode = LinkInternal;
if(flag_shared)
linkmode = LinkExternal;
switch(HEADTYPE) {
default:
if(linkmode == LinkAuto)
linkmode = LinkInternal;
if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0)
sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
break;
case Hdarwin:
case Hdragonfly:
case Hfreebsd:
case Hlinux:
case Hnacl:
case Hnetbsd:
case Hopenbsd:
case Hsolaris:
break;
}
switch(HEADTYPE) {
default:
diag("unknown -H option");
errorexit();
case Hplan9: /* plan 9 */
HEADR = 32L + 8L;
if(INITTEXT == -1)
INITTEXT = 0x200000+HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 0x200000;
break;
case Helf: /* elf32 executable */
HEADR = rnd(52L+3*32L, 16);
if(INITTEXT == -1)
INITTEXT = 0x80110000L;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hdarwin: /* apple MACH */
machoinit();
HEADR = INITIAL_MACHO_HEADR;
if(INITRND == -1)
INITRND = 4096;
if(INITTEXT == -1)
INITTEXT = 4096+HEADR;
if(INITDAT == -1)
INITDAT = 0;
break;
case Hlinux: /* elf64 executable */
case Hfreebsd: /* freebsd */
case Hnetbsd: /* netbsd */
case Hopenbsd: /* openbsd */
case Hdragonfly: /* dragonfly */
case Hsolaris: /* solaris */
elfinit();
HEADR = ELFRESERVE;
if(INITTEXT == -1)
INITTEXT = (1<<22)+HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hnacl:
elfinit();
debug['w']++; // disable dwarf, which gets confused and is useless anyway
HEADR = 0x10000;
funcalign = 32;
if(INITTEXT == -1)
INITTEXT = 0x20000;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 0x10000;
break;
case Hwindows: /* PE executable */
peinit();
HEADR = PEFILEHEADR;
if(INITTEXT == -1)
INITTEXT = PEBASE+PESECTHEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = PESECTALIGN;
break;
}
if(INITDAT != 0 && INITRND != 0)
print("warning: -D0x%llux is ignored because of -R0x%ux\n",
INITDAT, INITRND);
}
# 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.
include ../../Make.dist
This diff is collapsed.
// Copyright 2009 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.
// +build ignore
/*
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 main
// Inferno utils/8l/l.h
// http://code.google.com/p/inferno-os/source/browse/utils/8l/l.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <link.h>
#ifndef EXTERN
#define EXTERN extern
#endif
enum
{
thechar = '8',
PtrSize = 4,
IntSize = 4,
RegSize = 4,
MaxAlign = 32, // max data alignment
FuncAlign = 16,
MINLC = 1,
};
void adddynlib(char *lib);
void adddynrel(LSym *s, Reloc *r);
void adddynrela(LSym *rela, LSym *s, Reloc *r);
void adddynsym(Link *ctxt, LSym *s);
int archreloc(Reloc *r, LSym *s, vlong *val);
vlong archrelocvariant(Reloc *r, LSym *s, vlong t);
void asmb(void);
int elfreloc1(Reloc *r, vlong sectoff);
void elfsetupplt(void);
int machoreloc1(Reloc *r, vlong sectoff);
/* Used by ../ld/dwarf.c */
enum
{
DWARFREGSP = 4
};
// Inferno utils/8l/obj.c
// http://code.google.com/p/inferno-os/source/browse/utils/8l/obj.c
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// Reading object files.
#include "l.h"
#include "../ld/lib.h"
#include "../ld/elf.h"
#include "../ld/macho.h"
#include "../ld/dwarf.h"
#include "../ld/pe.h"
#include <ar.h>
void
main(int argc, char **argv)
{
linkarchinit();
ldmain(argc, argv);
}
void
linkarchinit(void)
{
thestring = "386";
thelinkarch = &link386;
thearch.thechar = thechar;
thearch.ptrsize = thelinkarch->ptrsize;
thearch.intsize = thelinkarch->ptrsize;
thearch.regsize = thelinkarch->regsize;
thearch.funcalign = FuncAlign;
thearch.maxalign = MaxAlign;
thearch.minlc = MINLC;
thearch.dwarfregsp = DWARFREGSP;
thearch.adddynlib = adddynlib;
thearch.adddynrel = adddynrel;
thearch.adddynsym = adddynsym;
thearch.archinit = archinit;
thearch.archreloc = archreloc;
thearch.archrelocvariant = archrelocvariant;
thearch.asmb = asmb;
thearch.elfreloc1 = elfreloc1;
thearch.elfsetupplt = elfsetupplt;
thearch.gentext = gentext;
thearch.machoreloc1 = machoreloc1;
thearch.lput = lputl;
thearch.wput = wputl;
thearch.vput = vputl;
thearch.linuxdynld = "/lib/ld-linux.so.2";
thearch.freebsddynld = "/usr/libexec/ld-elf.so.1";
thearch.openbsddynld = "/usr/libexec/ld.so";
thearch.netbsddynld = "/usr/libexec/ld.elf_so";
thearch.dragonflydynld = "/usr/libexec/ld-elf.so.2";
thearch.solarisdynld = "/lib/ld.so.1";
}
void
archinit(void)
{
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash.
if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0)
linkmode = LinkInternal;
switch(HEADTYPE) {
default:
if(linkmode == LinkAuto)
linkmode = LinkInternal;
if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0)
sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
break;
case Hdarwin:
case Hdragonfly:
case Hfreebsd:
case Hlinux:
case Hnetbsd:
case Hopenbsd:
break;
}
switch(HEADTYPE) {
default:
diag("unknown -H option");
errorexit();
case Hplan9: /* plan 9 */
HEADR = 32L;
if(INITTEXT == -1)
INITTEXT = 4096+32;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hdarwin: /* apple MACH */
machoinit();
HEADR = INITIAL_MACHO_HEADR;
if(INITTEXT == -1)
INITTEXT = 4096+HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hlinux: /* elf32 executable */
case Hfreebsd:
case Hnetbsd:
case Hopenbsd:
case Hdragonfly:
elfinit();
HEADR = ELFRESERVE;
if(INITTEXT == -1)
INITTEXT = 0x08048000+HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hnacl:
elfinit();
HEADR = 0x10000;
funcalign = 32;
if(INITTEXT == -1)
INITTEXT = 0x20000;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 0x10000;
break;
case Hwindows: /* PE executable */
peinit();
HEADR = PEFILEHEADR;
if(INITTEXT == -1)
INITTEXT = PEBASE+PESECTHEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = PESECTALIGN;
break;
}
if(INITDAT != 0 && INITRND != 0)
print("warning: -D0x%llux is ignored because of -R0x%ux\n",
INITDAT, INITRND);
}
# 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.
include ../../Make.dist
This diff is collapsed.
// Copyright 2009 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.
// +build ignore
/*
9l is the linker for 64-bit PowerPC and Power Architecture processors.
The $GOARCH for these tools is ppc64 (big endian) or
ppc64le (little endian).
The flags are documented in ../ld/doc.go.
*/
package main
// cmd/9l/l.h from Vita Nuova.
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2008 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2008 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <link.h>
#ifndef EXTERN
#define EXTERN extern
#endif
enum
{
thechar = '9',
PtrSize = 8,
IntSize = 8,
RegSize = 8,
MaxAlign = 32, // max data alignment
FuncAlign = 8,
MINLC = 4,
};
void adddynlib(char *lib);
void adddynrel(LSym *s, Reloc *r);
void adddynrela(LSym *rela, LSym *s, Reloc *r);
void adddynsym(Link *ctxt, LSym *s);
int archreloc(Reloc *r, LSym *s, vlong *val);
vlong archrelocvariant(Reloc *r, LSym *s, vlong t);
void asmb(void);
int elfreloc1(Reloc *r, vlong sectoff);
void elfsetupplt(void);
int machoreloc1(Reloc *r, vlong sectoff);
/* Used by ../ld/dwarf.c */
enum
{
DWARFREGSP = 1
};
// Inferno utils/5l/obj.c
// http://code.google.com/p/inferno-os/source/browse/utils/5l/obj.c
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// Reading object files.
#include "l.h"
#include "../ld/lib.h"
#include "../ld/elf.h"
#include "../ld/dwarf.h"
#include <ar.h>
void
main(int argc, char **argv)
{
linkarchinit();
ldmain(argc, argv);
}
void
linkarchinit(void)
{
thestring = getgoarch();
if(strcmp(thestring, "ppc64le") == 0)
thelinkarch = &linkppc64le;
else
thelinkarch = &linkppc64;
thearch.thechar = thechar;
thearch.ptrsize = thelinkarch->ptrsize;
thearch.intsize = thelinkarch->ptrsize;
thearch.regsize = thelinkarch->regsize;
thearch.funcalign = FuncAlign;
thearch.maxalign = MaxAlign;
thearch.minlc = MINLC;
thearch.dwarfregsp = DWARFREGSP;
thearch.adddynlib = adddynlib;
thearch.adddynrel = adddynrel;
thearch.adddynsym = adddynsym;
thearch.archinit = archinit;
thearch.archreloc = archreloc;
thearch.archrelocvariant = archrelocvariant;
thearch.asmb = asmb;
thearch.elfreloc1 = elfreloc1;
thearch.elfsetupplt = elfsetupplt;
thearch.gentext = gentext;
thearch.machoreloc1 = machoreloc1;
if(thelinkarch == &linkppc64le) {
thearch.lput = lputl;
thearch.wput = wputl;
thearch.vput = vputl;
} else {
thearch.lput = lputb;
thearch.wput = wputb;
thearch.vput = vputb;
}
// TODO(austin): ABI v1 uses /usr/lib/ld.so.1
thearch.linuxdynld = "/lib64/ld64.so.1";
thearch.freebsddynld = "XXX";
thearch.openbsddynld = "XXX";
thearch.netbsddynld = "XXX";
thearch.dragonflydynld = "XXX";
thearch.solarisdynld = "XXX";
}
void
archinit(void)
{
// getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
// Go was built; see ../../make.bash.
if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0)
linkmode = LinkInternal;
switch(HEADTYPE) {
default:
if(linkmode == LinkAuto)
linkmode = LinkInternal;
if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0)
sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
break;
}
switch(HEADTYPE) {
default:
diag("unknown -H option");
errorexit();
case Hplan9: /* plan 9 */
HEADR = 32L;
if(INITTEXT == -1)
INITTEXT = 4128;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hlinux: /* ppc64 elf */
if(strcmp(thestring, "ppc64") == 0)
debug['d'] = 1; // TODO(austin): ELF ABI v1 not supported yet
elfinit();
HEADR = ELFRESERVE;
if(INITTEXT == -1)
INITTEXT = 0x10000 + HEADR;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 0x10000;
break;
case Hnacl:
elfinit();
HEADR = 0x10000;
funcalign = 16;
if(INITTEXT == -1)
INITTEXT = 0x20000;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 0x10000;
break;
}
if(INITDAT != 0 && INITRND != 0)
print("warning: -D0x%ux is ignored because of -R0x%ux\n",
INITDAT, INITRND);
}
......@@ -135,7 +135,7 @@ func xinit() {
}
go386 = b
p := pathf("%s/include/u.h", goroot)
p := pathf("%s/src/all.bash", goroot)
if !isfile(p) {
fatal("$GOROOT is not set correctly or not exported\n"+
"\tGOROOT=%s\n"+
......@@ -507,50 +507,9 @@ var deptab = []struct {
prefix string // prefix of target
dep []string // dependency tweaks for targets with that prefix
}{
{"lib9", []string{
"$GOROOT/include/u.h",
"$GOROOT/include/utf.h",
"$GOROOT/include/fmt.h",
"$GOROOT/include/libc.h",
"fmt/*",
"utf/*",
}},
{"libbio", []string{
"$GOROOT/include/u.h",
"$GOROOT/include/utf.h",
"$GOROOT/include/fmt.h",
"$GOROOT/include/libc.h",
"$GOROOT/include/bio.h",
}},
{"liblink", []string{
"$GOROOT/include/u.h",
"$GOROOT/include/utf.h",
"$GOROOT/include/fmt.h",
"$GOROOT/include/libc.h",
"$GOROOT/include/bio.h",
"$GOROOT/include/ar.h",
"$GOROOT/include/link.h",
}},
{"cmd/5l", []string{
"$GOROOT/pkg/obj/${GOHOSTOS}_$GOHOSTARCH/libld.a",
}},
{"cmd/6l", []string{
"$GOROOT/pkg/obj/${GOHOSTOS}_$GOHOSTARCH/libld.a",
}},
{"cmd/8l", []string{
"$GOROOT/pkg/obj/${GOHOSTOS}_$GOHOSTARCH/libld.a",
}},
{"cmd/9l", []string{
"$GOROOT/pkg/obj/${GOHOSTOS}_$GOHOSTARCH/libld.a",
}},
{"cmd/go", []string{
"zdefaultcc.go",
}},
{"cmd/", []string{
"$GOROOT/pkg/obj/${GOHOSTOS}_$GOHOSTARCH/liblink.a",
"$GOROOT/pkg/obj/${GOHOSTOS}_$GOHOSTARCH/libbio.a",
"$GOROOT/pkg/obj/${GOHOSTOS}_$GOHOSTARCH/lib9.a",
}},
{"runtime", []string{
"zversion.go",
}},
......@@ -635,11 +594,6 @@ func install(dir string) {
case "lib9", "libbio", "liblink", "cmd/gc", "cmd/ld":
islib = true
isgo = false
case "cmd/5l",
"cmd/6l",
"cmd/8l",
"cmd/9l":
isgo = false
}
// Start final link command line.
......@@ -800,7 +754,7 @@ func install(dir string) {
if dir == "runtime" {
// For use by assembly and C files.
copyfile(pathf("%s/pkg/%s_%s/textflag.h", goroot, goos, goarch),
pathf("%s/src/cmd/ld/textflag.h", goroot), 0)
pathf("%s/src/runtime/textflag.h", goroot), 0)
copyfile(pathf("%s/pkg/%s_%s/funcdata.h", goroot, goos, goarch),
pathf("%s/src/runtime/funcdata.h", goroot), 0)
}
......@@ -1109,13 +1063,6 @@ func dopack(dst, src string, extra []string) {
// The Go packages and commands must be in dependency order,
// maintained by hand, but the order doesn't change often.
var buildorder = []string{
// Legacy C programs.
"lib9",
"libbio",
"liblink",
"cmd/ld", // must be before l
"cmd/%sl", // must be before a, g
// Go libraries and programs for bootstrap.
"runtime",
"errors",
......
......@@ -25,12 +25,16 @@ import (
var bootstrapDirs = []string{
"5a",
"5g",
"5l",
"6a",
"6g",
"6l",
"8a",
"8g",
"8l",
"9a",
"9g",
"9l",
"asm",
"asm/internal/arch",
"asm/internal/asm",
......@@ -44,10 +48,6 @@ var bootstrapDirs = []string{
"internal/obj/i386",
"internal/obj/ppc64",
"internal/obj/x86",
"new5l",
"new6l",
"new8l",
"new9l",
}
func bootstrapBuildTools() {
......
......@@ -1892,7 +1892,7 @@ func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action,
}
}
ldflags = append(ldflags, buildLdflags...)
return b.run(".", p.ImportPath, nil, buildToolExec, tool("new"+archChar+"l"), "-o", out, importArgs, ldflags, mainpkg)
return b.run(".", p.ImportPath, nil, buildToolExec, tool(archChar+"l"), "-o", out, importArgs, ldflags, mainpkg)
}
func (gcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error {
......
......@@ -393,12 +393,16 @@ const (
var goTools = map[string]targetDir{
"cmd/5a": toTool,
"cmd/5g": toTool,
"cmd/5l": toTool,
"cmd/6a": toTool,
"cmd/6g": toTool,
"cmd/6l": toTool,
"cmd/8a": toTool,
"cmd/8g": toTool,
"cmd/8l": toTool,
"cmd/9a": toTool,
"cmd/9g": toTool,
"cmd/9l": toTool,
"cmd/addr2line": toTool,
"cmd/api": toTool,
"cmd/asm": toTool,
......@@ -406,10 +410,6 @@ var goTools = map[string]targetDir{
"cmd/dist": toTool,
"cmd/fix": toTool,
"cmd/link": toTool,
"cmd/new5l": toTool,
"cmd/new6l": toTool,
"cmd/new8l": toTool,
"cmd/new9l": toTool,
"cmd/nm": toTool,
"cmd/objdump": toTool,
"cmd/pack": toTool,
......
# 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.
include ../../Make.dist
This diff is collapsed.
// 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.
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <link.h>
#include "lib.h"
#include "../../runtime/typekind.h"
// Decoding the type.* symbols. This has to be in sync with
// ../../runtime/type.go, or more specifically, with what
// ../gc/reflect.c stuffs in these.
static Reloc*
decode_reloc(LSym *s, int32 off)
{
int i;
for (i = 0; i < s->nr; i++)
if (s->r[i].off == off)
return s->r + i;
return nil;
}
static LSym*
decode_reloc_sym(LSym *s, int32 off)
{
Reloc *r;
r = decode_reloc(s,off);
if (r == nil)
return nil;
return r->sym;
}
static uvlong
decode_inuxi(uchar* p, int sz)
{
uint64 v;
uint32 l;
uchar *cast, *inuxi;
int i;
v = l = 0;
cast = nil;
inuxi = nil;
switch (sz) {
case 2:
cast = (uchar*)&l;
inuxi = inuxi2;
break;
case 4:
cast = (uchar*)&l;
inuxi = inuxi4;
break;
case 8:
cast = (uchar*)&v;
inuxi = inuxi8;
break;
default:
diag("dwarf: decode inuxi %d", sz);
errorexit();
}
for (i = 0; i < sz; i++)
cast[inuxi[i]] = p[i];
if (sz == 8)
return v;
return l;
}
static int
commonsize(void)
{
return 8*thearch.ptrsize + 8;
}
// Type.commonType.kind
uint8
decodetype_kind(LSym *s)
{
return s->p[1*thearch.ptrsize + 7] & KindMask; // 0x13 / 0x1f
}
// Type.commonType.kind
uint8
decodetype_noptr(LSym *s)
{
return s->p[1*thearch.ptrsize + 7] & KindNoPointers; // 0x13 / 0x1f
}
// Type.commonType.kind
uint8
decodetype_usegcprog(LSym *s)
{
return s->p[1*thearch.ptrsize + 7] & KindGCProg; // 0x13 / 0x1f
}
// Type.commonType.size
vlong
decodetype_size(LSym *s)
{
return decode_inuxi(s->p, thearch.ptrsize); // 0x8 / 0x10
}
// Type.commonType.gc
LSym*
decodetype_gcprog(LSym *s)
{
return decode_reloc_sym(s, 1*thearch.ptrsize + 8 + 2*thearch.ptrsize);
}
uint8*
decodetype_gcmask(LSym *s)
{
LSym *mask;
mask = decode_reloc_sym(s, 1*thearch.ptrsize + 8 + 1*thearch.ptrsize);
return mask->p;
}
// Type.ArrayType.elem and Type.SliceType.Elem
LSym*
decodetype_arrayelem(LSym *s)
{
return decode_reloc_sym(s, commonsize()); // 0x1c / 0x30
}
vlong
decodetype_arraylen(LSym *s)
{
return decode_inuxi(s->p + commonsize()+2*thearch.ptrsize, thearch.ptrsize);
}
// Type.PtrType.elem
LSym*
decodetype_ptrelem(LSym *s)
{
return decode_reloc_sym(s, commonsize()); // 0x1c / 0x30
}
// Type.MapType.key, elem
LSym*
decodetype_mapkey(LSym *s)
{
return decode_reloc_sym(s, commonsize()); // 0x1c / 0x30
}
LSym*
decodetype_mapvalue(LSym *s)
{
return decode_reloc_sym(s, commonsize()+thearch.ptrsize); // 0x20 / 0x38
}
// Type.ChanType.elem
LSym*
decodetype_chanelem(LSym *s)
{
return decode_reloc_sym(s, commonsize()); // 0x1c / 0x30
}
// Type.FuncType.dotdotdot
int
decodetype_funcdotdotdot(LSym *s)
{
return s->p[commonsize()];
}
// Type.FuncType.in.length
int
decodetype_funcincount(LSym *s)
{
return decode_inuxi(s->p + commonsize()+2*thearch.ptrsize, thearch.intsize);
}
int
decodetype_funcoutcount(LSym *s)
{
return decode_inuxi(s->p + commonsize()+3*thearch.ptrsize + 2*thearch.intsize, thearch.intsize);
}
LSym*
decodetype_funcintype(LSym *s, int i)
{
Reloc *r;
r = decode_reloc(s, commonsize() + thearch.ptrsize);
if (r == nil)
return nil;
return decode_reloc_sym(r->sym, r->add + i * thearch.ptrsize);
}
LSym*
decodetype_funcouttype(LSym *s, int i)
{
Reloc *r;
r = decode_reloc(s, commonsize() + 2*thearch.ptrsize + 2*thearch.intsize);
if (r == nil)
return nil;
return decode_reloc_sym(r->sym, r->add + i * thearch.ptrsize);
}
// Type.StructType.fields.Slice::length
int
decodetype_structfieldcount(LSym *s)
{
return decode_inuxi(s->p + commonsize() + thearch.ptrsize, thearch.intsize);
}
static int
structfieldsize(void)
{
return 5*thearch.ptrsize;
}
// Type.StructType.fields[]-> name, typ and offset.
char*
decodetype_structfieldname(LSym *s, int i)
{
Reloc *r;
// go.string."foo" 0x28 / 0x40
s = decode_reloc_sym(s, commonsize() + thearch.ptrsize + 2*thearch.intsize + i*structfieldsize());
if (s == nil) // embedded structs have a nil name.
return nil;
r = decode_reloc(s, 0); // s has a pointer to the string data at offset 0
if (r == nil) // shouldn't happen.
return nil;
return (char*) r->sym->p + r->add; // the c-string
}
LSym*
decodetype_structfieldtype(LSym *s, int i)
{
return decode_reloc_sym(s, commonsize() + thearch.ptrsize + 2*thearch.intsize + i*structfieldsize() + 2*thearch.ptrsize);
}
vlong
decodetype_structfieldoffs(LSym *s, int i)
{
return decode_inuxi(s->p + commonsize() + thearch.ptrsize + 2*thearch.intsize + i*structfieldsize() + 4*thearch.ptrsize, thearch.intsize);
}
// InterfaceTYpe.methods.length
vlong
decodetype_ifacemethodcount(LSym *s)
{
return decode_inuxi(s->p + commonsize() + thearch.ptrsize, thearch.intsize);
}
// Copyright 2009 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.
// +build ignore
/*
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/8l
It reads object files (.5, .6, .8, .9 files) and writes a binary named for the
architecture (5.out, 6.out, 8.out, 9.out) by default (if $GOOS is windows, a .exe suffix
will be appended).
Major changes include:
- support for ELF, Mach-O and PE 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.
Usage:
go tool 6l [flags] mainObj
Substitute 6l with 5l, 8l or 9l as appropriate.
Options new in this version:
-d
Elide the dynamic linking header. With this option, the binary
is statically linked and does not refer to a dynamic linker. Without this option
(the default), the binary's contents are identical but it is loaded with a dynamic
linker. This flag cannot be used when $GOOS is windows.
-H darwin (only in 6l/8l)
Write Apple Mach-O binaries (default when $GOOS is darwin)
-H dragonfly (only in 6l/8l)
Write DragonFly ELF binaries (default when $GOOS is dragonfly)
-H linux
Write Linux ELF binaries (default when $GOOS is linux)
-H freebsd
Write FreeBSD ELF binaries (default when $GOOS is freebsd)
-H netbsd
Write NetBSD ELF binaries (default when $GOOS is netbsd)
-H openbsd (only in 6l/8l)
Write OpenBSD ELF binaries (default when $GOOS is openbsd)
-H solaris (only in 6l)
Write Solaris ELF binaries (default when $GOOS is solaris)
-H windows (only in 6l/8l)
Write Windows PE32+ Console binaries (default when $GOOS is windows)
-H windowsgui (only in 6l/8l)
Write Windows PE32+ GUI binaries
-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_$GOARCH.
-r dir1:dir2:...
Set the dynamic linker search path when using ELF.
-s
Omit the symbol table and debug information.
-V
Print the linker version.
-w
Omit the DWARF symbol table.
-X symbol value
Set the value of a string variable. The symbol name
should be of the form importpath.name, as displayed
in the symbol table printed by "go tool nm".
-race
Link with race detection libraries.
-B value
Add a NT_GNU_BUILD_ID note when using ELF. The value
should start with 0x and be an even number of hex digits.
-Z
Zero stack on function entry. This is expensive but it might
be useful in cases where you are suffering from false positives
during garbage collection and are willing to trade the CPU time
for getting rid of the false positives.
NOTE: it only eliminates false positives caused by other function
calls, not false positives caused by dead temporaries stored in
the current function call.
-linkmode argument
Set the linkmode. The argument must be one of
internal, external, or auto. The default is auto.
This sets the linking mode as described in
../cgo/doc.go.
-tmpdir dir
Set the location to use for any temporary files. The
default is a newly created directory that is removed
after the linker completes. Temporary files are only
used in external linking mode.
-extld name
Set the name of the external linker to use in external
linking mode. The default is "gcc".
-extldflags flags
Set space-separated trailing flags to pass to the
external linker in external linking mode. The default
is to not pass any additional trailing flags.
*/
package main
This diff is collapsed.
// Copyright 2010 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.
/*
* Emit debug_abbrevs, debug_info and debug_line sections to current
* offset in cout.
*/
void dwarfemitdebugsections(void);
/*
* Add the dwarf section names to the ELF
* s[ection]h[eader]str[ing]tab. Prerequisite for
* dwarfaddelfheaders().
*/
void dwarfaddshstrings(LSym *shstrtab);
/*
* Add section headers pointing to the sections emitted in
* dwarfemitdebugsections.
*/
void dwarfaddelfheaders(void);
void dwarfaddmachoheaders(void);
void dwarfaddpeheaders(void);
void dwarfaddelfsectionsyms(void);
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Derived from Inferno utils/6l/l.h
// http://code.google.com/p/inferno-os/source/browse/utils/6l/l.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef EXTERN
#define EXTERN extern
#endif
typedef struct Arch Arch;
struct Arch {
int thechar;
int ptrsize;
int intsize;
int regsize;
int funcalign;
int maxalign;
int minlc;
int dwarfregsp;
char *linuxdynld;
char *freebsddynld;
char *netbsddynld;
char *openbsddynld;
char *dragonflydynld;
char *solarisdynld;
void (*adddynlib)(char*);
void (*adddynrel)(LSym*, Reloc*);
void (*adddynsym)(Link*, LSym*);
void (*archinit)(void);
int (*archreloc)(Reloc*, LSym*, vlong*);
vlong (*archrelocvariant)(Reloc*, LSym*, vlong);
void (*asmb)(void);
int (*elfreloc1)(Reloc*, vlong);
void (*elfsetupplt)(void);
void (*gentext)(void);
int (*machoreloc1)(Reloc*, vlong);
void (*lput)(uint32);
void (*wput)(uint16);
void (*vput)(uint64);
};
vlong rnd(vlong, vlong);
EXTERN Arch thearch;
EXTERN LSym* datap;
EXTERN int debug[128];
EXTERN char literal[32];
EXTERN int32 lcsize;
EXTERN char* rpath;
EXTERN int32 spsize;
EXTERN LSym* symlist;
EXTERN int32 symsize;
// Terrible but standard terminology.
// A segment describes a block of file to load into memory.
// A section further describes the pieces of that block for
// use in debuggers and such.
enum {
MAXIO = 8192,
MINFUNC = 16, // minimum size for a function
};
typedef struct Segment Segment;
typedef struct Section Section;
struct Segment
{
uchar rwx; // permission as usual unix bits (5 = r-x etc)
uvlong vaddr; // virtual address
uvlong length; // length in memory
uvlong fileoff; // file offset
uvlong filelen; // length on disk
Section* sect;
};
struct Section
{
uchar rwx;
int16 extnum;
int32 align;
char *name;
uvlong vaddr;
uvlong length;
Section *next; // in segment list
Segment *seg;
void *elfsect;
uvlong reloff;
uvlong rellen;
};
extern char symname[];
EXTERN char* INITENTRY;
EXTERN char* thestring;
EXTERN LinkArch* thelinkarch;
EXTERN char* outfile;
EXTERN int ndynexp;
EXTERN LSym** dynexp;
EXTERN int nldflag;
EXTERN char** ldflag;
EXTERN int havedynamic;
EXTERN int funcalign;
EXTERN int iscgo;
EXTERN int elfglobalsymndx;
extern int nelfsym;
EXTERN char* flag_installsuffix;
EXTERN int flag_race;
EXTERN int flag_shared;
EXTERN char* tracksym;
EXTERN char* interpreter;
EXTERN char* tmpdir;
EXTERN char* extld;
EXTERN char* extldflags;
EXTERN int debug_s; // backup old value of debug['s']
EXTERN Link* ctxt;
EXTERN int32 HEADR;
EXTERN int32 HEADTYPE;
EXTERN int32 INITRND;
EXTERN int64 INITTEXT;
EXTERN int64 INITDAT;
EXTERN char* INITENTRY; /* entry point */
EXTERN char* noname;
EXTERN char* paramspace;
EXTERN int nerrors;
EXTERN int linkmode;
EXTERN int64 liveness;
// for dynexport field of LSym
enum
{
CgoExportDynamic = 1<<0,
CgoExportStatic = 1<<1,
};
EXTERN Segment segtext;
EXTERN Segment segrodata;
EXTERN Segment segdata;
EXTERN Segment segdwarf;
typedef struct Endian Endian;
struct Endian
{
uint16 (*e16)(uchar*);
uint32 (*e32)(uchar*);
uint64 (*e64)(uchar*);
};
extern Endian be, le;
/* set by call to mywhatsys() */
extern char* goroot;
extern char* goarch;
extern char* goos;
/* whence for ldpkg */
enum {
FileObj = 0,
ArchiveObj,
Pkgdef
};
EXTERN char* headstring;
#pragma varargck type "Y" LSym*
#pragma varargck type "Z" char*
#pragma varargck type "i" char*
// buffered output
EXTERN Biobuf bso;
EXTERN Biobuf coutbuf;
void cput(uint8);
void Lflag(char *arg);
int Yconv(Fmt *fp);
int Zconv(Fmt *fp);
void addexport(void);
void address(void);
Section*addsection(Segment *seg, char *name, int rwx);
void addstrdata(char *name, char *value);
vlong addstring(LSym *s, char *str);
void asmelfsym(void);
void asmplan9sym(void);
uint16 be16(uchar *b);
uint32 be32(uchar *b);
uint64 be64(uchar *b);
void callgraph(void);
void checkgo(void);
void cflush(void);
void codeblk(int64 addr, int64 size);
vlong cpos(void);
void cseek(vlong p);
void cwrite(void *buf, int n);
void datblk(int64 addr, int64 size);
int datcmp(LSym *s1, LSym *s2);
vlong datoff(vlong addr);
void deadcode(void);
LSym* decodetype_arrayelem(LSym *s);
vlong decodetype_arraylen(LSym *s);
LSym* decodetype_chanelem(LSym *s);
int decodetype_funcdotdotdot(LSym *s);
int decodetype_funcincount(LSym *s);
LSym* decodetype_funcintype(LSym *s, int i);
int decodetype_funcoutcount(LSym *s);
LSym* decodetype_funcouttype(LSym *s, int i);
LSym* decodetype_gcprog(LSym *s);
uint8* decodetype_gcmask(LSym *s);
vlong decodetype_ifacemethodcount(LSym *s);
uint8 decodetype_kind(LSym *s);
uint8 decodetype_noptr(LSym *s);
uint8 decodetype_usegcprog(LSym *s);
LSym* decodetype_mapkey(LSym *s);
LSym* decodetype_mapvalue(LSym *s);
LSym* decodetype_ptrelem(LSym *s);
vlong decodetype_size(LSym *s);
int decodetype_structfieldcount(LSym *s);
char* decodetype_structfieldname(LSym *s, int i);
vlong decodetype_structfieldoffs(LSym *s, int i);
LSym* decodetype_structfieldtype(LSym *s, int i);
void dodata(void);
void dostkcheck(void);
void dostkoff(void);
void dosymtype(void);
void doversion(void);
void doweak(void);
void dynreloc(void);
void dynrelocsym(LSym *s);
vlong entryvalue(void);
void errorexit(void);
void follow(void);
void genasmsym(void (*put)(LSym*, char*, int, vlong, vlong, int, LSym*));
void gentext(void);
void growdatsize(vlong *datsizep, LSym *s);
char* headstr(int v);
int headtype(char *name);
void hostlink(void);
void hostobjs(void);
int iconv(Fmt *fp);
void importcycles(void);
void linkarchinit(void);
void ldelf(Biobuf *f, char *pkg, int64 length, char *pn);
void ldhostobj(void (*ld)(Biobuf*, char*, int64, char*), Biobuf *f, char *pkg, int64 length, char *pn, char *file);
void ldmacho(Biobuf *f, char *pkg, int64 length, char *pn);
void ldobj(Biobuf *f, char *pkg, int64 length, char *pn, char *file, int whence);
void ldpe(Biobuf *f, char *pkg, int64 length, char *pn);
void ldpkg(Biobuf *f, char *pkg, int64 length, char *filename, int whence);
uint16 le16(uchar *b);
uint32 le32(uchar *b);
uint64 le64(uchar *b);
void libinit(void);
LSym* listsort(LSym *l, int (*cmp)(LSym*, LSym*), LSym** (*nextp)(LSym*));
LSym** listnextp(LSym*);
LSym** listsubp(LSym*);
void loadinternal(char *name);
void loadlib(void);
void lputb(uint32 l);
void lputl(uint32 l);
void* mal(uint32 n);
void mark(LSym *s);
void mywhatsys(void);
void objfile(char *file, char *pkg);
void patch(void);
int pathchar(void);
void pcln(void);
void pclntab(void);
void findfunctab(void);
void putelfsectionsym(LSym* s, int shndx);
void putelfsymshndx(vlong sympos, int shndx);
void putsymb(LSym *s, char *name, int t, vlong v, vlong size, int ver, LSym *typ);
int rbyoff(const void *va, const void *vb);
void reloc(void);
void relocsym(LSym *s);
void setheadtype(char *s);
void setinterp(char *s);
void setlinkmode(char *arg);
void span(void);
void strnput(char *s, int n);
vlong symaddr(LSym *s);
void symtab(void);
void textaddress(void);
void undef(void);
void unmal(void *v, uint32 n);
void usage(void);
void vputb(uint64 v);
int valuecmp(LSym *a, LSym *b);
void vputl(uint64 v);
void wputb(ushort w);
void wputl(ushort w);
void xdefine(char *p, int t, vlong v);
void zerosig(char *sp);
void archinit(void);
void diag(char *fmt, ...);
void ldmain(int, char**);
#pragma varargck argpos diag 1
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -21,16 +21,3 @@
#define WRAPPER 32
// This function uses its incoming context register.
#define NEEDCTXT 64
/*c2go
enum
{
NOPROF = 1,
DUPOK = 2,
NOSPLIT = 4,
RODATA = 8,
NOPTR = 16,
WRAPPER = 32,
NEEDCTXT = 64,
};
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment