This is an archive of the discontinued LLVM Phabricator instance.

cmake: Add CLANG_GOLD_LIBDIR_SUFFIX to specify loc of LLVMgold.so
AbandonedPublic

Authored by mgorny on Aug 21 2016, 12:46 AM.

Details

Summary

Add CLANG_GOLD_LIBDIR_SUFFIX that defaults to ${LLVM_LIBDIR_SUFFIX}
and can be overriden if LLVMgold.so is installed elsewhere. The use case
are multilib systems where binutils is 64-bit and clang is 32-bit,
therefore the gold plugin is installed in 64-bit libdir while clang
is not.

Bug: https://llvm.org/bugs/show_bug.cgi?id=23793
Depends on: https://reviews.llvm.org/D23752

Diff Detail

Event Timeline

mgorny updated this revision to Diff 68802.Aug 21 2016, 12:46 AM
mgorny retitled this revision from to cmake: Add CLANG_GOLD_LIBDIR_SUFFIX to specify loc of LLVMgold.so.
mgorny updated this object.
mgorny added a reviewer: rafael.
mgorny added a subscriber: cfe-commits.

@rafael, ping. Could you review this, please? This is the solution you suggested on the bug.

mgorny added a subscriber: beanz.

@beanz, could you also look at this one? I'd like to replace CLANG_LIBDIR_SUFFIX with the runtimes suffix, and for this I'd have to get rid of this CLANG_LIBDIR_SUFFIX occurrence as well. However, I don't think LLVMgold.so really counts as a 'runtime', so I guess a default of LLVM_LIBDIR_SUFFIX with possible explicit override would work here.

beanz edited edge metadata.Oct 26 2016, 2:00 PM

@mgorny, I don't think LLVMgold qualifies as a runtime in the traditional sense. It more closely aligns with the tools vended by LLVM even though it is a shared library not an executable.

Runtime libraries are specifically libraries that products of clang are linked against (builtins, sanitizers, libcxx, libunwind...).

That bit of semantics aside, I don't think there is any situation where LLVMgold's libdir suffix would be different from LLVM's libdir suffix. Since LLVMgold is built and installed as part of LLVM, there is no mechanism (nor do I think there should be) to cause such a differentiation.

@rafael may disagree, and I will defer to his judgment if he does. My take is that we should just use LLVM_LIBDIR_SUFFIX for LLVMgold, and not have a separate variable.

@mgorny, I don't think LLVMgold qualifies as a runtime in the traditional sense. It more closely aligns with the tools vended by LLVM even though it is a shared library not an executable.

Runtime libraries are specifically libraries that products of clang are linked against (builtins, sanitizers, libcxx, libunwind...).

That bit of semantics aside, I don't think there is any situation where LLVMgold's libdir suffix would be different from LLVM's libdir suffix. Since LLVMgold is built and installed as part of LLVM, there is no mechanism (nor do I think there should be) to cause such a differentiation.

@rafael may disagree, and I will defer to his judgment if he does. My take is that we should just use LLVM_LIBDIR_SUFFIX for LLVMgold, and not have a separate variable.

The difference is that LLVMgold.so is not used by LLVM or clang directly but by the system binutils, and so it must match the ABI of the linker. If you have 32-bit libclang*, LLVM_LIBDIR_SUFFIX is 32 but ld is still a 64-bit executable that needs 64-bit LLVMgold.so.

chandlerc edited edge metadata.Oct 26 2016, 4:10 PM

@mgorny, I don't think LLVMgold qualifies as a runtime in the traditional sense. It more closely aligns with the tools vended by LLVM even though it is a shared library not an executable.

Runtime libraries are specifically libraries that products of clang are linked against (builtins, sanitizers, libcxx, libunwind...).

That bit of semantics aside, I don't think there is any situation where LLVMgold's libdir suffix would be different from LLVM's libdir suffix. Since LLVMgold is built and installed as part of LLVM, there is no mechanism (nor do I think there should be) to cause such a differentiation.

@rafael may disagree, and I will defer to his judgment if he does. My take is that we should just use LLVM_LIBDIR_SUFFIX for LLVMgold, and not have a separate variable.

The difference is that LLVMgold.so is not used by LLVM or clang directly but by the system binutils, and so it must match the ABI of the linker. If you have 32-bit libclang*, LLVM_LIBDIR_SUFFIX is 32 but ld is still a 64-bit executable that needs 64-bit LLVMgold.so.

