From patchwork Tue May 5 13:07:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaius Mulley X-Patchwork-Id: 134476 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id DFFFE4BA2E30 for ; Tue, 5 May 2026 13:08:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFFFE4BA2E30 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=UqYk94kw X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id F40094BA799A for ; Tue, 5 May 2026 13:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F40094BA799A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F40094BA799A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777986473; cv=none; b=QZMUyv9gx2hQbR2k0+IYDqYU2Oe9VlXT7RbE78eNQ6YxVWaAfejJsidR2EigYDVISZJiUCRExGLTW3Fp6/d5ivte0xULeu7IWToYnErfp5UgT7Hb7FpPCDWXo3SqcRn/N/yrWLak68J07oV3LakEX5Y7tVHzLQtD9xsDkPl8rtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777986473; c=relaxed/simple; bh=b96hU3gGe+2Bfv3MKdznVzNuybxvMeFK6JoAXP2NKRk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xck3Vq5PjFprRqNYIiYZutLB3vDXRC0GUvBiFEIx8PqCO07OpTSCKX65o70wRXvU57D3giRb5W1U2jckjcPu7FCaH98lGp1qh76WFh4i6C2J5VGUuaS2Vl3rVhtPer6gIAiVP/e3PBW3a5Cn168Eox0sQWGt0rg/PDcLz6pPlfA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F40094BA799A Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4890d945eb4so35282245e9.0 for ; Tue, 05 May 2026 06:07:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777986472; x=1778591272; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zKtqmpFgw5AQ7f5jMl3lA+NE/BH0Y21dJKcB3t2g5AA=; b=UqYk94kwXPHLs+WpcDzVslVvmxJyhEcMhcRxthgXc7uGSeBDe5bPWTir2Sc8ORPm8g 8GiyvXEjNgGwoOhZNotfE7GmUKtupduGrm46GWXwdhW/12S1iP0dpFSK8AU88o/uXAQa MPU6TunkVc67QK2DhYfP7HjyjD/6W9qgvvM5/KdoKkNcfySYKhK3VWTyTvQzhHVNs3yq ZZIdqmP/ODKFqev/xQP13JNAXkGMz7N18oTs0cBTgHSPBp/Gse1snOJT71hai6W3NHG6 XrksxTIF2WzFUWZUAS2L0WI0hqTfkR9ounYvYGOaRIlDiePZt3p14BZNGhTr540bUFOz VF6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777986472; x=1778591272; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zKtqmpFgw5AQ7f5jMl3lA+NE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; Tue, 05 May 2026 06:07:47 -0700 (PDT) Received: from gawain ([82.153.81.102]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48d14c1ef96sm19007575e9.11.2026.05.05.06.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 06:07:46 -0700 (PDT) Received: from gaius by gawain with local (Exim 4.98.2) (envelope-from ) id 1wKFV3-00000002hKG-2tT5; Tue, 05 May 2026 14:07:45 +0100 From: Gaius Mulley To: gcc-patches@gcc.gnu.org Cc: Gaius Mulley Subject: [pushed]PR modula2/120189: documented link command does not work Date: Tue, 5 May 2026 14:07:42 +0100 Message-ID: <20260505130742.643191-1-gaiusmod2@gmail.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org This is a tidyup for PR modula2/120189 to improve the description and include all source code in the Building a shared library section. gcc/ChangeLog: PR modula2/120189 * doc/gm2.texi (Building a shared library): Rewrite the description of the shared library and include complete code into the example. gcc/testsuite/ChangeLog: PR modula2/120189 * gm2/examples/cppcallingm2/run/pass/README: New test. * gm2/examples/cppcallingm2/run/pass/a.def: New test. * gm2/examples/cppcallingm2/run/pass/a.mod: New test. * gm2/examples/cppcallingm2/run/pass/b.def: New test. * gm2/examples/cppcallingm2/run/pass/b.mod: New test. * gm2/examples/cppcallingm2/run/pass/c.def: New test. * gm2/examples/cppcallingm2/run/pass/c.mod: New test. * gm2/examples/cppcallingm2/run/pass/test.cc: New test. Signed-off-by: Gaius Mulley --- gcc/doc/gm2.texi | 72 +++++++++++++++++-- .../gm2/examples/cppcallingm2/run/pass/README | 1 + .../gm2/examples/cppcallingm2/run/pass/a.def | 3 + .../gm2/examples/cppcallingm2/run/pass/a.mod | 9 +++ .../gm2/examples/cppcallingm2/run/pass/b.def | 3 + .../gm2/examples/cppcallingm2/run/pass/b.mod | 11 +++ .../gm2/examples/cppcallingm2/run/pass/c.def | 3 + .../gm2/examples/cppcallingm2/run/pass/c.mod | 10 +++ .../examples/cppcallingm2/run/pass/test.cc | 54 ++++++++++++++ 9 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gm2/examples/cppcallingm2/run/pass/README create mode 100644 gcc/testsuite/gm2/examples/cppcallingm2/run/pass/a.def create mode 100644 gcc/testsuite/gm2/examples/cppcallingm2/run/pass/a.mod create mode 100644 gcc/testsuite/gm2/examples/cppcallingm2/run/pass/b.def create mode 100644 gcc/testsuite/gm2/examples/cppcallingm2/run/pass/b.mod create mode 100644 gcc/testsuite/gm2/examples/cppcallingm2/run/pass/c.def create mode 100644 gcc/testsuite/gm2/examples/cppcallingm2/run/pass/c.mod create mode 100644 gcc/testsuite/gm2/examples/cppcallingm2/run/pass/test.cc diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi index e4a0e963563..4e2721bd1cb 100644 --- a/gcc/doc/gm2.texi +++ b/gcc/doc/gm2.texi @@ -2303,10 +2303,74 @@ intersect. @section Building a shared library This section describes building a tiny shared library implemented in -Modula-2 and built with @file{libtool}. Suppose a project consists of -three definition modules and three implementation modules -@file{a.def}, @file{a.mod}, @file{b.def}, @file{b.mod} and -@file{c.mod}. The first step is to compile the modules using position +Modula-2 and built with @file{libtool}. Consider a project consisting +of three definition modules and three implementation modules +@file{a.def}, @file{a.mod}, @file{b.def}, @file{b.mod}, @file{c.def} +and @file{c.mod}. + +@example +DEFINITION MODULE a ; + +END a. +@end example + +@example +IMPLEMENTATION MODULE a ; + +FROM libc IMPORT printf ; + +BEGIN + printf ("init: module a\n") +FINALLY + printf ("finish: module a\n") +END a. +@end example + +Module @code{b} is almost identical, but it imports module @code{a}. + +@example +DEFINITION MODULE b ; + +END b. +@end example + +@example +IMPLEMENTATION MODULE b ; + +IMPORT a ; +FROM libc IMPORT printf ; + + +BEGIN + printf ("init: module b\n") +FINALLY + printf ("finish: module b\n") +END b. +@end example + +Likewise Module @code{c} is almost identical, but it imports from +module @code{b}. + +@example +DEFINITION MODULE c ; + +END c. +@end example + +@example +IMPLEMENTATION MODULE c ; + +IMPORT b ; +FROM libc IMPORT printf ; + +BEGIN + printf ("init: module c\n") +FINALLY + printf ("finish: module c\n") +END c. +@end example + +The first step is to compile the modules using position independent code. This can be achieved by the following three commands: diff --git a/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/README b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/README new file mode 100644 index 00000000000..17cd40eedbc --- /dev/null +++ b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/README @@ -0,0 +1 @@ +This source code appears in the documentation section Building a shared library. diff --git a/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/a.def b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/a.def new file mode 100644 index 00000000000..0d634ac2d40 --- /dev/null +++ b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/a.def @@ -0,0 +1,3 @@ +DEFINITION MODULE a ; + +END a. diff --git a/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/a.mod b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/a.mod new file mode 100644 index 00000000000..d0fed0f65f6 --- /dev/null +++ b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/a.mod @@ -0,0 +1,9 @@ +IMPLEMENTATION MODULE a ; + +FROM libc IMPORT printf ; + +BEGIN + printf ("init: module a\n") +FINALLY + printf ("finish: module a\n") +END a. diff --git a/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/b.def b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/b.def new file mode 100644 index 00000000000..aff0fcc6478 --- /dev/null +++ b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/b.def @@ -0,0 +1,3 @@ +DEFINITION MODULE b ; + +END b. diff --git a/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/b.mod b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/b.mod new file mode 100644 index 00000000000..8f99701b5e6 --- /dev/null +++ b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/b.mod @@ -0,0 +1,11 @@ +IMPLEMENTATION MODULE b ; + +IMPORT a ; +FROM libc IMPORT printf ; + + +BEGIN + printf ("init: module b\n") +FINALLY + printf ("finish: module b\n") +END b. diff --git a/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/c.def b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/c.def new file mode 100644 index 00000000000..2d84b6dcbb1 --- /dev/null +++ b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/c.def @@ -0,0 +1,3 @@ +DEFINITION MODULE c ; + +END c. diff --git a/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/c.mod b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/c.mod new file mode 100644 index 00000000000..4cdfdd9bec7 --- /dev/null +++ b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/c.mod @@ -0,0 +1,10 @@ +IMPLEMENTATION MODULE c ; + +IMPORT b ; +FROM libc IMPORT printf ; + +BEGIN + printf ("init: module c\n") +FINALLY + printf ("finish: module c\n") +END c. diff --git a/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/test.cc b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/test.cc new file mode 100644 index 00000000000..5f1fd2a76e4 --- /dev/null +++ b/gcc/testsuite/gm2/examples/cppcallingm2/run/pass/test.cc @@ -0,0 +1,54 @@ +#include +#include + +#define USER_LIB NULL + +/* Add the runtime dependency for this file on modules a, b and c. */ + +void +dep (void) +{ + m2iso_M2RTS_RequestDependant (__FILE__, USER_LIB, "c", USER_LIB); + m2iso_M2RTS_RequestDependant (__FILE__, USER_LIB, "b", USER_LIB); + m2iso_M2RTS_RequestDependant (__FILE__, USER_LIB, "a", USER_LIB); +} + +void +init (int, char *[], char *[]) +{ + printf ("test.c:init\n"); +} + +void +fini (int, char *[], char *[]) +{ + printf ("test.c:fini\n"); +} + +void +construct_scaffold (int argc, char *argv[], char *envp[]) +{ + m2iso_M2RTS_RegisterModule (__FILE__, USER_LIB, + init, fini, dep); + m2iso_M2RTS_ConstructModules (__FILE__, USER_LIB, + DEFAULT_RUNTIME_MODULE_OVERRIDE, + argc, argv, envp); +} + +void +deconstruct_scaffold (int argc, char *argv[], char *envp[]) +{ + m2iso_M2RTS_DeconstructModules (__FILE__, USER_LIB, + argc, argv, envp); +} + +int +main (int argc, char *argv[], char *envp[]) +{ + printf ("main starts\n"); + construct_scaffold (argc, argv, envp); + printf ("main application goes here\n"); + deconstruct_scaffold (argc, argv, envp); + printf ("main tidying up\n"); + return 0; +}