一如既往,主要在工具链领域耕耘。
Highlights
- RELR relative relocation format (glibc, musl, DynamoRIO)
- zstd compressed debug sections (binutils, gdb, clang, lld/ELF, lldb)
- lld/ELF (huge performance improvement, RISC-V linker relaxation,
SHT_RISCV_ATTRIBUTES) - Clang built glibc (get the ball rolling)
- Make protected symbols work in binutils/glibc
- Involved in sanitizers, ThinLTO, AArch64/x86 hardening features, AArch64 Memtag ABI, RISC-V psABI, etc
RELR relative relocation format
- (In 2021-10, upstreamed
DT_RELRpatch to FreeBSD rtld-elf) - In April, upstreamed
DT_RELRpatch to glibc (highlighted feature for the 2.36 release) - In August, upstreamed
DT_RELRpatch to musl (milestone: 1.2.4) - Upstreamed
DT_RELRpatch to DynamoRIO - Contributed an unmerged gold patch
zstd compressed debug sections
- Added zstd support to gas, ld.bfd, gold, gdb, objcopy, readelf, objdump, addr2line, etc
- Added zstd support to clang, ld.lld, lldb, llvm-objcopy, llvm-symbolizer, llvm-dwarfdump, etc
zstd compressed debug sections
lld/ELF
RISC-V
陈枝懋 added initial RISC-V support for non-PIC in 2018. I added PIC and TLS support in 2019. The port was mature but linker relaxation was the last main piece to bring feature parity with GNU ld. This year I
- Implemented RISC-V linker relaxation
- Implemented
SHT_RISCV_ATTRIBUTESmerge support which has a niche value - Implemented
DT_RISCV_VARIANT_CC
RISC-V linker relaxation in lld
Performance
I spent some weekends improving the performance of lld/ELF this year. Let's compare an lld 13 built with latest Clang (/tmp/out/custom0/bin/lld) with latest lld built with latest Clang (/tmp/out/custom2/bin/lld).
Link a -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=on build of clang 16:
1 | lld 13: Time (mean ± σ): 687.1 ms ± 7.1 ms [User: 642.6 ms, System: 431.7 ms] |
Link a -DCMAKE_BUILD_TYPE=Debug build of clang 16:
1 | lld 13: Time (mean ± σ): 4.494 s ± 0.039 s [User: 7.516 s, System: 2.909 s] |
- Improve internal representation and optimize passes
- Parallelize section and local symbol initialization
- Parallelize relocation scanning
- Parallelize writes of different output sections
- Process archives as flattened
--start-librelocatable files (avoid memory accesses to archive symbol tables) - Parallelize
--compress-debug-sections=zlib
See lld 14 ELF changes and lld 15 ELF changes for detail. As usual, I wrote release notes for the two releases.
Clang built glibc (get the ball rolling)
glibc is probably the most prominent OSS which cannot be built with Clang yet. I sent some patches last year and made a few this year. See my notes from the last year: When can glibc be built with Clang?
This year Adhemerval Zanella from Linaro maintained a local branch to fix aarch64/i386/x86_64 builds. I reviewed some of his patches.
It seems that such work will benefit some research projects. For example, Intel FineIBT used a GRTE branch of glibc.
llvm-project
- C++/ObjC++: switch to gnu++17 as the default standard (fixed many tests)
--gcc-install-dir=: useclang++ --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/12to use the selected GCC installation directory- Defaulted to
-fsanitize-address-use-odr-indicator - Fixed a long-term bug related to local linkage
GlobalValuein non-prevailing COMDAT, exposed in (Thin)LTO+PGO - Helped some opaque pointers migration
- Helped legacy pass manager deprecation
Reviewed many commits. A lot of people don't add a Reviewed By: tag. Anyway, counting commits with the tag can give an underestimate.
1 | % git shortlog -sn bfc8f76e60a8efd920dbd6efc4467ffb6de15919.. --grep 'Reviewed .*MaskRay' | awk '{s+=$1}END{print s}' |
binutils
Reported many bugs and feature requests:
ar: Add --thin to avoid 'T' conflict with X/Open System Interfaceld: Make --compress-debug-sections=zlib parallelld: Customize output section typear: add 'L' modifier as a shortcut for ADDLIBgold: --no-define-common is incompatible with GNU ldld: `not found for insert` error has a weird orderingobjcopy --weaken-symbol does not weaken STB_GNU_UNIQUE symbolsgas: .set should copy st_size only if src's st_size is unsetgas: -gsomething-not-already-a-long-option does not get a diagnosticnm: add --no-weakld: ENTRY(no_such_symbol) in -shared mode does not report a warningbuild failures with make --shuffle -j Nbinutils: support zstd for SHF_COMPRESSED debug sectionsld ppc64: unneeded R_PPC64_NONE in .rela.dyn when linking Linux vdsogdb: support zstd for SHF_COMPRESSED debug sectionselfutils: support zstd for SHF_COMPRESSED debug sectionsobjdump -p considers an empty .gnu.version_r invalidgdb: support zstd compressed .gnu_debugdatareadelf: support zstd for SHF_COMPRESSED debug sectionsgold, dwp: support zstd for SHF_COMPRESSED debug sectionsld: add -w to suppress warningsld x86: -r should not define _TLS_MODULE_BASE_ld riscv: undefined elf_backend_obj_attrs_handle_unknown causes segfault when merging .riscv.attributesobjdump: add --show-all-symbols
My commits:
ar: Add --thin for creating thin archivesld: Support customized output section typeobjcopy --weaken-symbol: apply to STB_GNU_UNIQUE symbolsgas: copy st_size only if unsetgas: Port "copy st_size only if unset" to aarch64 and riscvaarch64: Disallow copy relocations on protected dataaarch64: Define elf_backend_extern_protected_data to 0 [PR 18705]aarch64: Allow PC-relative relocations against protected STT_FUNC for -sharedarm: Define elf_backend_extern_protected_data to 0 [PR 18705]x86: Make protected symbols local for -sharedRISC-V: Remove R_RISCV_GNU_VTINHERIT/R_RISCV_GNU_VTENTRYbinutils, gdb: support zstd compressed debug sectionslibctf: Add ZSTD_LIBS to LIBS so that ac_cv_libctf_bfd_elf can be truesim: Link ZSTD_LIBSld: Add --undefined-versionreadelf: support zstd compressed debug sections [PR 29640]gold, dwp: support zstd compressed input debug sections [PR 29641]gold: add --compress-debug-sections=zstd [PR 29641]
glibc
27 commits. Some work on the dynamic loader. Notable commits:
elf: Support DT_RELR relative relocation format [BZ #27924]elf: Replace PI_STATIC_AND_HIDDEN with opposite HIDDEN_VAR_NEEDS_DYNAMIC_RELOCelf: Refine direct extern access diagnostics to protected symbolelf: Remove ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA
Linux kernel
4 commits. Fixed linux-perf when unwinding ld.lld linked objects. Consulted on a number of toolchain questions.
Blog
Wrote 25 blog posts (including this one).
Misc
Added as a collaborator of riscv-non-isa/riscv-elf-psabi-doc.
Trips: Tucson, Greater Los Angeles, Cambridge and Boston, Denver, San Diego, Bellevue and Seattle, Kalispell, Washington, Honolulu.
Mastodon: https://hachyderm.io/@meowray