Development tools

Porting binutils 2.16.1 to MiNT, v 0.8

This text tries to explain the steps to port binutils 2.16.1 from original sources to a working MiNT port. Current patches from does not work, so a bit of rework is needed. Thanks to Mark Duckworth for his help.

Step 1: Get the necessary archives

You need original binutils-2.16.1 archive. The archive decompress to a 95 MB of source directory. You will also need autoconf and automake to rebuild needed and configure scripts.
$ tar xvzf binutils-2.16.1.tar.gz

Step 2: First try

Note: TARGETPATH is a directory where binutils-mint will be installed.

$ mkdir binutils-2.16.1-mint
$ cd binutils-2.16.1-mint
$ ../binutils-2.16.1/configure --prefix=$TARGETPATH --target=m68k-atari-mint
$ make

First error:

*** BFD does not support target m68k-atari-mint.
*** Look in bfd/config.bfd for supported targets.

Step 3: Patch BFD library to accept m68k-atari-mint target

BFD means binary file descriptor, and this is a library of functions used by all binutils tools to read/process/write files in various format (a.out, elf, coff and many others).
In current patches, there are 2 things needed for the MiNT target: a custom object file format (aout-mint) and a custom executable format (prg-mint).
The object file format seems to be needed.
The custom executable format is the well-known GEMDOS executable format, with its TEXT, DATA, BSS and relocation sections.

Step 3.1: Makefile and configure stuff

Let's try to also add ELF object format. First, the configure/makefile stuff:

Don't forget to run automake; autoconf in bfd subdir. Now aout-mint.c and prg-mint.c are missing, to build the BFD library:

make[3]: *** No rule to make target `aout-mint.c', needed by `aout-mint.lo'.  Stop.

Step 3.2: bfd/aout-mint.c

The current aout-mint.c from binutils- Using it for compilation in binutils-2.16.1 seem to work. The question is: do we really need this object file format, could be use ELF object file format instead?

aout-mint.c (binutils- version).

Now it is prg-mint.c's turn.

make[3]: *** No rule to make target `prg-mint.c', needed by `prg-mint.lo'.  Stop.

Step 3.3: bfd/prg-mint.c

prg-mint backend support both GNU and DRI file formats. I wonder if there are still people building DRI objects with previous C compilers (Lattice, Pure). Here is binutils-'s version:

prg-mint.c (binutils- version).

It does not work, we have many errors:

Note: in m68kmint_prg_final_link_relocate(), a check is done against rawsize at beginning of the function and return bfd_reloc_outofrange if failing. In binutils 2.16.1 it seems that an offset (or object size) is passed instead of needed value, hence out of range. This check must be disabled.

Now we have something missing:

Step 3.4: bfd_m68kmint_set_extended_flags function

This one is defined in prg-mint.c. The declaration is missing from bfd/bfd-in.h. You need to run 'make headers' in bfd build subdir.

Step 3.5: aout.x file

This file needs to be modified, in its emit_stringtab() function:

/* The MiNT backend writes past the string table.  It therefore has to
   know about the table size.  */
obj_aout_external_string_size (abfd) = _bfd_stringtab_size (tab) +

Step 3.6: obj_aout_ext macro

This time, we need to modify the aoutdata structure in libaout.h file, by adding a new ext field:

  /* A pointer for data used by aout extensions.  (Currently only used
     by MiNT executables (see prg-mint.c).  */
  PTR ext;

obj_aout_ext() is a macro to access this new field.

#define obj_aout_ext(bfd)                  (adata (bfd).ext)

Good, now BFD library builds correctly.

prg-mint.c (binutils-2.16.1 updated version).

Next tool is GAS:

configure: error: GAS does not know what format to use for target m68k-atari-mint

Step 4: GAS tool

Just need to add a line for m68k-atari-mint in gas/configure.tgt, in the m68k section of 'case ${generic_target} in':

  m68k-*-mint*)				fmt=aout ;;

Step 5: LD tool

Same problem as GAS, first we need to add a line for m68k-atari-mint in ld/configure.tgt, in the m68k section of 'case "${targ}" in'. I also added support for ELF files.

  m68k-*-mint*)				targ_emul=m68kmint
                            targ_extra_emuls=m68kelf ;;

Note: We could also add m68kelf as targets that ld could understand.

Step 5.1: m68kmint ld target

We have defined a m68kmint target for ld, now we must write the needed stuff. ld needs some em68kmint.* file. First, there is necessary stuff.
We need to add em68kmint.o to ALL_EMULATIONS variable.

	em68kmint.o	\

Then adding the stuff needed to generate our target:

em68kmint.c: $(srcdir)/emulparams/ \
  $(srcdir)/emultempl/mint.em $(srcdir)/scripttempl/ ${GEN_DEPENDS}
	${GENSCRIPTS} m68kmint "$(tdir_m68kmint)"

Now we need to write emulparams/, emultempl/mint.em and scripttempl/

Step 5.2: emulparams/

0xe4 is the length of the header, before the TEXT section in executable. TARGET_PAGE_SIZE is 2, so I guess it allows aligning sections on this multiple. We also need to add a TEMPLATE_NAME value, otherwise it will default to generic template, which we do not want (see ld/ldint.texinfo for infos).


Step 5.2: emultempl/mint.em

The purpose of this file is to allow ld to set the program flags in the executable header at link stage. Some new fields appears in 2.16.1 version in ld_emulation_xfer_struct structure.

mint.em (binutils- version).

Like for prg-mint.c, many fields/defines have their name changed:

Step 5.3: scripttempl/

The purpose of this file is to describe in which order the various sections are written to the executable file. (binutils- version).

Step 6: Time to test and debug!

Apparently the build is ok, but we must be sure the code generated/linked by all these tools is right. That's the hard part. Most of these tools have testsuite, but maybe it requires writing MiNT tests as well.

Here is the final patch:

Personnal productions
Development tools
Create a patch for binutils (binutils 2.16.1)
Create a patch for gcc (gcc 3.3.6, C language only)
Create a patch for gcc (gcc 3.3.6, C++ language)
Misc stuff

HTML 4.0 valide ! La montée de Pikes Peak Non aux brevets logiciels Nectarine demoscene radio
Write me to pmandin(at)caramail(point)com
(Address modified for spam protection)