Skip to content

Fix mimalloc patching #79716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ function Invoke-Program() {
[string] $Executable,
[switch] $OutNull = $false,
[string] $OutFile = "",
[string] $ErrorFile = "",
[Parameter(Position = 1, ValueFromRemainingArguments)]
[string[]] $Args
)
Expand Down Expand Up @@ -585,16 +586,23 @@ function Invoke-Program() {

if ($OutNull) {
$OutputLine += " > nul"
} elseif ("" -ne $OutFile) {
} elseif ($OutFile) {
$OutputLine += " > `"$OutFile`""
}
if ($ErrorFile) {
$OutputLine += " 2> `"$ErrorFile`""
}

Write-Output $OutputLine
} else {
if ($OutNull) {
& $Executable @Args | Out-Null
} elseif ("" -ne $OutFile) {
& $Executable @Args | Out-File -Encoding UTF8 $OutFile
} elseif ($OutFile -and $ErrorFile) {
& $Executable @Args > $OutFile 2> $ErrorFile
} elseif ($OutFile) {
& $Executable @Args > $OutFile
} elseif ($ErrorFile) {
& $Executable @Args 2> $ErrorFile
} else {
& $Executable @Args
}
Expand Down Expand Up @@ -1811,9 +1819,17 @@ function Build-mimalloc() {
foreach ($Tool in $Tools) {
$Binary = [IO.Path]::Combine($Arch.ToolchainInstallRoot, "usr", "bin", $Tool)
# Binary-patch in place
Start-Process -Wait -WindowStyle Hidden -FilePath "$SourceCache\mimalloc\bin\minject$BuildSuffix" -ArgumentList @("-f", "-i", "-v", "$Binary")
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-f" "-i" "-v" "$Binary"
# Log the import table
Start-Process -Wait -WindowStyle Hidden -FilePath "$SourceCache\mimalloc\bin\minject$BuildSuffix" -ArgumentList @("-l", "$Binary")
$LogFile = "$BinaryCache\$($Arch.LLVMTarget)\mimalloc\minject-log-$Tool.txt"
$ErrorFile = "$BinaryCache\$($Arch.LLVMTarget)\mimalloc\minject-log-$Tool-error.txt"
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-l" "$Binary" -OutFile $LogFile -ErrorFile $ErrorFile
# Verify patching
$Found = Select-String -Path $LogFile -Pattern "mimalloc"
if (-not $Found) {
Get-Content $ErrorFile
throw "Failed to patch mimalloc for $Tool"
}
}
}

Expand Down