MS linker has option /STUB for specifying custom stub binary which is included into final PE binary. GNU LD has hardcoded stub binary and does not allow user to specify custom stub binary like MS linker. Please add some new LD --stub option which changes the default GNU LD stub with one supplied by user.
Hi Pali, What does this stub look like ? Is it executable code ? Are there restrictions on how big it can be, the alignment it needs and so on ? Would it be possible to use objcopy to replace the stub generated by the linker with one supplied by the user ? Cheers Nick
Stub is executable code, I think it can be any valid binary in MZ format. Restrictions about alignement or size would come from the MZ format itself. About objcopy, I do not know about any way how to replace stub binary from existing PE binary. I think that replacement is harder operation because absolute offsets in PE structures needs to be adjusted when stub changes it size.
Hi Pali, I must admit that I am reluctant to pursue this feature. This stub is only used when running an executable in a DOS environment yes ? So its utility in modern Windows based systems seems to be quite small, and implementing it is likely to introduce new bugs into the linker. For the record the function where the hard-coded message is held is bfd/peicode.h:pe_mkobject(). The message is stored in a 64 byte array in the pe_data_type structure. Adding an option to store a custom sequence of 64 bytes into this structure would not be too hard, but I imagine that what you really want is to be able to store a stub of an arbitrary length. This would mean putting in a lot more changes, and would be much more likely to break things. This is why I am reluctant to have a go at this. Cheers Nick
Ok, I understand reasons. And I think that replacing 64-byte array by another with same size by some special linker flag has likely very small value, because this simple replacement can be done by e.g. dd tool.
Anyway, I see that for GO32 MZ binaries is bfd using GO32STUB env variable to specify other custom stub (bfd/coff-stgo32.c). So maybe this can be unified?