Skip to content

[compiler-rt] lots of "warning: unknown warning option '-Werror=builtin-declaration-mismatch'" messages #72413

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

Closed
ms178 opened this issue Nov 15, 2023 · 32 comments · May be fixed by #125602
Closed
Labels
cmake Build system in general and CMake in particular compiler-rt:builtins

Comments

@ms178
Copy link

ms178 commented Nov 15, 2023

Compiling llvm-git with 0a0e06f leads to the following new warnings in compiler-rt:

[747/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/floatundisf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[748/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/muldi3.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[749/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/ashrdi3.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[750/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/floatdidf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[751/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/floatdisf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[752/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/floatundidf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[753/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/lshrdi3.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[754/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/moddi3.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[755/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/udivdi3.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[757/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/ashldi3.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[766/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/divdi3.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[768/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/umoddi3.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[770/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/floatdixf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[790/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-i386.dir/i386/floatundixf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[929/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundidf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[930/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundisf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[942/6672] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundixf.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]

CachyOS also ships with a brand new gcc-version 13.2.1 20231110.

@EugeneZelenko EugeneZelenko added cmake Build system in general and CMake in particular compiler-rt:builtins and removed new issue labels Nov 15, 2023
@thesamesam
Copy link
Member

-Wbuiltin-declaration-mismatch is not referenced anywhere within the LLVM repository. It's likely your toolchain setting it or your build script.

@ms178
Copy link
Author

ms178 commented Nov 17, 2023

That's what I don't understand, neither my llvm-git PKGBUILD nor the /etc/makepkg.conf do set that explicitly.

@ms178
Copy link
Author

ms178 commented Nov 17, 2023

For reference, I am attaching the build config which is inside the PKGBUILD: PKGBUILD.txt

And these flags are set in /etc/makepkg.conf:

export CC=clang
export CXX=clang++
export CC_LD=lld
export CXX_LD=lld
export AR=llvm-ar
export NM=llvm-nm
export STRIP=llvm-strip
export OBJCOPY=llvm-objcopy
export OBJDUMP=llvm-objdump
export READELF=llvm-readelf
export RANLIB=llvm-ranlib
export HOSTCC=clang
export HOSTCXX=clang++
export HOSTAR=llvm-ar
export CPPFLAGS="-D_FORTIFY_SOURCE=0"
export CFLAGS="-O3 -march=native -mtune=native -maes -mbmi2 -mpclmul -mllvm -inline-threshold=500 -mllvm -extra-vectorizer-passes -mllvm -enable-cond-stores-vec -mllvm -slp-vectorize-hor-store -mllvm -enable-loopinterchange -mllvm -enable-loop-distribute -mllvm -enable-unroll-and-jam -mllvm -enable-loop-flatten -mllvm -interleave-small-loop-scalar-reduction -mllvm -unroll-runtime-multi-exit -mllvm -aggressive-ext-opt -fno-math-errno -fno-trapping-math -falign-functions=32 -funroll-loops -fno-semantic-interposition -fcf-protection=none -mharden-sls=none -fomit-frame-pointer -mprefer-vector-width=256 -flto=thin -fwhole-program-vtables -fsplit-lto-unit -mllvm -adce-remove-loops -mllvm -enable-ext-tsp-block-placement=1 -mllvm -enable-gvn-hoist -mllvm -enable-dfa-jump-thread -Wno-error -fgnuc-version=13.2.1 -fprofile-use=/home/marcus/Downloads/llvm17.profdata -ffp-contract=fast -fdata-sections -ffunction-sections -fno-unique-section-names -fsplit-machine-functions -freroll-loops -w"
export CXXFLAGS="${CFLAGS} -Wp,-U_GLIBCXX_ASSERTIONS"
export LDFLAGS="-Wl,--lto-CGO3 -Wl,--gc-sections -Wl,--icf=all -Wl,--lto-O3,-O3,-Bsymbolic-functions,--as-needed -fcf-protection=none -mharden-sls=none -Wl,-mllvm -Wl,-extra-vectorizer-passes -Wl,-mllvm -Wl,-enable-cond-stores-vec -Wl,-mllvm -Wl,-slp-vectorize-hor-store -Wl,-mllvm -Wl,-enable-loopinterchange -Wl,-mllvm -Wl,-enable-loop-distribute -Wl,-mllvm -Wl,-enable-unroll-and-jam -Wl,-mllvm -Wl,-enable-loop-flatten -Wl,-mllvm -Wl,-interleave-small-loop-scalar-reduction -Wl,-mllvm -Wl,-unroll-runtime-multi-exit -Wl,-mllvm -Wl,-aggressive-ext-opt -Wl,-mllvm -Wl,-enable-interleaved-mem-accesses -Wl,-mllvm -Wl,-enable-masked-interleaved-mem-accesses -march=native -maes -mbmi2 -mpclmul -flto=thin -fwhole-program-vtables -fuse-ld=lld -Wl,-zmax-page-size=0x200000 -fprofile-use=/home/marcus/Downloads/llvm17.profdata -freroll-loops -Wl,-mllvm -Wl,-adce-remove-loops -Wl,-mllvm -Wl,-enable-ext-tsp-block-placement=1 -Wl,-mllvm -Wl,-enable-gvn-hoist -Wl,-mllvm -Wl,-enable-dfa-jump-thread -Wl,--push-state -Wl,-whole-archive -ljemalloc_pic -Wl,--pop-state -lpthread -lstdc++ -lm -ldl -Wl,--undefined-version"
CCLDFLAGS="$LDFLAGS"
CXXLDFLAGS="$LDFLAGS"
export ASFLAGS="-D__AVX__=1 -D__AVX2__=1 -msse2avx -D__FMA__=1"

@mati865
Copy link
Contributor

mati865 commented Apr 30, 2024

@thesamesam it is, since dc298fe

@ms178
Copy link
Author

ms178 commented Feb 1, 2025

@arichardson @thesamesam Ping. Could you please take a look, this issue still reproduces on latest main.

@ms178
Copy link
Author

ms178 commented Feb 1, 2025

You might need to adjust the build_stage1.bash script manually, as I use a local PGO-profile with it.

@arichardson
Copy link
Member

Well that flag is only passed if the CMake configure command detects it as supported, so I have no idea why this is failing unless you are somehow overriding the compiler manually?

@ms178
Copy link
Author

ms178 commented Feb 2, 2025

I set the compiler flags via cmake within the scripts. And before the mentioned change, there were no such warnings.

@arichardson
Copy link
Member

I don't understand why this would be going wrong since cmake tests if the flag is supported before using it. The cmake log should be helpful for figuring this out.

Could be an issue with using DLLVM_ENABLE_PROJECTS=compiler-rt. This is no longer supported on main and should be using runtimes instead.

@ms178
Copy link
Author

ms178 commented Feb 3, 2025

Here are the logs from the ENABLE_PROJECTS build.

cmake_log.txt

CMakeCache.txt

With a ENABLE_RUNTIMES build, I don't get these warnings.

@thesamesam
Copy link
Member

thesamesam commented Feb 3, 2025

It might be the same thing as #124623. Please try to minimise the steps required to reproduce it rather than producing large scripts with options that definitely won't work for me.

@ms178
Copy link
Author

ms178 commented Feb 3, 2025

Sorry, I've already provided a script that reproduces the problem (which I've updated today to workaround this issue, hence you'd need to undo that change). If that script doesn't suit you, you should be able to reproduce the problem when building compiler-rt via the -DLLVM_ENABLE_PROJECTS=compiler-rt route. The problem was confirmed by a third party, we've also identified the change that introduced the problem and narrowed down that the warnings only appear when using -DLLVM_ENABLE_PROJECTS=compiler-rt, they do not appear when using -DLLVM_ENABLE_RUNTIMES=compiler-rt.

The following is what AI came up as a summary. This is all I - as an unpaid non-programmer - can possibly add to this discussion. I'll leave it to you programmers to get to the bottomn of this if that is still a reasonable request, as I was told that the ENABLE_PROJECTS route is deprecated for compiler-rt anyway which should make this issue obsolete soon.

These warnings are related to the -Werror=builtin-declaration-mismatch flag, which is not recognized by the Clang assembler. These warnings were introduced by commit dc298fecb79608e6628bd730ece42a6a77197a3c (https://github.com/llvm/llvm-project/commit/dc298fecb79608e6628bd730ece42a6a77197a3c), which added the -Werror=builtin-declaration-mismatch flag to check for incorrect builtin function signatures. The flag is intended for the C/C++ frontend but is being passed to the assembler when building assembly files.

The warnings only appear when using -DLLVM_ENABLE_PROJECTS=compiler-rt. They do not appear with -DLLVM_ENABLE_RUNTIMES=compiler-rt. This is likely because the PROJECTS build uses Clang as the default compiler for all files, including assembly, while the RUNTIMES build might use a different assembler or might not pass C/C++ frontend flags to the assembler.

The exact warning message is:

`warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]`

The warnings are observed for the following assembly files:

projects/compiler-rt/lib/builtins/i386/floatundisf.S
projects/compiler-rt/lib/builtins/i386/muldi3.S
projects/compiler-rt/lib/builtins/i386/ashrdi3.S
projects/compiler-rt/lib/builtins/i386/floatdidf.S
projects/compiler-rt/lib/builtins/i386/floatdisf.S
projects/compiler-rt/lib/builtins/i386/floatundidf.S
projects/compiler-rt/lib/builtins/i386/lshrdi3.S
projects/compiler-rt/lib/builtins/i386/moddi3.S
projects/compiler-rt/lib/builtins/i386/udivdi3.S
projects/compiler-rt/lib/builtins/i386/ashldi3.S
projects/compiler-rt/lib/builtins/i386/divdi3.S
projects/compiler-rt/lib/builtins/i386/umoddi3.S
projects/compiler-rt/lib/builtins/i386/floatdixf.S
projects/compiler-rt/lib/builtins/i386/floatundixf.S
projects/compiler-rt/lib/builtins/x86_64/floatundidf.S
projects/compiler-rt/lib/builtins/x86_64/floatundisf.S
projects/compiler-rt/lib/builtins/x86_64/floatundixf.S

@thesamesam
Copy link
Member

thesamesam commented Feb 3, 2025

No, you provided a script which you even admitted would need adaptation (in two ways!). No AI sludge, please.

Bugs require collaboration, I'm afraid, it's not a matter of throwing things over the wall. You pinged and said it's still happening, and I told you what I'd need to work on it. You're free to propose a patch yourself instead. I'll unsubscribe from this bug now.

@ms178
Copy link
Author

ms178 commented Feb 3, 2025

No, you provided a script which you even admitted would need adaptation (in two ways!). No AI sludge, please.

Bugs require collaboration, I'm afraid, it's not a matter of throwing things over the wall. You pinged and said it's still happening, and I told you what I'd need to work on it. You're free to propose a patch yourself instead. I'll unsubscribe from this bug now.

Sorry, but I am not just throwing things over the wall here. If adapting a script in two obvious ways is too much to ask for you, it is too much to ask for me to sink any more time into this soon-to-be-obsolete issue. My time is limited and also valuable. I can also work on other more meaningful issues. And I consider the hints that were given here good enough and actionable for you guys to actually do your job instead of letting laymen solve it for you.

@arichardson
Copy link
Member

@ms178 the following PR hopefully fixes this issue: #125602

@eli-schwartz
Copy link

The following is what AI came up as a summary. This is all I - as an unpaid non-programmer - can possibly add to this discussion.

So you paid good money for a program to "repeat, in your own words, [...]" without adding any useful or usable novel information, but...

My time is limited and also valuable.

With the implicit suggestion that the time of LLVM developers is neither one. Very nice. I suppose the contrast with you as "unpaid" means that LLVM developers are paid, hence why their time is unlimited.

And I consider the hints that were given here good enough and actionable for you guys to actually do your job instead of letting laymen solve it for you.

And here you are, again, claiming that this is a "job". Can you show me your paid support contract? People like you are why OSS developers give up on OSS.

That's true without you running a stochastic parrot designed to produce lies instead of actionable information -- though the stochastic parrot usage certainly doesn't help.

@ms178
Copy link
Author

ms178 commented Feb 4, 2025

@eli-schwartz

Let's not go this route of further escalation (you are arguing with a law professional who also happens to be a tech enthusiast). I also refuse to fight strawman arguments. Blaming me for not having a degree in software engineering to give you a better analysis (or even better, a mergable MR) is not helpful either. At least I put effort into providing you constructive analysis and feedback to the best of my abilities. That is all what you can hope for from a end user like me.

I also question the professionalism of you and Sam in dealing with my criticism. Yes, I might have overreacted emotionally as I would have hoped for a more forthcoming approach from the start. But the issue got ignored for two years even though the change that introduced it was identified in the meantime by a third party and could have been reverted or fixed in due time with some effort. Thankfully Alexander was more constructive without making unreasonable demands or blaming me and could identify a defect in the meantime. From the discussions of the proposed fix in #125602, I take away that my report and my insistance was of some value for the LLVM community after all.

Why CI and the build bots didn't catch it back then would be another interesting question for another day and poits to a lack in coverage.

@eli-schwartz
Copy link

Let's not go this route of further escalation (you are arguing with a law professional who also happens to be a tech enthusiast). I also refuse to fight strawman arguments. Blaming me for not having a degree in software engineering to give you a better analysis (or even better, a mergable MR) is not helpful either. At least I put effort into providing you constructive analysis and feedback to the best of my abilities. That is all what you can hope for from a end user like me.

You are welcome to escalate and sue me for defamation of character, if you like. It's very easy to claim anything on the internet.

But I am not blaming you for not having a degree in software engineering. And I'm not expecting or demanding an analysis of the underlying cause, nor a mergeable PR. I'm quite happy for end users to report the best they can and very understanding of when they cannot provide more info (even if that does mean sometimes that we will never be able to figure out the problem, it is easy to be polite about my sadness that I'm unable to figure out the problem!). I'm blaming you for being massively rude about it by demanding things from open source developers and claiming an entitlement. I'm blaming you for insinuating that your time is more valuable than the time of others. I'm blaming you for making it difficult to be sad about being unable to solve your problem.

Really, I don't know why this wasn't clear to you from the very start. At no point did I comment on your lack of a degree in software engineering, I commented on your hyperfixation on being "paid" and your demands that LLVM developers need to

actually do your job

which is actually, provably, a common cause of OSS developers quitting their unpaid tech enthusiast hobby which turns out to not actually be a job.

But the issue got ignored for two years even though the change that introduced it was identified in the meantime by a third party and could have been reverted or fixed in due time with some effort. Thankfully Alexander was more constructive without making unreasonable demands or blaming me and could identify a defect in the meantime. From the discussions of the proposed fix in #125602, I take away that my report and my insistance was of some value for the LLVM community after all.

From the discussion of the proposed fix in #125602, I take away that nobody has any clue how your report occurred and the attempted analysis and fix was an incorrect diagnosis. You even reported there that it does NOT fix anything for you. That means the LLVM community is now back at square one in trying to figure out whether there even is a defect to begin with, let alone what the defect is.

Sometimes issues are hard to understand, which is why they take a long time to fix. That's not the same thing as being "ignored".

Why CI and the build bots didn't catch it back then would be another interesting question for another day and poits to a lack in coverage.

Nobody has been able to figure out how to manually reproduce it either. It is, on the face of it, impossible to get wrong.

Again, if we're back at square one in trying to figure out why it happens in the first place (or even whether it is possible to happen in the first place, report notwithstanding), then we can't expect CI and build bots to catch it either.

@ms178
Copy link
Author

ms178 commented Feb 4, 2025

Eli,

While I appreciate your and Sam's engagement, I'm not interested in further personal attacks, baseless accusations or misinterpretations of my choice of words. Let's stick to the issue at hand. I stand by my initial report and the effort I put into providing information, even if the proposed fix in #125602 ultimately proved ineffective, as I reported there.

My comments about "doing your job" and time constraints, were rooted in genuine frustration with Sam's remarks, given the identification of the causative commit and his remarks that I interpreted as provocative and not helpful. I understand the situation is more complex than initially perceived. However, dismissing my contributions and resorting to insults is unproductive.

Regarding the "AI summary," it was an attempt to bridge the communication gap given my lack of programming expertise and shows the effort I am willing to invest to solve this issue. If that was unhelpful, I won't use it again.

Frankly, the energy spent on dissecting our choice of words would be better spent on investigating the issue itself, assuming it is still relevant given the deprecation of the ENABLE_PROJECTS route. I've provided detailed information, a reproducible script (which, yes, requires minor adaptation which won't burn out any OSS developer), and we've got the confirmation from @mati865 already. My time is limited, as is everyone's, but I've invested a considerable amount in this already and hoped Sam and you would be more constructive and forthcoming in the future.

If there's anything specific I can do to assist further, within my technical limitations, please let me know. I'm willing to test new revisions of that MR. Otherwise, I suggest we either focus on concrete steps towards a solution or acknowledge that the issue may be moot due to the deprecation of ENABLE_PROJECTS.

I expect a professional and constructive dialogue going forward from both of you and Sam that complies with LLVM's Code of Conduct.

@eli-schwartz
Copy link

My comments about "doing your job" and time constraints, were rooted in genuine frustration with Sam's remarks, given the identification of the causative commit and his remarks that I interpreted as provocative and not helpful. I understand the situation is more complex than initially perceived. However, dismissing my contributions and resorting to insults is unproductive.

You are more than welcome to interpret people's remarks, such as "Please try to minimise the steps required to reproduce it rather than producing large scripts with options that definitely won't work for me.", as provocative and unhelpful. As long as you're okay with those people then interpreting your comments about people's paid jobs, as provocative and unhelpful on your part.

Personally, I don't see how

Please try to minimise the steps required to reproduce it rather than producing large scripts with options that definitely won't work for me.

is provocative or unhelpful. It's pretty standard OSS interaction to expect users to aid in the investigation process, for example by testing their own build process incrementally through seeing which settings can be removed while still reproducing the problem, and not at all astonishing if an OSS developer therefore cordially requests you to do so.

(And you admitted that the large scripts in question contain hardcoded information such as your personal computer's login username, clearly those scripts won't work out of the box on someone else's machine, which is precisely why it is helpful for the reporter to, if they can, "please try" to minimize the size of the reproducer script.)

You may think you're frustrated, but I promise you, there are other people in the world who occasionally feel frustrated too.

Regarding the "AI summary," it was an attempt to bridge the communication gap given my lack of programming expertise and shows the effort I am willing to invest to solve this issue. If that was unhelpful, I won't use it again.

I am sorry to have to confirm this :( but AI is a hugely divisive topic that many, many, many people regard as a hoax produced by scammers and con artists grifting for venture capitalist money. There is a significant body of work around AI (in)accuracy, both scientific papers and bloggers. For an example of what some people think about it, see e.g. https://softwarecrisis.dev/letters/llmentalist/

On top of this, AI bots are behind the world's largest DDoS attack on the entirety of the open web, with great emphasis on the "distributed" part of "distributed denial of service". Additionally, AI is incredibly damaging to the environment in precisely the same way that cryptocurrency mining is.

Attempting to use AI to "bridge the communication gap" runs the risk of upsetting a subset of people who feel that you're insulting both their intelligence and their dayjob. The reasoning would be something like "this person thinks I'm not worth the effort of communicating with, and is instead helping destroy the planet in order to tell me information I already know".

Of course, your mileage may vary. Plenty of people seem to like AI a lot. But personally, I'd ask, why risk it?

Frankly, the energy spent on dissecting our choice of words would be better spent on investigating the issue itself, assuming it is still relevant given the deprecation of the ENABLE_PROJECTS route. I've provided detailed information, a reproducible script (which, yes, requires minor adaptation which won't burn out any OSS developer), and we've got the confirmation from @mati865 already.

You seem to be under the impression that people haven't investigated the issue itself, though I'm not sure why you believe that.

Note as well that @mati865 did NOT confirm your issue, only corrected Sam, who said:

-Wbuiltin-declaration-mismatch is not referenced anywhere within the LLVM repository. It's likely your toolchain setting it or your build script.

by pointing out that a reference had been added within the LLVM repository that very day. No claim was made that "I have reproduced the bug report."

I expect a professional and constructive dialogue going forward from both of you and Sam that complies with LLVM's Code of Conduct.

If you're accusing people of violating the LLVM Code of Conduct please communicate directly to the Code of Conduct committee. Note that this is a double-edged sword -- one could easily argue that language such as demanding people "actually do your job" is a Code of Conduct violation.

Threatening and browbeating people over Code of Conduct accusations is also a potential Code of Conduct violation, depending on whether or not the accusation turns out to be accurate or at least qualifies for the subjective "reasonable person would feel cause for concern" threshold. I personally would say that e.g.

Bugs require collaboration, I'm afraid, it's not a matter of throwing things over the wall. You pinged and said it's still happening, and I told you what I'd need to work on it.

is not something that the average person would be worried is a Code of Conduct violation to the extent one would have to publicly announce a belief that it was in violation.

As you've claimed:

I also question the professionalism of you and Sam in dealing with my criticism. Yes, I might have overreacted emotionally as I would have hoped for a more forthcoming approach from the start. But the issue got ignored for two years even though the change that introduced it was identified in the meantime by a third party and could have been reverted or fixed in due time with some effort. Thankfully Alexander was more constructive without making unreasonable demands or blaming me

I can only conclude that you believe it is a Code of Conduct violating level of "unprofessionalism" to make what you believe are "unreasonable demands" and then "blame" you for not having enough information to provide to merit further investigation.

@mati865
Copy link
Contributor

mati865 commented Feb 5, 2025

Note as well that @mati865 did NOT confirm your issue, only corrected Sam, who said:

-Wbuiltin-declaration-mismatch is not referenced anywhere within the LLVM repository. It's likely your toolchain setting it or your build script.

by pointing out that a reference had been added within the LLVM repository that very day. No claim was made that "I have reproduced the bug report."

I should have been more elaborate on my part. I'm 90% sure I have somehow hit this issue but the details are lost to the time now. Probably my reproducer was so complicated I decided to only confirm this issue might come from LLVM's own code.

@ms178
Copy link
Author

ms178 commented Feb 5, 2025

I can only conclude that you believe it is a Code of Conduct violating level of "unprofessionalism" to make what you believe are "unreasonable demands" and then "blame" you for not having enough information to provide to merit further investigation.

Eli, this will be my last comment on our personal dispute. I've filed a Code of Conduct violation where I've presented my side of the story with the concerned committee. From your lengthy comment that I still consider to be hostile in tone, I can see that you show no signs of any wrongdoing on your or Sam's part. That is unacceptable in my opinion. This is not my first interaction with OSS developers, hence a "standard OSS interaction" looks different from my experience and already had the pleasure to work with many other engineers that were more understanding and forthcoming to me as a non-programmer. They could keep a professional tone despite some of my reported problems originated from user error. Yet they didn't make unreasonable demands or came up with false accusations that I found to be highly discouraging of future contributions.

The adjusted script - even without the PGO-file that I use on my local machine (which can be easily deleted even under heavy time constraints by any developer willing to help within thirty seconds) should reproduce the problem. Yet I haven't seen any efforts of you or Sam trying to reproduce the issue with that provided script.
Yet you seem to prioritize defending your personal attacks and demands towards me over solving the technical issue at hand which doesn't fit my definition of productiveness.

Here is the adjusted script, I've tested it without the local PGO profile and it still reproduces the reported issue reliably. You need to run the setup-repo script (as linked above) first, though.

#!/bin/bash

TOPLEV=~/toolchain/llvm
cd ${TOPLEV} || (echo "Could not enter ${TOPLEV} directory"; exit 1)
mkdir -p ${TOPLEV}
git clone https://github.com/llvm/llvm-project.git

mkdir -p stage1 || (echo "Could not create stage1 directory"; exit 1)
cd stage1 || (echo "Could not enter stage 1 directory"; exit 1)

echo "== Configure Build"
echo "== Build with system clang"

cmake -G Ninja ${TOPLEV}/llvm-project/llvm \
    -DLLVM_BINUTILS_INCDIR=/usr/include \
    -DCMAKE_BUILD_TYPE=Release \
    -DCLANG_ENABLE_ARCMT=OFF \
    -DCLANG_ENABLE_STATIC_ANALYZER=OFF \
    -DCLANG_PLUGIN_SUPPORT=OFF \
    -DLLVM_ENABLE_BINDINGS=OFF \
    -DLLVM_ENABLE_OCAMLDOC=OFF \
    -DLLVM_INCLUDE_DOCS=OFF \
    -DLLVM_INCLUDE_EXAMPLES=OFF \
    -D LLVM_BUILD_DOCS=OFF \
    -D LLVM_ENABLE_SPHINX=OFF \
    -D LLVM_ENABLE_DOXYGEN=OFF \
    -D LLVM_ENABLE_Z3_SOLVER=ON \
    -DCMAKE_C_COMPILER=clang \
    -DCMAKE_CXX_COMPILER=clang++ \
    -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-pc-linux-gnu" \
    -DLLVM_USE_LINKER=lld \
    -DLLVM_USE_PERF=OFF \
    -DLLVM_ENABLE_PROJECTS="clang;lld;bolt;compiler-rt" \
    -DLLVM_TARGETS_TO_BUILD="X86" \
    -D CMAKE_C_FLAGS="-O3 -march=native -mtune=native -fcf-protection=none -mharden-sls=none -flto=thin -fwhole-program-vtables" \
    -D CMAKE_CXX_FLAGS="-O3 -march=native -mtune=native -fcf-protection=none -mharden-sls=none -flto=thin -fwhole-program-vtables" \
    -D CMAKE_EXE_LINKER_FLAGS="-Wl,--thinlto-jobs=8 -Wl,--lto-CGO3 -Wl,--gc-sections -Wl,--icf=all -Wl,--lto-O3,-O3,-Bsymbolic-functions,--as-needed -flto=thin -fwhole-program-vtables -fuse-ld=lld -Wl,-zmax-page-size=0x200000 -Wl,--push-state -Wl,-whole-archive -lmimalloc -Wl,--pop-state -lpthread -lstdc++ -lm -ldl" \
    -D CMAKE_MODULE_LINKER_FLAGS="-Wl,--thinlto-jobs=8 -Wl,--lto-CGO3 -Wl,--gc-sections -Wl,--icf=all -Wl,--lto-O3,-O3,-Bsymbolic-functions,--as-needed -flto=thin -fwhole-program-vtables -fuse-ld=lld -Wl,-zmax-page-size=0x200000 -Wl,--push-state -Wl,-whole-archive -lmimalloc -Wl,--pop-state -lpthread -lstdc++ -lm -ldl" \
    -D CMAKE_SHARED_LINKER_FLAGS="-Wl,--thinlto-jobs=8 -Wl,--lto-CGO3 -Wl,--gc-sections -Wl,--icf=all -Wl,--lto-O3,-O3,-Bsymbolic-functions,--as-needed -flto=thin -fwhole-program-vtables -fuse-ld=lld -Wl,-zmax-page-size=0x200000 -Wl,--push-state -Wl,-whole-archive -lmimalloc -Wl,--pop-state -lpthread -lstdc++ -lm -ldl" \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_BUILD_UTILS=OFF \
    -DLLVM_ENABLE_BACKTRACES=OFF \
    -DLLVM_ENABLE_WARNINGS=OFF \
    -DLLVM_INCLUDE_TESTS=OFF \
        -DCLANG_BUILD_TOOLS=ON \
        -DCLANG_TOOL_AMDGPU_ARCH_BUILD=OFF \
        -DCLANG_TOOL_APINOTES_TEST_BUILD=OFF \
        -DCLANG_ENABLE_OBJC_REWRITER=OFF \
        -DCLANG_TOOL_C_INDEX_TEST_BUILD=OFF \
        -DCLANG_TOOL_CLANG_CHECK_BUILD=OFF \
        -DCLANG_TOOL_CLANG_DIFF_BUILD=OFF \
        -DCLANG_TOOL_CLANG_EXTDEF_MAPPING_BUILD=OFF \
        -DCLANG_TOOL_CLANG_FORMAT_BUILD=OFF \
        -DCLANG_TOOL_CLANG_FUZZER_BUILD=OFF \
        -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=OFF \
        -DCLANG_TOOL_CLANG_INSTALLAPI_BUILD=OFF \
        -DCLANG_TOOL_CLANG_LINKER_WRAPPER_BUILD=OFF \
        -DCLANG_TOOL_CLANG_NVLINK_WRAPPER_BUILD=OFF \
        -DCLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD=OFF \
        -DCLANG_TOOL_CLANG_OFFLOAD_PACKAGER_BUILD=OFF \
        -DCLANG_TOOL_CLANG_REFACTOR_BUILD=OFF \
        -DCLANG_TOOL_CLANG_REPL_BUILD=OFF \
        -DCLANG_TOOL_CLANG_SCAN_DEPS_BUILD=OFF \
        -DCLANG_TOOL_CLANG_SHLIB_BUILD=OFF \
        -DCLANG_TOOL_CLANG_SYCL_LINKER_BUILD=OFF \
        -DCLANG_TOOL_DIAGTOOL_BUILD=OFF \
        -DCLANG_TOOL_LIBCLANG_BUILD=OFF \
        -DCLANG_TOOL_NVPTX_ARCH_BUILD=OFF \
        -DCLANG_TOOL_SCAN_BUILD_BUILD=OFF \
        -DCLANG_TOOL_SCAN_BUILD_PY_BUILD=OFF \
        -DCLANG_TOOL_SCAN_VIEW_BUILD=OFF \
        -DLLVM_TOOL_BUGPOINT_BUILD=OFF \
        -DLLVM_TOOL_BUGPOINT_PASSES_BUILD=OFF \
        -DLLVM_TOOL_DSYMUTIL_BUILD=OFF \
        -DLLVM_TOOL_DXIL_DIS_BUILD=OFF \
        -DLLVM_TOOL_LLVM_AS_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_BCANALYZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_C_TEST_BUILD=OFF \
        -DLLVM_TOOL_LLVM_CAT_BUILD=OFF \
        -DLLVM_TOOL_LLVM_CFI_VERIFY_BUILD=OFF \
        -DLLVM_TOOL_LLVM_EXEGESIS_BUILD=OFF \
        -DLLVM_TOOL_LLVM_EXTRACT_BUILD=OFF \
        -DLLVM_TOOL_LLVM_GSYMUTIL_BUILD=OFF \
        -DLLVM_TOOL_LLVM_IFS_BUILD=OFF \
        -DLLVM_TOOL_LLVM_ISEL_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_ITANIUM_DEMANGLE_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_JITLINK_BUILD=OFF \
        -DLLVM_TOOL_LLVM_JITLISTENER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_LIBTOOL_DARWIN_BUILD=OFF \
        -DLLVM_TOOL_LLVM_MC_ASSEMBLE_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_MC_DISASSEMBLE_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_MCA_BUILD=OFF \
        -DLLVM_TOOL_LLVM_MICROSOFT_DEMANGLE_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_OPT_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_OPT_REPORT_BUILD=OFF \
        -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=OFF \
        -DLLVM_TOOL_LLVM_READTAPI_BUILD=OFF \
        -DLLVM_TOOL_LLVM_REDUCE_BUILD=OFF \
        -DLLVM_TOOL_LLVM_REMARKUTIL_BUILD=OFF \
        -DLLVM_TOOL_LLVM_RUST_DEMANGLE_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_SPECIAL_CASE_LIST_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_TLI_CHECKER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_UNDNAME_BUILD=OFF \
        -DLLVM_TOOL_LLVM_XRAY_BUILD=OFF \
        -DLLVM_TOOL_LLVM_YAML_NUMERIC_PARSER_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_LLVM_YAML_PARSER_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_SPIRV_TOOLS_BUILD=OFF \
        -DLLVM_TOOL_VFABI_DEMANGLE_FUZZER_BUILD=OFF \
        -DLLVM_TOOL_XCODE_TOOLCHAIN_BUILD=OFF \
        -DLLVM_ENABLE_ZLIB=ON \
        -DLLVM_ENABLE_ZSTD=ON \
        -DLLVM_ENABLE_LIBXML2=ON \
        "-DLLVM_THINLTO_CACHE_PATH='${CMAKE_INSTALL_PREFIX}/llvm-thinlto'" \
    -DCMAKE_INSTALL_PREFIX=${TOPLEV}/llvm-bolt > cmake_log.txt 2>&1 || (echo "Could not configure project!"; exit 1)

echo "== Start Build"
ninja install || (echo "Could not build project!"; exit 1)

@arichardson
Copy link
Member

Which version of clang and cmake are you using when running this script?

@ms178
Copy link
Author

ms178 commented Feb 5, 2025

Which version of clang and cmake are you using when running this script?

I've tested Clang 19.1.7 (CachyOS default toolchain) and Clang-21git (7ef636e, built using my llvm-bolt-scripts), both of which reproduce this issue.

Cmake: 3.31.5 (CachyOS default)

@johnsonjamees
Copy link

johnsonjamees commented Feb 6, 2025

I'm trying to build AOSP clang-r530567 on an aarch64 machine using tc-build, which is basically a set of scripts to build LLVM and binutils, and I encountered the same error.

[2988/5097] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-aarch64.dir/outline_atomic_helpers.dir/outline_atomic_ldset8_4.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]
1 warning generated.
[2992/5097] Building ASM object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-aarch64.dir/outline_atomic_helpers.dir/outline_atomic_ldset8_5.S.o
warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]

Environment details

Ubuntu clang version 18.1.3 (1ubuntu1)
Target: aarch64-unknown-linux-gnu
cmake version 3.28.3

@arichardson
Copy link
Member

arichardson commented Feb 6, 2025

Ah I just noticed that the warnings appear to be for assembly files only. Are any C source files affected? I wonder if the problem is that cmake uses a different compiler for assembly sources here? I don't see CMAKE_ASM_COMPILER being overridden in the script above so it probably defaults to a different one?

@ms178
Copy link
Author

ms178 commented Feb 6, 2025

@arichardson I've provided that information in: #72413 (comment) in the part after The warnings are observed for the following assembly files:

I usually set export PATH="/home/marcus/llvm20/bin:$PATH" on the console to use that custom Clang toolchain for compiling stage1, hence I assume that that toolchain also gets gets used building the assembly files. But as stated, the error is also reproducible with the default LLVM/Clang toolchain from CachyOS when building stage 1.

As I don't know the differences under the hood between the ways ENABLE_PROJECTS and ENABLE_RUNTIMES build compiler-rt, this might be indeed another angle for further investigation.

@ms178
Copy link
Author

ms178 commented Feb 6, 2025

This is what Google Gemini 2.0 EXP (edited by me) has to say when analyzing the issue:

The -Werror=builtin-declaration-mismatch flag is intended for C/C++ code but is being incorrectly passed to the assembler when building assembly files (.S).

Problem:

The issue stems from this line in compiler-rt/lib/builtins/CMakeLists.txt:

append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG -Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)

This unconditionally adds -Werror=builtin-declaration-mismatch to BUILTIN_CFLAGS, which is then used for all files in the lib/builtins directory, including assembly files. The assembler doesn't recognize this C/C++ frontend flag, leading to the following warning (which becomes an error due to -Werror):

warning: unknown warning option '-Werror=builtin-declaration-mismatch'; did you mean '-Werror=missing-declarations'? [-Wunknown-warning-option]

This occurs specifically with -DLLVM_ENABLE_PROJECTS=compiler-rt. The -DLLVM_ENABLE_RUNTIMES=compiler-rt build does not exhibit the problem, likely because it uses a different compilation path that doesn't apply C/C++ frontend flags to assembly files.

The affected assembly files are:

  • projects/compiler-rt/lib/builtins/i386/floatundisf.S
  • projects/compiler-rt/lib/builtins/i386/muldi3.S
  • projects/compiler-rt/lib/builtins/i386/ashrdi3.S
  • projects/compiler-rt/lib/builtins/i386/floatdidf.S
  • projects/compiler-rt/lib/builtins/i386/floatdisf.S
  • projects/compiler-rt/lib/builtins/i386/floatundidf.S
  • projects/compiler-rt/lib/builtins/i386/lshrdi3.S
  • projects/compiler-rt/lib/builtins/i386/moddi3.S
  • projects/compiler-rt/lib/builtins/i386/udivdi3.S
  • projects/compiler-rt/lib/builtins/i386/ashldi3.S
  • projects/compiler-rt/lib/builtins/i386/divdi3.S
  • projects/compiler-rt/lib/builtins/i386/umoddi3.S
  • projects/compiler-rt/lib/builtins/i386/floatdixf.S
  • projects/compiler-rt/lib/builtins/i386/floatundixf.S
  • projects/compiler-rt/lib/builtins/x86_64/floatundidf.S
  • projects/compiler-rt/lib/builtins/x86_64/floatundisf.S
  • projects/compiler-rt/lib/builtins/x86_64/floatundixf.S

Proposed Solution:

The fix is to modify compiler-rt/lib/builtins/CMakeLists.txt to conditionally add the -Werror=builtin-declaration-mismatch flag only to C/C++ source files. We can achieve this using CMake's get_source_file_property and set_source_files_properties commands.

Here's the proposed change (assuming the builtins library target is named clang_rt.builtins and the source files are in a variable named BUILTIN_SOURCES):

# ... (previous CMake code) ...

# Assuming your source files are in a variable called BUILTIN_SOURCES
foreach (SOURCE_FILE ${BUILTIN_SOURCES})
  get_source_file_property(SOURCE_LANGUAGE ${SOURCE_FILE} LANGUAGE)
  if (SOURCE_LANGUAGE STREQUAL "C" OR SOURCE_LANGUAGE STREQUAL "CXX")
    # Apply the flag to the specific source file:
    set_source_files_properties(${SOURCE_FILE} PROPERTIES COMPILE_FLAGS "-Werror=builtin-declaration-mismatch")
  endif()
endforeach()

# ... (rest of the CMake code, including add_library) ...
add_library(clang_rt.builtins ${BUILTIN_SOURCES})

# ... (and you might still use BUILTIN_CFLAGS for other flags,
#      but NOT for -Werror=builtin-declaration-mismatch) ...
target_compile_options(clang_rt.builtins PRIVATE ${BUILTIN_CFLAGS})

Explanation:

  1. foreach (SOURCE_FILE ${BUILTIN_SOURCES}): Iterates through each source file added to the clang_rt.builtins target.
  2. get_source_file_property(SOURCE_LANGUAGE ${SOURCE_FILE} LANGUAGE): Retrieves the language (C, CXX, ASM, etc.) that CMake has determined for the current source file. This is the most reliable way to identify the file type.
  3. if (SOURCE_LANGUAGE STREQUAL "C" OR SOURCE_LANGUAGE STREQUAL "CXX"): Checks if the source file is a C or C++ file.
  4. set_source_files_properties(${SOURCE_FILE} PROPERTIES COMPILE_FLAGS "-Werror=builtin-declaration-mismatch"): If the file is C or C++, this line adds the -Werror=builtin-declaration-mismatch flag directly to the source file's properties. This ensures the flag is used only when compiling that specific file.
  5. target_compile_options(clang_rt.builtins PRIVATE ${BUILTIN_CFLAGS}): This line is kept, as BUILTIN_CFLAGS might contain other necessary flags. However, the problematic flag is now applied per-source-file, so it's safe to leave this line as is (or you can clean it up further if you know exactly what other flags are needed).

Advantages of this approach:

  • Correctness: It correctly handles mixed C, C++, and assembly code within the same target.
  • Precision: It applies the flag only to the relevant files, avoiding unintended consequences.
  • Maintainability: It keeps the logic for adding this specific warning flag localized and easy to understand.
  • Avoids Global Changes: It doesn't modify global CMake variables like CMAKE_C_FLAGS, which could have broader, unintended effects.

I believe this solution addresses the root cause of the build failure while preserving the intended behavior of checking for builtin declaration mismatches in C/C++ code. Could you please review this analysis and proposed fix? I'm happy to provide a patch if this looks good.

Thanks!

@ms178
Copy link
Author

ms178 commented Feb 6, 2025

@arichardson Good news, I've tested this AI proposed approach which gets rid of the warnings, just exchange line 786 to line 926 of /compiler-rt/lib/builtins/CMakeLists.txt with the following instead:

add_custom_target(builtins)
set_target_properties(builtins PROPERTIES FOLDER "Compiler-RT/Metatargets")

option(COMPILER_RT_ENABLE_SOFTWARE_INT128
  "Enable the int128 builtin routines for all targets."
  OFF)

if (APPLE)
  add_subdirectory(Darwin-excludes)
  add_subdirectory(macho_embedded)
  darwin_add_builtin_libraries(${BUILTIN_SUPPORTED_OS})
else ()
  set(BUILTIN_CFLAGS "")
  add_security_warnings(BUILTIN_CFLAGS 0)

  if (COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
    append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
  endif()

  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)

  # Add -Werror=builtin-declaration-mismatch only for C/C++ source files.
  if (COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
    # Get the list of source files. We do this before and after add_library
    # to handle any changes made during the library creation.
    set(builtin_sources "")
    foreach(src ${BUILTIN_SOURCES} ${BUILTIN_I128_SOURCES} ${BUILTIN_TARGET_SOURCES})
      list(APPEND builtin_sources ${src})
    endforeach()
  endif()

  # Don't embed directives for picking any specific CRT
  if (MSVC)
    set(CMAKE_MSVC_RUNTIME_LIBRARY "")
    append_list_if(COMPILER_RT_HAS_ZL_FLAG /Zl BUILTIN_CFLAGS)
  endif()

  # These flags would normally be added to CMAKE_C_FLAGS by the llvm
  # cmake step. Add them manually if this is a standalone build.
  if(COMPILER_RT_STANDALONE_BUILD)
    if(COMPILER_RT_BUILTINS_ENABLE_PIC)
      append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC BUILTIN_CFLAGS)
    endif()
    append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin BUILTIN_CFLAGS)
    if(COMPILER_RT_BUILTINS_HIDE_SYMBOLS)
      append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG -fvisibility=hidden BUILTIN_CFLAGS)
    endif()
    if(NOT COMPILER_RT_DEBUG)
      append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fomit-frame-pointer BUILTIN_CFLAGS)
    endif()
  endif()

  # Directly targeting the GPU requires a few extra flags.
  if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx")
    append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding BUILTIN_CFLAGS)
    append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib BUILTIN_CFLAGS)
    append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto BUILTIN_CFLAGS)
    append_list_if(COMPILER_RT_HAS_FCONVERGENT_FUNCTIONS_FLAG
                   -fconvergent-functions BUILTIN_CFLAGS)

    # AMDGPU targets want to use a generic ABI.
    if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn")
      append_list_if(COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG
                     "SHELL:-Xclang -mcode-object-version=none" BUILTIN_CFLAGS)
    endif()
  endif()

  set(BUILTIN_DEFS "")

  if(COMPILER_RT_BUILTINS_HIDE_SYMBOLS)
    append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG VISIBILITY_HIDDEN BUILTIN_DEFS)
  endif()

  if(COMPILER_RT_DISABLE_AARCH64_FMV)
    list(APPEND BUILTIN_DEFS DISABLE_AARCH64_FMV)
  elseif(COMPILER_RT_BAREMETAL_BUILD)
    list(APPEND BUILTIN_DEFS ENABLE_BAREMETAL_AARCH64_FMV)
  endif()

  append_list_if(COMPILER_RT_HAS_ASM_LSE HAS_ASM_LSE BUILTIN_DEFS)

  foreach (arch ${BUILTIN_SUPPORTED_ARCH})
    if (CAN_TARGET_${arch})
      cmake_push_check_state()
      # TODO: we should probably make most of the checks in builtin-config depend on the target flags.
      set(BUILTIN_CFLAGS_${arch} ${BUILTIN_CFLAGS})
      # CMAKE_REQUIRED_FLAGS must be a space separated string but unlike TARGET_${arch}_CFLAGS,
      # BUILTIN_CFLAGS_${arch} is a CMake list, so we have to join it to create a valid command line.
      list(JOIN BUILTIN_CFLAGS " " CMAKE_REQUIRED_FLAGS)
      set(CMAKE_REQUIRED_FLAGS "${TARGET_${arch}_CFLAGS} ${BUILTIN_CFLAGS_${arch}}")
      message(STATUS "Performing additional configure checks with target flags: ${CMAKE_REQUIRED_FLAGS}")
      # For ARM archs, exclude any VFP builtins if VFP is not supported
      if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em|armv8m.main|armv8.1m.main)$")
        string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}")
        check_compile_definition(__ARM_FP "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP)
        if(NOT COMPILER_RT_HAS_${arch}_VFP)
          list(REMOVE_ITEM ${arch}_SOURCES ${arm_Thumb1_VFPv2_DP_SOURCES} ${arm_Thumb1_VFPv2_SP_SOURCES} ${arm_Thumb1_SjLj_EH_SOURCES})
        else()
          # Exclude any double-precision builtins if VFP is single-precision-only
          try_compile_only(COMPILER_RT_HAS_${arch}_VFP_DP
                           SOURCE "#if !(__ARM_FP & 0x8)
                                   #error No double-precision support!
                                   #endif
                                   int main(void) { return 0; }")
          if(NOT COMPILER_RT_HAS_${arch}_VFP_DP)
            list(REMOVE_ITEM ${arch}_SOURCES ${arm_Thumb1_VFPv2_DP_SOURCES})
          endif()
        endif()
      endif()
      check_c_source_compiles("_Float16 foo(_Float16 x) { return x; }
                               int main(void) { return 0; }"
                              COMPILER_RT_HAS_${arch}_FLOAT16)
      append_list_if(COMPILER_RT_HAS_${arch}_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS_${arch})
      check_c_source_compiles("__bf16 foo(__bf16 x) { return x; }
                               int main(void) { return 0; }"
                              COMPILER_RT_HAS_${arch}_BFLOAT16)
      # Build BF16 files only when "__bf16" is available.
      if(COMPILER_RT_HAS_${arch}_BFLOAT16)
        list(APPEND ${arch}_SOURCES ${BF16_SOURCES})
      endif()

      # Remove a generic C builtin when an arch-specific builtin is specified.
      filter_builtin_sources(${arch}_SOURCES ${arch})

      # Needed for clear_cache on debug mode, due to r7's usage in inline asm.
      # Release mode already sets it via -O2/3, Debug mode doesn't.
      if (${arch} STREQUAL "armhf")
        list(APPEND BUILTIN_CFLAGS_${arch} -fomit-frame-pointer -DCOMPILER_RT_ARMHF_TARGET)
      endif()

      # For RISCV32, we must force enable int128 for compiling long
      # double routines.
      if(COMPILER_RT_ENABLE_SOFTWARE_INT128 OR "${arch}" STREQUAL "riscv32")
        list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128)
      endif()

      add_compiler_rt_runtime(clang_rt.builtins
                              STATIC
                              ARCHS ${arch}
                              DEPS ${deps_${arch}}
                              SOURCES ${${arch}_SOURCES}
                              DEFS ${BUILTIN_DEFS}
                              CFLAGS ${BUILTIN_CFLAGS_${arch}}
                              PARENT_TARGET builtins)
      cmake_pop_check_state()
    endif ()
  endforeach ()
endif ()

add_dependencies(compiler-rt builtins)

Edit: It doesn't seem to be the correct fix according to Sam, I've also seen a huge compile time regression with it in subsequent builds.

@ms178
Copy link
Author

ms178 commented Feb 6, 2025

I've proposed a patch in: #125602 (comment)

@negril

This comment has been minimized.

@llvm llvm locked as too heated and limited conversation to collaborators Feb 7, 2025
@llvm llvm unlocked this conversation May 1, 2025
@ms178 ms178 closed this as completed May 10, 2025
@llvm llvm deleted a comment from ms178 May 13, 2025
@llvm llvm locked and limited conversation to collaborators May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cmake Build system in general and CMake in particular compiler-rt:builtins
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants