1
0
mirror of https://github.com/golang/go synced 2024-11-23 09:10:08 -07:00

cmd/link: add AIX operating system

This commit adds AIX operating system to cmd/link package for ppc64
architecture.

Updates: #25893

Change-Id: I349e0a2658c31919b72117b62c4c9935c9af07c0
Reviewed-on: https://go-review.googlesource.com/c/138730
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Clément Chigot 2018-09-28 17:02:16 +02:00 committed by Ian Lance Taylor
parent 6155091042
commit 269e531917
8 changed files with 1315 additions and 3 deletions

View File

@ -314,6 +314,18 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
break
}
// On AIX, if a relocated symbol is in .data, a second relocation
// must be done by the loader, as the section .data will be moved.
// The "default" symbol address is still needed by the loader so
// the current relocation can't be skipped.
// runtime.algarray is different because it will end up in .rodata section
if ctxt.HeadType == objabi.Haix && r.Sym.Sect.Seg == &Segdata && r.Sym.Name != "runtime.algarray" {
// It's not possible to make a loader relocation to a DWARF section.
// FIXME
if s.Sect.Seg != &Segdwarf {
xcoffaddloaderreloc(ctxt, s, r)
}
}
o = Symaddr(r.Sym) + r.Add
@ -606,6 +618,7 @@ func dynrelocsym(ctxt *Link, s *sym.Symbol) {
thearch.Adddynrel(ctxt, s, r)
continue
}
if r.Sym != nil && r.Sym.Type == sym.SDYNIMPORT || r.Type >= 256 {
if r.Sym != nil && !r.Sym.Attr.Reachable() {
Errorf(s, "dynamic relocation to unreachable symbol %s", r.Sym.Name)
@ -1329,6 +1342,14 @@ func (ctxt *Link) dodata() {
gc.AddSym(s)
datsize += s.Size
}
// On AIX, TOC entries must be the last of .data
for _, s := range data[sym.SXCOFFTOC] {
s.Sect = sect
s.Type = sym.SDATA
datsize = aligndatsize(datsize, s)
s.Value = int64(uint64(datsize) - sect.Vaddr)
datsize += s.Size
}
checkdatsize(ctxt, datsize, sym.SDATA)
sect.Length = uint64(datsize) - sect.Vaddr
gc.End(int64(sect.Length))
@ -1688,6 +1709,10 @@ func (ctxt *Link) dodata() {
}
for _, sect := range Segdata.Sections {
sect.Extnum = int16(n)
if ctxt.HeadType == objabi.Haix && (sect.Name == ".noptrdata" || sect.Name == ".bss") {
// On AIX, "noptr" sections are merged with their "ptr" section
continue
}
n++
}
for _, sect := range Segdwarf.Sections {

View File

@ -163,6 +163,10 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
}
havedynamic = 1
}
if ctxt.HeadType == objabi.Haix {
xcoffadddynimpsym(ctxt, s)
}
continue
case "cgo_import_static":
@ -317,7 +321,8 @@ func fieldtrack(ctxt *Link) {
}
func (ctxt *Link) addexport() {
if ctxt.HeadType == objabi.Hdarwin {
// TODO(aix)
if ctxt.HeadType == objabi.Hdarwin || ctxt.HeadType == objabi.Haix {
return
}

View File

@ -39,6 +39,7 @@ import (
"cmd/link/internal/loadelf"
"cmd/link/internal/loadmacho"
"cmd/link/internal/loadpe"
"cmd/link/internal/loadxcoff"
"cmd/link/internal/objfile"
"cmd/link/internal/sym"
"crypto/sha1"
@ -1517,6 +1518,18 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
return ldhostobj(ldpe, ctxt.HeadType, f, pkg, length, pn, file)
}
if c1 == 0x01 && (c2 == 0xD7 || c2 == 0xF7) {
ldxcoff := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
textp, err := loadxcoff.Load(ctxt.Arch, ctxt.Syms, f, pkg, length, pn)
if err != nil {
Errorf(nil, "%v", err)
return
}
ctxt.Textp = append(ctxt.Textp, textp...)
}
return ldhostobj(ldxcoff, ctxt.HeadType, f, pkg, length, pn, file)
}
/* check the header */
line, err := f.ReadString('\n')
if err != nil {
@ -2243,7 +2256,7 @@ func Entryvalue(ctxt *Link) int64 {
if s.Type == 0 {
return *FlagTextAddr
}
if s.Type != sym.STEXT {
if ctxt.HeadType != objabi.Haix && s.Type != sym.STEXT {
Errorf(s, "entry not text")
}
return s.Value

View File

@ -224,6 +224,10 @@ func Main(arch *sys.Arch, theArch Arch) {
ctxt.dope()
ctxt.windynrelocsyms()
}
if ctxt.HeadType == objabi.Haix {
ctxt.doxcoff()
}
ctxt.addexport()
thearch.Gentext(ctxt) // trampolines, call stubs, etc.
ctxt.textbuildid()

View File

@ -66,7 +66,7 @@ func (ctxt *Link) computeTLSOffset() {
default:
log.Fatalf("unknown thread-local storage offset for %v", ctxt.HeadType)
case objabi.Hplan9, objabi.Hwindows, objabi.Hjs:
case objabi.Hplan9, objabi.Hwindows, objabi.Hjs, objabi.Haix:
break
/*

File diff suppressed because it is too large Load Diff

View File

@ -692,6 +692,11 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bo
// Runtime Handling" of "Power Architecture 64-Bit ELF V2 ABI
// Specification".
v := r.Sym.Value - 0x7000
if ctxt.HeadType == objabi.Haix {
// On AIX, the thread pointer points 0x7800 bytes after
// the TLS.
v -= 0x800
}
if int64(int16(v)) != v {
ld.Errorf(s, "TLS offset out of range %d", v)
}
@ -941,6 +946,13 @@ func asmb(ctxt *ld.Link) {
ctxt.Out.SeekSet(int64(ld.Segdwarf.Fileoff))
ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
loadersize := uint64(0)
if ctxt.HeadType == objabi.Haix && ctxt.BuildMode == ld.BuildModeExe {
loadero := uint64(ld.Rnd(int64(ld.Segdwarf.Fileoff+ld.Segdwarf.Filelen), int64(*ld.FlagRound)))
ctxt.Out.SeekSet(int64(loadero))
loadersize = ld.Loaderblk(ctxt, loadero)
}
/* output symbol table */
ld.Symsize = 0
@ -960,6 +972,16 @@ func asmb(ctxt *ld.Link) {
case objabi.Hplan9:
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
case objabi.Haix:
symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
// Add loader size if needed
if ctxt.BuildMode == ld.BuildModeExe {
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
symo += uint32(loadersize)
}
symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
}
ctxt.Out.SeekSet(int64(symo))
@ -988,6 +1010,10 @@ func asmb(ctxt *ld.Link) {
ctxt.Out.Write(sym.P)
ctxt.Out.Flush()
}
case objabi.Haix:
ld.Asmaixsym(ctxt)
ctxt.Out.Flush()
}
}
@ -1013,6 +1039,9 @@ func asmb(ctxt *ld.Link) {
objabi.Hopenbsd,
objabi.Hnacl:
ld.Asmbelf(ctxt, int64(symo))
case objabi.Haix:
ld.Asmbxcoff(ctxt)
}
ctxt.Out.Flush()

View File

@ -121,6 +121,10 @@ func archinit(ctxt *ld.Link) {
if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000
}
case objabi.Haix:
ld.Xcoffinit(ctxt)
}
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {