|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "bufio" |
| 5 | + "bytes" |
4 | 6 | "debug/macho"
|
5 | 7 | "internal/testenv"
|
6 | 8 | "io/ioutil"
|
@@ -315,3 +317,62 @@ func TestMacOSVersion(t *testing.T) {
|
315 | 317 | t.Errorf("no LC_VERSION_MIN_MACOSX load command found")
|
316 | 318 | }
|
317 | 319 | }
|
| 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