summaryrefslogtreecommitdiff
path: root/src/unexsunos4.c
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-09-17 23:52:45 +0000
committerRichard M. Stallman <rms@gnu.org>1994-09-17 23:52:45 +0000
commitedd2556799c17c260c565f1bb43bae856a9c5b40 (patch)
tree1dc3c579610f404e72e3676e7b19e4ed1d964066 /src/unexsunos4.c
parentd0cb5e047d1ae957f4698cd42d9d10011130c060 (diff)
downloademacs-edd2556799c17c260c565f1bb43bae856a9c5b40.tar.gz
(unexec): Fix logic for rounding section boundaries.
Diffstat (limited to 'src/unexsunos4.c')
-rw-r--r--src/unexsunos4.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/unexsunos4.c b/src/unexsunos4.c
index d8cac642168..25969256e07 100644
--- a/src/unexsunos4.c
+++ b/src/unexsunos4.c
@@ -214,7 +214,8 @@ unexec (new_name, a_name, bndry, bss_start, entry)
Doing them twice gives incorrect results. */
{
extern struct link_dynamic _DYNAMIC;
- unsigned long taddr = N_TXTADDR (ohdr);
+ unsigned long taddr = N_TXTADDR (ohdr) - N_TXTOFF (ohdr);
+ unsigned long daddr = N_DATADDR (ohdr) - N_DATOFF (ohdr);
unsigned long rel, erel;
unsigned rel_size;
@@ -245,10 +246,14 @@ unexec (new_name, a_name, bndry, bss_start, entry)
for (; rel < erel; rel += rel_size)
{
- unsigned long rpos = *(unsigned long *)(taddr + rel) - taddr;
-
- if (rpos < (unsigned long)&data_start - taddr)
- continue;
+ /* This is the unadjusted address from the reloc. */
+ unsigned long pos = *(unsigned long *)(taddr + rel);
+ /* This is the amount by which to adjust it. It
+ depends on which segment the address belongs to. */
+ unsigned long offset = (pos < (unsigned long)&data_start
+ ? taddr : daddr);
+ /* This is the adjusted address from the reloc. */
+ unsigned long rpos = pos - offset;
lseek (new, N_TXTOFF (nhdr) + rpos, L_SET);
write (new, old + N_TXTOFF (ohdr) + rpos, sizeof (unsigned long));