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

Implement unstable -Clink-self-contained values for MCP 510 #96884

Closed
wants to merge 6 commits into from

Conversation

lqd
Copy link
Member

@lqd lqd commented May 9, 2022

This PR is extracted from #96401 for easier review.

It implements half of MCP #510 as a prerequisite for supporting rust-lld via a command similar to -Clinker-flavor=gcc:lld -Clink-self-contained=linker: adding new unstable values to the -Clink-self-contained to independently control:

  • the CRT object linking, and
  • using the rustup-distributed linker

r? @petrochenkov

I know you plan on switching this to a +/- list: I didn't do this yet so this PR still represents the rough interface that was described in the zulip thread for opting in and out of both facets. And so still has temporary work, until we finalize the interface we want, and I'll make the changes you'd like to see in this PR.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 9, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 9, 2022
@bors
Copy link
Contributor

bors commented May 21, 2022

☔ The latest upstream changes (presumably #97239) made this pull request unmergeable. Please resolve the merge conflicts.

@lqd lqd force-pushed the mcp_link_self_contained branch from 34c1b91 to d477d45 Compare May 21, 2022 17:25
@petrochenkov
Copy link
Contributor

What we are currently shipping together with Rust toolchains.

windows-gnu:
	//MinGW libs
	"libgcc.a",
	"libgcc_eh.a",
	"libgcc_s.a",
	"libm.a",
	"libmingw32.a",
	"libmingwex.a",
	"libstdc++.a",
	"libiconv.a",
	"libmoldname.a",
	"libpthread.a",

	//Windows import libs
	"libadvapi32.a",
	"libbcrypt.a",
	"libcomctl32.a",
	"libcomdlg32.a",
	"libcredui.a",
	"libcrypt32.a",
	"libdbghelp.a",
	"libgdi32.a",
	"libimagehlp.a",
	"libiphlpapi.a",
	"libkernel32.a",
	"libmsimg32.a",
	"libmsvcrt.a",
	"libodbc32.a",
	"libole32.a",
	"liboleaut32.a",
	"libopengl32.a",
	"libpsapi.a",
	"librpcrt4.a",
	"libsecur32.a",
	"libsetupapi.a",
	"libshell32.a",
	"libsynchronization.a",
	"libuser32.a",
	"libuserenv.a",
	"libuuid.a",
	"libwinhttp.a",
	"libwinmm.a",
	"libwinspool.a",
	"libws2_32.a",
	"libwsock32.a",

	// Linker and dlltool
	"(i686,x86_64)-w64-mingw32-gcc.exe"
	"ld.exe"
	"dlltool.exe"
	"libwinpthread-1.dll" // needed by the exes

	// Crt objects
	"crt2.o", "dllcrt2.o"
musl:
	"libc.a"
	"crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o", "crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"
	"libunwind.a"
wasi:
	"libc.a"
	"crt1-command.o", "crt1-reactor.o"
fuchsia, fortanix, gnullvm (do not go through the self-contained dir but should):
	"libunwind.a"
other:
	sanitizer libs

@petrochenkov
Copy link
Contributor

These files can be pretty clearly separated into multiple components:

  • linker
  • crt objects
  • libc
  • libgcc/libunwind
  • sanitizers
  • rest of the mingw stuff

Notes:

  • dlltool goes together with linker, and will hopefully be reimplemented in Rust one day, using object-rs or whatever is necessary
  • libm, libpthread are a part of libc, they exist as separate libs only on some platforms, a couple more of mingw libs may also go there, need to investigate
  • I suspect that many of libs shipped with windows-gnu target are not even necessary for libstd, they were just used in the past to build rustc in self-contained mode

Relevant GCC/Clang options (for naming considerations):

  • crt objects: -nostartfiles
  • libc: -nolibc
  • libgcc/libunwind: -shared-libgcc, -static-libgcc, -unwindlib=<arg>

@petrochenkov
Copy link
Contributor

petrochenkov commented Jun 8, 2022

My suggested naming for the components: linker, crto, libc, unwind, sanitizers, mingw.

-Clink-self-contained=yes is -Clink-self-contained=+linker,+crto,+libc,+unwind,+sanitizers,+mingw.
-Clink-self-contained=no is -Clink-self-contained=-linker,-crto,-libc,-unwind,-sanitizers,-mingw.
-Clink-self-contained=+/-component only enables/disables that component, other components keep their default values (which may differ depending on targets).
+/-component does nothing if it's irrelevent to the given target.

Alternative: more coarse-grained components - +/-tools for linker and dlltool, and +/-libs for everything else.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 8, 2022
@petrochenkov
Copy link
Contributor

Multiple -Clink-self-contained options can be accumulated like -Ctarget-features.
E.g. -Clink-self-contained=yes -Clink-self-contained=-linker will mean -Clink-self-contained=-linker,+crto,+libc,+unwind,+sanitizers,+mingw.

This way we should be able to implement or stabilize all these components one by one, I think.

@mati865
Copy link
Contributor

mati865 commented Jun 11, 2022

dlltool goes together with linker

Seems reasonable given the fact the same Binutils bug that prevents us from using LLD also forces us to use dlltool.

will hopefully be reimplemented in Rust one day, using object-rs or whatever is necessary

I'd rather hope Binutils one day lands a fix for their bug with short import libs so windows-gnu can replace it (and the linker) with the same solution as windows-msvc and windows-gnullvm use.

@bors
Copy link
Contributor

bors commented Jul 14, 2022

☔ The latest upstream changes (presumably #98975) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@lqd any updates on this?

@Dylan-DPC
Copy link
Member

Closing this pr due to inactivity

@Dylan-DPC Dylan-DPC closed this May 13, 2023
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants