Skip to content
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

Add the needed bits for compiling with link-time optimization. #109

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

besser82
Copy link
Owner

@besser82 besser82 commented Aug 13, 2020

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.

@besser82 besser82 requested a review from zackw August 13, 2020 17:05
@codecov
Copy link

codecov bot commented Aug 13, 2020

Codecov Report

Merging #109 into develop will decrease coverage by 0.13%.
The diff coverage is n/a.

Impacted file tree graph

@@             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%) ⬇️
lib/crypt-des.c 91.13% <0.00%> (-0.79%) ⬇️
lib/crypt.c 95.16% <0.00%> (+0.11%) ⬆️

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.

@besser82 besser82 force-pushed the topic/besser82/lto branch from 3af8e8e to 13bf3f3 Compare August 13, 2020 19:23
Copy link
Collaborator

@zackw zackw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@besser82 besser82 force-pushed the topic/besser82/lto branch from 13bf3f3 to a3c3066 Compare August 13, 2020 21:39
@besser82
Copy link
Owner Author

besser82 commented Aug 13, 2020

@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.

@besser82 besser82 requested a review from zackw August 13, 2020 21:42
@besser82 besser82 force-pushed the topic/besser82/lto branch 16 times, most recently from 877603d to 3055b52 Compare August 15, 2020 10:06
@besser82
Copy link
Owner Author

@zackw Tested and works with GCC 10.2, LTO enabled: https://koji.fedoraproject.org/koji/buildinfo?buildID=1593132

@besser82
Copy link
Owner Author

@zackw Would you mind to have another look here?

@besser82 besser82 force-pushed the topic/besser82/lto branch from 3055b52 to 2e443c5 Compare August 18, 2020 14:24
@solardiz
Copy link
Collaborator

Before merging this, would anyone please comment on the concerns I brought up in #24 (comment)

Copy link
Collaborator

@zackw zackw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

lib/crypt-port.h Outdated Show resolved Hide resolved
libxcrypt.spec.rpkg Show resolved Hide resolved
@zackw
Copy link
Collaborator

zackw commented Aug 18, 2020

Also, just to verify, the xcrypt_symbol annotations are no longer necessary with this version of the patch?

@besser82
Copy link
Owner Author

Also, just to verify, the xcrypt_symbol annotations are no longer necessary with this version of the patch?

Yes, that's correct.

@zackw
Copy link
Collaborator

zackw commented Aug 18, 2020

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.

@besser82
Copy link
Owner Author

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.

@besser82 besser82 force-pushed the topic/besser82/lto branch from 2e443c5 to 78ca901 Compare August 18, 2020 17:24
@solardiz
Copy link
Collaborator

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.

@besser82 besser82 force-pushed the topic/besser82/lto branch from 78ca901 to f4c22e8 Compare August 18, 2020 18:21
GCC 10 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, 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.
This reverts commit 328563b.
@besser82 besser82 force-pushed the topic/besser82/lto branch from f4c22e8 to cbf3d3a Compare August 18, 2020 18:37
@besser82 besser82 force-pushed the topic/besser82/lto branch from cbf3d3a to 6a2a314 Compare August 18, 2020 18:47
@besser82
Copy link
Owner Author

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 1
           

See the complete overview on Codacy

README.md Show resolved Hide resolved
@zackw
Copy link
Collaborator

zackw commented Aug 18, 2020

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 :-(

@besser82
Copy link
Owner Author

@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…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lto linking, missing symbols
3 participants