Linker Failure, Data Success

Over the last few weeks I’ve spent a lot of time trying to generate ELF files that would make the linux linker happy. Using the standard ELF tools like readelf and nm I got pretty far in generating structurally correct files, but ld just didn’t want anything to do with them, it said the files were in an unsupported format.

Finally I decided to build gold and trace through the code while it tries to link to see what makes it choke. This way I discovered the first problem: it had nothing to do with the file format, I had just accidentally used a 1-based index a place where I should have been using 0-based. It turns out that ld‘s error messages are not the model of accuracy. Hrmf.

The trouble didn’t end there, however, and I ended up building my own version of ld and tracing through that to figure out what the problem is. The code in ld does reveal some of the limitations inherit in C, as exemplified by the wonderful RELOC_FOR_GLOBAL_SYMBOL macro which is an absolute delight to debug.

Yesterday finally I gave up linux linking for now and spent some time working on static data in Mach-O files, which now works. The neutrino compiler can now embed data which is accessible to the generated program. This is an important step towards the generated runtime so I’m pretty excited about that. The next step is to be able to store complete object graphs, which will require some object pointer relocation fun in the generator. But I think we’re close to having all the fundamental building blocks in place for self hosting the language.

Leave a Reply

Your email address will not be published. Required fields are marked *


*