IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    My involvement with LLVM 19

    MaskRay发表于 2024-08-19 06:17:21
    love 0

    LLVM 19 will soon be released. This post provides a summary of mycontributions in this release cycle to record my learning progress.

    • LLVM MC: Integratedassembler improvements in LLVM 19
    • lld/ELF: lld 19 ELFchanges
    • AArch64
      • [AArch64]Implement -fno-plt for SelectionDAG/GlobalISel
      • [AArch64]Support optional constant offset for constraint "S"
      • [AArch64AsmParser]Allow branch target symbol to have a shift/extend modifier name
      • [MC,AArch64]Create mapping symbols with non-unique names
    • ARM
      • [ARM,MC]Support FDPIC relocations. See MMU-less systems andFDPIC
    • RISC-V
      • [RISCV]Support constraint "s"
      • [MC,RISCV]Create mapping symbols with non-unique names
    • sanitizers
      • [ubsan]Support static linking with standalone runtime
      • [sanitizer]Reject unsupported -static at link time
      • __asan_register_elf_globals:properly check the "no instrumented global variable" case
      • [asan,test]Disable _FORTIFY_SOURCE test incompatible with glibc 2.40

    LLVM binary utilities

    • [llvm-readobj,ELF]Support --decompress/-z
    • [llvm-objcopy]Improve help messages
    • [llvm-readelf]Print a blank line for the first hex/string dump
    • [llvm-objcopy]Add --compress-sections
    • [llvm-readelf]Print more information for RELR

    Hashing

    I optimized the bit mixer used byllvm::DenseMap<std::pair<X, Y>> andllvm::DenseMap<std::tuple<X...>>.llvm/ADT/Hashing.h, used by StringRef hashingand DenseMap, was supposed to be non-deterministic. Despitethis, a lot of code relied on a specific iteration order. I mademultiple fixes across the code base and landed [Hashing] Use anon-deterministic seed if LLVM_ENABLE_ABI_BREAKING_CHECKS to improvetest coverage (e.g. assertion builds) and ensure future flexibility toreplace the algorithm.

    The change has a noticeable code size reduction

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # old
    movq _ZN4llvm7hashing6detail19fixed_seed_overrideE@GOTPCREL(%rip), %rax
    movq (%rax), %rax
    testq %rax, %rax
    movabsq $-49064778989728563, %rcx # imm = 0xFF51AFD7ED558CCD
    cmoveq %rcx, %rax

    # new
    movabsq $-49064778989728563, %rcx

    ... and significantcompile time improvement.

    I optimizedDenseMap::{find,erase}, yielding compile timeimprovement.

    The significant code size decrease from replacing Hashing.h bit mixerand simplifying/optimizing DenseMap code highlightspotential implementation challenges. While boost::unordered_flat_map,Abseil's Swiss Table, and Folly's F14 are likely faster, they couldincrease the code size significantly.

    NumericalStabilitySanitizer

    NumericalStabilitySanitizer is a new feature for the 19.x releases. Ihave made many changes on the compiler-rt part.

    Clang

    Driver maintenance

    • [Driver]Ensure ToolChain::LibraryPaths is not empty for non-Darwin
    • [Driver] Support -Wa,--defsym similar to -Wa,-defsym.
    • [Driver]Don't default to -mrelax-all for non-RISCV -O0. See Clang's-O0 output: branch displacement and size increase

    Options used by the LLVM integrated assembler are currently handledin an ad-hoc way. There is deduplication with and without LTO.Eventually we might want to adopt TableGen for these -Wa,options.

    Others:

    • [Sema]-Wpointer-bool-conversion: suppress lambda function pointer conversiondiagnostic during instantiation
    • [Sema]Mark alias/ifunc targets used and consider mangled names. This patchreceived a lot of scrutiny because it fixed an issue reported the XZbackdoor author(s).
    • Makediagnostic pragma override -Werror=foo and DefaultErrorwarnings
    • Many patches migrated code off from potentially non-deterministicllvm/ADT/Hashing.h
    • [CodeGen]Set attributes on resolvers emitted after ifuncs

    Code review

    I reviewed a wide range of patches, including areas like ADT/Support,binary utilities, MC, lld, clangDriver, LTO, sanitizers, LoongArch,RISC-V, and new features like NumericalStabilitySanitizer andRealTimeSanitizer.

    To quantify my involvement, a search for patches I commented on(repo:llvm/llvm-project is:pr -author:MaskRay commenter:MaskRay created:>2024-01-23)yields 780 results.



沪ICP备19023445号-2号
友情链接