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