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/link: macOS host linker warning about /usr/lib/libpthread.dylib #32512

Open
biskit opened this issue Jun 10, 2019 · 5 comments

Comments

@biskit
Copy link

commented Jun 10, 2019

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

$ go version
go version go1.12.5 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxx/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="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/18/jzwmssmd4pdb6m8yt54vyszc0000gn/T/go-build116537495=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

What did you expect to see?

What did you see instead?

bmax:~ bs$ uname -a
Darwin bmax 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
bmax:~ bs$ xcodebuild -version
Xcode 9.4.1
Build version 9F2000

code:

package main

import (
    "time"

    "github.com/gofrs/uuid"

    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/sqlite"
)

type Model struct {
    CreatedAt time.Time `json:"-"`
    UpdatedAt time.Time `json:"-"`
    DeletedAt *time.Time `json:"-" sql:"index"`
}

type Product struct {
    Model
    ID uuid.UUID
    Code  string
    Price uint
}

func main() {
    db, err := gorm.Open("sqlite3", "test.db")
    if err != nil {
        panic("failed to connect database")
    }
    defer db.Close()

    // Migrate the schema
    db.AutoMigrate(&Product{})

    uuid, err := uuid.NewV4()
    // Create
    db.Create(&Product{ID:uuid, Code: "L1212", Price: 1000})

    // Read
    var product Product
    db.First(&product, 1)                   // find product with id 1
    db.First(&product, "code = ?", "L1212") // find product with code l1212

    // Update - update product's price to 2000
    db.Model(&product).Update("Price", 2000)

    // Delete - delete product
    db.Delete(&product)
}
bmax:orm bs$ go build
# ~/test/orm
ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libpthread.dylib) built for (unknown). Note: This will be an error in the future.
ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libSystem.dylib) built for (unknown). Note: This will be an error in the future.

building any code that has cgo involved (in this case go-sqlite3 via gorm) will do it.

this only happens when using go modules.

however, when built under ~/go/src/github.com/mattn/go-sqlite3 with the command 'go build --tags "darwin"' it produces a libsqlite.a file that when used to build an executable does not produce this warning.

@randall77

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

bmax:orm bs$ go build
# ~/test/orm

I'm confused by this. Why did the prompt change?

Presumably you write that code you showed to a foo.go file in an orm directory. Then cd to that directory, and run go build. Then run ./orm. Anything else happening here?

So this error is from the dynamic loader?

Go progams link against /usr/lib/libSystem.B.dylib, I'm not sure why the B. is missing from the error. (The .B version is just a symlink to the one without the .B)
Go programs don't link against /usr/lib/libpthread.dylib, even indirectly. Even cgo Go programs. We get our pthread functionality indirectly through /usr/lib/system/libsystem_pthread.dylib. So where is that dependency coming from? Maybe some C libraries you're linking against?

All of that is for 10.12.6 aka Sierra. Maybe things on 10.14 have changed.

Could you do a otool -L orm and paste the output?

If you feel comfortable hacking the Go source, you might want to try messing with the version and compatibility version constants near the end of src/cmd/link/internal/ld/macho.go:Asmbmacho. Use otool -Lon the.dylib` files mentioned for hints on what to try. I'd try myself but I don't have a 10.14 box.

@biskit

This comment has been minimized.

Copy link
Author

commented Jun 10, 2019

the prompt should be /Users/foo/test/orm where test/orm is the directory and gormtest.go is the file. did not think it was a big deal.

so, when i do go build in /Users/foo/test/orm, the messages from ld show up.

ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libpthread.dylib) built for (unknown). Note: This will be an error in the future.
ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libSystem.dylib) built for (unknown). Note: This will be an error in the future.

when i run the binary ./orm it does execute and does its thing.

however, the build takes longer when compared to any other builds.

Yes, the error is from ld as you can see from the 'ld: warning: URGENT' line. this issue is a continuation to #27095 where you were looking for a demonstrable example.

here's the otool -L output:

bmax:orm bs$ otool -L orm 
orm:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)
@randall77

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

So the error is from go build, not from running the resulting executable?
(This is why we want to see exactly the steps you did, and exactly when the error appeared, to avoid confusion like this.)
Can you rerun go build with the -x option and post the results, so we can see which tool (compile, link, etc.) generates those errors?

@biskit

This comment has been minimized.

Copy link
Author

commented Jun 10, 2019

Yes, its from go build not on execution.

Here's the go build -x trace lines...

bmax:orm bs$ go build -x
WORK=/var/folders/18/jzwmssmd4pdb6m8yt54vyszc0000gn/T/go-build237385390
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg.link << 'EOF' # internal
packagefile bar/test/orm=/Users/foo/Library/Caches/go-build/27/274945b8fd3a4af6b16acaf61b372a509900a75181f79c5d16c172e7045382c5-d
packagefile github.com/gofrs/uuid=/Users/foo/Library/Caches/go-build/c6/c68b083aa714f26b72a4112043bd676160f7bee295febc7fa85da6ab43c383c2-d
packagefile github.com/jinzhu/gorm=/Users/foo/Library/Caches/go-build/5f/5f7c6c26f2ba9206c9728979d47614e705bd1f96477e4401809f6d523c205524-d
packagefile github.com/jinzhu/gorm/dialects/sqlite=/Users/foo/Library/Caches/go-build/f8/f8e07f76b790ec8c4695af703b4f76df021753b832228307568e9251f2aaebc5-d
packagefile time=/usr/local/go/pkg/darwin_amd64/time.a
packagefile runtime=/usr/local/go/pkg/darwin_amd64/runtime.a
packagefile bytes=/usr/local/go/pkg/darwin_amd64/bytes.a
packagefile crypto/md5=/usr/local/go/pkg/darwin_amd64/crypto/md5.a
packagefile crypto/rand=/usr/local/go/pkg/darwin_amd64/crypto/rand.a
packagefile crypto/sha1=/usr/local/go/pkg/darwin_amd64/crypto/sha1.a
packagefile database/sql/driver=/usr/local/go/pkg/darwin_amd64/database/sql/driver.a
packagefile encoding/binary=/usr/local/go/pkg/darwin_amd64/encoding/binary.a
packagefile encoding/hex=/usr/local/go/pkg/darwin_amd64/encoding/hex.a
packagefile encoding/json=/usr/local/go/pkg/darwin_amd64/encoding/json.a
packagefile fmt=/usr/local/go/pkg/darwin_amd64/fmt.a
packagefile hash=/usr/local/go/pkg/darwin_amd64/hash.a
packagefile io=/usr/local/go/pkg/darwin_amd64/io.a
packagefile net=/usr/local/go/pkg/darwin_amd64/net.a
packagefile os=/usr/local/go/pkg/darwin_amd64/os.a
packagefile sync=/usr/local/go/pkg/darwin_amd64/sync.a
packagefile database/sql=/usr/local/go/pkg/darwin_amd64/database/sql.a
packagefile errors=/usr/local/go/pkg/darwin_amd64/errors.a
packagefile github.com/jinzhu/inflection=/Users/foo/Library/Caches/go-build/d9/d952e8f6bdac2c5253277bdd59772ef4e7bff05b321fde411799f8c5b78ddb93-d
packagefile go/ast=/usr/local/go/pkg/darwin_amd64/go/ast.a
packagefile log=/usr/local/go/pkg/darwin_amd64/log.a
packagefile reflect=/usr/local/go/pkg/darwin_amd64/reflect.a
packagefile regexp=/usr/local/go/pkg/darwin_amd64/regexp.a
packagefile sort=/usr/local/go/pkg/darwin_amd64/sort.a
packagefile strconv=/usr/local/go/pkg/darwin_amd64/strconv.a
packagefile strings=/usr/local/go/pkg/darwin_amd64/strings.a
packagefile unicode=/usr/local/go/pkg/darwin_amd64/unicode.a
packagefile unicode/utf8=/usr/local/go/pkg/darwin_amd64/unicode/utf8.a
packagefile github.com/mattn/go-sqlite3=/Users/foo/Library/Caches/go-build/bf/bf16139aabbfb62d5197978710c40072c598b3822f6d3584db87ccc02c95520a-d
packagefile syscall=/usr/local/go/pkg/darwin_amd64/syscall.a
packagefile internal/bytealg=/usr/local/go/pkg/darwin_amd64/internal/bytealg.a
packagefile internal/cpu=/usr/local/go/pkg/darwin_amd64/internal/cpu.a
packagefile runtime/internal/atomic=/usr/local/go/pkg/darwin_amd64/runtime/internal/atomic.a
packagefile runtime/internal/math=/usr/local/go/pkg/darwin_amd64/runtime/internal/math.a
packagefile runtime/internal/sys=/usr/local/go/pkg/darwin_amd64/runtime/internal/sys.a
packagefile crypto=/usr/local/go/pkg/darwin_amd64/crypto.a
packagefile math/bits=/usr/local/go/pkg/darwin_amd64/math/bits.a
packagefile bufio=/usr/local/go/pkg/darwin_amd64/bufio.a
packagefile crypto/aes=/usr/local/go/pkg/darwin_amd64/crypto/aes.a
packagefile crypto/cipher=/usr/local/go/pkg/darwin_amd64/crypto/cipher.a
packagefile math/big=/usr/local/go/pkg/darwin_amd64/math/big.a
packagefile sync/atomic=/usr/local/go/pkg/darwin_amd64/sync/atomic.a
packagefile context=/usr/local/go/pkg/darwin_amd64/context.a
packagefile math=/usr/local/go/pkg/darwin_amd64/math.a
packagefile encoding=/usr/local/go/pkg/darwin_amd64/encoding.a
packagefile encoding/base64=/usr/local/go/pkg/darwin_amd64/encoding/base64.a
packagefile unicode/utf16=/usr/local/go/pkg/darwin_amd64/unicode/utf16.a
packagefile internal/fmtsort=/usr/local/go/pkg/darwin_amd64/internal/fmtsort.a
packagefile internal/nettrace=/usr/local/go/pkg/darwin_amd64/internal/nettrace.a
packagefile internal/poll=/usr/local/go/pkg/darwin_amd64/internal/poll.a
packagefile internal/singleflight=/usr/local/go/pkg/darwin_amd64/internal/singleflight.a
packagefile internal/x/net/dns/dnsmessage=/usr/local/go/pkg/darwin_amd64/internal/x/net/dns/dnsmessage.a
packagefile internal/x/net/route=/usr/local/go/pkg/darwin_amd64/internal/x/net/route.a
packagefile math/rand=/usr/local/go/pkg/darwin_amd64/math/rand.a
packagefile runtime/cgo=/usr/local/go/pkg/darwin_amd64/runtime/cgo.a
packagefile internal/syscall/unix=/usr/local/go/pkg/darwin_amd64/internal/syscall/unix.a
packagefile internal/testlog=/usr/local/go/pkg/darwin_amd64/internal/testlog.a
packagefile internal/race=/usr/local/go/pkg/darwin_amd64/internal/race.a
packagefile go/scanner=/usr/local/go/pkg/darwin_amd64/go/scanner.a
packagefile go/token=/usr/local/go/pkg/darwin_amd64/go/token.a
packagefile regexp/syntax=/usr/local/go/pkg/darwin_amd64/regexp/syntax.a
packagefile crypto/sha256=/usr/local/go/pkg/darwin_amd64/crypto/sha256.a
packagefile crypto/sha512=/usr/local/go/pkg/darwin_amd64/crypto/sha512.a
packagefile net/url=/usr/local/go/pkg/darwin_amd64/net/url.a
packagefile crypto/internal/subtle=/usr/local/go/pkg/darwin_amd64/crypto/internal/subtle.a
packagefile crypto/subtle=/usr/local/go/pkg/darwin_amd64/crypto/subtle.a
packagefile path/filepath=/usr/local/go/pkg/darwin_amd64/path/filepath.a
EOF
mkdir -p $WORK/b001/exe/
cd .
/usr/local/go/pkg/tool/darwin_amd64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -buildmode=exe -buildid=4JK3ubXmjvuBQnYDOLcz/dd0s1xGX6hfjH4FXNeKe/DSbQfRAC86zLWJQngazG/4JK3ubXmjvuBQnYDOLcz -extld=clang /Users/foo/Library/Caches/go-build/27/274945b8fd3a4af6b16acaf61b372a509900a75181f79c5d16c172e7045382c5-d
/usr/local/go/pkg/tool/darwin_amd64/buildid -w $WORK/b001/exe/a.out # internal
# bar/test/orm
ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libpthread.dylib) built for (unknown). Note: This will be an error in the future.
ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libSystem.dylib) built for (unknown). Note: This will be an error in the future.
mv $WORK/b001/exe/a.out orm
rm -r $WORK/b001/
@rsc rsc changed the title ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libpthread.dylib) built for (unknown). Note: This will be an error in the future. cmd/link: macOS host linker warning about /usr/lib/libpthread.dylib Jun 10, 2019
@biskit

This comment has been minimized.

Copy link
Author

commented Aug 21, 2019

still have same issues with 1.12.9.
may be these hints may provide insight to the warning messages:

  1. package is go-sqlite3
  2. here's the C includes that cause these issues
// +build cgo

package sqlite3

/*
#cgo CFLAGS: -std=gnu99
#cgo CFLAGS: -DSQLITE_ENABLE_RTREE
#cgo CFLAGS: -DSQLITE_THREADSAFE=1
#cgo CFLAGS: -DHAVE_USLEEP=1
#cgo CFLAGS: -DSQLITE_ENABLE_FTS3
#cgo CFLAGS: -DSQLITE_ENABLE_FTS3_PARENTHESIS
#cgo CFLAGS: -DSQLITE_ENABLE_FTS4_UNICODE61
//#cgo CFLAGS: -DSQLITE_TRACE_SIZE_LIMIT=15
#cgo CFLAGS: -DSQLITE_OMIT_DEPRECATED
#cgo CFLAGS: -DSQLITE_DISABLE_INTRINSIC
#cgo CFLAGS: -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1
#cgo CFLAGS: -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT
#cgo CFLAGS: -Wno-deprecated-declarations
#cgo linux,!android CFLAGS: -DHAVE_PREAD64=1 -DHAVE_PWRITE64=1
#ifndef USE_LIBSQLITE3
#include <sqlite3-binding.h>
#else
#include <sqlite3.h>
#endif
#include <stdlib.h>
#include <string.h>

the entire file: https://github.com/mattn/go-sqlite3/blob/master/sqlite3.go

and the warnings when building a binary with that library.

ld: warning: URGENT: building for OSX, but linking against dylib (/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation) built for (unknown). Note: This will be an error in the future.
ld: warning: URGENT: building for OSX, but linking against dylib (/System/Library/Frameworks//Security.framework/Security) built for (unknown). Note: This will be an error in the future.
ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libpthread.dylib) built for (unknown). Note: This will be an error in the future.
ld: warning: URGENT: building for OSX, but linking against dylib (/usr/lib/libSystem.dylib) built for (unknown). Note: This will be an error in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.