home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 262,256 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All   
   Re: Fun trick   
   13 Jan 25 13:45:50   
   
   From: arne@vajhoej.dk   
      
   On 1/9/2025 8:01 AM, hb0815 wrote:   
   > 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   
      
   > $ gdiff -ub lib.for-orig lib.for   
      
   > 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.   
      
   My Pascal code a few revisions back looked like:   
      
       lib$getjpi(item_code := jpi$_imagname, resultant_string :=   
   imgnam.body, resultant_length := imgnam.length);   
       if index(imgnam, ']libshr.EXE') > 0 then begin   
          writeln('This is a shareable image to link against not run');   
          $exit(ss$_normal);   
       end;   
      
   Maybe not elegant, but it did check.   
      
   > 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".   
      
   There are probably a lot of shareable images written in C out   
   there where the developer has no idea that they are runnable or   
   what code will run.   
      
   Arne   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca