Skip to content

Commit e7ce862

Browse files
committed
cmd/compile: fix spurious R_TLE_LE reloc on android/386
When compiling for GOARCH=386 GOOS=android, the compiler was attaching R_TLS_LE relocations inappropriately -- as of Go 1.13 the TLS access recipe for Android refers to a runtime symbol and no longer needs this type of relocation (which was causing a crash when the linker tried to process it). Updates #29674. Fixes #34788. Change-Id: Ida01875011b524586597b1f7e273aa14e11815d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/200337 Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Elias Naur <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent a0c1e8d commit e7ce862

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3468,7 +3468,7 @@ func (ab *AsmBuf) asmandsz(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, a *obj
34683468
}
34693469

34703470
if REG_AX <= base && base <= REG_R15 {
3471-
if a.Index == REG_TLS && !ctxt.Flag_shared {
3471+
if a.Index == REG_TLS && !ctxt.Flag_shared && !isAndroid {
34723472
rel = obj.Reloc{}
34733473
rel.Type = objabi.R_TLS_LE
34743474
rel.Siz = 4

src/cmd/link/link_test.go

+61
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"bufio"
5+
"bytes"
46
"debug/macho"
57
"internal/testenv"
68
"io/ioutil"
@@ -315,3 +317,62 @@ func TestMacOSVersion(t *testing.T) {
315317
t.Errorf("no LC_VERSION_MIN_MACOSX load command found")
316318
}
317319
}
320+
321+
const Issue34788src = `
322+
323+
package blah
324+
325+
func Blah(i int) int {
326+
a := [...]int{1, 2, 3, 4, 5, 6, 7, 8}
327+
return a[i&7]
328+
}
329+
`
330+
331+
func TestIssue34788Android386TLSSequence(t *testing.T) {
332+
testenv.MustHaveGoBuild(t)
333+
334+
// This is a cross-compilation test, so it doesn't make
335+
// sense to run it on every GOOS/GOARCH combination. Limit
336+
// the test to amd64 + darwin/linux.
337+
if runtime.GOARCH != "amd64" ||
338+
(runtime.GOOS != "darwin" && runtime.GOOS != "linux") {
339+
t.Skip("skipping on non-{linux,darwin}/amd64 platform")
340+
}
341+
342+
tmpdir, err := ioutil.TempDir("", "TestIssue34788Android386TLSSequence")
343+
if err != nil {
344+
t.Fatal(err)
345+
}
346+
defer os.RemoveAll(tmpdir)
347+
348+
src := filepath.Join(tmpdir, "blah.go")
349+
err = ioutil.WriteFile(src, []byte(Issue34788src), 0666)
350+
if err != nil {
351+
t.Fatal(err)
352+
}
353+
354+
obj := filepath.Join(tmpdir, "blah.o")
355+
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", obj, src)
356+
cmd.Env = append(os.Environ(), "GOARCH=386", "GOOS=android")
357+
if out, err := cmd.CombinedOutput(); err != nil {
358+
if err != nil {
359+
t.Fatalf("failed to compile blah.go: %v, output: %s\n", err, out)
360+
}
361+
}
362+
363+
// Run objdump on the resulting object.
364+
cmd = exec.Command(testenv.GoToolPath(t), "tool", "objdump", obj)
365+
out, oerr := cmd.CombinedOutput()
366+
if oerr != nil {
367+
t.Fatalf("failed to objdump blah.o: %v, output: %s\n", oerr, out)
368+
}
369+
370+
// Sift through the output; we should not be seeing any R_TLS_LE relocs.
371+
scanner := bufio.NewScanner(bytes.NewReader(out))
372+
for scanner.Scan() {
373+
line := scanner.Text()
374+
if strings.Contains(line, "R_TLS_LE") {
375+
t.Errorf("objdump output contains unexpected R_TLS_LE reloc: %s", line)
376+
}
377+
}
378+
}

0 commit comments

Comments
 (0)