Repository: go
Issue: build: hardcoded gcc command lines do not allow using TDM64 gcc on 32-bit Windows
Labels: OS-Windows

TDM64 is bi-arch gcc distribution with unusual configuration : 32-bit compiler produces 64-bit object files / executables by default, -m32 is required for 32-bit compilation.
See http://tdm-gcc.tdragon.net/quirks for details.

There are few places in Go source tree where C compiler name and required switches ( in particular -m32/-m64 ) are not obtained from environment variables or by running go env :
- on tip in src/runtime/syscall_windows_test.go
  - initialization of cbDLLs variable
  - C compiler run in function TestReturnAfterStackGrowInCallback
  - test for C compiler availability in TestStdcallAndCDeclCallbacks and TestReturnAfterStackGrowInCallback
- on 1.4.2
  - in src/make.bat
  - in src/runtime/syscall_windows_test.go : initialization of cbDLLs variable
  - in misc/cgo/testso/test.bat

As a result you simply can't build 1.4.2 using TDM64 on 32-bit Windows : compiled dist.exe is 64-bit.

On tip runtime test fails because of 64-bit test.dll :

```
--- FAIL: TestStdcallAndCDeclCallbacks (1.18s)
panic: Failed to load D:\opt\usr\src\go\tmp\TestCDeclCallback075906618\test.dll: %1 is not a valid Win32 application. [recovered]
    panic: Failed to load D:\opt\usr\src\go\tmp\TestCDeclCallback075906618\test.dll: %1 is not a valid Win32 application.

goroutine 103859 [running]:
testing.tRunner.func1(0x10d774a0)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:449 +0x131
syscall.MustLoadDLL(0x111c9100, 0x39, 0x1120c8d0)
    D:/opt/usr/src/go/jtip/src/syscall/dll_windows.go:62 +0x64
runtime_test.(*cbTest).run(0x10dbbf04, 0x10d774a0, 0x111c9100, 0x39)
    D:/opt/usr/src/go/jtip/src/runtime/syscall_windows_test.go:399 +0x2d
runtime_test.TestStdcallAndCDeclCallbacks(0x10d774a0)
    D:/opt/usr/src/go/jtip/src/runtime/syscall_windows_test.go:451 +0x406
testing.tRunner(0x10d774a0, 0x711084)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:455 +0x8f
created by testing.RunTests
    D:/opt/usr/src/go/jtip/src/testing/testing.go:560 +0x6e9

goroutine 1 [chan receive]:
testing.RunTests(0x657f3c, 0x7108e0, 0xaa, 0xaa, 0x59a401)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:561 +0x71b
testing.(*M).Run(0x10db9f7c, 0x10d27fa0)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:493 +0x68
main.main()
    runtime/_test/_testmain.go:880 +0x100

goroutine 102820 [chan receive]:
testing.(*T).Parallel(0x10d77b00)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:421 +0x65
runtime_test.TestStackGrowth(0x10d77b00)
    D:/opt/usr/src/go/jtip/src/runtime/stack_test.go:74 +0x25
testing.tRunner(0x10d77b00, 0x710f04)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:455 +0x8f
created by testing.RunTests
    D:/opt/usr/src/go/jtip/src/testing/testing.go:560 +0x6e9

goroutine 102821 [chan receive]:
testing.RunTests.func1(0x10d28380, 0x10d77b00)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:564 +0x3e
created by testing.RunTests
    D:/opt/usr/src/go/jtip/src/testing/testing.go:565 +0x765

goroutine 102823 [chan receive]:
testing.RunTests.func1(0x10d28380, 0x10d77b60)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:564 +0x3e
created by testing.RunTests
    D:/opt/usr/src/go/jtip/src/testing/testing.go:565 +0x765

goroutine 102822 [chan receive]:
testing.(*T).Parallel(0x10d77b60)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:421 +0x65
runtime_test.TestStackGrowthCallback(0x10d77b60)
    D:/opt/usr/src/go/jtip/src/runtime/stack_test.go:157 +0x25
testing.tRunner(0x10d77b60, 0x710f10)
    D:/opt/usr/src/go/jtip/src/testing/testing.go:455 +0x8f
created by testing.RunTests
    D:/opt/usr/src/go/jtip/src/testing/testing.go:560 +0x6e9
```