Bug 30147 - Allow to specify PE export name
Summary: Allow to specify PE export name
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-19 22:52 UTC by Pali Rohár
Modified: 2024-03-12 20:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pali Rohár 2023-02-19 22:52:36 UTC
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.
Comment 1 Nick Clifton 2023-02-20 12:51:56 UTC
(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
Comment 2 Pali Rohár 2023-02-20 18:15:09 UTC
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)?
Comment 3 Pali Rohár 2023-04-12 20:50:17 UTC
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.
Comment 4 Pali Rohár 2024-03-12 20:35:30 UTC
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?