Skip to content

cmd/link: ABI hash of a shared library changes if any inlineable function changes #23405

@bryanpkc

Description

@bryanpkc

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Tip.

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

linux_amd64

What did you do?

  1. Install a package containing an exported inlineable function in shared mode.
  2. Build an executable that links against the shared library produced in step 1.
  3. Make a minor change to the package, without changing the ABI, and re-install the shared library.
  4. Run the executable produced in step 2.

You can reproduce this easily with the makefile in my example:

https://github.com/bryanpkc/pkgdef-example

What did you expect to see?

Correct execution of the main executable.

What did you see instead?

$./main
abi mismatch detected between the executable and libgithub.com-bryanpkc-pkgdef-example-arith.so
fatal error: abi mismatch
runtime: panic before malloc heap initialized

Proposed solution

The ABI hash of a shared library (or Go plugin) is computed as a SHA1 sum of the package hashes of all packages included in the shared library, which are in turn computed from the export data of the packages (i.e. the contents of __.PKGDEF in the corresponding package archives). Currently the export data of a package includes the ASTs of all inlineable exported functions in the package. Doing this allows cross-package inlining in the usual static compilation scenario, but also makes the ABI hashes of shared libraries unnecessarily unstable.

This can be fixed by:

  1. When computing the ABI hash for the package, exclude the list of inlineable functions from a package's export data.
  2. Do not allow cross-package inlining from a dynlink package archive into a dependant program. (This may already be the case today, but I am not 100% sure.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions