https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116870
Bug ID: 116870
Summary: Corrupt executable created by GCC 14.2 on Windows
MinGW64 with mingw-w64-x86_64-toolchain
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: zmajeed at sbcglobal dot net
Target Milestone: ---
The debug build of duckdb on Windows MinGW64 produces a bad executable binary -
the release build works fine
DuckDB is large program at https://github.com/duckdb/duckdb - it's built in
MSYS2 MinGW64 on Windows - a debug build takes 25-30 minutes
Here's the resulting executable
----------------------------------------------------------
duckdb -version
-bash: duckdb: cannot execute binary file: Exec format error
ls -l duckdb
-rwxr-xr-x 3289334503 Sep 27 12:32 duckdb
file duckdb
duckdb: PE32+ executable (console) x86-64, for MS Windows, 21 sections
----------------------------------------------------------
I used readobjpe to get more info on the object - it shows section 14
.debug_info is invalid
----------------------------------------------------------
readobjpe duckdb
Reading: duckdb
WARNING section VirtualSize size 0xaf6f51c3 is larger than 2GB and suggests
this object is corrupt
File: duckdb Object type letter: P version: 80
64bit? : yes
filesize : 3301642798
offsetsize : 64
pointersize : 64
ftype : 0
endianness : 2
nthdroffset : 0x00000084
Opt-hdr-offset : 0x00000098
Opt-hdr-size : 0x000000f0
symtab-offset : 0xba562e00
strtab-offset : 0xbd2a358e
strtab-size : 0x07a0dca0
sectable-offset: 0x00000188
nt header
machine : 0x00008664
NumberOfSects : 0x00000016
PtrToSymTab : 0xba562e00
NumberofSyms : 0x0028394f
OptHdrSize : 0x000000f0
Charctrstics : 0x00000026
Optional Header
Magic : 0x0000020b
SectionAlign : 0x00000000
SizeOfHeadrs : 0x00000600
ImageBase : 0x140000000
Display 23 sections.
Section 14 fileoff: 0x00000390
Name: /19 : .debug_info
VirtSize : 0xaf6f51c3 (2943308227)
VirtAddr : 0x0468d000 (73977856)
Raw size : 0xaf6f5200 (2943308288)
Ptr To Rawdata : 0x0467e600 (73917952)
Characteristics: 0x42000040 (1107296320)
----------------------------------------------------------
Here's duckdb docs on setting the Windows environment and building from source
- https://duckdb.org/docs/dev/building/build_instructions
Here are incantations for a debug build that are not documented
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_EXTENSIONS="icu;parquet;json"
-B build -DENABLE_SANITIZER=FALSE -DENABLE_UBSAN=0 -DDISABLE_UNITY=1
cmake --build build --config Debug
The extra cmake options disable sanitizers that are not supported on Windows -
and disable cmake unity build to compile each source file separately
I tried a build with -gdwarf-4 but it also produced a bad executable
----------------------------------------------------------
Snippets from build logs
[749/2146] c++.exe -DDUCKDB -DDUCKDB_BUILD_LIBRARY
-DDUCKDB_EXTENSION_ICU_LINKED=1 -DDUCKDB_EXTENSION_JSON_LINKED=1
-DDUCKDB_EXTENSION_PARQUET_LINKED=1 -DDUCKDB_MAIN_LIBRARY -Isrc/include
-Ithird_party/fsst -Ithird_party/fmt/include -Ithird_party/hyperloglog
-Ithird_party/fastpforlib -Ithird_party/skiplist -Ithird_party/fast_float
-Ithird_party/re2 -Ithird_party/miniz -Ithird_party/utf8proc/include
-Ithird_party/concurrentqueue -Ithird_party/pcg -Ithird_party/mbedtls/include
-Ithird_party/jaro_winkler -Ithird_party/yyjson/include -Iextension
-Iextension/icu/include -Iextension/parquet/include -Iextension/json/include -g
-g -O0 -DDEBUG -Wall -Wunused -Werror=vla -Wnarrowing -pedantic -Wextra
-Wno-unused-parameter -Wno-redundant-move -Wimplicit-fallthrough -std=c++11 -MD
-MT
src/function/table/system/CMakeFiles/duckdb_table_func_system.dir/duckdb_optimizers.cpp.obj
-MF
src\function\table\system\CMakeFiles\duckdb_table_func_system.dir\duckdb_optimizers.cpp.obj.d
-
o
src/function/table/system/CMakeFiles/duckdb_table_func_system.dir/duckdb_optimizers.cpp.obj
-c src/function/table/system/duckdb_optimizers.cpp
[2143/2146] cmd.exe /C "cd . && mingw64\bin\c++.exe -D_POSIX_C_SOURCE=200809L
-g -g -O0 -DDEBUG -Wall -Wu
nused -Werror=vla -Wnarrowing -pedantic -Wextra -Wno-unused-parameter
-Wno-redundant-move -Wimplicit-fallthrough -shared -o src\libduckdb.dll
-Wl,--out-implib,src\libduckdb.dll.a
-Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\duckdb.rsp &&
cd ."
[2144/2146] cmd.exe /C "cd . && mingw64\bin\c++.exe -D_POSIX_C_SOURCE=200809L
-g -g -O0 -DDEBUG -Wall -Wunused -Werror=vla -Wnarrowing -pedantic
tools/shell/CMakeFiles/shell.dir/shell.c.obj -o duckdb.exe
-Wl,--out-implib,tools\shell\libduckdb.dll.a
-Wl,--major-image-version,0,--minor-image-version,0
tools/sqlite3_api_wrapper/libsqlite3_api_wrapper_static.a
src/libduckdb_static.a extension/icu/libicu_extension.a
extension/parquet/libparquet_extension.a extension/json/libjson_extension.a
src/libduckdb_static.a extension/icu/libicu_extension.a
extension/parquet/libparquet_extension.a extension/json/libjson_extension.a
-lws2_32 -lrstrtmgr third_party/fsst/libduckdb_fsst.a
third_party/fmt/libduckdb_fmt.a third_party/libpg_query/libduckdb_pg_query.a
third_party/re2/libduckdb_re2.a third_party/miniz/libduckdb_miniz.a
third_party/hyperloglog/libduckdb_hyperloglog.a
third_party/fastpforlib/libduckdb_fastpforlib.a
third_party/skiplist/libduckdb_skiplistlib.a
third_party/mbedtls/libduckdb_mbedtls.a third_party/yyjson/libduckdb_yyjson.a
third_party/utf8proc/libduckdb_utf8proc.a -lkernel32 -luser32 -lgdi32
-lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
----------------------------------------------------------
c++ --version
c++.exe (Rev1, Built by MSYS2 project) 14.2.0