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

git hash in --build-id #2805

Closed
htuch opened this issue Apr 11, 2017 · 16 comments
Closed

git hash in --build-id #2805

htuch opened this issue Apr 11, 2017 · 16 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@htuch
Copy link

htuch commented Apr 11, 2017

Some projects, such as Envoy (https://github.com/lyft/envoy/) need the ability to set -Wl,--build-id=<git hash of workspace generating build> to encode the build ID in the .note.gnu.build-id ELF section.

It seems that Bazel uses this for hashing inputs or setting to a fixed value, based on the stamp option in cc_binary or --stamp on the CLI. Manually specifying a linkopt does not override, since this comes before the Bazel supplied --build-id on the command line.

What's the best practice for doing this today in Bazel?

I noticed #216, but this doesn't seem to reference setting the --build-id, it seems to be concerned with obtaining the build information.

CC @mattklein123 envoyproxy/envoy#415

@buchgr
Copy link
Contributor

buchgr commented Apr 12, 2017

@mhlopko @ulfjack @lberki might know?

@buchgr
Copy link
Contributor

buchgr commented Apr 12, 2017

@htuch could you please ask this question on stackoverflow using the bazel tag (so that other users can also benefit from an answer)? Bazel devs are monitoring SO and I am sure we'll find someone to answer your question there.

thanks so much!

@lberki
Copy link
Contributor

lberki commented Apr 12, 2017

We could remove --build-id=md5 from the linker command line (I haven't seen evidence that it was put in after careful thought...), but I can't think of a good way to convey the build stamp information to a linker option.

My best guess would be to use the the stamping data in a genrule to write a linker script, then reference that linker script on the linker command line, but I don't know if you can do the equivalent of --build-id=<stuff> that way.

@htuch
Copy link
Author

htuch commented Apr 12, 2017

@buchgr I think this is probably the right forum as we need to have some changes made to Bazel to get this to work I believe.

@lberki Yeah, if there was a way to suppress the --build_id=md5 that would be enough. I think we could use a genrule to generate a linker option file with the hash, and then supply to linkopts the option @generated_linker_option_filename.

We're going to need a workaround until Bazel gains this support, so I will investigate and update this issue.

@htuch
Copy link
Author

htuch commented Apr 13, 2017

@buchgr @lberki Thanks for sorting this. Do you know the Bazel release number and release date this will intercept?

@buchgr
Copy link
Contributor

buchgr commented Apr 13, 2017

AFAIK it will be 0.5

@htuch
Copy link
Author

htuch commented Apr 13, 2017

I think there's a bit more to it than just the above commit. I tried writing a genrule to produce a file build_id_options that can be supplied by @build_id_options in linkopts. Bazel gets confused by linkopts beginning with @, treating them as labels that it needs to resolve rather than options to pass to the linker.

It would probably be most convenient if we can just add something like --build-id=$(BUILD_SCM_REVISION) to the linker. But this variable isn't available under make variable substitution today.

Can we reopen this issue to get to a working implementation?

@htuch
Copy link
Author

htuch commented Apr 14, 2017

Friendly ping to @buchgr to reopen. Thanks.

htuch added a commit to htuch/envoy that referenced this issue Apr 14, 2017
This is a workaround for
bazelbuild/bazel#2805.

Small reorganization of version_generated.cc rules, since we rely on them
here and this can also assist with the Google import of Envoy and its
versioning scheme.

Also added docs on build types and how to do release builds.
@buchgr buchgr reopened this Apr 14, 2017
mattklein123 pushed a commit to envoyproxy/envoy that referenced this issue Apr 17, 2017
This is a workaround for
bazelbuild/bazel#2805.

Small reorganization of version_generated.cc rules, since we rely on them
here and this can also assist with the Google import of Envoy and its
versioning scheme.

Also added docs on build types and how to do release builds.
@lberki lberki added the P1 I'll work on this now. (Assignee required) label Feb 1, 2018
@lberki
Copy link
Contributor

lberki commented Feb 1, 2018

Here's the plan: we are going to add a linker_param_files attribute to cc_binary which will tell Bazel to add options in it to the linker command line.

Then you can write a genrule that takes the commit hash out of the linkstamp information (stable-status.txt), writes -Wl,--build-id=<commithash> to a file, then add that to this new attribute on cc_binary.

LGTY?

@htuch
Copy link
Author

htuch commented Feb 1, 2018

@lberki LGTM,thanks. One question; what will happen to other linker params that are inserted by CROSSTOOLS or via the Bazel internally? I'm kind of worried we might still see the --build_id=md5 injected prior to our linker options?

@lberki
Copy link
Contributor

lberki commented Feb 1, 2018

I was hoping that later --build-id options supersede former ones. Isn't that the case?

@htuch
Copy link
Author

htuch commented Feb 1, 2018

Yeah, seems likely but needs verification. Ideally we have some Bazel test for this functionality that demonstrates this.

@hlopko
Copy link
Member

hlopko commented Feb 1, 2018

Since 724706b bazel doesn't emit --build-id=md5

@hlopko hlopko assigned oquenchil and unassigned hlopko Feb 2, 2018
@lberki lberki added P2 We'll consider working on this in future. (Assignee optional) and removed P1 I'll work on this now. (Assignee required) labels Feb 21, 2018
@helenalt
Copy link
Contributor

@oquenchil is this issue resolved with the additional_linker_inputs attribute?

@oquenchil
Copy link
Contributor

I'm still working on adding the additional_linker_inputs attribute but Harvey can use a workaround meanwhile which is ugly but does the job for now.

@htuch
Copy link
Author

htuch commented Feb 21, 2018

We're tracking this on the Envoy side in envoyproxy/envoy#2625. We need to find someone with cycles to validate the new Bazel native solutions, CC: @jmillikin-stripe.

@hlopko hlopko added team-Rules-CPP Issues for C++ rules and removed category: rules > C++ labels Oct 11, 2018
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) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants