Skip to content

Don't export API symbols on static build #7112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HenriquedoVal
Copy link

When linking to a static library that contains symbols with __declspec(dllexport), all these symbols will be part of the final executable, even if they are not needed. Maybe this is not the intended behavior. Although both ELF and PE (at least) can do this, most people don't load symbols of an executable, AFAIK.

Before:

Get-Item .\util_tests.exe | % { "Size of $($_.Name): $($_.Length / 1kb)kb" }
Size of util_tests.exe: 2594kb

❯ dumpbin -nologo -exports .\util_tests.exe

Dump of file .\util_tests.exe

File Type: EXECUTABLE IMAGE

  Section contains the following exports for util_tests.exe

    00000000 characteristics
    FFFFFFFF time date stamp
        0.00 version
           1 ordinal base
         956 number of functions
         956 number of names

    ordinal hint RVA      name

          1    0 0001E0F0 git_annotated_commit_free
          2    1 0001DF70 git_annotated_commit_from_fetchhead
          3    2 0001DC80 git_annotated_commit_from_ref
          .
          .
          956  3BB 000036F0 giterr_set_str

  Summary

        D000 .data
       15000 .pdata
       94000 .rdata
        2000 .reloc
        1000 .rsrc
      1D8000 .text
        1000 _RDATA

After:

Get-Item .\util_tests.exe | % { "Size of $($_.Name): $($_.Length / 1kb)kb" }
Size of util_tests.exe: 1705.5kb

❯ dumpbin -nologo -exports .\util_tests.exe

Dump of file .\util_tests.exe

File Type: EXECUTABLE IMAGE

  Summary

        D000 .data
        C000 .pdata
       77000 .rdata
        2000 .reloc
        1000 .rsrc
      122000 .text
        1000 _RDATA

I'm not sure if this is the right way to do it, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant