Repository: rust
Issue: Windows DllMain name is exported
Labels: A-linkage,O-windows,T-compiler,O-windows-msvc,C-bug

On Windows, Rust exports the name of `DllMain` (`std`) / `_DllMainCRTStartup` (`no_std`), which is not standard behaviour and unwanted in most cases (that I am aware of). [As far as I understand](https://github.com/rust-lang/rust/issues/37530#issuecomment-259799687) this happens because they must be marked with either `#[no_mangle]` or `#[export_name = ".."]` so the `link.exe` can find the symbol. The `extern` keyword must also be used to mark them as `stdcall` for 32 bit targets.

Example project:

- Cargo.toml
  ```toml
  [lib]
  crate-type = ["cdylib"]
  ```

- lib.rs (`std`)
  ```rust
  #[no_mangle]
  extern "system" fn DllMain(_: *const u8, _: u32, _: *const u8) -> u32 { 1 }
  ```

- lib.rs (`no_std`)
  ```rust
  #![no_std]

  #[panic_handler]
  fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }

  #[no_mangle]
  extern "system" fn _DllMainCRTStartup(_: *const u8, _: u32, _: *const u8) -> u32 { 1 }
  ```

## dumpbin output

- Example Windows dll file:
  ```
  Dump of file C:\Windows\System32\httpprxp.dll

  File Type: DLL

    Section contains the following exports for httpprxp.dll

      00000000 characteristics
          0.00 version
             1 ordinal base
             8 number of functions
             8 number of names

      ordinal hint RVA      name

            1    0 00001870 ProxyHelperGetProxyEventInformation
            2    1 00001D00 ProxyHelperProviderConnectToServer
            3    2 00001DC0 ProxyHelperProviderDisconnectFromServer
            4    3 000010E0 ProxyHelperProviderFreeMemory
            5    4 00001220 ProxyHelperProviderRegisterForEventNotification
            6    5 00001AC0 ProxyHelperProviderSetProxyConfiguration
            7    6 00001BA0 ProxyHelperProviderSetProxyCredentials
            8    7 00001620 ProxyHelperProviderUnregisterEventNotification

    Summary

          1000 .data
          1000 .didat
          1000 .pdata
          2000 .rdata
          1000 .reloc
          1000 .rsrc
          2000 .text
  ```

- Rust example from above (`std`):
  ```
  Dump of file std.dll

  File Type: DLL

    Section contains the following exports for std.dll

      00000000 characteristics
          0.00 version
             1 ordinal base
             2 number of functions
             2 number of names

      ordinal hint RVA      name

            1    0 00001000 DllMain = DllMain
            2    1 00001010 rust_eh_personality = rust_eh_personality

    Summary

          1000 .data
          1000 .pdata
          1000 .rdata
          1000 .reloc
          1000 .text
  ```

- Rust example from above (`no_std`):
  ```
  Dump of file no_std.dll

  File Type: DLL

    Section contains the following exports for no_std.dll

      00000000 characteristics
          0.00 version
             1 ordinal base
             1 number of functions
             1 number of names

      ordinal hint RVA      name

            1    0 00001000 _DllMainCRTStartup = _DllMainCRTStartup

    Summary

          1000 .rdata
          1000 .text
  ```

## Expected output

`DllMain` and `_DllMainCRTStartup` should not be exported by name, just as in the first dumpbin output example of a Windows system dll.

## Tested compiler version

```
rustc 1.41.0-nightly (c8ea4ace9 2019-12-14)
binary: rustc
commit-hash: c8ea4ace9213ae045123fdfeb59d1ac887656d31
commit-date: 2019-12-14
host: x86_64-pc-windows-msvc
release: 1.41.0-nightly
LLVM version: 9.0
```