Skip to content

Binary Static Library Artifact auditing tool #8741

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

Conversation

daniel-grumberg
Copy link
Contributor

This is an implementation of the auditing tool described in SE-0482.

Motivation:

As part of SE-0482 and #8639 we introduced the ability to depend on prebuilt static libraries (that expose a C interface) and that don't have any dependencies outside of the C standard library. This PR introduces an auditing tool that checks the ABI of static library artifact bundle and checks if it's compatible with the current host platform.

Modifications:

  • Create a new package subcommand that checks a local artifact bundle for unexpected external dependencies.
  • New internal APIs to inspect the ABI of a binary object (object file, static archive, dynamic library).

Result:

Users will be able to validate that their static library binary artifacts won't cause runtime issues for users.

@daniel-grumberg
Copy link
Contributor Author

We would also like to provide docker image that bundles the tool and has the oldest supported libc in the Swift ecosystem which is glibc 2.26 as of Swift 6.

@rauhul
Copy link
Member

rauhul commented Jun 2, 2025

Please correct me if I'm wrong, but I don't see how this tool checks for compatible ABIs at all. It seems to only deal with symbol names and doesn't have any knowledge the actual function ABI.

Also is there a reason this only works for the host triple? This seems like an odd requirement.

Lastly, why does this manually call shell tools? This functionality should likely be expressed in an action graph (via llbuild). The his would mean it could be included in larger graphs as well individually operations can be cached.

@daniel-grumberg daniel-grumberg force-pushed the dgrumberg/binary-artifact-audit branch from b4a419c to b1ac38f Compare June 2, 2025 14:39
@daniel-grumberg
Copy link
Contributor Author

We would also like to provide docker image that bundles the tool and has the oldest supported libc in the Swift ecosystem which is glibc 2.26 as of Swift 6.

Upon further reflection we can tell users to the 6.2 amazonlinux2 image once it comes out, until we figure out a more robust strategy in a future release.

@daniel-grumberg
Copy link
Contributor Author

@rauhul answers inline:

Please correct me if I'm wrong, but I don't see how this tool checks for compatible ABIs at all. It seems to only deal with symbol names and doesn't have any knowledge the actual function ABI.
Also is there a reason this only works for the host triple? This seems like an odd requirement.

This might a terminology misnomer (I am not a low level runtime person), but what it does validate is that any referenced symbols are either provided by default (e.g. compiler runtimes) or come from the system libc. It needs to run on the host triple because we don't actually have access to the system libc on the deployment target currently. We will recommend users run this on amazonlinux2 images as they have the oldest libc of the supported images.

Lastly, why does this manually call shell tools? This functionality should likely be expressed in an action graph (via llbuild). The his would mean it could be included in larger graphs as well individually operations can be cached.

I am not familiar with this, but this is not part of the build, it is a purely one of operation intended to be run in CI by binary static library artifact vendors.

@daniel-grumberg
Copy link
Contributor Author

@swift-ci please smoke-test

@daniel-grumberg
Copy link
Contributor Author

@swift-ci please test

@daniel-grumberg daniel-grumberg force-pushed the dgrumberg/binary-artifact-audit branch from b1ac38f to da1aff7 Compare June 2, 2025 15:16
@daniel-grumberg daniel-grumberg force-pushed the dgrumberg/binary-artifact-audit branch from da1aff7 to 1e5f09b Compare June 2, 2025 15:23
@daniel-grumberg
Copy link
Contributor Author

@swift-ci please test

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@daniel-grumberg daniel-grumberg enabled auto-merge (squash) June 3, 2025 12:27
@daniel-grumberg
Copy link
Contributor Author

@swift-ci please test windows

@daniel-grumberg
Copy link
Contributor Author

@swift-ci please test

@MaxDesiatov
Copy link
Contributor

@swift-ci test self hosted windows

@daniel-grumberg
Copy link
Contributor Author

@swift-ci test self-hosted windows


try await archiver.extract(from: path, to: archiveDirectory)

let artifacts = try fileSystem.getDirectoryContents(archiveDirectory)
Copy link
Member

Choose a reason for hiding this comment

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

Just to check are we filtering somewhere to only use the .a that also applies to the current host triplet?

Copy link
Contributor Author

@daniel-grumberg daniel-grumberg Jun 4, 2025

Choose a reason for hiding this comment

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

parseLibraryArtifactArchives does it for us.

@daniel-grumberg
Copy link
Contributor Author

@swift-ci test self hosted windows

@daniel-grumberg
Copy link
Contributor Author

@swift-ci test

@daniel-grumberg
Copy link
Contributor Author

@swift-ci test windows

@daniel-grumberg daniel-grumberg merged commit 7c5b0bc into swiftlang:main Jun 5, 2025
6 checks passed
daniel-grumberg added a commit that referenced this pull request Jun 11, 2025
This is an implementation of the auditing tool described in
[SE-0482](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0482-swiftpm-static-library-binary-target-non-apple-platforms.md).

### Motivation:

As part of SE-0482 and
#8639 we
introduced the ability to depend on prebuilt static libraries (that
expose a C interface) and that don't have any dependencies outside of
the C standard library. This PR introduces an auditing tool that checks
the ABI of static library artifact bundle and checks if it's compatible
with the current host platform.

### Modifications:

- Create a new package subcommand that checks a local artifact bundle
for unexpected external dependencies.
- New internal APIs to inspect the ABI of a binary object (object file,
static archive, dynamic library).

### Result:

Users will be able to validate that their static library binary
artifacts won't cause runtime issues for users.
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.

5 participants