Skip to content

CDRIVER-3906 do not add libm on macOS #738

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

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Feb 14, 2021

Requiring consumers of libbson-static to link against libm on macOS causes an issue for the Go driver's use of libmongocrypt (error encountered originally in MONGOCRYPT-309, but copying details here).

$ pkg-config --libs --cflags libmongocrypt-static
-DMONGOCRYPT_STATIC_DEFINE -DKMS_MSG_STATIC -DBSON_STATIC -I/usr/local/Cellar/libmongocrypt/1.2.0/include/mongocrypt -I/usr/local/Cellar/mongo-c-driver/1.17.4/include/libbson-1.0 -L/usr/local/Cellar/mongo-c-driver/1.17.4/lib /usr/local/Cellar/libmongocrypt/1.2.0/lib/libmongocrypt-static.a /usr/local/Cellar/libmongocrypt/1.2.0/lib/libkms_message-static.a -framework CoreFoundation -framework Security -lbson-static-1.0 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd

The /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd is a valid input to the macOS linker, and is a text based stub-library. By default, Go rejects unrecognized linker inputs. This will be fixed in golang/go#44263 in the go command.

Example:

// bson.go
package bson

// #cgo pkg-config: libbson-static-1.0
// #include <bson/bson.h>
// #include <stdlib.h>
import "C"
import "fmt"

func RunBson() {
	v := C.bson_get_version()
	fmt.Printf("v=%v\n", v)
}

Attempting to build with go results in an error:

$ go build -o bson bson.go
go build command-line-arguments: invalid flag in pkg-config --libs: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd

Users can work around this by specifying the environment variable CGO_LDFLAGS_ALLOW='^.*tbd$'. But, libm is part of libsystem on macOS. So I do not think it is necessary to explicitly link to libm on macOS.

@kevinAlbs kevinAlbs marked this pull request as ready for review February 16, 2021 17:54
@kevinAlbs kevinAlbs changed the title MONGOCRYPT-309 do not add libm on macOS CDRIVER-3906 do not add libm on macOS Feb 16, 2021
Copy link
Contributor

@rcsanchez97 rcsanchez97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevinAlbs kevinAlbs merged commit 20cada3 into mongodb:master Feb 17, 2021
kevinAlbs added a commit that referenced this pull request Apr 8, 2021
chardan pushed a commit to chardan/mongo-c-driver that referenced this pull request Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants