From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OUMgKJYRYmqmWykAWB0awg (envelope-from ) for ; Thu, 23 Jul 2026 09:05:26 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=XnmH9eTE; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9EA7C1E099; Thu, 23 Jul 2026 09:05:26 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id DFCCF1E099 for ; Thu, 23 Jul 2026 09:05:25 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F6724BA79B0 for ; Thu, 23 Jul 2026 13:05:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F6724BA79B0 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=XnmH9eTE Received: from hotpink.cherry.relay.mailchannels.net (hotpink.cherry.relay.mailchannels.net [23.83.223.85]) by sourceware.org (Postfix) with ESMTPS id 13B254BA79AD for ; Thu, 23 Jul 2026 13:03:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13B254BA79AD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=palves.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 13B254BA79AD Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.223.85 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784811799; cv=none; b=oHHYaJs6zAIwdANDHcZjpi5mkNTk6ulT/PkF/MrLLYSYFitCf5rF/t5VL5XcroM3uHUfd0Ude/j/2r3eyfUH2KRRU/6BuIEoT3oicUXJgE6UgxSh2TwV2Jjcy6FAthQjObg7+00rVvbfKycbupMHv6fOTNJPv9sJvqLot8KaofA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784811799; c=relaxed/simple; bh=zDFLjMIpOXn3fSdS077Xlmp8prewbWnhPIzKR7oTT8I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=S8ydhC4s6Z5QHVVcvBCjJOjqEvukzMEYvtLmf1IPtoKTMk8Z3WEeur/Lkr5vnZ5vcz9ikaflo1TqDCt9cpEIRQOxPK1wIgsJmczcOPdJiO5VGYXW0QDS2S3bza7hWPzLOrMBZf+wa1oCzR2g0CRQEp+Ko0eJNcPrR+gw0O2e6o4= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=XnmH9eTE DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13B254BA79AD X-Sender-Id: dreamhost|x-authsender|pedro@palves.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 2EF9F4C219D for ; Thu, 23 Jul 2026 13:03:18 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (100-103-89-24.trex-nlb.outbound.svc.cluster.local [100.103.89.24]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 61D5B4C2AD0 for ; Thu, 23 Jul 2026 13:03:02 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|pedro@palves.net X-MC-Relay: Good X-MailChannels-SenderId: dreamhost|x-authsender|pedro@palves.net X-MailChannels-Auth-Id: dreamhost X-Soft-Inform: 7cf2e9f54fb29dee_1784811798057_1816213868 X-MC-Loop-Signature: 1784811798057:2536874427 X-MC-Ingress-Time: 1784811798056 Received: from pdx1-sub0-mail-a249.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.103.89.24 (trex/8.0.2); Thu, 23 Jul 2026 13:03:18 +0000 Received: from localhost (bl20-181-64.dsl.telepac.pt [2.81.181.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pedro@palves.net) by pdx1-sub0-mail-a249.dreamhost.com (Postfix) with ESMTPSA id 4h5WWT6JCWz106Q for ; Thu, 23 Jul 2026 06:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=palves.net; s=dreamhost; t=1784811782; bh=TdBnQxLfUwFLPR37fVij5tyDdADkFa60SKK2pZWUTW8=; h=From:To:Subject:Date:Content-Transfer-Encoding; b=XnmH9eTEl0c0KWoC1ft6tP8P802u8TZ5OxfXn4qFaXEXC/mEgam+69xlcdfMZdjzI rih0Iu5sYOJOCmbsgrpDXmCBjxvPr7ZHFaD0/sfQvipC6T9GzhfFmBK5x8bZT3oKLB 2VIlwVZfk3OiAPZ1fUKcf0+EJhcvyGsE1NqPvVfoHPAhu2xGy5ib+aagE60Xonn2Ty mm4gesuKQ7cyiu78Eb0g/6DFHCn92duEXp1ClnJCmqKVCvKMZsDXvlIo163vO6bWG0 UiA25XtPplkNf8jPK3MHZFMJEP/qwcqTnekVAFuROEWg9LPcVtOrJ4oxvnwib/Ktav 3MPsyVwWh0/QA== From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 08/27] gdb/testsuite: Export all DLL symbols on windows-msvc via generated .def Date: Thu, 23 Jul 2026 14:00:59 +0100 Message-ID: <20260723130118.206735-9-pedro@palves.net> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723130118.206735-1-pedro@palves.net> References: <20260723130118.206735-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org When building a shared library for a test, gdb_compile_shlib arranges for the DLL's symbols to be exported and for an import library to be produced, so that the test executable can link against the DLL. With GNU ld this works implicitly: linking a DLL exports all of its symbols by default. lld-link, which is the linker clang drives on a windows-msvc target, does not do that. It exports nothing unless explicitly told to, via __declspec(dllexport) in the sources, a /EXPORT switch per symbol, or a module-definition (.def) file. The testsuite's shared-library sources carry (almost) no dllexport annotations, so the import library comes out empty and linking the test executable fails, e.g.: lld-link: error: undefined symbol: pendfunc Fix this by restoring the export-all-symbols behavior by generating a .def file that lists every defined, external symbol in the DLL's objects, and passing it to lld-link with /DEF. The symbol list is collected with nm. FWIW, this is the same approach CMake takes for its WINDOWS_EXPORT_ALL_SYMBOLS target property. Change-Id: I1a9638259986910d473c4f02fbf60437e3653e04 --- gdb/testsuite/lib/future.exp | 8 +++++ gdb/testsuite/lib/gdb.exp | 64 +++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/future.exp b/gdb/testsuite/lib/future.exp index ca37fdaaf52..e308bef0a60 100644 --- a/gdb/testsuite/lib/future.exp +++ b/gdb/testsuite/lib/future.exp @@ -224,6 +224,14 @@ proc gdb_find_readelf {} { return [gdb_transform_tool readelf] } +proc gdb_find_nm {} { + global NM_FOR_TARGET + if {[info exists NM_FOR_TARGET]} { + return $NM_FOR_TARGET + } + return [gdb_transform_tool nm] +} + proc gdb_find_windres {} { global WINDRES_FOR_TARGET if {[info exists WINDRES_FOR_TARGET]} { diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index c9ee8e9753d..b3588f0edec 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6812,7 +6812,11 @@ proc gdb_compile {source dest type options} { } if { $shlib_found == 0 } { set shlib_found 1 - if { [is_pecoff_target] } { + # lld-link does not understand GNU ld's + # --enable-auto-import. On windows-msvc the DLL's + # symbols are exported via a generated .def instead. + # See gdb_windows_gen_def_file. + if { [is_pecoff_target] && ![istarget "*-*-windows-msvc*"] } { lappend new_options "ldflags=-Wl,--enable-auto-import" } if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } { @@ -7208,6 +7212,50 @@ proc gdb_compile_pthreads {source dest type options} { } } +# Write a module-definition (.def) file to DEFFILE that exports every +# defined, external symbol found in OBJECTS, and return DEFFILE. +# Unlike GNU ld, which auto-exports a DLL's symbols, lld-link exports +# nothing unless told to, so the import library it produces would be +# empty and executables linking against the DLL would fail with +# undefined symbols. Feeding lld-link this generated .def restores +# the export-all-symbols behavior the testsuite relies on. Returns +# empty string on failure. + +proc gdb_windows_gen_def_file {objects deffile} { + set nm [gdb_find_nm] + + set exports {} + foreach obj $objects { + if {[catch {exec $nm $obj} output]} { + verbose -log "gdb_windows_gen_def_file: nm $obj failed: $output" + return "" + } + foreach line [split $output "\n"] { + # nm prints " ". A defined external + # symbol has an uppercase type letter, undefined (U) has a + # blank value, and local symbols use lowercase letters. + # Export text/weak as code and data/bss/rodata/common as + # DATA. + if {![regexp {^\S* +(\S) +(\S+)$} $line -> type name]} { + continue + } + switch -- $type { + "T" - "W" { lappend exports $name } + "D" - "B" - "R" - "C" { lappend exports "$name DATA" } + } + } + } + + set f [open $deffile w] + puts $f "EXPORTS" + foreach e [lsort -unique $exports] { + puts $f " $e" + } + close $f + + return $deffile +} + # Build a shared library from SOURCES. proc gdb_compile_shlib_1 {sources dest options} { @@ -7310,6 +7358,20 @@ proc gdb_compile_shlib_1 {sources dest options} { } if { [istarget "*-*-windows-msvc*"] } { lappend link_options "ldflags=-Wl,/IMPLIB:${name}.a" + + # lld-link exports nothing by default, so generate a + # .def listing every symbol and feed it in, to get the + # export-all-symbols behavior GNU ld gives us + # implicitly. + set deffile [gdb_windows_gen_def_file $objects ${dest}.def] + if { $deffile eq "" } { + return -1 + } + # Pass the path in Windows-native form so MSYS2's + # argument conversion doesn't mangle the "/DEF:/..." + # value. + set deffile [host_file_normalize $deffile] + lappend link_options "ldflags=-Wl,/DEF:${deffile}" } else { lappend link_options "ldflags=-Wl,--out-implib,${name}.a" } -- 2.54.0