-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Driver] Normalize the baremetal handling of libc++ and runtimes #101259
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the generic version of this doesn't include
-lc++abi
, while this one does. Similarly for-lsupc++
. Is that an important difference? It seems like most of the derived toolchains include this in their overrides.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a static/dynamic linking thing. If libc++ is a shared library it would have a DT_NEEDED libc++abi (or the GCC equivalent).
For static links I think we'd need the explicit
-lc++abi
or the GNU equivalent.If I can find some time I'll see if we can try this patch out on our exceptions/rtti library variant as that would need objects from libc++abi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I can confirm that leaving out -lc++abi does cause build failures with our C++ samples with undefined symbols from libc++abi.
The lld command (paths shortened for brevity) coming out of
clang++ --target=armv6m-none-eabi -march=armv6m -mfpu=none -mfloat-abi=soft -lcrt0-semihost -lsemihost -g -T ../../ldscripts/microbit.ld -o hello-exn.elf hello-exn.cpp
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with the current implementation is that it assumes that libc++abi is used as the C++ ABI library, but libc++ supports a number of different C++ ABI library implementations, including
none
which may be desirable for some of the baremetal use cases. The fact that baremetal driver explicitly passes-lc++abi
is a problem for us because there is nolibc++abi.a
in our toolchain and that's intentional but it leads to a link error.There are two solutions for pulling in the right C++ ABI library without needing to explicitly pass
-lc++abi
to the linker that are already used by other platforms:libc++.so
andlibc++.a
with an input linker script that pulls in the right C++ ABI library; libc++ build can generate one forlibc++.so
, this could be extended to supportlibc++.a
if needed.libc++abi.a
intolibc++.a
so you don't need a separate-lc++abi
, this is already supported by libc++ build.The advantage of either of these solutions is that Clang driver can remain agnostic to which C++ ABI library the vendor built libc++ against.
@smithp35 Would it be feasible to migrate your toolchain to use either of these solutions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libc++abi is intended to be an implementation detail of libc++. I don't have authority over the Clang Driver, but it makes sense to me that the Driver would only link against libc++ and assume that this provides the necessary symbols. If that means libc++ needs to merge libc++abi into itself or something like that, that's IMO the right thing to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would definitely be feasible. I'm hoping that we can make a solution drop out of the existing runtimes build perhaps with an additional CMake flag. For example if we provide an extra option to the runtimes build then it either spits out a libc++ linker script fragment (my preference) or merge libc++ and libc++abi libraries (this should work as long as libc++abi's objects are inserted after libc++).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have this and it's used on platforms like Darwin, Fuchsia or Linux:
llvm-project/libcxx/CMakeLists.txt
Lines 269 to 271 in 3d08ade
We already have this and it's what we've been using in our baremetal build for example:
llvm-project/libcxx/CMakeLists.txt
Lines 247 to 253 in 3d08ade
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing those out, I was under the impression that they had to be developed first. Although I'm not the Driver owner either I can try those out and get back to you tomorrow (apologies its a bit late in the day) with a second approval.