[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:
@@ -432,25 +432,33 @@ public:
|
||||
};
|
||||
|
||||
Error LinuxKernelRewriter::detectLinuxKernelVersion() {
|
||||
if (BinaryData *BD = BC.getBinaryDataByName("linux_banner")) {
|
||||
const BinarySection &Section = BD->getSection();
|
||||
const std::string S =
|
||||
Section.getContents().substr(BD->getOffset(), BD->getSize()).str();
|
||||
// Check for global and local linux_banner symbol.
|
||||
BinaryData *BD = BC.getBinaryDataByName("linux_banner");
|
||||
if (!BD)
|
||||
BD = BC.getBinaryDataByName("linux_banner/1");
|
||||
|
||||
const std::regex Re(R"---(Linux version ((\d+)\.(\d+)(\.(\d+))?))---");
|
||||
std::smatch Match;
|
||||
if (std::regex_search(S, Match, Re)) {
|
||||
const unsigned Major = std::stoi(Match[2].str());
|
||||
const unsigned Minor = std::stoi(Match[3].str());
|
||||
const unsigned Rev = Match[5].matched ? std::stoi(Match[5].str()) : 0;
|
||||
LinuxKernelVersion = LKVersion(Major, Minor, Rev);
|
||||
BC.outs() << "BOLT-INFO: Linux kernel version is " << Match[1].str()
|
||||
<< "\n";
|
||||
return Error::success();
|
||||
}
|
||||
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();
|
||||
|
||||
const std::regex Re(R"---(Linux version ((\d+)\.(\d+)(\.(\d+))?))---");
|
||||
std::smatch Match;
|
||||
if (std::regex_search(S, Match, Re)) {
|
||||
const unsigned Major = std::stoi(Match[2].str());
|
||||
const unsigned Minor = std::stoi(Match[3].str());
|
||||
const unsigned Rev = Match[5].matched ? std::stoi(Match[5].str()) : 0;
|
||||
LinuxKernelVersion = LKVersion(Major, Minor, Rev);
|
||||
BC.outs() << "BOLT-INFO: Linux kernel version is " << Match[1].str()
|
||||
<< "\n";
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
return createStringError(errc::executable_format_error,
|
||||
"Linux kernel version is unknown");
|
||||
"Linux kernel version is unknown: " + S);
|
||||
}
|
||||
|
||||
void LinuxKernelRewriter::processLKSections() {
|
||||
|
||||
Reference in New Issue
Block a user