From: sandmann AT clio DOT rice DOT edu (Charles Sandmann) Message-Id: <10211290511.AA14332@clio.rice.edu> Subject: DXE enhancements To: djgpp-workers AT delorie DOT com (DJGPP developers) Date: Thu, 28 Nov 2002 23:11:42 -0600 (CST) X-Mailer: ELM [version 2.5 PL2] Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com I've been hacking on DXEs. In particular, I want to be able to call I/O and other lib routines from DXEs; this will allow us to put big libraries such as libiconv there. Included below are my current working patches for comments. There is a new switch "-i" which enables the new behavior. If you use it, it does not complain about unresolved symbols, it assumes they will be fixed up at _dxe_load time; it then puts the required fixups at the end of the image. _dxe_load has a corresponding change to check for this new section and fix up values. It needs a fixup vector which is assumed to be set externally before calling _dxe_load in a wrapper. This fixup vector is currently written to the screen by dxegen; it would be linked into images loading the DXE (solves the strip issue). This is all very lightweight - my example DXE which calls malloc and printf is less than 200 bytes in size; the new dxe_load is only 200 bytes or more in size. I also plan to support multiple exports in a future hack, but that can be done today manually (the num_exports code below gives hints where it goes). Comments? *** dxegen.c_ Sun Dec 9 18:14:22 2001 --- dxegen4.c Thu Nov 28 22:53:10 2002 *************** int main(int argc, char **argv) *** 71,74 **** --- 71,88 ---- size_t i; dxe_header dh; + int num_import, num_export = 0; + long *import_symndx = NULL; + char **import_name = NULL; + + if (argc >= 2 && strcmp(argv[1], "-i") == 0) + { + argv++; + argc--; + num_import = 0; /* New option to allow imports */ + import_symndx = malloc(sizeof(long)); + import_name = malloc(sizeof(char *)); + } + else + num_import = -1; /* No imports allowed */ if (argc < 4) *************** int main(int argc, char **argv) *** 89,93 **** if (fh.f_nscns != 1 || argc > 4) { ! char command[1024], *libdir; fclose(input_f); --- 103,110 ---- if (fh.f_nscns != 1 || argc > 4) { ! char *command, *libdir; ! unsigned cmdmax = 1024; ! command = (char *)malloc(cmdmax); ! fclose(input_f); *************** int main(int argc, char **argv) *** 115,127 **** for(i=3;argv[i];i++) { strcat(command, argv[i]); strcat(command, " "); } strcat(command," -T dxe.ld "); ! printf("%s\n",command); i = system(command); if(i) return i; input_f = fopen("dxe__tmp.o", "rb"); --- 132,154 ---- for(i=3;argv[i];i++) { + if(strlen(command) + strlen(argv[i]) + 2 > cmdmax) { + cmdmax += 1024; + command = realloc(command, cmdmax); + } strcat(command, argv[i]); strcat(command, " "); } + + if(strlen(command) + 12 > cmdmax) { + cmdmax += 12; + command = realloc(command, cmdmax); + } strcat(command," -T dxe.ld "); ! printf("%s\n",command); i = system(command); if(i) return i; + free(command); input_f = fopen("dxe__tmp.o", "rb"); *************** int main(int argc, char **argv) *** 161,164 **** --- 188,203 ---- strings = malloc(strsz); fread(strings+4, 1, strsz-4, input_f); + + relocs = malloc(sizeof(RELOC)*sc.s_nreloc); + fseek(input_f, sc.s_relptr, 0); + fread(relocs, sc.s_nreloc, RELSZ, input_f); + #if 0 + /* Don't swap - it's in i386 order already */ + for (i=0; i 0) + { + for (i=0; i + char *_dxe_data; + long *_dxe_fixup; + void *_dxe_load(char *name) { *************** void *_dxe_load(char *name) *** 39,43 **** int i; _read(h, relocs, sizeof(long)*dh.nrelocs); - _close(h); for (i=0; i