Skip to content

Commit 0d65cd6

Browse files
hirochachachaianlancetaylor
authored andcommitted
cmd/internal/obj/x86: don't apply workaround for solaris to darwin
Currently, we have a workaround for solaris that enforce aboslute addressing for external symbols. However, We don't want to use the workaround for darwin. This CL also refactors code a little bit, because the original function name is not appropriate now. Updates #17490 Change-Id: Id21f9cdf33dca6a40647226be49010c2c324ee24 Reviewed-on: https://go-review.googlesource.com/54871 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 78984d3 commit 0d65cd6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/cmd/internal/obj/x86/asm6.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -1712,14 +1712,17 @@ var optab =
17121712

17131713
var opindex [(ALAST + 1) & obj.AMask]*Optab
17141714

1715-
// isextern reports whether s describes an external symbol that must avoid pc-relative addressing.
1715+
// useAbs reports whether s describes a symbol that must avoid pc-relative addressing.
17161716
// This happens on systems like Solaris that call .so functions instead of system calls.
17171717
// It does not seem to be necessary for any other systems. This is probably working
17181718
// around a Solaris-specific bug that should be fixed differently, but we don't know
17191719
// what that bug is. And this does fix it.
1720-
func isextern(s *obj.LSym) bool {
1721-
// All the Solaris dynamic imports from libc.so begin with "libc_".
1722-
return strings.HasPrefix(s.Name, "libc_")
1720+
func useAbs(ctxt *obj.Link, s *obj.LSym) bool {
1721+
if ctxt.Headtype == objabi.Hsolaris {
1722+
// All the Solaris dynamic imports from libc.so begin with "libc_".
1723+
return strings.HasPrefix(s.Name, "libc_")
1724+
}
1725+
return ctxt.Arch.Family == sys.I386 && !ctxt.Flag_shared
17231726
}
17241727

17251728
// single-instruction no-ops of various lengths.
@@ -2299,7 +2302,7 @@ func oclass(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) int {
22992302

23002303
case obj.NAME_EXTERN,
23012304
obj.NAME_STATIC:
2302-
if a.Sym != nil && isextern(a.Sym) || (ctxt.Arch.Family == sys.I386 && !ctxt.Flag_shared) {
2305+
if a.Sym != nil && useAbs(ctxt, a.Sym) {
23032306
return Yi32
23042307
}
23052308
return Yiauto // use pc-relative addressing
@@ -2800,7 +2803,7 @@ func vaddr(ctxt *obj.Link, p *obj.Prog, a *obj.Addr, r *obj.Reloc) int64 {
28002803
if a.Name == obj.NAME_GOTREF {
28012804
r.Siz = 4
28022805
r.Type = objabi.R_GOTPCREL
2803-
} else if isextern(s) || (ctxt.Arch.Family != sys.AMD64 && !ctxt.Flag_shared) {
2806+
} else if useAbs(ctxt, s) {
28042807
r.Siz = 4
28052808
r.Type = objabi.R_ADDR
28062809
} else {
@@ -2883,7 +2886,7 @@ func (asmbuf *AsmBuf) asmandsz(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, a
28832886
case obj.NAME_EXTERN,
28842887
obj.NAME_GOTREF,
28852888
obj.NAME_STATIC:
2886-
if !isextern(a.Sym) && ctxt.Arch.Family == sys.AMD64 {
2889+
if !useAbs(ctxt, a.Sym) && ctxt.Arch.Family == sys.AMD64 {
28872890
goto bad
28882891
}
28892892
if ctxt.Arch.Family == sys.I386 && ctxt.Flag_shared {
@@ -2953,7 +2956,7 @@ func (asmbuf *AsmBuf) asmandsz(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, a
29532956

29542957
asmbuf.rexflag |= regrex[base]&Rxb | rex
29552958
if base == REG_NONE || (REG_CS <= base && base <= REG_GS) || base == REG_TLS {
2956-
if (a.Sym == nil || !isextern(a.Sym)) && base == REG_NONE && (a.Name == obj.NAME_STATIC || a.Name == obj.NAME_EXTERN || a.Name == obj.NAME_GOTREF) || ctxt.Arch.Family != sys.AMD64 {
2959+
if (a.Sym == nil || !useAbs(ctxt, a.Sym)) && base == REG_NONE && (a.Name == obj.NAME_STATIC || a.Name == obj.NAME_EXTERN || a.Name == obj.NAME_GOTREF) || ctxt.Arch.Family != sys.AMD64 {
29572960
if a.Name == obj.NAME_GOTREF && (a.Offset != 0 || a.Index != 0 || a.Scale != 0) {
29582961
ctxt.Diag("%v has offset against gotref", p)
29592962
}

0 commit comments

Comments
 (0)