1
0
mirror of https://github.com/golang/go synced 2024-09-30 17:28:32 -06:00

[dev.link] cmd/link: change asmb2 api and rescope some functions

Change-Id: I49916b4740316a7042566e389759b70d7b1fa037
Reviewed-on: https://go-review.googlesource.com/c/go/+/234895
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Jeremy Faller 2020-05-21 21:19:07 -04:00
parent c7ade964ba
commit e1c0b751b5
7 changed files with 26 additions and 29 deletions

View File

@ -74,9 +74,10 @@ func asmb(ctxt *Link, ldr *loader.Loader) {
// - writing out the code/data/dwarf Segments
// - writing out the architecture specific pieces.
// This function handles the second part.
func asmb2(ctxt *Link) bool {
if ctxt.IsWasm() {
return false
func asmb2(ctxt *Link) {
if thearch.Asmb2 != nil {
thearch.Asmb2(ctxt, ctxt.loader)
return
}
Symsize = 0
@ -84,14 +85,14 @@ func asmb2(ctxt *Link) bool {
Lcsize = 0
if ctxt.IsDarwin() {
machlink := Domacholink(ctxt)
machlink := doMachoLink(ctxt)
if !*FlagS && ctxt.IsExternal() {
symo := int64(Segdwarf.Fileoff + uint64(Rnd(int64(Segdwarf.Filelen), int64(*FlagRound))) + uint64(machlink))
ctxt.Out.SeekSet(symo)
Machoemitreloc(ctxt)
machoEmitReloc(ctxt)
}
ctxt.Out.SeekSet(0)
Asmbmacho(ctxt)
asmbMacho(ctxt)
}
if ctxt.IsElf() {
@ -100,18 +101,18 @@ func asmb2(ctxt *Link) bool {
symo = int64(Segdwarf.Fileoff + Segdwarf.Filelen)
symo = Rnd(symo, int64(*FlagRound))
ctxt.Out.SeekSet(symo)
Asmelfsym(ctxt)
asmElfSym(ctxt)
ctxt.Out.Write(Elfstrdat)
if ctxt.IsExternal() {
Elfemitreloc(ctxt)
elfEmitReloc(ctxt)
}
}
ctxt.Out.SeekSet(0)
Asmbelf(ctxt, symo)
asmbElf(ctxt, symo)
}
if ctxt.IsWindows() {
Asmbpe(ctxt)
asmbPe(ctxt)
}
if ctxt.IsPlan9() {
@ -119,17 +120,17 @@ func asmb2(ctxt *Link) bool {
*FlagS = true
symo := int64(Segdata.Fileoff + Segdata.Filelen)
ctxt.Out.SeekSet(symo)
Asmplan9sym(ctxt)
asmbPlan9Sym(ctxt)
}
ctxt.Out.SeekSet(0)
WritePlan9Header(ctxt.Out, thearch.Plan9Magic, Entryvalue(ctxt), thearch.Plan9_64Bit)
writePlan9Header(ctxt.Out, thearch.Plan9Magic, Entryvalue(ctxt), thearch.Plan9_64Bit)
}
if ctxt.IsAIX() {
ctxt.Out.SeekSet(0)
fileoff := uint32(Segdwarf.Fileoff + Segdwarf.Filelen)
fileoff = uint32(Rnd(int64(fileoff), int64(*FlagRound)))
Asmbxcoff(ctxt, int64(fileoff))
asmbXcoff(ctxt, int64(fileoff))
}
if *FlagC {
@ -140,12 +141,10 @@ func asmb2(ctxt *Link) bool {
fmt.Printf("lcsize=%d\n", Lcsize)
fmt.Printf("total=%d\n", Segtext.Filelen+Segdata.Length+uint64(Symsize)+uint64(Lcsize))
}
return true
}
// WritePlan9Header writes out the plan9 header at the present position in the OutBuf.
func WritePlan9Header(buf *OutBuf, magic uint32, entry int64, is64Bit bool) {
// writePlan9Header writes out the plan9 header at the present position in the OutBuf.
func writePlan9Header(buf *OutBuf, magic uint32, entry int64, is64Bit bool) {
if is64Bit {
magic |= 0x00008000
}

View File

@ -1398,7 +1398,7 @@ func elfrelocsect(ctxt *Link, sect *sym.Section, syms []loader.Sym) {
sect.Rellen = uint64(ctxt.Out.Offset()) - sect.Reloff
}
func Elfemitreloc(ctxt *Link) {
func elfEmitReloc(ctxt *Link) {
for ctxt.Out.Offset()&7 != 0 {
ctxt.Out.Write8(0)
@ -1780,7 +1780,7 @@ func Asmbelfsetup() {
}
}
func Asmbelf(ctxt *Link, symo int64) {
func asmbElf(ctxt *Link, symo int64) {
ldr := ctxt.loader
eh := getElfEhdr()

View File

@ -574,7 +574,7 @@ func machoshbits(ctxt *Link, mseg *MachoSeg, sect *sym.Section, segname string)
}
}
func Asmbmacho(ctxt *Link) {
func asmbMacho(ctxt *Link) {
/* apple MACH */
va := *FlagTextAddr - int64(HEADR)
@ -964,7 +964,7 @@ func machodysymtab(ctxt *Link) {
ml.data[17] = 0 /* nlocrel */
}
func Domacholink(ctxt *Link) int64 {
func doMachoLink(ctxt *Link) int64 {
machosymtab(ctxt)
ldr := ctxt.loader
@ -1056,7 +1056,7 @@ func machorelocsect(ctxt *Link, ldr *loader.Loader, sect *sym.Section, syms []lo
sect.Rellen = uint64(ctxt.Out.Offset()) - sect.Reloff
}
func Machoemitreloc(ctxt *Link) {
func machoEmitReloc(ctxt *Link) {
for ctxt.Out.Offset()&7 != 0 {
ctxt.Out.Write8(0)
}

View File

@ -321,9 +321,7 @@ func Main(arch *sys.Arch, theArch Arch) {
bench.Start("reloc")
ctxt.reloc()
bench.Start("Asmb2")
if !asmb2(ctxt) {
thearch.Asmb2(ctxt, ctxt.loader)
}
asmb2(ctxt)
bench.Start("Munmap")
ctxt.Out.Close() // Close handles Munmapping if necessary.

View File

@ -1547,7 +1547,7 @@ func addpersrc(ctxt *Link) {
pefile.dataDirectory[pe.IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = h.virtualSize
}
func Asmbpe(ctxt *Link) {
func asmbPe(ctxt *Link) {
switch ctxt.Arch.Family {
default:
Exitf("unknown PE architecture: %v", ctxt.Arch.Family)

View File

@ -229,7 +229,7 @@ func genelfsym(ctxt *Link, elfbind int) {
}
}
func Asmelfsym(ctxt *Link) {
func asmElfSym(ctxt *Link) {
// the first symbol entry is reserved
putelfsyment(ctxt.Out, 0, 0, 0, STB_LOCAL<<4|STT_NOTYPE, 0, 0)
@ -274,7 +274,7 @@ func putplan9sym(ctxt *Link, ldr *loader.Loader, s loader.Sym, char SymbolType)
Symsize += int32(l) + 1 + int32(len(name)) + 1
}
func Asmplan9sym(ctxt *Link) {
func asmbPlan9Sym(ctxt *Link) {
ldr := ctxt.loader
// Add special runtime.text and runtime.etext symbols.

View File

@ -1556,7 +1556,7 @@ func xcoffwrite(ctxt *Link) {
}
// Generate XCOFF assembly file
func Asmbxcoff(ctxt *Link, fileoff int64) {
func asmbXcoff(ctxt *Link, fileoff int64) {
xfile.sectNameToScnum = make(map[string]int16)
// Add sections