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

Replace git_sha_rewriter.py with a generated linker option. #3021

Merged
merged 5 commits into from
Apr 23, 2018

Conversation

jmillikin-stripe
Copy link
Contributor

Description:
This replaces Envoy's use of a Python script to poke at raw ELF headers with a generated --build-id linker flag, following the example of @oquenchil in #2625.

Note: this means the //source/exe:envoy-static target is now stamped, instead of having a separate implicit envoy-static_stamped target.

I also edited the workspace status command so it treated the Git commit ID as "stable" instead of "volatile", so Bazel won't ignore it when relinking.

Risk Level: Low

Testing:
Tested locally on a MacOS and Linux build. Both of them have the current Git commit ID embedded in the expected binary sections.

Fixes #2551
Fixes #2625

@jmillikin-stripe jmillikin-stripe force-pushed the rm-git-sha-rewriter branch 2 times, most recently from 809af57 to 43dcd4a Compare April 7, 2018 03:12
@mattklein123
Copy link
Member

Approach at a high level LGTM. Assigning to @htuch for review. @jmillikin-stripe looks like there are still some CI issues.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

This is awesome @jmillikin-stripe, nice to see this landing.

bazel/BUILD Outdated
outs = ["gnu_build_id.ldscript"],
cmd = """
echo --build-id=0x$$(
grep STABLE_BUILD_SCM_REVISION bazel-out/stable-status.txt \\
Copy link
Member

Choose a reason for hiding this comment

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

How does this work when Envoy is used as a dependency in another project to assemble a binary? Are there any issues with relative paths? Can you validate with envoy-filter-example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't fully understand how the build-id feature is being used now, so I don't know what the desired behavior is when building from a higher-level repo.

Do you want the build ID to be Envoy's commit ID, or the commit ID of the root workspace? What if it's not being built from a Git repo -- should we make the build ID empty, or leave the flag unset, or ...?

Copy link
Member

Choose a reason for hiding this comment

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

@mattklein123 or other Lyfters will have to answer this one, as they have a similar setup to envoy-filter-example and use this for production build stamping.

Copy link
Member

Choose a reason for hiding this comment

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

I think right now it's the SHA of the envoy repo. Optimally, it would be the SHA of the owning repo, but whatever is fine with us as long as we have something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tweaked this a bit so it'll always use BUILD_SCM_REVISION, which should be compatible with most/all external repos. This means the decision to relink on a Git status change will be left up to the root workspace.

@@ -2,5 +2,5 @@
extern const char build_scm_revision[];
extern const char build_scm_status[];

const char build_scm_revision[] = BUILD_SCM_REVISION;
const char build_scm_status[] = BUILD_SCM_STATUS;
const char build_scm_revision[] = STABLE_BUILD_SCM_REVISION;
Copy link
Member

Choose a reason for hiding this comment

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

Curious if you think we can add a test to avoid regressions such as #2551?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I know of. Maybe we could hack something together in CI to add a fake empty commit, relink, and run envoy --version? Seems kinda fragile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI: I reverted changes to this file so we don't need to rename SCM status keys in everything that might build Envoy as a dependency.

bazel/BUILD Outdated
| sed 's/^STABLE_BUILD_SCM_REVISION //') \\
> $@
""",
stamp = 1,
Copy link
Member

Choose a reason for hiding this comment

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

What is stamp doing here and in the other genrules? I can't see much in the way of docs for genrule+stamp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stamp=1 gives the rule access to the bazel-out/stable-status.txt and bazel-out/volatile-status.txt files. It also makes the genrule depend directly on the stable status, so it'll re-run if the status changes.

The param is undocumented :( : bazelbuild/bazel#4942

"-sectcreate,__TEXT,__build_id", "$(location //bazel:raw_build_id.ldscript)"
],
"//conditions:default": [
"-Wl,@$(location //bazel:gnu_build_id.ldscript)",
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this needs to be @envoy//bazel... or similar in the envoy-filter-example scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I successfully built envoy-filter-example pointing to an Envoy src dir with my changes, and it has the correct build ID.

@jmillikin-stripe
Copy link
Contributor Author

Out of curiosity, how was the --build-id flag chosen as the storage for this info? One problem I hit was trying to represent non-Git builds, which have some arbitrary string as the "SCM version" instead of a Git commit ID.

It might make more sense to leave this flag alone and try to embed the version info as normal symbols.

@mattklein123
Copy link
Member

Out of curiosity, how was the --build-id flag chosen as the storage for this info? One problem I hit was trying to represent non-Git builds, which have some arbitrary string as the "SCM version" instead of a Git commit ID.

This is how I've always done it in the past. It gets embedded in core dumps, etc. and is easily accessible using normal tools. If there is a different way we can potentially change, but the main requirement is easily accessible in core dumps.

@htuch
Copy link
Member

htuch commented Apr 23, 2018

@jmillikin-stripe friendly ping on this one.

Fixes envoyproxy#2551

uses genrule workaround for missing STABLE_ keys in cc linkstamp,
more details at bazelbuild/bazel#1992

Signed-off-by: John Millikin <jmillikin@stripe.com>
Fixes envoyproxy#2625

Signed-off-by: John Millikin <jmillikin@stripe.com>
Signed-off-by: John Millikin <jmillikin@stripe.com>
@jmillikin-stripe
Copy link
Contributor Author

Sorry for the delay, got nerdsniped into a non-Envoy project last week. Comments addressed.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM modulo one nit comment.

bazel/BUILD Outdated
| sed 's/^BUILD_SCM_REVISION //') \\
> $@
""",
stamp = 1,
Copy link
Member

Choose a reason for hiding this comment

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

Can you leave a comment on the undocumented stamp semantics and the link the GH issue? I feel this will be useful when later revisiting these rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Signed-off-by: John Millikin <jmillikin@stripe.com>
@mattklein123
Copy link
Member

@jmillikin-stripe can you push an empty commit now that DCO bot is fixed?

Signed-off-by: John Millikin <jmillikin@stripe.com>
@mattklein123 mattklein123 merged commit b3bc488 into envoyproxy:master Apr 23, 2018
@jmillikin-stripe jmillikin-stripe deleted the rm-git-sha-rewriter branch April 23, 2018 22:08
@jrajahalme
Copy link
Contributor

Thanks!

jmillikin-stripe added a commit to jmillikin-stripe/envoy that referenced this pull request Apr 23, 2018
I tested envoyproxy#3021 with
envoy-filter-example to verify it works for non-default workspace roots,
but didn't realize the filter example's envoy binary is built without
linkstamping so the testing was worthless.

Experimental evidence is that the `deps` field needs `@envoy` but the
linker options are fine without it. I don't understand why this would be
true so I'm going to put `@envoy` in both places.

Signed-off-by: John Millikin <jmillikin@stripe.com>
ggreenway pushed a commit that referenced this pull request Apr 23, 2018
I tested #3021 with
envoy-filter-example to verify it works for non-default workspace roots,
but didn't realize the filter example's envoy binary is built without
linkstamping so the testing was worthless.

Experimental evidence is that the `deps` field needs `@envoy` but the
linker options are fine without it. I don't understand why this would be
true so I'm going to put `@envoy` in both places.

Signed-off-by: John Millikin <jmillikin@stripe.com>
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.

None yet

4 participants