llvm-project/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
PIE.yaml Delete unnecessary generality in loadFile. 2015-04-24 15:51:45 +00:00
align_text.yaml Use arithmetic type to represent alignments (not in log2) everywhere. 2015-03-26 02:20:25 +00:00
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 Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
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 Sort sections in relocatable files. 2016-01-04 22:29:36 +00:00
bind-opcodes.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
cstring-sections.yaml Delete unnecessary generality in loadFile. 2015-04-24 15:51:45 +00:00
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 lld/test/mach-o/dependency_info.yaml: Forgot to remove XFAIL:win32. 2016-02-09 07:44:10 +00:00
do-not-emit-unwind-fde-arm64.yaml Fix EHFrame processing to add implicit references when needed. 2016-03-15 21:33:10 +00:00
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 Check for mismatched arch and OS when linking MachO files. 2016-01-14 23:25:06 +00:00
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 Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
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 Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
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 Delete unnecessary generality in loadFile. 2015-04-24 15:51:45 +00:00
hello-world-armv7.yaml Update for llvm change. 2015-07-06 19:21:08 +00:00
hello-world-x86.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
hello-world-x86_64.yaml Parsed alignment should be a power of 2. 2016-03-24 00:36:37 +00:00
image-base.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
infer-arch.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
interposing-section.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
keep_private_externs.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
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 Subclass InputGraph to get darwin linker library semantics 2014-10-21 21:14:11 +00:00
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 [mach-o] Add support for upward linking 2014-10-16 19:31:28 +00:00
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 Set CPU_SUBTYPE_LIB64 in mach_header. 2016-02-04 20:43:43 +00:00
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-category-list-atom.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
objc-image-info-host-vs-simulator.yaml Set the objc constraint on the context based on the parsed files. 2016-01-19 19:46:41 +00:00
objc-image-info-invalid-size.yaml Remove unnecessary extra linked file in RUN line. NFC. 2016-01-15 23:25:40 +00:00
objc-image-info-invalid-version.yaml Check that the objc image info version is exactly 0 2016-01-15 23:25:37 +00:00
objc-image-info-mismatched-swift-version.yaml Add checking of differing swift versions in input files. 2016-01-16 00:07:22 +00:00
objc-image-info-pass-output.yaml Add an ObjCPass to the MachO linker. 2016-01-19 21:54:21 +00:00
objc-image-info-simulator-vs-host.yaml Set the objc constraint on the context based on the parsed files. 2016-01-19 19:46:41 +00:00
objc-image-info-unsupported-gc.yaml Give error on binaries containing GC objc image infos. 2016-01-16 00:57:07 +00:00
objc_export_list.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
order_file-basic.yaml Have one version of libSystem for each arch. NFC. 2016-08-11 18:08:59 +00:00
parse-aliases.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-arm-relocs.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-cfstring32.yaml Parsed alignment should be a power of 2. 2016-03-24 00:36:37 +00:00
parse-cfstring64.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-compact-unwind32.yaml
parse-compact-unwind64.yaml Parsed alignment should be a power of 2. 2016-03-24 00:36:37 +00:00
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 Fix MachO arm64 delta32ToGOT reloc encoding in -r. 2016-01-06 20:53:19 +00:00
parse-data-relocs-x86_64.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
parse-data.yaml Parsed alignment should be a power of 2. 2016-03-24 00:36:37 +00:00
parse-eh-frame-relocs-x86_64.yaml [LLD] Make sure MachO FDEs read their augmentation data strings from the right 2015-05-16 00:08:02 +00:00
parse-eh-frame-x86-anon.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-eh-frame-x86-labeled.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-eh-frame.yaml Parsed alignment should be a power of 2. 2016-03-24 00:36:37 +00:00
parse-function.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-initializers32.yaml
parse-initializers64.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-literals-error.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-literals.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-non-lazy-pointers.yaml
parse-relocs-x86.yaml Remove trailing whitespace characters. 2015-04-27 17:18:04 +00:00
parse-section-no-symbol.yaml
parse-tentative-defs.yaml YAML: Do not use 2^x notation to represent alignments. 2015-03-25 22:06:04 +00:00
parse-text-relocs-arm64.yaml [mach-o] Add support for arm64 (AAarch64) 2014-09-09 23:52:59 +00:00
parse-text-relocs-x86_64.yaml [LLD] Add support for MachO ripRel32MinusNAnon relocations. 2015-05-13 00:29:43 +00:00
parse-tlv-relocs-x86-64.yaml [lld] Add MachO thread-local storage support. 2015-06-23 20:35:31 +00:00
re-exported-dylib-ordinal.yaml Delete unnecessary generality in loadFile. 2015-04-24 15:51:45 +00:00
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 Add support for -sdk_version cmdline option. 2016-02-03 23:39:05 +00:00
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 [lld][Darwin] Add support for the -sectcreate option. 2015-10-24 08:20:51 +00:00
seg-protection-arm64.yaml Set max segment protection level. 2016-02-06 00:51:16 +00:00
seg-protection-x86_64.yaml Set max segment protection level. 2016-02-06 00:51:16 +00:00
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 MachoFile should default to using subsections_via_symbols. 2016-02-01 22:24:44 +00:00
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 [mach-o] Add support for upward linking 2014-10-16 19:31:28 +00:00
usage.yaml [mach-o] Fix so no options causes usage message to be printed 2014-09-09 00:45:35 +00:00
use-dylib.yaml Remove trailing whitespace. 2016-10-05 20:09:50 +00:00
use-simple-dylib.yaml Delete unnecessary generality in loadFile. 2015-04-24 15:51:45 +00:00
version-min-load-command-object.yaml Generate version min load commands when the platform is unknown. 2016-02-04 02:16:08 +00:00
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 [lld][MachO] Prune unused EH frames. 2015-10-23 05:39:16 +00:00
wrong-arch-error.yaml Delete unnecessary generality in loadFile. 2015-04-24 15:51:45 +00:00