Skip to content

fix(ct,eunit): add the build id to LLVM_PROFILE_FILE on Linux - #23

Open
TrapsterDK wants to merge 1 commit into
bazelverse:mainfrom
TrapsterDK:nif-profile-build-id
Open

TrapsterDK wants to merge 1 commit into
bazelverse:mainfrom
TrapsterDK:nif-profile-build-id

Conversation

@TrapsterDK

Copy link
Copy Markdown

Fixes #22

Problem

Bazel sets LLVM_PROFILE_FILE to a pattern with %m. Two NIFs with the same profile layout get the same %m, so they write to one .profraw. The second write fails with "Unable to merge profile data" and both NIFs report 0 hits.

Change

On Linux, the bash scripts generated by ct_test and eunit rewrite %m in LLVM_PROFILE_FILE to %b-%m before starting the VM. %b is the ELF build id, so each library writes its own profile. macOS and Windows are unchanged.

Notes:

  • %b needs compiler-rt from LLVM 21 or later. Older runtimes drop the unknown %b, so nothing changes there.
  • NIFs must be linked with a build id (-Wl,--build-id). With LLVM 21 or later and a library that has no build id, the runtime warns and writes to its default file name, so that profile is not collected.

Test

test/llvm_profile_file has an eunit and a ct_test target that set LLVM_PROFILE_FILE=prof/%h-%p-%m.profraw and check the value the VM sees: prof/%h-%p-%b-%m.profraw on Linux, unchanged on macOS. Both fail without the change. Windows is left out because the .bat scripts expand % in set.

bazel test //... passes in the root and in test/ with Bazel 9.2.0 and OTP 29 on Linux.

Assisted by Claude.

Two NIFs with the same profile layout share a %m signature and write to
one profile, so the second fails to merge and both lose their counts.
%b is the ELF build id, which differs per library.

Assisted by Claude.
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.

LLVM_PROFILE_FILE %m makes NIFs with the same layout share one profile

1 participant