mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] all: merge branch 'master' into dev.link
Clean merge. Change-Id: If2280b25fedfea9aca8560301cfa54ba4990e47b
This commit is contained in:
commit
cdaeaaca92
78 changed files with 2091 additions and 535 deletions
|
|
@ -1423,6 +1423,7 @@ func (ctxt *Link) hostlink() {
|
|||
}
|
||||
}
|
||||
|
||||
var altLinker string
|
||||
if ctxt.IsELF && ctxt.DynlinkingGo() {
|
||||
// We force all symbol resolution to be done at program startup
|
||||
// because lazy PLT resolution can use large amounts of stack at
|
||||
|
|
@ -1434,6 +1435,11 @@ func (ctxt *Link) hostlink() {
|
|||
// from the beginning of the section (like sym.STYPE).
|
||||
argv = append(argv, "-Wl,-znocopyreloc")
|
||||
|
||||
if objabi.GOOS == "android" {
|
||||
// Use lld to avoid errors from default linker (issue #38838)
|
||||
altLinker = "lld"
|
||||
}
|
||||
|
||||
if ctxt.Arch.InFamily(sys.ARM, sys.ARM64) && objabi.GOOS == "linux" {
|
||||
// On ARM, the GNU linker will generate COPY relocations
|
||||
// even with -znocopyreloc set.
|
||||
|
|
@ -1443,7 +1449,7 @@ func (ctxt *Link) hostlink() {
|
|||
// generating COPY relocations.
|
||||
//
|
||||
// In both cases, switch to gold.
|
||||
argv = append(argv, "-fuse-ld=gold")
|
||||
altLinker = "gold"
|
||||
|
||||
// If gold is not installed, gcc will silently switch
|
||||
// back to ld.bfd. So we parse the version information
|
||||
|
|
@ -1456,10 +1462,9 @@ func (ctxt *Link) hostlink() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ctxt.Arch.Family == sys.ARM64 && objabi.GOOS == "freebsd" {
|
||||
// Switch to ld.bfd on freebsd/arm64.
|
||||
argv = append(argv, "-fuse-ld=bfd")
|
||||
altLinker = "bfd"
|
||||
|
||||
// Provide a useful error if ld.bfd is missing.
|
||||
cmd := exec.Command(*flagExtld, "-fuse-ld=bfd", "-Wl,--version")
|
||||
|
|
@ -1469,6 +1474,9 @@ func (ctxt *Link) hostlink() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if altLinker != "" {
|
||||
argv = append(argv, "-fuse-ld="+altLinker)
|
||||
}
|
||||
|
||||
if ctxt.IsELF && len(buildinfo) > 0 {
|
||||
argv = append(argv, fmt.Sprintf("-Wl,--build-id=0x%x", buildinfo))
|
||||
|
|
@ -1505,7 +1513,7 @@ func (ctxt *Link) hostlink() {
|
|||
}
|
||||
|
||||
const compressDWARF = "-Wl,--compress-debug-sections=zlib-gnu"
|
||||
if ctxt.compressDWARF && linkerFlagSupported(argv[0], compressDWARF) {
|
||||
if ctxt.compressDWARF && linkerFlagSupported(argv[0], altLinker, compressDWARF) {
|
||||
argv = append(argv, compressDWARF)
|
||||
}
|
||||
|
||||
|
|
@ -1595,7 +1603,7 @@ func (ctxt *Link) hostlink() {
|
|||
if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared {
|
||||
// GCC uses -no-pie, clang uses -nopie.
|
||||
for _, nopie := range []string{"-no-pie", "-nopie"} {
|
||||
if linkerFlagSupported(argv[0], nopie) {
|
||||
if linkerFlagSupported(argv[0], altLinker, nopie) {
|
||||
argv = append(argv, nopie)
|
||||
break
|
||||
}
|
||||
|
|
@ -1696,7 +1704,7 @@ func (ctxt *Link) hostlink() {
|
|||
|
||||
var createTrivialCOnce sync.Once
|
||||
|
||||
func linkerFlagSupported(linker, flag string) bool {
|
||||
func linkerFlagSupported(linker, altLinker, flag string) bool {
|
||||
createTrivialCOnce.Do(func() {
|
||||
src := filepath.Join(*flagTmpdir, "trivial.c")
|
||||
if err := ioutil.WriteFile(src, []byte("int main() { return 0; }"), 0666); err != nil {
|
||||
|
|
@ -1756,6 +1764,9 @@ func linkerFlagSupported(linker, flag string) bool {
|
|||
}
|
||||
}
|
||||
|
||||
if altLinker != "" {
|
||||
flags = append(flags, "-fuse-ld="+altLinker)
|
||||
}
|
||||
flags = append(flags, flag, "trivial.c")
|
||||
|
||||
cmd := exec.Command(linker, flags...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue