-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Link using the linker directly #11937
Comments
I really like this idea, this has bit us in the past by unknowningly bringing in dependencies we weren't expecting. However, I don't think that this will be an easy thing to do. I found out that compilers add a lot of command line parameters to the system linker. This will be a difficult thing to do on all systems, but it may be doable. I'm pasting below a survey of what I've got a VM for. I got all of these via OSX/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o a.out /var/folders/9s/r4snvt950_d9_rcl6w50tvw80000gn/T/a-QOBPrL.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a Looks like everything here is guessable except for Arch linux"/usr/bin/ld.gold" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64/crt1.o /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64/crti.o /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/crtbegin.o -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2 -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../.. -L/lib -L/usr/lib /tmp/foo-93f224.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/crtend.o /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../lib64/crtn.o There's a lot of things going on here. We would need to find Ubuntu/usr/bin/ld -z relro --hash-style=gnu --as-needed --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -L/lib/x86_64-linux-gnu -L/lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib /tmp/foo-fw3tGx.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o This looks fairly similar to arch. There's some weird flags I haven't seen much before, but they're in theory fairly guessable. FreeBSD/usr/bin/ld --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/foo-zCRcGs.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o Nice an simple! Like ubuntu/arch, we'd have to find things like Windows (MinGW)I'm not sure how to copy/paste out of a windows terminal, but the command line used Windows also had the usual |
@alexcrichton: Arch Linux also passes (I think |
I hope if we can figure out how to invoke the linker correctly enough to get through the bots, that will be a great start, and patches for fixing other systems would arrive quickly. We can also leave in a fallback mode for awhile that just uses C for linking. |
We can also do it incrementally, using C for platforms that haven't been converted. |
One thing I recently realized, we can make some temporary progress by passing |
This will hopefully bring us closer to rust-lang#11937. We're still using gcc's idea of "startup files", but this should prevent us from leaking in dependencies that we don't quite want (libgcc for example once compiler-rt is what we use).
This will hopefully bring us closer to rust-lang#11937. We're still using gcc's idea of "startup files", but this should prevent us from leaking in dependencies that we don't quite want (libgcc for example once compiler-rt is what we use).
This will hopefully bring us closer to #11937. We're still using gcc's idea of "startup files", but this should prevent us from leaking in dependencies that we don't quite want (libgcc for example once compiler-rt is what we use).
An excellent example of the trickery that we'd need to perform is what It looks like there's a whole bunch of logic going on in there to find all these extra files. Including libclang would help, but it would indeed be a pretty big dependency to say that rustc is itself built on top of clang. |
@brson, @alexcrichton: do you think it is OK to target a specific linker (ld probably), or do we want linker driver to be completely scriptable, similar to gcc tool specs? |
I would expect to target the system |
Triage: we allow you to choose a linker, but still have a |
Triage: no change. However, see also: #36120 |
The clang code for doing this has moved slightly: https://github.com/llvm-mirror/clang/blob/release_50/lib/Driver/ToolChains/Darwin.cpp?utf8=%E2%9C%93#L1910 |
...outside of target specifications - that'll come next. Updates rust-lang#11937.
Some logic to deal with macOS < 10.8 cribbed from: https://github.com/llvm-mirror/clang/blob/64309d1/lib/Driver/ToolChains/Darwin.cpp#L1910 Updates rust-lang#11937.
...outside of target specifications - that'll come next. Updates rust-lang#11937.
Some logic to deal with macOS < 10.8 cribbed from: https://github.com/llvm-mirror/clang/blob/64309d1/lib/Driver/ToolChains/Darwin.cpp#L1910 Updates rust-lang#11937.
If someone still wants to pursue this (in which I'm not actually sure), then it can be done step-by-step. The next logical step is move from The CRT objects used by different toolchains are documented in #71769. |
Some negative experience with linking CRT objects manually instead of relying on gcc on musl targets: So, musl experience repeats the mingw one - using system CRT objects and libraries is strongly preferable to using those shipped with rustc. |
Right now we link through a C compiler, but Rust should not depend on having a C compiler available nor expose details of cc linking semantics.
I know there have been other issues on this but I can't find them.
The text was updated successfully, but these errors were encountered: