Page MenuHomePhabricator

[clang] Fix clang multiarch isssue with musl
Needs RevisionPublic

Authored by listout on Aug 10 2022, 5:46 AM.

Details

Summary

From clang 13.0.0 has a new option -print-multiarch, matching gcc. On
linux-musl systems this outputs x86_64-linux-gnu (or aarch64-linux-gnu, etc)
instead of x86_64-linux-musl (or aarch64-linux-musl, etc).

Amongst other things, this bug breaks compiling python with clang on musl
hosts, as the python configure script does a sanity check and notices the
output of -print-multiarch is inconsistent with the linux-musl platform triplet
it (correctly) deduces for the host by other means. (The configure script
errors out with "internal configure error for the platform triplet, please file
a bug report" FWIW. This worked okay in clang 12.0.1 because python only checks
the multiarch target for consistency if $CC -print-multiarch isn't an error.)

The implementation in Linux::getMultiarchTriple() of
clang/lib/Driver/ToolChains/Linux.cpp special-cases -linux-android targets, and
assumes -linux-gnu for anything else.

Credit for this patch goes to arachsys <Chris Webb> and mgorny <Michał Górny>
Please also reffer:
https://bugs.llvm.org/show_bug.cgi?id=52127 and
llvm/llvm-project#51469

Diff Detail

Event Timeline

listout created this revision.Aug 10 2022, 5:46 AM
listout requested review of this revision.Aug 10 2022, 5:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 5:46 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

The patch needs some rework for 15.x and above version. If people think it's appropriate then I'll be glad to make the changes

listout retitled this revision from [clang] Fix clang multiarch isssue with musl to [WIP] [clang] Fix clang multiarch isssue with musl.Aug 10 2022, 6:44 AM
listout updated this revision to Diff 451452.Aug 10 2022, 7:34 AM

Less drastic changes and rebased with main

listout updated this revision to Diff 451459.Aug 10 2022, 7:50 AM

Fix missing '+'

listout updated this revision to Diff 451572.Aug 10 2022, 11:07 AM

The diff seems to be restricted to few lines. It should include the full context.

clang/lib/Driver/ToolChains/Linux.cpp
49
  • !isMusl() does not mean it is "gnu".
  • Why don't just use Triple::getEnvironmentTypeName?
listout updated this revision to Diff 451757.Aug 11 2022, 12:50 AM

Using getEnvironmentTypeName() instead of isMusl()

listout marked an inline comment as done.Aug 11 2022, 12:52 AM

@barannikov88 made some changes. What do you think?

clang/lib/Driver/ToolChains/Linux.cpp
49

Sure, I'll change the patch

listout updated this revision to Diff 456920.Aug 31 2022, 3:54 AM
listout marked an inline comment as done.
listout retitled this revision from [WIP] [clang] Fix clang multiarch isssue with musl to [clang] Fix clang multiarch isssue with musl.

Hey everyone, it would be very helpful if someone looked at this and help me merge this patch, python3.11 is failing without these modifications

listout edited the summary of this revision. (Show Details)Aug 31 2022, 3:57 AM
aaron.ballman added a subscriber: aaron.ballman.

Adding another reviewer to try to get this unstuck.

Can you add test coverage for the changes (to clang\test\Driver)? Also, there should be a release note so users know about the fix (that can go into clang\docs\ReleaseNotes.rst).

MaskRay requested changes to this revision.EditedAug 31 2022, 9:42 AM

This may not be the right direction. If GCC is not configured with --enable-multi-arch, --print-multiarch output is an empty line.
The x86_64-linux-gnu style output is for Debian and its derivatives which omit vendor in the target triple.
Clang just prints this unconditionally, but the string is not really expected for non-Debian distributions.

If a build system needs to detect this (it really shouldn't), it probably should hard code Debian hierarchy, instead of expecting Clang to do something.

AIUI many musl based Linux distributions don't configure GCC with --enable-multi-arch.

This revision now requires changes to proceed.Aug 31 2022, 9:42 AM

This can be abandoned as --print-multiarch was removed. See also https://github.com/llvm/llvm-project/issues/51469#issuecomment-1236163566