tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
179 stars 13 forks source link

Question: How to determine start offset of eg main function in segment #107

Open ecm-pushbx opened 2 years ago

ecm-pushbx commented 2 years ago

As shown in my feature request I would like to trace assembly listing files created by gcc-ia16 using my debugger and trace listing viewer. Unlike simple DOS executables written in NASM assembly, the object-local zero offset does not correspond to a well-known offset (0100h) in the final executable's CS. Unlike, also, more complex DOS executables, the offset is apparently not one of a limited set of other possibilities either (0000h, 7C00h). This is what the listing file shows:

   8                            .text
   9                            .global main
  11                    main:
  12 0000 55                    push    bp

This instruction ended up at offset 0241h in the final file. How can I determine this number automatically so I can feed it to traclist?

ecm-pushbx commented 2 years ago

It appears that the map file can be used to find the offset. The map file can be generated by passing -Xlinker -Map=output.map to gcc. Buried in there we get:

 .text          0x0000000000000241       0x14 /tmp/ccY2O2dO.o
                0x0000000000000241                main

I'm unsure how to distinguish the tmp object from all other parts that are listed in the map file, however.

tkchia commented 2 years ago

@ecm-pushbx : maybe try generate the .o files as intermediate outputs, rather than going straight from .c to .exe. Thank you!