Commit 04642e92 authored by Shenghou Ma's avatar Shenghou Ma Committed by Minux Ma

cmd/internal/ld, cmd/8l: external linking for windows/386

Update #4069: this CL fixes the issue on windows/386.
Signed-off-by: default avatarShenghou Ma <minux@golang.org>
Change-Id: I2d2ea233f976aab3f356f9b508cdd246d5013e2e
Reviewed-on: https://go-review.googlesource.com/7283Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent b6ed943b
......@@ -235,6 +235,11 @@ func adddynrel(s *ld.LSym, r *ld.Reloc) {
r.Type = 256 // ignore during relocsym
return
}
if ld.HEADTYPE == ld.Hwindows && s.Size == PtrSize {
// nothing to do, the relocation will be laid out in pereloc1
return
}
}
ld.Ctxt.Cursym = s
......@@ -332,6 +337,36 @@ func machoreloc1(r *ld.Reloc, sectoff int64) int {
return 0
}
func pereloc1(r *ld.Reloc, sectoff int64) bool {
var v uint32
rs := r.Xsym
if rs.Dynid < 0 {
ld.Diag("reloc %d to non-coff symbol %s type=%d", r.Type, rs.Name, rs.Type)
return false
}
ld.Thearch.Lput(uint32(sectoff))
ld.Thearch.Lput(uint32(rs.Dynid))
switch r.Type {
default:
return false
case ld.R_ADDR:
v = ld.IMAGE_REL_I386_DIR32
case ld.R_CALL,
ld.R_PCREL:
v = ld.IMAGE_REL_I386_REL32
}
ld.Thearch.Wput(uint16(v))
return true
}
func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
if ld.Linkmode == ld.LinkExternal {
return -1
......
......@@ -68,6 +68,7 @@ func linkarchinit() {
ld.Thearch.Elfsetupplt = elfsetupplt
ld.Thearch.Gentext = gentext
ld.Thearch.Machoreloc1 = machoreloc1
ld.Thearch.PEreloc1 = pereloc1
ld.Thearch.Lput = ld.Lputl
ld.Thearch.Wput = ld.Wputl
ld.Thearch.Vput = ld.Vputl
......@@ -99,7 +100,8 @@ func archinit() {
ld.Hfreebsd,
ld.Hlinux,
ld.Hnetbsd,
ld.Hopenbsd:
ld.Hopenbsd,
ld.Hwindows:
break
}
......
......@@ -443,6 +443,8 @@ func relocsym(s *LSym) {
if rs.Type != SHOSTOBJ {
o += Symaddr(rs)
}
} else if HEADTYPE == Hwindows {
// nothing to do
} else {
Diag("unhandled pcrel relocation for %s", headstring)
}
......@@ -497,6 +499,8 @@ func relocsym(s *LSym) {
} else {
o += int64(r.Siz)
}
} else if HEADTYPE == Hwindows {
// nothing to do
} else {
Diag("unhandled pcrel relocation for %s", headstring)
}
......@@ -584,7 +588,7 @@ func reloc() {
}
func dynrelocsym(s *LSym) {
if HEADTYPE == Hwindows {
if HEADTYPE == Hwindows && Linkmode != LinkExternal {
rel := Linklookup(Ctxt, ".rel", 0)
if s == rel {
return
......
......@@ -462,11 +462,6 @@ func loadcgo(file string, pkg string, p string) {
}
if f[0] == "cgo_export_static" || f[0] == "cgo_export_dynamic" {
// TODO: Remove once we know Windows is okay.
if f[0] == "cgo_export_static" && HEADTYPE == Hwindows {
continue
}
if len(f) < 2 || len(f) > 3 {
goto err
}
......
......@@ -99,6 +99,7 @@ type Arch struct {
Elfsetupplt func()
Gentext func()
Machoreloc1 func(*Reloc, int64) int
PEreloc1 func(*Reloc, int64) bool
Lput func(uint32)
Wput func(uint16)
Vput func(uint64)
......@@ -744,6 +745,13 @@ func hostlink() {
if HEADTYPE == Hopenbsd {
argv = append(argv, "-Wl,-nopie")
}
if HEADTYPE == Hwindows {
if headstring == "windowsgui" {
argv = append(argv, "-mwindows")
} else {
argv = append(argv, "-mconsole")
}
}
if Iself && AssumeGoldLinker != 0 /*TypeKind(100016)*/ {
argv = append(argv, "-Wl,--rosegment")
......@@ -844,6 +852,9 @@ func hostlink() {
}
}
}
if HEADTYPE == Hwindows {
argv = append(argv, peimporteddlls()...)
}
if Debug['v'] != 0 {
fmt.Fprintf(&Bso, "host link:")
......@@ -1379,6 +1390,13 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
case SFILE:
put(nil, s.Name, 'f', s.Value, 0, int(s.Version), nil)
continue
case SHOSTOBJ:
if HEADTYPE == Hwindows {
put(s, s.Name, 'U', s.Value, 0, int(s.Version), nil)
}
continue
}
}
......
This diff is collapsed.
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