Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Gentoo Chat
  • Search

gcc vs clang: why/when do you stay/switch?

Opinions, ideas and thoughts about Gentoo. Anything and everything about Gentoo except support questions.
Post Reply
  • Print view
Advanced search
16 posts • Page 1 of 1
Author
Message
CaptainBlood
Advocate
Advocate
User avatar
Posts: 4237
Joined: Sun Jan 24, 2010 9:38 am

gcc vs clang: why/when do you stay/switch?

  • Quote

Post by CaptainBlood » Sun Dec 01, 2024 10:34 am

More and more topics have clang as an origin of issue.
Likely only because more and more users are switching. no judging on clang here.

I've just noticed stage3 has a LLVM version.

LTO kernel requires clang as gcc in this respect is simply not there.

IIUC clang is expected to compile faster in many cases which would be a time-saver when testing source packages or ebuilds.

As far as performance is concerned I know there are packages which do perform much faster when build with clang.
Defining such a list isn't a easy task. :)

There can be other reasons, unlisted there. :roll:

Anyone having switched at package level or globally to share reasons of choice, whatever their stage3 was?

Thks 4 ur attention, interest & support.
Last edited by CaptainBlood on Wed Dec 04, 2024 12:34 am, edited 5 times in total.
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4692
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sun Dec 01, 2024 11:19 am

I've used musl+llvm toolchain on amd64. And I'm about to set up one once again. Last time I ran it, it needed some extra work with some of the packages. And I needed to mask gcc.
I do run (not updated recently) glibc+llvm on my MacBook Air M2 which is arm64 obviously. I have hopes llvm could give better optimizations on Apple ARM since Apple itself uses llvm quite a lot. There hasn't been problems, but I don't use it very much because of the lack of memory (only 8G with no possibility to upgrade).
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Goverp
Advocate
Advocate
User avatar
Posts: 2402
Joined: Wed Mar 07, 2007 6:41 pm

  • Quote

Post by Goverp » Sun Dec 01, 2024 12:21 pm

I switched to Clang 'cos it uses less space to compile qtwebengine, and hence can compile it faster. Having done that for qtwebengine, I thought I'd try it on more and more stuff until now it's my default*. My reason for that is Clang & LLVM are much newer than gcc, and (as Captain Blood mentioned, works better with LTO), and I assume large software suffers with age.
Also, AFAIK the only way to compile a kernel with LTO is with Clang.

* I say "default", as I have a package.env file for those where Clang breaks, but I know that the Gentoo devs also override the use of Clang for packages they know are broken, so I probably use Clang rather less often than I think!
Greybeard
Top
CaptainBlood
Advocate
Advocate
User avatar
Posts: 4237
Joined: Sun Jan 24, 2010 9:38 am

  • Quote

Post by CaptainBlood » Sun Dec 01, 2024 1:13 pm

Goverp wrote:(as Captain Blood mentioned, works better with LTO)
Didn't said that, only mentioned clang dedicated kernel LTO feature.
Not saying that ain't true, I have no experience to share...

Thks 4 ur attention, interest & support.
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Top
Spanik
Veteran
Veteran
Posts: 1170
Joined: Fri Dec 12, 2003 9:10 pm
Location: Belgium

  • Quote

Post by Spanik » Mon Dec 02, 2024 9:09 am

I have a couple of packages that I use clang because when compiling them with gcc I hit a hardware issue with the cpu (AMD Epyc). So more a workaround then anything else.
Expert in non-working solutions
Top
mirekm
Apprentice
Apprentice
User avatar
Posts: 237
Joined: Thu Feb 12, 2004 8:17 am
Location: Gliwice

  • Quote

Post by mirekm » Mon Dec 02, 2024 9:12 am

I stay on gcc. The main reason is security. For gcc there is hardened version.
The other thing is that clang allow bad quality code to work, and you will never know where is a hole allowing attack to your computer.
Top
Hu
Administrator
Administrator
Posts: 24386
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Mon Dec 02, 2024 1:31 pm

Both gcc and clang allow bad quality code to compile, as long as the code is standards-compliant. It is fairly straightforward to write a program that both compilers will accept, but that has serious security problems when exposed to untrusted input. Therefore, I think it is not fair to blame clang for allowing bad quality code to work.
Top
CaptainBlood
Advocate
Advocate
User avatar
Posts: 4237
Joined: Sun Jan 24, 2010 9:38 am

  • Quote

Post by CaptainBlood » Mon Dec 02, 2024 10:32 pm

mirekm wrote:I stay on gcc. The main reason is security. For gcc there is hardened version.
So IIUC ebuild hardened kernel is currently gcc only, right?

Thks 4 ur attention, interest & support.
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Top
mirekm
Apprentice
Apprentice
User avatar
Posts: 237
Joined: Thu Feb 12, 2004 8:17 am
Location: Gliwice

  • Quote

Post by mirekm » Tue Dec 03, 2024 6:25 am

