llvm / llvm/llvm-project

llvm-objcopy's --compress-debug-sections doesn't work for COFF binaries (aka MinGW) while binutils' objcopy work

Open
#190,574 18 comments 0 reactions 0 assignees View on GitHub
tools:llvm-objcopy/strip
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Passed llvm-objcopy with option `--compress-debug-sections`
```
➜ build-mingw-x86_64 git:(develop) ✗ /Users/keeyou/yass-develop/third_party/llvm-build/Release+Asserts/bin/llvm-objcopy --only-keep-debug --compress-debug-sections yass.exe yass.exe.dbg
➜ build-mingw-x86_64 git:(develop) ✗ ls -alh yass.exe*
-rwxr-xr-x 1 keeyue staff 45M Apr 6 09:05 yass.exe
-rwxr-xr-x 1 keeyue staff 44M Apr 6 09:15 yass.exe.dbg
```
Passed llvm-objcopy without option `--compress-debug-sections`
```
➜ build-mingw-x86_64 git:(develop) ✗ rm yass.exe.dbg
➜ build-mingw-x86_64 git:(develop) ✗ /Users/keeyou/yass-develop/third_party/llvm-build/Release+Asserts/bin/llvm-objcopy --only-keep-debug yass.exe yass.exe.dbg
➜ build-mingw-x86_64 git:(develop) ✗ ls -alh yass.exe*
-rwxr-xr-x 1 keeyue staff 45M Apr 6 09:05 yass.exe
-rwxr-xr-x 1 keeyue staff 44M Apr 6 09:15 yass.exe.dbg
```

```
➜ build-mingw-x86_64 git:(develop) ✗ ~/clang+llvm-22.1.2-arm64-apple-darwin20.1.0/bin/llvm-objdump --all-headers yass.exe.dbg > yass.exe.dbg.headers.txt
➜ build-mingw-x86_64 git:(develop) ✗ /Users/keeyou/yass-develop/third_party/llvm-build/Release+Asserts/bin/llvm-objcopy --only-keep-debug --compress-debug-sections yass.exe yass.exe.dbg
➜ build-mingw-x86_64 git:(develop) ✗ ~/clang+llvm-22.1.2-arm64-apple-darwin20.1.0/bin/llvm-objdump --all-headers yass.exe.dbg > yass.exe.dbg.headers.with-compress.txt
➜ build-mingw-x86_64 git:(develop) ✗ diff yass.exe.dbg.headers.with-compress.txt yass.exe.dbg.headers.txt
➜ build-mingw-x86_64 git:(develop) ✗ echo $?
0
```

no .zdebug sections generated.
[yass.exe.dbg.headers.txt](https://github.com/user-attachments/files/26492604/yass.exe.dbg.headers.txt)
[yass.exe.dbg.headers.with-compress.txt](https://github.com/user-attachments/files/26492605/yass.exe.dbg.headers.with-compress.txt)

For comparison, binutils's objcopy works as expected:

Image

You can checked it with .zdebug sections
[yass.exe.dbg.headers.with-binutils.txt](https://github.com/user-attachments/files/26493236/yass.exe.dbg.headers.with-binutils.txt)

BTW the llvm-objcopy I used is coming from 23git aka [this url](https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-23-init-5669-g8a0be0bc-4.tar.xz) or for Linux [this url](https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-llvmorg-23-init-5669-g8a0be0bc-4.tar.xz)
```
➜ build-mingw-x86_64 git:(develop) ✗ ../third_party/llvm-mingw-20250709-ucrt-macos-universal/bin/llvm-objcopy --version
llvm-objcopy, compatible with GNU objcopy
LLVM (http://llvm.org/):
LLVM version 20.1.8
Optimized build.
➜ build-mingw-x86_64 git:(develop) ✗ /Users/keeyou/yass-develop/third_party/llvm-build/Release+Asserts/bin/llvm-objcopy --version
llvm-objcopy, compatible with GNU objcopy
LLVM (http://llvm.org/):
LLVM version 23.0.0git
Optimized build.
```
which is built with zlib support:
```
➜ yass-develop git:(develop) /Users/keeyou/yass-develop/third_party/llvm-build/Release+Asserts/bin/clang -target x86_64-unknown-linux-gnu -gz -c -### -x c third_party/llvm-libc/dummy.c|&grep compress-debug-sections
"/Users/keeyou/yass-develop/third_party/llvm-build/Release+Asserts/bin/clang" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "dummy.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "--compress-debug-sections=zlib" "-fdebug-compilation-dir=/Users/keeyou/yass-develop" "-target-linker-version" "1221.4" "-fcoverage-compilation-dir=/Users/keeyou/yass-develop" "-resource-dir" "/Users/keeyou/yass-develop/third_party/llvm-build/Release+Asserts/lib/clang/23" "-internal-isystem" "/Users/keeyou/yass-develop/third_party/llvm-build/Release+Asserts/lib/clang/23/include" "-internal-isystem" "/usr/local/include" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-faddrsig" "-fdwarf2-cfi-asm" "-o" "dummy.o" "-x" "c" "third_party/llvm-libc/dummy.c"
```

Image

BTW I obtained the copy the mingw binaries from winlibs.com aka [this url](https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-12.0.0-ucrt-r3/winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.7-mingw-w64ucrt-12.0.0-r3.7z)

Image

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported llvm-objcopy command with a COFF/MinGW binary and compare the generated debug-section headers with and without --compress-debug-sections. Use the attached header outputs and the binutils comparison as the expected behavior; done means compressed .zdebug sections are present in the output.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.