Commit c776592a authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/internal/ld: prefer constants from cmd/internal/obj

The majority of this CL was prepared via scripted invocations of
`gofmt -w -r "$SYM -> obj.$SYM" cmd/internal/ld/*.go` and `gofmt -w -r
"ld.$SYM -> obj.$SYM" cmd/?l/*.go`.

Because of issue #7417, that was followed by repeatedly running an AWK
script to identify lines that differed other than whitespace changes
or "ld." or "obj." prefixes and manually restoring comments.

Finally, the redundant constants from cmd/internal/ld/link.go were
removed, and "goimports -w" was used to cleanup import lines.

Passes rsc.io/toolstash/buildall, even when modified to also build cmd.

Fixes #10055.

Change-Id: Icd5dbe819a3b6520ce883748e60017dc8e9a2e85
Reviewed-on: https://go-review.googlesource.com/9112Reviewed-by: default avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 6e221a90
This diff is collapsed.
...@@ -96,10 +96,10 @@ func archinit() { ...@@ -96,10 +96,10 @@ func archinit() {
log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE))) log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE)))
} }
case ld.Hlinux, case obj.Hlinux,
ld.Hfreebsd, obj.Hfreebsd,
ld.Hnacl, obj.Hnacl,
ld.Hdarwin: obj.Hdarwin:
break break
} }
...@@ -107,7 +107,7 @@ func archinit() { ...@@ -107,7 +107,7 @@ func archinit() {
default: default:
ld.Exitf("unknown -H option: %v", ld.HEADTYPE) ld.Exitf("unknown -H option: %v", ld.HEADTYPE)
case ld.Hplan9: /* plan 9 */ case obj.Hplan9: /* plan 9 */
ld.HEADR = 32 ld.HEADR = 32
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -120,10 +120,10 @@ func archinit() { ...@@ -120,10 +120,10 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hlinux, /* arm elf */ case obj.Hlinux, /* arm elf */
ld.Hfreebsd, obj.Hfreebsd,
ld.Hnetbsd, obj.Hnetbsd,
ld.Hopenbsd: obj.Hopenbsd:
ld.Debug['d'] = 0 ld.Debug['d'] = 0
// with dynamic linking // with dynamic linking
ld.Elfinit() ld.Elfinit()
...@@ -138,7 +138,7 @@ func archinit() { ...@@ -138,7 +138,7 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hnacl: case obj.Hnacl:
ld.Elfinit() ld.Elfinit()
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 16 ld.Funcalign = 16
...@@ -152,7 +152,7 @@ func archinit() { ...@@ -152,7 +152,7 @@ func archinit() {
ld.INITRND = 0x10000 ld.INITRND = 0x10000
} }
case ld.Hdarwin: /* apple MACH */ case obj.Hdarwin: /* apple MACH */
ld.Debug['w'] = 1 // disable DWARF generataion ld.Debug['w'] = 1 // disable DWARF generataion
ld.Machoinit() ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR ld.HEADR = ld.INITIAL_MACHO_HEADR
...@@ -174,6 +174,6 @@ func archinit() { ...@@ -174,6 +174,6 @@ func archinit() {
// embed goarm to runtime.goarm // embed goarm to runtime.goarm
s := ld.Linklookup(ld.Ctxt, "runtime.goarm", 0) s := ld.Linklookup(ld.Ctxt, "runtime.goarm", 0)
s.Type = ld.SRODATA s.Type = obj.SRODATA
ld.Adduint8(ld.Ctxt, s, uint8(ld.Ctxt.Goarm)) ld.Adduint8(ld.Ctxt, s, uint8(ld.Ctxt.Goarm))
} }
This diff is collapsed.
...@@ -104,15 +104,15 @@ func archinit() { ...@@ -104,15 +104,15 @@ func archinit() {
log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE))) log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE)))
} }
case ld.Hdarwin, case obj.Hdarwin,
ld.Hdragonfly, obj.Hdragonfly,
ld.Hfreebsd, obj.Hfreebsd,
ld.Hlinux, obj.Hlinux,
ld.Hnacl, obj.Hnacl,
ld.Hnetbsd, obj.Hnetbsd,
ld.Hopenbsd, obj.Hopenbsd,
ld.Hsolaris, obj.Hsolaris,
ld.Hwindows: obj.Hwindows:
break break
} }
...@@ -120,7 +120,7 @@ func archinit() { ...@@ -120,7 +120,7 @@ func archinit() {
default: default:
ld.Exitf("unknown -H option: %v", ld.HEADTYPE) ld.Exitf("unknown -H option: %v", ld.HEADTYPE)
case ld.Hplan9: /* plan 9 */ case obj.Hplan9: /* plan 9 */
ld.HEADR = 32 + 8 ld.HEADR = 32 + 8
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -133,7 +133,7 @@ func archinit() { ...@@ -133,7 +133,7 @@ func archinit() {
ld.INITRND = 0x200000 ld.INITRND = 0x200000
} }
case ld.Helf: /* elf32 executable */ case obj.Helf: /* elf32 executable */
ld.HEADR = int32(ld.Rnd(52+3*32, 16)) ld.HEADR = int32(ld.Rnd(52+3*32, 16))
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -146,7 +146,7 @@ func archinit() { ...@@ -146,7 +146,7 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hdarwin: /* apple MACH */ case obj.Hdarwin: /* apple MACH */
ld.Machoinit() ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR ld.HEADR = ld.INITIAL_MACHO_HEADR
...@@ -160,12 +160,12 @@ func archinit() { ...@@ -160,12 +160,12 @@ func archinit() {
ld.INITDAT = 0 ld.INITDAT = 0
} }
case ld.Hlinux, /* elf64 executable */ case obj.Hlinux, /* elf64 executable */
ld.Hfreebsd, /* freebsd */ obj.Hfreebsd, /* freebsd */
ld.Hnetbsd, /* netbsd */ obj.Hnetbsd, /* netbsd */
ld.Hopenbsd, /* openbsd */ obj.Hopenbsd, /* openbsd */
ld.Hdragonfly, /* dragonfly */ obj.Hdragonfly, /* dragonfly */
ld.Hsolaris: /* solaris */ obj.Hsolaris: /* solaris */
ld.Elfinit() ld.Elfinit()
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
...@@ -179,7 +179,7 @@ func archinit() { ...@@ -179,7 +179,7 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hnacl: case obj.Hnacl:
ld.Elfinit() ld.Elfinit()
ld.Debug['w']++ // disable dwarf, which gets confused and is useless anyway ld.Debug['w']++ // disable dwarf, which gets confused and is useless anyway
ld.HEADR = 0x10000 ld.HEADR = 0x10000
...@@ -194,7 +194,7 @@ func archinit() { ...@@ -194,7 +194,7 @@ func archinit() {
ld.INITRND = 0x10000 ld.INITRND = 0x10000
} }
case ld.Hwindows: /* PE executable */ case obj.Hwindows: /* PE executable */
ld.Peinit() ld.Peinit()
ld.HEADR = ld.PEFILEHEADR ld.HEADR = ld.PEFILEHEADR
......
...@@ -74,7 +74,7 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -74,7 +74,7 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int {
default: default:
return -1 return -1
case ld.R_ADDR: case obj.R_ADDR:
switch r.Siz { switch r.Siz {
case 4: case 4:
ld.Thearch.Vput(ld.R_AARCH64_ABS32 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_ABS32 | uint64(elfsym)<<32)
...@@ -84,14 +84,14 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -84,14 +84,14 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int {
return -1 return -1
} }
case ld.R_ADDRARM64: case obj.R_ADDRARM64:
// two relocations: R_AARCH64_ADR_PREL_PG_HI21 and R_AARCH64_ADD_ABS_LO12_NC // two relocations: R_AARCH64_ADR_PREL_PG_HI21 and R_AARCH64_ADD_ABS_LO12_NC
ld.Thearch.Vput(ld.R_AARCH64_ADR_PREL_PG_HI21 | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_ADR_PREL_PG_HI21 | uint64(elfsym)<<32)
ld.Thearch.Vput(uint64(r.Xadd)) ld.Thearch.Vput(uint64(r.Xadd))
ld.Thearch.Vput(uint64(sectoff + 4)) ld.Thearch.Vput(uint64(sectoff + 4))
ld.Thearch.Vput(ld.R_AARCH64_ADD_ABS_LO12_NC | uint64(elfsym)<<32) ld.Thearch.Vput(ld.R_AARCH64_ADD_ABS_LO12_NC | uint64(elfsym)<<32)
case ld.R_CALLARM64: case obj.R_CALLARM64:
if r.Siz != 4 { if r.Siz != 4 {
return -1 return -1
} }
...@@ -116,7 +116,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -116,7 +116,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
// ld64 has a bug handling MACHO_ARM64_RELOC_UNSIGNED with !extern relocation. // ld64 has a bug handling MACHO_ARM64_RELOC_UNSIGNED with !extern relocation.
// see cmd/internal/ld/data.go for details. The workarond is that don't use !extern // see cmd/internal/ld/data.go for details. The workarond is that don't use !extern
// UNSIGNED relocation at all. // UNSIGNED relocation at all.
if rs.Type == ld.SHOSTOBJ || r.Type == ld.R_CALLARM64 || r.Type == ld.R_ADDRARM64 || r.Type == ld.R_ADDR { if rs.Type == obj.SHOSTOBJ || r.Type == obj.R_CALLARM64 || r.Type == obj.R_ADDRARM64 || r.Type == obj.R_ADDR {
if rs.Dynid < 0 { if rs.Dynid < 0 {
ld.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type) ld.Diag("reloc %d to non-macho symbol %s type=%d", r.Type, rs.Name, rs.Type)
return -1 return -1
...@@ -136,10 +136,10 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -136,10 +136,10 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
default: default:
return -1 return -1
case ld.R_ADDR: case obj.R_ADDR:
v |= ld.MACHO_ARM64_RELOC_UNSIGNED << 28 v |= ld.MACHO_ARM64_RELOC_UNSIGNED << 28
case ld.R_CALLARM64: case obj.R_CALLARM64:
if r.Xadd != 0 { if r.Xadd != 0 {
ld.Diag("ld64 doesn't allow BR26 reloc with non-zero addend: %s+%d", rs.Name, r.Xadd) ld.Diag("ld64 doesn't allow BR26 reloc with non-zero addend: %s+%d", rs.Name, r.Xadd)
} }
...@@ -147,7 +147,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int { ...@@ -147,7 +147,7 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
v |= 1 << 24 // pc-relative bit v |= 1 << 24 // pc-relative bit
v |= ld.MACHO_ARM64_RELOC_BRANCH26 << 28 v |= ld.MACHO_ARM64_RELOC_BRANCH26 << 28
case ld.R_ADDRARM64: case obj.R_ADDRARM64:
r.Siz = 4 r.Siz = 4
// Two relocation entries: MACHO_ARM64_RELOC_PAGEOFF12 MACHO_ARM64_RELOC_PAGE21 // Two relocation entries: MACHO_ARM64_RELOC_PAGEOFF12 MACHO_ARM64_RELOC_PAGE21
// if r.Xadd is non-zero, add two MACHO_ARM64_RELOC_ADDEND. // if r.Xadd is non-zero, add two MACHO_ARM64_RELOC_ADDEND.
...@@ -193,7 +193,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -193,7 +193,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
default: default:
return -1 return -1
case ld.R_ADDRARM64: case obj.R_ADDRARM64:
r.Done = 0 r.Done = 0
// set up addend for eventual relocation via outer symbol. // set up addend for eventual relocation via outer symbol.
...@@ -204,7 +204,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -204,7 +204,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
rs = rs.Outer rs = rs.Outer
} }
if rs.Type != ld.SHOSTOBJ && rs.Sect == nil { if rs.Type != obj.SHOSTOBJ && rs.Sect == nil {
ld.Diag("missing section for %s", rs.Name) ld.Diag("missing section for %s", rs.Name)
} }
r.Xsym = rs r.Xsym = rs
...@@ -219,7 +219,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -219,7 +219,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
// the BR26 relocation should be fully resolved at link time. // the BR26 relocation should be fully resolved at link time.
// That is the reason why the next if block is disabled. When the bug in ld64 // That is the reason why the next if block is disabled. When the bug in ld64
// is fixed, we can enable this block and also enable duff's device in cmd/7g. // is fixed, we can enable this block and also enable duff's device in cmd/7g.
if false && ld.HEADTYPE == ld.Hdarwin { if false && ld.HEADTYPE == obj.Hdarwin {
// Mach-O wants the addend to be encoded in the instruction // Mach-O wants the addend to be encoded in the instruction
// Note that although Mach-O supports ARM64_RELOC_ADDEND, it // Note that although Mach-O supports ARM64_RELOC_ADDEND, it
// can only encode 24-bit of signed addend, but the instructions // can only encode 24-bit of signed addend, but the instructions
...@@ -239,7 +239,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -239,7 +239,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
return 0 return 0
case ld.R_CALLARM64: case obj.R_CALLARM64:
r.Done = 0 r.Done = 0
r.Xsym = r.Sym r.Xsym = r.Sym
*val = int64(0xfc000000 & uint32(r.Add)) *val = int64(0xfc000000 & uint32(r.Add))
...@@ -250,15 +250,15 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -250,15 +250,15 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
} }
switch r.Type { switch r.Type {
case ld.R_CONST: case obj.R_CONST:
*val = r.Add *val = r.Add
return 0 return 0
case ld.R_GOTOFF: case obj.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0))
return 0 return 0
case ld.R_ADDRARM64: case obj.R_ADDRARM64:
t := ld.Symaddr(r.Sym) + r.Add - ((s.Value + int64(r.Off)) &^ 0xfff) t := ld.Symaddr(r.Sym) + r.Add - ((s.Value + int64(r.Off)) &^ 0xfff)
if t >= 1<<32 || t < -1<<32 { if t >= 1<<32 || t < -1<<32 {
ld.Diag("program too large, address relocation distance = %d", t) ld.Diag("program too large, address relocation distance = %d", t)
...@@ -280,7 +280,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -280,7 +280,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
} }
return 0 return 0
case ld.R_CALLARM64: case obj.R_CALLARM64:
*val = int64((0xfc000000 & uint32(r.Add)) | uint32((ld.Symaddr(r.Sym)+r.Add*4-(s.Value+int64(r.Off)))/4)) *val = int64((0xfc000000 & uint32(r.Add)) | uint32((ld.Symaddr(r.Sym)+r.Add*4-(s.Value+int64(r.Off)))/4))
return 0 return 0
} }
...@@ -308,7 +308,7 @@ func adddynlib(lib string) { ...@@ -308,7 +308,7 @@ func adddynlib(lib string) {
ld.Addstring(s, "") ld.Addstring(s, "")
} }
ld.Elfwritedynent(ld.Linklookup(ld.Ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(s, lib))) ld.Elfwritedynent(ld.Linklookup(ld.Ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(s, lib)))
} else if ld.HEADTYPE == ld.Hdarwin { } else if ld.HEADTYPE == obj.Hdarwin {
ld.Machoadddynlib(lib) ld.Machoadddynlib(lib)
} else { } else {
ld.Diag("adddynlib: unsupported binary format") ld.Diag("adddynlib: unsupported binary format")
...@@ -352,7 +352,7 @@ func asmb() { ...@@ -352,7 +352,7 @@ func asmb() {
ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen)) ld.Datblk(int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
machlink := uint32(0) machlink := uint32(0)
if ld.HEADTYPE == ld.Hdarwin { if ld.HEADTYPE == obj.Hdarwin {
if ld.Debug['v'] != 0 { if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f dwarf\n", obj.Cputime()) fmt.Fprintf(&ld.Bso, "%5.2f dwarf\n", obj.Cputime())
} }
...@@ -387,10 +387,10 @@ func asmb() { ...@@ -387,10 +387,10 @@ func asmb() {
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND))) symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
} }
case ld.Hplan9: case obj.Hplan9:
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen) symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case ld.Hdarwin: case obj.Hdarwin:
symo = uint32(ld.Rnd(int64(uint64(ld.HEADR)+ld.Segtext.Filelen), int64(ld.INITRND)) + ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND)) + int64(machlink)) symo = uint32(ld.Rnd(int64(uint64(ld.HEADR)+ld.Segtext.Filelen), int64(ld.INITRND)) + ld.Rnd(int64(ld.Segdata.Filelen), int64(ld.INITRND)) + int64(machlink))
} }
...@@ -415,7 +415,7 @@ func asmb() { ...@@ -415,7 +415,7 @@ func asmb() {
} }
} }
case ld.Hplan9: case obj.Hplan9:
ld.Asmplan9sym() ld.Asmplan9sym()
ld.Cflush() ld.Cflush()
...@@ -429,7 +429,7 @@ func asmb() { ...@@ -429,7 +429,7 @@ func asmb() {
ld.Cflush() ld.Cflush()
} }
case ld.Hdarwin: case obj.Hdarwin:
if ld.Linkmode == ld.LinkExternal { if ld.Linkmode == ld.LinkExternal {
ld.Machoemitreloc() ld.Machoemitreloc()
} }
...@@ -444,7 +444,7 @@ func asmb() { ...@@ -444,7 +444,7 @@ func asmb() {
ld.Cseek(0) ld.Cseek(0)
switch ld.HEADTYPE { switch ld.HEADTYPE {
default: default:
case ld.Hplan9: /* plan 9 */ case obj.Hplan9: /* plan 9 */
ld.Thearch.Lput(0x647) /* magic */ ld.Thearch.Lput(0x647) /* magic */
ld.Thearch.Lput(uint32(ld.Segtext.Filelen)) /* sizes */ ld.Thearch.Lput(uint32(ld.Segtext.Filelen)) /* sizes */
ld.Thearch.Lput(uint32(ld.Segdata.Filelen)) ld.Thearch.Lput(uint32(ld.Segdata.Filelen))
...@@ -454,14 +454,14 @@ func asmb() { ...@@ -454,14 +454,14 @@ func asmb() {
ld.Thearch.Lput(0) ld.Thearch.Lput(0)
ld.Thearch.Lput(uint32(ld.Lcsize)) ld.Thearch.Lput(uint32(ld.Lcsize))
case ld.Hlinux, case obj.Hlinux,
ld.Hfreebsd, obj.Hfreebsd,
ld.Hnetbsd, obj.Hnetbsd,
ld.Hopenbsd, obj.Hopenbsd,
ld.Hnacl: obj.Hnacl:
ld.Asmbelf(int64(symo)) ld.Asmbelf(int64(symo))
case ld.Hdarwin: case obj.Hdarwin:
ld.Asmbmacho() ld.Asmbmacho()
} }
......
...@@ -89,7 +89,7 @@ func archinit() { ...@@ -89,7 +89,7 @@ func archinit() {
} }
// Darwin/arm64 only supports external linking // Darwin/arm64 only supports external linking
if ld.HEADTYPE == ld.Hdarwin { if ld.HEADTYPE == obj.Hdarwin {
ld.Linkmode = ld.LinkExternal ld.Linkmode = ld.LinkExternal
} }
...@@ -101,7 +101,7 @@ func archinit() { ...@@ -101,7 +101,7 @@ func archinit() {
if ld.Linkmode == ld.LinkExternal && obj.Getgoextlinkenabled() != "1" { if ld.Linkmode == ld.LinkExternal && obj.Getgoextlinkenabled() != "1" {
log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE))) log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE)))
} }
case ld.Hlinux, ld.Hdarwin: case obj.Hlinux, obj.Hdarwin:
break break
} }
...@@ -109,7 +109,7 @@ func archinit() { ...@@ -109,7 +109,7 @@ func archinit() {
default: default:
ld.Exitf("unknown -H option: %v", ld.HEADTYPE) ld.Exitf("unknown -H option: %v", ld.HEADTYPE)
case ld.Hplan9: /* plan 9 */ case obj.Hplan9: /* plan 9 */
ld.HEADR = 32 ld.HEADR = 32
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -122,7 +122,7 @@ func archinit() { ...@@ -122,7 +122,7 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hlinux: /* arm64 elf */ case obj.Hlinux: /* arm64 elf */
ld.Elfinit() ld.Elfinit()
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -135,7 +135,7 @@ func archinit() { ...@@ -135,7 +135,7 @@ func archinit() {
ld.INITRND = 0x10000 ld.INITRND = 0x10000
} }
case ld.Hdarwin: /* apple MACH */ case obj.Hdarwin: /* apple MACH */
ld.Debug['w'] = 1 // disable DWARF generation ld.Debug['w'] = 1 // disable DWARF generation
ld.Machoinit() ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR ld.HEADR = ld.INITIAL_MACHO_HEADR
...@@ -149,7 +149,7 @@ func archinit() { ...@@ -149,7 +149,7 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hnacl: case obj.Hnacl:
ld.Elfinit() ld.Elfinit()
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 16 ld.Funcalign = 16
......
This diff is collapsed.
...@@ -96,12 +96,12 @@ func archinit() { ...@@ -96,12 +96,12 @@ func archinit() {
log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE))) log.Fatalf("cannot use -linkmode=external with -H %s", ld.Headstr(int(ld.HEADTYPE)))
} }
case ld.Hdarwin, case obj.Hdarwin,
ld.Hfreebsd, obj.Hfreebsd,
ld.Hlinux, obj.Hlinux,
ld.Hnetbsd, obj.Hnetbsd,
ld.Hopenbsd, obj.Hopenbsd,
ld.Hwindows: obj.Hwindows:
break break
} }
...@@ -109,7 +109,7 @@ func archinit() { ...@@ -109,7 +109,7 @@ func archinit() {
default: default:
ld.Exitf("unknown -H option: %v", ld.HEADTYPE) ld.Exitf("unknown -H option: %v", ld.HEADTYPE)
case ld.Hplan9: /* plan 9 */ case obj.Hplan9: /* plan 9 */
ld.HEADR = 32 ld.HEADR = 32
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -122,7 +122,7 @@ func archinit() { ...@@ -122,7 +122,7 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hdarwin: /* apple MACH */ case obj.Hdarwin: /* apple MACH */
ld.Machoinit() ld.Machoinit()
ld.HEADR = ld.INITIAL_MACHO_HEADR ld.HEADR = ld.INITIAL_MACHO_HEADR
...@@ -136,10 +136,10 @@ func archinit() { ...@@ -136,10 +136,10 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hlinux, /* elf32 executable */ case obj.Hlinux, /* elf32 executable */
ld.Hfreebsd, obj.Hfreebsd,
ld.Hnetbsd, obj.Hnetbsd,
ld.Hopenbsd: obj.Hopenbsd:
ld.Elfinit() ld.Elfinit()
ld.HEADR = ld.ELFRESERVE ld.HEADR = ld.ELFRESERVE
...@@ -153,7 +153,7 @@ func archinit() { ...@@ -153,7 +153,7 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hnacl: case obj.Hnacl:
ld.Elfinit() ld.Elfinit()
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 32 ld.Funcalign = 32
...@@ -167,7 +167,7 @@ func archinit() { ...@@ -167,7 +167,7 @@ func archinit() {
ld.INITRND = 0x10000 ld.INITRND = 0x10000
} }
case ld.Hwindows: /* PE executable */ case obj.Hwindows: /* PE executable */
ld.Peinit() ld.Peinit()
ld.HEADR = ld.PEFILEHEADR ld.HEADR = ld.PEFILEHEADR
......
...@@ -118,7 +118,7 @@ func gentext() { ...@@ -118,7 +118,7 @@ func gentext() {
for s = *pprevtextp; s != nil; pprevtextp, s = &s.Next, s.Next { for s = *pprevtextp; s != nil; pprevtextp, s = &s.Next, s.Next {
for i = range s.R { for i = range s.R {
r = &s.R[i] r = &s.R[i]
if r.Type != 256+ld.R_PPC64_REL24 || r.Sym.Type != ld.SDYNIMPORT { if r.Type != 256+ld.R_PPC64_REL24 || r.Sym.Type != obj.SDYNIMPORT {
continue continue
} }
...@@ -168,7 +168,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) { ...@@ -168,7 +168,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) {
plt := ld.Linklookup(ld.Ctxt, ".plt", 0) plt := ld.Linklookup(ld.Ctxt, ".plt", 0)
stub.Type = ld.STEXT stub.Type = obj.STEXT
// Save TOC pointer in TOC save slot // Save TOC pointer in TOC save slot
ld.Adduint32(ld.Ctxt, stub, 0xf8410018) // std r2,24(r1) ld.Adduint32(ld.Ctxt, stub, 0xf8410018) // std r2,24(r1)
...@@ -183,7 +183,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) { ...@@ -183,7 +183,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) {
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
r.Off += int32(r.Siz) r.Off += int32(r.Siz)
} }
r.Type = ld.R_POWER_TOC r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_HA r.Variant = ld.RV_POWER_HA
ld.Adduint32(ld.Ctxt, stub, 0x3d820000) // addis r12,r2,targ@plt@toc@ha ld.Adduint32(ld.Ctxt, stub, 0x3d820000) // addis r12,r2,targ@plt@toc@ha
r = ld.Addrel(stub) r = ld.Addrel(stub)
...@@ -194,7 +194,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) { ...@@ -194,7 +194,7 @@ func gencallstub(abicase int, stub *ld.LSym, targ *ld.LSym) {
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
r.Off += int32(r.Siz) r.Off += int32(r.Siz)
} }
r.Type = ld.R_POWER_TOC r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_LO r.Variant = ld.RV_POWER_LO
ld.Adduint32(ld.Ctxt, stub, 0xe98c0000) // ld r12,targ@plt@toc@l(r12) ld.Adduint32(ld.Ctxt, stub, 0xe98c0000) // ld r12,targ@plt@toc@l(r12)
...@@ -220,7 +220,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) { ...@@ -220,7 +220,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
// Handle relocations found in ELF object files. // Handle relocations found in ELF object files.
case 256 + ld.R_PPC64_REL24: case 256 + ld.R_PPC64_REL24:
r.Type = ld.R_CALLPOWER r.Type = obj.R_CALLPOWER
// This is a local call, so the caller isn't setting // This is a local call, so the caller isn't setting
// up r12 and r2 is the same for the caller and // up r12 and r2 is the same for the caller and
...@@ -229,7 +229,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) { ...@@ -229,7 +229,7 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
// to use r12 to compute r2.) // to use r12 to compute r2.)
r.Add += int64(r.Sym.Localentry) * 4 r.Add += int64(r.Sym.Localentry) * 4
if targ.Type == ld.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
// Should have been handled in elfsetupplt // Should have been handled in elfsetupplt
ld.Diag("unexpected R_PPC64_REL24 for dyn import") ld.Diag("unexpected R_PPC64_REL24 for dyn import")
} }
...@@ -237,8 +237,8 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) { ...@@ -237,8 +237,8 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
return return
case 256 + ld.R_PPC64_ADDR64: case 256 + ld.R_PPC64_ADDR64:
r.Type = ld.R_ADDR r.Type = obj.R_ADDR
if targ.Type == ld.SDYNIMPORT { if targ.Type == obj.SDYNIMPORT {
// These happen in .toc sections // These happen in .toc sections
adddynsym(ld.Ctxt, targ) adddynsym(ld.Ctxt, targ)
...@@ -252,56 +252,56 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) { ...@@ -252,56 +252,56 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
return return
case 256 + ld.R_PPC64_TOC16: case 256 + ld.R_PPC64_TOC16:
r.Type = ld.R_POWER_TOC r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_LO | ld.RV_CHECK_OVERFLOW r.Variant = ld.RV_POWER_LO | ld.RV_CHECK_OVERFLOW
return return
case 256 + ld.R_PPC64_TOC16_LO: case 256 + ld.R_PPC64_TOC16_LO:
r.Type = ld.R_POWER_TOC r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_LO r.Variant = ld.RV_POWER_LO
return return
case 256 + ld.R_PPC64_TOC16_HA: case 256 + ld.R_PPC64_TOC16_HA:
r.Type = ld.R_POWER_TOC r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_HA | ld.RV_CHECK_OVERFLOW r.Variant = ld.RV_POWER_HA | ld.RV_CHECK_OVERFLOW
return return
case 256 + ld.R_PPC64_TOC16_HI: case 256 + ld.R_PPC64_TOC16_HI:
r.Type = ld.R_POWER_TOC r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_HI | ld.RV_CHECK_OVERFLOW r.Variant = ld.RV_POWER_HI | ld.RV_CHECK_OVERFLOW
return return
case 256 + ld.R_PPC64_TOC16_DS: case 256 + ld.R_PPC64_TOC16_DS:
r.Type = ld.R_POWER_TOC r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_DS | ld.RV_CHECK_OVERFLOW r.Variant = ld.RV_POWER_DS | ld.RV_CHECK_OVERFLOW
return return
case 256 + ld.R_PPC64_TOC16_LO_DS: case 256 + ld.R_PPC64_TOC16_LO_DS:
r.Type = ld.R_POWER_TOC r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_DS r.Variant = ld.RV_POWER_DS
return return
case 256 + ld.R_PPC64_REL16_LO: case 256 + ld.R_PPC64_REL16_LO:
r.Type = ld.R_PCREL r.Type = obj.R_PCREL
r.Variant = ld.RV_POWER_LO r.Variant = ld.RV_POWER_LO
r.Add += 2 // Compensate for relocation size of 2 r.Add += 2 // Compensate for relocation size of 2
return return
case 256 + ld.R_PPC64_REL16_HI: case 256 + ld.R_PPC64_REL16_HI:
r.Type = ld.R_PCREL r.Type = obj.R_PCREL
r.Variant = ld.RV_POWER_HI | ld.RV_CHECK_OVERFLOW r.Variant = ld.RV_POWER_HI | ld.RV_CHECK_OVERFLOW
r.Add += 2 r.Add += 2
return return
case 256 + ld.R_PPC64_REL16_HA: case 256 + ld.R_PPC64_REL16_HA:
r.Type = ld.R_PCREL r.Type = obj.R_PCREL
r.Variant = ld.RV_POWER_HA | ld.RV_CHECK_OVERFLOW r.Variant = ld.RV_POWER_HA | ld.RV_CHECK_OVERFLOW
r.Add += 2 r.Add += 2
return return
} }
// Handle references to ELF symbols from our own object files. // Handle references to ELF symbols from our own object files.
if targ.Type != ld.SDYNIMPORT { if targ.Type != obj.SDYNIMPORT {
return return
} }
...@@ -357,15 +357,15 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -357,15 +357,15 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
} }
switch r.Type { switch r.Type {
case ld.R_CONST: case obj.R_CONST:
*val = r.Add *val = r.Add
return 0 return 0
case ld.R_GOTOFF: case obj.R_GOTOFF:
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0))
return 0 return 0
case ld.R_ADDRPOWER: case obj.R_ADDRPOWER:
// r->add is two ppc64 instructions holding an immediate 32-bit constant. // r->add is two ppc64 instructions holding an immediate 32-bit constant.
// We want to add r->sym's address to that constant. // We want to add r->sym's address to that constant.
// The encoding of the immediate x<<16 + y, // The encoding of the immediate x<<16 + y,
...@@ -393,7 +393,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -393,7 +393,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
} }
return 0 return 0
case ld.R_CALLPOWER: case obj.R_CALLPOWER:
// Bits 6 through 29 = (S + A - P) >> 2 // Bits 6 through 29 = (S + A - P) >> 2
var o1 uint32 var o1 uint32
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian { if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
...@@ -415,7 +415,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -415,7 +415,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
*val = int64(o1&0xfc000003 | uint32(t)&^0xfc000003) *val = int64(o1&0xfc000003 | uint32(t)&^0xfc000003)
return 0 return 0
case ld.R_POWER_TOC: // S + A - .TOC. case obj.R_POWER_TOC: // S + A - .TOC.
*val = ld.Symaddr(r.Sym) + r.Add - symtoc(s) *val = ld.Symaddr(r.Sym) + r.Add - symtoc(s)
return 0 return 0
...@@ -539,7 +539,7 @@ func addpltsym(ctxt *ld.Link, s *ld.LSym) { ...@@ -539,7 +539,7 @@ func addpltsym(ctxt *ld.Link, s *ld.LSym) {
r.Sym = glink r.Sym = glink
r.Off = int32(glink.Size) r.Off = int32(glink.Size)
r.Siz = 4 r.Siz = 4
r.Type = ld.R_CALLPOWER r.Type = obj.R_CALLPOWER
ld.Adduint32(ctxt, glink, 0x48000000) // b .glink ld.Adduint32(ctxt, glink, 0x48000000) // b .glink
// In the ppc64 ABI, the dynamic linker is responsible // In the ppc64 ABI, the dynamic linker is responsible
...@@ -594,7 +594,7 @@ func ensureglinkresolver() *ld.LSym { ...@@ -594,7 +594,7 @@ func ensureglinkresolver() *ld.LSym {
r.Off = int32(glink.Size) r.Off = int32(glink.Size)
r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0) r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0)
r.Siz = 8 r.Siz = 8
r.Type = ld.R_ADDRPOWER r.Type = obj.R_ADDRPOWER
// addis r11,0,.plt@ha; addi r11,r11,.plt@l // addis r11,0,.plt@ha; addi r11,r11,.plt@l
r.Add = 0x3d600000<<32 | 0x396b0000 r.Add = 0x3d600000<<32 | 0x396b0000
...@@ -639,7 +639,7 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) { ...@@ -639,7 +639,7 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) {
/* type */ /* type */
t := ld.STB_GLOBAL << 4 t := ld.STB_GLOBAL << 4
if s.Cgoexport != 0 && s.Type&ld.SMASK == ld.STEXT { if s.Cgoexport != 0 && s.Type&obj.SMASK == obj.STEXT {
t |= ld.STT_FUNC t |= ld.STT_FUNC
} else { } else {
t |= ld.STT_OBJECT t |= ld.STT_OBJECT
...@@ -650,14 +650,14 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) { ...@@ -650,14 +650,14 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) {
ld.Adduint8(ctxt, d, 0) ld.Adduint8(ctxt, d, 0)
/* section where symbol is defined */ /* section where symbol is defined */
if s.Type == ld.SDYNIMPORT { if s.Type == obj.SDYNIMPORT {
ld.Adduint16(ctxt, d, ld.SHN_UNDEF) ld.Adduint16(ctxt, d, ld.SHN_UNDEF)
} else { } else {
ld.Adduint16(ctxt, d, 1) ld.Adduint16(ctxt, d, 1)
} }
/* value */ /* value */
if s.Type == ld.SDYNIMPORT { if s.Type == obj.SDYNIMPORT {
ld.Adduint64(ctxt, d, 0) ld.Adduint64(ctxt, d, 0)
} else { } else {
ld.Addaddr(ctxt, d, s) ld.Addaddr(ctxt, d, s)
...@@ -740,7 +740,7 @@ func asmb() { ...@@ -740,7 +740,7 @@ func asmb() {
symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND))) symo = uint32(ld.Rnd(int64(symo), int64(ld.INITRND)))
} }
case ld.Hplan9: case obj.Hplan9:
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen) symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
} }
...@@ -765,7 +765,7 @@ func asmb() { ...@@ -765,7 +765,7 @@ func asmb() {
} }
} }
case ld.Hplan9: case obj.Hplan9:
ld.Asmplan9sym() ld.Asmplan9sym()
ld.Cflush() ld.Cflush()
...@@ -789,7 +789,7 @@ func asmb() { ...@@ -789,7 +789,7 @@ func asmb() {
ld.Cseek(0) ld.Cseek(0)
switch ld.HEADTYPE { switch ld.HEADTYPE {
default: default:
case ld.Hplan9: /* plan 9 */ case obj.Hplan9: /* plan 9 */
ld.Thearch.Lput(0x647) /* magic */ ld.Thearch.Lput(0x647) /* magic */
ld.Thearch.Lput(uint32(ld.Segtext.Filelen)) /* sizes */ ld.Thearch.Lput(uint32(ld.Segtext.Filelen)) /* sizes */
ld.Thearch.Lput(uint32(ld.Segdata.Filelen)) ld.Thearch.Lput(uint32(ld.Segdata.Filelen))
...@@ -799,11 +799,11 @@ func asmb() { ...@@ -799,11 +799,11 @@ func asmb() {
ld.Thearch.Lput(0) ld.Thearch.Lput(0)
ld.Thearch.Lput(uint32(ld.Lcsize)) ld.Thearch.Lput(uint32(ld.Lcsize))
case ld.Hlinux, case obj.Hlinux,
ld.Hfreebsd, obj.Hfreebsd,
ld.Hnetbsd, obj.Hnetbsd,
ld.Hopenbsd, obj.Hopenbsd,
ld.Hnacl: obj.Hnacl:
ld.Asmbelf(int64(symo)) ld.Asmbelf(int64(symo))
} }
......
...@@ -113,7 +113,7 @@ func archinit() { ...@@ -113,7 +113,7 @@ func archinit() {
default: default:
ld.Exitf("unknown -H option: %v", ld.HEADTYPE) ld.Exitf("unknown -H option: %v", ld.HEADTYPE)
case ld.Hplan9: /* plan 9 */ case obj.Hplan9: /* plan 9 */
ld.HEADR = 32 ld.HEADR = 32
if ld.INITTEXT == -1 { if ld.INITTEXT == -1 {
...@@ -126,7 +126,7 @@ func archinit() { ...@@ -126,7 +126,7 @@ func archinit() {
ld.INITRND = 4096 ld.INITRND = 4096
} }
case ld.Hlinux: /* ppc64 elf */ case obj.Hlinux: /* ppc64 elf */
if ld.Thestring == "ppc64" { if ld.Thestring == "ppc64" {
ld.Debug['d'] = 1 // TODO(austin): ELF ABI v1 not supported yet ld.Debug['d'] = 1 // TODO(austin): ELF ABI v1 not supported yet
} }
...@@ -142,7 +142,7 @@ func archinit() { ...@@ -142,7 +142,7 @@ func archinit() {
ld.INITRND = 0x10000 ld.INITRND = 0x10000
} }
case ld.Hnacl: case obj.Hnacl:
ld.Elfinit() ld.Elfinit()
ld.HEADR = 0x10000 ld.HEADR = 0x10000
ld.Funcalign = 16 ld.Funcalign = 16
......
This diff is collapsed.
...@@ -688,7 +688,7 @@ func adddwarfrel(sec *LSym, sym *LSym, offsetbase int64, siz int, addend int64) ...@@ -688,7 +688,7 @@ func adddwarfrel(sec *LSym, sym *LSym, offsetbase int64, siz int, addend int64)
r.Xsym = sym r.Xsym = sym
r.Off = int32(Cpos() - offsetbase) r.Off = int32(Cpos() - offsetbase)
r.Siz = uint8(siz) r.Siz = uint8(siz)
r.Type = R_ADDR r.Type = obj.R_ADDR
r.Add = addend r.Add = addend
r.Xadd = addend r.Xadd = addend
if Iself && Thearch.Thechar == '6' { if Iself && Thearch.Thechar == '6' {
...@@ -1691,11 +1691,11 @@ func writelines() { ...@@ -1691,11 +1691,11 @@ func writelines() {
varhash = [HASHSIZE]*DWDie{} varhash = [HASHSIZE]*DWDie{}
for a = s.Autom; a != nil; a = a.Link { for a = s.Autom; a != nil; a = a.Link {
switch a.Name { switch a.Name {
case A_AUTO: case obj.A_AUTO:
dt = DW_ABRV_AUTO dt = DW_ABRV_AUTO
offs = int64(a.Aoffset) - int64(Thearch.Ptrsize) offs = int64(a.Aoffset) - int64(Thearch.Ptrsize)
case A_PARAM: case obj.A_PARAM:
dt = DW_ABRV_PARAM dt = DW_ABRV_PARAM
offs = int64(a.Aoffset) offs = int64(a.Aoffset)
...@@ -2039,7 +2039,7 @@ func writegdbscript() int64 { ...@@ -2039,7 +2039,7 @@ func writegdbscript() int64 {
} }
func align(size int64) { func align(size int64) {
if HEADTYPE == Hwindows { // Only Windows PE need section align. if HEADTYPE == obj.Hwindows { // Only Windows PE need section align.
strnput("", int(Rnd(size, PEFILEALIGN)-size)) strnput("", int(Rnd(size, PEFILEALIGN)-size))
} }
} }
...@@ -2053,7 +2053,7 @@ func writedwarfreloc(s *LSym) int64 { ...@@ -2053,7 +2053,7 @@ func writedwarfreloc(s *LSym) int64 {
r = &s.R[ri] r = &s.R[ri]
if Iself { if Iself {
i = Thearch.Elfreloc1(r, int64(r.Off)) i = Thearch.Elfreloc1(r, int64(r.Off))
} else if HEADTYPE == Hdarwin { } else if HEADTYPE == obj.Hdarwin {
i = Thearch.Machoreloc1(r, int64(r.Off)) i = Thearch.Machoreloc1(r, int64(r.Off))
} else { } else {
i = -1 i = -1
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package ld package ld
import ( import (
"cmd/internal/obj"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
) )
...@@ -775,7 +776,7 @@ func Elfinit() { ...@@ -775,7 +776,7 @@ func Elfinit() {
// 32-bit architectures // 32-bit architectures
case '5': case '5':
// we use EABI on both linux/arm and freebsd/arm. // we use EABI on both linux/arm and freebsd/arm.
if HEADTYPE == Hlinux || HEADTYPE == Hfreebsd { if HEADTYPE == obj.Hlinux || HEADTYPE == obj.Hfreebsd {
ehdr.flags = 0x5000002 // has entry point, Version5 EABI ehdr.flags = 0x5000002 // has entry point, Version5 EABI
} }
fallthrough fallthrough
...@@ -1245,7 +1246,7 @@ func elfdynhash() { ...@@ -1245,7 +1246,7 @@ func elfdynhash() {
nsym := Nelfsym nsym := Nelfsym
s := Linklookup(Ctxt, ".hash", 0) s := Linklookup(Ctxt, ".hash", 0)
s.Type = SELFROSECT s.Type = obj.SELFROSECT
s.Reachable = true s.Reachable = true
i := nsym i := nsym
...@@ -1576,7 +1577,7 @@ func doelf() { ...@@ -1576,7 +1577,7 @@ func doelf() {
/* predefine strings we need for section headers */ /* predefine strings we need for section headers */
shstrtab := Linklookup(Ctxt, ".shstrtab", 0) shstrtab := Linklookup(Ctxt, ".shstrtab", 0)
shstrtab.Type = SELFROSECT shstrtab.Type = obj.SELFROSECT
shstrtab.Reachable = true shstrtab.Reachable = true
Addstring(shstrtab, "") Addstring(shstrtab, "")
...@@ -1590,15 +1591,15 @@ func doelf() { ...@@ -1590,15 +1591,15 @@ func doelf() {
// for dynamic internal linker or external linking, so that various // for dynamic internal linker or external linking, so that various
// binutils could correctly calculate PT_TLS size. // binutils could correctly calculate PT_TLS size.
// see http://golang.org/issue/5200. // see http://golang.org/issue/5200.
if HEADTYPE != Hopenbsd { if HEADTYPE != obj.Hopenbsd {
if Debug['d'] == 0 || Linkmode == LinkExternal { if Debug['d'] == 0 || Linkmode == LinkExternal {
Addstring(shstrtab, ".tbss") Addstring(shstrtab, ".tbss")
} }
} }
if HEADTYPE == Hnetbsd { if HEADTYPE == obj.Hnetbsd {
Addstring(shstrtab, ".note.netbsd.ident") Addstring(shstrtab, ".note.netbsd.ident")
} }
if HEADTYPE == Hopenbsd { if HEADTYPE == obj.Hopenbsd {
Addstring(shstrtab, ".note.openbsd.ident") Addstring(shstrtab, ".note.openbsd.ident")
} }
if len(buildinfo) > 0 { if len(buildinfo) > 0 {
...@@ -1692,7 +1693,7 @@ func doelf() { ...@@ -1692,7 +1693,7 @@ func doelf() {
/* dynamic symbol table - first entry all zeros */ /* dynamic symbol table - first entry all zeros */
s := Linklookup(Ctxt, ".dynsym", 0) s := Linklookup(Ctxt, ".dynsym", 0)
s.Type = SELFROSECT s.Type = obj.SELFROSECT
s.Reachable = true s.Reachable = true
switch Thearch.Thechar { switch Thearch.Thechar {
case '6', '7', '9': case '6', '7', '9':
...@@ -1704,7 +1705,7 @@ func doelf() { ...@@ -1704,7 +1705,7 @@ func doelf() {
/* dynamic string table */ /* dynamic string table */
s = Linklookup(Ctxt, ".dynstr", 0) s = Linklookup(Ctxt, ".dynstr", 0)
s.Type = SELFROSECT s.Type = obj.SELFROSECT
s.Reachable = true s.Reachable = true
if s.Size == 0 { if s.Size == 0 {
Addstring(s, "") Addstring(s, "")
...@@ -1719,30 +1720,30 @@ func doelf() { ...@@ -1719,30 +1720,30 @@ func doelf() {
s = Linklookup(Ctxt, ".rel", 0) s = Linklookup(Ctxt, ".rel", 0)
} }
s.Reachable = true s.Reachable = true
s.Type = SELFROSECT s.Type = obj.SELFROSECT
/* global offset table */ /* global offset table */
s = Linklookup(Ctxt, ".got", 0) s = Linklookup(Ctxt, ".got", 0)
s.Reachable = true s.Reachable = true
s.Type = SELFGOT // writable s.Type = obj.SELFGOT // writable
/* ppc64 glink resolver */ /* ppc64 glink resolver */
if Thearch.Thechar == '9' { if Thearch.Thechar == '9' {
s := Linklookup(Ctxt, ".glink", 0) s := Linklookup(Ctxt, ".glink", 0)
s.Reachable = true s.Reachable = true
s.Type = SELFRXSECT s.Type = obj.SELFRXSECT
} }
/* hash */ /* hash */
s = Linklookup(Ctxt, ".hash", 0) s = Linklookup(Ctxt, ".hash", 0)
s.Reachable = true s.Reachable = true
s.Type = SELFROSECT s.Type = obj.SELFROSECT
s = Linklookup(Ctxt, ".got.plt", 0) s = Linklookup(Ctxt, ".got.plt", 0)
s.Reachable = true s.Reachable = true
s.Type = SELFSECT // writable s.Type = obj.SELFSECT // writable
s = Linklookup(Ctxt, ".plt", 0) s = Linklookup(Ctxt, ".plt", 0)
...@@ -1750,9 +1751,9 @@ func doelf() { ...@@ -1750,9 +1751,9 @@ func doelf() {
if Thearch.Thechar == '9' { if Thearch.Thechar == '9' {
// In the ppc64 ABI, .plt is a data section // In the ppc64 ABI, .plt is a data section
// written by the dynamic linker. // written by the dynamic linker.
s.Type = SELFSECT s.Type = obj.SELFSECT
} else { } else {
s.Type = SELFRXSECT s.Type = obj.SELFRXSECT
} }
Thearch.Elfsetupplt() Thearch.Elfsetupplt()
...@@ -1764,21 +1765,21 @@ func doelf() { ...@@ -1764,21 +1765,21 @@ func doelf() {
s = Linklookup(Ctxt, ".rel.plt", 0) s = Linklookup(Ctxt, ".rel.plt", 0)
} }
s.Reachable = true s.Reachable = true
s.Type = SELFROSECT s.Type = obj.SELFROSECT
s = Linklookup(Ctxt, ".gnu.version", 0) s = Linklookup(Ctxt, ".gnu.version", 0)
s.Reachable = true s.Reachable = true
s.Type = SELFROSECT s.Type = obj.SELFROSECT
s = Linklookup(Ctxt, ".gnu.version_r", 0) s = Linklookup(Ctxt, ".gnu.version_r", 0)
s.Reachable = true s.Reachable = true
s.Type = SELFROSECT s.Type = obj.SELFROSECT
/* define dynamic elf table */ /* define dynamic elf table */
s = Linklookup(Ctxt, ".dynamic", 0) s = Linklookup(Ctxt, ".dynamic", 0)
s.Reachable = true s.Reachable = true
s.Type = SELFSECT // writable s.Type = obj.SELFSECT // writable
/* /*
* .dynamic table * .dynamic table
...@@ -1906,7 +1907,7 @@ func Asmbelf(symo int64) { ...@@ -1906,7 +1907,7 @@ func Asmbelf(symo int64) {
* segment boundaries downwards to include it. * segment boundaries downwards to include it.
* Except on NaCl where it must not be loaded. * Except on NaCl where it must not be loaded.
*/ */
if HEADTYPE != Hnacl { if HEADTYPE != obj.Hnacl {
o := int64(Segtext.Vaddr - pph.vaddr) o := int64(Segtext.Vaddr - pph.vaddr)
Segtext.Vaddr -= uint64(o) Segtext.Vaddr -= uint64(o)
Segtext.Length += uint64(o) Segtext.Length += uint64(o)
...@@ -1924,22 +1925,22 @@ func Asmbelf(symo int64) { ...@@ -1924,22 +1925,22 @@ func Asmbelf(symo int64) {
sh.addralign = 1 sh.addralign = 1
if interpreter == "" { if interpreter == "" {
switch HEADTYPE { switch HEADTYPE {
case Hlinux: case obj.Hlinux:
interpreter = Thearch.Linuxdynld interpreter = Thearch.Linuxdynld
case Hfreebsd: case obj.Hfreebsd:
interpreter = Thearch.Freebsddynld interpreter = Thearch.Freebsddynld
case Hnetbsd: case obj.Hnetbsd:
interpreter = Thearch.Netbsddynld interpreter = Thearch.Netbsddynld
case Hopenbsd: case obj.Hopenbsd:
interpreter = Thearch.Openbsddynld interpreter = Thearch.Openbsddynld
case Hdragonfly: case obj.Hdragonfly:
interpreter = Thearch.Dragonflydynld interpreter = Thearch.Dragonflydynld
case Hsolaris: case obj.Hsolaris:
interpreter = Thearch.Solarisdynld interpreter = Thearch.Solarisdynld
} }
} }
...@@ -1953,14 +1954,14 @@ func Asmbelf(symo int64) { ...@@ -1953,14 +1954,14 @@ func Asmbelf(symo int64) {
} }
pnote = nil pnote = nil
if HEADTYPE == Hnetbsd || HEADTYPE == Hopenbsd { if HEADTYPE == obj.Hnetbsd || HEADTYPE == obj.Hopenbsd {
var sh *ElfShdr var sh *ElfShdr
switch HEADTYPE { switch HEADTYPE {
case Hnetbsd: case obj.Hnetbsd:
sh = elfshname(".note.netbsd.ident") sh = elfshname(".note.netbsd.ident")
resoff -= int64(elfnetbsdsig(sh, uint64(startva), uint64(resoff))) resoff -= int64(elfnetbsdsig(sh, uint64(startva), uint64(resoff)))
case Hopenbsd: case obj.Hopenbsd:
sh = elfshname(".note.openbsd.ident") sh = elfshname(".note.openbsd.ident")
resoff -= int64(elfopenbsdsig(sh, uint64(startva), uint64(resoff))) resoff -= int64(elfopenbsdsig(sh, uint64(startva), uint64(resoff)))
} }
...@@ -2141,7 +2142,7 @@ func Asmbelf(symo int64) { ...@@ -2141,7 +2142,7 @@ func Asmbelf(symo int64) {
// Do not emit PT_TLS for OpenBSD since ld.so(1) does // Do not emit PT_TLS for OpenBSD since ld.so(1) does
// not currently support it. This is handled // not currently support it. This is handled
// appropriately in runtime/cgo. // appropriately in runtime/cgo.
if Ctxt.Tlsoffset != 0 && HEADTYPE != Hopenbsd { if Ctxt.Tlsoffset != 0 && HEADTYPE != obj.Hopenbsd {
ph := newElfPhdr() ph := newElfPhdr()
ph.type_ = PT_TLS ph.type_ = PT_TLS
ph.flags = PF_R ph.flags = PF_R
...@@ -2150,7 +2151,7 @@ func Asmbelf(symo int64) { ...@@ -2150,7 +2151,7 @@ func Asmbelf(symo int64) {
} }
} }
if HEADTYPE == Hlinux { if HEADTYPE == obj.Hlinux {
ph := newElfPhdr() ph := newElfPhdr()
ph.type_ = PT_GNU_STACK ph.type_ = PT_GNU_STACK
ph.flags = PF_W + PF_R ph.flags = PF_W + PF_R
...@@ -2206,7 +2207,7 @@ elfobj: ...@@ -2206,7 +2207,7 @@ elfobj:
// generate .tbss section for dynamic internal linking (except for OpenBSD) // generate .tbss section for dynamic internal linking (except for OpenBSD)
// external linking generates .tbss in data.c // external linking generates .tbss in data.c
if Linkmode == LinkInternal && Debug['d'] == 0 && HEADTYPE != Hopenbsd { if Linkmode == LinkInternal && Debug['d'] == 0 && HEADTYPE != obj.Hopenbsd {
sh := elfshname(".tbss") sh := elfshname(".tbss")
sh.type_ = SHT_NOBITS sh.type_ = SHT_NOBITS
sh.addralign = uint64(Thearch.Regsize) sh.addralign = uint64(Thearch.Regsize)
...@@ -2239,13 +2240,13 @@ elfobj: ...@@ -2239,13 +2240,13 @@ elfobj:
eh.ident[EI_MAG1] = 'E' eh.ident[EI_MAG1] = 'E'
eh.ident[EI_MAG2] = 'L' eh.ident[EI_MAG2] = 'L'
eh.ident[EI_MAG3] = 'F' eh.ident[EI_MAG3] = 'F'
if HEADTYPE == Hfreebsd { if HEADTYPE == obj.Hfreebsd {
eh.ident[EI_OSABI] = ELFOSABI_FREEBSD eh.ident[EI_OSABI] = ELFOSABI_FREEBSD
} else if HEADTYPE == Hnetbsd { } else if HEADTYPE == obj.Hnetbsd {
eh.ident[EI_OSABI] = ELFOSABI_NETBSD eh.ident[EI_OSABI] = ELFOSABI_NETBSD
} else if HEADTYPE == Hopenbsd { } else if HEADTYPE == obj.Hopenbsd {
eh.ident[EI_OSABI] = ELFOSABI_OPENBSD eh.ident[EI_OSABI] = ELFOSABI_OPENBSD
} else if HEADTYPE == Hdragonfly { } else if HEADTYPE == obj.Hdragonfly {
eh.ident[EI_OSABI] = ELFOSABI_NONE eh.ident[EI_OSABI] = ELFOSABI_NONE
} }
if elf64 { if elf64 {
...@@ -2286,10 +2287,10 @@ elfobj: ...@@ -2286,10 +2287,10 @@ elfobj:
a += int64(elfwriteinterp()) a += int64(elfwriteinterp())
} }
if Linkmode != LinkExternal { if Linkmode != LinkExternal {
if HEADTYPE == Hnetbsd { if HEADTYPE == obj.Hnetbsd {
a += int64(elfwritenetbsdsig()) a += int64(elfwritenetbsdsig())
} }
if HEADTYPE == Hopenbsd { if HEADTYPE == obj.Hopenbsd {
a += int64(elfwriteopenbsdsig()) a += int64(elfwriteopenbsdsig())
} }
if len(buildinfo) > 0 { if len(buildinfo) > 0 {
......
...@@ -432,12 +432,12 @@ func loadcgo(file string, pkg string, p string) { ...@@ -432,12 +432,12 @@ func loadcgo(file string, pkg string, p string) {
s = Linklookup(Ctxt, local, 0) s = Linklookup(Ctxt, local, 0)
if local != f[1] { if local != f[1] {
} }
if s.Type == 0 || s.Type == SXREF || s.Type == SHOSTOBJ { if s.Type == 0 || s.Type == obj.SXREF || s.Type == obj.SHOSTOBJ {
s.Dynimplib = lib s.Dynimplib = lib
s.Extname = remote s.Extname = remote
s.Dynimpvers = q s.Dynimpvers = q
if s.Type != SHOSTOBJ { if s.Type != obj.SHOSTOBJ {
s.Type = SDYNIMPORT s.Type = obj.SDYNIMPORT
} }
havedynamic = 1 havedynamic = 1
} }
...@@ -451,7 +451,7 @@ func loadcgo(file string, pkg string, p string) { ...@@ -451,7 +451,7 @@ func loadcgo(file string, pkg string, p string) {
} }
local = f[1] local = f[1]
s = Linklookup(Ctxt, local, 0) s = Linklookup(Ctxt, local, 0)
s.Type = SHOSTOBJ s.Type = obj.SHOSTOBJ
s.Size = 0 s.Size = 0
continue continue
} }
...@@ -568,7 +568,7 @@ func markflood() { ...@@ -568,7 +568,7 @@ func markflood() {
var i int var i int
for s := markq; s != nil; s = s.Queue { for s := markq; s != nil; s = s.Queue {
if s.Type == STEXT { if s.Type == obj.STEXT {
if Debug['v'] > 1 { if Debug['v'] > 1 {
fmt.Fprintf(&Bso, "marktext %s\n", s.Name) fmt.Fprintf(&Bso, "marktext %s\n", s.Name)
} }
...@@ -699,7 +699,7 @@ func deadcode() { ...@@ -699,7 +699,7 @@ func deadcode() {
buf.WriteString("\n") buf.WriteString("\n")
} }
s.Type = SCONST s.Type = obj.SCONST
s.Value = 0 s.Value = 0
} }
} }
...@@ -727,7 +727,7 @@ func doweak() { ...@@ -727,7 +727,7 @@ func doweak() {
s.Type = t.Type s.Type = t.Type
s.Outer = t s.Outer = t
} else { } else {
s.Type = SCONST s.Type = obj.SCONST
s.Value = 0 s.Value = 0
} }
...@@ -737,7 +737,7 @@ func doweak() { ...@@ -737,7 +737,7 @@ func doweak() {
} }
func addexport() { func addexport() {
if HEADTYPE == Hdarwin { if HEADTYPE == obj.Hdarwin {
return return
} }
......
...@@ -567,21 +567,21 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) { ...@@ -567,21 +567,21 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) {
goto bad goto bad
case ElfSectFlagAlloc: case ElfSectFlagAlloc:
s.Type = SRODATA s.Type = obj.SRODATA
case ElfSectFlagAlloc + ElfSectFlagWrite: case ElfSectFlagAlloc + ElfSectFlagWrite:
if sect.type_ == ElfSectNobits { if sect.type_ == ElfSectNobits {
s.Type = SNOPTRBSS s.Type = obj.SNOPTRBSS
} else { } else {
s.Type = SNOPTRDATA s.Type = obj.SNOPTRDATA
} }
case ElfSectFlagAlloc + ElfSectFlagExec: case ElfSectFlagAlloc + ElfSectFlagExec:
s.Type = STEXT s.Type = obj.STEXT
} }
if sect.name == ".got" || sect.name == ".toc" { if sect.name == ".got" || sect.name == ".toc" {
s.Type = SELFGOT s.Type = obj.SELFGOT
} }
if sect.type_ == ElfSectProgbits { if sect.type_ == ElfSectProgbits {
s.P = sect.base s.P = sect.base
...@@ -610,8 +610,8 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) { ...@@ -610,8 +610,8 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) {
if uint64(s.Size) < sym.size { if uint64(s.Size) < sym.size {
s.Size = int64(sym.size) s.Size = int64(sym.size)
} }
if s.Type == 0 || s.Type == SXREF { if s.Type == 0 || s.Type == obj.SXREF {
s.Type = SNOPTRBSS s.Type = obj.SNOPTRBSS
} }
continue continue
} }
...@@ -643,14 +643,14 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) { ...@@ -643,14 +643,14 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) {
s.Sub = sect.sym.Sub s.Sub = sect.sym.Sub
sect.sym.Sub = s sect.sym.Sub = s
s.Type = sect.sym.Type | s.Type&^SMASK | SSUB s.Type = sect.sym.Type | s.Type&^obj.SMASK | obj.SSUB
if s.Cgoexport&CgoExportDynamic == 0 { if s.Cgoexport&CgoExportDynamic == 0 {
s.Dynimplib = "" // satisfy dynimport s.Dynimplib = "" // satisfy dynimport
} }
s.Value = int64(sym.value) s.Value = int64(sym.value)
s.Size = int64(sym.size) s.Size = int64(sym.size)
s.Outer = sect.sym s.Outer = sect.sym
if sect.sym.Type == STEXT { if sect.sym.Type == obj.STEXT {
if s.External != 0 && s.Dupok == 0 { if s.External != 0 && s.Dupok == 0 {
Diag("%s: duplicate definition of %s", pn, s.Name) Diag("%s: duplicate definition of %s", pn, s.Name)
} }
...@@ -677,7 +677,7 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) { ...@@ -677,7 +677,7 @@ func ldelf(f *Biobuf, pkg string, length int64, pn string) {
if s.Sub != nil { if s.Sub != nil {
s.Sub = listsort(s.Sub, valuecmp, listsubp) s.Sub = listsort(s.Sub, valuecmp, listsubp)
} }
if s.Type == STEXT { if s.Type == obj.STEXT {
if s.Onlist != 0 { if s.Onlist != 0 {
log.Fatalf("symbol %s listed multiple times", s.Name) log.Fatalf("symbol %s listed multiple times", s.Name)
} }
...@@ -893,7 +893,7 @@ func readelfsym(elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) { ...@@ -893,7 +893,7 @@ func readelfsym(elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) {
// set dupok generally. See http://codereview.appspot.com/5823055/ // set dupok generally. See http://codereview.appspot.com/5823055/
// comment #5 for details. // comment #5 for details.
if s != nil && sym.other == 2 { if s != nil && sym.other == 2 {
s.Type |= SHIDDEN s.Type |= obj.SHIDDEN
s.Dupok = 1 s.Dupok = 1
} }
} }
...@@ -910,7 +910,7 @@ func readelfsym(elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) { ...@@ -910,7 +910,7 @@ func readelfsym(elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) {
// so put it in the hash table. // so put it in the hash table.
if needSym != 0 { if needSym != 0 {
s = Linklookup(Ctxt, sym.name, Ctxt.Version) s = Linklookup(Ctxt, sym.name, Ctxt.Version)
s.Type |= SHIDDEN s.Type |= obj.SHIDDEN
} }
break break
...@@ -922,14 +922,14 @@ func readelfsym(elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) { ...@@ -922,14 +922,14 @@ func readelfsym(elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) {
// don't bother to add them into hash table // don't bother to add them into hash table
s = linknewsym(Ctxt, sym.name, Ctxt.Version) s = linknewsym(Ctxt, sym.name, Ctxt.Version)
s.Type |= SHIDDEN s.Type |= obj.SHIDDEN
} }
case ElfSymBindWeak: case ElfSymBindWeak:
if needSym != 0 { if needSym != 0 {
s = linknewsym(Ctxt, sym.name, 0) s = linknewsym(Ctxt, sym.name, 0)
if sym.other == 2 { if sym.other == 2 {
s.Type |= SHIDDEN s.Type |= obj.SHIDDEN
} }
} }
...@@ -940,7 +940,7 @@ func readelfsym(elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) { ...@@ -940,7 +940,7 @@ func readelfsym(elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) {
} }
if s != nil && s.Type == 0 && sym.type_ != ElfSymTypeSection { if s != nil && s.Type == 0 && sym.type_ != ElfSymTypeSection {
s.Type = SXREF s.Type = obj.SXREF
} }
sym.sym = s sym.sym = s
......
package ld package ld
import ( import (
"cmd/internal/obj"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"log" "log"
...@@ -583,16 +584,16 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) { ...@@ -583,16 +584,16 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) {
if sect.segname == "__TEXT" { if sect.segname == "__TEXT" {
if sect.name == "__text" { if sect.name == "__text" {
s.Type = STEXT s.Type = obj.STEXT
} else { } else {
s.Type = SRODATA s.Type = obj.SRODATA
} }
} else { } else {
if sect.name == "__bss" { if sect.name == "__bss" {
s.Type = SNOPTRBSS s.Type = obj.SNOPTRBSS
s.P = s.P[:0] s.P = s.P[:0]
} else { } else {
s.Type = SNOPTRDATA s.Type = obj.SNOPTRDATA
} }
} }
...@@ -644,7 +645,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) { ...@@ -644,7 +645,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) {
Exitf("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name) Exitf("%s: duplicate symbol reference: %s in both %s and %s", pn, s.Name, s.Outer.Name, sect.sym.Name)
} }
s.Type = outer.Type | SSUB s.Type = outer.Type | obj.SSUB
s.Sub = outer.Sub s.Sub = outer.Sub
outer.Sub = s outer.Sub = s
s.Outer = outer s.Outer = outer
...@@ -652,7 +653,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) { ...@@ -652,7 +653,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) {
if s.Cgoexport&CgoExportDynamic == 0 { if s.Cgoexport&CgoExportDynamic == 0 {
s.Dynimplib = "" // satisfy dynimport s.Dynimplib = "" // satisfy dynimport
} }
if outer.Type == STEXT { if outer.Type == obj.STEXT {
if s.External != 0 && s.Dupok == 0 { if s.External != 0 && s.Dupok == 0 {
Diag("%s: duplicate definition of %s", pn, s.Name) Diag("%s: duplicate definition of %s", pn, s.Name)
} }
...@@ -683,7 +684,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) { ...@@ -683,7 +684,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) {
} }
} }
if s.Type == STEXT { if s.Type == obj.STEXT {
if s.Onlist != 0 { if s.Onlist != 0 {
log.Fatalf("symbol %s listed multiple times", s.Name) log.Fatalf("symbol %s listed multiple times", s.Name)
} }
...@@ -760,7 +761,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) { ...@@ -760,7 +761,7 @@ func ldmacho(f *Biobuf, pkg string, length int64, pn string) {
// want to make it pc-relative aka relative to rp->off+4 // want to make it pc-relative aka relative to rp->off+4
// but the scatter asks for relative to off = sect->rel[j+1].value - sect->addr. // but the scatter asks for relative to off = sect->rel[j+1].value - sect->addr.
// adjust rp->add accordingly. // adjust rp->add accordingly.
rp.Type = R_PCREL rp.Type = obj.R_PCREL
rp.Add += int64(uint64(int64(rp.Off)+4) - (uint64(sect.rel[j+1].value) - sect.addr)) rp.Add += int64(uint64(int64(rp.Off)+4) - (uint64(sect.rel[j+1].value) - sect.addr))
......
...@@ -246,16 +246,16 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) { ...@@ -246,16 +246,16 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) {
switch sect.sh.Characteristics & (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE) { switch sect.sh.Characteristics & (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE) {
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ: //.rdata case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ: //.rdata
s.Type = SRODATA s.Type = obj.SRODATA
case IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.bss case IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.bss
s.Type = SNOPTRBSS s.Type = obj.SNOPTRBSS
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.data case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.data
s.Type = SNOPTRDATA s.Type = obj.SNOPTRDATA
case IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ: //.text case IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ: //.text
s.Type = STEXT s.Type = obj.STEXT
default: default:
err = fmt.Errorf("unexpected flags %#06x for PE section %s", sect.sh.Characteristics, sect.name) err = fmt.Errorf("unexpected flags %#06x for PE section %s", sect.sh.Characteristics, sect.name)
...@@ -315,12 +315,12 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) { ...@@ -315,12 +315,12 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) {
case IMAGE_REL_I386_REL32, IMAGE_REL_AMD64_REL32, case IMAGE_REL_I386_REL32, IMAGE_REL_AMD64_REL32,
IMAGE_REL_AMD64_ADDR32, // R_X86_64_PC32 IMAGE_REL_AMD64_ADDR32, // R_X86_64_PC32
IMAGE_REL_AMD64_ADDR32NB: IMAGE_REL_AMD64_ADDR32NB:
rp.Type = R_PCREL rp.Type = obj.R_PCREL
rp.Add = int64(int32(Le32(rsect.base[rp.Off:]))) rp.Add = int64(int32(Le32(rsect.base[rp.Off:])))
case IMAGE_REL_I386_DIR32NB, IMAGE_REL_I386_DIR32: case IMAGE_REL_I386_DIR32NB, IMAGE_REL_I386_DIR32:
rp.Type = R_ADDR rp.Type = obj.R_ADDR
// load addend from image // load addend from image
rp.Add = int64(int32(Le32(rsect.base[rp.Off:]))) rp.Add = int64(int32(Le32(rsect.base[rp.Off:])))
...@@ -328,7 +328,7 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) { ...@@ -328,7 +328,7 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) {
case IMAGE_REL_AMD64_ADDR64: // R_X86_64_64 case IMAGE_REL_AMD64_ADDR64: // R_X86_64_64
rp.Siz = 8 rp.Siz = 8
rp.Type = R_ADDR rp.Type = obj.R_ADDR
// load addend from image // load addend from image
rp.Add = int64(Le64(rsect.base[rp.Off:])) rp.Add = int64(Le64(rsect.base[rp.Off:]))
...@@ -373,11 +373,11 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) { ...@@ -373,11 +373,11 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) {
s = sym.sym s = sym.sym
if sym.sectnum == 0 { // extern if sym.sectnum == 0 { // extern
if s.Type == SDYNIMPORT { if s.Type == obj.SDYNIMPORT {
s.Plt = -2 // flag for dynimport in PE object files. s.Plt = -2 // flag for dynimport in PE object files.
} }
if s.Type == SXREF && sym.value > 0 { // global data if s.Type == obj.SXREF && sym.value > 0 { // global data
s.Type = SNOPTRDATA s.Type = obj.SNOPTRDATA
s.Size = int64(sym.value) s.Size = int64(sym.value)
} }
...@@ -404,11 +404,11 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) { ...@@ -404,11 +404,11 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) {
s.Sub = sect.sym.Sub s.Sub = sect.sym.Sub
sect.sym.Sub = s sect.sym.Sub = s
s.Type = sect.sym.Type | SSUB s.Type = sect.sym.Type | obj.SSUB
s.Value = int64(sym.value) s.Value = int64(sym.value)
s.Size = 4 s.Size = 4
s.Outer = sect.sym s.Outer = sect.sym
if sect.sym.Type == STEXT { if sect.sym.Type == obj.STEXT {
if s.External != 0 && s.Dupok == 0 { if s.External != 0 && s.Dupok == 0 {
Diag("%s: duplicate definition of %s", pn, s.Name) Diag("%s: duplicate definition of %s", pn, s.Name)
} }
...@@ -426,7 +426,7 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) { ...@@ -426,7 +426,7 @@ func ldpe(f *Biobuf, pkg string, length int64, pn string) {
if s.Sub != nil { if s.Sub != nil {
s.Sub = listsort(s.Sub, valuecmp, listsubp) s.Sub = listsort(s.Sub, valuecmp, listsubp)
} }
if s.Type == STEXT { if s.Type == obj.STEXT {
if s.Onlist != 0 { if s.Onlist != 0 {
log.Fatalf("symbol %s listed multiple times", s.Name) log.Fatalf("symbol %s listed multiple times", s.Name)
} }
...@@ -523,7 +523,7 @@ func readpesym(peobj *PeObj, i int, y **PeSym) (err error) { ...@@ -523,7 +523,7 @@ func readpesym(peobj *PeObj, i int, y **PeSym) (err error) {
} }
if s != nil && s.Type == 0 && (sym.sclass != IMAGE_SYM_CLASS_STATIC || sym.value != 0) { if s != nil && s.Type == 0 && (sym.sclass != IMAGE_SYM_CLASS_STATIC || sym.value != 0) {
s.Type = SXREF s.Type = obj.SXREF
} }
if strings.HasPrefix(sym.name, "__imp_") { if strings.HasPrefix(sym.name, "__imp_") {
s.Got = -2 // flag for __imp_ s.Got = -2 // flag for __imp_
......
...@@ -376,7 +376,7 @@ func libinit() { ...@@ -376,7 +376,7 @@ func libinit() {
} }
if !DynlinkingGo() { if !DynlinkingGo() {
Linklookup(Ctxt, INITENTRY, 0).Type = SXREF Linklookup(Ctxt, INITENTRY, 0).Type = obj.SXREF
} }
} }
...@@ -485,7 +485,7 @@ func loadlib() { ...@@ -485,7 +485,7 @@ func loadlib() {
// dependency problems when compiling natively (external linking requires // dependency problems when compiling natively (external linking requires
// runtime/cgo, runtime/cgo requires cmd/cgo, but cmd/cgo needs to be // runtime/cgo, runtime/cgo requires cmd/cgo, but cmd/cgo needs to be
// compiled using external linking.) // compiled using external linking.)
if (Thearch.Thechar == '5' || Thearch.Thechar == '7') && HEADTYPE == Hdarwin && iscgo { if (Thearch.Thechar == '5' || Thearch.Thechar == '7') && HEADTYPE == obj.Hdarwin && iscgo {
Linkmode = LinkExternal Linkmode = LinkExternal
} }
} }
...@@ -516,13 +516,13 @@ func loadlib() { ...@@ -516,13 +516,13 @@ func loadlib() {
// Drop all the cgo_import_static declarations. // Drop all the cgo_import_static declarations.
// Turns out we won't be needing them. // Turns out we won't be needing them.
for s := Ctxt.Allsym; s != nil; s = s.Allsym { for s := Ctxt.Allsym; s != nil; s = s.Allsym {
if s.Type == SHOSTOBJ { if s.Type == obj.SHOSTOBJ {
// If a symbol was marked both // If a symbol was marked both
// cgo_import_static and cgo_import_dynamic, // cgo_import_static and cgo_import_dynamic,
// then we want to make it cgo_import_dynamic // then we want to make it cgo_import_dynamic
// now. // now.
if s.Extname != "" && s.Dynimplib != "" && s.Cgoexport == 0 { if s.Extname != "" && s.Dynimplib != "" && s.Cgoexport == 0 {
s.Type = SDYNIMPORT s.Type = obj.SDYNIMPORT
} else { } else {
s.Type = 0 s.Type = 0
} }
...@@ -539,8 +539,8 @@ func loadlib() { ...@@ -539,8 +539,8 @@ func loadlib() {
// TODO(crawshaw): android should require leaving the tlsg->type // TODO(crawshaw): android should require leaving the tlsg->type
// alone (as the runtime-provided SNOPTRBSS) just like darwin/arm. // alone (as the runtime-provided SNOPTRBSS) just like darwin/arm.
// But some other part of the linker is expecting STLSBSS. // But some other part of the linker is expecting STLSBSS.
if tlsg.Type != SDYNIMPORT && (goos != "darwin" || Thearch.Thechar != '5') { if tlsg.Type != obj.SDYNIMPORT && (goos != "darwin" || Thearch.Thechar != '5') {
tlsg.Type = STLSBSS tlsg.Type = obj.STLSBSS
} }
tlsg.Size = int64(Thearch.Ptrsize) tlsg.Size = int64(Thearch.Ptrsize)
tlsg.Reachable = true tlsg.Reachable = true
...@@ -579,7 +579,7 @@ func loadlib() { ...@@ -579,7 +579,7 @@ func loadlib() {
// binaries, so leave it enabled on OS X (Mach-O) binaries. // binaries, so leave it enabled on OS X (Mach-O) binaries.
// Also leave it enabled on Solaris which doesn't support // Also leave it enabled on Solaris which doesn't support
// statically linked binaries. // statically linked binaries.
if Buildmode == BuildmodeExe && havedynamic == 0 && HEADTYPE != Hdarwin && HEADTYPE != Hsolaris { if Buildmode == BuildmodeExe && havedynamic == 0 && HEADTYPE != obj.Hdarwin && HEADTYPE != obj.Hsolaris {
Debug['d'] = 1 Debug['d'] = 1
} }
...@@ -743,7 +743,7 @@ func ldhostobj(ld func(*Biobuf, string, int64, string), f *Biobuf, pkg string, l ...@@ -743,7 +743,7 @@ func ldhostobj(ld func(*Biobuf, string, int64, string), f *Biobuf, pkg string, l
// force external linking for any libraries that link in code that // force external linking for any libraries that link in code that
// uses errno. This can be removed if the Go linker ever supports // uses errno. This can be removed if the Go linker ever supports
// these relocation types. // these relocation types.
if HEADTYPE == Hdragonfly { if HEADTYPE == obj.Hdragonfly {
if pkg == "net" || pkg == "os/user" { if pkg == "net" || pkg == "os/user" {
isinternal = false isinternal = false
} }
...@@ -898,13 +898,13 @@ func hostlink() { ...@@ -898,13 +898,13 @@ func hostlink() {
argv = append(argv, "-s") argv = append(argv, "-s")
} }
if HEADTYPE == Hdarwin { if HEADTYPE == obj.Hdarwin {
argv = append(argv, "-Wl,-no_pie,-pagezero_size,4000000") argv = append(argv, "-Wl,-no_pie,-pagezero_size,4000000")
} }
if HEADTYPE == Hopenbsd { if HEADTYPE == obj.Hopenbsd {
argv = append(argv, "-Wl,-nopie") argv = append(argv, "-Wl,-nopie")
} }
if HEADTYPE == Hwindows { if HEADTYPE == obj.Hwindows {
if headstring == "windowsgui" { if headstring == "windowsgui" {
argv = append(argv, "-mwindows") argv = append(argv, "-mwindows")
} else { } else {
...@@ -990,7 +990,7 @@ func hostlink() { ...@@ -990,7 +990,7 @@ func hostlink() {
} }
} }
} }
if HEADTYPE == Hwindows { if HEADTYPE == obj.Hwindows {
argv = append(argv, peimporteddlls()...) argv = append(argv, peimporteddlls()...)
} }
...@@ -1157,7 +1157,7 @@ func ldshlibsyms(shlib string) { ...@@ -1157,7 +1157,7 @@ func ldshlibsyms(shlib string) {
"Found duplicate symbol %s reading from %s, first found in %s", "Found duplicate symbol %s reading from %s, first found in %s",
s.Name, shlib, lsym.File) s.Name, shlib, lsym.File)
} }
lsym.Type = SDYNIMPORT lsym.Type = obj.SDYNIMPORT
lsym.File = libpath lsym.File = libpath
} }
...@@ -1168,7 +1168,7 @@ func ldshlibsyms(shlib string) { ...@@ -1168,7 +1168,7 @@ func ldshlibsyms(shlib string) {
var last *LSym var last *LSym
for s := Ctxt.Textp; s != nil; s = s.Next { for s := Ctxt.Textp; s != nil; s = s.Next {
if s.Type == SDYNIMPORT { if s.Type == obj.SDYNIMPORT {
continue continue
} }
...@@ -1360,7 +1360,7 @@ func stkcheck(up *Chain, depth int) int { ...@@ -1360,7 +1360,7 @@ func stkcheck(up *Chain, depth int) int {
// should never be called directly. // should never be called directly.
// only diagnose the direct caller. // only diagnose the direct caller.
// TODO(mwhudson): actually think about this. // TODO(mwhudson): actually think about this.
if depth == 1 && s.Type != SXREF && !DynlinkingGo() { if depth == 1 && s.Type != obj.SXREF && !DynlinkingGo() {
Diag("call to external function %s", s.Name) Diag("call to external function %s", s.Name)
} }
return -1 return -1
...@@ -1401,7 +1401,7 @@ func stkcheck(up *Chain, depth int) int { ...@@ -1401,7 +1401,7 @@ func stkcheck(up *Chain, depth int) int {
r = &s.R[ri] r = &s.R[ri]
switch r.Type { switch r.Type {
// Direct call. // Direct call.
case R_CALL, R_CALLARM, R_CALLARM64, R_CALLPOWER: case obj.R_CALL, obj.R_CALLARM, obj.R_CALLARM64, obj.R_CALLPOWER:
ch.limit = int(int32(limit) - pcsp.value - int32(callsize())) ch.limit = int(int32(limit) - pcsp.value - int32(callsize()))
ch.sym = r.Sym ch.sym = r.Sym
...@@ -1422,7 +1422,7 @@ func stkcheck(up *Chain, depth int) int { ...@@ -1422,7 +1422,7 @@ func stkcheck(up *Chain, depth int) int {
// so we have to make sure it can call morestack. // so we have to make sure it can call morestack.
// Arrange the data structures to report both calls, so that // Arrange the data structures to report both calls, so that
// if there is an error, stkprint shows all the steps involved. // if there is an error, stkprint shows all the steps involved.
case R_CALLIND: case obj.R_CALLIND:
ch.limit = int(int32(limit) - pcsp.value - int32(callsize())) ch.limit = int(int32(limit) - pcsp.value - int32(callsize()))
ch.sym = nil ch.sym = nil
...@@ -1549,11 +1549,11 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) { ...@@ -1549,11 +1549,11 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
// skip STEXT symbols. Normal STEXT symbols are emitted by walking textp. // skip STEXT symbols. Normal STEXT symbols are emitted by walking textp.
s := Linklookup(Ctxt, "runtime.text", 0) s := Linklookup(Ctxt, "runtime.text", 0)
if s.Type == STEXT { if s.Type == obj.STEXT {
put(s, s.Name, 'T', s.Value, s.Size, int(s.Version), nil) put(s, s.Name, 'T', s.Value, s.Size, int(s.Version), nil)
} }
s = Linklookup(Ctxt, "runtime.etext", 0) s = Linklookup(Ctxt, "runtime.etext", 0)
if s.Type == STEXT { if s.Type == obj.STEXT {
put(s, s.Name, 'T', s.Value, s.Size, int(s.Version), nil) put(s, s.Name, 'T', s.Value, s.Size, int(s.Version), nil)
} }
...@@ -1561,27 +1561,27 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) { ...@@ -1561,27 +1561,27 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
if s.Hide != 0 || (s.Name[0] == '.' && s.Version == 0 && s.Name != ".rathole") { if s.Hide != 0 || (s.Name[0] == '.' && s.Version == 0 && s.Name != ".rathole") {
continue continue
} }
switch s.Type & SMASK { switch s.Type & obj.SMASK {
case SCONST, case obj.SCONST,
SRODATA, obj.SRODATA,
SSYMTAB, obj.SSYMTAB,
SPCLNTAB, obj.SPCLNTAB,
SINITARR, obj.SINITARR,
SDATA, obj.SDATA,
SNOPTRDATA, obj.SNOPTRDATA,
SELFROSECT, obj.SELFROSECT,
SMACHOGOT, obj.SMACHOGOT,
STYPE, obj.STYPE,
SSTRING, obj.SSTRING,
SGOSTRING, obj.SGOSTRING,
SGOFUNC, obj.SGOFUNC,
SWINDOWS: obj.SWINDOWS:
if !s.Reachable { if !s.Reachable {
continue continue
} }
put(s, s.Name, 'D', Symaddr(s), s.Size, int(s.Version), s.Gotype) put(s, s.Name, 'D', Symaddr(s), s.Size, int(s.Version), s.Gotype)
case SBSS, SNOPTRBSS: case obj.SBSS, obj.SNOPTRBSS:
if !s.Reachable { if !s.Reachable {
continue continue
} }
...@@ -1590,22 +1590,22 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) { ...@@ -1590,22 +1590,22 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
} }
put(s, s.Name, 'B', Symaddr(s), s.Size, int(s.Version), s.Gotype) put(s, s.Name, 'B', Symaddr(s), s.Size, int(s.Version), s.Gotype)
case SFILE: case obj.SFILE:
put(nil, s.Name, 'f', s.Value, 0, int(s.Version), nil) put(nil, s.Name, 'f', s.Value, 0, int(s.Version), nil)
case SHOSTOBJ: case obj.SHOSTOBJ:
if HEADTYPE == Hwindows || Iself { if HEADTYPE == obj.Hwindows || Iself {
put(s, s.Name, 'U', s.Value, 0, int(s.Version), nil) put(s, s.Name, 'U', s.Value, 0, int(s.Version), nil)
} }
case SDYNIMPORT: case obj.SDYNIMPORT:
if !s.Reachable { if !s.Reachable {
continue continue
} }
put(s, s.Extname, 'U', 0, 0, int(s.Version), nil) put(s, s.Extname, 'U', 0, 0, int(s.Version), nil)
case STLSBSS: case obj.STLSBSS:
if Linkmode == LinkExternal && HEADTYPE != Hopenbsd { if Linkmode == LinkExternal && HEADTYPE != obj.Hopenbsd {
var type_ int var type_ int
if goos == "android" { if goos == "android" {
type_ = 'B' type_ = 'B'
...@@ -1628,12 +1628,12 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) { ...@@ -1628,12 +1628,12 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
for a = s.Autom; a != nil; a = a.Link { for a = s.Autom; a != nil; a = a.Link {
// Emit a or p according to actual offset, even if label is wrong. // Emit a or p according to actual offset, even if label is wrong.
// This avoids negative offsets, which cannot be encoded. // This avoids negative offsets, which cannot be encoded.
if a.Name != A_AUTO && a.Name != A_PARAM { if a.Name != obj.A_AUTO && a.Name != obj.A_PARAM {
continue continue
} }
// compute offset relative to FP // compute offset relative to FP
if a.Name == A_PARAM { if a.Name == obj.A_PARAM {
off = a.Aoffset off = a.Aoffset
} else { } else {
off = a.Aoffset - int32(Thearch.Ptrsize) off = a.Aoffset - int32(Thearch.Ptrsize)
...@@ -1697,7 +1697,7 @@ func Entryvalue() int64 { ...@@ -1697,7 +1697,7 @@ func Entryvalue() int64 {
if s.Type == 0 { if s.Type == 0 {
return INITTEXT return INITTEXT
} }
if s.Type != STEXT { if s.Type != obj.STEXT {
Diag("entry not text: %s", s.Name) Diag("entry not text: %s", s.Name)
} }
return s.Value return s.Value
...@@ -1712,7 +1712,7 @@ func undefsym(s *LSym) { ...@@ -1712,7 +1712,7 @@ func undefsym(s *LSym) {
if r.Sym == nil { // happens for some external ARM relocs if r.Sym == nil { // happens for some external ARM relocs
continue continue
} }
if r.Sym.Type == Sxxx || r.Sym.Type == SXREF { if r.Sym.Type == obj.Sxxx || r.Sym.Type == obj.SXREF {
Diag("undefined: %s", r.Sym.Name) Diag("undefined: %s", r.Sym.Name)
} }
if !r.Sym.Reachable { if !r.Sym.Reachable {
...@@ -1746,7 +1746,7 @@ func callgraph() { ...@@ -1746,7 +1746,7 @@ func callgraph() {
if r.Sym == nil { if r.Sym == nil {
continue continue
} }
if (r.Type == R_CALL || r.Type == R_CALLARM || r.Type == R_CALLPOWER) && r.Sym.Type == STEXT { if (r.Type == obj.R_CALL || r.Type == obj.R_CALLARM || r.Type == obj.R_CALLPOWER) && r.Sym.Type == obj.STEXT {
fmt.Fprintf(&Bso, "%s calls %s\n", s.Name, r.Sym.Name) fmt.Fprintf(&Bso, "%s calls %s\n", s.Name, r.Sym.Name)
} }
} }
...@@ -1790,7 +1790,7 @@ func checkgo() { ...@@ -1790,7 +1790,7 @@ func checkgo() {
if r.Sym == nil { if r.Sym == nil {
continue continue
} }
if (r.Type == R_CALL || r.Type == R_CALLARM) && r.Sym.Type == STEXT { if (r.Type == obj.R_CALL || r.Type == obj.R_CALLARM) && r.Sym.Type == obj.STEXT {
if r.Sym.Cfunc == 1 { if r.Sym.Cfunc == 1 {
changed = 1 changed = 1
r.Sym.Cfunc = 2 r.Sym.Cfunc = 2
...@@ -1813,7 +1813,7 @@ func checkgo() { ...@@ -1813,7 +1813,7 @@ func checkgo() {
if r.Sym == nil { if r.Sym == nil {
continue continue
} }
if (r.Type == R_CALL || r.Type == R_CALLARM) && r.Sym.Type == STEXT { if (r.Type == obj.R_CALL || r.Type == obj.R_CALLARM) && r.Sym.Type == obj.STEXT {
if s.Cfunc == 0 && r.Sym.Cfunc == 2 && r.Sym.Nosplit == 0 { if s.Cfunc == 0 && r.Sym.Cfunc == 2 && r.Sym.Nosplit == 0 {
fmt.Printf("Go %s calls C %s\n", s.Name, r.Sym.Name) fmt.Printf("Go %s calls C %s\n", s.Name, r.Sym.Name)
} else if s.Cfunc == 2 && s.Nosplit != 0 && r.Sym.Nosplit == 0 { } else if s.Cfunc == 2 && s.Nosplit != 0 && r.Sym.Nosplit == 0 {
......
...@@ -173,73 +173,6 @@ type Pciter struct { ...@@ -173,73 +173,6 @@ type Pciter struct {
done int done int
} }
// LSym.type
const (
Sxxx = iota
STEXT
SELFRXSECT
STYPE
SSTRING
SGOSTRING
SGOFUNC
SRODATA
SFUNCTAB
STYPELINK
SSYMTAB
SPCLNTAB
SELFROSECT
SMACHOPLT
SELFSECT
SMACHO
SMACHOGOT
SWINDOWS
SELFGOT
SNOPTRDATA
SINITARR
SDATA
SBSS
SNOPTRBSS
STLSBSS
SXREF
SMACHOSYMSTR
SMACHOSYMTAB
SMACHOINDIRECTPLT
SMACHOINDIRECTGOT
SFILE
SFILEPATH
SCONST
SDYNIMPORT
SHOSTOBJ
SSUB = 1 << 8
SMASK = SSUB - 1
SHIDDEN = 1 << 9
)
// Reloc.type
const (
R_ADDR = 1 + iota
R_ADDRPOWER
R_ADDRARM64
R_SIZE
R_CALL
R_CALLARM
R_CALLARM64
R_CALLIND
R_CALLPOWER
R_CONST
R_PCREL
R_TLS
R_TLS_LE
R_TLS_IE
R_GOTOFF
R_PLT0
R_PLT1
R_PLT2
R_USEFIELD
R_POWER_TOC
R_GOTPCREL
)
// Reloc.variant // Reloc.variant
const ( const (
RV_NONE = iota RV_NONE = iota
...@@ -251,12 +184,6 @@ const ( ...@@ -251,12 +184,6 @@ const (
RV_TYPE_MASK = RV_CHECK_OVERFLOW - 1 RV_TYPE_MASK = RV_CHECK_OVERFLOW - 1
) )
// Auto.name
const (
A_AUTO = 1 + iota
A_PARAM
)
const ( const (
LINKHASH = 100003 LINKHASH = 100003
) )
...@@ -264,33 +191,11 @@ const ( ...@@ -264,33 +191,11 @@ const (
// Pcdata iterator. // Pcdata iterator.
// for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) } // for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
// symbol version, incremented each time a file is loaded.
// version==1 is reserved for savehist.
const (
HistVersion = 1
)
// Link holds the context for writing object code from a compiler // Link holds the context for writing object code from a compiler
// to be linker input or for reading that input into the linker. // to be linker input or for reading that input into the linker.
// LinkArch is the definition of a single architecture. // LinkArch is the definition of a single architecture.
/* executable header types */
const (
Hunknown = 0 + iota
Hdarwin
Hdragonfly
Helf
Hfreebsd
Hlinux
Hnacl
Hnetbsd
Hopenbsd
Hplan9
Hsolaris
Hwindows
)
const ( const (
LinkAuto = 0 + iota LinkAuto = 0 + iota
LinkInternal LinkInternal
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package ld package ld
import ( import (
"cmd/internal/obj"
"sort" "sort"
"strings" "strings"
) )
...@@ -306,31 +307,31 @@ func domacho() { ...@@ -306,31 +307,31 @@ func domacho() {
// empirically, string table must begin with " \x00". // empirically, string table must begin with " \x00".
s := Linklookup(Ctxt, ".machosymstr", 0) s := Linklookup(Ctxt, ".machosymstr", 0)
s.Type = SMACHOSYMSTR s.Type = obj.SMACHOSYMSTR
s.Reachable = true s.Reachable = true
Adduint8(Ctxt, s, ' ') Adduint8(Ctxt, s, ' ')
Adduint8(Ctxt, s, '\x00') Adduint8(Ctxt, s, '\x00')
s = Linklookup(Ctxt, ".machosymtab", 0) s = Linklookup(Ctxt, ".machosymtab", 0)
s.Type = SMACHOSYMTAB s.Type = obj.SMACHOSYMTAB
s.Reachable = true s.Reachable = true
if Linkmode != LinkExternal { if Linkmode != LinkExternal {
s := Linklookup(Ctxt, ".plt", 0) // will be __symbol_stub s := Linklookup(Ctxt, ".plt", 0) // will be __symbol_stub
s.Type = SMACHOPLT s.Type = obj.SMACHOPLT
s.Reachable = true s.Reachable = true
s = Linklookup(Ctxt, ".got", 0) // will be __nl_symbol_ptr s = Linklookup(Ctxt, ".got", 0) // will be __nl_symbol_ptr
s.Type = SMACHOGOT s.Type = obj.SMACHOGOT
s.Reachable = true s.Reachable = true
s.Align = 4 s.Align = 4
s = Linklookup(Ctxt, ".linkedit.plt", 0) // indirect table for .plt s = Linklookup(Ctxt, ".linkedit.plt", 0) // indirect table for .plt
s.Type = SMACHOINDIRECTPLT s.Type = obj.SMACHOINDIRECTPLT
s.Reachable = true s.Reachable = true
s = Linklookup(Ctxt, ".linkedit.got", 0) // indirect table for .got s = Linklookup(Ctxt, ".linkedit.got", 0) // indirect table for .got
s.Type = SMACHOINDIRECTGOT s.Type = obj.SMACHOINDIRECTGOT
s.Reachable = true s.Reachable = true
} }
} }
...@@ -571,7 +572,7 @@ func Asmbmacho() { ...@@ -571,7 +572,7 @@ func Asmbmacho() {
} }
func symkind(s *LSym) int { func symkind(s *LSym) int {
if s.Type == SDYNIMPORT { if s.Type == obj.SDYNIMPORT {
return SymKindUndef return SymKindUndef
} }
if s.Cgoexport != 0 { if s.Cgoexport != 0 {
...@@ -627,7 +628,7 @@ func (x machoscmp) Less(i, j int) bool { ...@@ -627,7 +628,7 @@ func (x machoscmp) Less(i, j int) bool {
func machogenasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) { func machogenasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
genasmsym(put) genasmsym(put)
for s := Ctxt.Allsym; s != nil; s = s.Allsym { for s := Ctxt.Allsym; s != nil; s = s.Allsym {
if s.Type == SDYNIMPORT || s.Type == SHOSTOBJ { if s.Type == obj.SDYNIMPORT || s.Type == obj.SHOSTOBJ {
if s.Reachable { if s.Reachable {
put(s, "", 'D', 0, 0, 0, nil) put(s, "", 'D', 0, 0, 0, nil)
} }
...@@ -685,7 +686,7 @@ func machosymtab() { ...@@ -685,7 +686,7 @@ func machosymtab() {
Adduint8(Ctxt, symstr, '\x00') Adduint8(Ctxt, symstr, '\x00')
} }
if s.Type == SDYNIMPORT || s.Type == SHOSTOBJ { if s.Type == obj.SDYNIMPORT || s.Type == obj.SHOSTOBJ {
Adduint8(Ctxt, symtab, 0x01) // type N_EXT, external symbol Adduint8(Ctxt, symtab, 0x01) // type N_EXT, external symbol
Adduint8(Ctxt, symtab, 0) // no section Adduint8(Ctxt, symtab, 0) // no section
Adduint16(Ctxt, symtab, 0) // desc Adduint16(Ctxt, symtab, 0) // desc
......
...@@ -6,6 +6,7 @@ package ld ...@@ -6,6 +6,7 @@ package ld
import ( import (
"bytes" "bytes"
"cmd/internal/obj"
"fmt" "fmt"
"log" "log"
"strconv" "strconv"
...@@ -84,8 +85,8 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) { ...@@ -84,8 +85,8 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) {
} }
s := Linklookup(ctxt, name, v) s := Linklookup(ctxt, name, v)
var dup *LSym var dup *LSym
if s.Type != 0 && s.Type != SXREF { if s.Type != 0 && s.Type != obj.SXREF {
if (t == SDATA || t == SBSS || t == SNOPTRBSS) && len(data) == 0 && nreloc == 0 { if (t == obj.SDATA || t == obj.SBSS || t == obj.SNOPTRBSS) && len(data) == 0 && nreloc == 0 {
if s.Size < int64(size) { if s.Size < int64(size) {
s.Size = int64(size) s.Size = int64(size)
} }
...@@ -95,10 +96,10 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) { ...@@ -95,10 +96,10 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) {
return return
} }
if (s.Type == SDATA || s.Type == SBSS || s.Type == SNOPTRBSS) && len(s.P) == 0 && len(s.R) == 0 { if (s.Type == obj.SDATA || s.Type == obj.SBSS || s.Type == obj.SNOPTRBSS) && len(s.P) == 0 && len(s.R) == 0 {
goto overwrite goto overwrite
} }
if s.Type != SBSS && s.Type != SNOPTRBSS && dupok == 0 && s.Dupok == 0 { if s.Type != obj.SBSS && s.Type != obj.SNOPTRBSS && dupok == 0 && s.Dupok == 0 {
log.Fatalf("duplicate symbol %s (types %d and %d) in %s and %s", s.Name, s.Type, t, s.File, pn) log.Fatalf("duplicate symbol %s (types %d and %d) in %s and %s", s.Name, s.Type, t, s.File, pn)
} }
if len(s.P) > 0 { if len(s.P) > 0 {
...@@ -111,13 +112,13 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) { ...@@ -111,13 +112,13 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) {
overwrite: overwrite:
s.File = pkg s.File = pkg
s.Dupok = uint8(dupok) s.Dupok = uint8(dupok)
if t == SXREF { if t == obj.SXREF {
log.Fatalf("bad sxref") log.Fatalf("bad sxref")
} }
if t == 0 { if t == 0 {
log.Fatalf("missing type for %s in %s", name, pn) log.Fatalf("missing type for %s in %s", name, pn)
} }
if t == SBSS && (s.Type == SRODATA || s.Type == SNOPTRBSS) { if t == obj.SBSS && (s.Type == obj.SRODATA || s.Type == obj.SNOPTRBSS) {
t = int(s.Type) t = int(s.Type)
} }
s.Type = int16(t) s.Type = int16(t)
...@@ -156,7 +157,7 @@ overwrite: ...@@ -156,7 +157,7 @@ overwrite:
} }
} }
if s.Type == STEXT { if s.Type == obj.STEXT {
s.Args = int32(rdint(f)) s.Args = int32(rdint(f))
s.Locals = int32(rdint(f)) s.Locals = int32(rdint(f))
s.Nosplit = uint8(rdint(f)) s.Nosplit = uint8(rdint(f))
...@@ -235,7 +236,7 @@ overwrite: ...@@ -235,7 +236,7 @@ overwrite:
fmt.Fprintf(ctxt.Bso, "nosplit ") fmt.Fprintf(ctxt.Bso, "nosplit ")
} }
fmt.Fprintf(ctxt.Bso, "size=%d value=%d", int64(s.Size), int64(s.Value)) fmt.Fprintf(ctxt.Bso, "size=%d value=%d", int64(s.Size), int64(s.Value))
if s.Type == STEXT { if s.Type == obj.STEXT {
fmt.Fprintf(ctxt.Bso, " args=%#x locals=%#x", uint64(s.Args), uint64(s.Locals)) fmt.Fprintf(ctxt.Bso, " args=%#x locals=%#x", uint64(s.Args), uint64(s.Locals))
} }
fmt.Fprintf(ctxt.Bso, "\n") fmt.Fprintf(ctxt.Bso, "\n")
...@@ -326,14 +327,14 @@ func rdsym(ctxt *Link, f *Biobuf, pkg string) *LSym { ...@@ -326,14 +327,14 @@ func rdsym(ctxt *Link, f *Biobuf, pkg string) *LSym {
if strings.HasPrefix(s.Name, "$f32.") { if strings.HasPrefix(s.Name, "$f32.") {
x, _ := strconv.ParseUint(s.Name[5:], 16, 32) x, _ := strconv.ParseUint(s.Name[5:], 16, 32)
i32 := int32(x) i32 := int32(x)
s.Type = SRODATA s.Type = obj.SRODATA
s.Local = true s.Local = true
Adduint32(ctxt, s, uint32(i32)) Adduint32(ctxt, s, uint32(i32))
s.Reachable = false s.Reachable = false
} else if strings.HasPrefix(s.Name, "$f64.") || strings.HasPrefix(s.Name, "$i64.") { } else if strings.HasPrefix(s.Name, "$f64.") || strings.HasPrefix(s.Name, "$i64.") {
x, _ := strconv.ParseUint(s.Name[5:], 16, 64) x, _ := strconv.ParseUint(s.Name[5:], 16, 64)
i64 := int64(x) i64 := int64(x)
s.Type = SRODATA s.Type = obj.SRODATA
s.Local = true s.Local = true
Adduint64(ctxt, s, uint64(i64)) Adduint64(ctxt, s, uint64(i64))
s.Reachable = false s.Reachable = false
......
...@@ -143,10 +143,10 @@ func renumberfiles(ctxt *Link, files []*LSym, d *Pcdata) { ...@@ -143,10 +143,10 @@ func renumberfiles(ctxt *Link, files []*LSym, d *Pcdata) {
// Give files numbers. // Give files numbers.
for i := 0; i < len(files); i++ { for i := 0; i < len(files); i++ {
f = files[i] f = files[i]
if f.Type != SFILEPATH { if f.Type != obj.SFILEPATH {
ctxt.Nhistfile++ ctxt.Nhistfile++
f.Value = int64(ctxt.Nhistfile) f.Value = int64(ctxt.Nhistfile)
f.Type = SFILEPATH f.Type = obj.SFILEPATH
f.Next = ctxt.Filesyms f.Next = ctxt.Filesyms
ctxt.Filesyms = f ctxt.Filesyms = f
} }
...@@ -212,7 +212,7 @@ var pclntabLastFunc *LSym ...@@ -212,7 +212,7 @@ var pclntabLastFunc *LSym
func pclntab() { func pclntab() {
funcdata_bytes := int64(0) funcdata_bytes := int64(0)
ftab := Linklookup(Ctxt, "runtime.pclntab", 0) ftab := Linklookup(Ctxt, "runtime.pclntab", 0)
ftab.Type = SPCLNTAB ftab.Type = obj.SPCLNTAB
ftab.Reachable = true ftab.Reachable = true
// See golang.org/s/go12symtab for the format. Briefly: // See golang.org/s/go12symtab for the format. Briefly:
...@@ -378,7 +378,7 @@ const ( ...@@ -378,7 +378,7 @@ const (
// function for a pc. See src/runtime/symtab.go:findfunc for details. // function for a pc. See src/runtime/symtab.go:findfunc for details.
func findfunctab() { func findfunctab() {
t := Linklookup(Ctxt, "runtime.findfunctab", 0) t := Linklookup(Ctxt, "runtime.findfunctab", 0)
t.Type = SRODATA t.Type = obj.SRODATA
t.Reachable = true t.Reachable = true
t.Local = true t.Local = true
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package ld package ld
import ( import (
"cmd/internal/obj"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"sort" "sort"
...@@ -450,9 +451,9 @@ func Peinit() { ...@@ -450,9 +451,9 @@ func Peinit() {
nextfileoff = int(PEFILEHEADR) nextfileoff = int(PEFILEHEADR)
// some mingw libs depend on this symbol, for example, FindPESectionByName // some mingw libs depend on this symbol, for example, FindPESectionByName
xdefine("__image_base__", SDATA, PEBASE) xdefine("__image_base__", obj.SDATA, PEBASE)
xdefine("_image_base__", SDATA, PEBASE) xdefine("_image_base__", obj.SDATA, PEBASE)
} }
func pewrite() { func pewrite() {
...@@ -487,7 +488,7 @@ func initdynimport() *Dll { ...@@ -487,7 +488,7 @@ func initdynimport() *Dll {
dr = nil dr = nil
var m *Imp var m *Imp
for s := Ctxt.Allsym; s != nil; s = s.Allsym { for s := Ctxt.Allsym; s != nil; s = s.Allsym {
if !s.Reachable || s.Type != SDYNIMPORT { if !s.Reachable || s.Type != obj.SDYNIMPORT {
continue continue
} }
for d = dr; d != nil; d = d.next { for d = dr; d != nil; d = d.next {
...@@ -529,7 +530,7 @@ func initdynimport() *Dll { ...@@ -529,7 +530,7 @@ func initdynimport() *Dll {
// Add real symbol name // Add real symbol name
for d := dr; d != nil; d = d.next { for d := dr; d != nil; d = d.next {
for m = d.ms; m != nil; m = m.next { for m = d.ms; m != nil; m = m.next {
m.s.Type = SDATA m.s.Type = obj.SDATA
Symgrow(Ctxt, m.s, int64(Thearch.Ptrsize)) Symgrow(Ctxt, m.s, int64(Thearch.Ptrsize))
dynName := m.s.Extname dynName := m.s.Extname
// only windows/386 requires stdcall decoration // only windows/386 requires stdcall decoration
...@@ -538,12 +539,12 @@ func initdynimport() *Dll { ...@@ -538,12 +539,12 @@ func initdynimport() *Dll {
} }
dynSym := Linklookup(Ctxt, dynName, 0) dynSym := Linklookup(Ctxt, dynName, 0)
dynSym.Reachable = true dynSym.Reachable = true
dynSym.Type = SHOSTOBJ dynSym.Type = obj.SHOSTOBJ
r := Addrel(m.s) r := Addrel(m.s)
r.Sym = dynSym r.Sym = dynSym
r.Off = 0 r.Off = 0
r.Siz = uint8(Thearch.Ptrsize) r.Siz = uint8(Thearch.Ptrsize)
r.Type = R_ADDR r.Type = obj.R_ADDR
// pre-allocate symtab entries for those symbols // pre-allocate symtab entries for those symbols
dynSym.Dynid = int32(ncoffsym) dynSym.Dynid = int32(ncoffsym)
...@@ -553,10 +554,10 @@ func initdynimport() *Dll { ...@@ -553,10 +554,10 @@ func initdynimport() *Dll {
} else { } else {
dynamic := Linklookup(Ctxt, ".windynamic", 0) dynamic := Linklookup(Ctxt, ".windynamic", 0)
dynamic.Reachable = true dynamic.Reachable = true
dynamic.Type = SWINDOWS dynamic.Type = obj.SWINDOWS
for d := dr; d != nil; d = d.next { for d := dr; d != nil; d = d.next {
for m = d.ms; m != nil; m = m.next { for m = d.ms; m != nil; m = m.next {
m.s.Type = SWINDOWS | SSUB m.s.Type = obj.SWINDOWS | obj.SSUB
m.s.Sub = dynamic.Sub m.s.Sub = dynamic.Sub
dynamic.Sub = m.s dynamic.Sub = m.s
m.s.Value = dynamic.Size m.s.Value = dynamic.Size
...@@ -902,7 +903,7 @@ func dope() { ...@@ -902,7 +903,7 @@ func dope() {
rel := Linklookup(Ctxt, ".rel", 0) rel := Linklookup(Ctxt, ".rel", 0)
rel.Reachable = true rel.Reachable = true
rel.Type = SELFROSECT rel.Type = obj.SELFROSECT
initdynimport() initdynimport()
initdynexport() initdynexport()
...@@ -954,7 +955,7 @@ func addpesym(s *LSym, name string, type_ int, addr int64, size int64, ver int, ...@@ -954,7 +955,7 @@ func addpesym(s *LSym, name string, type_ int, addr int64, size int64, ver int,
if coffsym != nil { if coffsym != nil {
// only windows/386 requires underscore prefix on external symbols // only windows/386 requires underscore prefix on external symbols
if Thearch.Thechar == '8' && Linkmode == LinkExternal && (s.Type == SHOSTOBJ || s.Cgoexport != 0) && s.Name == s.Extname { if Thearch.Thechar == '8' && Linkmode == LinkExternal && (s.Type == obj.SHOSTOBJ || s.Cgoexport != 0) && s.Name == s.Extname {
s.Name = "_" + s.Name s.Name = "_" + s.Name
} }
cs := &coffsym[ncoffsym] cs := &coffsym[ncoffsym]
...@@ -964,7 +965,7 @@ func addpesym(s *LSym, name string, type_ int, addr int64, size int64, ver int, ...@@ -964,7 +965,7 @@ func addpesym(s *LSym, name string, type_ int, addr int64, size int64, ver int,
} }
// Note: although address of runtime.edata (type SDATA) is at the start of .bss section // Note: although address of runtime.edata (type SDATA) is at the start of .bss section
// it still belongs to the .data section, not the .bss section. // it still belongs to the .data section, not the .bss section.
if uint64(s.Value) >= Segdata.Vaddr+Segdata.Filelen && s.Type != SDATA && Linkmode == LinkExternal { if uint64(s.Value) >= Segdata.Vaddr+Segdata.Filelen && s.Type != obj.SDATA && Linkmode == LinkExternal {
cs.value = int64(uint64(s.Value) - Segdata.Vaddr - Segdata.Filelen) cs.value = int64(uint64(s.Value) - Segdata.Vaddr - Segdata.Filelen)
cs.sect = bsssect cs.sect = bsssect
} else if uint64(s.Value) >= Segdata.Vaddr { } else if uint64(s.Value) >= Segdata.Vaddr {
......
...@@ -157,7 +157,7 @@ func Ldmain() { ...@@ -157,7 +157,7 @@ func Ldmain() {
} }
if outfile == "" { if outfile == "" {
if HEADTYPE == Hwindows { if HEADTYPE == obj.Hwindows {
outfile = fmt.Sprintf("%c.out.exe", Thearch.Thechar) outfile = fmt.Sprintf("%c.out.exe", Thearch.Thechar)
} else { } else {
outfile = fmt.Sprintf("%c.out", Thearch.Thechar) outfile = fmt.Sprintf("%c.out", Thearch.Thechar)
...@@ -215,11 +215,11 @@ func Ldmain() { ...@@ -215,11 +215,11 @@ func Ldmain() {
callgraph() callgraph()
doelf() doelf()
if HEADTYPE == Hdarwin { if HEADTYPE == obj.Hdarwin {
domacho() domacho()
} }
dostkcheck() dostkcheck()
if HEADTYPE == Hwindows { if HEADTYPE == obj.Hwindows {
dope() dope()
} }
addexport() addexport()
......
...@@ -47,26 +47,26 @@ var headers = []struct { ...@@ -47,26 +47,26 @@ var headers = []struct {
name string name string
val int val int
}{ }{
{"darwin", Hdarwin}, {"darwin", obj.Hdarwin},
{"dragonfly", Hdragonfly}, {"dragonfly", obj.Hdragonfly},
{"elf", Helf}, {"elf", obj.Helf},
{"freebsd", Hfreebsd}, {"freebsd", obj.Hfreebsd},
{"linux", Hlinux}, {"linux", obj.Hlinux},
{"android", Hlinux}, // must be after "linux" entry or else headstr(Hlinux) == "android" {"android", obj.Hlinux}, // must be after "linux" entry or else headstr(Hlinux) == "android"
{"nacl", Hnacl}, {"nacl", obj.Hnacl},
{"netbsd", Hnetbsd}, {"netbsd", obj.Hnetbsd},
{"openbsd", Hopenbsd}, {"openbsd", obj.Hopenbsd},
{"plan9", Hplan9}, {"plan9", obj.Hplan9},
{"solaris", Hsolaris}, {"solaris", obj.Hsolaris},
{"windows", Hwindows}, {"windows", obj.Hwindows},
{"windowsgui", Hwindows}, {"windowsgui", obj.Hwindows},
} }
func linknew(arch *LinkArch) *Link { func linknew(arch *LinkArch) *Link {
ctxt := new(Link) ctxt := new(Link)
ctxt.Hash = make(map[symVer]*LSym) ctxt.Hash = make(map[symVer]*LSym)
ctxt.Arch = arch ctxt.Arch = arch
ctxt.Version = HistVersion ctxt.Version = obj.HistVersion
ctxt.Goroot = obj.Getgoroot() ctxt.Goroot = obj.Getgoroot()
p := obj.Getgoarch() p := obj.Getgoarch()
...@@ -92,7 +92,7 @@ func linknew(arch *LinkArch) *Link { ...@@ -92,7 +92,7 @@ func linknew(arch *LinkArch) *Link {
default: default:
log.Fatalf("unknown thread-local storage offset for %s", Headstr(ctxt.Headtype)) log.Fatalf("unknown thread-local storage offset for %s", Headstr(ctxt.Headtype))
case Hplan9, Hwindows: case obj.Hplan9, obj.Hwindows:
break break
/* /*
...@@ -100,15 +100,15 @@ func linknew(arch *LinkArch) *Link { ...@@ -100,15 +100,15 @@ func linknew(arch *LinkArch) *Link {
* Translate 0(FS) and 8(FS) into -16(FS) and -8(FS). * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS).
* Known to low-level assembly in package runtime and runtime/cgo. * Known to low-level assembly in package runtime and runtime/cgo.
*/ */
case Hlinux, case obj.Hlinux,
Hfreebsd, obj.Hfreebsd,
Hnetbsd, obj.Hnetbsd,
Hopenbsd, obj.Hopenbsd,
Hdragonfly, obj.Hdragonfly,
Hsolaris: obj.Hsolaris:
ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
case Hnacl: case obj.Hnacl:
switch ctxt.Arch.Thechar { switch ctxt.Arch.Thechar {
default: default:
log.Fatalf("unknown thread-local storage offset for nacl/%s", ctxt.Arch.Name) log.Fatalf("unknown thread-local storage offset for nacl/%s", ctxt.Arch.Name)
...@@ -127,7 +127,7 @@ func linknew(arch *LinkArch) *Link { ...@@ -127,7 +127,7 @@ func linknew(arch *LinkArch) *Link {
* OS X system constants - offset from 0(GS) to our TLS. * OS X system constants - offset from 0(GS) to our TLS.
* Explained in ../../runtime/cgo/gcc_darwin_*.c. * Explained in ../../runtime/cgo/gcc_darwin_*.c.
*/ */
case Hdarwin: case obj.Hdarwin:
switch ctxt.Arch.Thechar { switch ctxt.Arch.Thechar {
default: default:
log.Fatalf("unknown thread-local storage offset for darwin/%s", ctxt.Arch.Name) log.Fatalf("unknown thread-local storage offset for darwin/%s", ctxt.Arch.Name)
......
...@@ -30,7 +30,10 @@ ...@@ -30,7 +30,10 @@
package ld package ld
import "strings" import (
"cmd/internal/obj"
"strings"
)
// Symbol table. // Symbol table.
...@@ -118,7 +121,7 @@ func putelfsym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ *L ...@@ -118,7 +121,7 @@ func putelfsym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ *L
} }
var elfshnum int var elfshnum int
if xo.Type == SDYNIMPORT || xo.Type == SHOSTOBJ { if xo.Type == obj.SDYNIMPORT || xo.Type == obj.SHOSTOBJ {
elfshnum = SHN_UNDEF elfshnum = SHN_UNDEF
} else { } else {
if xo.Sect == nil { if xo.Sect == nil {
...@@ -138,7 +141,7 @@ func putelfsym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ *L ...@@ -138,7 +141,7 @@ func putelfsym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ *L
// maybe one day STB_WEAK. // maybe one day STB_WEAK.
bind := STB_GLOBAL bind := STB_GLOBAL
if ver != 0 || (x.Type&SHIDDEN != 0) || x.Local { if ver != 0 || (x.Type&obj.SHIDDEN != 0) || x.Local {
bind = STB_LOCAL bind = STB_LOCAL
} }
...@@ -160,7 +163,7 @@ func putelfsym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ *L ...@@ -160,7 +163,7 @@ func putelfsym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ *L
addr -= int64(xo.Sect.(*Section).Vaddr) addr -= int64(xo.Sect.(*Section).Vaddr)
} }
other := STV_DEFAULT other := STV_DEFAULT
if x.Type&SHIDDEN != 0 { if x.Type&obj.SHIDDEN != 0 {
other = STV_HIDDEN other = STV_HIDDEN
} }
putelfsyment(off, addr, size, bind<<4|type_&0xf, elfshnum, other) putelfsyment(off, addr, size, bind<<4|type_&0xf, elfshnum, other)
...@@ -215,7 +218,7 @@ func putplan9sym(x *LSym, s string, t int, addr int64, size int64, ver int, go_ ...@@ -215,7 +218,7 @@ func putplan9sym(x *LSym, s string, t int, addr int64, size int64, ver int, go_
'Z', 'Z',
'm': 'm':
l := 4 l := 4
if HEADTYPE == Hplan9 && Thearch.Thechar == '6' && Debug['8'] == 0 { if HEADTYPE == obj.Hplan9 && Thearch.Thechar == '6' && Debug['8'] == 0 {
Lputb(uint32(addr >> 32)) Lputb(uint32(addr >> 32))
l = 8 l = 8
} }
...@@ -297,59 +300,59 @@ func symtab() { ...@@ -297,59 +300,59 @@ func symtab() {
// Define these so that they'll get put into the symbol table. // Define these so that they'll get put into the symbol table.
// data.c:/^address will provide the actual values. // data.c:/^address will provide the actual values.
xdefine("runtime.text", STEXT, 0) xdefine("runtime.text", obj.STEXT, 0)
xdefine("runtime.etext", STEXT, 0) xdefine("runtime.etext", obj.STEXT, 0)
xdefine("runtime.typelink", SRODATA, 0) xdefine("runtime.typelink", obj.SRODATA, 0)
xdefine("runtime.etypelink", SRODATA, 0) xdefine("runtime.etypelink", obj.SRODATA, 0)
xdefine("runtime.rodata", SRODATA, 0) xdefine("runtime.rodata", obj.SRODATA, 0)
xdefine("runtime.erodata", SRODATA, 0) xdefine("runtime.erodata", obj.SRODATA, 0)
xdefine("runtime.noptrdata", SNOPTRDATA, 0) xdefine("runtime.noptrdata", obj.SNOPTRDATA, 0)
xdefine("runtime.enoptrdata", SNOPTRDATA, 0) xdefine("runtime.enoptrdata", obj.SNOPTRDATA, 0)
xdefine("runtime.data", SDATA, 0) xdefine("runtime.data", obj.SDATA, 0)
xdefine("runtime.edata", SDATA, 0) xdefine("runtime.edata", obj.SDATA, 0)
xdefine("runtime.bss", SBSS, 0) xdefine("runtime.bss", obj.SBSS, 0)
xdefine("runtime.ebss", SBSS, 0) xdefine("runtime.ebss", obj.SBSS, 0)
xdefine("runtime.noptrbss", SNOPTRBSS, 0) xdefine("runtime.noptrbss", obj.SNOPTRBSS, 0)
xdefine("runtime.enoptrbss", SNOPTRBSS, 0) xdefine("runtime.enoptrbss", obj.SNOPTRBSS, 0)
xdefine("runtime.end", SBSS, 0) xdefine("runtime.end", obj.SBSS, 0)
xdefine("runtime.epclntab", SRODATA, 0) xdefine("runtime.epclntab", obj.SRODATA, 0)
xdefine("runtime.esymtab", SRODATA, 0) xdefine("runtime.esymtab", obj.SRODATA, 0)
// garbage collection symbols // garbage collection symbols
s := Linklookup(Ctxt, "runtime.gcdata", 0) s := Linklookup(Ctxt, "runtime.gcdata", 0)
s.Type = SRODATA s.Type = obj.SRODATA
s.Size = 0 s.Size = 0
s.Reachable = true s.Reachable = true
xdefine("runtime.egcdata", SRODATA, 0) xdefine("runtime.egcdata", obj.SRODATA, 0)
s = Linklookup(Ctxt, "runtime.gcbss", 0) s = Linklookup(Ctxt, "runtime.gcbss", 0)
s.Type = SRODATA s.Type = obj.SRODATA
s.Size = 0 s.Size = 0
s.Reachable = true s.Reachable = true
xdefine("runtime.egcbss", SRODATA, 0) xdefine("runtime.egcbss", obj.SRODATA, 0)
// pseudo-symbols to mark locations of type, string, and go string data. // pseudo-symbols to mark locations of type, string, and go string data.
var symtype *LSym var symtype *LSym
if !DynlinkingGo() { if !DynlinkingGo() {
s = Linklookup(Ctxt, "type.*", 0) s = Linklookup(Ctxt, "type.*", 0)
s.Type = STYPE s.Type = obj.STYPE
s.Size = 0 s.Size = 0
s.Reachable = true s.Reachable = true
symtype = s symtype = s
} }
s = Linklookup(Ctxt, "go.string.*", 0) s = Linklookup(Ctxt, "go.string.*", 0)
s.Type = SGOSTRING s.Type = obj.SGOSTRING
s.Local = true s.Local = true
s.Size = 0 s.Size = 0
s.Reachable = true s.Reachable = true
symgostring := s symgostring := s
s = Linklookup(Ctxt, "go.func.*", 0) s = Linklookup(Ctxt, "go.func.*", 0)
s.Type = SGOFUNC s.Type = obj.SGOFUNC
s.Local = true s.Local = true
s.Size = 0 s.Size = 0
s.Reachable = true s.Reachable = true
...@@ -359,7 +362,7 @@ func symtab() { ...@@ -359,7 +362,7 @@ func symtab() {
symt = Linklookup(Ctxt, "runtime.symtab", 0) symt = Linklookup(Ctxt, "runtime.symtab", 0)
symt.Local = true symt.Local = true
symt.Type = SSYMTAB symt.Type = obj.SSYMTAB
symt.Size = 0 symt.Size = 0
symt.Reachable = true symt.Reachable = true
...@@ -378,37 +381,37 @@ func symtab() { ...@@ -378,37 +381,37 @@ func symtab() {
s.Local = true s.Local = true
} }
if s.Type != SRODATA { if s.Type != obj.SRODATA {
continue continue
} }
if strings.HasPrefix(s.Name, "type.") && !DynlinkingGo() { if strings.HasPrefix(s.Name, "type.") && !DynlinkingGo() {
s.Type = STYPE s.Type = obj.STYPE
s.Hide = 1 s.Hide = 1
s.Outer = symtype s.Outer = symtype
} }
if strings.HasPrefix(s.Name, "go.typelink.") { if strings.HasPrefix(s.Name, "go.typelink.") {
ntypelinks++ ntypelinks++
s.Type = STYPELINK s.Type = obj.STYPELINK
s.Hide = 1 s.Hide = 1
s.Outer = symtypelink s.Outer = symtypelink
} }
if strings.HasPrefix(s.Name, "go.string.") { if strings.HasPrefix(s.Name, "go.string.") {
s.Type = SGOSTRING s.Type = obj.SGOSTRING
s.Hide = 1 s.Hide = 1
s.Outer = symgostring s.Outer = symgostring
} }
if strings.HasPrefix(s.Name, "go.func.") { if strings.HasPrefix(s.Name, "go.func.") {
s.Type = SGOFUNC s.Type = obj.SGOFUNC
s.Hide = 1 s.Hide = 1
s.Outer = symgofunc s.Outer = symgofunc
} }
if strings.HasPrefix(s.Name, "gcargs.") || strings.HasPrefix(s.Name, "gclocals.") || strings.HasPrefix(s.Name, "gclocals·") { if strings.HasPrefix(s.Name, "gcargs.") || strings.HasPrefix(s.Name, "gclocals.") || strings.HasPrefix(s.Name, "gclocals·") {
s.Type = SGOFUNC s.Type = obj.SGOFUNC
s.Hide = 1 s.Hide = 1
s.Outer = symgofunc s.Outer = symgofunc
s.Align = 4 s.Align = 4
...@@ -421,7 +424,7 @@ func symtab() { ...@@ -421,7 +424,7 @@ func symtab() {
// the definition of moduledata in runtime/symtab.go. // the definition of moduledata in runtime/symtab.go.
// This code uses several global variables that are set by pcln.go:pclntab. // This code uses several global variables that are set by pcln.go:pclntab.
moduledata := Linklookup(Ctxt, "runtime.firstmoduledata", 0) moduledata := Linklookup(Ctxt, "runtime.firstmoduledata", 0)
moduledata.Type = SNOPTRDATA moduledata.Type = obj.SNOPTRDATA
moduledatasize := moduledata.Size moduledatasize := moduledata.Size
moduledata.Size = 0 // truncate symbol back to 0 bytes to reinitialize moduledata.Size = 0 // truncate symbol back to 0 bytes to reinitialize
moduledata.Reachable = true moduledata.Reachable = true
...@@ -466,8 +469,8 @@ func symtab() { ...@@ -466,8 +469,8 @@ func symtab() {
Symgrow(Ctxt, moduledata, moduledatasize) Symgrow(Ctxt, moduledata, moduledatasize)
lastmoduledatap := Linklookup(Ctxt, "runtime.lastmoduledatap", 0) lastmoduledatap := Linklookup(Ctxt, "runtime.lastmoduledatap", 0)
if lastmoduledatap.Type != SDYNIMPORT { if lastmoduledatap.Type != obj.SDYNIMPORT {
lastmoduledatap.Type = SNOPTRDATA lastmoduledatap.Type = obj.SNOPTRDATA
lastmoduledatap.Size = 0 // overwrite existing value lastmoduledatap.Size = 0 // overwrite existing value
Addaddr(Ctxt, lastmoduledatap, moduledata) Addaddr(Ctxt, lastmoduledatap, moduledata)
} }
......
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