Skip to content
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

allocation functions exported when they shouldn't be #34493

Closed
retep998 opened this issue Jun 27, 2016 · 6 comments
Closed

allocation functions exported when they shouldn't be #34493

retep998 opened this issue Jun 27, 2016 · 6 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@retep998
Copy link
Member

retep998 commented Jun 27, 2016


Only the first two functions in that list should be there, the rest don't belong there.
Using x86_64-pc-windows-msvc.

cc @alexcrichton

@retep998 retep998 changed the title cdylib on windows msvc exports stuff from alloc and unwind crates cdylib on windows msvc exports stuff from alloc and panic crates Jun 27, 2016
@alexcrichton
Copy link
Member

All the symbols starting with __ are exported because they are #[no_mangle] pub extern and the rust_begin_unwind symbol is exported because it's a "weak lang item". The compiler automatically exports all #[no_mangle] pub extern functions, regardless of whether they're lang items or not (as they typically have ABI implications). This is not an MSVC-specific issue, it plagues all platforms.

The solution here would likely be to not tag these functions with #[no_mangle] pub extern but instead have them specially recognized to the compiler as not part of the public ABI but just an implementation detail of various compiler structures (e.g. allocators and panic runtimes).

@steveklabnik steveklabnik added A-linkage Area: linking into static, shared libraries and binaries O-windows-msvc Toolchain: MSVC, Operating system: Windows labels Jun 27, 2016
@nagisa
Copy link
Member

nagisa commented Jul 3, 2016

Right, so I hit this issue the hard way:

note: liballoc_system-8102e29f.rlib(alloc_system-8102e29f.0.o) : error LNK2005: __rust_deallocate already defined in other_rustc_built.dll.lib(other_rustc_built.dll)

On the MSVC .dll the symbol is plain exported: you can link to it, load via GetProcAddress, it has entry address etc.

On unix-like platforms, on the other hand, the symbol in question is undefined (i.e. imported):

0000000000000000       F *UND*  0000000000000000              __rust_deallocate

as it should be.

@alexcrichton alexcrichton removed the O-windows-msvc Toolchain: MSVC, Operating system: Windows label Jul 4, 2016
@alexcrichton alexcrichton changed the title cdylib on windows msvc exports stuff from alloc and panic crates allocation functions exported when they shouldn't be Jul 23, 2016
@alexcrichton
Copy link
Member

I've updated the title of this bug to indicate that it's not just Windows nor is it just cdylib.

The solution I mentioned before may not be too hard to implement. I believe that the logic which decides to export these functions (for LTO at least) is here, and we probably can just add a whitelist of symbols that shouldn't be exported because they're just internal implementation details when compiling with LTO.

cc @froydnj
cc https://bugzilla.mozilla.org/show_bug.cgi?id=1288173

@alexcrichton
Copy link
Member

Also note that this "whitelist" should also consider symbols like:

  • rust_eh_personality
  • rust_eh_personality_catch
  • rust_begin_unwind

It's basically the same thing there where once we have LTO none of them need to actually get exported all the way, just linked up.

@alexcrichton alexcrichton added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Jul 23, 2016
@c3st7n
Copy link
Contributor

c3st7n commented Jul 25, 2016

I'd be interested in looking at this if I could get a mentor.

@alexcrichton
Copy link
Member

@c3st7n sure! If you need any help or pointers to get start just let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

5 participants