Commit 269e5319 authored by Clément Chigot's avatar Clément Chigot Committed by Ian Lance Taylor

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: default avatarIan Lance Taylor <iant@golang.org>
parent 61550910
...@@ -314,6 +314,18 @@ func relocsym(ctxt *Link, s *sym.Symbol) { ...@@ -314,6 +314,18 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
break 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 o = Symaddr(r.Sym) + r.Add
...@@ -606,6 +618,7 @@ func dynrelocsym(ctxt *Link, s *sym.Symbol) { ...@@ -606,6 +618,7 @@ func dynrelocsym(ctxt *Link, s *sym.Symbol) {
thearch.Adddynrel(ctxt, s, r) thearch.Adddynrel(ctxt, s, r)
continue continue
} }
if r.Sym != nil && r.Sym.Type == sym.SDYNIMPORT || r.Type >= 256 { if r.Sym != nil && r.Sym.Type == sym.SDYNIMPORT || r.Type >= 256 {
if r.Sym != nil && !r.Sym.Attr.Reachable() { if r.Sym != nil && !r.Sym.Attr.Reachable() {
Errorf(s, "dynamic relocation to unreachable symbol %s", r.Sym.Name) Errorf(s, "dynamic relocation to unreachable symbol %s", r.Sym.Name)
...@@ -1329,6 +1342,14 @@ func (ctxt *Link) dodata() { ...@@ -1329,6 +1342,14 @@ func (ctxt *Link) dodata() {
gc.AddSym(s) gc.AddSym(s)
datsize += s.Size 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) checkdatsize(ctxt, datsize, sym.SDATA)
sect.Length = uint64(datsize) - sect.Vaddr sect.Length = uint64(datsize) - sect.Vaddr
gc.End(int64(sect.Length)) gc.End(int64(sect.Length))
...@@ -1688,6 +1709,10 @@ func (ctxt *Link) dodata() { ...@@ -1688,6 +1709,10 @@ func (ctxt *Link) dodata() {
} }
for _, sect := range Segdata.Sections { for _, sect := range Segdata.Sections {
sect.Extnum = int16(n) 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++ n++
} }
for _, sect := range Segdwarf.Sections { for _, sect := range Segdwarf.Sections {
......
...@@ -163,6 +163,10 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) { ...@@ -163,6 +163,10 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
} }
havedynamic = 1 havedynamic = 1
} }
if ctxt.HeadType == objabi.Haix {
xcoffadddynimpsym(ctxt, s)
}
continue continue
case "cgo_import_static": case "cgo_import_static":
...@@ -317,7 +321,8 @@ func fieldtrack(ctxt *Link) { ...@@ -317,7 +321,8 @@ func fieldtrack(ctxt *Link) {
} }
func (ctxt *Link) addexport() { func (ctxt *Link) addexport() {
if ctxt.HeadType == objabi.Hdarwin { // TODO(aix)
if ctxt.HeadType == objabi.Hdarwin || ctxt.HeadType == objabi.Haix {
return return
} }
......
...@@ -39,6 +39,7 @@ import ( ...@@ -39,6 +39,7 @@ import (
"cmd/link/internal/loadelf" "cmd/link/internal/loadelf"
"cmd/link/internal/loadmacho" "cmd/link/internal/loadmacho"
"cmd/link/internal/loadpe" "cmd/link/internal/loadpe"
"cmd/link/internal/loadxcoff"
"cmd/link/internal/objfile" "cmd/link/internal/objfile"
"cmd/link/internal/sym" "cmd/link/internal/sym"
"crypto/sha1" "crypto/sha1"
...@@ -1517,6 +1518,18 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string, ...@@ -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) 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 */ /* check the header */
line, err := f.ReadString('\n') line, err := f.ReadString('\n')
if err != nil { if err != nil {
...@@ -2243,7 +2256,7 @@ func Entryvalue(ctxt *Link) int64 { ...@@ -2243,7 +2256,7 @@ func Entryvalue(ctxt *Link) int64 {
if s.Type == 0 { if s.Type == 0 {
return *FlagTextAddr return *FlagTextAddr
} }
if s.Type != sym.STEXT { if ctxt.HeadType != objabi.Haix && s.Type != sym.STEXT {
Errorf(s, "entry not text") Errorf(s, "entry not text")
} }
return s.Value return s.Value
......
...@@ -224,6 +224,10 @@ func Main(arch *sys.Arch, theArch Arch) { ...@@ -224,6 +224,10 @@ func Main(arch *sys.Arch, theArch Arch) {
ctxt.dope() ctxt.dope()
ctxt.windynrelocsyms() ctxt.windynrelocsyms()
} }
if ctxt.HeadType == objabi.Haix {
ctxt.doxcoff()
}
ctxt.addexport() ctxt.addexport()
thearch.Gentext(ctxt) // trampolines, call stubs, etc. thearch.Gentext(ctxt) // trampolines, call stubs, etc.
ctxt.textbuildid() ctxt.textbuildid()
......
...@@ -66,7 +66,7 @@ func (ctxt *Link) computeTLSOffset() { ...@@ -66,7 +66,7 @@ func (ctxt *Link) computeTLSOffset() {
default: default:
log.Fatalf("unknown thread-local storage offset for %v", ctxt.HeadType) 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 break
/* /*
......
This diff is collapsed.
...@@ -692,6 +692,11 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bo ...@@ -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 // Runtime Handling" of "Power Architecture 64-Bit ELF V2 ABI
// Specification". // Specification".
v := r.Sym.Value - 0x7000 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 { if int64(int16(v)) != v {
ld.Errorf(s, "TLS offset out of range %d", v) ld.Errorf(s, "TLS offset out of range %d", v)
} }
...@@ -941,6 +946,13 @@ func asmb(ctxt *ld.Link) { ...@@ -941,6 +946,13 @@ func asmb(ctxt *ld.Link) {
ctxt.Out.SeekSet(int64(ld.Segdwarf.Fileoff)) ctxt.Out.SeekSet(int64(ld.Segdwarf.Fileoff))
ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen)) 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 */ /* output symbol table */
ld.Symsize = 0 ld.Symsize = 0
...@@ -960,6 +972,16 @@ func asmb(ctxt *ld.Link) { ...@@ -960,6 +972,16 @@ func asmb(ctxt *ld.Link) {
case objabi.Hplan9: case objabi.Hplan9:
symo = uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen) 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)) ctxt.Out.SeekSet(int64(symo))
...@@ -988,6 +1010,10 @@ func asmb(ctxt *ld.Link) { ...@@ -988,6 +1010,10 @@ func asmb(ctxt *ld.Link) {
ctxt.Out.Write(sym.P) ctxt.Out.Write(sym.P)
ctxt.Out.Flush() ctxt.Out.Flush()
} }
case objabi.Haix:
ld.Asmaixsym(ctxt)
ctxt.Out.Flush()
} }
} }
...@@ -1013,6 +1039,9 @@ func asmb(ctxt *ld.Link) { ...@@ -1013,6 +1039,9 @@ func asmb(ctxt *ld.Link) {
objabi.Hopenbsd, objabi.Hopenbsd,
objabi.Hnacl: objabi.Hnacl:
ld.Asmbelf(ctxt, int64(symo)) ld.Asmbelf(ctxt, int64(symo))
case objabi.Haix:
ld.Asmbxcoff(ctxt)
} }
ctxt.Out.Flush() ctxt.Out.Flush()
......
...@@ -121,6 +121,10 @@ func archinit(ctxt *ld.Link) { ...@@ -121,6 +121,10 @@ func archinit(ctxt *ld.Link) {
if *ld.FlagRound == -1 { if *ld.FlagRound == -1 {
*ld.FlagRound = 0x10000 *ld.FlagRound = 0x10000
} }
case objabi.Haix:
ld.Xcoffinit(ctxt)
} }
if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 { if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
......
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