[BOLT][Linux] Fix linux_banner lookup (#144962)

While detecting the Linux kernel version, look for `linux_banner` symbol
with local visibility if the global one was not found.

Fixes #144847
This commit is contained in:
Maksim Panchenko 2025-06-19 23:09:34 -07:00 committed by GitHub
parent 69974658f0
commit b8d3efa189
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 16 deletions

View File

@ -432,7 +432,15 @@ public:
};
Error LinuxKernelRewriter::detectLinuxKernelVersion() {
if (BinaryData *BD = BC.getBinaryDataByName("linux_banner")) {
// Check for global and local linux_banner symbol.
BinaryData *BD = BC.getBinaryDataByName("linux_banner");
if (!BD)
BD = BC.getBinaryDataByName("linux_banner/1");
if (!BD)
return createStringError(errc::executable_format_error,
"unable to locate linux_banner");
const BinarySection &Section = BD->getSection();
const std::string S =
Section.getContents().substr(BD->getOffset(), BD->getSize()).str();
@ -448,9 +456,9 @@ Error LinuxKernelRewriter::detectLinuxKernelVersion() {
<< "\n";
return Error::success();
}
}
return createStringError(errc::executable_format_error,
"Linux kernel version is unknown");
"Linux kernel version is unknown: " + S);
}
void LinuxKernelRewriter::processLKSections() {

View File

@ -17,6 +17,11 @@
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr
# RUN: llvm-bolt %t.exe -o %t.out 2>&1 | FileCheck --check-prefix=CHECK-C %s
# RUN: %clang -DD -target x86_64-unknown-unknown \
# RUN: %cflags -nostdlib %s -o %t.exe \
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr
# RUN: llvm-bolt %t.exe -o %t.out 2>&1 | FileCheck --check-prefix=CHECK-D %s
.text
.globl foo
.type foo, %function
@ -46,6 +51,12 @@ linux_banner:
#endif
# CHECK-C: BOLT-INFO: Linux kernel version is 6.6
#ifdef D
.hidden linux_banner
.string "Linux version 6.6.15.2-2-xxx\n"
#endif
# CHECK-D: BOLT-INFO: Linux kernel version is 6.6
.size linux_banner, . - linux_banner
## Fake Linux Kernel sections.