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

Using -extldflags in gc_linkopts gets ignored by go tool link #305

Closed
toby-jazz opened this issue Mar 13, 2017 · 2 comments
Closed

Using -extldflags in gc_linkopts gets ignored by go tool link #305

toby-jazz opened this issue Mar 13, 2017 · 2 comments
Assignees

Comments

@toby-jazz
Copy link

toby-jazz commented Mar 13, 2017

Related to #217 and #161
When passing -extldflags with gc_linkopts:

go_binary(
    name = "foo",
    srcs = ["foo.go"],
    gc_linkopts = [
        "-extldflags \"-static\"",
    ],
)

the -extldflags gets added to go tool link twice due to _emit_go_link_action (https://github.com/bazelbuild/rules_go/blob/master/go/def.bzl#L442).
It looks like go tool link then only uses the second set of flags, meaning the flags passed in through gc_linkopts are ignored.
Ideally these flags should be merged so that only one -extldflags is emitted.

@jayconrod jayconrod self-assigned this Mar 13, 2017
jayconrod pushed a commit to jayconrod/rules_go that referenced this issue Mar 14, 2017
_emit_go_link_action now scans gc_linkopts for -extldflags
arguments. The Go linker will only use the last list passed to it
(earlier lists are silently ignored), so we combine these into one
external flags list.

Fixes bazel-contrib#305
jayconrod pushed a commit to jayconrod/rules_go that referenced this issue Mar 14, 2017
_emit_go_link_action now scans gc_linkopts for -extldflags
arguments. The Go linker will only use the last list passed to it
(earlier lists are silently ignored), so we combine these into one
external flags list.

Fixes bazel-contrib#305
jayconrod pushed a commit to jayconrod/rules_go that referenced this issue Mar 14, 2017
_emit_go_link_action now scans gc_linkopts for -extldflags
arguments. The Go linker will only use the last list passed to it
(earlier lists are silently ignored), so we combine these into one
external flags list.

Fixes bazel-contrib#305
jayconrod added a commit that referenced this issue Mar 15, 2017
_emit_go_link_action now scans gc_linkopts for -extldflags
arguments. The Go linker will only use the last list passed to it
(earlier lists are silently ignored), so we combine these into one
external flags list.

Fixes #305
@sumitd2
Copy link

sumitd2 commented Jan 5, 2023

Hi team, I have the same issue with v0.26.0, please help:

go_binary(
    name = "cockroach",
    embed = [":cockroach_lib"],cgo = True,gc_linkopts = ["-extldflags=-lkeyutils"],
    visibility = ["//visibility:public"],
)

bazel-out/ppc-opt-exec-2B5CBBC6/bin/external/go_sdk/builder '-param=bazel-out/ppc-fastbuild/bin/pkg/cmd/cockroach/cockroach_/cockroach-0.params' -- -extld /usr/bin/gcc '-extldflags=-lkeyutils' '-buildid=redacted' -extldflags '-fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -pass-exit-codes -lm')

@fmeum
Copy link
Member

fmeum commented Jan 9, 2023

@sumitd2 Could you try gc_linkopts = ["-extldflags", "-lkeyutils"]?

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

No branches or pull requests

4 participants