[all-commits] [llvm/llvm-project] bef829: [XRay] Make xray_instr_map compatible with Mach-O

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu Jun 22 10:03:31 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bef8294650f0119238830d73a7527023c7c8a97f
      https://github.com/llvm/llvm-project/commit/bef8294650f0119238830d73a7527023c7c8a97f
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-06-22 (Thu, 22 Jun 2023)

  Changed paths:
    M llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    M llvm/test/CodeGen/AArch64/xray-attribute-instrumentation.ll
    M llvm/test/CodeGen/AArch64/xray-omit-function-index.ll
    M llvm/test/CodeGen/AArch64/xray-partial-instrumentation-skip-entry.ll
    M llvm/test/CodeGen/AArch64/xray-partial-instrumentation-skip-exit.ll
    M llvm/test/CodeGen/AArch64/xray-tail-call-sled.ll
    M llvm/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll
    M llvm/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll
    M llvm/test/CodeGen/X86/xray-attribute-instrumentation.ll
    M llvm/test/CodeGen/X86/xray-log-args.ll
    M llvm/test/CodeGen/X86/xray-partial-instrumentation-skip-entry.ll
    M llvm/test/CodeGen/X86/xray-partial-instrumentation-skip-exit.ll
    M llvm/test/CodeGen/X86/xray-tail-call-sled.ll

  Log Message:
  -----------
  [XRay] Make xray_instr_map compatible with Mach-O

The `__DATA,xray_instr_map` section has label differences like
`.quad Lxray_sled_0-Ltmp0` that is represented as a pair of UNSIGNED and SUBTRACTOR relocations.

LLVM integrated assembler attempts to rewrite A-B into A-B'+offset where B' can
be included in the symbol table. B' is called an atom and should be a
non-temporary symbol in the same section. However, since `xray_instr_map` does
not define a non-temporary symbol, the SUBTRACTOR relocation will have no
associated symbol, and its `r_extern` value will be 0. Therefore, we will see
linker errors like:

    error: SUBTRACTOR relocation must be extern at offset 0 of __DATA,xray_instr_map in a.o

To fix this issue, we need to define a non-temporary symbol in the section. We
can accomplish this by renaming `Lxray_sleds_start0` to `lxray_sleds_start0`
("L" to "l").

`lxray_sleds_start0` serves as the atom for this dead-strippable subsection.
With the `S_ATTR_LIVE_SUPPORT` attribute, `ld -dead_strip` will retain
subsections that reference live functions.

Special thanks to Oleksii Lozovskyi for reporting the issue and providing
initial analysis.

Differential Revision: https://reviews.llvm.org/D153239




More information about the All-commits mailing list