Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: link error when building net/http on macOS #38338

Closed
nicolas42 opened this issue Apr 9, 2020 · 4 comments
Closed

cmd/go: link error when building net/http on macOS #38338

nicolas42 opened this issue Apr 9, 2020 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@nicolas42
Copy link

What version of Go are you using (go version)?

$ go version

go version go1.14.2 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

macos 10.13.6

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nick2/Library/Caches/go-build"
GOENV="/Users/nick2/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/nick2/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="/Users/nick2/opt/miniconda3/bin/x86_64-apple-darwin13.4.0-ar"
CC="x86_64-apple-darwin13.4.0-clang"
CXX="x86_64-apple-darwin13.4.0-clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dm/2w2btgwj4f38934mhkm7w4700000gp/T/go-build530020094=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Ran this very simple script which uses the net/http package

package main

import (
"flag"
"log"
"net/http"
)

func main() {
port := flag.String("p", "8080", "port to serve on")
directory := flag.String("d", ".", "the directory of static file to host")
flag.Parse()

http.Handle("/", http.FileServer(http.Dir(*directory)))

log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))

}

What did you expect to see?

Serving on HTTP port 8080

What did you see instead?

runtime/cgo

ld: warning: ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libpthread.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libpthread.tbdignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd

Undefined symbols for architecture x86_64:
"___stack_chk_fail", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"___stack_chk_guard", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"___stderrp", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
_x_cgo_thread_start in _x008.o
"_abort", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
_x_cgo_thread_start in _x008.o
"_fprintf", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
"_free", referenced from:
_threadentry in _x004.o
"_fwrite", referenced from:
_x_cgo_thread_start in _x008.o
"_malloc", referenced from:
_x_cgo_thread_start in _x008.o
"_nanosleep", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
"_pthread_attr_destroy", referenced from:
_x_cgo_init in _x004.o
"_pthread_attr_getstacksize", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"_pthread_attr_init", referenced from:
_x_cgo_init in _x004.o
__cgo_sys_thread_start in _x004.o
"_pthread_cond_broadcast", referenced from:
_x_cgo_notify_runtime_init_done in _x005.o
"_pthread_cond_wait", referenced from:
__cgo_wait_runtime_init_done in _x005.o
"_pthread_create", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
(maybe you meant: __cgo_try_pthread_create)
"_pthread_detach", referenced from:
_x_cgo_sys_thread_create in _x005.o
__cgo_try_pthread_create in _x005.o
"_pthread_mutex_lock", referenced from:
__cgo_wait_runtime_init_done in _x005.o
_x_cgo_notify_runtime_init_done in _x005.o
_x_cgo_set_context_function in _x005.o
__cgo_get_context_function in _x005.o
"_pthread_mutex_unlock", referenced from:
__cgo_wait_runtime_init_done in _x005.o
_x_cgo_notify_runtime_init_done in _x005.o
_x_cgo_set_context_function in _x005.o
__cgo_get_context_function in _x005.o
"_pthread_sigmask", referenced from:
__cgo_sys_thread_start in _x004.o
"_setenv", referenced from:
_x_cgo_setenv in _x006.o
(maybe you meant: _x_cgo_setenv)
"_strerror", referenced from:
__cgo_sys_thread_start in _x004.o
_x_cgo_sys_thread_create in _x005.o
"_unsetenv", referenced from:
_x_cgo_unsetenv in _x006.o
(maybe you meant: _x_cgo_unsetenv)
ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

=============================

It works if I disable CGO in the terminal.

CGO_ENABLED=0 go run serve.go

I'm confused because I don't use cgo in any of the code as far as I can tell.

@bcmills
Copy link
Contributor

bcmills commented Apr 10, 2020

These sorts of failures on macOS typically indicate a corrupted or otherwise-broken C toolchain, typically something involving Anaconda

I note the following in your go env output, which indeed suggests a broken Anaconda toolchain:

AR="/Users/nick2/opt/miniconda3/bin/x86_64-apple-darwin13.4.0-ar"
CC="x86_64-apple-darwin13.4.0-clang"
CXX="x86_64-apple-darwin13.4.0-clang++"

What happens if you uninstall miniconda3 and/or reinstall the default macOS clang toolchain?

What happens if you explicitly set CC=/usr/bin/clang (as described in #32559 (comment))?

@bcmills bcmills changed the title net/http needs cgo to be disabled on macos? cmd/go: link error when building net/http on macOS Apr 10, 2020
@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Apr 10, 2020
@bcmills bcmills added this to the Unplanned milestone Apr 10, 2020
@bcmills
Copy link
Contributor

bcmills commented Apr 10, 2020

(This looks like a duplicate of #29597.)

@gopherbot
Copy link
Contributor

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants
@nicolas42 @bcmills @gopherbot and others