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

don't actually build .a files on Linux, instead pass the original .o files to the final link #1411

Closed
bsilver8192 opened this issue Jun 15, 2016 · 6 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug
Milestone

Comments

@bsilver8192
Copy link
Contributor

In #492, @ulfjack mentioned that "We don't actually build .a files on Linux, where we instead pass the original .o files to the final link (or at least, we have code to do that, and I think it's enabled by default). This is faster than building intermediate .a files and uses less disk space." That sounds nice, but doesn't seem to actually work:

$ bazel build --subcommands //:main
INFO: Found 1 target...
>>>>> # //:main [action 'Creating runfiles tree bazel-out/local-fastbuild/bin/main.runfiles']
...
>>>>> # //:gen_files [action 'Executing genrule //:gen_files']
...
>>>>> # //:a [action 'Compiling a.c']
...
>>>>> # //:main [action 'Compiling main.c']
...
>>>>> # //:a [action 'Linking liba.a']
...
>>>>> # //:main [action 'Linking main']
...
Target //:main up-to-date:
  bazel-bin/main
INFO: Elapsed time: 2.655s, Critical Path: 0.61s

BUILD:

genrule(
  name = 'gen_files',
  outs = ['a.c', 'main.c'],
  cmd = 'echo "int main() {}" > $(location main.c) && touch $(location a.c)',
)

cc_library(
  name = 'a',
  srcs = ['a.c'],
)

cc_binary(
  name = 'main',
  srcs = ['main.c'],
  deps = [':a'],
)
@ulfjack
Copy link
Contributor

ulfjack commented Jun 16, 2016

The CROSSTOOL file needs to declare that it supports that mode by setting
supports_start_end_lib = true. Maybe the cc_configure rule doesn't do that
by default? Maybe it depends on the compiler version?

On Wed, Jun 15, 2016 at 11:53 PM, bsilver8192 [email protected]
wrote:

In #492 #492, @ulfjack
https://github.com/ulfjack mentioned that "We don't actually build .a
files on Linux, where we instead pass the original .o files to the final
link (or at least, we have code to do that, and I think it's enabled by
default). This is faster than building intermediate .a files and uses less
disk space." That sounds nice, but doesn't seem to actually work:

$ bazel build --subcommands //:mainINFO: Found 1 target...>>>>> # //:main [action 'Creating runfiles tree bazel-out/local-fastbuild/bin/main.runfiles']...>>>>> # //:gen_files [action 'Executing genrule //:gen_files']...>>>>> # //:a [action 'Compiling a.c']...>>>>> # //:main [action 'Compiling main.c']...>>>>> # //:a [action 'Linking liba.a']...>>>>> # //:main [action 'Linking main']...Target //:main up-to-date: bazel-bin/mainINFO: Elapsed time: 2.655s, Critical Path: 0.61s

BUILD:

genrule(
name = 'gen_files',
outs = ['a.c', 'main.c'],
cmd = 'echo "int main() {}" > $(location main.c) && touch $(location a.c)',
)

cc_library(
name = 'a',
srcs = ['a.c'],
)

cc_binary(
name = 'main',
srcs = ['main.c'],
deps = [':a'],
)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1411, or mute the thread
https://github.com/notifications/unsubscribe/AHA9Ybtyudm5fSli3cF4l1TXnAV8T_jEks5qMHRQgaJpZM4I21SW
.

@bsilver8192
Copy link
Contributor Author

That would be the problem. Those appear to be a gold-only flags, and cc_configure.bzl doesn't attempt to auto-detect using gold. If I add linker_flag: "-fuse-ld=gold" (necessary on my Debian Jessie system to use gold) and change to supports_start_end_lib: true, then it works.

Would it make sense to have cc_configure.bzl try -fuse-ld=gold and set stuff appropriately if it works? Or maybe somehow detect if the default linker is gold?

@philwo
Copy link
Member

philwo commented Jun 20, 2016

Topic area is C++ auto configuration, so assignee is Damien. :)

@dslomov
Copy link
Contributor

dslomov commented Jun 28, 2016

@damienmg Any more information that is needed here?

@damienmg damienmg added type: bug P2 We'll consider working on this in future. (Assignee optional) category: misc > bootstrap / installation and removed under investigation labels Jul 29, 2016
@damienmg damienmg added this to the 0.5 milestone Jul 29, 2016
@damienmg
Copy link
Contributor

Sorry lost track with my personnal issues, it is indeed something that we should do, triaged.

@hlopko hlopko self-assigned this Nov 15, 2016
@hlopko
Copy link
Member

hlopko commented Nov 18, 2016

Should be fixed by cc3d79c, closing. Thank you bsilver8192!

@hlopko hlopko closed this as completed Nov 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug
Projects
None yet
Development

No branches or pull requests

7 participants