outcoff: BR 2685756: fix SAFESEH with an internal symbol
[nasm/perl-rewrite.git] / rdoff / rdx.c
blob8e70b1ad272c06544550b2b6b434e754b4d4160e
1 /* rdx.c RDOFF Object File loader program
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the license given in the file "LICENSE"
6 * distributed in the NASM archive.
7 */
9 /* note: most of the actual work of this program is done by the modules
10 "rdfload.c", which loads and relocates the object file, and by "rdoff.c",
11 which contains general purpose routines to manipulate RDOFF object
12 files. You can use these files in your own program to load RDOFF objects
13 and execute the code in them in a similar way to what is shown here. */
15 #include "compiler.h"
17 #include <stdio.h>
18 #include <stdlib.h>
20 #include "rdfload.h"
21 #include "symtab.h"
23 typedef int (*main_fn) (int, char **); /* Main function prototype */
25 int main(int argc, char **argv)
27 rdfmodule *m;
28 main_fn code;
29 symtabEnt *s;
31 if (argc < 2) {
32 puts("usage: rdx <rdoff-executable> [params]\n");
33 exit(255);
36 m = rdfload(argv[1]);
38 if (!m) {
39 rdfperror("rdx", argv[1]);
40 exit(255);
43 rdf_relocate(m); /* in this instance, the default relocation
44 values will work fine, but they may need changing
45 in other cases... */
47 s = symtabFind(m->symtab, "_main");
48 if (!s) {
49 fprintf(stderr, "rdx: could not find symbol '_main' in '%s'\n",
50 argv[1]);
51 exit(255);
54 code = (main_fn)(size_t) s->offset;
56 argv++, argc--; /* remove 'rdx' from command line */
58 return code(argc, argv); /* execute */