When generating ELF binary it is possible to specify its export name by -soname= option, and this option is working fine ELF. But seems there is no way to specify export name when generating PE binary. LD accepts -soname= option also for PE binaries but seems that it is just ignored without any warning/error message. And PE export name in export table (.edata) is taken from the -o output option.
(In reply to Pali Rohár from comment #0) Hi Pali, > But seems there is no way to specify export name when generating PE binary. > LD accepts -soname= option also for PE binaries but seems that it is just > ignored without any warning/error message. True - the documentation does mention that this is an ELF only option, but the linker probably could generate a warning message if it is used when generating output in a different format. > And PE export name in export > table (.edata) is taken from the -o output option. For this, I think that you need to use a .def file. If one is provided then the export name is taken from the NAME field in that file. Cheers Nick
It is quite annoying if for different platforms it is needed to use different command line options or different config files to specify some option, like setting export name. It makes build systems, scripts, etc... which compiles multiplatform applications / libraries via gcc/ld more complicated. Would not it be better to have one common option which sets export name for both ELF and PE targets (and possible other supported by binutils)?
I have tested that it is really possible to set export name via DEF file when generating PE binary. Export name can be specified via LIBRARY or via NAME keyword. At least I would suggest to extend -soname= documentation and mention there this information how to set PE export name.
Also I must admit that it is annoying if some flags has to be passed to LD as command line arguments and some other flags via (new temporary) file which is specified as command line argument. It is highly unexpected usage/behavior. I see that -soname for ELF targets has quite different meaning than PE export name, even that it is used for similar purposes. Nick, what about these changes? * Throws warning or maybe better error when -soname= is specified for non-ELF target (targets which do not support soname). * Document that -soname= is ELF specific. Document how to set PE export name, what is default value and how ELF soname and PE export name differs. * Add a new command line option for setting PE export name (+ document it) for both DLL libraries and EXE executables. I do not know what can be the best name but reusing -soname is not a good idea (as it does quite different thing). Maybe -pe-export-name? Or -exportname?