Does binary id work with shared libraries?

Consider this example:

$ cat a.cpp
void foo();
void bar();

int main() {
foo();
bar();
return 0;
}

$ cat foo.cpp
void foo(){}
$ cat bar.cpp
void bar(){}
$ clang -fprofile-instr-generate -Wl,--build-id -O2 -fpic foo.cpp -o foo.so
$ clang -fprofile-instr-generate -Wl,--build-id -O2 -fpic bar.cpp -o bar.so
$ clang -fprofile-instr-generate -O2 -Wl,-build-id a.cpp $PWD/foo.so $PWD/bar.so -o a.exe
$ env LLVM_PROFILE_FILE="default.profraw" ./a.exe
$ llvm-profdata merge -o profdata default.profraw
$ llvm-profdata show --binary-ids default.profraw
Instrumentation level: Front-end
Total functions: 3
Maximum function count: 1
Maximum internal block count: 0
Binary IDs:
06022829f1a980398e09aa4fc4d26d78a1e9fac0
$ llvm-profdata show --binary-ids profdata
Instrumentation level: Front-end
Total functions: 3
Maximum function count: 1
Maximum internal block count: 0
Binary IDs:
06022829f1a980398e09aa4fc4d26d78a1e9fac0
$ llvm-readobj --notes bar.so
..
Build ID: 06022829f1a980398e09aa4fc4d26d78a1e9fac0
...

In this case, there are 3 raw profiles one after another in default.profraw. Each of them has a binary id.

  1. default.profraw actually contains 3 binary ids for a.exe, foo.so, bar.so, verified using hexdump, but llvm-prodata show --binary-ids is only able to show the one of them (It’s bar.so’s binary id in this case).
  2. After merging, profdata only contains one binary id. Does this mean binary id is not useful anymore after merging?

@gulfemsavrun @petrhosek

That’s a bug and not an intended behavior. Can you file an issue on GitHub? We need to look into it.

Filed at Profile binary id does not work with shared libraries · Issue #72699 · llvm/llvm-project · GitHub