[llvm-branch-commits] [llvm] [BOLT] Use identify_magic for shared library detection (PR #190902)
Amir Ayupov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Apr 9 15:42:44 PDT 2026
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/190902
>From 0da209e81e5301cca7265175a519586961075667 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Tue, 7 Apr 2026 20:52:08 -0700
Subject: [PATCH 1/2] format
Created using spr 1.3.4
---
bolt/lib/Profile/DataAggregator.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index 413b0986d7c89f..f39cdda086a50d 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -24,7 +24,6 @@
#include "llvm/ADT/ScopeExit.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Errc.h"
>From 67a3e4f1d642009a5a596ae68719b4b2fb5081fe Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Wed, 8 Apr 2026 15:10:51 -0700
Subject: [PATCH 2/2] PIE vs DSO
Created using spr 1.3.4
---
bolt/lib/Profile/CMakeLists.txt | 1 +
bolt/lib/Profile/DataAggregator.cpp | 2 +-
bolt/test/X86/pre-aggregated-perf-shlib.test | 15 ++++++++++-----
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/bolt/lib/Profile/CMakeLists.txt b/bolt/lib/Profile/CMakeLists.txt
index a2bb4aa074c75d..a6686510f91a77 100644
--- a/bolt/lib/Profile/CMakeLists.txt
+++ b/bolt/lib/Profile/CMakeLists.txt
@@ -11,6 +11,7 @@ add_llvm_library(LLVMBOLTProfile
DISABLE_LLVM_LINK_LLVM_DYLIB
LINK_COMPONENTS
+ BinaryFormat
Demangle
MC
Support
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index f39cdda086a50d..08ae24bfd411c4 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -398,7 +398,7 @@ void DataAggregator::parsePreAggregated() {
file_magic Magic;
if (BC && !BC->HasFixedLoadAddress &&
!identify_magic(BC->getFilename(), Magic) &&
- Magic == file_magic::elf_shared_object) {
+ Magic == file_magic::elf_shared_object && !BC->HasInterpHeader) {
if (auto FileBID = BC->getFileBuildID()) {
FilterBuildID = *FileBID;
outs() << "PERF2BOLT: filtering pre-aggregated data for buildid "
diff --git a/bolt/test/X86/pre-aggregated-perf-shlib.test b/bolt/test/X86/pre-aggregated-perf-shlib.test
index bd5c0cf8c28512..c804910de55751 100644
--- a/bolt/test/X86/pre-aggregated-perf-shlib.test
+++ b/bolt/test/X86/pre-aggregated-perf-shlib.test
@@ -5,7 +5,9 @@
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
# RUN: %clang %cflags %t.o -o %t.so -shared -Wl,-q -Wl,--build-id=0xaabb1122 -nostdlib
+# RUN: %clang %cflags %t.o -o %t.exe -fPIC -pie -Wl,-q -Wl,--build-id=0xaabb1122 -nostdlib
# RUN: link_fdata %s %t.so %t.pa PREAGG
+# RUN: link_fdata %s %t.exe %t.pa-pie PREAGG
# RUN: link_fdata %s %t.so %t.pa-bid PREAGG-BID
## Test 1: Without buildid prefix, addresses don't match the .so's buildid
@@ -31,6 +33,7 @@ foo:
pushq %rbp
movq %rsp, %rbp
cmpl $0, %edi
+Lbr:
je Lfalse
Ltrue:
movl $1, %eax
@@ -42,11 +45,8 @@ Lret:
retq
.size foo, .-foo
-# PREAGG: B #foo# #Lret# 10 0
-# PREAGG: F #Lfalse# #Lret# 5
-
-# PREAGG-BID: B aabb1122:#foo# aabb1122:#Lret# 10 0
-# PREAGG-BID: F aabb1122:#Lfalse# aabb1122:#Lret# 5
+# PREAGG: T #Lbr# #Lfalse# #Lret# 10
+# PREAGG-BID: T aabb1122:#Lbr# aabb1122:#Lfalse# aabb1122:#Lret# 10
## Test 3: Executable with ".so" in the filename should NOT trigger filtering.
## The old heuristic (ends_with(".so")) would false-positive here, but
@@ -68,3 +68,8 @@ Lret:
# CHECK-NOEXT: PERF2BOLT: filtering pre-aggregated data for buildid aabb1122
# CHECK-NOEXT: BOLT-INFO: 1 out of {{[0-9]+}} functions in the binary
# CHECK-NOEXT-NOT: (0.0%)
+#
+## Test 5: Check that PIE binaries are not misidentified as shared libraries.
+# RUN: perf2bolt %t.exe -o %t.fdata5 --pa -p %t.pa-pie 2>&1 | FileCheck %s \
+# RUN: --check-prefix=CHECK-PIE
+# CHECK-PIE: BOLT-INFO: 1 out of {{[0-9]+}} functions in the binary
More information about the llvm-branch-commits
mailing list