Skip to content

Add creation of the build-id to the linker flags #435

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

imciner2
Copy link
Member

This is the toolchain part of the implementation of the build-id. This should now make the linker build in a build-id to the libraries/executables, and use one that also allows reproducibility.

ref: JuliaPackaging/Yggdrasil#11013, JuliaPackaging/BinaryBuilder.jl#1272

@imciner2
Copy link
Member Author

Forgot that build-id is an ELF only thing, so we can only add it on Linux and FreeBSD.

@giordano
Copy link
Member

Can we have some tests?

@giordano
Copy link
Member

Side note, I just realised we may not have reproducibility tests in this repo. We have some in BinaryBuilder: https://github.com/search?q=repo%3AJuliaPackaging%2FBinaryBuilder.jl+reproducibility+language%3AJulia+path%3A%2F%5Etest%5C%2F%2F&type=code

@imciner2
Copy link
Member Author

I've blind-coded a test for this based on what I think the output should be. Let's see if that passes. it's a bit awkward because we don't have the actual elf to query here, so I had to do a readelf inside the script and just parse the output.

Co-authored-by: Mosè Giordano <[email protected]>
@giordano
Copy link
Member

Can ObjectFile.jl read the notes?

@imciner2
Copy link
Member Author

Can ObjectFile.jl read the notes?

It can, but I didn't see any place where we can get the actual compiled file out in these tests already (or at least I didn't see any tests doing it), and we didn't have ObjectFile.jl in the deps already, so I didn't dive deeper into trying to make that work.

Using ObjectFile.jl, this is pseudo-code to test if the build-id section exists (and can also form the basis for an Audit pass in BinaryBuilder.jl):

l = open(<lib>)
obj_handles = readmeta(l)
obj = first(obj_handles)
sec = ELFSections(obj)

# This will be true if there is no section
findfirst(s -> section_name(s) == ".note.gnu.build-id", sec) === nothing

@imciner2
Copy link
Member Author

And I guess readelf in the sandbox is old enough it doesn't decode the name of the section, so we have to match on the description NT_GNU_BUILD_ID instead (which was in the output).

Copy link
Member

@giordano giordano left a comment

Choose a reason for hiding this comment

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

Looks good to me. @vtjnash do you want to have a look?

@imciner2
Copy link
Member Author

It's not quite as easy on Windows. Apparently, the support for build-id was added in binutils 2.25, which means we can only support the build-id on Windows for GCC >= 5.2.0 and not the default GCC 4.8.5 we use.

@giordano
Copy link
Member

You should be able to access gcc_version to conditionally set that, right?

@imciner2
Copy link
Member Author

Yep, that variable should be accessible. I just went down the rabbit hole of also adding a test for the Windows COFF format including the build-id info.

@imciner2
Copy link
Member Author

Ok, after going down yet another rabbit hole to get the tests for the build-id running on the Windows binaries, this should be good to go now. We will add a reproducible build-id to all platforms other than macOS automatically now (but I think I read somewhere macOS compilers provided a build-id already, so that shouldn't be a problem).

@giordano giordano added runner 🏃‍♀️ enhancement New feature or request labels Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants