+++ /dev/null
-#******************************************************************************
-# @file Makefile.p32
-#******************************************************************************
-AS=as386
-CC=gcc386
-LD=ld386
-
-COPTS=-S -O2 -fno-common -ansi -I. -I./include -I../pdos/pdpclib -I../pdos/src -D__PDOS386__ -D__32BIT__ -D__NOBIVA__ -D__PDOS__ -Wall -Werror -ansi -m32 -pedantic
-COBJ=aout.o coff.o elks.o hashtab.o ld.o lib.o link.o map.o mz.o omf.o pe.o report.o section.o symbol.o vector.o write7x.o
-
-all: clean slink.exe
-
-slink.exe: $(COBJ)
- $(LD) -s -o slink.exe ../pdos/pdpclib/pdosst32.o $(COBJ) ../pdos/pdpclib/pdos.a
-
-.c.o:
- $(CC) $(COPTS) -o $*.s $<
- $(AS) -o $@ $*.s
- rm -f $*.s
-
-clean:
- for %f in ($(COBJ)) do ( rm -f %f )
-
- rm -f slink
- rm -f slink.exe
+++ /dev/null
-#******************************************************************************
-# @file Makefile.pdw
-#******************************************************************************
-AS=aswin
-CC=gccwin
-LD=ldwin
-
-COPTS=-S -O2 -fno-common -ansi -I. -I./include -I../pdos/pdpclib -I../pdos/src -D__WIN32__ -D__NOBIVA__ -D__PDOS__ -Wall -Werror -ansi -m32 -pedantic
-COBJ=aout.o coff.o elks.o hashtab.o ld.o lib.o link.o map.o mz.o omf.o pe.o report.o section.o symbol.o vector.o write7x.o
-
-all: clean slink.exe
-
-slink.exe: $(COBJ)
- $(LD) -s -o slink.exe ../pdos/pdpclib/w32start.o $(COBJ) ../pdos/pdpclib/msvcrt.a ../pdos/src/kernel32.a
-
-.c.o:
- $(CC) $(COPTS) -o $*.s $<
- $(AS) -o $@ $*.s
- rm -f $*.s
-
-clean:
- for %f in ($(COBJ)) do ( rm -f %f )
-
- rm -f slink
- rm -f slink.exe
+++ /dev/null
-AS=pdas --oformat coff
-CC=gccwin
-LD=pdld
-
-COPTS=-S -O2 -fno-common -ansi -I. -I../pdos/pdpclib -D__WIN32__ -D__NOBIVA__ -D__PDOS__
-COBJ=aout.obj coff.obj elks.obj hashtab.obj ld.obj lib.obj link.obj map.obj \
- mz.obj omf.obj pe.obj report.obj section.obj symbol.obj vector.obj write7x.obj
-
-all: clean slink.exe
-
-slink.exe: $(COBJ)
- $(LD) -s -nostdlib --no-insert-timestamp -o slink.exe ../pdos/pdpclib/w32start.obj $(COBJ) ../pdos/pdpclib/msvcrt.lib
-
-.c.obj:
- $(CC) $(COPTS) $<
- $(AS) -o $@ $*.s
- rm -f $*.s
-
-clean:
- rm -f *.obj slink.exe
#include "section.h"
#include "symbol.h"
+static unsigned long section_alignment = DEFAULT_SECTION_ALIGNMENT;
+
static void translate_relocation (struct reloc_entry *reloc, struct aout_relocation_info *input_reloc, struct section_part *part, struct aout_exec *exec_p) {
unsigned long r_symbolnum = array_to_integer (input_reloc->r_symbolnum, 4);
FILE *fp;
unsigned char *data, *pos;
- unsigned long data_size;
+ unsigned long image_size;
struct section *text_section, *data_section, *bss_section;
+ unsigned long text_size = 0, data_size = 0, bss_size = 0;
struct aout_exec exec;
memset (&exec, 0, sizeof (exec));
integer_to_array (OMAGIC, exec.a_info, 4);
+ if (text_section) {
+
+ if (state->impure) {
+ text_size = text_section->total_size;
+ } else {
+ text_size = ALIGN (text_section->total_size, section_alignment);
+ }
+
+ }
+
if (data_section) {
- integer_to_array (data_section->rva, exec.a_text, 4);
-
- if (bss_section) {
- integer_to_array (bss_section->rva - data_section->rva, exec.a_data, 4);
+ if (state->impure) {
+ data_size = data_section->total_size;
} else {
- integer_to_array (data_section->total_size, exec.a_data, 4);
+ data_size = ALIGN (data_section->total_size, section_alignment);
}
- } else {
+ }
- integer_to_array (0, exec.a_data, 4);
-
- if (bss_section) {
- integer_to_array (bss_section->rva, exec.a_text, 4);
+ if (bss_section) {
+
+ if (state->impure) {
+ bss_size = bss_section->total_size;
} else {
- integer_to_array (text_section ? text_section->total_size : 0, exec.a_text, 4);
+ bss_size = ALIGN (bss_section->total_size, section_alignment);
}
}
- integer_to_array (bss_section ? bss_section->total_size : 0, exec.a_bss, 4);
+ integer_to_array (text_size, exec.a_text, 4);
+ integer_to_array (data_size, exec.a_data, 4);
+
+ integer_to_array (bss_size, exec.a_bss, 4);
integer_to_array (state->entry_point, exec.a_entry, 4);
if (text_section) {
integer_to_array (section_get_num_relocs (data_section) * sizeof (struct aout_relocation_info), exec.a_drsize, 4);
}
- data_size = sizeof (exec);
+ image_size = sizeof (exec);
- data_size += (array_to_integer (exec.a_text, 4) + array_to_integer (exec.a_data, 4));
- data_size += (array_to_integer (exec.a_trsize, 4) + array_to_integer (exec.a_drsize, 4));
+ image_size += (array_to_integer (exec.a_text, 4) + array_to_integer (exec.a_data, 4));
+ image_size += (array_to_integer (exec.a_trsize, 4) + array_to_integer (exec.a_drsize, 4));
- data_size += 4;
+ image_size += 4;
- data = xmalloc (data_size);
+ data = xmalloc (image_size);
memcpy (data, &exec, sizeof (exec));
pos = data + sizeof (exec);
integer_to_array (4, pos, 4);
- if (fwrite (data, data_size, 1, fp) != 1) {
+ if (fwrite (data, image_size, 1, fp) != 1) {
report_at (program_name, 0, REPORT_ERROR, "failed to write data to '%s'", filename);
}
fclose (fp);
}
+
+
+void aout_before_link (void) {
+
+ if (!state->impure) {
+
+ struct section *section;
+
+ for (section = all_sections; section; section = section->next) {
+
+ if (section->section_alignment < section_alignment) {
+ section->section_alignment = section_alignment;
+ }
+
+ }
+
+ }
+
+}
#define N_TYPE 0x1e
-void aout_write (const char *filename);
void read_aout_object (const char *filename, unsigned char *data, unsigned long data_size);
+void aout_before_link (void);
+void aout_write (const char *filename);
+
#define OMAGIC 0407
#define ZMAGIC 0413
#include "section.h"
#include "symbol.h"
+static unsigned long section_alignment = DEFAULT_SECTION_ALIGNMENT;
+
static void translate_relocation (struct reloc_entry *reloc, struct elks_relocation_info *input_reloc, struct section_part *part, struct elks_exec *exec_p) {
unsigned long r_symbolnum = array_to_integer (input_reloc->r_symbolnum, 4);
FILE *fp;
unsigned char *data, *pos;
- unsigned long data_size;
+ unsigned long image_size;
struct section *text_section, *data_section, *bss_section;
+ unsigned long text_size = 0, data_size = 0, bss_size = 0;
struct elks_exec exec;
memset (&exec, 0, sizeof (exec));
exec.a_cpu = (state->format == LD_FORMAT_I386_ELKS) ? 0x10 : 0x04;
exec.a_hdrlen = sizeof (exec);
+ if (text_section) {
+
+ if (state->impure) {
+ text_size = text_section->total_size;
+ } else {
+ text_size = ALIGN (text_section->total_size, section_alignment);
+ }
+
+ }
+
if (data_section) {
- integer_to_array (data_section->rva, exec.a_text, 4);
-
- if (bss_section) {
- integer_to_array (bss_section->rva - data_section->rva, exec.a_data, 4);
+ if (state->impure) {
+ data_size = data_section->total_size;
} else {
- integer_to_array (data_section->total_size, exec.a_data, 4);
+ data_size = ALIGN (data_section->total_size, section_alignment);
}
- } else {
+ }
- integer_to_array (0, exec.a_data, 4);
-
- if (bss_section) {
- integer_to_array (bss_section->rva, exec.a_text, 4);
+ if (bss_section) {
+
+ if (state->impure) {
+ bss_size = bss_section->total_size;
} else {
- integer_to_array (text_section ? text_section->total_size : 0, exec.a_text, 4);
+ bss_size = ALIGN (bss_section->total_size, section_alignment);
}
}
- integer_to_array (bss_section ? bss_section->total_size : 0, exec.a_bss, 4);
+ integer_to_array (text_size, exec.a_text, 4);
+ integer_to_array (data_size, exec.a_data, 4);
+
+ integer_to_array (bss_size, exec.a_bss, 4);
integer_to_array (state->entry_point, exec.a_entry, 4);
integer_to_array (array_to_integer (exec.a_text, 4) + array_to_integer (exec.a_data, 4), exec.a_total, 4);
integer_to_array (section_get_num_relocs (data_section) * sizeof (struct elks_relocation_info), exec.a_drsize, 4);
}
- data_size = sizeof (exec);
+ image_size = sizeof (exec);
- data_size += (array_to_integer (exec.a_text, 4) + array_to_integer (exec.a_data, 4));
- data_size += (array_to_integer (exec.a_trsize, 4) + array_to_integer (exec.a_drsize, 4));
+ image_size += (array_to_integer (exec.a_text, 4) + array_to_integer (exec.a_data, 4));
+ image_size += (array_to_integer (exec.a_trsize, 4) + array_to_integer (exec.a_drsize, 4));
- data_size += 4;
+ image_size += 4;
+ data = xmalloc (image_size);
data = xmalloc (data_size);
memcpy (data, &exec, sizeof (exec));
integer_to_array (4, pos, 4);
- if (fwrite (data, data_size, 1, fp) != 1) {
+ if (fwrite (data, image_size, 1, fp) != 1) {
report_at (program_name, 0, REPORT_ERROR, "failed to write data to '%s'", filename);
}
fclose (fp);
}
+
+
+void elks_before_link (void) {
+
+ if (!state->impure) {
+
+ struct section *section;
+
+ for (section = all_sections; section; section = section->next) {
+
+ if (section->section_alignment < section_alignment) {
+ section->section_alignment = section_alignment;
+ }
+
+ }
+
+ }
+
+}
#define N_TYPE 0x1e
#define ELKS_MAGIC 0403
-void elks_write (const char *filename);
void read_elks_object (const char *filename, unsigned char *data, unsigned long data_size);
+void elks_before_link (void);
+void elks_write (const char *filename);
+
#endif /* _ELKS_H */
}
- if (state->format == LD_FORMAT_I386_COFF) {
+ if (state->format == LD_FORMAT_I386_AOUT) {
+ aout_before_link ();
+ } else if (state->format == LD_FORMAT_I386_COFF) {
coff_before_link ();
+ } else if (state->format == LD_FORMAT_I386_ELKS) {
+ elks_before_link ();
} else if (state->format == LD_FORMAT_I386_PE) {
pe_before_link ();
}
int emit_relocs, use_custom_base_address;
unsigned long size_of_headers;
- int generate_symbols_table;
- int emulation;
+ int emulation, generate_symbols_table, impure;
};
extern struct ld_state *state;
extern const char *program_name;
+#define DEFAULT_SECTION_ALIGNMENT 0x1000
+#define DEFAULT_FILE_ALIGNMENT 0x0200
+
void map_write (const char *filename);
void link (void);
#define LD_OPTION_FORMAT 4
#define LD_OPTION_GENERATE_SYMBOLS_TABLE 5
#define LD_OPTION_HELP 6
-#define LD_OPTION_IMAGE_BASE 7
-#define LD_OPTION_MAP 8
-#define LD_OPTION_MAP_FILE 9
-#define LD_OPTION_OUTFILE 10
+#define LD_OPTION_IMPURE 7
+#define LD_OPTION_IMAGE_BASE 8
+#define LD_OPTION_MAP 9
+#define LD_OPTION_MAP_FILE 10
+#define LD_OPTION_OUTFILE 11
static struct ld_option opts[] = {
{ "-M", LD_OPTION_TYPE_SHORT, LD_OPTION_MAP, LD_OPTION_NO_ARG },
{ "-Map", LD_OPTION_TYPE_SHORT, LD_OPTION_MAP_FILE, LD_OPTION_HAS_ARG },
- { "-N", LD_OPTION_TYPE_SHORT, LD_OPTION_IGNORED, LD_OPTION_NO_ARG },
+ { "-N", LD_OPTION_TYPE_SHORT, LD_OPTION_IMPURE, LD_OPTION_NO_ARG },
{ "-e", LD_OPTION_TYPE_SHORT, LD_OPTION_ENTRY, LD_OPTION_HAS_ARG },
{ "-m", LD_OPTION_TYPE_SHORT, LD_OPTION_EMULATION, LD_OPTION_HAS_ARG },
{ "--help", LD_OPTION_TYPE_LONG, LD_OPTION_HELP, LD_OPTION_NO_ARG },
{ "--image-base", LD_OPTION_TYPE_LONG, LD_OPTION_IMAGE_BASE, LD_OPTION_HAS_ARG },
{ "--oformat", LD_OPTION_TYPE_LONG, LD_OPTION_FORMAT, LD_OPTION_HAS_ARG },
- { "--omagic", LD_OPTION_TYPE_LONG, LD_OPTION_IGNORED, LD_OPTION_NO_ARG },
+ { "--omagic", LD_OPTION_TYPE_LONG, LD_OPTION_IMPURE, LD_OPTION_NO_ARG },
{ "--output", LD_OPTION_TYPE_LONG, LD_OPTION_OUTFILE, LD_OPTION_HAS_ARG },
{ "--print-map", LD_OPTION_TYPE_LONG, LD_OPTION_MAP, LD_OPTION_NO_ARG },
{ "--strip-all", LD_OPTION_TYPE_LONG, LD_OPTION_IGNORED, LD_OPTION_NO_ARG },
fprintf (stderr, "\n");
fprintf (stderr, " -M, --print-map Print map file on standard output.\n");
- fprintf (stderr, " -N, --omagic Ignored.\n");
+ fprintf (stderr, " -N, --omagic Do not page align data in a.out and elks.\n");
fprintf (stderr, "\n");
fprintf (stderr, " -Map FILE Write a linker map to FILE.\n");
}
+ case LD_OPTION_IMPURE: {
+
+ state->impure = 1;
+ break;
+
+ }
+
case LD_OPTION_MAP: {
state->output_map_filename = "";
int i;
for (i = 0; i < size; i++) {
- value |= arr[i] << (CHAR_BIT * i);
+ value |= (unsigned long) arr[i] << (CHAR_BIT * i);
}
return value;
int i, j;
for (i = size, j = 0; i > 0; i--, j++) {
- value |= arr[j] << (CHAR_BIT * (i - 1));
+ value |= (unsigned long) arr[j] << (CHAR_BIT * (i - 1));
}
return value;
#ifndef _MZ_H
#define _MZ_H
-#define DEFAULT_SECTION_ALIGNMENT 0x1000
-#define DEFAULT_FILE_ALIGNMENT 0x0200
-
struct mz_exec {
unsigned char e_magic[2]; /* Magic number */
#ifndef _PE_H
#define _PE_H
-#define DEFAULT_SECTION_ALIGNMENT 0x1000
-#define DEFAULT_FILE_ALIGNMENT 0x0200
-
struct msdos_header {
unsigned char e_magic[2]; /* Magic number */