Re: Fun trick

Liste des GroupesRevenir à co vms 
Sujet : Re: Fun trick
De : mw40171 (at) *nospam* mucweb.de (hb0815)
Groupes : comp.os.vms
Date : 09. Jan 2025, 14:01:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vlohc5$3cc83$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On 1/9/25 02:00, Arne Vajhøj wrote:
Hmmm.
 It works in C, but it does not seem to work in
any other language (tested with Pascal and Fortran).
...
I assume the difference relates to user code main not being
the real program entry.
So, make it a main entry.
This is on Alpha. It should work on IA64 and x86. I don't have access to any of the latter systems. If this does not work on these systems, I know how to make it work, anyway.
$ gdiff -ub lib.pas-orig lib.pas
--- lib.pas-orig        2025-01-09 07:34:25 -0500
+++ lib.pas     2025-01-09 07:37:14 -0500
@@ -1,19 +1,11 @@
-[inherit('sys$library:starlet')]
-module lib(input, output);
-
-[global]
-procedure ooops;
-
-begin
-   writeln('This is a shareable image to link against not run');
-   $exit(ss$_normal);
-end;
+program lib(input, output);
  [global]
  procedure say;
-
  begin
     writeln('Hi');
  end;
+begin
+   writeln('This is a shareable image to link against not run');
  end.
$
...
$ def/user libshr sys$disk:[]libshr.exe;
$ r prg
Hi
$ r libshr
This is a shareable image to link against not run
$
and
$ gdiff -ub lib.for-orig lib.for
--- lib.for-orig        2025-01-09 07:43:03 -0500
+++ lib.for     2025-01-09 07:43:25 -0500
@@ -1,7 +1,5 @@
-      subroutine ooops
-      include '($ssdef)'
+      program ooops
        write(*,*) 'This is a shareable image to link against not run'
-      call sys$exit(ss$_normal)
        end
  c
        subroutine say
$
...
$ def/user libshr sys$disk:[]libshr.exe;
$ r prg
Hi
$ r libshr
This is a shareable image to link against not run
$
Also, I should have mentioned ... Your shareable with printing a message from init code can not be used as a "normal" shareable image. The message will always be printed. That's probably not what you want.
Init code of an image is always run. For a shareable image it is run at activation time, for a main image it is run at image startup time. For some reasons I distinguish these two phases although others prefer to say that "startup" is part of activation.
My shareable image only prints its message if a user (accidently) runs it as main image.
All this works because VMS defines a weak transfer (or entry) address. The C compiler in absence of a "main" assigns this weak transfer to the first function seen in a source module. (I admit, I initially didn't test this with other compilers; obviously FORTRAN and PASCAL do not define this). The linker keeps track of the first weak transfer it encounters and uses it as image transfer, if there is no "strong" transfer, in C no "main". This makes the shareable image "runnable". If This often ends up in an unexpected error, if a user (accidently) runs it as main image: the first (static) function may expect arguments and may therefore miserably fail. I bet that there are only a few shareable images that are prepared for being run as a main image.
For C this works at least on Alpha, IA64 and x86. On the latter two this is more visible, because there is a VMS weak symbol in the symbol table - of the object module. On Alpha the information is in the EOBJ$C_EEOM record (and on VAX I assume it is the OBJ$C_EOM record).

Date Sujet#  Auteur
8 Jan 25 * Fun trick39Arne Vajhøj
8 Jan 25 +- Re: Fun trick1Lawrence D'Oliveiro
8 Jan 25 +* Re: Fun trick11John Reagan
8 Jan 25 i`* Re: Fun trick10Arne Vajhøj
8 Jan 25 i `* Re: Fun trick9John Reagan
8 Jan 25 i  +* Re: Fun trick2Arne Vajhøj
8 Jan 25 i  i`- Re: Fun trick1Arne Vajhøj
8 Jan 25 i  `* Re: Fun trick6Arne Vajhøj
14 Jan 25 i   `* Re: Fun trick5John Reagan
14 Jan 25 i    `* Re: Fun trick4Lawrence D'Oliveiro
14 Jan 25 i     `* Re: Fun trick3Arne Vajhøj
14 Jan 25 i      +- Re: Fun trick1Arne Vajhøj
15 Jan 25 i      `- Re: Fun trick1John Reagan
8 Jan 25 `* Re: Fun trick26hb0815
8 Jan 25  `* Re: Fun trick25Arne Vajhøj
8 Jan 25   `* Re: Fun trick24hb0815
9 Jan 25    `* Re: Fun trick23Arne Vajhøj
9 Jan 25     `* Re: Fun trick22hb0815
13 Jan 25      +* Re: Fun trick11Arne Vajhøj
17 Jan 25      i`* GNU diff command, was: Re: Fun trick10Simon Clubley
17 Jan 25      i `* Re: GNU diff command, was: Re: Fun trick9Craig A. Berry
17 Jan 25      i  `* Re: GNU diff command, was: Re: Fun trick8Craig A. Berry
19 Jan 25      i   `* Re: GNU diff command, was: Re: Fun trick7hb0815
21 Jan 25      i    `* Re: GNU diff command, was: Re: Fun trick6Craig A. Berry
22 Jan 25      i     `* Re: GNU diff command, was: Re: Fun trick5hb0815
22 Jan 25      i      `* Re: GNU diff command, was: Re: Fun trick4Lawrence D'Oliveiro
23 Jan 25      i       `* Re: GNU diff command, was: Re: Fun trick3Robert A. Brooks
24 Jan 25      i        `* Re: GNU diff command, was: Re: Fun trick2Simon Clubley
25 Jan 25      i         `- Re: GNU diff command, was: Re: Fun trick1Dave Froble
13 Jan 25      `* Re: Fun trick10Arne Vajhøj
13 Jan 25       `* Re: Fun trick9Lawrence D'Oliveiro
13 Jan 25        `* Re: Fun trick8Arne Vajhøj
14 Jan 25         +* Re: Fun trick6John Reagan
14 Jan 25         i`* Re: Fun trick5Arne Vajhøj
3 Feb 25         i +- Cobol (was Re: Fun trick)1Arne Vajhøj
3 Feb 25         i `* Re: Fun trick3Arne Vajhøj
3 Feb 25         i  `* Cobol (was: Re: Fun trick)2Arne Vajhøj
5 Feb 25         i   `- Re: Cobol1Arne Vajhøj
14 Jan 25         `- Re: Fun trick1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal