From: Craig Neth USG <neth@zk3.dec.com>
Cc: "T. Cornilleau" <Thierry.Cornilleau@cnam.fr>
Subject: Re: Dynamic loading on OSF
Date: 1996/12/03 [thread overview]
Message-ID: <32A4774D.ABD@zk3.dec.com> (raw)
In-Reply-To: 329B9055.7945@cnam.fr
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 <c_asm.h>
#include <machine/pal.h>
#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.
================================================================================
prev parent reply other threads:[~1996-12-03 5:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-11-26 5:00 Dynamic loading on OSF T. Cornilleau
1996-12-03 5:00 ` Craig Neth USG [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox