llvm-capstone/lld/test/mach-o
Rui Ueyama ea65b5aa49 [MACH-O] Fix the ASM code generated for __stub_helpers section
Patch by Patricio Villalobos.

I discovered that lld for darwin is generating the wrong code for lazy
bindings in the __stub_helper section (at least for osx 10.12). This is
the way i can reproduce this problem, using this program:

  #include <stdio.h>

  int main(int argc, char **argv) {
      printf("C: printf!\n");
      puts("C: puts!\n");
      return 0;
  }

Then I link it using i have tested it in 3.9, 4.0 and 4.1 versions:

  $ clang -c hello.c
  $ lld -flavor darwin hello.o -o h1  -lc

When i execute the binary h1 the system gives me the following error:

  C: printf!
  dyld: lazy symbol binding failed:
  BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
  has segment 4 which is too large (0..3)
  dyld: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too
  large (0..3)
  Trace/BPT trap: 5

Investigating the code, it seems that the problem is that the asm code
generated in the file StubPass.cpp, specifically in the line 323,when it
adds, what it seems an arbitrary number (12) to the offset into the lazy
bind opcodes section, but it should be calculated depending on the
MachONormalizedFileBinaryWrite::lazyBindingInfo result.

I confirmed this bug by patching the code manually in the binary and
writing the right offset in the asm code (__stub_helper).

This patch fixes the content of the atom that contains the assembly code
when the offset is known.

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

llvm-svn: 311734
2017-08-24 23:51:40 +00:00
..
Inputs Partially revert r287009: Remove trailing whitespace. 2016-11-15 19:09:13 +00:00
align_text.yaml
arm64-reloc-negDelta32-fixup.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
arm64-relocs-errors-delta64-offset.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
arm64-section-order.yaml
arm-interworking-movw.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
arm-interworking.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
arm-shims.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
arm-subsections-via-symbols.yaml
bind-opcodes.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
cstring-sections.yaml
data-in-code-load-command.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
data-only-dylib.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
dead-strip-globals.yaml Dead strip DESC bits should only be set on object files. 2016-08-11 21:27:18 +00:00
debug-syms.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
demangle.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
dependency_info.yaml
do-not-emit-unwind-fde-arm64.yaml
dso_handle.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
dylib-install-names.yaml Fix off-by-one error in default currentVersion. 2016-08-11 18:41:14 +00:00
eh-frame-relocs-arm64.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
error-simulator-vs-macosx.yaml
exe-offsets.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
exe-segment-overlap.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
executable-exports.yaml Fix lld test that was causing llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast 2017-06-19 21:48:29 +00:00
export-trie-order.yaml ExportTrie nodes need to be visisted in order. 2016-08-05 21:37:12 +00:00
exported_symbols_list-dylib.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
exported_symbols_list-obj.yaml
exported_symbols_list-undef.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
fat-archive.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
filelist.yaml
flat_namespace_undef_error.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
flat_namespace_undef_suppress.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
force_load-dylib.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
force_load-x86_64.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
framework-user-paths.yaml
function-starts-load-command.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
gcc_except_tab-got-arm64.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
got-order.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
hello-world-arm64.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
hello-world-armv6.yaml
hello-world-armv7.yaml
hello-world-x86_64.yaml
hello-world-x86.yaml
image-base.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
infer-arch.yaml
interposing-section.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
keep_private_externs.yaml
lazy-bind-x86_64.yaml [MACH-O] Fix the ASM code generated for __stub_helpers section 2017-08-24 23:51:40 +00:00
lc_segment_filesize.yaml [lld][MachO] Fix LC_SEGEMENT[_64] filesize computation in -r mode. 2016-08-10 22:15:09 +00:00
lib-search-paths.yaml
library-order.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
library-rescan.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
libresolve-bizarre-root-override.yaml
libresolve-multiple-syslibroots.yaml
libresolve-one-syslibroot.yaml
libresolve-simple.yaml
libresolve-user-paths.yaml
libresolve-z.yaml
linker-as-ld.yaml [CMake] Fix linker-as-ld to symlink instead of copy lld 2016-09-12 22:38:43 +00:00
lit.local.cfg Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
mach_header-cpusubtype.yaml
mh_bundle_header.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
mh_dylib_header.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
objc_export_list.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
objc-category-list-atom.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
objc-image-info-host-vs-simulator.yaml
objc-image-info-invalid-size.yaml
objc-image-info-invalid-version.yaml
objc-image-info-mismatched-swift-version.yaml
objc-image-info-pass-output.yaml
objc-image-info-simulator-vs-host.yaml
objc-image-info-unsupported-gc.yaml
order_file-basic.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
parse-aliases.yaml
parse-arm-relocs.yaml
parse-cfstring32.yaml
parse-cfstring64.yaml
parse-compact-unwind32.yaml
parse-compact-unwind64.yaml
parse-data-in-code-armv7.yaml Fix one more test missed by r278372. The next commit will update libsystem in a way which broke without this fix as it referenced the wrong file 2016-08-11 18:43:42 +00:00
parse-data-in-code-x86.yaml
parse-data-relocs-arm64.yaml
parse-data-relocs-x86_64.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
parse-data.yaml
parse-eh-frame-relocs-x86_64.yaml
parse-eh-frame-x86-anon.yaml
parse-eh-frame-x86-labeled.yaml
parse-eh-frame.yaml
parse-function.yaml
parse-initializers32.yaml
parse-initializers64.yaml
parse-literals-error.yaml
parse-literals.yaml
parse-non-lazy-pointers.yaml
parse-relocs-x86.yaml
parse-section-no-symbol.yaml
parse-tentative-defs.yaml
parse-text-relocs-arm64.yaml
parse-text-relocs-x86_64.yaml
parse-tlv-relocs-x86-64.yaml
PIE.yaml
re-exported-dylib-ordinal.yaml
rpath.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
run-tlv-pass-x86-64.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
sdk-version-error.yaml
sectalign.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
sectattrs.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
sectcreate.yaml
seg-protection-arm64.yaml
seg-protection-x86_64.yaml
source-version.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
stack-size.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
string-table.yaml The first string table entry should be a null terminated space, not just null. 2016-08-08 23:20:04 +00:00
subsections-via-symbols-default.yaml
twolevel_namespace_undef_dynamic_lookup.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
twolevel_namespace_undef_warning_suppress.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
unwind-info-simple-arm64.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
unwind-info-simple-x86_64.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
upward-dylib-load-command.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
upward-dylib-paths.yaml
usage.yaml
use-dylib.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
use-simple-dylib.yaml
version-min-load-command-object.yaml
version-min-load-command.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
write-final-sections.yaml
wrong-arch-error.yaml