summaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1996-12-01 16:58:31 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:34:16 +0200
commitf8de35da65c5d93bb733073cf40da154bc1c0748 (patch)
treed28c7644739a24402376d24cb0020ea410a9ccff /ld
parentc218c617b5be443b7968308506969ad2b726d73c (diff)
downloaddev86-f8de35da65c5d93bb733073cf40da154bc1c0748.tar.gz
Import Dev86src-0.0.9.tar.gzv0.0.9
Diffstat (limited to 'ld')
-rw-r--r--ld/Makefile8
-rw-r--r--ld/bindef.h20
-rw-r--r--ld/ld.c25
-rw-r--r--ld/readobj.c18
-rw-r--r--ld/writebin.c18
-rw-r--r--ld/writex86.c15
6 files changed, 85 insertions, 19 deletions
diff --git a/ld/Makefile b/ld/Makefile
index a4d2bb7..6351f10 100644
--- a/ld/Makefile
+++ b/ld/Makefile
@@ -1,11 +1,11 @@
ifneq ($(TOPDIR),)
include $(TOPDIR)/Make.defs
-
-CFLAGS=$(CCFLAGS) -DREL_OUTPUT
+CFLAGS =$(CCFLAGS) -DREL_OUTPUT
else
-CC=bcc -3 -N
-LDFLAGS=
+LDFLAGS =-s
+LIBDIR =/usr/bin
+CFLAGS =-O -DREL_OUTPUT
endif
# May need some of these if the auto-sense fails.
diff --git a/ld/bindef.h b/ld/bindef.h
index 4ccaf53..2a2d8d8 100644
--- a/ld/bindef.h
+++ b/ld/bindef.h
@@ -1,4 +1,6 @@
+#ifndef MSDOS
+#ifndef NO_AOUT
/* Ok, I'm just gonna make it simple ... override this if you like. */
#ifndef A_OUT_INCL
#define A_OUT_INCL "a.out.h"
@@ -12,12 +14,7 @@
# else
# define A_OUT_INCL "bsd-a.out.h"
# endif
-
-# ifdef MSDOS
-# define A_OUT_INCL "a_out.h"
-# else
-# define A_OUT_INCL "a.out.h" /* maybe local copy of <a.out.h> for X-link */
-# endif
+# define A_OUT_INCL "a.out.h" /* maybe local copy of <a.out.h> for X-link */
# endif /* BSD_A_OUT */
#endif
@@ -48,7 +45,9 @@
# else
# define RELOC_INFO_SIZE (sizeof (struct relocation_info))
# endif
-# define C_EXT N_EXT
+# ifdef N_EXT
+# define C_EXT N_EXT
+# endif
# define C_STAT 0
# define n_was_name n_un.n_name
# define n_was_numaux n_other
@@ -66,3 +65,10 @@
# define n_was_type n_type
# endif /* BSD_A_OUT */
+/* And finally make sure it worked */
+#ifdef C_EXT
+#define AOUT_DETECTED 1
+#endif
+
+#endif /* NO_AOUT */
+#endif /* MSDOS */
diff --git a/ld/ld.c b/ld/ld.c
index eacbaa2..a98618e 100644
--- a/ld/ld.c
+++ b/ld/ld.c
@@ -184,6 +184,31 @@ char **argv;
}
}
+#ifdef REL_OUTPUT
+#ifndef MSDOS
+ if( flag['r'] && !flag['N'] )
+ {
+ /* Ok, try for an alternate linker */
+ if( strcmp(argv[0], "ld86r") != 0 )
+ {
+ argv[0] = "ld86r";
+ execv("/usr/bin/ld86r", argv);
+ execv("/usr/bin/ld86", argv);
+ }
+ }
+#endif
+#endif
+
+#ifdef MSDOS
+ /* MSDOS Native is special, we make a COM file */
+ if( flag['N'] )
+ {
+ flag['N'] = 0;
+ flag['d'] = 1;
+ text_base_value = 0x100;
+ }
+#endif
+
/* Headerless executables can't use symbols. */
headerless = flag['d'];
if( headerless ) flag['s'] = 1;
diff --git a/ld/readobj.c b/ld/readobj.c
index da83b0a..137facc 100644
--- a/ld/readobj.c
+++ b/ld/readobj.c
@@ -77,14 +77,22 @@ bool_pt trace;
filepos = SARMAG;
while ((filelength = readarheader(&archentry)) > 0)
{
+ unsigned int magic;
if (trace)
errtrace(archentry, 2);
filepos += sizeof(struct ar_hdr);
- for (modcount = readfileheader(); modcount-- != 0;)
+ magic = (unsigned) readsize(2);
+ if(magic == OMAGIC)
{
- readmodule(stralloc(filename), archentry);
- modlast->textoffset += filepos;
+ seekin(filepos);
+ for (modcount = readfileheader(); modcount-- != 0;)
+ {
+ readmodule(stralloc(filename), archentry);
+ modlast->textoffset += filepos;
+ }
}
+ else if( magic == 0x3C21 ) /* "!<" */
+ filelength = SARMAG;
seekin(filepos += ld_roundup(filelength, 2, long));
}
break;
@@ -107,8 +115,8 @@ char **parchentry;
arheader.ar_name, sizeof arheader.ar_name);
endptr = nameptr + sizeof arheader.ar_name;
do
- *endptr = 0;
- while (endptr > nameptr && *--endptr == ' ');
+ *endptr-- = 0;
+ while (endptr > nameptr && (*endptr == ' ' || *endptr == '/'));
return strtoul(arheader.ar_size, (char **) NUL_PTR, 0);
}
diff --git a/ld/writebin.c b/ld/writebin.c
index de4b01c..60440f7 100644
--- a/ld/writebin.c
+++ b/ld/writebin.c
@@ -3,14 +3,18 @@
/* Copyright (C) 1994 Bruce Evans */
-#include "syshead.h"
+#ifndef NO_AOUT
#define A_OUT_INCL <a.out.h>
+#endif
+
+#include "syshead.h"
#include "bindef.h"
#include "const.h"
#include "obj.h"
#include "type.h"
#include "globvar.h"
+#ifdef AOUT_DETECTED
#define btextoffset (text_base_value)
#define bdataoffset (data_base_value)
#define page_size() 4096
@@ -936,3 +940,15 @@ bin_off_t count;
while (count-- > 0)
writechar(0);
}
+#else
+
+PUBLIC void writebin(outfilename, argsepid, argbits32, argstripflag, arguzp)
+char *outfilename;
+bool_pt argsepid;
+bool_pt argbits32;
+bool_pt argstripflag;
+bool_pt arguzp;
+{
+ fatalerror("Native a.out generation not included, sorry");
+}
+#endif
diff --git a/ld/writex86.c b/ld/writex86.c
index 25cc0d6..2b0f00a 100644
--- a/ld/writex86.c
+++ b/ld/writex86.c
@@ -13,6 +13,12 @@
#define bdataoffset (data_base_value)
#define page_size() ((bin_off_t)4096)
+#ifdef __ELF__
+#ifndef ELF_SYMS
+#define ELF_SYMS 1
+#endif
+#endif
+
# define FILEHEADERLENGTH (headerless?0:A_MINHDR)
/* part of header not counted in offsets */
#define DPSEG 2
@@ -94,7 +100,11 @@ bool_pt arguzp;
bin_off_t tempoffset;
if( reloc_output )
+#ifndef MSDOS
fatalerror("Output binformat not configured relocatable, use -N");
+#else
+ fatalerror("Cannot use -r under MSDOS, sorry");
+#endif
sepid = argsepid;
bits32 = argbits32;
@@ -286,7 +296,7 @@ bool_pt arguzp;
(symptr = *symparray) != NUL_PTR; ++symparray)
if (symptr->modptr == modptr)
{
-#ifdef __ELF__
+#if ELF_SYMS
if (symptr->name[0] == '_' && symptr->name[1] )
strncpy((char *) extsym.n_name, symptr->name+1,
sizeof extsym.n_name);
@@ -519,7 +529,8 @@ PRIVATE void writeheader()
offtocn((char *) &header.a_entry, page_size(),
sizeof header.a_entry);
offtocn((char *) &header.a_total, (bin_off_t)
- (endoffset < 0x00010000L ? 0x00010000L : endoffset + 0x0008000L),
+ (endoffset < 0x00008000L ? endoffset+0x8000L :
+ (endoffset < 0x00010000L ? 0x00010000L : endoffset + 0x0008000L)),
sizeof header.a_total);
if( FILEHEADERLENGTH )
writeout((char *) &header, FILEHEADERLENGTH);