1. Sep 24, 2021
  2. Sep 18, 2021
    • Maksim Panchenko's avatar
      [BOLT][DWARF] Write new .debug_abbrev sections · 4d5cd1bf
      Maksim Panchenko authored
      Summary:
      Instead of patching the original .debug_abbrev section contents,
      generate new section data based on parsed compilation unit
      abbreviations.
      
      This eliminates the dependency on the LLVM extension that records
      abbreviation attribute offsets while parsing .debug_abbrev contents.
      
      The output with this patch should stay the same (NFC).
      
      (cherry picked from FBD31133611)
      4d5cd1bf
  3. Sep 23, 2021
  4. Sep 08, 2021
    • Vladislav Khmelevsky's avatar
      [PR] AArch64: Skip some of the relocations processing · 00c0659b
      Vladislav Khmelevsky authored
      Summary:
      There are some cases, when relocations must not be processed by bolt.
      This patch handles three of such cases:
      * The linker might eliminate the instruction and replace it with NOP
      * The linker might perform TLS relocations relaxations, replacing the
      got to direct TP + offset access.
      * Due to errata 843419 the linker might create a veneer, replacing the
      load/store instruction with branching.
      
      In both cases linker leaves old relocations, that are no longer matches
      the instruction emmited to binary, so we must avoid processing of these
      relocations.
      
      Vladislav Khmelevsky,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD31002384)
      00c0659b
  5. Sep 03, 2021
    • Vladislav Khmelevsky's avatar
      [PR] Fix aarch64 TLS relocations handling · 542c03c3
      Vladislav Khmelevsky authored
      Summary:
      There are few problems found when dealing with TLS relocations for
      aarch64.
      
      * RewriteInstance.cpp
      ** While analyzing TLS relocation we don't have to modify
      SymbolAddress (which is the offset from the TLS section), so we need to
      just skip verifiction
      ** The non-got related TLS relocations on aarch64 might be skipped too
      ** The forse relocation must be applied for GOT relocations on
      Aarch64. The symbol adress for GOT relocation might no be pointing
      on GOT section (for example ADRP GOT may point to the wrong section,
      since GOT table is not page-aligned), so we won't try to get section by
      the symbol address.
      
      * Relocation.cpp - Remove R_AARCH64_TLSLE_ADD_TPREL_HI12 and
      R_AARCH64_TLSLE_ADD_TPREL_LO12_NC from isGOT check, since they are not
      got-related relocations
      
      * BinaryFunction.h
      ** Remove R_AARCH64_TLSLE_ADD_TPREL_HI12 and
      R_AARCH64_TLSLE_ADD_TPREL_LO12_NC from adding to relocation list, since
      this is actually an offset in TLS section and BOLT does not change it we
      don't need to do something with this relocations, the value won't change
      in new binary files
      ** Refactor the code, separating aarch64 and x86 relocations
      
      * AArch64MCPlusBuilder.cpp
      ** Add forgotten LO12 relocations to switch case to getTargetExprFor
      
      Vladislav Khmelevsky,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD31003349)
      542c03c3
  6. Sep 22, 2021
    • Maksim Panchenko's avatar
      [BOLT] Fix warnings from LLVM DWARF reading library · 48fbeb1a
      Maksim Panchenko authored
      Summary:
      LLVM started printing warnings when DWARFDebugInfoEntry::extractFast()
      is invoked trying to read a DIE past the current unit limits. This
      results in verbose warnings from BOLT which are harmless but confusing
      to the user. Check the boundaries before calling the API above.
      
      (cherry picked from FBD31097271)
      48fbeb1a
  7. Sep 21, 2021
  8. Sep 16, 2021
    • Rafael Auler's avatar
      [BOLT] [NFC] Cleanup old code in mapCodeSections · 47ce9b39
      Rafael Auler authored
      Summary:
      In "Add initial function injection support", Laith added this
      code because injected functions would use the original text section as
      the section to emit their code to. Now, what happens is that functions
      are mapped to either their own section in non-reloc mode, or mapped to
      a particular section in the pass reassign sections. So this section does
      not need to have an output address anymore and this code is obsolete.
      
      (cherry picked from FBD30980450)
      47ce9b39
  9. Sep 11, 2021
    • Rafael Auler's avatar
      [BOLT] Fix binary corruption in non-reloc mode · 7b779f81
      Rafael Auler authored
      Summary:
      We have a problem where we will emit sections that we are not supposed
      to emit (with no output offset assigned). This will make us write at
      file offset 0 and corrupt the first sections in the binary (usually
      .interp section will be corrupted and bash will refuse to run the
      binary).
      
      This only happens in non-reloc mode when using JTS_BASIC and when we
      do not emit a function that has a jump table (if it gets too large).
      
      Using -update-debug-sections will trigger the pass
      check-large-functions, which will mark large funcs as non-simple
      and will hide this bug.
      
      (cherry picked from FBD30882012)
      7b779f81
  10. Aug 08, 2021
    • Vasily Leonenko's avatar
      [PR] Instrumentation: use TryLock for SimpleHashTable getter · 9aa134dc
      Vasily Leonenko authored
      Summary:
      This commit introduces TryLock usage for SimpleHashTable getter to
      avoid deadlock and relax syscalls usage which causes significant
      overhead in runtime.
      The old behavior left under -conservative-instrumentation option passed
      to instrumentation library.
      Also, this commit includes a corresponding test case: instrumentation of
      executable which performs indirect calls from common code and signal
      handler.
      
      Note: in case if TryLock was failed to acquire the lock - this indirect
      call will not be accounted in the resulting profile.
      
      Vasily Leonenko,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD30821949)
      9aa134dc
  11. Aug 28, 2021
  12. Sep 07, 2021
  13. Aug 28, 2021
  14. Aug 18, 2021
    • Joey Thaman's avatar
      [BOLT] Optimize the three way branch · 3e8af67a
      Joey Thaman authored
      Summary:
      Three way branches commonly appear
      in HHVM. They have one test and then two jumps.  The
      jump's destinations are not currently optimized.
      This pass attempts to optimize which is the first branch.
      
      (cherry picked from FBD30460441)
      3e8af67a
  15. Aug 20, 2021
    • Vladislav Khmelevsky's avatar
      [PR] AArch64: Fix ADR instruction handling · c040431f
      Vladislav Khmelevsky authored
      Summary:
      There are 2 problems found when handling ADR instruction:
      1. When extracting value from the ADR instruction we need to do
      it another way, then we do it for ADRP instruction.
      2. When creating target expression the VariantKind should be other for
      ADR instruction.
      
      And we introduces R_AARCH64_ADR_PREL_LO21,
      R_AARCH64_TLSDESC_ADR_PREL21 and R_AARCH64_ADR_PREL_PG_HI21_NC
      relocations support.
      
      Also this patch introduces AdrPass, which will replace non-local
      pointing ADR instructions with ADRP + ADD instructions sequence due to
      small offset range of ADR instruction, so after BOLT magic there are no
      guarantees that ADR instruction will still be in the range of
      just +- 1MB from its target. The instruction replacement needs
      relocations to be avalailable, so we won't remove "IsFromCode"
      relocations after disassembly from BF anymore. Also we need original
      offset of ADR instruction to be available so we add offset annotation
      for these instructions.
      
      The last thing this patch adds is ARM testing directory, which will be
      used only on ARM testing servers. The common tests (non-assembler tests
      which are platform-independent) might be moved from the X86 directory to
      the parent one in the future, so such tests could be tested on both X86
      and ARM machines.
      
      Vladislav Khmelevsky,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD30497379)
      c040431f
  16. Aug 22, 2021
    • Vladislav Khmelevsky's avatar
      [PR] Print relocations warning if failed to process · a1036e42
      Vladislav Khmelevsky authored
      Summary:
      Currently most of the warnings are printed only in debug mode. Since
      relocations are very important for binary correct work I suggest to
      print number of failed to process relocations to pay extra attention in
      case some problems with them were met
      
      Vladislav Khmelevsky,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD30500629)
      a1036e42
  17. Aug 11, 2021
    • Joey Thaman's avatar
      [BOLT] Added Constant and Copy Propagation to tail duplicated blocks · ef6186c8
      Joey Thaman authored
      Summary:
      Added a function in TailDuplication
      that will do Constant and Copy Propagation for blocks that
      we duplicated as a part of tail duplication.  Added supporting
      functions to MCPlusBuilder to find src registers and replace
      registers
      
      (cherry picked from FBD30231907)
      ef6186c8
  18. Jun 30, 2021
    • Vladislav Khmelevsky's avatar
      [PR] Fdata: Escape whitespaces in symbol names · 2a5790b6
      Vladislav Khmelevsky authored
      Summary:
      This patch is part of preparation for golang support. The golang symbols
      might have spaces in the name (for example "type..eq.[10]interface {}").
      Since fdata uses spaces as a field separator such names brakes the fdata
      format, so we need to escape whitespaces and backslashes in symbol names
      using the backslash character.
      
      Vladislav Khmelevsky,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD29999491)
      2a5790b6
  19. Aug 13, 2021
    • Amir Ayupov's avatar
      [BOLT][NFC][PR] Removed unused singletonSet · b64de075
      Amir Ayupov authored
      Summary:
      Remove unused code introduced a while ago (2016), with its use removed
      since then.
      
      PR facebookincubator/BOLT#198
      
      Author: Amir Aupov <aaupov@fb.com>
      
      (cherry picked from FBD30376537)
      b64de075
  20. Aug 12, 2021
    • Vladislav Khmelevsky's avatar
      [PR] Fix AARCH64 ADR* relocations · 8459c14c
      Vladislav Khmelevsky authored
      Summary:
      The ADRP instructions has 21 bits to store page offsets + 12 lowest bits
      are zero, that give us a total of 33 bits (32 bits for address + 1 sign
      bit, to address +- 4GB).
      
      Vladislav Khmelevsky,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD30283044)
      8459c14c
  21. Aug 17, 2021
    • Rafael Auler's avatar
      Fix NFC tests · faee814f
      Rafael Auler authored
      Summary:
      Our NFC tests are failing on debug-fission-single.s. Fix the test
      to be compliant with our checking script.
      
      (cherry picked from FBD30352415)
      faee814f
  22. Jun 30, 2021
  23. Jun 19, 2021
  24. Jul 22, 2021
  25. Jul 31, 2021
  26. Jul 30, 2021
    • Vasily Leonenko's avatar
      [PR] Instrumentation: Introduce instrumentation-binpath argument · 519cbbaa
      Vasily Leonenko authored
      Summary:
      This commit introduces -instrumentation-binpath argument used
      to point instuqmented binary in runtime in case if /proc/self/map_files
      path is not accessible due to access restriction issues.
      
      Vasily Leonenko
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD30092681)
      519cbbaa
  27. Jun 25, 2021
  28. Jun 24, 2021
  29. Jun 21, 2021
    • Vasily Leonenko's avatar
      [PR] Instrumentation: Initial support for static executables · 9b39a823
      Vasily Leonenko authored
      Summary:
      This commit introduces static binaries instrumentation
      support.  Note that current implementation does not support profile
      output on the instrumented binary finalization. So it requires to use
      -instrumentation-sleep-time=N (N>0) option usage.  Note: There is
      unhandled case with static PIE executable which might have dynamic
      header.
      
      Vasily Leonenko,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD30092471)
      9b39a823
  30. Jan 19, 2021
    • Elvina Yakubova's avatar
      [PR] Instrumentation: Add support for opening libs based on links /proc/self/map_files · 2ffd6e2b
      Elvina Yakubova authored
      Summary:
      This commit adds support for opening libs based on links
      /proc/self/map_files.  For this we're getting current virtual address
      and searching the lib in the directory with such address range. After
      that, we're getting full path to the binary by using readlink
      function. Direct read from link in /proc/self/map_files entries is not
      possible because of lack of permissions.
      
      Elvina Yakubova,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD30092422)
      2ffd6e2b
  31. Jan 18, 2021
  32. Jun 19, 2021
    • Vasily Leonenko's avatar
      [PR] Instrumentation: Generate and use _start and _fini trampolines · ad79d517
      Vasily Leonenko authored
      Summary:
      This commit implements new method for _start & _fini functions hooking
      which allows to use relative jumps for future PIE & .so library support.
      Instead of using absolute address of _start & _fini functions known on
      linking stage - we'll use dynamically created trampoline functions and
      use corresponding symbols in instrumentation runtime library.
      
      As we would like to use instrumentation for dynamically loaded binaries
      (with PIE & .so), thus we need to compile instrumentation library with
      "-fPIC" flag to support relative address resolution for functions and
      data.
      
      For shared libraries we need to handle initialization of instrumentation
      library case by using DT_INIT section entry point.
      
      Also this commit adds detection if the binary is executable or shared
      library based on existence of PT_INTERP header. In case of shared
      library we save information about real library init function address
      for further usage for instrumentation library init trampoline function
      creation and also update DT_INIT to point instrumentation library init
      function.
      
      Functions called from init/fini functions should be called with forced
      stack alignment to avoid issues with instructions which relies on it.
      E.g. optimized string operations.
      
      Vasily Leonenko,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD30092316)
      ad79d517
  33. Jul 30, 2021
    • Amir Ayupov's avatar
      [BOLT][NFC] Unify isTailCall interface across X86 and AArch64 · 60b10a8e
      Amir Ayupov authored
      Summary:
      Move the common code into MCPlusBuilder.h.
      Use group 1 `kTailCall` MCAnnotation instead of dynamically allocated
      annotation.
      This diff reduces the processing time overhead to 1.5% vs using
      TAILJMP opcode.
      
      (cherry picked from FBD30055585)
      60b10a8e
  34. Jul 14, 2021
    • Maksim Panchenko's avatar
      [BOLT] Support PLT sections with variable entry sizes · 89a2e160
      Maksim Panchenko authored
      Summary:
      The linker can generate 8- or 16-byte entries in .plt.got and .plt.sec
      sections. On X86, the main differentiator is the presence of endbr64
      instruction at the beginning of the entry. Detect the instruction and
      adjust the size accordingly.
      
      (cherry picked from FBD29847639)
      89a2e160
  35. Jul 29, 2021
  36. Jul 17, 2021
  37. Jun 25, 2021
    • Vasily Leonenko's avatar
      RewriteInstance: account .stab and .stabstr as debug sections · 68be8caf
      Vasily Leonenko authored
      Summary:
      .stab and .stabstr are special sections containing debugging
      information and strings associated with the debugging information.
      This commit adds them to the list of debugging sections, so
      these sections can be removed for output binary.
      
      Vasily Leonenko,
      Advanced Software Technology Lab, Huawei
      
      (cherry picked from FBD29746153)
      68be8caf
  38. Jul 17, 2021