Add the needed bits for compiling with link-time optimization. #109
Codecov Report
Merging #109 into develop will decrease coverage by 0.13%.The diff coverage is n/a.
@@ Coverage Diff @@
## develop #109 +/- ##
===========================================
- Coverage 94.48% 94.34% -0.14%
===========================================
Files 32 32
Lines 3750 3764 +14
===========================================
+ Hits 3543 3551 +8
- Misses 207 213 +6
| Impacted Files | Coverage Δ | |
|---|---|---|
| lib/crypt-yescrypt.c | 82.00% <0.00%> (-6.64%) | :arrow_down: |
| lib/crypt-des.c | 91.13% <0.00%> (-0.79%) | :arrow_down: |
| lib/crypt.c | 95.16% <0.00%> (+0.11%) | :arrow_up: |
------
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update 328563b...2e443c5. Read the comment docs.
Is this really enough to make it work? I was under the impression we needed __attribute__ ((symver)) as well (see GCC bug 48200).
Why is it necessary to use -flto-partition=none?
I was under the impression one ought to set AR, CC, NM, RANLIB, and CFLAGS as arguments to configure, e.g.
./configure CC="gcc" AR="gcc-ar" NM="gcc-nm" RANLIB="gcc-ranlib" CFLAGS="-g -O2 -flto -flto-partition=none" ...
The change to use ${NM-nm} in test/symbols-*.sh is approved independent of the rest of the patch, please go ahead and push it separately.
@zackw I've fixed your concerns in the rebased commits.
Is this really enough to make it work? I was under the impression we needed __attribute__ ((symver)) as well (see GCC bug 48200).
For LLVM/Clang it simply works that way. For GCC 10.2 one either needs to implement __attribute__ ((symver)) for symbol versioning, or pass -flto -flto-partition=none to skip automatic partitioning of the symbol table, resolved by the linker, which would drop all exported versioned symbols not used by the library itself.
Why is it necessary to use -flto-partition=none?
This is necessary, if one does NOT use __attribute__ ((symver)) with GCC and LTO enabled; see above.
Anyways, my rebased commits use the new symver attribute with GCC 10.2. LLVM/Clang doesn't support it nor needs it.
@zackw Tested and works with GCC 10.2, LTO enabled: https://koji.fedoraproject.org/koji/buildinfo?buildID=1593132
@zackw Would you mind to have another look here?
Before merging this, would anyone please comment on the concerns I brought up in https://github.com/besser82/libxcrypt/issues/24#issuecomment-674139907
The order of operations here briefly confused me into thinking the #if conditional was backward. Can you please rearrange it like this?
#if __GNUC__ > 10 || (__GNUC__ == 10 && __GNUC_MINOR__ >= 2)
/* Starting with GCC 10.2, we can use the symver attribute to define symbol versions.
This has the advantage of working correctly with link-time optimization. */
/* Set the symbol version for EXTSTR, which uses INTNAME as its
implementation. */
# define symver_set(extstr, intname, version, mode) // ...
/* Referencing specific _compatibility_ symbols still needs inline asm. */
# define _symver_ref(extstr, intname, version) // ...
Per @solardiz's concerns, let's _not_ do this yet. Instead maybe just change the comment to "The library can be built with LTO using GCC >=10.2, but this mode is still experimental and not recommended for production."
I have to say I share @solardiz's concerns about exposing latent UB. I would be okay with merging the changes to crypt-port.h, documenting that an LTO-using build is now possible but _experimental_ and discouraged for production use, ~~and not changing libxcrypt.spec.rpkg yet.~~ [never mind that last bit, I thought it was the spec for what actually goes into Fedora]
If we made the configure script detect LTO and force --disable-obsolete-api when it did, do you think that would be sufficient to "ensure that build wouldn't be inadvertently usable in production", @solardiz ?
Also, just to verify, the xcrypt_symbol annotations are no longer necessary with this version of the patch?
Well, the purpose of this file is to build a new rpm from each commit to develop explicitly for testing. See: https://copr.fedorainfracloud.org/coprs/besser82/libxcrypt_CI/
Those builds need an explicit activation by the user and are otherwise NOT installed nor propagated to production enviroments.
Also, just to verify, the xcrypt_symbol annotations are no longer necessary with this version of the patch?
Yes, that's correct.
Oh, OK. I thought this was the spec file used for the builds actually going into Fedora. I retract this comment.
Will update this with the next rebase.
Can we get a CI build with all hashes enabled, LTO on, and ASan+UBSan also on? That would be a quick way to get _some_ more confidence that the code is UB-sound.
Can we get a CI build with all hashes enabled, LTO on, and ASan+UBSan also on? That would be a quick way to get _some_ more confidence that the code is UB-sound.
I will check if that's possible. We LLVM / Clang >= 7 on Travis for this. Or is this possible with GCC as well? We can use Fedora >= 32 to do it, if GCC supports that as well.
If we made the configure script detect LTO and force --disable-obsolete-api when it did, do you think that would be sufficient to "ensure that build wouldn't be inadvertently usable in production", @solardiz ?
I think that would be weird - mixing unrelated things together, and excluding the obsolete APIs from our own LTO stress-testing. If we do use LTO for stress-testing, let's use the opportunity fully.
Codacy found an issue: [[fenced-code-flag] Missing code language flag](https://app.codacy.com/manual/besser82/libxcrypt/pullRequest?prid=6010975)
Every time you force-push this branch, I get multiple emails from Codacy about the missing syntax-highlighting annotation in the README. It's making it hard for me to tell what actually changed :-(
@zackw For some funny reason I can even reproduce the errors shown on TravisCI with GCC 10.2 + ASan,UBSan without LTO enabled… :S
The other funny thing is: If I replace crypt_r with crypt_rn in test/special-char-salt.c the tests succeeds…
zackw
besser82
GCC 10.2 and LLVM/Clang 10 offer initial support for building libraries, that are using symbol versioning features, with LTO.
To make use of this with GCC 10.2, the exported versioned symbols need to be declared explicitly with
__attribute__((symver (...))).LLVM/Clang 10 supports symbol versioning with LTO out of the box without any changes needed.
Fixes #24.