@@ -112,30 +112,41 @@ jobs:
112112 # LLVMSupport.lib. When statically linked into a Rust binary via
113113 # llvm-sys, these collide with ucrt.lib's heap symbols (LNK2005).
114114 #
115- # Fix: remove the rpmalloc object(s) from LLVMSupport.lib and
116- # provide a no-op stub for rpmalloc_linker_reference (called by
117- # InitLLVM.cpp.obj to force-pull rpmalloc at link time).
115+ # Fix: extract all objects, remove the rpmalloc ones, compile a
116+ # stub for rpmalloc_linker_reference, and rebuild the library.
118117 $supportLib = "$LLVM_DIR\lib\LLVMSupport.lib"
119- $llvmLib = "$LLVM_DIR\bin\llvm-lib .exe"
118+ $llvmAr = "$LLVM_DIR\bin\llvm-ar .exe"
120119 $clang = "$LLVM_DIR\bin\clang.exe"
121- if ((Test-Path $supportLib) -and (Test-Path $llvmLib)) {
122- Write-Host "Stripping rpmalloc objects from LLVMSupport.lib..."
123- $listing = & $llvmLib /LIST $supportLib 2>&1
124- $rpMembers = $listing | Where-Object { $_ -match "rpmalloc|rpnew|malloc\.c" }
125- foreach ($m in $rpMembers) {
126- $m = $m.Trim()
127- if ($m) {
128- Write-Host " Removing: $m"
129- & $llvmLib /REMOVE:$m $supportLib
130- }
120+ if ((Test-Path $supportLib) -and (Test-Path $llvmAr)) {
121+ $workDir = "$LLVM_DIR\lib\_rpmalloc_strip"
122+ New-Item -ItemType Directory -Force -Path $workDir | Out-Null
123+ Push-Location $workDir
124+
125+ Write-Host "Extracting LLVMSupport.lib members..."
126+ & $llvmAr x $supportLib
127+
128+ # Remove rpmalloc-related objects
129+ $rpFiles = Get-ChildItem -Filter "*.obj" | Where-Object { $_.Name -match "rpmalloc" }
130+ foreach ($f in $rpFiles) {
131+ Write-Host " Removing: $($f.Name)"
132+ Remove-Item $f.FullName -Force
131133 }
134+
132135 # Provide stub so InitLLVM.cpp.obj's reference resolves
133- $stubC = "$LLVM_DIR\lib\ rpmalloc_stub.c"
134- $stubObj = "$LLVM_DIR\lib\ rpmalloc_stub.obj"
136+ $stubC = Join-Path $workDir " rpmalloc_stub.c"
137+ $stubObj = Join-Path $workDir " rpmalloc_stub.obj"
135138 Set-Content $stubC "void rpmalloc_linker_reference(void) {}"
136139 & $clang -c -o $stubObj $stubC
137- & $llvmLib $supportLib $stubObj
138- Remove-Item $stubC, $stubObj -Force -ErrorAction SilentlyContinue
140+ Remove-Item $stubC -Force
141+
142+ # Rebuild the library from all remaining objects
143+ Write-Host "Rebuilding LLVMSupport.lib without rpmalloc..."
144+ Remove-Item $supportLib -Force
145+ $objs = (Get-ChildItem -Filter "*.obj").FullName
146+ & $llvmAr rcs $supportLib @objs
147+
148+ Pop-Location
149+ Remove-Item $workDir -Recurse -Force
139150 Write-Host "Done — rpmalloc stripped, stub added."
140151 }
141152
@@ -479,25 +490,35 @@ jobs:
479490
480491 # Strip rpmalloc from LLVMSupport.lib (same fix as Build job above)
481492 $supportLib = "$LLVM_DIR\lib\LLVMSupport.lib"
482- $llvmLib = "$LLVM_DIR\bin\llvm-lib .exe"
493+ $llvmAr = "$LLVM_DIR\bin\llvm-ar .exe"
483494 $clang = "$LLVM_DIR\bin\clang.exe"
484- if ((Test-Path $supportLib) -and (Test-Path $llvmLib)) {
485- Write-Host "Stripping rpmalloc objects from LLVMSupport.lib..."
486- $listing = & $llvmLib /LIST $supportLib 2>&1
487- $rpMembers = $listing | Where-Object { $_ -match "rpmalloc|rpnew|malloc\.c" }
488- foreach ($m in $rpMembers) {
489- $m = $m.Trim()
490- if ($m) {
491- Write-Host " Removing: $m"
492- & $llvmLib /REMOVE:$m $supportLib
493- }
495+ if ((Test-Path $supportLib) -and (Test-Path $llvmAr)) {
496+ $workDir = "$LLVM_DIR\lib\_rpmalloc_strip"
497+ New-Item -ItemType Directory -Force -Path $workDir | Out-Null
498+ Push-Location $workDir
499+
500+ Write-Host "Extracting LLVMSupport.lib members..."
501+ & $llvmAr x $supportLib
502+
503+ $rpFiles = Get-ChildItem -Filter "*.obj" | Where-Object { $_.Name -match "rpmalloc" }
504+ foreach ($f in $rpFiles) {
505+ Write-Host " Removing: $($f.Name)"
506+ Remove-Item $f.FullName -Force
494507 }
495- $stubC = "$LLVM_DIR\lib\rpmalloc_stub.c"
496- $stubObj = "$LLVM_DIR\lib\rpmalloc_stub.obj"
508+
509+ $stubC = Join-Path $workDir "rpmalloc_stub.c"
510+ $stubObj = Join-Path $workDir "rpmalloc_stub.obj"
497511 Set-Content $stubC "void rpmalloc_linker_reference(void) {}"
498512 & $clang -c -o $stubObj $stubC
499- & $llvmLib $supportLib $stubObj
500- Remove-Item $stubC, $stubObj -Force -ErrorAction SilentlyContinue
513+ Remove-Item $stubC -Force
514+
515+ Write-Host "Rebuilding LLVMSupport.lib without rpmalloc..."
516+ Remove-Item $supportLib -Force
517+ $objs = (Get-ChildItem -Filter "*.obj").FullName
518+ & $llvmAr rcs $supportLib @objs
519+
520+ Pop-Location
521+ Remove-Item $workDir -Recurse -Force
501522 Write-Host "Done — rpmalloc stripped, stub added."
502523 }
503524
0 commit comments