[all-commits] [llvm/llvm-project] dd647e: Rework the `Option` library to reduce dynamic relo...

Chandler Carruth via All-commits all-commits at lists.llvm.org
Wed Dec 11 15:45:07 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: dd647e3e608ed0b2bac7c588d5859b80ef4a5976
      https://github.com/llvm/llvm-project/commit/dd647e3e608ed0b2bac7c588d5859b80ef4a5976
  Author: Chandler Carruth <chandlerc at gmail.com>
  Date:   2024-12-11 (Wed, 11 Dec 2024)

  Changed paths:
    M clang-tools-extra/clangd/CompileCommands.cpp
    M clang/lib/Driver/DriverOptions.cpp
    M clang/lib/Frontend/CompilerInvocation.cpp
    M clang/tools/clang-installapi/Options.cpp
    M clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
    M clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
    M clang/tools/clang-scan-deps/ClangScanDeps.cpp
    M clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
    M lld/COFF/DriverUtils.cpp
    M lld/ELF/DriverUtils.cpp
    M lld/MachO/DriverUtils.cpp
    M lld/MinGW/Driver.cpp
    M lld/wasm/Driver.cpp
    M lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    M lldb/tools/driver/Driver.cpp
    M lldb/tools/lldb-dap/lldb-dap.cpp
    M lldb/tools/lldb-server/lldb-gdbserver.cpp
    M llvm/include/llvm/Option/OptTable.h
    M llvm/include/llvm/Option/Option.h
    M llvm/lib/ExecutionEngine/JITLink/COFFDirectiveParser.cpp
    M llvm/lib/Option/OptTable.cpp
    M llvm/lib/Option/Option.cpp
    M llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
    M llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
    M llvm/tools/dsymutil/dsymutil.cpp
    M llvm/tools/llvm-cgdata/llvm-cgdata.cpp
    M llvm/tools/llvm-cvtres/llvm-cvtres.cpp
    M llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
    M llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
    M llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
    M llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
    M llvm/tools/llvm-dwp/llvm-dwp.cpp
    M llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
    M llvm/tools/llvm-ifs/llvm-ifs.cpp
    M llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
    M llvm/tools/llvm-lipo/llvm-lipo.cpp
    M llvm/tools/llvm-ml/llvm-ml.cpp
    M llvm/tools/llvm-mt/llvm-mt.cpp
    M llvm/tools/llvm-nm/llvm-nm.cpp
    M llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
    M llvm/tools/llvm-objdump/llvm-objdump.cpp
    M llvm/tools/llvm-rc/llvm-rc.cpp
    M llvm/tools/llvm-readobj/llvm-readobj.cpp
    M llvm/tools/llvm-readtapi/llvm-readtapi.cpp
    M llvm/tools/llvm-size/llvm-size.cpp
    M llvm/tools/llvm-strings/llvm-strings.cpp
    M llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
    M llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
    M llvm/tools/sancov/sancov.cpp
    M llvm/unittests/Option/OptionMarshallingTest.cpp
    M llvm/unittests/Option/OptionParsingTest.cpp
    M llvm/utils/TableGen/OptionParserEmitter.cpp

  Log Message:
  -----------
  Rework the `Option` library to reduce dynamic relocations (#119198)

Apologies for the large change, I looked for ways to break this up and
all of the ones I saw added real complexity. This change focuses on the
option's prefixed names and the array of prefixes. These are present in
every option and the dominant source of dynamic relocations for PIE or
PIC users of LLVM and Clang tooling. In some cases, 100s or 1000s of
them for the Clang driver which has a huge number of options.

This PR addresses this by building a string table and a prefixes table
that can be referenced with indices rather than pointers that require
dynamic relocations. This removes almost 7k dynmaic relocations from the
`clang` binary, roughly 8% of the remaining dynmaic relocations outside
of vtables. For busy-boxing use cases where many different option tables
are linked into the same binary, the savings add up a bit more.

The string table is a straightforward mechanism, but the prefixes
required some subtlety. They are encoded in a Pascal-string fashion with
a size followed by a sequence of offsets. This works relatively well for
the small realistic prefixes arrays in use.

Lots of code has to change in order to land this though: both all the
option library code has to be updated to use the string table and
prefixes table, and all the users of the options library have to be
updated to correctly instantiate the objects.

Some follow-up patches in the works to provide an abstraction for this
style of code, and to start using the same technique for some of the
other strings here now that the infrastructure is in place.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list