Handle object code with the "large" model PIC (eg. gcc's `-fPIC' option).

This commit is contained in:
pk 1995-08-04 21:49:00 +00:00
parent 72acb4fe30
commit d579c1b1db
6 changed files with 64 additions and 34 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: ld.h,v 1.17 1995/06/04 21:56:26 pk Exp $
* $Id: ld.h,v 1.18 1995/08/04 21:49:06 pk Exp $
*/
/*-
* This code is derived from software copyrighted by the Free Software
@ -154,17 +154,19 @@ extern int netzmagic;
#define RELOC_LAZY_P(r) ((r)->r_jmptable)
#define CHECK_GOT_RELOC(r) ((r)->r_pcrel)
#define RELOC_PIC_TYPE(r) ((r)->r_baserel? \
PIC_TYPE_LARGE:PIC_TYPE_NONE)
#define RELOC_INIT_SEGMENT_RELOC(r)
#endif
#ifndef MAX_GOTOFF
#define MAX_GOTOFF (LONG_MAX)
#define MAX_GOTOFF(x) (LONG_MAX)
#endif
#ifndef MIN_GOTOFF
#define MIN_GOTOFF (LONG_MIN)
#define MIN_GOTOFF(x) (LONG_MIN)
#endif
/*
@ -599,6 +601,10 @@ extern struct exec outheader; /* Output file header. */
extern int magic; /* Output file magic. */
extern int oldmagic;
extern int relocatable_output;
extern int pic_type;
#define PIC_TYPE_NONE 0
#define PIC_TYPE_SMALL 1
#define PIC_TYPE_LARGE 2
/* Size of a page. */
extern int page_size;

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.43 1995/06/30 12:33:56 pk Exp $
* $Id: ld.c,v 1.44 1995/08/04 21:49:00 pk Exp $
*/
/* Define how to initialize system-dependent header fields. */
@ -43,6 +43,7 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91";
#include <sys/file.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -120,6 +121,7 @@ int set_sect_start; /* start of set element vectors */
int set_sect_size; /* size of above */
int link_mode; /* Current link mode */
int pic_type; /* PIC type */
/*
* When loading the text and data, we can avoid doing a close
@ -2051,6 +2053,11 @@ consider_relocation(entry, dataseg)
lsp = &entry->symbols[reloc->r_symbolnum];
alloc_rrs_gotslot(entry, reloc, lsp);
if (pic_type != PIC_TYPE_NONE &&
RELOC_PIC_TYPE(reloc) != pic_type)
errx(1, "%s: illegal reloc type mix",
get_file_name(entry));
pic_type = RELOC_PIC_TYPE(reloc);
} else if (RELOC_EXTERN_P(reloc)) {

View File

@ -1,5 +1,5 @@
/*
* $Id: ld.h,v 1.17 1995/06/04 21:56:26 pk Exp $
* $Id: ld.h,v 1.18 1995/08/04 21:49:06 pk Exp $
*/
/*-
* This code is derived from software copyrighted by the Free Software
@ -154,17 +154,19 @@ extern int netzmagic;
#define RELOC_LAZY_P(r) ((r)->r_jmptable)
#define CHECK_GOT_RELOC(r) ((r)->r_pcrel)
#define RELOC_PIC_TYPE(r) ((r)->r_baserel? \
PIC_TYPE_LARGE:PIC_TYPE_NONE)
#define RELOC_INIT_SEGMENT_RELOC(r)
#endif
#ifndef MAX_GOTOFF
#define MAX_GOTOFF (LONG_MAX)
#define MAX_GOTOFF(x) (LONG_MAX)
#endif
#ifndef MIN_GOTOFF
#define MIN_GOTOFF (LONG_MIN)
#define MIN_GOTOFF(x) (LONG_MIN)
#endif
/*
@ -599,6 +601,10 @@ extern struct exec outheader; /* Output file header. */
extern int magic; /* Output file magic. */
extern int oldmagic;
extern int relocatable_output;
extern int pic_type;
#define PIC_TYPE_NONE 0
#define PIC_TYPE_SMALL 1
#define PIC_TYPE_LARGE 2
/* Size of a page. */
extern int page_size;

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.43 1995/06/30 12:33:56 pk Exp $
* $Id: ld.c,v 1.44 1995/08/04 21:49:00 pk Exp $
*/
/* Define how to initialize system-dependent header fields. */
@ -43,6 +43,7 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91";
#include <sys/file.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -120,6 +121,7 @@ int set_sect_start; /* start of set element vectors */
int set_sect_size; /* size of above */
int link_mode; /* Current link mode */
int pic_type; /* PIC type */
/*
* When loading the text and data, we can avoid doing a close
@ -2051,6 +2053,11 @@ consider_relocation(entry, dataseg)
lsp = &entry->symbols[reloc->r_symbolnum];
alloc_rrs_gotslot(entry, reloc, lsp);
if (pic_type != PIC_TYPE_NONE &&
RELOC_PIC_TYPE(reloc) != pic_type)
errx(1, "%s: illegal reloc type mix",
get_file_name(entry));
pic_type = RELOC_PIC_TYPE(reloc);
} else if (RELOC_EXTERN_P(reloc)) {

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: rrs.c,v 1.17 1995/06/05 01:01:51 pk Exp $
* $Id: rrs.c,v 1.18 1995/08/04 21:49:08 pk Exp $
*/
#include <sys/param.h>
@ -36,13 +36,12 @@
#include <sys/file.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <err.h>
#include <fcntl.h>
#include <ar.h>
#include <ranlib.h>
#include <a.out.h>
#include <stab.h>
#include <string.h>
@ -75,6 +74,8 @@ static int rrs_symbol_size;
static int current_jmpslot_offset;
static int current_got_offset;
static int max_got_offset;
static int min_got_offset;
static int got_origin;
static int current_reloc_offset;
static int current_hash_index;
@ -431,7 +432,7 @@ claim_rrs_gotslot(entry, rp, lsp, addend)
/* GOT offset 0 is reserved */
current_got_offset += sizeof(got_t);
if (current_got_offset > MAX_GOTOFF)
if (current_got_offset > max_got_offset)
errx(1, "%s: GOT overflow on symbol `%s' at %#x",
get_file_name(entry), sp->name, RELOC_ADDRESS(rp));
@ -538,7 +539,7 @@ claim_rrs_internal_gotslot(entry, rp, lsp, addend)
/* GOT offset 0 is reserved */
current_got_offset += sizeof(got_t);
if (current_got_offset > MAX_GOTOFF)
if (current_got_offset > max_got_offset)
errx(1, "%s: GOT overflow for relocation at %#x",
get_file_name(entry), RELOC_ADDRESS(rp));
@ -846,6 +847,7 @@ consider_rrs_section_lengths()
void
relocate_rrs_addresses()
{
int gotsize;
dynamic_symbol->value = 0;
@ -856,16 +858,16 @@ relocate_rrs_addresses()
*/
current_jmpslot_offset = sizeof(jmpslot_t);
current_got_offset = 0;
max_got_offset = MAX_GOTOFF(pic_type);
min_got_offset = MIN_GOTOFF(pic_type);
gotsize = number_of_gotslots * sizeof(got_t);
if (1 /* Not "-fPIC" seen */) {
int gotsize = number_of_gotslots * sizeof(got_t);
if (gotsize + min_got_offset - (int)sizeof(got_t) > max_got_offset)
warnx("Global Offset Table overflow (use `-fPIC')");
if (gotsize + MIN_GOTOFF - (int)sizeof(got_t) > MAX_GOTOFF)
warnx("Global Offset Table overflow");
if (gotsize > MAX_GOTOFF)
/* Position at "two-complements" origin */
current_got_offset += MIN_GOTOFF;
}
if (gotsize > max_got_offset)
/* Position at "two-complements" origin */
current_got_offset += min_got_offset;
got_origin = -current_got_offset;

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: rrs.c,v 1.17 1995/06/05 01:01:51 pk Exp $
* $Id: rrs.c,v 1.18 1995/08/04 21:49:08 pk Exp $
*/
#include <sys/param.h>
@ -36,13 +36,12 @@
#include <sys/file.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <err.h>
#include <fcntl.h>
#include <ar.h>
#include <ranlib.h>
#include <a.out.h>
#include <stab.h>
#include <string.h>
@ -75,6 +74,8 @@ static int rrs_symbol_size;
static int current_jmpslot_offset;
static int current_got_offset;
static int max_got_offset;
static int min_got_offset;
static int got_origin;
static int current_reloc_offset;
static int current_hash_index;
@ -431,7 +432,7 @@ claim_rrs_gotslot(entry, rp, lsp, addend)
/* GOT offset 0 is reserved */
current_got_offset += sizeof(got_t);
if (current_got_offset > MAX_GOTOFF)
if (current_got_offset > max_got_offset)
errx(1, "%s: GOT overflow on symbol `%s' at %#x",
get_file_name(entry), sp->name, RELOC_ADDRESS(rp));
@ -538,7 +539,7 @@ claim_rrs_internal_gotslot(entry, rp, lsp, addend)
/* GOT offset 0 is reserved */
current_got_offset += sizeof(got_t);
if (current_got_offset > MAX_GOTOFF)
if (current_got_offset > max_got_offset)
errx(1, "%s: GOT overflow for relocation at %#x",
get_file_name(entry), RELOC_ADDRESS(rp));
@ -846,6 +847,7 @@ consider_rrs_section_lengths()
void
relocate_rrs_addresses()
{
int gotsize;
dynamic_symbol->value = 0;
@ -856,16 +858,16 @@ relocate_rrs_addresses()
*/
current_jmpslot_offset = sizeof(jmpslot_t);
current_got_offset = 0;
max_got_offset = MAX_GOTOFF(pic_type);
min_got_offset = MIN_GOTOFF(pic_type);
gotsize = number_of_gotslots * sizeof(got_t);
if (1 /* Not "-fPIC" seen */) {
int gotsize = number_of_gotslots * sizeof(got_t);
if (gotsize + min_got_offset - (int)sizeof(got_t) > max_got_offset)
warnx("Global Offset Table overflow (use `-fPIC')");
if (gotsize + MIN_GOTOFF - (int)sizeof(got_t) > MAX_GOTOFF)
warnx("Global Offset Table overflow");
if (gotsize > MAX_GOTOFF)
/* Position at "two-complements" origin */
current_got_offset += MIN_GOTOFF;
}
if (gotsize > max_got_offset)
/* Position at "two-complements" origin */
current_got_offset += min_got_offset;
got_origin = -current_got_offset;