From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,6a0170ee33c96180 X-Google-Attributes: gidfee84,public From: Craig Neth USG Subject: Re: Dynamic loading on OSF Date: 1996/12/03 Message-ID: <32A4774D.ABD@zk3.dec.com>#1/1 X-Deja-AN: 202185158 references: <329B9055.7945@cnam.fr> cc: "T. Cornilleau" content-type: text/plain; charset=us-ascii organization: Digital UNIX Development Environment Group mime-version: 1.0 newsgroups: comp.unix.osf.osf1 x-mailer: Mozilla 3.01Gold (X11; I; OSF1 V4.0 alpha) T. Cornilleau wrote: > > Hello, > > I'm trying to dynamically load, in a running process, a C function > stored in a file. To do that, I have rewrittent a C program which works > fin on a SUN OS 4.1.3. But on a DEC OSF 3.2, i have a segmentation > fault. Both OS use COFF as object file format. > > All my programs are attached. [... programs deleted ...] Your fundamental problem is that the linker will round the -T value that you pass it to one that is aligned on a 64K boundary. So you are loading the program at a non-rounded address but the linker is relocating it to a rounded address, with the result being you're jumping to someplace other than where the code is... You need to round the address you pass to your relink function, making sure you sbrk() the difference between the current break and however much it takes to round the address to a multiple of 65536. Also, you have a bunch of int/long mismatches in your example - addresses are longs in DIGITAL UNIX. In particular, you need to fix the sprintf that builds the 'ld' command line - you have a %x for the address field and it needs to be a %lx. I hacked up your program with these changes and got it working. One last thing - I think to be absolutely kosher you need to issue a 'imb' PAL call to flush the instruction cache before jumping to the routine, as the Alpha processor has separate instruction and data caches and you are putting instructions into data space. Here's a sequence you can use to define a macro, IMB(), that does what you need: #include #include #define QUOTE(s) #s #define STR(s) QUOTE(s) #define IMB() asm("call_pal " STR(PAL_imb)) -- -------------------------------------------------------------------------------- Craig Neth ! neth@zk3.dec.com DIGITAL Equipment Corporation ! 110 Spit Brook Road ZKO3-3/W17 ! Nashua, NH 03062 ! Opinions expressed herein are my own. ================================================================================