r/cpp • u/unddoch DragonflyDB/Clang • Sep 06 '22
Clang 15 has been released!
https://discourse.llvm.org/t/llvm-15-0-0-release/6509962
u/qoning Sep 06 '22
Claims to implement the bulk of modules proposal. Any word on what the state actually is from someone who used it in alpha? Support on clang has been my major blocker to switching most new code to modules.
12
u/bretbrownjr Sep 06 '22
You can look at the bug tracker. Honestly, someone going through and distilling a list of deal breaker bugs should be a big help.
Other than that, the big showstopper, IMO, is the lack of support for modular dependency discovery. Basically, we need the module version of the -M flags. Without that, you'll need a very specific build setup to build modular C++ in Clang. Bill Hoffman's talk about CMake and modules at CppCon next week should touch on this.
Tracking issue: https://github.com/llvm/llvm-project/issues/56917
3
u/encyclopedist Sep 07 '22 edited Sep 07 '22
Is there a plan to implement P1689R5 "Format for describing dependencies of source files" in Clang?
/u/mathstuf (one of the authors of the proposal and Cmake maintainer) has been working on implementing this in Cmake and GCC. See also https://www.reddit.com/r/cpp/comments/pb6i6r/comment/haae24r/
Edit Bill Hoffman appears to work at Kitware too, so obviously he should be familiar with P1689 and mathstuf's work. Looking forward for his talk.
Edit 2 Bill Hoffman not just works at Kitware, he is CTO of Kitware and original author of CMake
Edit 3 The talk linked in a sibling comment provides a good overview of the stuff mentioned in my comment.
3
u/bretbrownjr Sep 07 '22
There has been a little preliminary discussion on implementing the paper. If anyone is interested in, qualified for, and/or willing to fund this work, reach out.
I expect updating the above issue with a detailed design of how to enhance clang and/or clang-scan-deps to implement the paper would be a good next step.
2
u/mathstuf cmake dev Dec 21 '22
Clang patches are under review. See the commit stack here: https://reviews.llvm.org/D139168
I have a branch on my fork with the patches all applied: https://github.com/mathstuf/llvm-project/tree/p1689r5-csd
1
0
44
u/eco_was_taken Sep 06 '22
Great. Now I just have to wait forever for AppleClang to catch up.
7
Sep 06 '22
You can use the regular clang on macos
15
u/eco_was_taken Sep 06 '22
Yeah but using the non-standard configuration usually comes with its own set of problems in my experience.
3
Sep 06 '22
Non-standard? Could you please elaborate?
25
u/eco_was_taken Sep 06 '22
As in, not the usual configuration that is typically expected on the platform. Like running MinGW on Windows instead of MSVC.
Using a less common configuration works but I find the more I do things like that the more obscure my bugs get and it becomes harder to figure out what is going on if nobody else is having the same problem I'm having. I find it's usually not worth the trouble if the alternative is just patience.
7
Sep 06 '22
Well, the alternative is to use the superior OS. Come to the dark side, we have cookies ;)
25
u/eco_was_taken Sep 06 '22
Unfortunately your side (assuming Linux) lacks my customer base (Windows 90%, macOS 10%).
-1
u/Meowx64 Sep 07 '22 edited Sep 07 '22
Edit: For those who are not aware about how to check kernel in Android, it will be somewhere near settings -> about phone .
Meanwhile 50%+ of users chilling on android with >linux4.x + kernel ;).
|As of April 2022, Android, an operating system using the Linux kernel, is the world's most-used operating system when judged by web use. It has 43% of the global market, followed by Windows with 30%, Apple iOS with 17%, macOS with 6%, then (desktop) Linux at 0.98% also using the Linux kernel.[1] These numbers do not include embedded devices or game consoles.
https://en.wikipedia.org/wiki/Usage_share_of_operating_systems
7
u/eco_was_taken Sep 07 '22
I write fairly niche construction industry software. I can assure you 0% of our current or potential customer base uses a Linux desktop. I'd like if they did but they don't.
0
u/Meowx64 Sep 07 '22
Construction Industry Software? Aren't they usually web based? (Sorry, hearing the term for first time and what suddenly comes to my mind is hiring contractors which is usually done through web browsers or dedicated apps in android phones)
→ More replies (0)4
u/pjmlp Sep 07 '22
Anyone that has done Android development knows quite well that Linux kernel is an implementation detail not exposed to the public APIs in userspace, a newer version of Android could be using Zephyr, *BSD or Fuschia and only those using rooted devices or OEMs would notice the difference.
By the way, using clang/NDK is even worse experience than any Apple platform.
0
u/Meowx64 Sep 07 '22 edited Sep 07 '22
Eventhough I never stated the dev experience on various env's, I have to interject there since even though I am noob in Android programming I am familiar with NDK used in android(Used for interacting with Termux in the past)
I. General
Never heard any emulator dev(Since mostly, they are interested in cross platform apps) stating "Porting my X emulator to iOS is easier than Android, provided most are written in C++". (Unless you are calling a Java library)
In game space, most developers use a engineers use a custom engine which has a higher probability of having ports for android than iOS or even MacOS
Regarding Linux is swapped with X or Y. According to the statistics, most Android users are not on latest Android Version. So, there will be large Android/Linux users in wild for a long time while X or Y emerges mainstream.
II. Software Dev Experience
I will gladly write my application in Vulkan and OpenGL and restrict support for MacOS than learning(or buying a mac device for the sake of porting it to it) how MoltenVk works(Yes, MoltenVk requires additional steps to make it run on MacOS and is limited) or Metal(Which has it's own issues). Now I can even switch my Vulkan drivers. (Supported in qualcomm devices)
I can find libraries(C/C++) that works well on Linux or Windows than that works on MacOS
III. General Linux Merits(I personally gained, since you mentioned NDK for some reason)
No more dllopen() shenanigans (Windows)
A good package manager (Windows)
There is no "recommended" languages. (MacOS)
Can try experimental features.
Better drivers for AMD(Mesa).
More
TBN, I never owned a mac device. So, some of them are known issues like Graphic API's among devs. Also, I didn't add anything more since I assume MacOS provides benefits of Unix. (Even though the Userland is proprietary)
6
5
2
u/T8N4QImy5Lx5 Sep 07 '22
When is xcode 14 getting released? Waiting on this to bundle the appleclang update
1
u/T8N4QImy5Lx5 Sep 08 '22
Wow Xcode 14 RC came out soon after asking: https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes
77
u/SuperV1234 https://romeo.training | C++ Mentoring & Consulting Sep 06 '22
Improved
-O0code generation for calls tostd::move,std::forward,std::move_if_noexcept,std::addressof, andstd::as_const. These are now treated as compiler builtins and implemented directly, rather than instantiating the definition from the standard library.
Rejoice! Thank you so much for this.
It also applies to optimizations levels higher than -O0, right? Might want to change the wording in the release notes to avoid confusion.
27
Sep 06 '22
-O
nincludes all optimizations from -On-1so there is no need to state this explicitly.8
u/concealed_cat Sep 07 '22
O0 is different than other O's. I'm not sure what this specifically refers to, but based on the wording alone, I'm guessing it's an improvement in the non-optimizing pipeline.
1
u/m_riss1 Sep 06 '22
Isn’t -O0 the same as having -g, or just leaving the field blank? (or for those not familiar with C/C++ compilers: having no optimizations turned on)
14
u/Nobody_1707 Sep 07 '22
-O0is the default on clang and does no optimizations, but it's not the same as-gwhich enables debug information and can be used with any -O flag.10
12
u/puremourning Sep 06 '22 edited Sep 07 '22
I believe clang 15 defaults to PIE on Linux. Woe betide anyone who links against a .o heinously built without -fPIC.
2 days of headscratching that cost me!
FYI there’s a cmake macro to revert this when building clang. https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#build-system-changes
But apparently, they may remove the option, so pray you don’t have third party libraries you can’t rebuild!
2
u/iwubcode Sep 07 '22
FYI there’s a cmake macro to revert this when building clang.
Do you remember what you used when building clang with cmake to revert this behavior to clang 14's default?
1
u/puremourning Sep 07 '22
Not precisely, but It’s in the clang 15 release notes under Build system changes.
https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#build-system-changes
2
u/ChrisTX4 Sep 07 '22
Clang merely copies the default on most Linux distros and Android. Furthermore, they might merely remove the option to change the default, not the compiler options to build with PIC/PIE or not, so you can always build a non-PIE binary if you really have to.
Any decent build system will also be able to do this for you: CMake for example can use
POSITION_INDEPENDENT_CODEto control PIC/PIE regardless of defaults.However, unless that’s the case, there’s no reason not to use PIE. On 32-bit x86, this was somewhat different as it lacked “RIP” addressing, but on x86-64 and other platforms, the overhead is absolutely minimal.
3
u/puremourning Sep 07 '22
The reason is that the .a/.o files are provided by a third-party and we can't recompile them (for example).
Yes, you can change your build system. Yes you can recompile clang. Yes, yes, yes. And I suppose it's reasonable for a major compiler version to have to do these sorts of things.
But I thought the change of the default, in a way which breaks existing builds in obscure ways, is something the community might want to be aware of, given how long it took me to work it out.
The meta discussion as to why this change was made amounts to, yes, as you say many distro's (not all!) build their system compiler this way. Oh and there's a PR to add this same default to gcc. But that PR was summarily rejected with the following, somewhat amusing, comment:
No. The reason it's an option is it's optional.
But like I said, the argument for-or-against PIE is somewhat tangential; my point was that the change to PIE-by-default might break your build if you just upgrade to clang 15 and don't know about this. Hopefully saved someone some time.
0
Sep 06 '22
Isn't position-independent code slower? Why would it default to that?
13
u/encyclopedist Sep 06 '22
As a security hardening measure, for example.
-11
Sep 06 '22
Interesting. But that's not something we do in C++.
20
u/encyclopedist Sep 06 '22
It allows the operating system to randomize position of your code at loading time. This is something the operating system does, not your code itself.
-13
Sep 06 '22
Yes, I understand. But that's not the kind of trade we do by default in C++. As an example, we don't do bounds checking by default, even though buffer overflow is a common security vulnerability.
0
Sep 06 '22
[deleted]
7
Sep 07 '22
I don't understand why my previous comment is heavily downvoted. A simple "The overhead is much lower than bounds checking, so it's worth it" would be a constructive response.
4
u/pjmlp Sep 07 '22
Those of us that care about security and have to use C++ for whatever reason, do use them.
9
u/patstew Sep 06 '22
PIC is needed for shared libraries. Perhaps it's so that objects by default are suitable for linking into shared libraries or executables.
1
u/Jannik2099 Sep 07 '22
No, this was done for security purposes. All distros already set their gcc to default-pie
2
u/puremourning Sep 07 '22
The runtime impact may be marginal, but the pages and pages of obscure build time linker errors are pretty terminal. And confusing.
2
u/Jannik2099 Sep 07 '22
Eh?
All stuff you link against should be PIC anyways. This was a major defect in clang if anything, one that we finally fixed
2
u/puremourning Sep 07 '22
if you have an existing third-party .a/.o and try to link against it, your build might fail if it wasn't compiled with -fPIC, and you can't recompile it.
It's confusing because:
it all compiles and links fine with gcc
it all compiles and links fine with clang < 15
with clang 15 the linker (pick one gnu ld, ldd, gold) say something like
"cannot make ... reference ... in libc.so... (recompile with -fPIC)"your code is already compiled with -fPIC (but some third-party dependency isn't)
you look at your compile line and don't see -fPIE
etc.
All stuff you link against should be PIC anyways.
not static libraries or objects. at least, it's not guaranteed.
one example is googletest, which by doesn't enable -fPIC in its default build.
1
u/Jannik2099 Sep 07 '22
it all compiles and links fine with gcc
No it doesn't. GCC defaults to PIC on pretty much all distros. Things may work by default with ld.bfd because it enables TEXTRELs by default, which is a whole other security issue in itself.
Sorry for "breaking" your stuff, bit this change should've been done a decade ago. And you can still always do -fno-PIC
1
2
u/SkoomaDentist Antimodern C++, Embedded, Audio Sep 07 '22
Isn't position-independent code slower?
The Linux implementation is (frankly, it's just plain idiotic on x86). Windows did that better by using regular loader relocation techniques.
2
u/Jannik2099 Sep 07 '22
The Linux implementation is (frankly, it's just plain idiotic on x86).
Isn't this better with -fPIC vs -fpic ?
2
u/Jannik2099 Sep 07 '22
PIC is a very important security option. Literally every linux distro uses it system wide, this change is for parity with gcc
2
Sep 06 '22 edited Sep 06 '22
My Ubuntu claims to have Clang 16 already. How does that work, can someone explain?
11
u/encyclopedist Sep 06 '22 edited Sep 06 '22
Which version of Ubuntu do you have? Ubuntu 22.04 only has clang-14.
Edit: maybe you have LLVM apt repository enabled. It has LLVM-16 development branch available.
4
Sep 06 '22
Ubuntu 22.04. Today I did this and now it has clang 16.
14
u/encyclopedist Sep 06 '22
As I expected, you have enabled LLVM apt repository. It makes available not only released version, but also development branch. Currently, this development branch is llvm-16.
2
Sep 06 '22
Thank you. Good to know. I was starting to think they're using a different numbering system, like AppleClang. Nice to know that's not the case.
4
u/erichkeane Clang Maintainer(Templates), EWG Chair Sep 06 '22
Looks like that is a nightly build, so you're going to get a somewhat unstable compiler that way.
2
Sep 06 '22
Yes. So, is this a betta release of some sort?
3
u/smdowney WG21, Text/Unicode SG, optional<T&> Sep 06 '22
16 is current trunk, so don't assume that it's going to be entirely stable for a while. At some point it will be branched for release and will start to stabilise.
The earlier versions are off the release branches for those versions, but, I believe, they track commits on the branches, not releases. Haven't checked and the ease of getting them makes it mostly worth it in any case.
0
Sep 06 '22
[deleted]
51
u/__Mark___ libc++ dev Sep 06 '22
It's in there ;-) https://releases.llvm.org/15.0.0/projects/libcxx/docs/ReleaseNotes.html
The C++20 format library is feature complete, but not all Standard LWG issues have been addressed. Since it is expected that at least one of these issues will cause an ABI break the format`The C++20 format library is feature complete, but not all Standard LWGissues have been addressed. Since it is expected that at least one of these issues will cause an ABI break the format library is considered experimental.
0
Sep 06 '22
[deleted]
35
u/__Mark___ libc++ dev Sep 06 '22
No we made changes in Clang and libc++ making the experimental library easier to use. This requires Clang 15 and your vendor should ship the experimental library. (I expect most of the vendors do so be default.)
Then it's one extra switch to enable the experimental library
-fexperimental-library0
Sep 07 '22
[deleted]
3
u/louis_dionne libc++ | C++ Committee | Boost.Hana Sep 07 '22
You are probably missing a target-specific include directory. Try to look for `__config_site` under something like `<...>/include/<target>/c++/v1`. On most platforms (macOS is a notable exclusion), Clang now puts `__config_site` in a target-specific location, which allows different targets to have different libc++ configurations. This is nice, but it does make things a bit more complicated for you. Although if you build everything with the Booststrapping build (https://libcxx.llvm.org/BuildingLibcxx.html#bootstrapping-build), I would expect that you don't need to pass `-nostdinc++ -I <whatever>`. Clang should just find the libc++ headers alone.
7
u/qalmakka Sep 07 '22
If I look to the C++20 implementation status of MSVC, GCC and Clang, Clang is lagging quite behind. What happened? It was always one of the first to get new standards a few years ago, and now after years it still doesn't have stuff like concepts completely ironed out.
Is it maybe due to the fact Apple and Google apparently don't give a damn about (modern) C++ anymore ?