Simplify update of r_addend field in relocation record if `-r' is on.

The old quirky code did strange things.
This commit is contained in:
pk 1995-12-28 18:04:59 +00:00
parent 2bb60e32ec
commit 4162cf6459
5 changed files with 98 additions and 166 deletions

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: md.c,v 1.11 1995/11/28 19:29:45 pk Exp $
* $Id: md.c,v 1.12 1995/12/28 18:05:10 pk Exp $
*/
#include <sys/param.h>
@ -103,43 +103,29 @@ iflush(sp)
*/
long
md_get_addend(r, addr)
struct relocation_info *r;
unsigned char *addr;
struct relocation_info *r;
unsigned char *addr;
{
return r->r_addend;
}
void
md_relocate(r, relocation, addr, relocatable_output)
struct relocation_info *r;
long relocation;
unsigned char *addr;
int relocatable_output;
struct relocation_info *r;
long relocation;
unsigned char *addr;
int relocatable_output;
{
register unsigned long mask;
#ifndef RTLD
if (relocatable_output) {
/*
* Non-PC relative relocations which are absolute or
* which have become non-external now have fixed
* relocations. Set the ADD_EXTRA of this relocation
* to be the relocation we have now determined.
* Store relocation where the next link-edit run
* will look for it.
*/
if (!RELOC_PCREL_P(r)) {
if ((int) r->r_type <= RELOC_32
|| RELOC_EXTERN_P(r) == 0)
RELOC_ADD_EXTRA(r) = relocation;
} else if (RELOC_EXTERN_P(r))
/*
* External PC-relative relocations continue
* to move around; update their relocations
* by the amount they have moved so far.
*/
RELOC_ADD_EXTRA(r) -= pc_relocation;
r->r_addend = relocation;
return;
}
#endif
relocation >>= RELOC_VALUE_RIGHTSHIFT(r);
@ -186,8 +172,8 @@ int relocatable_output;
*/
int
md_make_reloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
r->r_type = rp->r_type;
r->r_addend = rp->r_addend;
@ -218,9 +204,9 @@ int type;
*/
void
md_make_jmpslot(sp, offset, index)
jmpslot_t *sp;
long offset;
long index;
jmpslot_t *sp;
long offset;
long index;
{
u_long fudge = (u_long) -(sizeof(sp->opcode1) + offset);
sp->opcode1 = SAVE;
@ -241,9 +227,9 @@ long index;
*/
void
md_fix_jmpslot(sp, offset, addr)
jmpslot_t *sp;
long offset;
u_long addr;
jmpslot_t *sp;
long offset;
u_long addr;
{
/*
* Here comes a RELOC_{LO10,HI22} relocation pair
@ -263,8 +249,8 @@ u_long addr;
*/
void
md_make_jmpreloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
if (type & RELTYPE_RELATIVE)
r->r_type = RELOC_RELATIVE;
@ -279,8 +265,8 @@ int type;
*/
void
md_make_gotreloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
/*
* GOT value resolved (symbolic or entry point): R_32
@ -301,7 +287,7 @@ int type;
*/
void
md_make_cpyreloc(rp, r)
struct relocation_info *rp, *r;
struct relocation_info *rp, *r;
{
r->r_type = RELOC_COPY_DAT;
r->r_addend = 0;
@ -309,8 +295,8 @@ struct relocation_info *rp, *r;
void
md_set_breakpoint(where, savep)
long where;
long *savep;
long where;
long *savep;
{
*savep = *(long *)where;
*(long *)where = TRAP;
@ -323,10 +309,10 @@ long *savep;
*/
void
md_init_header(hp, magic, flags)
struct exec *hp;
int magic, flags;
struct exec *hp;
int magic, flags;
{
#ifdef NetBSD
#ifdef __NetBSD__
N_SETMAGIC((*hp), magic, MID_MACHINE, flags);
/* TEXT_START depends on the value of outheader.a_entry. */
@ -349,9 +335,9 @@ int magic, flags;
*/
int
md_midcompat(hp)
struct exec *hp;
struct exec *hp;
{
#ifdef NetBSD
#ifdef __NetBSD__
#define SUN_M_SPARC 3
return (((md_swap_long(hp->a_midmag)&0x00ff0000) >> 16) == SUN_M_SPARC);
#else

View File

@ -32,7 +32,7 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91";
Set, indirect, and warning symbol features added by Randy Smith. */
/*
* $Id: ld.c,v 1.44 1995/08/04 21:49:00 pk Exp $
* $Id: ld.c,v 1.45 1995/12/28 18:04:59 pk Exp $
*/
/* Define how to initialize system-dependent header fields. */
@ -2734,7 +2734,6 @@ copy_data(entry)
* relocation info, in core. NRELOC says how many there are.
*/
/* HACK: md.c may need access to this */
int pc_relocation;
void
@ -2754,9 +2753,9 @@ perform_relocation(data, data_size, reloc, nreloc, entry, dataseg)
int data_relocation = entry->data_start_address - entry->header.a_text;
int bss_relocation = entry->bss_start_address -
entry->header.a_text - entry->header.a_data;
pc_relocation = dataseg?
entry->data_start_address - entry->header.a_text:
entry->text_start_address;
pc_relocation = dataseg
? entry->data_start_address - entry->header.a_text
: entry->text_start_address;
for (; r < end; r++) {
int addr = RELOC_ADDRESS(r);
@ -3120,18 +3119,6 @@ coptxtrel(entry)
RELOC_SYMBOL(r) = (sp->defined & N_TYPE);
} else
RELOC_SYMBOL(r) = sp->symbolnum;
#ifdef RELOC_ADD_EXTRA
/*
* If we aren't going to be adding in the
* value in memory on the next pass of the
* loader, then we need to add it in from the
* relocation entry, unless the symbol remains
* external in our output. Otherwise the work we
* did in this pass is lost.
*/
if (!RELOC_MEMORY_ADD_P(r) && !RELOC_EXTERN_P(r))
RELOC_ADD_EXTRA(r) += sp->value;
#endif
} else
/*
* Global symbols come first.

View File

@ -32,7 +32,7 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91";
Set, indirect, and warning symbol features added by Randy Smith. */
/*
* $Id: ld.c,v 1.44 1995/08/04 21:49:00 pk Exp $
* $Id: ld.c,v 1.45 1995/12/28 18:04:59 pk Exp $
*/
/* Define how to initialize system-dependent header fields. */
@ -2734,7 +2734,6 @@ copy_data(entry)
* relocation info, in core. NRELOC says how many there are.
*/
/* HACK: md.c may need access to this */
int pc_relocation;
void
@ -2754,9 +2753,9 @@ perform_relocation(data, data_size, reloc, nreloc, entry, dataseg)
int data_relocation = entry->data_start_address - entry->header.a_text;
int bss_relocation = entry->bss_start_address -
entry->header.a_text - entry->header.a_data;
pc_relocation = dataseg?
entry->data_start_address - entry->header.a_text:
entry->text_start_address;
pc_relocation = dataseg
? entry->data_start_address - entry->header.a_text
: entry->text_start_address;
for (; r < end; r++) {
int addr = RELOC_ADDRESS(r);
@ -3120,18 +3119,6 @@ coptxtrel(entry)
RELOC_SYMBOL(r) = (sp->defined & N_TYPE);
} else
RELOC_SYMBOL(r) = sp->symbolnum;
#ifdef RELOC_ADD_EXTRA
/*
* If we aren't going to be adding in the
* value in memory on the next pass of the
* loader, then we need to add it in from the
* relocation entry, unless the symbol remains
* external in our output. Otherwise the work we
* did in this pass is lost.
*/
if (!RELOC_MEMORY_ADD_P(r) && !RELOC_EXTERN_P(r))
RELOC_ADD_EXTRA(r) += sp->value;
#endif
} else
/*
* Global symbols come first.

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: md.c,v 1.11 1995/11/28 19:29:45 pk Exp $
* $Id: md.c,v 1.12 1995/12/28 18:05:10 pk Exp $
*/
#include <sys/param.h>
@ -103,43 +103,29 @@ iflush(sp)
*/
long
md_get_addend(r, addr)
struct relocation_info *r;
unsigned char *addr;
struct relocation_info *r;
unsigned char *addr;
{
return r->r_addend;
}
void
md_relocate(r, relocation, addr, relocatable_output)
struct relocation_info *r;
long relocation;
unsigned char *addr;
int relocatable_output;
struct relocation_info *r;
long relocation;
unsigned char *addr;
int relocatable_output;
{
register unsigned long mask;
#ifndef RTLD
if (relocatable_output) {
/*
* Non-PC relative relocations which are absolute or
* which have become non-external now have fixed
* relocations. Set the ADD_EXTRA of this relocation
* to be the relocation we have now determined.
* Store relocation where the next link-edit run
* will look for it.
*/
if (!RELOC_PCREL_P(r)) {
if ((int) r->r_type <= RELOC_32
|| RELOC_EXTERN_P(r) == 0)
RELOC_ADD_EXTRA(r) = relocation;
} else if (RELOC_EXTERN_P(r))
/*
* External PC-relative relocations continue
* to move around; update their relocations
* by the amount they have moved so far.
*/
RELOC_ADD_EXTRA(r) -= pc_relocation;
r->r_addend = relocation;
return;
}
#endif
relocation >>= RELOC_VALUE_RIGHTSHIFT(r);
@ -186,8 +172,8 @@ int relocatable_output;
*/
int
md_make_reloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
r->r_type = rp->r_type;
r->r_addend = rp->r_addend;
@ -218,9 +204,9 @@ int type;
*/
void
md_make_jmpslot(sp, offset, index)
jmpslot_t *sp;
long offset;
long index;
jmpslot_t *sp;
long offset;
long index;
{
u_long fudge = (u_long) -(sizeof(sp->opcode1) + offset);
sp->opcode1 = SAVE;
@ -241,9 +227,9 @@ long index;
*/
void
md_fix_jmpslot(sp, offset, addr)
jmpslot_t *sp;
long offset;
u_long addr;
jmpslot_t *sp;
long offset;
u_long addr;
{
/*
* Here comes a RELOC_{LO10,HI22} relocation pair
@ -263,8 +249,8 @@ u_long addr;
*/
void
md_make_jmpreloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
if (type & RELTYPE_RELATIVE)
r->r_type = RELOC_RELATIVE;
@ -279,8 +265,8 @@ int type;
*/
void
md_make_gotreloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
/*
* GOT value resolved (symbolic or entry point): R_32
@ -301,7 +287,7 @@ int type;
*/
void
md_make_cpyreloc(rp, r)
struct relocation_info *rp, *r;
struct relocation_info *rp, *r;
{
r->r_type = RELOC_COPY_DAT;
r->r_addend = 0;
@ -309,8 +295,8 @@ struct relocation_info *rp, *r;
void
md_set_breakpoint(where, savep)
long where;
long *savep;
long where;
long *savep;
{
*savep = *(long *)where;
*(long *)where = TRAP;
@ -323,10 +309,10 @@ long *savep;
*/
void
md_init_header(hp, magic, flags)
struct exec *hp;
int magic, flags;
struct exec *hp;
int magic, flags;
{
#ifdef NetBSD
#ifdef __NetBSD__
N_SETMAGIC((*hp), magic, MID_MACHINE, flags);
/* TEXT_START depends on the value of outheader.a_entry. */
@ -349,9 +335,9 @@ int magic, flags;
*/
int
md_midcompat(hp)
struct exec *hp;
struct exec *hp;
{
#ifdef NetBSD
#ifdef __NetBSD__
#define SUN_M_SPARC 3
return (((md_swap_long(hp->a_midmag)&0x00ff0000) >> 16) == SUN_M_SPARC);
#else

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: md.c,v 1.11 1995/11/28 19:29:45 pk Exp $
* $Id: md.c,v 1.12 1995/12/28 18:05:10 pk Exp $
*/
#include <sys/param.h>
@ -103,43 +103,29 @@ iflush(sp)
*/
long
md_get_addend(r, addr)
struct relocation_info *r;
unsigned char *addr;
struct relocation_info *r;
unsigned char *addr;
{
return r->r_addend;
}
void
md_relocate(r, relocation, addr, relocatable_output)
struct relocation_info *r;
long relocation;
unsigned char *addr;
int relocatable_output;
struct relocation_info *r;
long relocation;
unsigned char *addr;
int relocatable_output;
{
register unsigned long mask;
#ifndef RTLD
if (relocatable_output) {
/*
* Non-PC relative relocations which are absolute or
* which have become non-external now have fixed
* relocations. Set the ADD_EXTRA of this relocation
* to be the relocation we have now determined.
* Store relocation where the next link-edit run
* will look for it.
*/
if (!RELOC_PCREL_P(r)) {
if ((int) r->r_type <= RELOC_32
|| RELOC_EXTERN_P(r) == 0)
RELOC_ADD_EXTRA(r) = relocation;
} else if (RELOC_EXTERN_P(r))
/*
* External PC-relative relocations continue
* to move around; update their relocations
* by the amount they have moved so far.
*/
RELOC_ADD_EXTRA(r) -= pc_relocation;
r->r_addend = relocation;
return;
}
#endif
relocation >>= RELOC_VALUE_RIGHTSHIFT(r);
@ -186,8 +172,8 @@ int relocatable_output;
*/
int
md_make_reloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
r->r_type = rp->r_type;
r->r_addend = rp->r_addend;
@ -218,9 +204,9 @@ int type;
*/
void
md_make_jmpslot(sp, offset, index)
jmpslot_t *sp;
long offset;
long index;
jmpslot_t *sp;
long offset;
long index;
{
u_long fudge = (u_long) -(sizeof(sp->opcode1) + offset);
sp->opcode1 = SAVE;
@ -241,9 +227,9 @@ long index;
*/
void
md_fix_jmpslot(sp, offset, addr)
jmpslot_t *sp;
long offset;
u_long addr;
jmpslot_t *sp;
long offset;
u_long addr;
{
/*
* Here comes a RELOC_{LO10,HI22} relocation pair
@ -263,8 +249,8 @@ u_long addr;
*/
void
md_make_jmpreloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
if (type & RELTYPE_RELATIVE)
r->r_type = RELOC_RELATIVE;
@ -279,8 +265,8 @@ int type;
*/
void
md_make_gotreloc(rp, r, type)
struct relocation_info *rp, *r;
int type;
struct relocation_info *rp, *r;
int type;
{
/*
* GOT value resolved (symbolic or entry point): R_32
@ -301,7 +287,7 @@ int type;
*/
void
md_make_cpyreloc(rp, r)
struct relocation_info *rp, *r;
struct relocation_info *rp, *r;
{
r->r_type = RELOC_COPY_DAT;
r->r_addend = 0;
@ -309,8 +295,8 @@ struct relocation_info *rp, *r;
void
md_set_breakpoint(where, savep)
long where;
long *savep;
long where;
long *savep;
{
*savep = *(long *)where;
*(long *)where = TRAP;
@ -323,10 +309,10 @@ long *savep;
*/
void
md_init_header(hp, magic, flags)
struct exec *hp;
int magic, flags;
struct exec *hp;
int magic, flags;
{
#ifdef NetBSD
#ifdef __NetBSD__
N_SETMAGIC((*hp), magic, MID_MACHINE, flags);
/* TEXT_START depends on the value of outheader.a_entry. */
@ -349,9 +335,9 @@ int magic, flags;
*/
int
md_midcompat(hp)
struct exec *hp;
struct exec *hp;
{
#ifdef NetBSD
#ifdef __NetBSD__
#define SUN_M_SPARC 3
return (((md_swap_long(hp->a_midmag)&0x00ff0000) >> 16) == SUN_M_SPARC);
#else