Skip to content

Commit

Permalink
cmd/link: add support for openbsd/ppc64
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
4a6f656c committed Aug 23, 2023
1 parent 4711299 commit 7f92dcc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@ func mustLinkExternal(goos, goarch string, cgoEnabled bool) bool {
}
case "ppc64":
// Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
return true
if goos == "aix" || goos == "linux" {
return true
}
}

switch goos {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/ld/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func determineLinkMode(ctxt *Link) {
}
case LinkExternal:
switch {
case buildcfg.GOARCH == "ppc64" && buildcfg.GOOS != "aix":
case buildcfg.GOARCH == "ppc64" && buildcfg.GOOS == "linux":
Exitf("external linking not supported for %s/ppc64", buildcfg.GOOS)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/ld/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func Elfinit(ctxt *Link) {
switch ctxt.Arch.Family {
// 64-bit architectures
case sys.PPC64, sys.S390X:
if ctxt.Arch.ByteOrder == binary.BigEndian {
if ctxt.Arch.ByteOrder == binary.BigEndian && ctxt.HeadType != objabi.Hopenbsd {
ehdr.Flags = 1 /* Version 1 ABI */
} else {
ehdr.Flags = 2 /* Version 2 ABI */
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/link/internal/ppc64/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,8 @@ func genstubs(ctxt *ld.Link, ldr *loader.Loader) {
for _, s := range ctxt.Textp {
relocs := ldr.Relocs(s)
for i := 0; i < relocs.Count(); i++ {
r := relocs.At(i)
switch r.Type() {
case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_REL24):
switch r := relocs.At(i); r.Type() {
case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_REL24), objabi.R_CALLPOWER:
switch ldr.SymType(r.Sym()) {
case sym.SDYNIMPORT:
// This call goes through the PLT, generate and call through a PLT stub.
Expand Down Expand Up @@ -633,7 +632,7 @@ func addelfdynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s lo
su.SetRelocAdd(rIdx, r.Add()+localEoffset)

if targType == sym.SDYNIMPORT {
// Should have been handled in elfsetupplt
// Should have been handled in genstubs
ldr.Errorf(s, "unexpected R_PPC64_REL24 for dyn import")
}

Expand Down Expand Up @@ -1575,7 +1574,6 @@ func archrelocvariant(target *ld.Target, ldr *loader.Loader, r loader.Reloc, rv
var o1 uint32
if target.IsBigEndian() {
o1 = binary.BigEndian.Uint32(p[r.Off()-2:])

} else {
o1 = binary.LittleEndian.Uint32(p[r.Off():])
}
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/link/internal/ppc64/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Init() (*sys.Arch, ld.Arch) {
LinuxdynldMusl: musl,

Freebsddynld: "XXX",
Openbsddynld: "XXX",
Openbsddynld: "/usr/libexec/ld.so",
Netbsddynld: "XXX",
Dragonflydynld: "XXX",
Solarisdynld: "XXX",
Expand Down Expand Up @@ -100,7 +100,8 @@ func archinit(ctxt *ld.Link) {
*ld.FlagRound = 4096
}

case objabi.Hlinux: /* ppc64 elf */
case objabi.Hlinux, /* ppc64 elf */
objabi.Hopenbsd:
ld.Elfinit(ctxt)
ld.HEADR = ld.ELFRESERVE
if *ld.FlagTextAddr == -1 {
Expand Down
4 changes: 3 additions & 1 deletion src/internal/platform/supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func MustLinkExternal(goos, goarch string, withCgo bool) bool {
case "ppc64":
// Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
// https://go.dev/issue/8912
return true
if goos == "aix" || goos == "linux" {
return true
}
}

switch goos {
Expand Down

0 comments on commit 7f92dcc

Please sign in to comment.