Skip to content

Commit 7f92dcc

Browse files
committed
cmd/link: add support for openbsd/ppc64
Add linker support for the openbsd/ppc64 port. Updates #56001 Change-Id: I18bc19b4086599996aebfbe68f2e85e1200589ca Reviewed-on: https://go-review.googlesource.com/c/go/+/475619 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Joel Sing <[email protected]> Reviewed-by: Lynn Boger <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Paul Murphy <[email protected]> Reviewed-by: Eric Grosse <[email protected]>
1 parent 4711299 commit 7f92dcc

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

src/cmd/dist/build.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,9 @@ func mustLinkExternal(goos, goarch string, cgoEnabled bool) bool {
589589
}
590590
case "ppc64":
591591
// Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
592-
return true
592+
if goos == "aix" || goos == "linux" {
593+
return true
594+
}
593595
}
594596

595597
switch goos {

src/cmd/link/internal/ld/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func determineLinkMode(ctxt *Link) {
217217
}
218218
case LinkExternal:
219219
switch {
220-
case buildcfg.GOARCH == "ppc64" && buildcfg.GOOS != "aix":
220+
case buildcfg.GOARCH == "ppc64" && buildcfg.GOOS == "linux":
221221
Exitf("external linking not supported for %s/ppc64", buildcfg.GOOS)
222222
}
223223
}

src/cmd/link/internal/ld/elf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func Elfinit(ctxt *Link) {
243243
switch ctxt.Arch.Family {
244244
// 64-bit architectures
245245
case sys.PPC64, sys.S390X:
246-
if ctxt.Arch.ByteOrder == binary.BigEndian {
246+
if ctxt.Arch.ByteOrder == binary.BigEndian && ctxt.HeadType != objabi.Hopenbsd {
247247
ehdr.Flags = 1 /* Version 1 ABI */
248248
} else {
249249
ehdr.Flags = 2 /* Version 2 ABI */

src/cmd/link/internal/ppc64/asm.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,8 @@ func genstubs(ctxt *ld.Link, ldr *loader.Loader) {
270270
for _, s := range ctxt.Textp {
271271
relocs := ldr.Relocs(s)
272272
for i := 0; i < relocs.Count(); i++ {
273-
r := relocs.At(i)
274-
switch r.Type() {
275-
case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_REL24):
273+
switch r := relocs.At(i); r.Type() {
274+
case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_REL24), objabi.R_CALLPOWER:
276275
switch ldr.SymType(r.Sym()) {
277276
case sym.SDYNIMPORT:
278277
// This call goes through the PLT, generate and call through a PLT stub.
@@ -633,7 +632,7 @@ func addelfdynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s lo
633632
su.SetRelocAdd(rIdx, r.Add()+localEoffset)
634633

635634
if targType == sym.SDYNIMPORT {
636-
// Should have been handled in elfsetupplt
635+
// Should have been handled in genstubs
637636
ldr.Errorf(s, "unexpected R_PPC64_REL24 for dyn import")
638637
}
639638

@@ -1575,7 +1574,6 @@ func archrelocvariant(target *ld.Target, ldr *loader.Loader, r loader.Reloc, rv
15751574
var o1 uint32
15761575
if target.IsBigEndian() {
15771576
o1 = binary.BigEndian.Uint32(p[r.Off()-2:])
1578-
15791577
} else {
15801578
o1 = binary.LittleEndian.Uint32(p[r.Off():])
15811579
}

src/cmd/link/internal/ppc64/obj.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func Init() (*sys.Arch, ld.Arch) {
7171
LinuxdynldMusl: musl,
7272

7373
Freebsddynld: "XXX",
74-
Openbsddynld: "XXX",
74+
Openbsddynld: "/usr/libexec/ld.so",
7575
Netbsddynld: "XXX",
7676
Dragonflydynld: "XXX",
7777
Solarisdynld: "XXX",
@@ -100,7 +100,8 @@ func archinit(ctxt *ld.Link) {
100100
*ld.FlagRound = 4096
101101
}
102102

103-
case objabi.Hlinux: /* ppc64 elf */
103+
case objabi.Hlinux, /* ppc64 elf */
104+
objabi.Hopenbsd:
104105
ld.Elfinit(ctxt)
105106
ld.HEADR = ld.ELFRESERVE
106107
if *ld.FlagTextAddr == -1 {

src/internal/platform/supported.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ func MustLinkExternal(goos, goarch string, withCgo bool) bool {
9999
case "ppc64":
100100
// Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
101101
// https://go.dev/issue/8912
102-
return true
102+
if goos == "aix" || goos == "linux" {
103+
return true
104+
}
103105
}
104106

105107
switch goos {

0 commit comments

Comments
 (0)