Browse Source

Some fixes for aelflod and aslod.

Copy rhead() and rsect() from aslod to aelflod, so aelflod can work
for machine with 64-bit long.

In aelflod, fix ELF header so file(1) no longer reports "corrupted
section header size".

Signed-off-by: Manoel Trapier <godzil@godzil.net>
George Koehler 11 years ago
parent
commit
c602379db9
2 changed files with 25 additions and 36 deletions
  1. 24 35
      util/amisc/aelflod.c
  2. 1 1
      util/amisc/aslod.c

+ 24 - 35
util/amisc/aelflod.c

@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include "../../modules/src/object/obj.h"
 #include <stdarg.h>
 #include <stdint.h>
 #include <string.h>
@@ -70,7 +71,7 @@ const char elf_le_ident_string[] = {
 
 char hdr[HDR_LENGTH] ;
 
-/* Segment numbers understood by aslod. */
+/* Segment numbers understood by aelflod. */
 
 enum {
 	TEXT = 0,
@@ -222,42 +223,25 @@ void emitphdr(unsigned long address, unsigned long filesize,
 	fileoffset += filesize;
 }
 
-void iconvert(char* buf, char* str, char* fmt)
-{
-	register char *nf, *ni, *no ;
-	int last, i ;
-	uint32_t value ;
-	ni=buf ; no=str ; nf=fmt ;
-	while (( last = *nf++ )) {
-		last -= '0' ;
-		if ( last<1 || last >9 ) fatal("illegal out.h format string\n");
-		value=0 ;
-		i=last ;
-		while ( i-- ) {
-			value = (value<<8) + (ni[i]&0xFF) ;
-		}
-		switch ( last ) {
-		case 0 : break ;
-		case 1 : *no= value ; break ;
-		case 2 : *(uint16_t *)no = value ; break ;
-		case 4 : *(uint32_t *)no = value ; break ;
-		default :
-			 fatal("illegal out.h format string\n");
-		}
-		ni += last ; no += last ;
-	}
-}
-
 /* Read the ack.out file header. */
 
 int rhead(FILE* f, struct outhead* head)
 {
-	char buf[sizeof(struct outhead)];
+	char buf[SZ_HEAD], *c;
 	
 	if (fread(buf, sizeof(buf), 1, f) != 1)
 		return 0;
-		
-	iconvert(buf, (char*) head, SF_HEAD);
+
+	c = buf;
+	head->oh_magic = uget2(c); c += 2;
+	head->oh_stamp = uget2(c); c += 2;
+	head->oh_flags = uget2(c); c += 2;
+	head->oh_nsect = uget2(c); c += 2;
+	head->oh_nrelo = uget2(c); c += 2;
+	head->oh_nname = uget2(c); c += 2;
+	head->oh_nemit = get4(c); c += 4;
+	head->oh_nchar = get4(c);
+
 	return 1;
 }
 
@@ -265,12 +249,17 @@ int rhead(FILE* f, struct outhead* head)
  
 int rsect(FILE* f, struct outsect* sect)
 {
-	char buf[sizeof(struct outsect)];
+	char buf[SZ_SECT], *c;
 	
 	if (fread(buf, sizeof(buf), 1, f) != 1)
 		return 0;
 		
-	iconvert(buf, (char*) sect, SF_SECT);
+	c = buf;
+	sect->os_base = get4(c); c += 4;
+	sect->os_size = get4(c); c += 4;
+	sect->os_foff = get4(c); c += 4;
+	sect->os_flen = get4(c); c += 4;
+	sect->os_lign = get4(c);
 	return 1 ;
 }
 
@@ -289,13 +278,13 @@ int main(int argc, char* argv[])
 		switch (argv[1][1])
 		{
 			case 'h':
-				fprintf(stderr, "%s: Syntax: aslod [-h] <inputfile> <outputfile>\n",
+				fprintf(stderr, "%s: Syntax: aelflod [-h] <inputfile> <outputfile>\n",
 					program);
 				exit(0);
 				
 			default:
 			syntaxerror:
-				fatal("syntax error --- try -h for help)");
+				fatal("syntax error --- try -h for help");
 		}
 		
 		argv++;
@@ -409,7 +398,7 @@ int main(int argc, char* argv[])
 	emit16(ELF_HEADER_SIZE);           /* elf header size */
 	emit16(PROGRAM_HEADER_SIZE);       /* program header entry size */
 	emit16(1);                         /* number of program header entries */
-	emit16(0);                         /* section header entry size */
+	emit16(0x28);                         /* section header entry size */
 	emit16(0);                         /* number of section header entries */
 	emit16(0);                         /* section header string table index = SHN_UNDEF */
 	

+ 1 - 1
util/amisc/aslod.c

@@ -209,7 +209,7 @@ int main(int argc, char* argv[])
 				
 			default:
 			syntaxerror:
-				fatal("syntax error --- try -h for help)");
+				fatal("syntax error --- try -h for help");
 		}
 		
 		argv++;