Bug 1956484

Summary: Build libLLVM.so and libclang-cpp.so with -fno-semantic-interposition and -Bsymbolic-functions
Product: [Fedora] Fedora Reporter: Fangrui Song <i>
Component: clangAssignee: Tom Stellard <tstellar>
Status: CLOSED UPSTREAM QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 34CC: airlied, nick.desaulniers, sbergman, sguelton, siddharth.kde, tstellar
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-06-06 03:53:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Fangrui Song 2021-05-03 18:50:13 UTC
[I am not a Fedora user; I just read the build file and made the suggestion]

As I mentioned on "Re: Very slow clang kernel config .." (https://lore.kernel.org/lkml/20210501235549.vugtjeb7dmd5xell@google.com/),
the llvm and clang builds can use -Wl,-Bsymbolic-functions to improve performance.
The performance of the built clang will be comparable to a mostly statically linked (libLLVM*.a libclang*.a) PIE clang, as evidenced by my few runs building x86_64 defconfig 'vmlinux' (-j 40):

# the compile flags may be very different from the clang builds below.
system gcc; LLVM=
     1050.15s user 192.96s system 3015% cpu   41.219 total
     1055.47s user 196.51s system 3022% cpu   41.424 total

clang (libLLVM*.a libclang*.a); LLVM=1
    1588.35s user 193.02s system 3223% cpu   55.259 total
    1613.59s user 193.22s system 3234% cpu   55.861 total
clang (libLLVM.so libclang-cpp.so); LLVM=1
    1870.07s user 222.86s system 3256% cpu 1:04.26 total
    1863.26s user 220.59s system 3219% cpu 1:04.73 total
    1877.79s user 223.98s system 3233% cpu 1:05.00 total
    1859.32s user 221.96s system 3241% cpu 1:04.20 total
clang (libLLVM.so libclang-cpp.so -fno-semantic-interposition); LLVM=1
    1810.47s user 222.98s system 3288% cpu 1:01.83 total
    1790.46s user 219.65s system 3227% cpu 1:02.27 total
    1796.46s user 220.88s system 3139% cpu 1:04.25 total
    1796.55s user 221.28s system 3215% cpu 1:02.75 total
clang (libLLVM.so libclang-cpp.so -fno-semantic-interposition -Wl,-Bsymbolic); LLVM=1
    1608.75s user 221.39s system 3192% cpu   57.333 total
    1607.85s user 220.60s system 3205% cpu   57.042 total
    1598.64s user 191.21s system 3208% cpu   55.778 total
clang (libLLVM.so libclang-cpp.so -fno-semantic-interposition -Wl,-Bsymbolic-functions); LLVM=1
    1617.35s user 220.54s system 3217% cpu   57.115 total


-fno-semantic-interposition can avoid some GOT (on x86-64 the optimization is partially covered by R_X86_64_{REX_,}GOTPCRELX)
(in clang, access to external linkage default visibility non-comdat definition in the same translation unit).
As of gcc 11 and clang 12, this option is a no-op on non-x86, but compilers may improve for other architectures in the future.


-Bsymbolic is less safe because it can break interaction with copy relocations (https://maskray.me/blog/2021-01-09-copy-relocations-canonical-plt-entries-and-protected).

Comment 1 Fangrui Song 2021-06-06 03:53:40 UTC
Upstream uses -fno-semantic-interposition and -Bsymbolic-functions by default now. Closing.