But how does that work? The LLVM libraries linked into LLVMgold.so can't be 32-bit if it is loaded into a 64-bit binutils.

The difference is that LLVMgold.so is not used by LLVM or clang directly but by the system binutils, and so it must match the ABI of the linker. If you have 32-bit libclang*, LLVM_LIBDIR_SUFFIX is 32 but ld is still a 64-bit executable that needs 64-bit LLVMgold.so.

But how does that work? The LLVM libraries linked into LLVMgold.so can't be 32-bit if it is loaded into a 64-bit binutils.

Just to be clear, the suffix I'm talking about is used only in Driver to specify location of LLVMgold.so. The file is a part of a separate 64-bit install of LLVM (+ clang) which obviously has all the necessary 64-bit libraries.

The difference is that LLVMgold.so is not used by LLVM or clang directly but by the system binutils, and so it must match the ABI of the linker. If you have 32-bit libclang*, LLVM_LIBDIR_SUFFIX is 32 but ld is still a 64-bit executable that needs 64-bit LLVMgold.so.

But how does that work? The LLVM libraries linked into LLVMgold.so can't be 32-bit if it is loaded into a 64-bit binutils.

Just to be clear, the suffix I'm talking about is used only in Driver to specify location of LLVMgold.so. The file is a part of a separate 64-bit install of LLVM (+ clang) which obviously has all the necessary 64-bit libraries.

I'm not sure it really makes sense for the Clang driver to go hunting for an LLVMgold.so from an unrelated build of Clang and LLVM.

The Clang driver is going to run a particular CC1 invocation, ask it to produce bitcode, and then hand that to a linker invocation and give it a plugin to read that bitcode. I think it is reasonable for the only plugin it looks for to be the one installed alongside its lib/clang/... and not one from some other installation in some other directory. How would it even know that this other LLVMgold.so can read the bitcode that CC1 is producing? What if they're different versions? Or support different targets?

I'm not sure it really makes sense for the Clang driver to go hunting for an LLVMgold.so from an unrelated build of Clang and LLVM.

The Clang driver is going to run a particular CC1 invocation, ask it to produce bitcode, and then hand that to a linker invocation and give it a plugin to read that bitcode. I think it is reasonable for the only plugin it looks for to be the one installed alongside its lib/clang/... and not one from some other installation in some other directory. How would it even know that this other LLVMgold.so can read the bitcode that CC1 is producing? What if they're different versions? Or support different targets?

Well, this is the builder/distributor's responsibility. If they override this specific suffix, they need to ensure that the value is correct.

That said, I don't mind using the generic runtimes directory approach, that is having LLVMgold.so relative to lib/clang. However, in this case it would probably be reasonable to adjust the install path in LLVM as well (the move of runtimes path to LLVM was requested separately).

Another option is to just pass --plugin=LLVMgold.so and rely on the linker search instead of providing a full path. However, I guess that might break some uncommon installations.

I'm not sure it really makes sense for the Clang driver to go hunting for an LLVMgold.so from an unrelated build of Clang and LLVM.

The Clang driver is going to run a particular CC1 invocation, ask it to produce bitcode, and then hand that to a linker invocation and give it a plugin to read that bitcode. I think it is reasonable for the only plugin it looks for to be the one installed alongside its lib/clang/... and not one from some other installation in some other directory. How would it even know that this other LLVMgold.so can read the bitcode that CC1 is producing? What if they're different versions? Or support different targets?

Well, this is the builder/distributor's responsibility. If they override this specific suffix, they need to ensure that the value is correct.

That said, I don't mind using the generic runtimes directory approach, that is having LLVMgold.so relative to lib/clang. However, in this case it would probably be reasonable to adjust the install path in LLVM as well (the move of runtimes path to LLVM was requested separately).

I think all of these options are just way too much magic to support a very strange use case (IMO). Mixing and matching a 32-bit Clang build with a 64-bit LLVMgold build and expecting magic flags like '-flto' to Just Work seems like too much.

It isn't like this prevents users from directly specifying things. The syntax isn't even that crazy. And that way they'll know what they're getting.

Another option is to just pass --plugin=LLVMgold.so and rely on the linker search instead of providing a full path. However, I guess that might break some uncommon installations.

Sure. Or we could tell users to directly do this and keep the '-flto' behavior maximally simple and predictable.

mgorny abandoned this revision.Oct 27 2016, 1:05 AM

Works for me. I don't know if this even has a valid failure case, just felt uneasy about having the obviously-wrong path in code.