Support for Delphi 6

Issue #1 resolved
Mattes D created an issue

The Delphi 6 linker produces MAP files that cannot be read by map2pdb out of the box. It reports overlapping segments via an exception, with no details as to what the offending segments are.

Is there any chance of getting this ancient IDE supported by this tool? It would help me immensely.

I’m attaching a sample Hello World application source, executable and map file produced.

Comments (5)

  1. Anders@Melander

    Yes, it’s a bit inconvenient that the error message doesn’t state which the overlapping segments are (I’ll fix that) but in your case there’s no doubt - because they all overlap:

     Start         Length     Name                   Class
     0001:00000000 000013A0H .text                   CODE
     0002:00000000 0000009CH .data                   DATA
     0002:0000009C 000006E5H .bss                    BSS
    

    As you can see the .data and .bss segments both overlap the .text segment. On top of that you have two segments with the same index: 0002. This is also illegal.

    If I recalculate the segment offsets and make the indices unique:

     Start         Length     Name                   Class
     0001:00000000 000013A0H .text                   CODE
     0002:000013A0 0000009CH .data                   DATA
     0003:0000143C 00001B21H .bss                    BSS
    

    Then the segments pass but now the symbol parser bugs out because the format of the symbol names is different from that of newer Delphi versions (and there’s also a few bugs in my symbol name parser). I’ll get the bugs fixed and modify the symbol name parser so it can handle the Delphi 6 format, but I think you will have to handle the invalid segment indices and offset values yourself.

  2. Mattes D reporter

    Is there any definitive source on the format of the MAP files themselves, or is it just guesswork? Because I’d venture a guess that the files are valid, from Delphi’s point of view - the segments indices needn’t be identifiers, but rather pointers to the real EXE file’s sections (so the MAP file above would mean that the EXE file’s .text section contains segment 0001 and the segment 0002 spans the EXE file’s sections .data and .bss, from .data's start offset of 0.

  3. Anders Melander repo owner

    No there’s no formal definition of the map file format. It’s not a file format that is consumed by Delphi itself so it’s perfectly possible for Delphi to produce garbage map files and never notice it.

    While it might be possible to create a set of rules that will fit your map file, it will mean that large parts of the current design must be rewritten. I rely on segment indices being unique (it’s the key into the segment collection) and I rely on segment offsets and size being correct.

    If you look at the map files of newer Delphi versions then you will see that no segments overlap and all indices are unique. The same applies for pdb files produced by for example VS.

    Here’s the EXE sections of your application:

    As you can see the .text, .data and .bss are three separate sections and they should have been tree separate segments in the map file.

  4. Anders Melander repo owner

    Fixes #1 This change enables the map reader to parse Delphi 6 generated map files. Map reader: Fix for symbol name that does not start with module name causes error. Fix various related string indexing bugs.

    → <<cset e09a9f4419f4>>

  5. Log in to comment