Hu wrote:Both gcc and clang allow bad quality code to compile, as long as the code is standards-compliant. It is fairly straightforward to write a program that both compilers will accept, but that has serious security problems when exposed to untrusted input. Therefore, I think it is not fair to blame clang for allowing bad quality code to work.
But what I see trying to compile chromium with gcc, there are frequently compilation errors like missing includes of header files, private parts of objects used globally, etc. All these get compiled clearly with clang, while you get errors with gcc.
What that says?
Top
mirekm
Apprentice
Apprentice
User avatar
Posts: 237
Joined: Thu Feb 12, 2004 8:17 am
Location: Gliwice

  • Quote

Post by mirekm » Tue Dec 03, 2024 6:30 am

[quote]So IIUC ebuild hardened kernel is currently gcc only, right?
/quote]

This I don't know. I didn't try to compile kernel with clang. As far I remember, on newest kernels there were patches to compile it with clang.
Top
bstaletic
Guru
Guru
Posts: 517
Joined: Sat Apr 05, 2014 5:46 pm

  • Quote

Post by bstaletic » Tue Dec 03, 2024 7:18 am

mirekm wrote:But what I see trying to compile chromium with gcc, there are frequently compilation errors like missing includes of header files, private parts of objects used globally, etc. All these get compiled clearly with clang, while you get errors with gcc.
What that says?
Taking your claims about compile time errors at face value, it only says that one specific project is only tested with clang.
Go look at magic_enum and you'll see the codebase that reaches into the implementation specific stuff of all three common C++ compilers.
Automagically printing enumerators is not possible in standard C++ and won't be until proposal P2996 gets implemented.

Even funnier is that operator| was absolutely not portable even between compiler versions, when it comes to piping user defined views. We needed P2387 to give us std::ranges::range_adaptor_closure and std::bind_back.
That did not stop some brave souls to find the implementation details for each compiler that supported C++20 at the time and do a lot of std::_Compiler_specific_things.
Top
CaptainBlood
Advocate
Advocate
User avatar
Posts: 4237
Joined: Sun Jan 24, 2010 9:38 am

  • Quote

Post by CaptainBlood » Tue Dec 03, 2024 10:29 am

mirekm wrote:
CaptainBlood wrote:So IIUC ebuild hardened kernel is currently gcc only, right?
This I don't know. I didn't try to compile kernel with clang. As far I remember, on newest kernels there were patches to compile it with clang.
My bad, :oops: You must be talking stage3 then?

Thks 4 ur attention, interest & support.
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Top
Hu
Administrator
Administrator
Posts: 24386
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Tue Dec 03, 2024 1:36 pm

To extend on bstaletic's response to mirekm's comments about Chromium, I would add that if gcc is rejecting these files, and clang is accepting them, then it seems more likely that gcc is being strict about requiring correct inputs and clang is being sloppy and allowing invalid inputs. However, mirekm's earlier post read to me more like a complaint that clang was allowing insecure code to succeed. There is an important distinction between code which is unsafe to run because it may do something bad versus code that is safe to run, but painful to read and compile. Assuming mirekm's comments about Chromium are accurate, we know only that some unspecified version is painful to compile. It might be perfectly safe and secure to run once it is compiled. Without a specific version and specific error messages, we cannot determine the true extent of the problems with Chromium.
Top
pjp
Administrator
Administrator
User avatar
Posts: 20668
Joined: Tue Apr 16, 2002 10:35 pm

  • Quote

Post by pjp » Tue Dec 03, 2024 11:17 pm

I dislike having only a single option. So while I'm glad they both exist, I'd ideally only need one installed.

I use both, albeit not for anything meaningful. gcc from the command line, clang in make files. The former including a link to 'gcc' while the latter does not.
Quis separabit? Quo animo?
Top
pa4wdh
Veteran
Veteran
Posts: 1015
Joined: Fri Dec 16, 2005 6:55 pm

  • Quote

Post by pa4wdh » Wed Dec 04, 2024 3:55 pm

I"m using gcc (unless some ebuild forces otherwise).

I know clang/llvm exists, but i don't know a single reason to use one or the other. For now i'm using gcc because it's the default.
I hope with this topic i'll learn something about both and be able to make an informed decision :).
The gentoo way of bringing peace to the world:
USE="-war" emerge --newuse @world

My shared code repository: https://code.pa4wdh.nl.eu.org
Music, Free as in Freedom: https://www.jamendo.com
Top
flysideways
Guru
Guru
Posts: 527
Joined: Sat Jan 29, 2005 1:06 pm

  • Quote

Post by flysideways » Thu Dec 05, 2024 8:45 pm

I have not gone out of my way to use clang, but, after the runaway amount of memory webkit-gtk needs and the upstream recommendation to use clang, my 8G Gentoo Pi 5 has per package invocation of clang for webkit-gtk. With clang, it compiles fine with 4 threads and about the same time as earlier gcc builds when 8G would still support 4 threads.

Using gcc, I was down to 2 threads to avoid out of memory errors. Even with 2 threads, there were occasions I noticed the system memory was at 6.6G.

Time permitting, it would be interesting to do the llvm install.
Top
Post Reply
  • Print view

16 posts • Page 1 of 1

Return to “Gentoo Chat”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic