Skip to content

Commit

Permalink
cmd: merge branch 'dev.link' into master
Browse files Browse the repository at this point in the history
In the dev.link branch we continued developing the new object
file format support and the linker improvements described in
https://golang.org/s/better-linker . Since the last merge, more
progress has been made to improve the new linker, with
improvements on both linker speed and memory usage.

This is a clean merge.

Change-Id: I38516d6c4b41021bc61c1b9886e701de5fa2b0f1
  • Loading branch information
cherrymui committed May 1, 2020
2 parents c12d702 + 1667b35 commit bed9325
Show file tree
Hide file tree
Showing 28 changed files with 910 additions and 605 deletions.
32 changes: 17 additions & 15 deletions src/cmd/link/internal/amd64/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func makeWritable(s *sym.Symbol) {
}
}

func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loader.Sym, r *loader.Reloc2, rIdx int) bool {
func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loader.Sym, r loader.Reloc2, rIdx int) bool {
targ := r.Sym()
var targType sym.SymKind
if targ != 0 {
Expand Down Expand Up @@ -242,7 +242,7 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load

// Reread the reloc to incorporate any changes in type above.
relocs := ldr.Relocs(s)
*r = relocs.At2(rIdx)
r = relocs.At2(rIdx)

switch r.Type() {
case objabi.R_CALL,
Expand Down Expand Up @@ -393,36 +393,38 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load
return false
}

func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
func elfreloc2(ctxt *ld.Link, ldr *loader.Loader, s loader.Sym, r loader.ExtRelocView, sectoff int64) bool {
ctxt.Out.Write64(uint64(sectoff))

elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
switch r.Type {
xsym := ldr.Syms[r.Xsym]
elfsym := ld.ElfSymForReloc(ctxt, xsym)
siz := r.Siz()
switch r.Type() {
default:
return false
case objabi.R_ADDR:
if r.Siz == 4 {
case objabi.R_ADDR, objabi.R_DWARFSECREF:
if siz == 4 {
ctxt.Out.Write64(uint64(elf.R_X86_64_32) | uint64(elfsym)<<32)
} else if r.Siz == 8 {
} else if siz == 8 {
ctxt.Out.Write64(uint64(elf.R_X86_64_64) | uint64(elfsym)<<32)
} else {
return false
}
case objabi.R_TLS_LE:
if r.Siz == 4 {
if siz == 4 {
ctxt.Out.Write64(uint64(elf.R_X86_64_TPOFF32) | uint64(elfsym)<<32)
} else {
return false
}
case objabi.R_TLS_IE:
if r.Siz == 4 {
if siz == 4 {
ctxt.Out.Write64(uint64(elf.R_X86_64_GOTTPOFF) | uint64(elfsym)<<32)
} else {
return false
}
case objabi.R_CALL:
if r.Siz == 4 {
if r.Xsym.Type == sym.SDYNIMPORT {
if siz == 4 {
if xsym.Type == sym.SDYNIMPORT {
if ctxt.DynlinkingGo() {
ctxt.Out.Write64(uint64(elf.R_X86_64_PLT32) | uint64(elfsym)<<32)
} else {
Expand All @@ -435,8 +437,8 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
return false
}
case objabi.R_PCREL:
if r.Siz == 4 {
if r.Xsym.Type == sym.SDYNIMPORT && r.Xsym.ElfType() == elf.STT_FUNC {
if siz == 4 {
if xsym.Type == sym.SDYNIMPORT && xsym.ElfType() == elf.STT_FUNC {
ctxt.Out.Write64(uint64(elf.R_X86_64_PLT32) | uint64(elfsym)<<32)
} else {
ctxt.Out.Write64(uint64(elf.R_X86_64_PC32) | uint64(elfsym)<<32)
Expand All @@ -445,7 +447,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
return false
}
case objabi.R_GOTPCREL:
if r.Siz == 4 {
if siz == 4 {
ctxt.Out.Write64(uint64(elf.R_X86_64_GOTPCREL) | uint64(elfsym)<<32)
} else {
return false
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/amd64/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Init() (*sys.Arch, ld.Arch) {
Archrelocvariant: archrelocvariant,
Asmb: asmb,
Asmb2: asmb2,
Elfreloc1: elfreloc1,
Elfreloc2: elfreloc2,
Elfsetupplt: elfsetupplt,
Gentext2: gentext2,
Machoreloc1: machoreloc1,
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/link/internal/arm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func braddoff(a int32, b int32) int32 {
return int32((uint32(a))&0xff000000 | 0x00ffffff&uint32(a+b))
}

func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loader.Sym, r *loader.Reloc2, rIdx int) bool {
func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loader.Sym, r loader.Reloc2, rIdx int) bool {

targ := r.Sym()
var targType sym.SymKind
Expand Down Expand Up @@ -216,7 +216,7 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load

// Reread the reloc to incorporate any changes in type above.
relocs := ldr.Relocs(s)
*r = relocs.At2(rIdx)
r = relocs.At2(rIdx)

switch r.Type() {
case objabi.R_CALLARM:
Expand Down Expand Up @@ -256,7 +256,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
switch r.Type {
default:
return false
case objabi.R_ADDR:
case objabi.R_ADDR, objabi.R_DWARFSECREF:
if r.Siz == 4 {
ctxt.Out.Write32(uint32(elf.R_ARM_ABS32) | uint32(elfsym)<<8)
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/link/internal/arm64/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func gentext2(ctxt *ld.Link, ldr *loader.Loader) {
initfunc.AddReloc(rel2)
}

func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loader.Sym, r *loader.Reloc2, rIdx int) bool {
func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loader.Sym, r loader.Reloc2, rIdx int) bool {

targ := r.Sym()
var targType sym.SymKind
Expand Down Expand Up @@ -213,7 +213,7 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load

// Reread the reloc to incorporate any changes in type above.
relocs := ldr.Relocs(s)
*r = relocs.At2(rIdx)
r = relocs.At2(rIdx)

switch r.Type() {
case objabi.R_CALL,
Expand Down Expand Up @@ -332,7 +332,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
switch r.Type {
default:
return false
case objabi.R_ADDR:
case objabi.R_ADDR, objabi.R_DWARFSECREF:
switch r.Siz {
case 4:
ctxt.Out.Write64(uint64(elf.R_AARCH64_ABS32) | uint64(elfsym)<<32)
Expand Down
Loading

0 comments on commit bed9325

Please sign in to comment.