diff options
author | Robert de Bath <rdebath@poboxes.com> | 1997-07-20 12:16:17 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:39:55 +0200 |
commit | 9d97bc3cb3aecd3416fb7c4be3ca2f436665b696 (patch) | |
tree | b1e5b67ef9e065efb6a4c9977ecfac8dedbad39b /ld | |
parent | e63c244cb22bf48ca1d2695784a072269d19ea96 (diff) | |
download | dev86-9d97bc3cb3aecd3416fb7c4be3ca2f436665b696.tar.gz |
Import Dev86src-0.12.4.tar.gzv0.12.4
Diffstat (limited to 'ld')
-rw-r--r-- | ld/Makefile | 6 | ||||
-rw-r--r-- | ld/io.c | 7 | ||||
-rw-r--r-- | ld/objchop.c | 87 | ||||
-rw-r--r-- | ld/typeconv.c | 4 | ||||
-rw-r--r-- | ld/x86_aout.h | 2 |
5 files changed, 101 insertions, 5 deletions
diff --git a/ld/Makefile b/ld/Makefile index 2e30d96..9e1f124 100644 --- a/ld/Makefile +++ b/ld/Makefile @@ -1,7 +1,7 @@ LIBDIR =/usr/bin CFLAGS =-O -LDFLAGS =-s +LDFLAGS = # May need some of these if the auto-sense fails. # -DV7_A_OUT # a.out.h is like V7 @@ -18,7 +18,7 @@ DEFS =-DREL_OUTPUT -DBUGCOMPAT OBJS= dumps.o io.o ld.o readobj.o table.o typeconv.o linksyms.o \ writex86.o writebin.o writerel.o -all: ld86 +all: ld86 objchop ld86: $(OBJS) $(CC) $(LDFLAGS) $(OBJS) -o $@ @@ -28,7 +28,7 @@ install: ld86 install -m 755 ld86 $(LIBDIR) clean realclean: - rm -f $(OBJS) ld86 + rm -f *.o ld86 objchop $(OBJS): align.h ar.h bindef.h byteord.h config.h const.h globvar.h obj.h \ syshead.h type.h x86_aout.h @@ -121,8 +121,10 @@ int level; PUBLIC void executable() { +#ifndef MSDOS if (errcount == 0) chmod(outputname, outputperms); +#endif } PUBLIC void flusherr() @@ -179,15 +181,18 @@ char *filename; outputname = filename; #ifdef O_BINARY - if ((outfd = open(filename, O_BINARY|O_RDWR|O_CREAT|O_TRUNC, CREAT_PERMS)) == ERR) + if ((outfd = open(filename, O_BINARY|O_WRONLY|O_CREAT|O_TRUNC, CREAT_PERMS)) == ERR) #else if ((outfd = creat(filename, CREAT_PERMS)) == ERR) #endif outputerror("cannot open"); +#ifndef MSDOS + /* Can't do this on MSDOS; it upsets share.exe */ oldmask = umask(0); umask(oldmask); outputperms = ((CREAT_PERMS | EXEC_PERMS) & ~oldmask); chmod(filename, outputperms & ~EXEC_PERMS); +#endif #ifdef REL_OUTPUT drelbufptr = drelbuf; diff --git a/ld/objchop.c b/ld/objchop.c new file mode 100644 index 0000000..c5a81e4 --- /dev/null +++ b/ld/objchop.c @@ -0,0 +1,87 @@ + +#include <stdio.h> +#include "x86_aout.h" + +#ifndef __OUT_OK + +main() +{ + fprintf(stderr, "Compile error: struct exec invalid\n"); + exit(1); +} + +#else + +FILE * ifd; +struct exec header; + +main(argc, argv) +int argc; +char ** argv; +{ + FILE * ofd; + if( argc != 5 ) fatal("Usage: objchop a.out text.bin data.bin sizes.asm"); + + ifd = fopen(argv[1], "r"); + if( ifd == 0 ) fatal("Cannot open input file"); + + if( fread(&header, A_MINHDR, 1, ifd) != 1 ) + fatal("Incomplete executable header"); + + if( BADMAG(header) ) + fatal("Input file has bad magic number"); + + if( fseek(ifd, A_TEXTPOS(header), 0) < 0 ) + fatal("Cannot seek to start of text"); + + write_file(argv[2], header.a_text); + + if( fseek(ifd, A_DATAPOS(header), 0) < 0 ) + fatal("Cannot seek to start of data"); + + write_file(argv[3], header.a_data); + + ofd = fopen(argv[4], "w"); + if( ofd == 0 ) fatal("Cannot open output file"); + + fprintf(ofd, "TEXT_SIZE=%ld\nDATA_SIZE=%ld\nBSS_SIZE=%ld\nALLOC_SIZE=%ld\n", + header.a_text, header.a_data, header.a_bss, header.a_total); + + fclose(ofd); + + exit(0); +} + +write_file(fname, bsize) +char * fname; +long bsize; +{ + char buffer[1024]; + int ssize; + FILE * ofd; + + ofd = fopen(fname, "w"); + if( ofd == 0 ) fatal("Cannout open output file"); + + while(bsize>0) + { + if( bsize > sizeof(buffer) ) ssize = sizeof(buffer); + else ssize = bsize; + + if( (ssize=fread(buffer, 1, ssize, ifd)) <= 0 ) + fatal("Error reading segment from executable"); + if( fwrite(buffer, 1, ssize, ofd) != ssize ) + fatal("Error writing output file"); + bsize -= ssize; + } + fclose(ofd); +} + +fatal(str) +char * str; +{ + fprintf(stderr, "objchop: %s\n", str); + exit(2); +} + +#endif diff --git a/ld/typeconv.c b/ld/typeconv.c index 6cc4a20..708d92b 100644 --- a/ld/typeconv.c +++ b/ld/typeconv.c @@ -156,6 +156,8 @@ unsigned count; { switch (count) { + case 0: + return 0; case 1: return buf[0] & 0xFF; case 2: @@ -174,6 +176,8 @@ unsigned count; { switch (count) { + case 0: + return 0; case 1: return buf[0] & 0xFF; case 2: diff --git a/ld/x86_aout.h b/ld/x86_aout.h index af2c537..777f281 100644 --- a/ld/x86_aout.h +++ b/ld/x86_aout.h @@ -9,7 +9,7 @@ #define __AOUT_H /* If the host isn't an x86 all bets are off, use chars. */ -#if defined(i386) || defined(__BCC__) +#if defined(i386) || defined(__BCC__) || defined(MSDOS) typedef long Long; #define __OUT_OK 1 #else |