mirror of
https://github.com/golang/go
synced 2024-11-05 11:56:12 -07: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:
parent
c7ade964ba
commit
e1c0b751b5
@ -74,9 +74,10 @@ func asmb(ctxt *Link, ldr *loader.Loader) {
|
|||||||
// - writing out the code/data/dwarf Segments
|
// - writing out the code/data/dwarf Segments
|
||||||
// - writing out the architecture specific pieces.
|
// - writing out the architecture specific pieces.
|
||||||
// This function handles the second part.
|
// This function handles the second part.
|
||||||
func asmb2(ctxt *Link) bool {
|
func asmb2(ctxt *Link) {
|
||||||
if ctxt.IsWasm() {
|
if thearch.Asmb2 != nil {
|
||||||
return false
|
thearch.Asmb2(ctxt, ctxt.loader)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Symsize = 0
|
Symsize = 0
|
||||||
@ -84,14 +85,14 @@ func asmb2(ctxt *Link) bool {
|
|||||||
Lcsize = 0
|
Lcsize = 0
|
||||||
|
|
||||||
if ctxt.IsDarwin() {
|
if ctxt.IsDarwin() {
|
||||||
machlink := Domacholink(ctxt)
|
machlink := doMachoLink(ctxt)
|
||||||
if !*FlagS && ctxt.IsExternal() {
|
if !*FlagS && ctxt.IsExternal() {
|
||||||
symo := int64(Segdwarf.Fileoff + uint64(Rnd(int64(Segdwarf.Filelen), int64(*FlagRound))) + uint64(machlink))
|
symo := int64(Segdwarf.Fileoff + uint64(Rnd(int64(Segdwarf.Filelen), int64(*FlagRound))) + uint64(machlink))
|
||||||
ctxt.Out.SeekSet(symo)
|
ctxt.Out.SeekSet(symo)
|
||||||
Machoemitreloc(ctxt)
|
machoEmitReloc(ctxt)
|
||||||
}
|
}
|
||||||
ctxt.Out.SeekSet(0)
|
ctxt.Out.SeekSet(0)
|
||||||
Asmbmacho(ctxt)
|
asmbMacho(ctxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctxt.IsElf() {
|
if ctxt.IsElf() {
|
||||||
@ -100,18 +101,18 @@ func asmb2(ctxt *Link) bool {
|
|||||||
symo = int64(Segdwarf.Fileoff + Segdwarf.Filelen)
|
symo = int64(Segdwarf.Fileoff + Segdwarf.Filelen)
|
||||||
symo = Rnd(symo, int64(*FlagRound))
|
symo = Rnd(symo, int64(*FlagRound))
|
||||||
ctxt.Out.SeekSet(symo)
|
ctxt.Out.SeekSet(symo)
|
||||||
Asmelfsym(ctxt)
|
asmElfSym(ctxt)
|
||||||
ctxt.Out.Write(Elfstrdat)
|
ctxt.Out.Write(Elfstrdat)
|
||||||
if ctxt.IsExternal() {
|
if ctxt.IsExternal() {
|
||||||
Elfemitreloc(ctxt)
|
elfEmitReloc(ctxt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctxt.Out.SeekSet(0)
|
ctxt.Out.SeekSet(0)
|
||||||
Asmbelf(ctxt, symo)
|
asmbElf(ctxt, symo)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctxt.IsWindows() {
|
if ctxt.IsWindows() {
|
||||||
Asmbpe(ctxt)
|
asmbPe(ctxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctxt.IsPlan9() {
|
if ctxt.IsPlan9() {
|
||||||
@ -119,17 +120,17 @@ func asmb2(ctxt *Link) bool {
|
|||||||
*FlagS = true
|
*FlagS = true
|
||||||
symo := int64(Segdata.Fileoff + Segdata.Filelen)
|
symo := int64(Segdata.Fileoff + Segdata.Filelen)
|
||||||
ctxt.Out.SeekSet(symo)
|
ctxt.Out.SeekSet(symo)
|
||||||
Asmplan9sym(ctxt)
|
asmbPlan9Sym(ctxt)
|
||||||
}
|
}
|
||||||
ctxt.Out.SeekSet(0)
|
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() {
|
if ctxt.IsAIX() {
|
||||||
ctxt.Out.SeekSet(0)
|
ctxt.Out.SeekSet(0)
|
||||||
fileoff := uint32(Segdwarf.Fileoff + Segdwarf.Filelen)
|
fileoff := uint32(Segdwarf.Fileoff + Segdwarf.Filelen)
|
||||||
fileoff = uint32(Rnd(int64(fileoff), int64(*FlagRound)))
|
fileoff = uint32(Rnd(int64(fileoff), int64(*FlagRound)))
|
||||||
Asmbxcoff(ctxt, int64(fileoff))
|
asmbXcoff(ctxt, int64(fileoff))
|
||||||
}
|
}
|
||||||
|
|
||||||
if *FlagC {
|
if *FlagC {
|
||||||
@ -140,12 +141,10 @@ func asmb2(ctxt *Link) bool {
|
|||||||
fmt.Printf("lcsize=%d\n", Lcsize)
|
fmt.Printf("lcsize=%d\n", Lcsize)
|
||||||
fmt.Printf("total=%d\n", Segtext.Filelen+Segdata.Length+uint64(Symsize)+uint64(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.
|
// writePlan9Header writes out the plan9 header at the present position in the OutBuf.
|
||||||
func WritePlan9Header(buf *OutBuf, magic uint32, entry int64, is64Bit bool) {
|
func writePlan9Header(buf *OutBuf, magic uint32, entry int64, is64Bit bool) {
|
||||||
if is64Bit {
|
if is64Bit {
|
||||||
magic |= 0x00008000
|
magic |= 0x00008000
|
||||||
}
|
}
|
||||||
|
@ -1398,7 +1398,7 @@ func elfrelocsect(ctxt *Link, sect *sym.Section, syms []loader.Sym) {
|
|||||||
sect.Rellen = uint64(ctxt.Out.Offset()) - sect.Reloff
|
sect.Rellen = uint64(ctxt.Out.Offset()) - sect.Reloff
|
||||||
}
|
}
|
||||||
|
|
||||||
func Elfemitreloc(ctxt *Link) {
|
func elfEmitReloc(ctxt *Link) {
|
||||||
|
|
||||||
for ctxt.Out.Offset()&7 != 0 {
|
for ctxt.Out.Offset()&7 != 0 {
|
||||||
ctxt.Out.Write8(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
|
ldr := ctxt.loader
|
||||||
eh := getElfEhdr()
|
eh := getElfEhdr()
|
||||||
|
@ -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 */
|
/* apple MACH */
|
||||||
va := *FlagTextAddr - int64(HEADR)
|
va := *FlagTextAddr - int64(HEADR)
|
||||||
|
|
||||||
@ -964,7 +964,7 @@ func machodysymtab(ctxt *Link) {
|
|||||||
ml.data[17] = 0 /* nlocrel */
|
ml.data[17] = 0 /* nlocrel */
|
||||||
}
|
}
|
||||||
|
|
||||||
func Domacholink(ctxt *Link) int64 {
|
func doMachoLink(ctxt *Link) int64 {
|
||||||
machosymtab(ctxt)
|
machosymtab(ctxt)
|
||||||
|
|
||||||
ldr := ctxt.loader
|
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
|
sect.Rellen = uint64(ctxt.Out.Offset()) - sect.Reloff
|
||||||
}
|
}
|
||||||
|
|
||||||
func Machoemitreloc(ctxt *Link) {
|
func machoEmitReloc(ctxt *Link) {
|
||||||
for ctxt.Out.Offset()&7 != 0 {
|
for ctxt.Out.Offset()&7 != 0 {
|
||||||
ctxt.Out.Write8(0)
|
ctxt.Out.Write8(0)
|
||||||
}
|
}
|
||||||
|
@ -321,9 +321,7 @@ func Main(arch *sys.Arch, theArch Arch) {
|
|||||||
bench.Start("reloc")
|
bench.Start("reloc")
|
||||||
ctxt.reloc()
|
ctxt.reloc()
|
||||||
bench.Start("Asmb2")
|
bench.Start("Asmb2")
|
||||||
if !asmb2(ctxt) {
|
asmb2(ctxt)
|
||||||
thearch.Asmb2(ctxt, ctxt.loader)
|
|
||||||
}
|
|
||||||
|
|
||||||
bench.Start("Munmap")
|
bench.Start("Munmap")
|
||||||
ctxt.Out.Close() // Close handles Munmapping if necessary.
|
ctxt.Out.Close() // Close handles Munmapping if necessary.
|
||||||
|
@ -1547,7 +1547,7 @@ func addpersrc(ctxt *Link) {
|
|||||||
pefile.dataDirectory[pe.IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = h.virtualSize
|
pefile.dataDirectory[pe.IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = h.virtualSize
|
||||||
}
|
}
|
||||||
|
|
||||||
func Asmbpe(ctxt *Link) {
|
func asmbPe(ctxt *Link) {
|
||||||
switch ctxt.Arch.Family {
|
switch ctxt.Arch.Family {
|
||||||
default:
|
default:
|
||||||
Exitf("unknown PE architecture: %v", ctxt.Arch.Family)
|
Exitf("unknown PE architecture: %v", ctxt.Arch.Family)
|
||||||
|
@ -229,7 +229,7 @@ func genelfsym(ctxt *Link, elfbind int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Asmelfsym(ctxt *Link) {
|
func asmElfSym(ctxt *Link) {
|
||||||
|
|
||||||
// the first symbol entry is reserved
|
// the first symbol entry is reserved
|
||||||
putelfsyment(ctxt.Out, 0, 0, 0, STB_LOCAL<<4|STT_NOTYPE, 0, 0)
|
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
|
Symsize += int32(l) + 1 + int32(len(name)) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func Asmplan9sym(ctxt *Link) {
|
func asmbPlan9Sym(ctxt *Link) {
|
||||||
ldr := ctxt.loader
|
ldr := ctxt.loader
|
||||||
|
|
||||||
// Add special runtime.text and runtime.etext symbols.
|
// Add special runtime.text and runtime.etext symbols.
|
||||||
|
@ -1556,7 +1556,7 @@ func xcoffwrite(ctxt *Link) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate XCOFF assembly file
|
// Generate XCOFF assembly file
|
||||||
func Asmbxcoff(ctxt *Link, fileoff int64) {
|
func asmbXcoff(ctxt *Link, fileoff int64) {
|
||||||
xfile.sectNameToScnum = make(map[string]int16)
|
xfile.sectNameToScnum = make(map[string]int16)
|
||||||
|
|
||||||
// Add sections
|
// Add sections
|
||||||
|
Loading…
Reference in New Issue
Block a user