From patchwork Wed Sep 30 09:33:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Bacci X-Patchwork-Id: 144994 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89DA44BB3B9A for ; Wed, 30 Sep 2026 09:35:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89DA44BB3B9A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=jYbWC1ZY X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazolkn19013086.outbound.protection.outlook.com [52.103.33.86]) by sourceware.org (Postfix) with ESMTPS id 012594BB24E6 for ; Wed, 30 Sep 2026 09:34:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 012594BB24E6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=outlook.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 012594BB24E6 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.103.33.86 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1790760849; cv=pass; b=KTcy2nuUsrlsfc6M9wOUIlDG2O2uIcLIvWx9YcBEcJnC8hlg5cDNMj5kI/pI6Q8U7askJPEdNoetRhOib7LqWVS34mrw5qLdHbgKTHD/WraoMrJsyfYx20KHiXPSy4c0by7M0qRnJ3qz5xPbRvi7hN7cEl6t69yBpaEzYNpcJrg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1790760849; c=relaxed/simple; bh=YJoP5P6dGUaxjnnKz2/6I9SSvbZ0g4ulwnIAW2Ghyy0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xxD21OxySK7+ZjJ2pbtd6ukA5qPeXOgTejJJZRJj8+nCEbdy+oQBERFqeJYh4GzIPEIvbGENYP+EmyQPEYFCjM6FcJWizdPqTs7kvNjuDfItj/E0WtRE3DUUWHX5o4k8b/+FWq6WblXRVRAUsDbLacTPg/nb+l3xlsQJLnP22z4= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=jYbWC1ZY DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 012594BB24E6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=h7CkXJ5TfXe0bDNl3UGKVDwVxRXf1giV6AO5VF2jtiAHTWbC0qZzlU9fptQphtqXcI+TPsEQYIopWv6IiXd94ybgXeU1PEw1NBwa5STAmTxPR4jx4v3X7kACRz50V1I0cSZlAInEQFCy6EfQhlfXPQcowb+GqMgMyM5r60mjxQ6oOeywnogoXxGRW52n9PyC2+5lDwjMx9FtgcEqlfdw7epQ7i4Cqq2vA7YG5vC0yTJ9vxdWGxR8pZAAZRuxb4GE2lZvpQMyK4a5z0hFMBf9/JSoo7rwoemJR8u8hT/8ZBVBy2oSdu5vu4iks+UEV1LUexGp8kcjr0SSPSik0ZqU0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O957FtBgdNNwwGgbDbH5IVhQXH/XxPRZLmO0qf+KN/s=; b=Bq05ndbEfo7+OFbmKnDjH/n77KW85vtSEjn7S9EfZCPHxP+lLm6hsg0disl+T8swIj9fIKSrvEfrD0m1CnDoir2hNnr5CpRaKFEOEILwrA8bHstO7Egn2oqy1NjKt82Bv9Av/JaWf+qzAxrgiqjPqXLZzu8NX3B3/soNvQukdINpvjvP3lOBuvsEe6ojtnZTFRkjYtPE0qpciq98StvCLupB64gV8K6s7D/8tVaoHqvS/z9LvC/RiMXqsdF3hbxVcpSRTBa3woi2UAAdAzVmzvpK4nGaJWqlb9oahuyPIoqKB8c11ClNJiNxZNJ3DnsbiF17tP4Yu+xj3Gtl1QOt4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O957FtBgdNNwwGgbDbH5IVhQXH/XxPRZLmO0qf+KN/s=; b=jYbWC1ZYSen8k4m9KvZuY9I6b/aw9VIyH/c9Wucs0I5sPUndFObvOKKqhkKLhV3ftDQKP3CIdmzov1XCOC4xv74X8JIgwBUSYhvVL3EuiXMNftmMavw8Qhvg3SPhak1QSgOepSlMKSXh8qNsAvYelTOSd4YwteHZFBY2DxOf47iA9zYBrYHMp3PrKYjVnW/dT0Euiqz5JGHslHFh9f1nN7aCabArJe9HDKLtMTOI/ueZ0Akwz0Okies7DVjWOdOA5L1bThNCLKy1Vy1cbX2vb1dkkc+0s2S243B2kotbzACm6HaUAwvghFVtTKnrYhkr0g4vFCZEM1lkm714prerjQ== Received: from AS4PR02MB7902.eurprd02.prod.outlook.com (2603:10a6:20b:4b2::9) by PAVPR02MB9521.eurprd02.prod.outlook.com (2603:10a6:102:305::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.23; Wed, 30 Sep 2026 09:33:59 +0000 Received: from AS4PR02MB7902.eurprd02.prod.outlook.com ([fe80::2a24:bc25:8b55:3de8]) by AS4PR02MB7902.eurprd02.prod.outlook.com ([fe80::2a24:bc25:8b55:3de8%5]) with mapi id 15.21.0451.022; Wed, 30 Sep 2026 09:33:58 +0000 From: Luca Bacci To: binutils@sourceware.org Cc: mingw-w64-public@lists.sourceforge.net Subject: [PATCH 1/2] ld-pe: Refactor code dealing with -exclude-symbols Date: Wed, 30 Sep 2026 11:33:51 +0200 Message-ID: X-Mailer: git-send-email 2.55.0 X-ClientProxiedBy: MI2PEPF00000B7B.ITAP293.PROD.OUTLOOK.COM (2603:10a6:298:1::411) To AS4PR02MB7902.eurprd02.prod.outlook.com (2603:10a6:20b:4b2::9) X-Microsoft-Original-Message-ID: <20260930093352.378-1-luca.bacci@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS4PR02MB7902:EE_|PAVPR02MB9521:EE_ X-MS-Office365-Filtering-Correlation-Id: 77a0e57a-b9d7-4298-09ed-08df1ed5f435 X-Microsoft-Antispam: BCL:0; ARA:14566002|19110799012|8060799015|4140399003|25010399006|24021099003|23021999003|41001999006|5072599009|15080799012|260925184616899003|40105399003|52005399003|12091999003|2607281247196008|440099028|3412199025; X-Microsoft-Antispam-Message-Info: B1/FDb4D8vcU6ZI8xy1tvFnAJ3MBFV633r9ym1nW605Rdniqp68ucZNBOvoMcJ11GQDS7pQi1+dpKnjI93/RDuCrcLxM4+goltvU9u6dJvaO9vD4L0d+uLAGt5EHxw7TBa1JgBmLYZZ2Z/HA+V4F5mfPmHR8EAMn0Sg2rtsgtx0K0FiPplZujX3mfMwzZAyoxv5OQGlCyECE8tkt+kqipFzGvVRCVvm1dfq+2Lpyyg8MTRfJ2wAVUlgi64JuJHklQ29pyyUKyingTiL8OYt5Oc/coIb8FThvc1+NyqHS69bF8r07FPQ3htclVedEtTUUeY9gq4Khw31+NR2d64Vzanym6S+Jbl5FCslocQgB19HBjje57RKKGl+RTvILM9XEbGDeE6noo0IFuKbNcVI8qpcjuoSQWisItpWst0kmQNHvb1WP9JL30++YrmY5EVprF7wQPcKFdARVG5fcC+daPCSxRsGdavyiwLJIzBybZSMPkY5zoXUdtFwA6WKDjfQbvLmuVBMy/NawxiwroncJ84ldPmhkP+5qw/DFprOxPZy9OI8gLcDFWweNvy0YNLjzuk+jbrbutrG1gtb1VsEvyL3/FBMwXK3/zt2iUp++o3O5dyKjhlzic0vupitkQBtkIeMg/XPnm3/w96Ntlq91kXTA8Mk4JPzxsgvTupKrpbCFTsnyU5aHuxhOyOBoSZjk30t9ruCQ/b01d60OqHDmB+7OS+arlhtajuB5dSvUnWO2tXBrYXkZ1DznHvp7eIyT8G48Ld7ddetVib3DjxCYoTyPzIhsQhD6TyORHE5WJ4qKw79kiHkMUXGnCV78+qaXMv5INn+F9cWrm/jRHnd/D2+F/nRLJmI+VdDuAqfMs4u6dsKRI7sX//9EU7dn3aqz8lGPhU3VFtpCkPwgYyEViUDClL0rKLGgc45JMLhOBh9dYM5cL/xKCvLty3+oaoyekgR9G5a2GHv2T2WCjWXb0rp3MNVRn+7QwkaKyEKBxutIjuQQAAoHLVN8pVSLG2Fg X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: E3ViT7pVFqPTdcdt9YZVEu4cisAwoYm2kA88yDGjsPFLJbbPCG9aDJXIQ4AY4qXpwvyrVr8NIQZ8p6gNW5LjsiYMmjuszWvkyEnK/uq+BoztA0s0NPWaCWvLVaVaPtuza1SK4qnGFuCpPZGFjRxJP5JD2GT8NB16S5VnTOteUy3hxG1E3LzJMNzjXv3eziqG4jlbstVAlXJLaMnv2Mz57aDgemF+Fcb1xZp+envk4ETiHOBB5ZmN+l8VOa+fiFieGAdyhRJmHKJ6c2E/KfWm52e5jvX/JdQ9j+EBRCk6yoHFbLzVQB0dW7FdT6nyOUaiLxqVAir1cKgJkAPtTdcLfyW031GVlHY316Fnm6k3JBuXA3CgAhZmeAjeYIWpg51tFZnRAqTWt9lKiUUKnm7IiFj3wxk7cQZkY7bM2NFZBitN9s1wPOPHswzu4Cn2ItKbig2DWdIbKeX9AnxPO8XmA3bickOK2j7WJsnNgp68eg8R1ellhhCxjjmIc/qAmqjjbj+4hzClb43Qe/ygRiapJhIb+okZSlF8dJhQm3llUspzjosu08N4l7AemOFE18mwSSpNo01KYl5zD2HoqY55U5GBWX/eGHvqCPnwDOMW7e5mOWzv+z3qiSNXejkAvSiIYJ2FFBYZzaWRgDLA5qnvcKwOQ97ZjSLCMVj7suq7Vsp1mPNOLX5xuMcb9zEM5uhLGcG8y16WKdYX8/2//0J4sg0TWDt3ko7AUzHLWu+QiprxQlXllIAlfHafC7+K3zdbuQ07NoxxN6Ma5buRQs25ggx/UsLCmsFsxXjkP3J5XpMDR3rAmnC9h8rwmNHpZgLymRmxZI39+NrzNZkmSCjncWnzsCSTl43BG+u99GCzjTF0OqO6ITCLYFjZwL9HT7uTiNnGnW6nekIN1A7nxIVm69UUXlu1084XXTfoQVt1tp63tThAQDSQhgjYXdLBsdyHAjbRCZhw/U8IlprlokRbl8ebN9YgAOpsTlt8GJWcBUrz5bNcFxwrTUOCTzm5GqeOfiuLFYkblNEocnPsKMgt4oFeq7gVLba54/NNB9zgSGubGdVf0YjVqrb8W6m/2ONa3VCfYZCL/H19iffQHuPylo9qyqJ9a8v4sZRkD1ZsxqjfgO0WY7sDNpwMK4uG+F04hLHiDTpNMHVTJKVdMthIYd1gp8KLjE0OEbQuF8X+IX2q7tTM0fzxumwe9sYgnJBY28nhxHNQaHmuXHod4t5BgFlAONgw8yllZ+2IqXBDnrqEswWq25TGPfayU3yeG6iDC2qiP0hCcOsjkSEVga0Q2ZacF/2IZtJwEZ/FGI6pFj7xHkt+MA/Fqo6HrwDy9bvLFylQ3FEJItyHXZ448sZLyyaWzKYpslXOkwyTw9+ojWkOyebFD28tCtf6MG3SpGeQ X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77a0e57a-b9d7-4298-09ed-08df1ed5f435 X-MS-Exchange-CrossTenant-AuthSource: AS4PR02MB7902.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 09:33:58.8590 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR02MB9521 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GB_MSAUTHSOURCE_EUROPE, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org Make it more generic. We'll make use of that code in the next commit. --- ld/deffile.h | 12 +++--- ld/deffilep.y | 115 +++++++++++++++++++++++++++++++------------------- ld/pe-dll.c | 10 +---- 3 files changed, 79 insertions(+), 58 deletions(-) diff --git a/ld/deffile.h b/ld/deffile.h index 83bc4b1c..9269d488 100644 --- a/ld/deffile.h +++ b/ld/deffile.h @@ -61,9 +61,11 @@ typedef struct def_file_aligncomm { unsigned int alignment; /* log-2 alignment. */ } def_file_aligncomm; -typedef struct def_file_exclude_symbol { - char *symbol_name; /* Name of excluded symbol. */ -} def_file_exclude_symbol; +typedef struct def_file_symbol_list { + char **array; /* Sorted array of symbols names. */ + unsigned int count; /* Count of entries in the array. */ + unsigned int allocated; /* Count of allocated entries in the array. */ +} def_file_symbol_list; typedef struct def_file { /* From the NAME or LIBRARY command. */ @@ -102,9 +104,7 @@ typedef struct def_file { def_file_aligncomm *aligncomms; /* From EXCLUDE_SYMBOLS or embedded directives. */ - unsigned int num_exclude_symbols, max_exclude_symbols; - def_file_exclude_symbol *exclude_symbols; - + def_file_symbol_list exclude_symbols; } def_file; extern def_file *def_file_empty (void); diff --git a/ld/deffilep.y b/ld/deffilep.y index e715c4d2..bac19249 100644 --- a/ld/deffilep.y +++ b/ld/deffilep.y @@ -377,6 +377,9 @@ struct directive static struct directive *directives = 0; +static void +symbol_list_clear (def_file_symbol_list *symbols); + def_file * def_file_empty (void) { @@ -441,7 +444,6 @@ void def_file_free (def_file *fdef) { int i; - unsigned int ui; if (!fdef) return; @@ -493,11 +495,7 @@ def_file_free (def_file *fdef) free (c); } - for (ui = 0; ui < fdef->num_exclude_symbols; ui++) - { - free (fdef->exclude_symbols[ui].symbol_name); - } - free (fdef->exclude_symbols); + symbol_list_clear (&fdef->exclude_symbols); free (fdef); } @@ -948,37 +946,44 @@ def_file_add_import_at (def_file *fdef, points at an element which is identical to the one searched for. */ static unsigned int -find_exclude_in_list (def_file_exclude_symbol *b, unsigned int max, - const char *name, bool *is_ident) +symbol_list_find_entry (def_file_symbol_list *symbols, + const char *name, + bool *is_ident) { int e; unsigned int l, r, p; *is_ident = false; - if (!max) + + if (symbols->count == 0) return 0; - if ((e = strcmp (b[0].symbol_name, name)) <= 0) + + if ((e = strcmp (symbols->array[0], name)) <= 0) { - if (!e) + if (e == 0) *is_ident = true; return 0; } - if (max == 1) + + if (symbols->count == 1) return 1; - if ((e = strcmp (b[max - 1].symbol_name, name)) > 0) - return max; - else if (!e || max == 2) + + if ((e = strcmp (symbols->array[symbols->count - 1], name)) > 0) + return symbols->count; + else if (e == 0 || symbols->count == 2) { - if (!e) + if (e == 0) *is_ident = true; - return max - 1; + return symbols->count - 1; } - l = 0; r = max - 1; + + l = 0; + r = symbols->count - 1; while (l < r) { p = (l + r) / 2; - e = strcmp (b[p].symbol_name, name); - if (!e) + e = strcmp (symbols->array[p], name); + if (e == 0) { *is_ident = true; return p; @@ -988,45 +993,67 @@ find_exclude_in_list (def_file_exclude_symbol *b, unsigned int max, else if (e > 0) l = p + 1; } - if ((e = strcmp (b[l].symbol_name, name)) > 0) + + if ((e = strcmp (symbols->array[l], name)) > 0) ++l; - else if (!e) + else if (e == 0) *is_ident = true; + return l; } -static def_file_exclude_symbol * -def_file_add_exclude_symbol (def_file *fdef, const char *name) +static void +symbol_list_add (def_file_symbol_list *symbols, + const char *name) { - def_file_exclude_symbol *e; - unsigned pos; + unsigned int pos; bool is_dup = false; - pos = find_exclude_in_list (fdef->exclude_symbols, fdef->num_exclude_symbols, - name, &is_dup); + pos = symbol_list_find_entry (symbols, name, &is_dup); /* We need to avoid duplicates. */ if (is_dup) - return (fdef->exclude_symbols + pos); + return; - if (fdef->num_exclude_symbols >= fdef->max_exclude_symbols) + if (symbols->count == symbols->allocated) { - fdef->max_exclude_symbols += SYMBOL_LIST_ARRAY_GROW; - fdef->exclude_symbols - = xrealloc (fdef->exclude_symbols, - fdef->max_exclude_symbols * sizeof (*fdef->exclude_symbols)); + symbols->allocated += SYMBOL_LIST_ARRAY_GROW; + symbols->array = xrealloc (symbols->array, + symbols->allocated * sizeof (symbols->array[0])); } - e = fdef->exclude_symbols + pos; - /* If we're inserting in the middle of the array, we need to move the - following elements forward. */ - if (pos != fdef->num_exclude_symbols) - memmove (e + 1, e, sizeof (*e) * (fdef->num_exclude_symbols - pos)); - /* Wipe the element for use as a new entry. */ - memset (e, 0, sizeof (*e)); - e->symbol_name = xstrdup (name); - fdef->num_exclude_symbols++; - return e; + /* If we're inserting in the middle of the array + * we need to move the following elements forward. + */ + if (pos != symbols->count) + { + memmove (symbols->array + pos + 1, + symbols->array + pos, + (symbols->count - pos) * sizeof (symbols->array[0])); + } + + symbols->array[pos] = xstrdup (name); + symbols->count++; +} + +static void +symbol_list_clear (def_file_symbol_list *symbols) +{ + unsigned int ui; + + for (ui = 0; ui < symbols->count; ui++) + free (symbols->array[ui]); + + free (symbols->array); + + memset (symbols, 0, sizeof (*symbols)); +} + +static void +def_file_add_exclude_symbol (def_file *fdef, + const char *name) +{ + symbol_list_add (&fdef->exclude_symbols, name); } struct diff --git a/ld/pe-dll.c b/ld/pe-dll.c index f43bd148..6fb3dce2 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -781,14 +781,8 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info * } } - if (pe_def_file->exclude_symbols) - { - for (ui = 0; ui < pe_def_file->num_exclude_symbols; ui++) - { - pe_dll_add_excludes (pe_def_file->exclude_symbols[ui].symbol_name, - EXCLUDESYMS); - } - } + for (ui = 0; ui < pe_def_file->exclude_symbols.count; ui++) + pe_dll_add_excludes (pe_def_file->exclude_symbols.array[ui], EXCLUDESYMS); /* If we are building an executable and there is nothing to export, we do not build an export table at all. */ From patchwork Wed Sep 30 09:33:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Bacci X-Patchwork-Id: 144993 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F38BD4BB1C2A for ; Wed, 30 Sep 2026 09:35:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F38BD4BB1C2A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=YUxjfo84 X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazolkn19013086.outbound.protection.outlook.com [52.103.33.86]) by sourceware.org (Postfix) with ESMTPS id 30DAE4BB24F1 for ; Wed, 30 Sep 2026 09:34:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30DAE4BB24F1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=outlook.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 30DAE4BB24F1 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=52.103.33.86 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1790760852; cv=pass; b=v0NiJeFvIG+br2FPzy+g6i0/Y5NfgApWsOew5g9bv0++CYYzC8H1sSuXDzA5qDo8S6ySTjwrkaniCPzRDow5cVmSSQiIadKZ3uZF3GlD0sKH+xwtR9rkBNNbhepzfseIOKGcVD4uk7QZaRvqAMG0FK9DylJoAIsjpqkhuZhuqIg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1790760852; c=relaxed/simple; bh=NBUce5SjgEnrR19UpMy+K9txMVSfJPQLwtob/EyCi+A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=srHXbgQeuGgq/CLcXjV6N4Th7RiDZloMwanAuaDjDr9zs52mAFAo0EkPpLoajOXfaSmxsVqAvlliiF0zA0FAKmh5D67fpxPI9k7gp3ii2yzTBDvUHVVoaVc8ifhIHbWIjjtJ2vtomMA/HG1gDKG0Mdy5KaxFFGPVhyPRvhlOLIs= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=YUxjfo84 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30DAE4BB24F1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TVyT7/gOIqvha6D2mVcW7TQq96uXbjf9hs0pdPq5hz6+OHNwSK0TSRoxP6pxtBt2d7882LZHD0sU68sbXuQhNfuFPjyUk8Qveb21I1Z8hqrgZ204egzM7fhy9Tox4sd9gzEgC5PeuyuqqsRAhPwmuJYY7bOIwO79fLN3qq4gGaulXtvahfPwybjZCGuCnWKGQDyeC3XNPTithCHt+8Ra4+rEc5oVhwVpMPMppngjDZVOtvjjUO4OVlqKvcGfzbOOqV+wsjUazJRzqu7p7WNxl0+hks4bJUty57VRHGiRl9M+0AyIm8pbeoKDStA9ryW+YImU+yUSWVwMVX+7lCkSyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Gl4IA/RViIGpWKXjq+LZT2sGdpYNNloxUO3A774vHwg=; b=ltVZNtoOoR1ep92MBBdhBf6gL/F7j4YE/KHtuoqsVADcFbgOZId905snrGViK579wCRZFGnXB6n6wtpXh9AqTbcVIoEhdX2TZxwksW16T6iL48pGD7FKaktgRxtljx7AVqffKElFmSG9x9y8pngvatw9QMwTPVjA/xgcNSZWEk+bRJIRm3wtHBnYYro6beGObPP9boGfvtA7qRbUWLxLsxDBODoAv11LPJdsv/zdKMQBaGFswCVhvlmjAu/wMoys4fKo9Y9fIxLpU3e2max3uYy20yNHMIHaB+WOcUlWO0IQnN+sqn3lF47m6ikDXnzLCYgo+uYm0mqvWEuqYuGZMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gl4IA/RViIGpWKXjq+LZT2sGdpYNNloxUO3A774vHwg=; b=YUxjfo841q6fJ8H7Lsom+LmTtxY5wrRXEFv4vnpe6J94V0a0IHDe4VWjJGXhk5he1nWvvl2CGLclT6ABIwxAcpei0v4Tc4d/g09+sCfeJ4ROlJ0RYB6tqglU3/1rGUZ1l0t6wTPfaiae3HcE4RBl59S6QRJeX0PRc8QcdkOpJ/W2XsqdwOyd04Rt5pFeLtctVzziqgO8ZiGGrljYhAtAI1ULT2x+jY33kFSuq5VBOXVhWVqDCj4cG4j0mLExI+3+CmTl7lQMltI6Rbch4AKPJ3qdy0htfi/FBxsZTYO7BUN3YaVtr7zAXYBIHkzWfT8b3zt0PljypvJar6Yg2Oks0A== Received: from AS4PR02MB7902.eurprd02.prod.outlook.com (2603:10a6:20b:4b2::9) by PAVPR02MB9521.eurprd02.prod.outlook.com (2603:10a6:102:305::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.23; Wed, 30 Sep 2026 09:34:07 +0000 Received: from AS4PR02MB7902.eurprd02.prod.outlook.com ([fe80::2a24:bc25:8b55:3de8]) by AS4PR02MB7902.eurprd02.prod.outlook.com ([fe80::2a24:bc25:8b55:3de8%5]) with mapi id 15.21.0451.022; Wed, 30 Sep 2026 09:34:07 +0000 From: Luca Bacci To: binutils@sourceware.org Cc: mingw-w64-public@lists.sourceforge.net Subject: [PATCH 2/2] ld-pe: Add support for -undefined, -include directives Date: Wed, 30 Sep 2026 11:33:52 +0200 Message-ID: X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930093352.378-1-luca.bacci@outlook.com> References: <20260930093352.378-1-luca.bacci@outlook.com> X-ClientProxiedBy: MI2PEPF00000B7B.ITAP293.PROD.OUTLOOK.COM (2603:10a6:298:1::411) To AS4PR02MB7902.eurprd02.prod.outlook.com (2603:10a6:20b:4b2::9) X-Microsoft-Original-Message-ID: <20260930093352.378-2-luca.bacci@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS4PR02MB7902:EE_|PAVPR02MB9521:EE_ X-MS-Office365-Filtering-Correlation-Id: 4179f76f-1684-46a6-7474-08df1ed5f93c X-Microsoft-Antispam: BCL:0; ARA:14566002|51005399006|19110799012|8060799015|12121999013|25010399006|24021099003|23021999003|5072599009|15080799012|260925184616899003|40105399003|12091999003|10035399007|2607281247196008|440099028|3412199025; X-Microsoft-Antispam-Message-Info: tyqvEblRaNsSTHtZHy8GE5gwgBn84TgT0PHK3lFlgqfFrNjQJeBdxqkO9cXRJN741ZCV0x3IunLwMe1ltB6CWTkdrIKey9u+pr7MzBu/+Tm06Eo4F0eO21i1fyU+bipaDLiYT/VKgwG1JbihGVEn/GydWdBtSCqZdRYjcetaXELuHD1Kiti0XfdybOcZRG8EhS+i/LbcuIVqT+AcKDUX2UiKDsy7HK09Wg0SQau0VMGFnmL9UdNzWEwshEPUIqGfjQZaauxiXNpB1m3JaGWthzd3ErhdEc78XOunXbAhksAUkuki1LQPIZPpdH1lTXK5PF2JNywB56UCleNcXoZgn/miIkHy+z+7FjpqpS76qKBgfsEm6meistWvpGn1Vm0/fekn98mKd/FLodRabegtG+IlHAz4rokV+8RL7/a64W3T5+AQYRHo1G3OrV3i9YOI9AZ40e+Us9N+zG0t/Cce/QF69ULAGqI60Ch5Ki4hYMAq12SvLBMURNvBsF1kevIfBLsalEN/lAQYEoXwwKbiZEzwJwxMGG3k18ng4NFFm2V+slh4CckLsTB9Jo93ts+/6YToEg4WpUVi9RmjcmKdybv5p1tGQuQ/InuupBD0AeD765IYbFgKyqHFq3Cfoz/Z0zNrhyw1hZVLPSZFK+XJ97hZMHOSNh2C8rWS4s5eH26pDPLlZ65nh6sa/sUWKc+YracGO1BERaXGOxlGlBDHHOz7ek9m/5uh5kzvsIeSoF+EMPgqQNI2H74klULjAYk8LSKJ/g+ZWqroTQ2YRVf6rB9BonN2u7vBcWfqMk1uHjUCC4xyeyXfQmjt1DfU46rtb4VWm9LMRDoGncBll5Z9oxAKkQJkJ0nloOxSIvYm8+FANFc1TVNDWSFlhv8rdLfgt/eoTEFd7paFOqDqwBBKi8lVN+/YZ/nocZMQrIHr3wruo5/5WZPn7Fs8+Z+kPMW/1IaWtljmbU6ZYX5oHNUlf1dShPZ/bzg2UDRbVNFe+a8= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: znU1GeOBn+H3LK+cyBt43O1LzrYukex3IkxMJtL7IiLy8RmErzoFd+bfJc3FQOOhvUiDsMwnDb8RXXJy0m3WZkYJzbz2OHOzrOph8WG9TuJ4HGuhqVrREHqy3VKP2yN0X4vosll7/DCMw5G+EZn/z0tT9hsucWcsYpcfNxsJlm+Aw00dKMH+RHygi6/ediwnyGZLg1BUc0pmNO/vd5K6sJfFwDxObBcFX9J91ssJjnLNTbbkv4HIKi7OHULLkQDflUUjgS0cxtIzBIipPfFGL79NdNoO/3wJHVxjpHk4BrqLMAhslFOBqxZKDeoofhTbh0/Mi+oURzSbIAbcwxvYJ8tFJt1KMdtRRTlhcf3RNfN2oCaA/e85ToCGMW0XZc3CO4L1+J73+ImW0vRcu+S8kPNtLK5YVIswgM5ba73elTgvmJHSg4d7B7Z8IKwe5zs9qhErYml3OqauFfT02yoh1kzvLoxkiqzi1Q7i3xyllR6H5t/wYBWwOVAHHrWVJ33+jXtAusAWLnSXQXFFzoQZOf84Mxs6dFtfcwv9ewlEVncmwQsRO1svHcP25uKH9o1CMvdC+beVoIIsNhlTybgYyNBk4lSL9s+eiNk0w+ZzlH2nm/4RiMDc79E4m5X1auPIfZ0f9pOiCffjtE1sXgi5334gMlWNrymLy9E7DDEjnJypLuDtpBzBji/fM2Vy9XteDLJjG65RKCkUtudar7mJQkucZl8YpsFh9brIFPxaTXeDxvq8zX9KDh6T6eKRCWgLC7iR/zQjcsfqKSqhXf02GzjUNzlpr1hwjgGe2JWhwOm2erg3DPfnyPCwAbuDjPJNDKIjjO/UGTaUlSI/UcnvDguAo6RmNebuEImjgZJj51SoOZoBEob9IZWrCGyxKDPaWTS+89G50/jfePj1doRw/slxx9Tmchi/CKjtRsZS3MOLuZFIlCx6hDwr30vN7zaEk9aQizrPxaS0mRweydP5HrQ9DQIko7WqZIp86Zpumt0t7WBs81YgJ6yFidKefy/pTDvxWhfE1rULvNsC7nUCD26d7dwTqnSWwxy6vgv2o/FBD+G0L1ICpFY15r6pSJjC5XfHQN235MEV5LJHEYZ/4tdJxQxXd90+/A+7pHWVPj66MskwpvuHvEQl/S2okv7+g+exrVLJQoaOzGrZAa7EYEVcsle70rmf0N0RlXwIkvik41GmBy21YEXQnFtyytYoB9LbtNot9MK2l/CffgIWv8InVUjgkQhjfmhvJEZYjrydGkwhBLMtoW5RKp3OHPbY4WksUpU+G9acy9RVghHr8ZfJfWdLwVFqwS/+ghhr/UqiWnpcEU6yBbzdMiXtuMsjzncnnA5eduK/uznbUe/mkMA/8DbHPYAgC+Z/JVrIGJoIil3JYc00CxPOzPRpCKRX X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4179f76f-1684-46a6-7474-08df1ed5f93c X-MS-Exchange-CrossTenant-AuthSource: AS4PR02MB7902.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 09:34:07.1353 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR02MB9521 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GB_MSAUTHSOURCE_EUROPE, GIT_PATCH_0, PROLO_LEO1, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org Add support for specifying undefined symbol names: * As linker directives in COFF object files (.drectve section) * As statements in DEF module-definition files See git commit 37513c1e for a similar change. This enables support for retaining attribute `used' symbols. Note that attribute `retain' is ELF-specific. The consensus is that attribute `used' on PE, MACH-O should keep both the compiler and the linker from discarding the symbol [1] [2]. References: 1. https://reviews.llvm.org/D96838 2. https://clang.llvm.org/docs/AttributeReference.html#retain --- ld/deffile.h | 3 ++ ld/deffilep.y | 45 ++++++++++++++++++- ld/pe-dll.c | 3 ++ ld/testsuite/ld-pe/pe.exp | 4 ++ ld/testsuite/ld-pe/undefined-def-i386.d | 16 +++++++ ld/testsuite/ld-pe/undefined-def-i386.def | 4 ++ ld/testsuite/ld-pe/undefined-def-i386.s | 19 ++++++++ ld/testsuite/ld-pe/undefined-def-x86_64.d | 16 +++++++ ld/testsuite/ld-pe/undefined-def-x86_64.def | 4 ++ ld/testsuite/ld-pe/undefined-def-x86_64.s | 19 ++++++++ ld/testsuite/ld-pe/undefined-embedded-i386.d | 16 +++++++ ld/testsuite/ld-pe/undefined-embedded-i386.s | 21 +++++++++ .../ld-pe/undefined-embedded-x86_64.d | 16 +++++++ .../ld-pe/undefined-embedded-x86_64.s | 21 +++++++++ 14 files changed, 206 insertions(+), 1 deletion(-) create mode 100755 ld/testsuite/ld-pe/undefined-def-i386.d create mode 100755 ld/testsuite/ld-pe/undefined-def-i386.def create mode 100755 ld/testsuite/ld-pe/undefined-def-i386.s create mode 100755 ld/testsuite/ld-pe/undefined-def-x86_64.d create mode 100755 ld/testsuite/ld-pe/undefined-def-x86_64.def create mode 100755 ld/testsuite/ld-pe/undefined-def-x86_64.s create mode 100755 ld/testsuite/ld-pe/undefined-embedded-i386.d create mode 100755 ld/testsuite/ld-pe/undefined-embedded-i386.s create mode 100755 ld/testsuite/ld-pe/undefined-embedded-x86_64.d create mode 100755 ld/testsuite/ld-pe/undefined-embedded-x86_64.s diff --git a/ld/deffile.h b/ld/deffile.h index 9269d488..a7d7bd67 100644 --- a/ld/deffile.h +++ b/ld/deffile.h @@ -105,6 +105,9 @@ typedef struct def_file { /* From EXCLUDE_SYMBOLS or embedded directives. */ def_file_symbol_list exclude_symbols; + + /* From UNDEFINED, INCLUDE or embedded directives. */ + def_file_symbol_list undefined_symbols; } def_file; extern def_file *def_file_empty (void); diff --git a/ld/deffilep.y b/ld/deffilep.y index bac19249..547fb4d1 100644 --- a/ld/deffilep.y +++ b/ld/deffilep.y @@ -104,6 +104,8 @@ static void def_version (int, int); static void def_directive (char *); static void def_aligncomm (char *str, int align); static void def_exclude_symbols (char *str); +static void def_undefined (char *str); +static void def_include (char *str); static int def_parse (void); static void def_error (const char *); static int def_lex (void); @@ -124,7 +126,7 @@ static const char *lex_parse_string_end = 0; %token NAME LIBRARY DESCRIPTION STACKSIZE_K HEAPSIZE CODE DATAU DATAL %token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANTU CONSTANTL -%token PRIVATEU PRIVATEL ALIGNCOMM EXCLUDE_SYMBOLS +%token PRIVATEU PRIVATEL ALIGNCOMM EXCLUDE_SYMBOLS INCLUDE UNDEFINED %token READ WRITE EXECUTE SHARED_K NONAMEU NONAMEL DIRECTIVE EQUAL %token ID %token DIGITS @@ -159,6 +161,8 @@ command: | DIRECTIVE ID { def_directive ($2);} | ALIGNCOMM anylang_id ',' NUMBER { def_aligncomm ($2, $4);} | EXCLUDE_SYMBOLS symbol_list + | INCLUDE inclist + | UNDEFINED undlist ; @@ -256,6 +260,7 @@ keyword_as_name: BASE { $$ = "BASE"; } | EXPORTS { $$ = "EXPORTS"; } | HEAPSIZE { $$ = "HEAPSIZE"; } | IMPORTS { $$ = "IMPORTS"; } + | INCLUDE { $$ = "INCLUDE"; } /* Disable LIBRARY keyword as valid symbol-name. This is necessary for libtool, which places this command after EXPORTS command. This behavior is illegal by specification, but sadly required by @@ -270,6 +275,7 @@ keyword_as_name: BASE { $$ = "BASE"; } | READ { $$ = "READ"; } | SHARED_K { $$ = "SHARED"; } | STACKSIZE_K { $$ = "STACKSIZE"; } + | UNDEFINED { $$ = "UNDEFINED"; } | VERSIONK { $$ = "VERSION"; } | WRITE { $$ = "WRITE"; } ; @@ -344,6 +350,18 @@ symbol_list: | symbol_list ',' anylang_id { def_exclude_symbols ($3); } ; +undlist: + anylang_id { def_undefined ($1); } + | undlist anylang_id { def_undefined ($2); } + | undlist ',' anylang_id { def_undefined ($3); } + ; + +inclist: + anylang_id { def_include ($1); } + | inclist anylang_id { def_include ($2); } + | inclist ',' anylang_id { def_include ($3); } + ; + opt_digits: DIGITS { $$ = $1; } | { $$ = ""; } ; @@ -496,6 +514,7 @@ def_file_free (def_file *fdef) } symbol_list_clear (&fdef->exclude_symbols); + symbol_list_clear (&fdef->undefined_symbols); free (fdef); } @@ -1056,6 +1075,13 @@ def_file_add_exclude_symbol (def_file *fdef, symbol_list_add (&fdef->exclude_symbols, name); } +static void +def_file_add_undefined_symbol (def_file *fdef, + const char *name) +{ + symbol_list_add (&fdef->undefined_symbols, name); +} + struct { char *param; @@ -1069,6 +1095,8 @@ diropts[] = { "-export", EXPORTS }, { "-aligncomm", ALIGNCOMM }, { "-exclude-symbols", EXCLUDE_SYMBOLS }, + { "-include", INCLUDE }, + { "-undefined", UNDEFINED }, { 0, 0 } }; @@ -1387,6 +1415,19 @@ def_exclude_symbols (char *str) def_file_add_exclude_symbol (def, str); } +static void +def_undefined (char *str) +{ + def_file_add_undefined_symbol (def, str); +} + +static void +def_include (char *str) +{ + /* include is an alias for undefined */ + def_undefined (str); +} + static void def_error (const char *err) { @@ -1437,6 +1478,7 @@ tokens[] = { "EXPORTS", EXPORTS }, { "HEAPSIZE", HEAPSIZE }, { "IMPORTS", IMPORTS }, + { "INCLUDE", INCLUDE }, { "LIBRARY", LIBRARY }, { "NAME", NAME }, { "NONAME", NONAMEU }, @@ -1448,6 +1490,7 @@ tokens[] = { "SEGMENTS", SECTIONS }, { "SHARED", SHARED_K }, { "STACKSIZE", STACKSIZE_K }, + { "UNDEFINED", UNDEFINED }, { "VERSION", VERSIONK }, { "WRITE", WRITE }, { 0, 0 } diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 6fb3dce2..972742b5 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -784,6 +784,9 @@ process_def_file_and_drectve (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info * for (ui = 0; ui < pe_def_file->exclude_symbols.count; ui++) pe_dll_add_excludes (pe_def_file->exclude_symbols.array[ui], EXCLUDESYMS); + for (ui = 0; ui < pe_def_file->undefined_symbols.count; ui++) + lang_add_gc_name (pe_def_file->undefined_symbols.array[ui]); + /* If we are building an executable and there is nothing to export, we do not build an export table at all. */ if (bfd_link_executable (info) && pe_def_file->num_exports == 0 diff --git a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp index b95f61b8..7f6806ca 100644 --- a/ld/testsuite/ld-pe/pe.exp +++ b/ld/testsuite/ld-pe/pe.exp @@ -177,6 +177,10 @@ run_dump_test "exclude-symbols-embedded-i386" run_dump_test "exclude-symbols-embedded-x86_64" run_dump_test "exclude-symbols-def-i386" run_dump_test "exclude-symbols-def-x86_64" +run_dump_test "undefined-embedded-i386" +run_dump_test "undefined-embedded-x86_64" +run_dump_test "undefined-def-i386" +run_dump_test "undefined-def-x86_64" if [check_shared_lib_support] { set old_ASFLAGS $ASFLAGS diff --git a/ld/testsuite/ld-pe/undefined-def-i386.d b/ld/testsuite/ld-pe/undefined-def-i386.d new file mode 100755 index 00000000..dd7943ee --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-def-i386.d @@ -0,0 +1,16 @@ +#source: undefined-def-i386.s +#target: i?86-*-cygwin* i?86-*-pe i?86-*-mingw* +#ld: --gc-sections -shared ${srcdir}/${subdir}/undefined-def-i386.def +#objdump: -h + +#not .*sym3.* +#... +Sections: +Idx Name.* +\s+\d+ export1 .* +^.*$ +\s+\d+ sym1 .* +^.*$ +\s+\d+ sym2 .* +^.*$ +#pass diff --git a/ld/testsuite/ld-pe/undefined-def-i386.def b/ld/testsuite/ld-pe/undefined-def-i386.def new file mode 100755 index 00000000..3c023fc4 --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-def-i386.def @@ -0,0 +1,4 @@ +LIBRARY undefined-def.dll +UNDEFINED +_sym1 +_sym2 diff --git a/ld/testsuite/ld-pe/undefined-def-i386.s b/ld/testsuite/ld-pe/undefined-def-i386.s new file mode 100755 index 00000000..2b89178a --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-def-i386.s @@ -0,0 +1,19 @@ +.global _export1 +.global _sym1 +.global _sym2 +.global _sym3 +.section export1,"xr" +_export1: + ret +.section sym1,"xr" +_sym1: + ret +.section sym2,"xr" +_sym2: + ret +.section sym3,"xr" +_sym3: + ret + +.section .drectve,"yn" +.ascii " -export:export1" diff --git a/ld/testsuite/ld-pe/undefined-def-x86_64.d b/ld/testsuite/ld-pe/undefined-def-x86_64.d new file mode 100755 index 00000000..52314c91 --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-def-x86_64.d @@ -0,0 +1,16 @@ +#source: undefined-def-x86_64.s +#target: x86_64-*-cygwin* x86_64-*-pe x86_64-*-mingw* +#ld: --gc-sections -shared ${srcdir}/${subdir}/undefined-def-x86_64.def +#objdump: -h + +#not .*sym3.* +#... +Sections: +Idx Name.* +\s+\d+ export1 .* +^.*$ +\s+\d+ sym1 .* +^.*$ +\s+\d+ sym2 .* +^.*$ +#pass diff --git a/ld/testsuite/ld-pe/undefined-def-x86_64.def b/ld/testsuite/ld-pe/undefined-def-x86_64.def new file mode 100755 index 00000000..18b4b6d9 --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-def-x86_64.def @@ -0,0 +1,4 @@ +LIBRARY undefined-def.dll +UNDEFINED +sym1 +sym2 diff --git a/ld/testsuite/ld-pe/undefined-def-x86_64.s b/ld/testsuite/ld-pe/undefined-def-x86_64.s new file mode 100755 index 00000000..6d2c70a5 --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-def-x86_64.s @@ -0,0 +1,19 @@ +.global export1 +.global sym1 +.global sym2 +.global sym3 +.section export1,"xr" +export1: + ret +.section sym1,"xr" +sym1: + ret +.section sym2,"xr" +sym2: + ret +.section sym3,"xr" +sym3: + ret + +.section .drectve,"yn" +.ascii " -export:export1" diff --git a/ld/testsuite/ld-pe/undefined-embedded-i386.d b/ld/testsuite/ld-pe/undefined-embedded-i386.d new file mode 100755 index 00000000..690dbf77 --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-embedded-i386.d @@ -0,0 +1,16 @@ +#source: undefined-embedded-i386.s +#target: i?86-*-cygwin* i?86-*-pe i?86-*-mingw* +#ld: --gc-sections -shared +#objdump: -h + +#not .*sym3.* +#... +Sections: +Idx Name.* +\s+\d+ export1 .* +^.*$ +\s+\d+ sym1 .* +^.*$ +\s+\d+ sym2 .* +^.*$ +#pass diff --git a/ld/testsuite/ld-pe/undefined-embedded-i386.s b/ld/testsuite/ld-pe/undefined-embedded-i386.s new file mode 100755 index 00000000..d229429f --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-embedded-i386.s @@ -0,0 +1,21 @@ +.global _export1 +.global _sym1 +.global _sym2 +.global _sym3 +.section export1,"xr" +_export1: + ret +.section sym1,"xr" +_sym1: + ret +.section sym2,"xr" +_sym2: + ret +.section sym3,"xr" +_sym3: + ret + +.section .drectve,"yn" +.ascii " -export:export1" +.ascii " -undefined:_sym1,_unknownsym" +.ascii " -include:_unknownsym,_sym2" diff --git a/ld/testsuite/ld-pe/undefined-embedded-x86_64.d b/ld/testsuite/ld-pe/undefined-embedded-x86_64.d new file mode 100755 index 00000000..5ceceb40 --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-embedded-x86_64.d @@ -0,0 +1,16 @@ +#source: undefined-embedded-x86_64.s +#target: x86_64-*-cygwin* x86_64-*-pe x86_64-*-mingw* +#ld: --gc-sections -shared +#objdump: -h + +#not .*sym3.* +#... +Sections: +Idx Name.* +\s+\d+ export1 .* +^.*$ +\s+\d+ sym1 .* +^.*$ +\s+\d+ sym2 .* +^.*$ +#pass diff --git a/ld/testsuite/ld-pe/undefined-embedded-x86_64.s b/ld/testsuite/ld-pe/undefined-embedded-x86_64.s new file mode 100755 index 00000000..1331c3f0 --- /dev/null +++ b/ld/testsuite/ld-pe/undefined-embedded-x86_64.s @@ -0,0 +1,21 @@ +.global export1 +.global sym1 +.global sym2 +.global sym3 +.section export1,"xr" +export1: + ret +.section sym1,"xr" +sym1: + ret +.section sym2,"xr" +sym2: + ret +.section sym3,"xr" +sym3: + ret + +.section .drectve,"yn" +.ascii " -export:export1" +.ascii " -undefined:sym1,unknownsym" +.ascii " -include:unknownsym,sym2"