switch pair {
case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le",
"darwin-amd64", "darwin-386",
- "android-arm", "android-arm64", "android-386":
+ "android-arm", "android-arm64", "android-386",
+ "windows-amd64", "windows-386":
return true
}
return false
"android/amd64", "android/arm", "android/arm64", "android/386":
codegenArg = "-shared"
case "darwin/amd64", "darwin/386":
+ case "windows/amd64", "windows/386":
+ // Do not add usual .exe suffix to the .dll file.
+ cfg.ExeSuffix = ""
default:
base.Fatalf("-buildmode=c-shared not supported on %s\n", platform)
}
name := "a.out"
if p.Internal.ExeName != "" {
name = p.Internal.ExeName
- } else if cfg.Goos == "darwin" && cfg.BuildBuildmode == "c-shared" && p.Internal.Target != "" {
+ } else if (cfg.Goos == "darwin" || cfg.Goos == "windows") && cfg.BuildBuildmode == "c-shared" && p.Internal.Target != "" {
// On OS X, the linker output name gets recorded in the
// shared library's LC_ID_DYLIB load command.
// The code invoking the linker knows to pass only the final
// path element. Arrange that the path element matches what
// we'll install it as; otherwise the library is only loadable as "a.out".
+ // On Windows, DLL file name is recorded in PE file
+ // export section, so do like on OS X.
_, name = filepath.Split(p.Internal.Target)
}
a.Target = a.Objdir + filepath.Join("exe", name) + cfg.ExeSuffix
// (and making the resulting shared library useless),
// run the link in the output directory so that -o can name
// just the final path element.
+ // On Windows, DLL file name is recorded in PE file
+ // export section, so do like on OS X.
dir := "."
- if cfg.Goos == "darwin" && cfg.BuildBuildmode == "c-shared" {
+ if (cfg.Goos == "darwin" || cfg.Goos == "windows") && cfg.BuildBuildmode == "c-shared" {
dir, out = filepath.Split(out)
}
}
if ctxt.Arch == sys.Arch386 {
- if (ctxt.BuildMode == BuildModeCArchive && Iself) || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE || ctxt.DynlinkingGo() {
+ if (ctxt.BuildMode == BuildModeCArchive && Iself) || (ctxt.BuildMode == BuildModeCShared && Headtype != objabi.Hwindows) || ctxt.BuildMode == BuildModePIE || ctxt.DynlinkingGo() {
got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0)
got.Type = sym.SDYNIMPORT
got.Attr |= sym.AttrReachable
if ctxt.UseRelro() {
argv = append(argv, "-Wl,-z,relro")
}
- // Pass -z nodelete to mark the shared library as
- // non-closeable: a dlclose will do nothing.
- argv = append(argv, "-shared", "-Wl,-z,nodelete")
+ argv = append(argv, "-shared")
+ if Headtype != objabi.Hwindows {
+ // Pass -z nodelete to mark the shared library as
+ // non-closeable: a dlclose will do nothing.
+ argv = append(argv, "-Wl,-z,nodelete")
+ }
}
case BuildModeShared:
if ctxt.UseRelro() {