Bug 228865

Summary: Adding missing REFERENCED_FROM_ASM annotations to facilitate LTO
Product: WebKit Reporter: Michael Catanzaro <mcatanzaro>
Component: JavaScriptCoreAssignee: Michael Catanzaro <mcatanzaro>
Status: RESOLVED FIXED    
Severity: Normal CC: aperez, bugs-noreply, ews-watchlist, keith_miller, kloczko.tomasz, mark.lam, mcatanzaro, mgorse, msaboff, saam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: PC   
OS: Linux   
See Also: https://bugzilla.redhat.com/show_bug.cgi?id=1990111
Attachments:
Description Flags
Patch none

Description Michael Catanzaro 2021-08-06 09:21:06 PDT
When investigating why WebKitGTK fails to build with LTO (link-time optimization) enabled, one of the GCC developers noticed that we are missing __attribute__ (("used")) on several C++ functions declared in LLIntSlowPaths.h and WasmSlowPaths.h that are called only from asm. Without this attribute, GCC assumes the functions are unused and drops them, then linking fails because they really are used.

Turns out, this is the *only* problem that prevents building WebKit with LTO, so this patch should allow distros like Fedora and SUSE to drop downstream workarounds to turn off LTO.

To test building with LTO, I used -DCMAKE_C_FLAGS="-flto=auto -ffat-lto-objects" -DCMAKE_CXX_FLAGS="-flto=auto -ffat-lto-objects" with GCC. Note that is GCC-specific. Clang uses "-flto" instead, simpler.
Comment 1 Michael Catanzaro 2021-08-06 09:24:33 PDT
(In reply to Michael Catanzaro from comment #0)
> Turns out, this is the *only* problem that prevents building WebKit with
> LTO, so this patch should allow distros like Fedora and SUSE to drop
> downstream workarounds to turn off LTO.

Oh, well I'm actually getting an ld.gold internal error as well. Workaround for that is -DUSE_LD_GOLD=OFF. We might want to get rid of ld.gold anyway since it's no longer well-maintained.
Comment 2 Michael Catanzaro 2021-08-06 09:28:19 PDT
Created attachment 435072 [details]
Patch
Comment 3 Adrian Perez 2021-08-09 00:36:48 PDT
Comment on attachment 435072 [details]
Patch

Nice find. I think the patch is correct 😉
Comment 4 Yusuke Suzuki 2021-08-09 00:46:00 PDT
Comment on attachment 435072 [details]
Patch

r=me
Comment 5 EWS 2021-08-09 03:53:12 PDT
Committed r280770 (240354@main): <https://commits.webkit.org/240354@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 435072 [details].
Comment 6 Radar WebKit Bug Importer 2021-08-09 03:54:17 PDT
<rdar://problem/81689158>
Comment 7 Michael Catanzaro 2021-08-12 13:08:26 PDT
(In reply to Michael Catanzaro from comment #0)
> To test building with LTO, I used -DCMAKE_C_FLAGS="-flto=auto
> -ffat-lto-objects" -DCMAKE_CXX_FLAGS="-flto=auto -ffat-lto-objects" with
> GCC. Note that is GCC-specific. Clang uses "-flto" instead, simpler.

Correction: according to https://fedoraproject.org/wiki/Changes/LTOBuildImprovements#Detailed_Description actually do not want to use -ffat-lto-objects because we don't install any .o or .a files. Huh.
Comment 8 Michael Catanzaro 2021-08-23 12:35:39 PDT
*** Bug 202346 has been marked as a duplicate of this bug. ***