#include "section.h"
#include "symbol.h"
+#define LD_OPTION_IGNORED 0
+#define LD_OPTION_SHARED 1
+
+static struct ld_option opts[] = {
+
+ { "--shared", LD_OPTION_TYPE_LONG, LD_OPTION_SHARED, LD_OPTION_NO_ARG },
+ { "-Bshareable", LD_OPTION_TYPE_LONG, LD_OPTION_SHARED, LD_OPTION_NO_ARG },
+
+ { 0, 0, 0, 0 }
+
+};
+
+int axe_check_option (const char *cmd_arg, int argc, char **argv, int *optind, const char **optarg) {
+
+ struct ld_option *popt;
+
+ for (popt = opts; ; popt++) {
+
+ const char *p1 = popt->name;
+ const char *r1 = cmd_arg;
+
+ if (!p1) {
+ break;
+ }
+
+ if (!strstart (p1, &r1)) {
+
+ if (popt->type == LD_OPTION_TYPE_LONG) {
+
+ if (*r1 != '-') {
+ continue;
+ }
+
+ p1 = popt->name + 1;
+ r1 = cmd_arg;
+
+ if (!strstart (p1, &r1)) {
+ continue;
+ }
+
+ } else {
+ continue;
+ }
+
+ }
+
+ (*optarg) = r1;
+
+ if (popt->flgs & LD_OPTION_HAS_ARG) {
+
+ if (*r1 == '\0') {
+
+ if ((*optind) >= argc) {
+
+ report_at (program_name, 0, REPORT_ERROR, "argument to '%s' is missing", cmd_arg);
+ exit (EXIT_FAILURE);
+
+ }
+
+ (*optarg) = argv[(*optind)++];
+
+ }
+
+ } else if (*r1 != '\0') {
+ continue;
+ }
+
+ return popt->idx;
+
+ }
+
+ return -1;
+
+}
+
+void axe_use_option (const char *cmd_arg, int idx, const char *optarg) {
+
+ (void) optarg;
+
+ switch (idx) {
+
+ case LD_OPTION_IGNORED: {
+
+ break;
+
+ }
+
+ case LD_OPTION_SHARED: {
+
+ state->create_shared_library = 1;
+ break;
+
+ }
+
+ default: {
+
+ report_at (program_name, 0, REPORT_ERROR, "unsupported option '%s'", cmd_arg);
+ exit (EXIT_FAILURE);
+
+ }
+
+ }
+
+}
+
+void axe_print_help (void) {
+
+ fprintf (stderr, "axe:\n\n");
+ fprintf (stderr, " -shared, -Bshareable Create a shared library.\n");
+
+}
+
+
#define EM_I386 3
#define EM_AMD64 62
};
#define AXE_TYPE 0x1e
+int axe_check_option (const char *cmd_arg, int argc, char **argv, int *optind, const char **optarg);
+
+void axe_print_help (void);
+void axe_use_option (const char *cmd_arg, int idx, const char *optarg);
+
void axe_before_link (void);
void axe_write32 (const char *filename);
unsigned long size_of_headers;
int emulation, generate_symbols_table, impure;
+ int leading_underscore;
};
#define LD_EMULATION_I386_DX 0x05
#define LD_EMULATION_I386_PE 0x06
-#define LD_EMULATION_MACHO 0x07
+#define LD_EMULATION_AXE 0x07
+#define LD_EMULATION_MACHO 0x08
#define LD_FORMAT_COM 0x00
#include <stdlib.h>
#include <string.h>
+#include "axe.h"
#include "ld.h"
#include "lib.h"
#include "macho.h"
{ 0, 0, 0 },
{ 0, 0, 0 },
{ &pe_print_help, &pe_check_option, &pe_use_option },
+ { &axe_print_help, &axe_check_option, &axe_use_option },
{ &macho_print_help, &macho_check_option, &macho_use_option }
};
state->format = LD_FORMAT_I386_AXE;
- /*if (state->emulation == LD_EMULATION_NONE) {
- state->emulation = LD_EMULATION_I386_AOUT;
- }*/
+ if (state->emulation == LD_EMULATION_NONE) {
+ state->emulation = LD_EMULATION_AXE;
+ }
break;
state->format = LD_FORMAT_AMD64_AXE;
- /*if (state->emulation == LD_EMULATION_NONE) {
- state->emulation = LD_EMULATION_I386_AOUT;
- }*/
+ if (state->emulation == LD_EMULATION_NONE) {
+ state->emulation = LD_EMULATION_AXE;
+ }
break;
state->emulation = LD_EMULATION_I386_PE;
}
+ state->leading_underscore = 0;
break;
}
}
+ state->leading_underscore = 1;
+
while (optind < argc) {
r = argv[optind++];
#include "write7x.h"
static char *output_implib_filename = 0;
-static int kill_at = 0, leading_underscore = 1;
+static int kill_at = 0;
static unsigned short subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
}
- leading_underscore = 0;
break;
}
name_list = xmalloc (sizeof (*name_list));
- if (leading_underscore && symbol->name[0] == '_') {
+ if (state->leading_underscore && symbol->name[0] == '_') {
name_list->name = xstrdup (symbol->name + 1);
} else {
name_list->name = xstrdup (symbol->name);
symbol_info = xmalloc (sizeof (*symbol_info));
symbol_info->name = xmalloc (7 + strlen (export_name[i].name) + 1);
- if (leading_underscore) {
+ if (state->leading_underscore) {
sprintf (symbol_info->name, "__imp__%s", export_name[i].name);
} else {
sprintf (symbol_info->name, "__imp_%s", export_name[i].name);
offsets[4 + i] = offset2;
- if (leading_underscore) {
+ if (state->leading_underscore) {
offset2 += write_file_header (outfile, header_name, bHeaderName, sizeof (import_hdr) + 1 + strlen (export_names[i].name) + 1 + module_name_length + 1, 0);
} else {
offset2 += write_file_header (outfile, header_name, bHeaderName, sizeof (import_hdr) + strlen (export_names[i].name) + 1 + module_name_length + 1, 0);
integer_to_array (IMAGE_FILE_MACHINE_I386, import_hdr.Machine, 2, 0);
}
- if (leading_underscore) {
+ if (state->leading_underscore) {
integer_to_array (1 + strlen (export_names[i].name) + 1 + module_name_length + 1, import_hdr.SizeOfData, 4, 0);
} else {
integer_to_array (strlen (export_names[i].name) + 1 + module_name_length + 1, import_hdr.SizeOfData, 4, 0);
}
- type |= (kill_at ? IMPORT_NAME_UNDECORATE : IMPORT_NAME_NOPREFIX) << 2;
+ if (kill_at) {
+ type |= IMPORT_NAME_UNDECORATE << 2;
+ } else if (state->leading_underscore) {
+ type |= IMPORT_NAME_NOPREFIX << 2;
+ } else {
+ type |= IMPORT_NAME << 2;
+ }
integer_to_array (type, import_hdr.Type, 2, 0);
offset2 += write_data (outfile, &import_hdr, sizeof (import_hdr));
- if (leading_underscore) {
+ if (state->leading_underscore) {
name = xmalloc (1 + strlen (export_names[i].name) + 1);
sprintf (name, "_%s", export_names[i].name);
for (i = 0; i < num_names; i++) {
- if (leading_underscore) {
+ if (state->leading_underscore) {
symbol->name = xmalloc (1 + strlen (export_names[i].name) + 1);
sprintf (symbol->name, "_%s", export_names[i].name);
symbol->name = xmalloc (6 + strlen (import_name) + 1);
- if (leading_underscore) {
+ if (state->leading_underscore) {
sprintf (symbol->name, "__imp_%s", import_name);
} else {
sprintf (symbol->name, "__imp%s", import_name);