1. Nov 07, 2020
    • Amir Ayupov's avatar
      Lost in rebase: call registerFragment with a reference to TargetBF · f86a78a4
      Amir Ayupov authored
      Summary: Fixes broken build due to a lost dereferencing
      
      (cherry picked from FBD24799948)
      f86a78a4
    • Amir Ayupov's avatar
      Conservatively handle jump tables in split functions · 2b09d672
      Amir Ayupov authored
      Summary:
      - Allow jump table entries to point to locations inside the function and its fragments.
      Reasoning behind this is that jump table identification has the logic of stopping at entry which belongs to a function different from the one originally referencing jump table. This assumption is invalid for jump tables with entries pointing to both parent function and cold fragments, leading to "unclaimed PC-relative relocations" assertion.
      
      - Add fragment identification heuristic based on function name regex and contiguous jump table entries.
      Currently, parent-to-fragment relationship is set up based on interprocedural references – direct references from the parent function. These references don't include references through jump table.
      Additionally, some fragments are only reachable through jump table. In that case, in order to fully consume jump table, add parent-to-fragment relationship during `analyzeJumpTable` using the following heuristics:
        1. Fragment is identified as such based on name (contains `.cold.` part), but
        2. Parent function is not set – no direct interprocedural references to that fragment, and
        3. Fragment has the name of the form <parent>.cold(.\d+)
      
      * For split functions with jump table entries spanning parent and fragments, mark parent and all fragments as ignored.
      
      (cherry picked from FBD24456904)
      2b09d672
    • Amir Ayupov's avatar
      processInterproceduralReferences: record references to cold fragments as entry points · dc48354f
      Amir Ayupov authored
      Summary:
      For interprocedural references to fragments, record them as
      fragment entry points. Not registering these entry points leads to
      UCE removing the blocks and "Undefined temporary symbol"
      assertion.
      
      (cherry picked from FBD24511281)
      dc48354f
    • Amir Ayupov's avatar
      Extract BinaryContext::registerFragment · 54522877
      Amir Ayupov authored
      Summary: registerFragment to be reused in adding fragments reachable only through jump tables.
      
      (cherry picked from FBD24656651)
      54522877
  2. Nov 05, 2020
    • Vladislav Khmelevsky's avatar
      [BOLT][PR] Handle TLS relocations on AArch64 · 58460460
      Vladislav Khmelevsky authored
      Summary:
      Some of the TLS relocatios like R_AARCH64_TLSDESC_ADR_PAGE21 must be
      handled by bolt and should not be skipped by the removed condition. Some
      of the TLS relocations like R_AARCH64_TLS_TPREL64 could really be skipped
      here, but AFAIU this condition was added as part of BOLT its self optimization, so
      to prevent future problems here my suggestion is not to add another condition
      like "isTLS(RType) && isTLSRelocatable(RType)", but just remove it since
      absense of this condition should not broke any other TLS relocation.
      Vladislav Khmelevsky,
      Advanced Software Technology Lab, Huawei
      
      Pull Request resolved: https://github.com/facebookincubator/BOLT/pull/103
      GitHub Author: Vladislav Khmelevsky <Vladislav.Khmelevskyi@huawei.com>
      
      (cherry picked from FBD24745928)
      58460460
    • Maksim Panchenko's avatar
      [BOLT] Fix C++ exceptions for shared objects · 4f4239ce
      Maksim Panchenko authored
      Summary:
      Fix several issues to make C++ exceptions work in shared objects:
        * Set MCObjectFileInfo PIC type based on the input binary type.
        * Support indirect (DW_EH_PE_indirect) encoding while writing
          exception Type Table.
        * Use different LPStart value and landing pad encoding for .so's.
        * Disable splitting of exception-handling code for .so's because of
          the new encoding.
      
      (cherry picked from FBD24698765)
      4f4239ce
  3. Nov 04, 2020
    • Rafael Auler's avatar
      [BOLT] Remove threaded EliminateUnreachableBlock version · c1bb4dcb
      Rafael Auler authored
      Summary:
      EliminateUnreachableBlocks has a data race because it depends
      on BinaryContext::computeCodeSize. computeCodeSize supports independent
      Emitters, enabling a lock-free execution. Unfortunately, that is almost
      as expensive as the lock. Removing the boilerplate code for
      parallellization of this pass turned out to be the best alternative: no
      races and slightly better execution time for HHVM.
      
      (cherry picked from FBD24716250)
      c1bb4dcb
  4. Oct 31, 2020
    • Rafael Auler's avatar
      [BOLT] Please sanitizers · 37921b48
      Rafael Auler authored
      Summary:
      In BinaryContext, we had StringRef holding a reference to
      an r-value std::string. This triggers clang's address sanitizer
      warnings. In MCPlusBuilder we had a left shift overflowing a type,
      which is undefined behavior. Similarly, in CallGraph, we had a hash
      function shifting a negative value, which is also UB. The last two
      triggers the UB sanitizer.
      
      (cherry picked from FBD24661045)
      37921b48
    • Rafael Auler's avatar
      [DOCS] Add instrumentation instructions to README · 3e78082c
      Rafael Auler authored
      Summary: Add basic instructions on how to instrument a binary.
      
      (cherry picked from FBD24660183)
      3e78082c
    • Rafael Auler's avatar
      [BOLT] Fix no-asserts build · eb12d719
      Rafael Auler authored
      Summary: Only use dump() method under DEBUG() macro.
      
      (cherry picked from FBD24666481)
      eb12d719
  5. Oct 23, 2020
    • Maksim Panchenko's avatar
      [BOLT] Always keep dynamic symbols defined · 6b185ccc
      Maksim Panchenko authored
      Summary:
      Some symbols in .dynsym will be erroneously marked as belonging to a
      non-allocatable section that BOLT can remove. In that case, keep the
      original invalid index for such symbols instead of setting the UNDEF
      index.
      
      (cherry picked from FBD24488677)
      6b185ccc
  6. Oct 22, 2020
    • Amir Ayupov's avatar
      Add pass number to dot dump filename · 5f2f96c4
      Amir Ayupov authored
      Summary:
      Change .dot dumps filename format from
        <function>-<passname>.dot
      to
        <function>-<passidx>_<passname>.dot
      This change helps navigate dumps by making the pass order explicit.
      Example:
        execute_stack_op.cold.6-1(*2)-00_build-cfg.dot
        execute_stack_op.cold.6-1(*2)-01_validate-internal-calls.dot
        execute_stack_op.cold.6-1(*2)-02_strip-rep-ret.dot
        ...
      
      (cherry picked from FBD24452903)
      5f2f96c4
    • Maksim Panchenko's avatar
      [BOLT] Fix PatchEntries pass · d91add0b
      Maksim Panchenko authored
      Summary:
      While refactoring the pass, I removed the important transactional
      property of the patching process. Restore it.
      
      (cherry picked from FBD24440214)
      d91add0b
  7. Oct 18, 2020
  8. Oct 17, 2020
    • Rafael Auler's avatar
      [BOLT] Ignore __hot_start, __hot_end from input · e4396c41
      Rafael Auler authored
      Summary:
      When -hot-text is on, do not read __hot_start and __hot_end
      from input (inserted by a linker script with the intent of ordering
      functions). This can confuse BOLT into creating a function with this
      name depending on which address the symbol lands and we will assert
      when trying to emit our own __hot_start/__hot_end with symbol
      redefinition.
      
      (cherry picked from FBD24366636)
      e4396c41
  9. Oct 15, 2020
    • Alexander Shaposhnikov's avatar
      Inject a hook into the entry point on MachO · 6133d259
      Alexander Shaposhnikov authored
      Summary:
      This diff is a preparation for loading the runtime on MachO.
      The proposed schema is the following:
      
      1/  Function "bolt_instr_setup" is placed into the predefined section "setup" (in the final setting this function will be coming from the instrumentation runtime but we still will be placing it into this section).
      
      2/ In the instrumentation pass we create a symbol "bolt_instr_setup" and inject the corresponding call into the beginning of the function representing the entry point of the binary.
      
      (cherry picked from FBD24329530)
      6133d259
  10. Oct 16, 2020
  11. Oct 15, 2020
    • Alexander Shaposhnikov's avatar
      Add first bits to cross-compile the runtime for OSX · bbd9d610
      Alexander Shaposhnikov authored
      Summary: Add first bits to cross-compile the runtime for OSX.
      
      (cherry picked from FBD24330977)
      bbd9d610
    • Rafael Auler's avatar
      [BOLT] In shrinkwrap, do not split prefix/instr · 0b6df06e
      Rafael Auler authored
      Summary:
      When placing restore instructions in the shrink wrapping pass,
      we typically put them right before the last instruction of a block at
      the dominance frontier. If this instruction happened to have a prefix,
      because the MC lib separates prefix into separate MCInsts, we would
      accidentally put a load between a prefix and another instruction. Fix
      this.
      
      (cherry picked from FBD24295324)
      0b6df06e
  12. Oct 13, 2020
  13. Oct 12, 2020
  14. Oct 13, 2020
  15. Oct 03, 2020
  16. Oct 10, 2020
  17. Oct 08, 2020
  18. Oct 06, 2020
  19. Oct 05, 2020
    • Alexander Shaposhnikov's avatar
      Add -check-overlapping-elements option · 71e185f2
      Alexander Shaposhnikov authored
      Summary:
      This diff adds a command line option to disable the check of overlapping elements in Mach-O parsing. This check in its current form is prohibitively expensive for large binaries.
      A long-term fix would be to reimplement the check in a more efficient manner (and contribute it to the upstream).
      
      (cherry picked from FBD24109468)
      71e185f2
  20. Oct 06, 2020
    • Rafael Auler's avatar
      [BOLT] Fix sign issue when validating X86 relocations · d7fb9986
      Rafael Auler authored
      Summary:
      In analyzeRelocations, we extract the result of the relocation
      from binary code to recreate the target of it in a few special cases.
      For R_X86_64_32S relocations, however, we were neglecting the
      possibility of the encoded value in the instruction to be negative.
      
      (cherry picked from FBD24096347)
      d7fb9986
  21. Oct 01, 2020
  22. Sep 30, 2020
    • Amir Ayupov's avatar
      postProcessEntryPoints: return after setIgnored and setSimple are set · d1ec11b2
      Amir Ayupov authored
      Summary:
      This patch fixes the assertion failure during instrumentation.
      
      The assertion is raised by `getInstructionAtOffset` , which expects `CurrentState` to be either `Disassembled` or `CFG`.
      
      The function is called from `postProcessEntryPoints`, which goes over Labels and performs a series of checks. The checks call BinaryFunction methods `setSimple(false)` or `setIgnored()`.
      However, if `setIgnored` is invoked, it resets the state to `Empty`. Thus subsequent call to `getInstructionAtOffset` will fail.
      
      (cherry picked from FBD24005197)
      d1ec11b2
  23. Sep 24, 2020
  24. Sep 16, 2020
  25. Sep 15, 2020
    • Maksim Panchenko's avatar
      [BOLT] Eliminate "shallow" function lookup · a82cff0f
      Maksim Panchenko authored
      Summary:
      Whenever we search for a function based on its address in the input
      binary, we now always return a corresponding fragment for split
      functions. If the user needs an access to the main fragment, they can
      call getTopmostFragment().
      
      (cherry picked from FBD23670311)
      a82cff0f
    • Maksim Panchenko's avatar
      [BOLT] Do no map sections with zero address · 62469b50
      Maksim Panchenko authored
      Summary:
      Sections that do not originate from the input binary will have an
      input address set to zero and thus do not have to be mapped.
      
      Mapping such sections caused a build time regression in non-relocation
      mode.
      
      (cherry picked from FBD23670334)
      62469b50
  26. Aug 21, 2020
    • Amir Ayupov's avatar
      Bugfix for splitting critical edges in shrink wrapping · 8c4ba8f1
      Amir Ayupov authored
      Summary:
      Fix issue with splitting critical edges originating at
      the same BB in ShrinkWrapping::splitFrontierCritEdges.
      
      Splitting of critical edges originating at the same FromBB
      wasn't handled correctly as the Frontier at index corresponding
      to FromBB was overwritten with basic blocks created for
      multiple DestinationBBs.
      
      (cherry picked from FBD23232398)
      8c4ba8f1