├── .gitignore ├── APPLE_LICENSE ├── README.md ├── ar ├── append.c ├── ar.1 ├── ar.5 ├── ar.c ├── archive.c ├── archive.h ├── contents.c ├── delete.c ├── extern.h ├── extract.c ├── misc.c ├── move.c ├── pathnames.h ├── print.c └── replace.c ├── cctools.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── efitools ├── makerelocs.c ├── mtoc.c └── mtor.c ├── gprof ├── arcs.c ├── calls.c ├── dfn.c ├── getnfile.c ├── gprof.c ├── gprof.callg ├── gprof.flat ├── gprof.h ├── hertz.c ├── lookup.c ├── m68k.h ├── printgprof.c ├── printlist.c ├── scatter.c └── vax.h ├── include ├── architecture │ ├── i386 │ │ ├── fpu.h │ │ └── frame.h │ ├── m88k │ │ ├── fp_regs.h │ │ └── reg_help.h │ ├── nrw │ │ ├── macro_help.h │ │ └── reg_help.h │ └── sparc │ │ └── reg.h ├── coff │ ├── aouthdr.h │ ├── base_relocs.h │ ├── bytesex.h │ ├── debug_directory.h │ ├── filehdr.h │ ├── ms_dos_stub.h │ ├── scnhdr.h │ └── syment.h ├── elf │ └── dwarf2.h ├── gnu │ ├── a.out.h │ ├── exec.h │ └── symseg.h ├── i386 │ └── eflags.h ├── llvm-c │ └── Disassembler.h ├── mach-o │ ├── arch.h │ ├── arm │ │ └── reloc.h │ ├── arm64 │ │ └── reloc.h │ ├── dyld.h │ ├── dyld_debug.h │ ├── dyld_gdb.h │ ├── dyld_priv.h │ ├── fat.h │ ├── getsect.h │ ├── gmon.h │ ├── i386 │ │ └── swap.h │ ├── kld.h │ ├── ldsyms.h │ ├── loader.h │ ├── nlist.h │ ├── ranlib.h │ ├── redo_prebinding.h │ ├── reloc.h │ ├── rld.h │ ├── rld_state.h │ ├── sarld.h │ ├── stab.h │ ├── swap.h │ └── x86_64 │ │ └── reloc.h ├── mach │ ├── arm │ │ ├── _structs.h │ │ ├── thread_state.h │ │ └── thread_status.h │ ├── hppa │ │ └── thread_status.h │ ├── i386 │ │ ├── _structs.h │ │ ├── fp_reg.h │ │ ├── thread_state.h │ │ └── thread_status.h │ ├── i860 │ │ └── thread_status.h │ ├── m68k │ │ └── thread_status.h │ ├── m88k │ │ └── thread_status.h │ ├── machine-cctools.h │ ├── ppc │ │ ├── _structs.h │ │ └── thread_status.h │ ├── slot_name.h │ └── sparc │ │ └── thread_status.h ├── modules │ ├── MachO.exclavecore.modulemap │ ├── MachO.exclavekit.modulemap │ ├── MachO_Private.exclavekit.modulemap │ ├── mach-o.exclavekit.modulemap │ └── mach-o.exclavekit.private.modulemap ├── opcode │ └── arm.h ├── standalone │ ├── getsect.h │ └── libsa.h ├── stuff │ ├── SymLoc.h │ ├── align.h │ ├── allocate.h │ ├── arch.h │ ├── args.h │ ├── best_arch.h │ ├── bool.h │ ├── breakout.h │ ├── bytesex.h │ ├── code_directory.h │ ├── crc32.h │ ├── depinfo.h │ ├── diagnostics.h │ ├── dylib_roots.h │ ├── dylib_table.h │ ├── errors.h │ ├── execute.h │ ├── guess_short_name.h │ ├── hash_string.h │ ├── hppa.h │ ├── llvm.h │ ├── lto.h │ ├── macosx_deployment_target.h │ ├── ofile.h │ ├── openstep_mach.h │ ├── print.h │ ├── reloc.h │ ├── rnd.h │ ├── seg_addr_table.h │ ├── symbol.h │ ├── symbol_list.h │ ├── unix_standard_mode.h │ ├── version_number.h │ ├── vm_flush_cache.h │ ├── write64.h │ └── xcode.h ├── sys │ └── gmon.h └── xar │ └── xar.h ├── ld ├── 4byte_literals.c ├── 4byte_literals.h ├── 8byte_literals.c ├── 8byte_literals.h ├── arm_reloc.c ├── arm_reloc.h ├── coalesced_sections.c ├── coalesced_sections.h ├── cstring_literals.c ├── cstring_literals.h ├── debugcompunit.c ├── debugcompunit.h ├── debugline.c ├── debugline.h ├── dwarf2.h ├── dylibs.c ├── dylibs.h ├── fvmlibs.c ├── fvmlibs.h ├── generic_reloc.c ├── generic_reloc.h ├── hash_string.h ├── hppa_reloc.c ├── hppa_reloc.h ├── i860_reloc.c ├── i860_reloc.h ├── indirect_sections.c ├── indirect_sections.h ├── layout.c ├── layout.h ├── ld.c ├── ld.h ├── librld.ofileList ├── literal_pointers.c ├── literal_pointers.h ├── live_refs.h ├── m88k_reloc.c ├── m88k_reloc.h ├── mod_sections.c ├── mod_sections.h ├── objects.c ├── objects.h ├── pass1.c ├── pass1.h ├── pass2.c ├── pass2.h ├── ppc_reloc.c ├── ppc_reloc.h ├── rld.c ├── sections.c ├── sections.h ├── sets.c ├── sets.h ├── sparc_reloc.c ├── sparc_reloc.h ├── specs.c ├── specs.h ├── symbols.c ├── symbols.h ├── uuid.c └── uuid.h ├── libmacho ├── arch.c ├── dylib.ofileList ├── get_end.c ├── getsecbyname.c ├── getsegbyname.c ├── i386_swap.c ├── shlib.ofileList ├── slot_name.c └── swap.c ├── libstuff ├── SymLoc.c ├── align.c ├── allocate.c ├── apple_version.c ├── arch.c ├── arch_usage.c ├── args.c ├── best_arch.c ├── breakout.c ├── bytesex.c ├── checkout.c ├── code_directory.c ├── coff_bytesex.c ├── crc32.c ├── depinfo.c ├── diagnostics.c ├── dylib_roots.c ├── dylib_table.c ├── errors.c ├── execute.c ├── fatal_arch.c ├── fatals.c ├── get_arch_from_host.c ├── get_toc_byte_sex.c ├── guess_short_name.c ├── hash_string.c ├── hppa.c ├── llvm.c ├── lto.c ├── macosx_deployment_target.c ├── ofile.c ├── ofile_error.c ├── ofile_get_word.c ├── print.c ├── reloc.c ├── rnd.c ├── seg_addr_table.c ├── set_arch_flag_name.c ├── swap_headers.c ├── symbol_list.c ├── unix_standard_mode.c ├── version_number.c ├── vm_flush_cache.c ├── write64.c ├── writeout.c └── xcode.c ├── libstuff_test ├── align_test.c ├── allocate_test.c ├── arch_test.c ├── args_test.c ├── depinfo_test.c ├── get_arch_from_host_test.c ├── guess_short_name_test.c ├── libstuff_test.c ├── null_test.c ├── reset_load_command_pointers_test.c ├── rnd_test.c ├── test.c ├── test.h ├── test_main.h ├── test_util.c ├── test_util.h └── version_number_test.c ├── man ├── Mach-O.5 ├── NSModule.3 ├── NSObjectFileImage.3 ├── NSObjectFileImage_priv.3 ├── a.out.5 ├── arch.3 ├── as.1 ├── bitcode_strip.1 ├── check_dylib.1 ├── checksyms.1 ├── cmpdylib.1 ├── codesign_allocate.1 ├── ctf_insert.1 ├── depinfo.1 ├── diagtest.1 ├── dyld.1 ├── dyld.3 ├── dyld_debug.3 ├── end.3 ├── get_end.3 ├── getsectbyname.3 ├── getsectbynamefromheader.3 ├── getsectdata.3 ├── getsectdatafromheader.3 ├── getsegbyname.3 ├── gprof.1 ├── indr.1 ├── install_name_tool.1 ├── kld.3 ├── ld_classic.1 ├── libtool.1 ├── lipo.1 ├── llvm-otool.1 ├── mtoc.1 ├── mtor.1 ├── nm-classic.1 ├── nm.1 ├── nmedit.1 ├── otool-classic.1 ├── otool.1 ├── pagestuff.1 ├── ranlib.1 ├── ranlib.5 ├── redo_prebinding.1 ├── redo_prebinding.3 ├── rld.3 ├── seg_addr_table.1 ├── segedit.1 ├── size-classic.1 ├── size.1 ├── stab.5 ├── strings.1 ├── strip.1 └── vtool.1 ├── misc ├── Info.plist ├── as ├── bitcode_strip.c ├── check_dylib.c ├── checksyms.c ├── cmpdylib.c ├── codesign_allocate-Info.plist ├── codesign_allocate.c ├── ctf_insert.c ├── depinfo.c ├── diagtest.c ├── indr.c ├── inout.c ├── install_name_tool.c ├── libtool.c ├── lipo.c ├── nm.c ├── pagestuff.c ├── redo_prebinding.c ├── seg_addr_table.c ├── seg_hack.c ├── segedit.c ├── size.c ├── strings.c ├── strip.c └── vtool.c ├── otool ├── arm64_disasm.c ├── arm64_disasm.h ├── arm_disasm.c ├── arm_disasm.h ├── coff_print.c ├── cxa_demangle.h ├── dyld_bind_info.c ├── dyld_bind_info.h ├── fixup-chains.h ├── i386_disasm.c ├── i386_disasm.h ├── main.c ├── ofile_print.c ├── ofile_print.h ├── otool.h ├── print_bitcode.c ├── print_objc.c ├── print_objc2_32bit.c ├── print_objc2_64bit.c ├── print_objc2_util.c └── print_objc2_util.h ├── tests ├── Makefile ├── README.md ├── bin │ ├── check.pl │ ├── exit-non-zero-pass.pl │ ├── fail-if-exit-non-zero.pl │ ├── fail-if-exit-zero.pl │ ├── fail-if-no-stdin.pl │ ├── fail-if-stdin.pl │ ├── fail-iff-exit-zero.pl │ ├── new-makefile-test.pl │ ├── note-tool.pl │ ├── pass-iff-exit-non-zero.pl │ ├── pass-iff-exit-zero.pl │ ├── pass-iff-no-stdin.pl │ ├── pass-iff-stdin.pl │ ├── rewrite-macho.pl │ ├── run-tests.pl │ └── verify-align.pl ├── data │ └── echo.fat ├── include │ ├── MachO.pm │ ├── MachO │ │ ├── ArchiveObject.pm │ │ ├── Base.pm │ │ ├── CPU.pm │ │ ├── FatHeader.pm │ │ ├── FatObject.pm │ │ ├── LEB128.pm │ │ ├── LoadCommands.pm │ │ ├── MachHeader.pm │ │ ├── MachObject.pm │ │ ├── StringTable.pm │ │ ├── SymbolTable.pm │ │ └── Trie.pm │ └── common.makefile ├── run-tests ├── src │ ├── bar.c │ ├── foo.c │ ├── hello.c │ ├── hello_textexec.c │ ├── objc_hi.m │ ├── preload.c │ ├── preload_bss.c │ ├── times.c │ └── verstool.c └── test-cases │ ├── 1a_harness_test │ └── Makefile │ ├── 1b_check_test │ └── Makefile │ ├── as-gas │ └── Makefile │ ├── as-llvm │ └── Makefile │ ├── as-symbol │ ├── Makefile │ └── x.s │ ├── bitcode_strip-bigendian │ └── Makefile │ ├── bitcode_strip-chained-binds │ └── Makefile │ ├── bitcode_strip-codesign │ └── Makefile │ ├── bitcode_strip-resign │ └── Makefile │ ├── bitcode_strip_arm64_32 │ ├── Makefile │ └── empty.c │ ├── bitcode_strip_large │ └── Makefile │ ├── cc_log_diagnostics │ └── Makefile │ ├── codesign │ └── Makefile │ ├── codesign_allocate-bigendian │ └── Makefile │ ├── codesign_allocate-chained-binds │ └── Makefile │ ├── codesign_allocate_arm64_32 │ └── Makefile │ ├── codesign_allocate_debug │ └── Makefile │ ├── codesign_allocate_large │ └── Makefile │ ├── codesign_allocate_requirement │ └── Makefile │ ├── ctf_insert-no-text │ ├── Makefile │ ├── in.exe │ └── in.txt │ ├── ctf_insert-split_seg-chained │ ├── Makefile │ └── preload.c │ ├── ctf_insert-split_seg │ ├── Makefile │ └── preload.c │ ├── ctf_insert │ └── Makefile │ ├── install_name_tool-change │ ├── Makefile │ └── client.c │ ├── install_name_tool-id │ └── Makefile │ ├── libstuff-unit-tests │ └── Makefile │ ├── libtool-atfile │ ├── Makefile │ ├── deterministic.txt │ ├── libfoo.c │ ├── loop.txt │ ├── object.txt │ └── static.txt │ ├── libtool-atomic │ ├── Makefile │ └── libfoo.c │ ├── libtool-cpusubtype-flags │ └── Makefile │ ├── libtool-deterministic │ ├── Makefile │ └── libfoo.c │ ├── libtool-filelist-commapath │ ├── Makefile │ ├── filelist, dir │ │ └── filelist │ └── libfoo.c │ ├── libtool-ldtrace-file │ └── Makefile │ ├── libtool-ldtrace-json-file │ └── Makefile │ ├── libtool-ldtrace-json-stderr │ └── Makefile │ ├── libtool-ldtrace-stderr │ └── Makefile │ ├── libtool-static-times │ └── Makefile │ ├── libtool-static │ ├── Makefile │ └── libfoo.c │ ├── lipo-arch_blank │ └── Makefile │ ├── lipo-archs │ └── Makefile │ ├── lipo-bigendian │ └── Makefile │ ├── lipo-cpusubtype-order │ ├── Makefile │ └── foo.c │ ├── lipo-hidden │ ├── Makefile │ └── empty.c │ ├── lipo-info │ └── Makefile │ ├── lipo-large │ └── Makefile │ ├── lipo-thin-times │ └── Makefile │ ├── llvm-otool │ └── Makefile │ ├── mtor-bad-file │ └── Makefile │ ├── mtor-preload-bss │ └── Makefile │ ├── mtor-preload-packdata │ └── Makefile │ ├── mtor-preload │ └── Makefile │ ├── mtor-usage │ └── Makefile │ ├── nm-classic-lto-weak-ref │ ├── Makefile │ └── weak-ref.cpp │ ├── nm-classic-m-cold-func │ ├── Makefile │ └── symtool.c │ ├── nm-classic-m │ ├── Makefile │ ├── atsPathVersSuffix.c │ ├── atsVersSuffix.c │ ├── foo.c │ ├── fooPath.c │ ├── fooPathSuffix.c │ ├── fooPathVers.c │ ├── fooSuffix.c │ ├── fooVers.c │ ├── foo_bar.c │ ├── foo_barSuffix.c │ ├── main.c │ ├── qt.c │ ├── qtPath.c │ ├── x.c │ ├── xPathSuffix.c │ └── xSuffix.c │ ├── nmedit-D │ └── Makefile │ ├── nmedit-reloc-bypass │ ├── Makefile │ ├── ex.a │ ├── ex.c │ └── ex.exp │ ├── nmedit-usage │ └── Makefile │ ├── otool-classic-L │ ├── Makefile │ └── mangle.pl │ ├── otool-classic-S │ └── Makefile │ ├── otool-classic-addr-slide │ └── Makefile │ ├── otool-classic-bind_info-chained-weak │ ├── Makefile │ ├── weak-large-addends.cpp │ ├── weak-no-addends.cpp │ └── weak-small-addends.cpp │ ├── otool-classic-bind_info-chained │ └── Makefile │ ├── otool-classic-bind_info │ └── Makefile │ ├── otool-classic-cpusubtype-flags │ └── Makefile │ ├── otool-classic-f │ └── Makefile │ ├── otool-classic-o-rel32 │ ├── Makefile │ ├── hi-abs-32.dylib │ ├── hi-abs-64.dylib │ ├── hi-dir-32.dylib │ ├── hi-dir-64.dylib │ ├── hi-rel-32.dylib │ ├── hi-rel-64.dylib │ ├── hi.h │ ├── hi.m │ └── main.m │ ├── otool-classic-o-selrefs │ ├── Dylib.h │ ├── Dylib.m │ ├── Makefile │ ├── Protocol.h │ └── Tool.m │ ├── otool-classic-o │ ├── Dylib.h │ ├── Dylib.m │ ├── Makefile │ ├── Protocol.h │ └── Tool.m │ ├── otool-classic-pointer-formats │ ├── Makefile │ ├── firmware.c │ ├── tool.c │ ├── tool_ARM64E │ ├── tool_NONE │ ├── tool_PTR_32 │ ├── tool_PTR_32_FIRMWARE │ ├── tool_PTR_64 │ ├── tool_PTR_ARM64E_USERLAND24 │ └── tool_THREADED │ ├── otool-classic-ptrauth-flag │ └── Makefile │ ├── otool-classic-t │ ├── Makefile │ └── hello.s │ ├── otool-classic-x │ └── Makefile │ ├── pagestuff-chained-binds │ └── Makefile │ ├── pagestuff-usage │ ├── Makefile │ ├── testfile │ └── verstool.c │ ├── ranlib-8byte-aligned │ └── Makefile │ ├── ranlib-atomic │ ├── Makefile │ └── libfoo.c │ ├── ranlib-t │ └── Makefile │ ├── segedit-extract │ ├── Makefile │ ├── MementoMori1.txt │ └── main.c │ ├── segedit-replace-bigendian │ ├── Makefile │ ├── MementoMori1.txt │ ├── MementoMori2.txt │ ├── dirty_data.txt │ └── main.c │ ├── segedit-replace-chained-binds │ ├── Makefile │ ├── MementoMori1.txt │ ├── MementoMori2.txt │ ├── dirty_data.txt │ └── main.c │ ├── segedit-replace │ ├── Makefile │ ├── MementoMori1.txt │ ├── MementoMori2.txt │ ├── dirty_data.txt │ └── main.c │ ├── size-usage │ └── Makefile │ ├── strings-stdin │ └── Makefile │ ├── strip-D │ └── Makefile │ ├── strip-R │ ├── Makefile │ └── list.txt │ ├── strip-S-dice │ ├── Makefile │ └── dice.o │ ├── strip-S-nosyms │ ├── Makefile │ └── nosyms.o │ ├── strip-T │ ├── Makefile │ └── hello.swift │ ├── strip-archive-times │ └── Makefile │ ├── strip-chained-binds │ ├── Makefile │ └── symbols.c │ ├── strip-dylib-exports-trie │ ├── Makefile │ └── foo.c │ ├── strip-indirectsym_pad │ ├── Makefile │ ├── dylib.c │ └── dylib.sym │ ├── strip-prestripped │ └── Makefile │ ├── strip-resign │ └── Makefile │ ├── strip-uniq │ ├── Makefile │ ├── bar.c │ ├── foo.c │ └── main.c │ ├── strip-zero-ar-date │ └── Makefile │ ├── verify-build-version │ ├── Makefile │ └── foo.c │ ├── verify-iosmac-backdeploy │ ├── Makefile │ └── foo.c │ ├── verify-iosmac │ ├── Makefile │ └── foo.c │ ├── vtool-remove │ └── Makefile │ ├── vtool-set │ └── Makefile │ ├── vtool-show │ └── Makefile │ └── vtool-usage │ └── Makefile ├── update.sh └── xcode ├── as_license.sh ├── cctools.xcconfig ├── codesign_allocate.xcconfig ├── copy_if.sh ├── copy_macho_headers_standalone.sh ├── create_symlink.sh ├── libstuff.xcconfig ├── macho_dynamic.xcconfig ├── macho_dynamic_driverkit.xcconfig ├── macho_headers.sh ├── macho_headers.xcconfig ├── macho_static.xcconfig ├── otool.xcconfig ├── private_efi.xcconfig ├── private_test.xcconfig ├── private_tool.xcconfig ├── public_tool.xcconfig └── strip.xcconfig /.gitignore: -------------------------------------------------------------------------------- 1 | # Don't track content of these folders 2 | **/xcuserdata 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cctools 2 | 3 | This repo is a mirror of cctools source dumps from opensource.apple.com. 4 | This is useful for diffing changes between Xcode versions and building 5 | various tools for debugging issues. 6 | 7 | ## Building 8 | 9 | If you would like to build any of these tools yourself, which can be 10 | useful for debugging various issues, you can use these branches: 11 | 12 | - [buildable-16.0](https://github.com/keith/cctools/tree/buildable-16.0) 13 | - [buildable-15.3](https://github.com/keith/cctools/tree/buildable-15.3) 14 | - [buildable-15.0](https://github.com/keith/cctools/tree/buildable-15.0) 15 | - [buildable-13.2.1](https://github.com/keith/cctools/tree/buildable-13.2.1) 16 | - [buildable-12.0](https://github.com/keith/cctools/tree/buildable-12.0) 17 | 18 | 19 | ## Updating this repo 20 | 21 | ```sh 22 | ./update.sh URL_OF_TAR_GZ 23 | ``` 24 | -------------------------------------------------------------------------------- /cctools.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /cctools.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /gprof/gprof.flat: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | flat profile: 5 | 6 | % the percentage of the total running time of the 7 | time program used by this function. 8 | 9 | cumulative a running sum of the number of seconds accounted 10 | seconds for by this function and those listed above it. 11 | 12 | self the number of seconds accounted for by this 13 | seconds function alone. This is the major sort for this 14 | listing. 15 | 16 | calls the number of times this function was invoked, if 17 | this function is profiled, else blank. 18 | 19 | self the average number of milliseconds spent in this 20 | ms/call function per call, if this function is profiled, 21 | else blank. 22 | 23 | total the average number of milliseconds spent in this 24 | ms/call function and its descendents per call, if this 25 | function is profiled, else blank. 26 | 27 | name the name of the function. This is the minor sort 28 | for this listing. The index shows the location of 29 | the function in the gprof listing. If the index is 30 | in parenthesis it shows where it would appear in 31 | the gprof listing if it were to be printed. 32 | 33 | -------------------------------------------------------------------------------- /include/coff/bytesex.h: -------------------------------------------------------------------------------- 1 | #ifndef _COFF_BYTESEX_H 2 | #define _COFF_BYTESEX_H 3 | 4 | #include "stuff/bytesex.h" 5 | #include "coff/base_relocs.h" 6 | #include "coff/ms_dos_stub.h" 7 | #include "coff/filehdr.h" 8 | #include "coff/aouthdr.h" 9 | #include "coff/scnhdr.h" 10 | #include "coff/syment.h" 11 | #include "coff/debug_directory.h" 12 | 13 | __private_extern__ void swap_base_relocation_block_header( 14 | struct base_relocation_block_header *h, 15 | enum byte_sex target_byte_sex); 16 | 17 | __private_extern__ void swap_base_relocation_entry( 18 | struct base_relocation_entry *b, 19 | uint32_t n, 20 | enum byte_sex target_byte_sex); 21 | 22 | __private_extern__ void swap_ms_dos_stub( 23 | struct ms_dos_stub *m, 24 | enum byte_sex target_byte_sex); 25 | 26 | __private_extern__ void swap_filehdr( 27 | struct filehdr *f, 28 | enum byte_sex target_byte_sex); 29 | 30 | __private_extern__ void swap_aouthdr( 31 | struct aouthdr *a, 32 | enum byte_sex target_byte_sex); 33 | 34 | __private_extern__ void swap_aouthdr_64( 35 | struct aouthdr_64 *a, 36 | enum byte_sex target_byte_sex); 37 | 38 | __private_extern__ void swap_scnhdr( 39 | struct scnhdr *s, 40 | uint32_t n, 41 | enum byte_sex target_byte_sex); 42 | 43 | __private_extern__ void swap_syment( 44 | struct syment *s, 45 | uint32_t n, 46 | enum byte_sex target_byte_sex); 47 | 48 | __private_extern__ void swap_debug_directory_entry( 49 | struct debug_directory_entry *d, 50 | enum byte_sex target_byte_sex); 51 | 52 | __private_extern__ void swap_mtoc_debug_info( 53 | struct mtoc_debug_info *m, 54 | enum byte_sex target_byte_sex); 55 | 56 | #endif /* _COFF_BYTESEX_H */ 57 | -------------------------------------------------------------------------------- /include/mach/arm/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | */ 4 | /* 5 | * @OSF_COPYRIGHT@ 6 | */ 7 | 8 | #ifndef _MACH_ARM_THREAD_STATE_H_ 9 | #define _MACH_ARM_THREAD_STATE_H_ 10 | 11 | #define ARM_THREAD_STATE_MAX (272) 12 | 13 | #if defined (__arm__) 14 | #define THREAD_STATE_MAX ARM_THREAD_STATE_MAX 15 | #endif 16 | 17 | #if defined(__arm64__) && !defined(THREAD_STATE_MAX) 18 | #define THREAD_STATE_MAX ARM_THREAD_STATE_MAX 19 | #endif 20 | 21 | #endif /* _MACH_ARM_THREAD_STATE_H_ */ 22 | -------------------------------------------------------------------------------- /include/mach/i386/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_I386_THREAD_STATE_H_ 33 | #define _MACH_I386_THREAD_STATE_H_ 34 | 35 | /* Size of maximum exported thread state in words */ 36 | #define I386_THREAD_STATE_MAX (614) /* Size of biggest state possible */ 37 | 38 | #if defined (__i386__) || defined(__x86_64__) 39 | #define THREAD_STATE_MAX I386_THREAD_STATE_MAX 40 | #endif 41 | 42 | #endif /* _MACH_I386_THREAD_STATE_H_ */ 43 | -------------------------------------------------------------------------------- /include/mach/slot_name.h: -------------------------------------------------------------------------------- 1 | #include 2 | extern void slot_name(cpu_type_t, 3 | cpu_subtype_t, 4 | char **, 5 | char **); 6 | -------------------------------------------------------------------------------- /include/modules/MachO.exclavecore.modulemap: -------------------------------------------------------------------------------- 1 | module MachO [system] { 2 | umbrella "mach-o" 3 | module * { export * } 4 | } 5 | -------------------------------------------------------------------------------- /include/modules/MachO.exclavekit.modulemap: -------------------------------------------------------------------------------- 1 | module MachO [system] { 2 | umbrella "mach-o" 3 | module * { export * } 4 | } 5 | -------------------------------------------------------------------------------- /include/modules/MachO_Private.exclavekit.modulemap: -------------------------------------------------------------------------------- 1 | module MachO_Private [system] { 2 | umbrella "mach-o" 3 | 4 | module dyld { 5 | header "mach-o/dyld_priv.h" 6 | export * 7 | } 8 | 9 | explicit module * { export * } 10 | } 11 | -------------------------------------------------------------------------------- /include/modules/mach-o.exclavekit.modulemap: -------------------------------------------------------------------------------- 1 | extern module MachO "../MachO.modulemap" 2 | 3 | module MachO_Placeholder_OldFile [system] { 4 | } 5 | -------------------------------------------------------------------------------- /include/modules/mach-o.exclavekit.private.modulemap: -------------------------------------------------------------------------------- 1 | extern module MachO_Private "../MachO_Private.modulemap" 2 | 3 | module MachO_Private_Placeholder_OldFile [system] { 4 | } 5 | -------------------------------------------------------------------------------- /include/stuff/SymLoc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #include "bool.h" 24 | 25 | extern const char * symLocForDylib( 26 | const char *installName, 27 | const char *releaseName, 28 | enum bool *found_project, 29 | enum bool disablewarnings, 30 | enum bool no_error_if_missing); 31 | 32 | extern const char * dstLocForDylib( 33 | const char *installName, 34 | const char *releaseName, 35 | enum bool *found_project, 36 | enum bool disablewarnings, 37 | enum bool no_error_if_missing); 38 | 39 | const char * LocForDylib( 40 | const char *installName, 41 | const char *releaseName, 42 | const char *dirname, 43 | enum bool *found_project, 44 | enum bool disablewarnings, 45 | enum bool no_error_if_missing); 46 | -------------------------------------------------------------------------------- /include/stuff/allocate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | /* defined in allocate.c */ 28 | 29 | __private_extern__ void *allocate( 30 | size_t size); 31 | 32 | __private_extern__ void *reallocate( 33 | void *, 34 | size_t size); 35 | 36 | __private_extern__ char *savestr( 37 | const char *s); 38 | 39 | __private_extern__ char *makestr( 40 | const char *args, ...); 41 | -------------------------------------------------------------------------------- /include/stuff/crc32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | __private_extern__ uint32_t crc32( 24 | const void *buf, 25 | uint32_t len); 26 | -------------------------------------------------------------------------------- /include/stuff/dylib_roots.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | extern char * get_symfile_for_dylib( 24 | char *install_name, 25 | char *release_name, 26 | enum bool *found_project, 27 | enum bool disablewarnings, 28 | enum bool no_error_if_missing); 29 | 30 | extern char * get_dstfile_for_dylib( 31 | char *install_name, 32 | char *release_name, 33 | enum bool *found_project, 34 | enum bool disablewarnings, 35 | enum bool no_error_if_missing); 36 | 37 | extern char * find_dylib_in_root( 38 | char *install_name, 39 | const char *root); 40 | -------------------------------------------------------------------------------- /include/stuff/dylib_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | /* 24 | * The table of known dynamic library names and addresses they are linked at. 25 | * This is loaded from a -dylib_table option or from the default file: 26 | * ~rc/Data/DylibTable . 27 | */ 28 | struct dylib_table { 29 | uint32_t seg1addr; 30 | char *name; 31 | }; 32 | 33 | extern struct dylib_table * parse_dylib_table( 34 | char *file_name, 35 | char *flag, 36 | char *argument); 37 | 38 | extern struct dylib_table * parse_default_dylib_table( 39 | char **file_name); 40 | 41 | extern struct dylib_table *search_dylib_table( 42 | struct dylib_table *dylib_table, 43 | char *name); 44 | 45 | extern char * guess_dylib_install_name( 46 | char *name); 47 | -------------------------------------------------------------------------------- /include/stuff/execute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | /* 28 | * execute() does an execvp using the argv passed to it. If the parameter 29 | * verbose is non-zero the command is printed to stderr. A non-zero return 30 | * value indicates success zero indicates failure. 31 | */ 32 | __private_extern__ int execute( 33 | char **argv, 34 | int verbose); 35 | 36 | __private_extern__ void add_execute_list( 37 | char *str); 38 | 39 | __private_extern__ void add_execute_list_with_prefix( 40 | char *str); 41 | 42 | __private_extern__ char * cmd_with_prefix( 43 | char *str); 44 | 45 | __private_extern__ void reset_execute_list( 46 | void); 47 | 48 | __private_extern__ int execute_list( 49 | int verbose); 50 | -------------------------------------------------------------------------------- /include/stuff/guess_short_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #include "stuff/bool.h" 24 | 25 | __private_extern__ char * guess_short_name( 26 | char *name, 27 | enum bool *is_framework, 28 | char **return_suffix); 29 | -------------------------------------------------------------------------------- /include/stuff/hash_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | __private_extern__ int32_t hash_string( 28 | char *key); 29 | -------------------------------------------------------------------------------- /include/stuff/llvm.h: -------------------------------------------------------------------------------- 1 | #ifndef _STUFF_LLVM_H_ 2 | #define _STUFF_LLVM_H_ 3 | 4 | #include "llvm-c/Disassembler.h" 5 | 6 | void* llvm_load(void); 7 | 8 | __private_extern__ LLVMDisasmContextRef llvm_create_disasm( 9 | const char *TripleName, 10 | const char *CPU, 11 | void *DisInfo, 12 | int TagType, 13 | LLVMOpInfoCallback GetOpInfo, 14 | LLVMSymbolLookupCallback SymbolLookUp); 15 | 16 | __private_extern__ void llvm_disasm_dispose( 17 | LLVMDisasmContextRef DC); 18 | 19 | __private_extern__ size_t llvm_disasm_instruction( 20 | LLVMDisasmContextRef DC, 21 | uint8_t *Bytes, 22 | uint64_t BytesSize, 23 | uint64_t Pc, 24 | char *OutString, 25 | size_t OutStringSize); 26 | 27 | __private_extern__ int llvm_disasm_set_options( 28 | LLVMDisasmContextRef DC, 29 | uint64_t Options); 30 | 31 | __private_extern__ const char *llvm_disasm_version_string( 32 | void); 33 | 34 | __private_extern__ int llvm_disasm_new_getopinfo_abi( 35 | void); 36 | 37 | #endif /* _STUFF_LLVM_H_ */ 38 | -------------------------------------------------------------------------------- /include/stuff/lto.h: -------------------------------------------------------------------------------- 1 | #ifndef _STUFF_LTO_H_ 2 | #define _STUFF_LTO_H_ 3 | 4 | #include "stuff/arch.h" 5 | 6 | #ifdef LTO_SUPPORT 7 | 8 | __private_extern__ int is_llvm_bitcode_from_memory( 9 | char *addr, 10 | uint32_t size, 11 | struct arch_flag *arch_flag, 12 | void **mod); /* maybe NULL */ 13 | 14 | __private_extern__ uint32_t lto_get_nsyms( 15 | void *mod); 16 | 17 | __private_extern__ int lto_toc_symbol( 18 | void *mod, 19 | uint32_t symbol_index, 20 | int commons_in_toc); 21 | 22 | __private_extern__ void lto_get_nlist_64( 23 | struct nlist_64 *nl, 24 | void *mod, 25 | uint32_t symbol_index); 26 | 27 | __private_extern__ const char * lto_symbol_name( 28 | void *mod, 29 | uint32_t symbol_index); 30 | 31 | __private_extern__ void lto_free( 32 | void *mod); 33 | 34 | #endif /* LTO_SUPPORT */ 35 | 36 | #endif /* _STUFF_LTO_H_ */ 37 | -------------------------------------------------------------------------------- /include/stuff/macosx_deployment_target.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #include 24 | 25 | struct macosx_deployment_target { 26 | uint32_t major; /* major version */ 27 | uint32_t minor; /* minor version (if any or zero) */ 28 | char *name; /* name for printing */ 29 | }; 30 | 31 | __private_extern__ void get_macosx_deployment_target( 32 | struct macosx_deployment_target *value); 33 | 34 | __private_extern__ void put_macosx_deployment_target( 35 | char *target); 36 | -------------------------------------------------------------------------------- /include/stuff/print.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | #import 28 | 29 | __private_extern__ void print( 30 | const char *format, ...) 31 | #ifdef __GNUC__ 32 | __attribute__ ((format (printf, 1, 2))) 33 | #endif 34 | ; 35 | __private_extern__ void vprint( 36 | const char *format, va_list ap) 37 | __attribute__((format(printf, 1, 0))); 38 | -------------------------------------------------------------------------------- /include/stuff/reloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | #import 28 | #import "stuff/bool.h" 29 | 30 | __private_extern__ uint32_t reloc_pair_r_type( 31 | cpu_type_t cputype); 32 | __private_extern__ enum bool reloc_has_pair( 33 | cpu_type_t cputype, 34 | uint32_t r_type); 35 | __private_extern__ enum bool reloc_is_sectdiff( 36 | cpu_type_t cputype, 37 | uint32_t r_type); 38 | -------------------------------------------------------------------------------- /include/stuff/symbol.h: -------------------------------------------------------------------------------- 1 | #ifndef _STUFF_SYMBOL_H_ 2 | #define _STUFF_SYMBOL_H_ 3 | 4 | #include 5 | 6 | struct symbol { 7 | char *name; 8 | char *indr_name; 9 | uint64_t n_value; 10 | int is_thumb; 11 | }; 12 | 13 | #endif /* _STUFF_SYMBOL_H_ */ 14 | -------------------------------------------------------------------------------- /include/stuff/symbol_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #include 24 | #include 25 | 26 | /* 27 | * Data structures to perform selective stripping of symbol table entries. 28 | */ 29 | struct symbol_list { 30 | char *name; /* name of the global symbol */ 31 | void *sym; /* pointer to the nlist structure for this symbol */ 32 | enum bool seen; /* set if the symbol is seen in the input file */ 33 | }; 34 | 35 | __private_extern__ void setup_symbol_list( 36 | char *file, 37 | struct symbol_list **list, 38 | uint32_t *size); 39 | 40 | __private_extern__ int symbol_list_bsearch( 41 | const char *name, 42 | const struct symbol_list *sym); 43 | -------------------------------------------------------------------------------- /include/stuff/unix_standard_mode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #include "stuff/bool.h" 24 | 25 | __private_extern__ enum bool get_unix_standard_mode( 26 | void); 27 | -------------------------------------------------------------------------------- /include/stuff/version_number.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | __private_extern__ enum bool get_version_number( 24 | const char *flag, 25 | const char *argument, 26 | uint32_t *value); 27 | -------------------------------------------------------------------------------- /include/stuff/vm_flush_cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | #import 28 | __private_extern__ kern_return_t vm_flush_cache( 29 | mach_port_t target_task, 30 | vm_address_t address, 31 | vm_size_t size); 32 | -------------------------------------------------------------------------------- /include/stuff/write64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #include 25 | 26 | /* 27 | * This is a drop-in write(2) replacement that does the right thing when trying 28 | * to write out 31-bits or more of data. While the write(2) system call has 29 | * 64-bit wide arguments, it only honors 31 bits for historical reasons. 30 | * This restriction does not appear to be unique to Darwin. 31 | */ 32 | ssize_t write64(int fildes, const void *buf, size_t nbyte); 33 | -------------------------------------------------------------------------------- /include/stuff/xcode.h: -------------------------------------------------------------------------------- 1 | // 2 | // xcode.h 3 | // cctools 4 | // 5 | // Created by Michael Trent on 4/24/20. 6 | // 7 | 8 | const char* xcode_developer_path(void); 9 | -------------------------------------------------------------------------------- /ld/arm_reloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | /* 28 | * Global types, variables and routines declared in the file arm_reloc.c. 29 | * 30 | * The following include file need to be included before this file: 31 | * #include 32 | * #include "section.h" 33 | */ 34 | __private_extern__ void arm_reloc( 35 | char *contents, 36 | struct relocation_info *relocs, 37 | struct section_map *section_map, 38 | struct live_refs *refs, 39 | unsigned long reloc_index); 40 | -------------------------------------------------------------------------------- /ld/coalesced_sections.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | __private_extern__ void coalesced_section_merge( 28 | void *data, 29 | struct merged_section *ms, 30 | struct section *s, 31 | struct section_map *section_map, 32 | enum bool redo_live); 33 | 34 | __private_extern__ void coalesced_section_order( 35 | void *data, 36 | struct merged_section *ms); 37 | 38 | __private_extern__ void coalesced_section_reset_live( 39 | void *data, 40 | struct merged_section *ms); 41 | -------------------------------------------------------------------------------- /ld/hash_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | /* 24 | * hash_string() compute a hash code for the specified null terminated string. 25 | * The caller can then mod it with the size of the hash table. 26 | */ 27 | static 28 | inline 29 | unsigned long 30 | hash_string( 31 | char *key, 32 | unsigned long *len) 33 | { 34 | char *cp; 35 | long k; 36 | 37 | cp = key; 38 | k = 0; 39 | while(*cp) 40 | k = (((k << 1) + (k >> 14)) ^ (*cp++)) & 0x3fff; 41 | if(len != NULL) 42 | *len = cp - key; 43 | return(k); 44 | } 45 | -------------------------------------------------------------------------------- /ld/hppa_reloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | /* 28 | * Global types, variables and routines declared in the file hppa_reloc.c. 29 | * 30 | * The following include file need to be included before this file: 31 | * #include 32 | * #include "section.h" 33 | */ 34 | __private_extern__ void hppa_reloc( 35 | char *contents, 36 | struct relocation_info *relocs, 37 | struct section_map *map); 38 | -------------------------------------------------------------------------------- /ld/i860_reloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | /* 28 | * Global types, variables and routines declared in the file i860_reloc.c. 29 | * 30 | * The following include file need to be included before this file: 31 | * #include 32 | * #include "section.h" 33 | */ 34 | __private_extern__ void i860_reloc( 35 | char *contents, 36 | struct relocation_info *relocs, 37 | struct section_map *map); 38 | -------------------------------------------------------------------------------- /ld/librld.ofileList: -------------------------------------------------------------------------------- 1 | librld.o 2 | -------------------------------------------------------------------------------- /ld/m88k_reloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | /* 28 | * Global types, variables and routines declared in the file m88k_reloc.c. 29 | * 30 | * The following include file need to be included before this file: 31 | * #include 32 | * #include "section.h" 33 | */ 34 | __private_extern__ void m88k_reloc( 35 | char *contents, 36 | struct relocation_info *relocs, 37 | struct section_map *map); 38 | -------------------------------------------------------------------------------- /ld/ppc_reloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | /* 28 | * Global types, variables and routines declared in the file ppc_reloc.c. 29 | * 30 | * The following include file need to be included before this file: 31 | * #include 32 | * #include "section.h" 33 | */ 34 | __private_extern__ void ppc_reloc( 35 | char *contents, 36 | struct relocation_info *relocs, 37 | struct section_map *section_map, 38 | struct live_refs *refs, 39 | unsigned long reloc_index); 40 | -------------------------------------------------------------------------------- /ld/sparc_reloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | /* 28 | * Global types, variables and routines declared in the file sparc_reloc.c. 29 | * 30 | * The following include file need to be included before this file: 31 | * #include 32 | * #include "section.h" 33 | */ 34 | __private_extern__ void sparc_reloc( 35 | char *contents, 36 | struct relocation_info *relocs, 37 | struct section_map *map); 38 | 39 | -------------------------------------------------------------------------------- /ld/uuid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #if defined(__MWERKS__) && !defined(__private_extern__) 24 | #define __private_extern__ __declspec(private_extern) 25 | #endif 26 | 27 | #include 28 | #include 29 | #if !(defined(KLD) && defined(__STATIC__)) 30 | #include 31 | #else 32 | #include 33 | #endif /* !(defined(KLD) && defined(__STATIC__)) */ 34 | 35 | /* 36 | * uuid() is called to set the uuid[] bytes for the uuid load command. 37 | */ 38 | __private_extern__ 39 | void 40 | uuid( 41 | uint8_t *uuid) 42 | { 43 | #if defined(KLD) && defined(__STATIC__) 44 | memset(uuid, '\0', sizeof(struct uuid_command)); 45 | #else 46 | uuid_generate_random((void *)uuid); 47 | #endif 48 | } 49 | -------------------------------------------------------------------------------- /ld/uuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | /* 25 | * uuid() is called to set the uuid[] bytes for the uuid load command. 26 | */ 27 | __private_extern__ void uuid( 28 | uint8_t *uuid); 29 | -------------------------------------------------------------------------------- /libmacho/dylib.ofileList: -------------------------------------------------------------------------------- 1 | arch.o 2 | getsecbyname.o 3 | getsegbyname.o 4 | get_end.o 5 | swap.o 6 | i386_swap.o 7 | m68k_swap.o 8 | sparc_swap.o 9 | ppc_swap.o 10 | -------------------------------------------------------------------------------- /libmacho/shlib.ofileList: -------------------------------------------------------------------------------- 1 | arch.o 2 | getmachhead.o 3 | getsecbyname.o 4 | getsegbyname.o 5 | get_end.o 6 | swap.o 7 | -------------------------------------------------------------------------------- /libstuff/apple_version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2020 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | /* 24 | * apple_version.c 25 | * cctools libstuff 26 | * 27 | * Created by Michael Trent on 12/20/18. 28 | */ 29 | 30 | #ifndef CURRENT_PROJECT_VERSION 31 | #define CURRENT_PROJECT_VERSION "cctools-localbuild" 32 | #endif /* CURRENT_PROJECT_VERSION */ 33 | 34 | const char apple_version[] = "" CURRENT_PROJECT_VERSION; 35 | -------------------------------------------------------------------------------- /libstuff/arch_usage.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #ifndef RLD 24 | #include /* first to get rid of pre-comp warning */ 25 | #include 26 | #include "stuff/arch.h" 27 | #include "stuff/errors.h" 28 | 29 | /* 30 | * arch_usage() is called when an unknown architecture flag is encountered. 31 | * It prints the currently know architecture flags on stderr. 32 | */ 33 | __private_extern__ 34 | void 35 | arch_usage(void) 36 | { 37 | unsigned long i; 38 | const struct arch_flag *arch_flags; 39 | 40 | arch_flags = get_arch_flags(); 41 | fprintf(stderr, "%s: known architecture flags are:", progname); 42 | for(i = 0; arch_flags[i].name != NULL; i++){ 43 | fprintf(stderr, " %s", arch_flags[i].name); 44 | } 45 | fprintf(stderr, "\n"); 46 | } 47 | #endif /* !defined(RLD) */ 48 | -------------------------------------------------------------------------------- /libstuff/hash_string.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #include 24 | #include "stuff/hash_string.h" 25 | /* 26 | * A hash function used for converting a string into a single number. It is 27 | * then usually mod'ed with the hash table size to get an index into the hash 28 | * table. 29 | */ 30 | __private_extern__ 31 | int32_t 32 | hash_string( 33 | char *key) 34 | { 35 | char *cp; 36 | int32_t k; 37 | 38 | cp = key; 39 | k = 0; 40 | while(*cp) 41 | k = (((k << 1) + (k >> 14)) ^ (*cp++)) & 0x3fff; 42 | return(k); 43 | } 44 | -------------------------------------------------------------------------------- /libstuff/print.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | #ifndef RLD 24 | #include 25 | #include 26 | #include "stuff/print.h" 27 | 28 | /* 29 | * All printing of all messages for ofile functions goes through this function. 30 | * It is broken out here so it can be overridden for some uses. 31 | */ 32 | __private_extern__ 33 | void 34 | vprint( 35 | const char *format, 36 | va_list ap) 37 | { 38 | vfprintf(stderr, format, ap); 39 | } 40 | 41 | /* 42 | * The print function that just calls the above vprint() function. 43 | */ 44 | __private_extern__ 45 | void 46 | print( 47 | const char *format, 48 | ...) 49 | { 50 | va_list ap; 51 | 52 | va_start(ap, format); 53 | vprint(format, ap); 54 | va_end(ap); 55 | } 56 | #endif /* !defined(RLD) */ 57 | -------------------------------------------------------------------------------- /libstuff/xcode.c: -------------------------------------------------------------------------------- 1 | // 2 | // xcode.c 3 | // stuff 4 | // 5 | // Created by Michael Trent on 4/24/20. 6 | // 7 | 8 | #include "stuff/write64.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | const char* xcode_developer_path(void) 17 | { 18 | static const char* xc_dev_path; 19 | 20 | if (!xc_dev_path) { 21 | void* handle = dlopen("/usr/lib/libxcselect.dylib", RTLD_NOW); 22 | if (handle) { 23 | bool (*xc_get_path)(char *buffer, int buffer_size, 24 | bool *was_environment, bool *was_cltools, 25 | bool *was_default); 26 | xc_get_path = dlsym(handle, "xcselect_get_developer_dir_path"); 27 | if (xc_get_path) { 28 | char path[MAXPATHLEN]; 29 | bool ignore; 30 | if (xc_get_path(path, MAXPATHLEN, &ignore, &ignore, &ignore)) { 31 | xc_dev_path = (const char*)strdup(path); 32 | } 33 | } 34 | } 35 | } 36 | 37 | return xc_dev_path; 38 | } 39 | -------------------------------------------------------------------------------- /libstuff_test/get_arch_from_host_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // get_arch_from_host_test.c 3 | // libstuff_test 4 | // 5 | // Created by Michael Trent on 1/21/19. 6 | // 7 | 8 | #include "test_main.h" 9 | 10 | #include "stuff/arch.h" 11 | 12 | static void test_get_arch_from_host(void) 13 | { 14 | struct arch_flag family; 15 | struct arch_flag specific; 16 | 17 | // it's difficult to test the active host without knowing what it is. 18 | int res = get_arch_from_host(&family, &specific); 19 | check_nonzero("get_arch_from_host result", res); 20 | check_nonzero("family cputype", family.cputype); 21 | check_nonzero("specific cputype", specific.cputype); 22 | } 23 | 24 | static int test_main(void) 25 | { 26 | int err = 0; 27 | 28 | if (!err) err = test_add("test get_arch_from_host", test_get_arch_from_host); 29 | 30 | return err; 31 | } 32 | -------------------------------------------------------------------------------- /libstuff_test/libstuff_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // libstuff_test 4 | // 5 | // Created by Michael Trent on 1/19/19. 6 | // 7 | 8 | #include "test.h" 9 | 10 | #include "stuff/errors.h" 11 | 12 | /* used by error routines as the name of this program */ 13 | char *progname = NULL; 14 | 15 | int main(int argc, const char * argv[]) 16 | { 17 | progname = (char*)argv[0]; 18 | 19 | // run the tests 20 | return test_run(); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /libstuff_test/null_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // null_test.cpp 3 | // libstuff_test 4 | // 5 | // Created by Michael Trent on 1/19/19. 6 | // 7 | 8 | #include "test_main.h" 9 | 10 | static void test_null(void) 11 | { 12 | ; 13 | } 14 | 15 | int test_main(void) 16 | { 17 | return test_add("test harness initialization", test_null); 18 | } 19 | -------------------------------------------------------------------------------- /libstuff_test/test_main.h: -------------------------------------------------------------------------------- 1 | // 2 | // test_main.h 3 | // cctools 4 | // 5 | // Created by Michael Trent on 5/25/19. 6 | // 7 | // When creating a new test, include this header, call the TEST_INTIALIZE 8 | // macro, then define a function test_main() like so: 9 | // 10 | // static int test_main(void) 11 | // { 12 | // int err = 0; 13 | // if (!err) err = test_add("some test", test_some_test); 14 | // return err; 15 | // } 16 | // 17 | // individal tests take and return void, and call check_* or test_* functions 18 | // to report failure status. 19 | 20 | #ifndef test_case_h 21 | #define test_case_h 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include "test.h" 28 | 29 | #define TEST_INITIALIZE \ 30 | static int test_main(void);\ 31 | __attribute__((constructor)) static void init(void)\ 32 | {\ 33 | test_register_initializer(0, test_main);\ 34 | }\ 35 | 36 | TEST_INITIALIZE 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* test_case_h */ 43 | -------------------------------------------------------------------------------- /libstuff_test/test_util.c: -------------------------------------------------------------------------------- 1 | // 2 | // test_util.c 3 | // libstuff_test 4 | // 5 | // Created by Michael Trent on 5/31/19. 6 | // 7 | 8 | #include "test_util.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int test_write_tmp_data(const void* data, size_t size, char** name_p) 17 | { 18 | if (!data || !name_p) { 19 | errno = EINVAL; 20 | return -1; 21 | } 22 | 23 | char* name = strdup("/tmp/libstuff_test.XXXXXX"); 24 | int fd = mkstemp(name); 25 | if (-1 == fd) { 26 | fprintf(stderr, "error: cannot make temporary file: %s\n", 27 | strerror(errno)); 28 | free(name); 29 | return -1; 30 | } 31 | 32 | const unsigned char* uchars = (const unsigned char*)data; 33 | while (size) { 34 | const size_t limit = 0x7FFFFFFF; 35 | size_t towrite = size < limit ? size : limit; 36 | ssize_t wrote = write(fd, uchars, towrite); 37 | if (-1 == wrote) { 38 | fprintf(stderr, "error: cannot write to file %s: %s\n", name, 39 | strerror(errno)); 40 | free(name); 41 | return -1; 42 | } 43 | else if (0 == wrote) { 44 | break; 45 | } 46 | else { 47 | size -= wrote; 48 | uchars += wrote; 49 | } 50 | } 51 | 52 | *name_p = name; 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /libstuff_test/test_util.h: -------------------------------------------------------------------------------- 1 | // 2 | // test_util.h 3 | // libstuff_test 4 | // 5 | // Created by Michael Trent on 5/31/19. 6 | // 7 | 8 | #ifndef test_util_h 9 | #define test_util_h 10 | 11 | #include 12 | 13 | // test_write_tmp_data 14 | // write data of size to a file in /tmp. The path to the file will be returned 15 | // in *name, which will need to be deallocated via free(). Returns 0 on success 16 | // or -1 on error. 17 | int test_write_tmp_data(const void* data, size_t size, char** name); 18 | 19 | #endif /* test_util_h */ 20 | -------------------------------------------------------------------------------- /man/NSObjectFileImage_priv.3: -------------------------------------------------------------------------------- 1 | .TH NSObjectFileImage 3 "July 9, 2003" "Apple Computer, Inc." 2 | .SH NAME 3 | NSObjectFileImage_priv \- programmatic interface for working with Mach-O files 4 | .SH SYNOPSIS 5 | .nf 6 | .PP 7 | #include 8 | .sp .5 9 | extern enum DYLD_BOOL 10 | NSFindSectionAndOffsetInObjectFileImage( 11 | NSObjectFileImage objectFileImage, 12 | unsigned long imageOffset, 13 | const char** segmentName, /* can be NULL */ 14 | const char** sectionName, /* can be NULL */ 15 | unsigned long* sectionOffset) /* can be NULL */ 16 | .sp .5 17 | extern enum DYLD_BOOL 18 | NSHasModInitObjectFileImage( 19 | NSObjectFileImage objectFileImage); 20 | .fi 21 | .SH DESCRIPTION 22 | .PP 23 | These routines are the programmatic interface for working with Mach-O files. 24 | They bring the Mach-O file into memory and the API allows the file to 25 | be inspected or loaded into the program. On creation of an object file image 26 | it is checked to insure it is a valid format and it is compatible with the host 27 | machine's cpu architecture. 28 | .PP 29 | .PP 30 | .I NSFindSectionAndOffsetInObjectFileImage 31 | is supplied an imageOffset into an ObjectFileImage and returns 32 | via parameters the segment/section name and offset into that section of 33 | that imageOffset. It returns FALSE if the imageOffset is not 34 | in any section, otherwise TRUE. You can used the resulting sectionOffset to 35 | index into the data returned by NSGetSectionDataInObjectFileImage. 36 | .PP 37 | .I NSHasModInitObjectFileImage 38 | returns TRUE if the NSObjectFileImage has any module initialization routines 39 | and FALSE otherwise. 40 | 41 | .SH ALSO SEE 42 | NSObjectFileImage(3), NSModule(3), dyld(3) 43 | -------------------------------------------------------------------------------- /man/a.out.5: -------------------------------------------------------------------------------- 1 | .so man5/Mach-O.5 2 | -------------------------------------------------------------------------------- /man/as.1: -------------------------------------------------------------------------------- 1 | .TH AS 1 "August 23, 2023" "Apple Inc." 2 | .SH NAME 3 | as \- assembler 4 | .SH SYNOPSIS 5 | .B as 6 | [ 7 | .I "option \&..." 8 | ] [ 9 | .I "file \&..." 10 | ] 11 | .SH DESCRIPTION 12 | The 13 | .I as 14 | command is deprecated. It is now calls clang to use clang's "intergated assembler". 15 | .PP 16 | Clang will automatically run its assembler on files with a .s extension. 17 | So you can replace: "as -arch arm64 foo.s -o foo.o" with "clang -arch arm64 foo.s -o foo.o" 18 | .SH "SEE ALSO" 19 | cc(1), ld(1), nm(1), otool(1), arch(3), Mach-O(5) 20 | -------------------------------------------------------------------------------- /man/bitcode_strip.1: -------------------------------------------------------------------------------- 1 | .TH BITCODE_STRIP 1 "June 23, 2020" "Apple, Inc." 2 | .SH NAME 3 | bitcode_strip \- remove or leave the bitcode segment in a Mach-O file 4 | .SH SYNOPSIS 5 | .B bitcode_strip 6 | .I input 7 | [ 8 | .B \-r 9 | | 10 | .B \-m 11 | | 12 | .B \-l 13 | ] [ 14 | .B \-v 15 | ] [ 16 | .B \-keep_cs 17 | ] 18 | .BI \-o " output" 19 | .SH DESCRIPTION 20 | .I bitcode_strip 21 | strips Mach-O files and Universal files containing LLVM bitcode, either by 22 | removing the bitcode or by removing the native executable code. If the Mach-O 23 | file or architecture in an Universal file does not have a bitcode segment it 24 | is left essentially unchanged. By default 25 | .B bitcode_strip 26 | will remove the code signature load commands from the output file as the 27 | code signature is no longer valid. 28 | .SH OPTIONS 29 | .TP 30 | .B \-r 31 | Remove the __LLVM bitcode segment entirely. 32 | .TP 33 | .B \-m 34 | Remove the bitcode from the __LLVM segment, leaving behind a marker. 35 | .TP 36 | .B \-l 37 | Remove all of the native executable code, leaving the LLVM bitcode behind. In 38 | this case, 39 | .B bitcode_strip 40 | will take care to preserve the (__TEXT,__info_plist) section while removing the 41 | rest of the __TEXT segment. 42 | .TP 43 | .B \-v 44 | Print the arguments passed to other tools run by 45 | .B bitcode_strip 46 | when processing bitcode files. 47 | .TP 48 | .B \-keep_cs 49 | Preserve the codesign load commands in the output binary, even though the code 50 | signature is no longer valid. This can be useful when using 51 | .BR codesign (1) 52 | .B \-preserve-metadata 53 | to resign the binary. 54 | .TP 55 | .BI \-o " output" 56 | specifies the output file as 57 | .I output. 58 | .TP 59 | .BI input 60 | specifies the input Mach-O or Universal file to operate on. 61 | .SH "SEE ALSO" 62 | .BR codesign (1), 63 | .BR otool (1). 64 | -------------------------------------------------------------------------------- /man/check_dylib.1: -------------------------------------------------------------------------------- 1 | .TH CHECK_DYLIB l "September 10, 2001" "Apple Computer, Inc." 2 | .SH NAME 3 | check_dylib \- perform checks on a dynamic library file 4 | .SH SYNOPSIS 5 | .B check_dylib 6 | filename \-install_name 7 | .I install_name 8 | \-seg_addr_table 9 | .I seg_addr_table 10 | \-seg_addr_table_filename 11 | .I path_name 12 | .sp .5 13 | .SH DESCRIPTION 14 | .I Check_dylib 15 | is a tool used by Apple's Build and Integration team to perform checks on a 16 | Mach-O dynamic library as part of the build process. The checks are performed 17 | and 18 | .IR check_dylib (l) 19 | returns the status of the checks as exit values. 20 | .PP 21 | The checks are performed in the following order: 22 | .PP 23 | If the install name of the dynamic library does not start with @executable_path 24 | check the install name of the dynamic library file against the specified 25 | .B \-install_name 26 | argument and if it does not match it exit with a value of 2. 27 | .PP 28 | Check the segment address table specified by 29 | .B \-seg_addr_table 30 | for an entry with the 31 | .I path_name 32 | argument of the 33 | .B \-seg_addr_table_filename 34 | and if one is not found in the table exit with a value of 3. 35 | .PP 36 | Check the dynamic library file's address against the address in the matching 37 | entry in the segment address table specified by 38 | .B \-seg_addr_table 39 | and 40 | .B \-seg_addr_table_filename 41 | and if it does not match exit with a value of 4. 42 | .PP 43 | Check the address of the dynamic library and if it is zero exit with a value 44 | of 5. 45 | .PP 46 | If there is any other errors 47 | .IR check_dylib (l) 48 | exits with a value of 1. If no checks fail then 49 | .IR check_dylib (l) 50 | exits with a value of 0. 51 | .SH "SEE ALSO" 52 | seg_addr_table(l), doug(0) 53 | -------------------------------------------------------------------------------- /man/codesign_allocate.1: -------------------------------------------------------------------------------- 1 | .TH CODESIGN_ALLOCATE 1 "April 17, 2017" "Apple, Inc." 2 | .SH NAME 3 | codesign_allocate \- add code signing data to a Mach-O file 4 | .SH SYNOPSIS 5 | .B codesign_allocate 6 | \-i oldfile [ \-a arch size ]... [ \-A cputype cpusubtype size ]... \-o newfile 7 | .SH DESCRIPTION 8 | .I codesign_allocate 9 | sets up a Mach-O file used by the dynamic linker so space for code signing data 10 | of the specified size for the specified architecture is embedded in the Mach-O 11 | file. The program must be passed one \-a argument or one \-A argument for each 12 | architecture in a universal file, or exactly one \-a or \-A for a thin file. 13 | .TP 14 | .BI \-i " oldfile" 15 | specifies the input file as 16 | .I oldfile. 17 | .TP 18 | .BI \-o " newfile" 19 | specifies the output file as 20 | .I newfile. 21 | .TP 22 | .BI \-a " arch size" 23 | specifies for the architecture 24 | .I arch 25 | that the size of the code signing data is to be 26 | .I size. 27 | The value of 28 | .I size 29 | must be a multiple of 16. 30 | .TP 31 | .BI \-A " cputype cpusubtype size" 32 | specifies for the architecture as a pair of decimal integers for the cputype and 33 | cpusubtype that the size of the code signing data is to be 34 | .I size. 35 | The value of 36 | .I size 37 | must be a multiple of 16. 38 | .TP 39 | .BI \-r 40 | remove the code signature data and the LC_CODE_SIGNATURE load command. This 41 | is the same as specifiying the 42 | .B -a 43 | or 44 | .B -A 45 | option with a 46 | .I size 47 | of zero. 48 | .TP 49 | .BI \-p 50 | page align the code signature data by padding string table and changing its 51 | size. This is not the default as 52 | .IR codesign (1) 53 | currently can't use this option. 54 | -------------------------------------------------------------------------------- /man/ctf_insert.1: -------------------------------------------------------------------------------- 1 | .TH CTF_INSERT 1 "June 23, 2020" "Apple, Inc." 2 | .SH NAME 3 | ctf_insert \- insert Compact C Type Format data into a mach_kernel file 4 | .SH SYNOPSIS 5 | .B ctf_insert 6 | input [ \-arch arch file ]... \-o output 7 | .SH DESCRIPTION 8 | .I ctf_insert 9 | inserts CTF (Compact C Type Format) data into a mach_kernel binary, storing the 10 | data in a newly created (__CTF,__ctf) section. This section must not be 11 | present in the input file. 12 | .IR ctf_insert (1) 13 | must be passed one 14 | .B \-arch 15 | argument for each architecture in a universal file, or 16 | exactly one 17 | .B \-arch 18 | for a thin file. 19 | .TP 20 | .BI input 21 | specifies the input mach_kernel. 22 | .TP 23 | .BI \-o " output" 24 | specifies the output file. 25 | .TP 26 | .BI \-arch " arch file" 27 | specifies a file of CTF data to be used for the specified 28 | .I arch 29 | in a Mach-O or universal file. The file's content will be stored in a newly 30 | created (__CTF,__ctf) section. 31 | .SH "SEE ALSO" 32 | .BR otool (1), 33 | .BR segedit (1). 34 | -------------------------------------------------------------------------------- /man/end.3: -------------------------------------------------------------------------------- 1 | .so man3/get_end.3 2 | -------------------------------------------------------------------------------- /man/getsectbynamefromheader.3: -------------------------------------------------------------------------------- 1 | .so man3/getsectbyname.3 2 | -------------------------------------------------------------------------------- /man/getsectdata.3: -------------------------------------------------------------------------------- 1 | .so man3/getsectbyname.3 2 | -------------------------------------------------------------------------------- /man/getsectdatafromheader.3: -------------------------------------------------------------------------------- 1 | .so man3/getsectbyname.3 2 | -------------------------------------------------------------------------------- /man/getsegbyname.3: -------------------------------------------------------------------------------- 1 | .TH GETSEGBYNAME 3 "October 3, 2008" "Apple, Inc." 2 | .SH NAME 3 | getsegbyname \- get the segment command for the named segment 4 | .SH SYNOPSIS 5 | .nf 6 | \fB#include \fR 7 | .PP 8 | const struct segment_command *\fBgetsegbyname\fR(const char *\fIsegname\fR); 9 | .fi 10 | .SH DESCRIPTION 11 | This routine returns the segment_command structure for the named segment if it 12 | exists in the Mach-O (Mach object) executable 13 | .IR getsegbyname (3) 14 | is linked into. Otherwise 15 | .IR getsegbyname (3) 16 | returns 17 | .SM NULL. 18 | It uses the link editor defined symbol _mh_execute_header and 19 | just looks through the load commands. Since these are mapped into the 20 | .SM \_\|\_TEXT 21 | segment they are read-only and thus 22 | .I const 23 | by default. 24 | If this is to be used in executables linked with 25 | .B \-pie 26 | then the value return by the call to 27 | .IR _dyld_get_image_vmaddr_slide (0) 28 | will need to be added to the 29 | .B vmaddr 30 | field of the segment_command struct. 31 | .SH "SEE ALSO" 32 | end(3), getsectbyname(3) 33 | -------------------------------------------------------------------------------- /man/mtoc.1: -------------------------------------------------------------------------------- 1 | .TH MTOC 1 "July 21, 2017" "Apple, Inc." 2 | .SH NAME 3 | mtoc \- convert a Mach-O file to a PECOFF file 4 | .SH SYNOPSIS 5 | .B mtoc 6 | [ \-subsystem type ] [ \-section_alignment value ] [ \-align value ] [ \-version major.minor ] [ \-d filename ] input output 7 | .SH DESCRIPTION 8 | .I mtoc 9 | converts the 10 | .I input 11 | EFI file built as a Mach-O file into an 12 | .I output 13 | PEFOFF file. 14 | .TP 15 | .BI \-subsystem " type" 16 | specifies the EFI subsystem 17 | .I type 18 | which can be 19 | .IR application , 20 | .I boot 21 | or 22 | .I runtime. 23 | The default is 24 | .IR application . 25 | .TP 26 | .BI "\-section_alignment" " value" 27 | Specifies the PECOFF section alignment. 28 | .I value 29 | is a hexadecimal number that must be an integral power of 2. 30 | The default is the Mac OS X target pagesize (1000 hex). This value should 31 | match the value used for 32 | .B "\-segalign" 33 | when linking the Mach-O file. 34 | .TP 35 | .BI "\-align" " value" 36 | Specifies the PECOFF file and section alignment. 37 | .I value 38 | is a hexadecimal number that must be an integral power of 2. 39 | The default is 400 hex. This value should match the value used for 40 | .B "\-segalign" 41 | when linking the Mach-O file. 42 | .TP 43 | .BI "\-version" " major.minor" 44 | Specifies the PECOFF 45 | .I major 46 | and 47 | .I minor 48 | versions for the MajorImageVersion and MinorImageVersion fields. 49 | .TP 50 | .BI "\-d " filename" 51 | Specifies the filename to be used to create a debug directory entry with. 52 | -------------------------------------------------------------------------------- /man/nm-classic.1: -------------------------------------------------------------------------------- 1 | .so man1/nm.1 2 | -------------------------------------------------------------------------------- /man/otool.1: -------------------------------------------------------------------------------- 1 | .so man1/otool-classic.1 2 | -------------------------------------------------------------------------------- /man/pagestuff.1: -------------------------------------------------------------------------------- 1 | .TH PAGESTUFF 1 "June 23, 2020" "Apple, Inc." 2 | .SH NAME 3 | pagestuff \- Mach-O file page analysis tool 4 | .SH SYNOPSIS 5 | pagestuff file [-arch arch_flag] [[-a] [-p] | [pagenumber...]] 6 | .SH DESCRIPTION 7 | .B pagestuff 8 | shows how a structure of a Mach-O or universal file corresponds 9 | to logical pages on the current system. Structural information includes 10 | the location and extent of file headers, sections and segments, symbol tables, 11 | code signatures, etc. When displaying a universal file, all architectures will 12 | be shown unless otherwise specified by the 13 | .B \-arch 14 | flag. 15 | .PP 16 | The options to 17 | .BR pagestuff (1) 18 | are: 19 | .TP 20 | .BI \-arch " arch_type" 21 | Specifies the architecture, 22 | .I arch_type, 23 | of the file for 24 | .B pagestuff 25 | to operate on when the file is a universal file. (See 26 | .BR arch (3) 27 | for the currently known 28 | .IR arch_type s.) 29 | When this option is used the logical page numbers start from the beginning of 30 | the architecture file within the universal file. 31 | .TP 32 | .BI \-pagesize " pagesize" 33 | Specifies the page size to use when computing logical page boundaries. By 34 | default 35 | .I pagestuff 36 | will use the page size of the current system. 37 | .TP 38 | .B \-a 39 | Display all pages in the file. 40 | .TP 41 | .B \-p 42 | Print a list of the sections of the specified file, offsets and lengths. 43 | When displaying a universal file, all archs will be displayed unless 44 | Print a list of the sections of the specified Mach-O file, with offsets and 45 | lengths. Note that the 46 | .BR size (1) 47 | tool displays a much more concise listing given the `-l -m -x' arguments. 48 | .SH "SEE ALSO" 49 | .BR size (1) , 50 | .BR arch (3) , 51 | .BR Mach-O (5) . 52 | -------------------------------------------------------------------------------- /man/ranlib.1: -------------------------------------------------------------------------------- 1 | .so man1/libtool.1 2 | -------------------------------------------------------------------------------- /man/size-classic.1: -------------------------------------------------------------------------------- 1 | .so man1/size.1 2 | -------------------------------------------------------------------------------- /man/size.1: -------------------------------------------------------------------------------- 1 | .TH SIZE 1 "July 28, 2005" "Apple Computer, Inc." 2 | .SH NAME 3 | size \- print the size of the sections in an object file 4 | .SH SYNOPSIS 5 | .B size 6 | [ option ... ] [ object ... ] 7 | .SH DESCRIPTION 8 | .I Size 9 | (without the 10 | .B \-m 11 | option) prints the (decimal) number of bytes required by the \_\^\_TEXT, 12 | \_\^\_DATA and \_\^\_OBJC segments. All other segments are totaled and 13 | that size is listed in the `others' column. The final two columns is 14 | the sum in decimal and hexadecimal. 15 | If no file is specified, 16 | .B a.out 17 | is used. 18 | .PP 19 | The options to 20 | .IR size (1) 21 | are: 22 | .TP 23 | .B \- 24 | Treat the remaining arguments as name of object files not options to 25 | .IR size (1). 26 | .TP 27 | .B \-m 28 | Print the sizes of the Mach-O segments and sections as well as the total sizes 29 | of the sections in each segment and the total size of the segments in the file. 30 | .TP 31 | .B \-l 32 | When used with the 33 | .B \-m 34 | option, also print the addresses and offsets of the sections and segments. 35 | .TP 36 | .B \-x 37 | When used with the 38 | .B \-m 39 | option, 40 | print the values in hexadecimal (with leading 0x's) rather than decimal. 41 | .TP 42 | .BI \-arch " arch_type" 43 | Specifies the architecture, 44 | .I arch_type, 45 | of the file for 46 | .IR size (1) 47 | to operate on when the file is a universal file. (See 48 | .IR arch (3) 49 | for the currently know 50 | .IR arch_type s.) 51 | The 52 | .I arch_type 53 | can be "all" to operate on all architectures in the file. 54 | The default is to display only the host architecture, if the file contains it; 55 | otherwise, all architectures in the file are shown. 56 | .SH "SEE ALSO" 57 | otool(1) 58 | .SH BUGS 59 | The size of common symbols can't be reflected in any of the numbers for 60 | relocatable object files. 61 | -------------------------------------------------------------------------------- /misc/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | com.apple.tool.codesign_allocate.standard 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundleName 12 | codesign_allocate 13 | CFBundleVersion 14 | 0.3 15 | Application-Group 16 | com.apple.tool.codesign_allocate 17 | 18 | 19 | -------------------------------------------------------------------------------- /misc/as: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | 3 | DIR="$(dirname "$(realpath "$0")")" 4 | 5 | # remove -q and -Q args (which clang does not support) 6 | for arg do 7 | shift 8 | [ "$arg" = "-q" ] && continue 9 | [ "$arg" = "-Q" ] && continue 10 | set -- "$@" "$arg" 11 | done 12 | 13 | # use clang driver to run clang's integrated assembler 14 | $DIR/clang -x assembler -c "$@" 15 | 16 | 17 | -------------------------------------------------------------------------------- /misc/codesign_allocate-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | com.apple.tool.codesign_allocate.standard 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundleName 12 | codesign_allocate 13 | CFBundleVersion 14 | 0.3 15 | Application-Group 16 | com.apple.tool.codesign_allocate 17 | 18 | 19 | -------------------------------------------------------------------------------- /misc/depinfo.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // depinfo 4 | // 5 | // Created by Michael Trent on 9/10/19. 6 | // 7 | 8 | #include "stuff/depinfo.h" 9 | #include "stuff/errors.h" 10 | 11 | #include 12 | #include 13 | 14 | char* progname; 15 | 16 | void usage(const char * __restrict format, ...) 17 | __attribute__((format(printf, 1, 2))); 18 | 19 | int main(int argc, const char * argv[]) 20 | { 21 | progname = (char*)*argv++; 22 | argc--; 23 | 24 | if (argc == 0) 25 | usage(NULL); 26 | 27 | int showPaths = argc > 1; 28 | while (argc > 0) 29 | { 30 | if (showPaths) 31 | printf("%s:\n", *argv); 32 | depinfo_read(*argv, DI_READ_LOG | DI_READ_NORETVAL); 33 | if (errors) 34 | return 1; 35 | argv++; 36 | argc--; 37 | } 38 | return 0; 39 | } 40 | 41 | void usage(const char * __restrict format, ...) 42 | { 43 | const char* basename = strrchr(progname, '/'); 44 | if (basename) 45 | basename++; 46 | else 47 | basename = progname; 48 | 49 | va_list args; 50 | va_start(args, format); 51 | 52 | if (format) { 53 | fprintf(stderr, "error: "); 54 | vfprintf(stderr, format, args);; 55 | fprintf(stderr, "\n"); 56 | } 57 | 58 | va_end(args); 59 | 60 | fprintf(stderr, "usage: %s ...\n", basename); 61 | 62 | exit(EXIT_FAILURE); 63 | } 64 | -------------------------------------------------------------------------------- /otool/arm64_disasm.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | #import 5 | #include "stuff/symbol.h" 6 | #include "llvm-c/Disassembler.h" 7 | 8 | extern uint32_t arm64_disassemble( 9 | char *sect, 10 | uint32_t left, 11 | uint64_t addr, 12 | uint64_t sect_addr, 13 | enum byte_sex object_byte_sex, 14 | struct relocation_info *relocs, 15 | uint32_t nrelocs, 16 | struct relocation_info *ext_relocs, 17 | uint32_t next_relocs, 18 | struct relocation_info *loc_relocs, 19 | uint32_t nloc_relocs, 20 | struct dyld_bind_info *dbi, 21 | uint64_t ndbi, 22 | enum chain_format_t chain_format, 23 | struct nlist *symbols, 24 | struct nlist_64 *symbols64, 25 | uint32_t nsymbols, 26 | struct symbol *sorted_symbols, 27 | uint32_t nsorted_symbols, 28 | char *strings, 29 | uint32_t strings_size, 30 | uint32_t *indirect_symbols, 31 | uint32_t nindirect_symbols, 32 | cpu_type_t cputype, 33 | struct load_command *load_commands, 34 | uint32_t ncmds, 35 | uint32_t sizeofcmds, 36 | char *object_addr, 37 | uint64_t object_size, 38 | enum bool verbose, 39 | LLVMDisasmContextRef dc); 40 | 41 | extern LLVMDisasmContextRef create_arm64_llvm_disassembler( 42 | cpu_subtype_t cpusubtype); 43 | extern void delete_arm64_llvm_disassembler(LLVMDisasmContextRef dc); 44 | -------------------------------------------------------------------------------- /otool/cxa_demangle.h: -------------------------------------------------------------------------------- 1 | extern 2 | char * 3 | __cxa_demangle( 4 | const char* mangled_name, 5 | char *output_buffer, 6 | size_t *length, 7 | int *status); 8 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | INSTALL_FILES = Makefile bin include run-tests test-cases 2 | EXECUTABLES_FILES = run-tests bin/exit-non-zero-pass.pl \ 3 | bin/fail-if-exit-non-zero.pl bin/fail-if-exit-zero.pl \ 4 | bin/fail-if-no-stdin.pl bin/fail-if-stdin.pl \ 5 | bin/fail-iff-exit-zero.pl bin/pass-iff-exit-non-zero.pl \ 6 | bin/pass-iff-exit-zero.pl bin/pass-iff-no-stdin.pl \ 7 | bin/pass-iff-stdin.pl bin/verify-align.pl 8 | 9 | MKDIRS = /bin/mkdir -p 10 | SRCROOT = . 11 | 12 | installsrc: 13 | $(MKDIRS) $(SRCROOT) 14 | chmod 755 $(SRCROOT) 15 | gnutar cf - $(INSTALL_FILES) | (cd $(SRCROOT); gnutar xf -) 16 | chmod -R u+rwX,go+rX $(SRCROOT)/* 17 | cd $(SRCROOT); chmod a+x $(EXECUTABLES_FILES) 18 | #cd $(SRCROOT); chmod a-w `find . -type f -print` 19 | find $(SRCROOT) -type f -exec chmod a-w '{}' \; 20 | -------------------------------------------------------------------------------- /tests/bin/exit-non-zero-pass.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # ${PASS_UNLESS} "test name" command 7 | # 8 | 9 | use strict; 10 | 11 | my $string = shift @ARGV; 12 | my $ret = system(@ARGV); 13 | my $exit_value = $ret >> 8; 14 | my $signal_num = $ret & 127; 15 | my $dumped_core = $ret & 128; 16 | my $crashed = $signal_num + $dumped_core; 17 | 18 | if(0 == $exit_value || 0 != $crashed) 19 | { 20 | printf("FAIL $string\n"); 21 | } 22 | else 23 | { 24 | printf("PASS $string\n"); 25 | } 26 | 27 | exit 0; 28 | -------------------------------------------------------------------------------- /tests/bin/fail-if-exit-non-zero.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | 5 | my $test_name = ""; 6 | if ( exists $ENV{UNIT_TEST_NAME} ) { 7 | $test_name = $ENV{UNIT_TEST_NAME}; 8 | } 9 | 10 | if(system(@ARGV) != 0) 11 | { 12 | printf("FAIL $test_name\n"); 13 | exit 1; 14 | } 15 | 16 | exit 0; 17 | -------------------------------------------------------------------------------- /tests/bin/fail-if-exit-zero.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | use strict; 4 | 5 | my $test_name = ""; 6 | if ( exists $ENV{UNIT_TEST_NAME} ) { 7 | $test_name = $ENV{UNIT_TEST_NAME}; 8 | } 9 | 10 | my $ret = system(@ARGV); 11 | my $exit_value = $ret >> 8; 12 | my $signal_num = $ret & 127; 13 | my $dumped_core = $ret & 128; 14 | my $crashed = $signal_num + $dumped_core; 15 | 16 | if(0 == $exit_value || 0 != $crashed) 17 | { 18 | printf("FAIL $test_name\n"); 19 | exit 1; 20 | } 21 | 22 | exit 0; 23 | -------------------------------------------------------------------------------- /tests/bin/fail-if-no-stdin.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # command | ${FAIL_IF_EMPTY} 7 | # 8 | 9 | use strict; 10 | 11 | my $test_name = ""; 12 | if ( exists $ENV{UNIT_TEST_NAME} ) { 13 | $test_name = $ENV{UNIT_TEST_NAME}; 14 | } 15 | 16 | if( eof STDIN ) 17 | { 18 | printf("FAIL $test_name\n"); 19 | exit 1; 20 | } 21 | 22 | exit 0; 23 | -------------------------------------------------------------------------------- /tests/bin/fail-if-stdin.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # command | ${FAIL_IF_STDIN} 7 | # 8 | 9 | use strict; 10 | 11 | my $test_name = ""; 12 | if ( exists $ENV{UNIT_TEST_NAME} ) { 13 | $test_name = $ENV{UNIT_TEST_NAME}; 14 | } 15 | 16 | if( eof STDIN ) 17 | { 18 | exit 0; 19 | } 20 | 21 | printf("FAIL $test_name\n"); 22 | exit 1; 23 | -------------------------------------------------------------------------------- /tests/bin/fail-iff-exit-zero.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # ${FALL_IFF} command 7 | # 8 | 9 | use strict; 10 | 11 | my $test_name = ""; 12 | if ( exists $ENV{UNIT_TEST_NAME} ) { 13 | $test_name = $ENV{UNIT_TEST_NAME}; 14 | } 15 | 16 | my $ret = system(@ARGV); 17 | my $exit_value = $ret >> 8; 18 | my $signal_num = $ret & 127; 19 | my $dumped_core = $ret & 128; 20 | my $crashed = $signal_num + $dumped_core; 21 | 22 | if(0 == $exit_value || 0 != $crashed) 23 | { 24 | printf("FAIL $test_name\n"); 25 | exit 1; 26 | } 27 | 28 | printf("PASS $test_name\n"); 29 | exit 0; 30 | -------------------------------------------------------------------------------- /tests/bin/pass-iff-exit-non-zero.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # ${PASS_IFF} command 7 | # 8 | 9 | use strict; 10 | 11 | my $test_name = ""; 12 | if ( exists $ENV{UNIT_TEST_NAME} ) { 13 | $test_name = $ENV{UNIT_TEST_NAME}; 14 | } 15 | 16 | my $ret = system(@ARGV); 17 | my $exit_value = $ret >> 8; 18 | my $signal_num = $ret & 127; 19 | my $dumped_core = $ret & 128; 20 | my $crashed = $signal_num + $dumped_core; 21 | 22 | if(0 == $exit_value || 0 != $crashed) 23 | { 24 | printf("FAIL $test_name\n"); 25 | exit 1; 26 | } 27 | 28 | printf("PASS $test_name\n"); 29 | exit 0; 30 | -------------------------------------------------------------------------------- /tests/bin/pass-iff-exit-zero.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # ${PASS_IFF} command 7 | # 8 | 9 | use strict; 10 | 11 | my $test_name = ""; 12 | if ( exists $ENV{UNIT_TEST_NAME} ) { 13 | $test_name = $ENV{UNIT_TEST_NAME}; 14 | } 15 | 16 | if(0 != system(@ARGV)) 17 | { 18 | printf("FAIL $test_name\n"); 19 | exit 1; 20 | } 21 | 22 | printf("PASS $test_name\n"); 23 | exit 0; 24 | -------------------------------------------------------------------------------- /tests/bin/pass-iff-no-stdin.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # command | ${PASS_IFF_EMPTY} 7 | # 8 | 9 | use strict; 10 | 11 | my $test_name = ""; 12 | if ( exists $ENV{UNIT_TEST_NAME} ) { 13 | $test_name = $ENV{UNIT_TEST_NAME}; 14 | } 15 | 16 | if( eof STDIN ) 17 | { 18 | printf("PASS $test_name\n"); 19 | exit 0; 20 | } 21 | 22 | printf("FAIL $test_name\n"); 23 | exit 1; 24 | -------------------------------------------------------------------------------- /tests/bin/pass-iff-stdin.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Usage: 5 | # 6 | # command | ${PASS_IFF_STDIN} 7 | # 8 | 9 | use strict; 10 | 11 | my $test_name = ""; 12 | if ( exists $ENV{UNIT_TEST_NAME} ) { 13 | $test_name = $ENV{UNIT_TEST_NAME}; 14 | } 15 | 16 | if( eof STDIN ) 17 | { 18 | printf("FAIL $test_name\n"); 19 | exit 1 20 | } 21 | 22 | printf("PASS $test_name\n"); 23 | exit 0; 24 | 25 | -------------------------------------------------------------------------------- /tests/data/echo.fat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/data/echo.fat -------------------------------------------------------------------------------- /tests/src/bar.c: -------------------------------------------------------------------------------- 1 | int bar(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/src/foo.c: -------------------------------------------------------------------------------- 1 | #if !defined(FOO) 2 | #define FOO foo 3 | #endif 4 | 5 | int FOO(void) 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/src/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | printf("hello, world!\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/src/hello_textexec.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __attribute__ ((section ("__TEXT_EXEC,__text,regular,pure_instructions"))) 4 | static void hello(void) 5 | { 6 | printf("hello, world!\n"); 7 | } 8 | 9 | int main(void) 10 | { 11 | hello(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/objc_hi.m: -------------------------------------------------------------------------------- 1 | #import 2 | #include 3 | 4 | @interface Hi : NSObject 5 | { 6 | int payload; 7 | } 8 | - (void)greetings; 9 | - (void)unused; 10 | @end 11 | 12 | @implementation Hi 13 | - (void)greetings 14 | { 15 | printf("hello, Objective-C!\n"); 16 | } 17 | - (void)unused 18 | { 19 | } 20 | @end 21 | 22 | int main(void) 23 | { 24 | @autoreleasepool { 25 | Hi* hi = [[Hi alloc] init]; 26 | [hi greetings]; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /tests/src/preload.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //#if defined(__LP64__) 4 | //const uint64_t data_addr = 0; 5 | //const uint32_t data_size = 0; 6 | //#else 7 | const uint32_t data_addr = 0; 8 | const uint32_t data_size = 0; 9 | //#endif 10 | 11 | char hello[32] = "hello\n"; 12 | 13 | int main(void) 14 | { 15 | static char zero[32]; 16 | int i; 17 | for (i = 0; hello[i]; ++i); 18 | return i; 19 | } 20 | -------------------------------------------------------------------------------- /tests/src/preload_bss.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const uint32_t data_addr = 0; 4 | const uint32_t data_size = 0; 5 | 6 | int main(void) 7 | { 8 | static char zero[32]; 9 | int i; 10 | for (i = 0; zero[i]; ++i); 11 | return i; 12 | } 13 | -------------------------------------------------------------------------------- /tests/src/times.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, const char* argv[]) 6 | { 7 | for(int i = 1; i < argc; ++i) { 8 | const char* path = argv[i]; 9 | struct stat sb; 10 | 11 | printf("%s\n", path); 12 | if (0 == stat(path, &sb)) { 13 | printf(" atime: %ld\t%ld\n", sb.st_atimespec.tv_sec, 14 | sb.st_atimespec.tv_nsec); 15 | printf(" mtime: %ld\t%ld\n", sb.st_mtimespec.tv_sec, 16 | sb.st_mtimespec.tv_nsec); 17 | printf(" ctime: %ld\t%ld\n", sb.st_ctimespec.tv_sec, 18 | sb.st_ctimespec.tv_nsec); 19 | printf(" btime: %ld\t%ld\n", sb.st_birthtimespec.tv_sec, 20 | sb.st_birthtimespec.tv_nsec); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/test-cases/1a_harness_test/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | ${PASS_IFF} true 8 | 9 | clean: 10 | -------------------------------------------------------------------------------- /tests/test-cases/1b_check_test/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | $(PASS_IFF) ${TESTROOT}/bin/check.pl -tv 8 | 9 | clean: 10 | -------------------------------------------------------------------------------- /tests/test-cases/as-llvm/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # smoke test for as, just to exercise some code. 4 | # 5 | # This test uses the llvm assemblers for code generation. 6 | 7 | PLATFORM = MACOS 8 | TESTROOT = ../.. 9 | include ${TESTROOT}/include/common.makefile 10 | 11 | .PHONY: all clean 12 | 13 | all: 14 | # make sure as can find clang 15 | ${AS} /dev/null 2>&1 > as.txt | echo 16 | if grep -q "not installed" as.txt;\ 17 | then\ 18 | echo XFAIL;\ 19 | false;\ 20 | fi 21 | 22 | # convert a non-trivial test binary into assembly 23 | ${CC} -arch ${ARCH} ${TESTROOT}/src/verstool.c -S -o verstool.s -O2 24 | 25 | # build the binary 26 | ${FAIL_IF_ERROR} ${AS} -arch ${ARCH} -q -o verstool.o verstool.s 2>&1 27 | ${FAIL_IF_ERROR} ${CC} -o verstool verstool.o -lsystem 2>&1 28 | 29 | # run the binary, if applicable 30 | if [ "$(ARCH)" == "x64_64" ]; \ 31 | then \ 32 | ./verstool 2>&1 | ${CHECK}; \ 33 | fi 34 | # CHECK: usage: verstool list 35 | # CHECK: write [(vm|bv) ] ... 36 | 37 | echo PASS 38 | clean: 39 | rm -rf a.out as.txt verstool.s verstool.o verstool 40 | -------------------------------------------------------------------------------- /tests/test-cases/as-symbol/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # SEED: Web: nlist entry values are truncated to 32-bits 4 | # Verify negative constants are properly sign-extended in the 64-bit assembler. 5 | 6 | PLATFORM = MACOS 7 | TESTROOT = ../.. 8 | include ${TESTROOT}/include/common.makefile 9 | 10 | .PHONY: all clean 11 | 12 | all: 13 | $(AS) -Q -arch x86_64 -o x.o x.s 2>as.stderr 14 | $(OTOOLC) -tV x.o | $(CHECK) 15 | # CHECK: 0000000000000000 movq %rax, -0x5(%rsi) 16 | # CHECK: 0000000000000004 movq %rax, -0x5(%rsi) 17 | # CHECK: 0000000000000008 movq %rax, -0x5(%rsi) 18 | # CHECK: 000000000000000c movq %rax, -0x5(%rsi) 19 | # CHECK: 0000000000000010 movq %rax, -0x5(%rsi) 20 | # CHECK: 0000000000000014 movq %rax, -0x5(%rsi) 21 | # CHECK: 0000000000000018 retq 22 | 23 | # filter the gas deprecated warning out of stderr 24 | cat as.stderr | grep -v deprecated 1>&2 | true 25 | 26 | echo PASS 27 | 28 | clean: 29 | rm -f x.o as.stderr 30 | -------------------------------------------------------------------------------- /tests/test-cases/as-symbol/x.s: -------------------------------------------------------------------------------- 1 | rightp = 8 2 | leftp = 13 3 | leftn = -leftp 4 | 5 | .text 6 | .align 2 7 | .p2align 3 8 | .globl junk 9 | junk: 10 | movq %rax,-5(%rsi) 11 | movq %rax,-13+8(%rsi) 12 | movq %rax,-13+rightp(%rsi) 13 | movq %rax,-leftp+rightp(%rsi) 14 | movq %rax,leftn+rightp(%rsi) 15 | movq %rax,rightp+leftn(%rsi) 16 | ret 17 | -------------------------------------------------------------------------------- /tests/test-cases/bitcode_strip-bigendian/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: WATCHOS 2 | 3 | .PHONY: all clean 4 | 5 | PLATFORM = WATCHOS 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | all: 10 | # compile a bitcode app 11 | ${CC} -arch arm64_32 -fembed-bitcode -o hello ${TESTROOT}/src/hello.c 12 | 13 | # verify bitcode strip works 14 | ${BITCODE_STRIP} -r -o hello.st hello 15 | ${OTOOLC} -lv hello.st | ${CHECK} 16 | 17 | # modify our file to look like a big endian arch 18 | ${TESTROOT}/bin/rewrite-macho.pl -a ppc -o hello.swap hello 19 | 20 | # verify bitcode strip still works 21 | ${BITCODE_STRIP} -r -o hello.st hello.swap 22 | ${OTOOLC} -lv hello.st | ${CHECK} 23 | # CHECK-NOT: .*(past end of file) 24 | 25 | echo PASS 26 | 27 | clean: 28 | rm -f hello hello.swap hello.st 29 | -------------------------------------------------------------------------------- /tests/test-cases/bitcode_strip-chained-binds/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: WATCHOS 2 | 3 | PLATFORM = WATCHOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | all: 8 | # compile a bitcode app with chained binds 9 | ${CC} -arch arm64_32 -fembed-bitcode -Wl,-fixup_chains -o hello \ 10 | ${TESTROOT}/src/hello.c 11 | 12 | # strip the binary 13 | ${BITCODE_STRIP} -r -o hello.st hello 14 | ${OTOOLC} -lv hello.st | ${CHECK} 15 | ${BITCODE_STRIP} -r -o hello.st hello 16 | ${OTOOLC} -lv hello.st | ${CHECK} 17 | # CHECK-NOT: .*(past end of file) 18 | 19 | ${PASS_IFF} ${CHECKSYMS} hello.st 20 | 21 | clean: 22 | rm -f hello hello.st 23 | -------------------------------------------------------------------------------- /tests/test-cases/bitcode_strip-resign/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # ER: Change "strip" tool to ad-hoc sign 3 | 4 | PLATFORM = MACOS 5 | TESTROOT = ../.. 6 | include ${TESTROOT}/include/common.makefile 7 | SRC = ${TESTROOT}/src 8 | 9 | .PHONY: all clean 10 | 11 | all: 12 | # Codesigning support for bitcode_strip was disabled to reduce risk 13 | # in the GlacierPointB release. This "echo XFAIL" can be removed in 14 | # order to renable the re-signing logic 15 | echo XFAIL 16 | 17 | ${CC} -o hello -fembed-bitcode ${SRC}/hello.c 18 | codesign -s - hello 19 | codesign --verify hello | ${CHECK} -p VERIFY 20 | # VERIFY: .*valid on disk 21 | 22 | ${BITCODE_STRIP} -r hello -o hello -keep_cs 23 | codesign --verify hello | ${CHECK} -p VERIFY 24 | 25 | echo PASS 26 | 27 | clean: 28 | rm -f hello 29 | -------------------------------------------------------------------------------- /tests/test-cases/bitcode_strip_arm64_32/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: WATCHOS 2 | # 3 | # Unable to load framework in watch app due to dyld mmap error __LINKEDIT in Segment::map() 4 | 5 | PLATFORM = WATCHOS 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | all: 10 | $(CC) -arch arm64_32 -dynamiclib -o empty.dylib -fembed-bitcode empty.c 11 | $(BITCODE_STRIP) -m -o empty2.dylib empty.dylib 12 | # otool -lv empty2.dylib | grep -A4 __LLVM > segment.txt 13 | # grep filesize segment.txt | grep 16384 | $(PASS_IFF_STDIN) 14 | $(VERIFY_ALIGN_16K) empty2.dylib | $(PASS_IFF_EMPTY) 15 | 16 | clean: 17 | rm -rf empty.dylib empty2.dylib 18 | -------------------------------------------------------------------------------- /tests/test-cases/bitcode_strip_arm64_32/empty.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/bitcode_strip_large/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: WATCHOS 2 | # 3 | # test large files rdar://43285000 4 | PLATFORM = WATCHOS 5 | TESTROOT = ../.. 6 | include ${TESTROOT}/include/common.makefile 7 | 8 | TMPDIR = /tmp/$(TEST).tmp 9 | 10 | all: 11 | # clean some local storage 12 | rm -rf $(TMPDIR) 13 | $(MKDIRS) $(TMPDIR) 14 | 15 | # make a big file of zeroes 16 | dd if=/dev/zero of=$(TMPDIR)/zeroes bs=1024000 count=1000 \ 17 | 2>&1 1>/dev/null 18 | 19 | # link our file 20 | $(CC) -arch $(ARCH) \ 21 | -Wl,-sectcreate,__ZERO,__zero1,$(TMPDIR)/zeroes \ 22 | -Wl,-sectcreate,__ZERO,__zero2,$(TMPDIR)/zeroes \ 23 | -Wl,-sectcreate,__ZERO,__zero3,$(TMPDIR)/zeroes \ 24 | -fembed-bitcode-marker \ 25 | -o $(TMPDIR)/hello ${TESTROOT}/src/hello.c 26 | 27 | # strip 28 | $(PASS_IFF) $(BITCODE_STRIP) -m -o $(TMPDIR)/hello.bs \ 29 | $(TMPDIR)/hello 30 | 31 | clean: 32 | rm -rf $(TMPDIR) 33 | -------------------------------------------------------------------------------- /tests/test-cases/codesign/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # run codesign on a new binary with the specified codesign_allocate and verify 4 | # both the codesign_allocate tool is acceptable to codesign as well as the 5 | # codesign_allocate output. 6 | # 7 | # codesign will only accept the codesign_allocae helper tool if it has been 8 | # signed by Apple. If codesign_allocate is not Apple-signed (because it was 9 | # built locally, perhaps) this test will XFAIL. 10 | 11 | PLATFORM = MACOS 12 | TESTROOT = ../.. 13 | include ${TESTROOT}/include/common.makefile 14 | 15 | all: 16 | @echo CS_ALLOC=${CS_ALLOC} 17 | @echo 18 | 19 | # compile a test file 20 | $(CC) -arch ${ARCH} -o hello ${TESTROOT}/src/hello.c 21 | 22 | # verify cs_allocate is signed by apple 23 | -codesign -v -R="anchor apple" ${CS_ALLOC}; \ 24 | status=$$?; \ 25 | if [ "$$status" != "0" ]; then \ 26 | echo "codesign is not Apple-signed"; \ 27 | echo "XFAIL"; \ 28 | else \ 29 | CODESIGN_ALLOCATE=${CS_ALLOC} ${PASS_IFF} codesign -s - hello; \ 30 | fi 31 | 32 | clean: 33 | rm -rf hello hello.cstemp 34 | -------------------------------------------------------------------------------- /tests/test-cases/codesign_allocate-bigendian/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | ARCH := `machine` 8 | 9 | all: 10 | # compile an executable 11 | ${CC} -arch ${ARCH} -o hello ${TESTROOT}/src/hello.c 12 | 13 | # test codesigning 14 | ${CS_ALLOC} -i hello -a ${ARCH} 512 -o hello.signed 15 | ${OTOOLC} -lv hello.signed | ${CHECK} 16 | 17 | # modify our file to look like a big endian arch 18 | ${TESTROOT}/bin/rewrite-macho.pl -a ppc -o hello.swap hello 19 | 20 | # test codesigning again 21 | ${CS_ALLOC} -i hello.swap -a ppc 512 -o hello.signed 22 | ${OTOOLC} -lv hello.signed | ${CHECK} 23 | # CHECK: cmd LC_CODE_SIGNATURE 24 | # CHECK-NEXT: cmdsize 16 25 | # CHECK-NEXT: dataoff \d+ 26 | # CHECK-NEXT: datasize \d+ 27 | 28 | echo PASS 29 | 30 | clean: 31 | rm -f hello hello.swap hello.signed 32 | -------------------------------------------------------------------------------- /tests/test-cases/codesign_allocate-chained-binds/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | all: 8 | # when replacing an existing code signature with a page-aligned code 9 | # signature codesign_allocate will rewrite linkedit in order to 10 | # elminate the padding between the string table and the code signature. 11 | # If the calculation is wrong, the Mach-O will be corrupt: 12 | # 13 | # checksyms: object: hello2 malformed object (code signature data at 14 | # offset 12288 with a size of 32, overlaps string table at offset 8456 15 | # with a size of 3840) 16 | # 17 | ${CC} -Wl,-fixup_chains -o hello ${TESTROOT}/src/hello.c 18 | codesign -s - hello 19 | ${FAIL_IF_ERROR} ${CHECKSYMS} hello 20 | ${CS_ALLOC} -p -i hello -o hello2 -a x86_64 32 21 | ${FAIL_IF_ERROR} ${CHECKSYMS} hello2 22 | 23 | # codesign_allocate will error "chained 24 | # fixups out of place" after stripping. 25 | # 26 | # Verify we can codesign a binary even if the chained fixups data 27 | # has been logically stripped away. 28 | ${CC} -o hello_bc -fembed-bitcode -Wl,-fixup_chains \ 29 | ${TESTROOT}/src/hello.c 30 | ${BITCODE_STRIP} -l -o hello_bc hello_bc 31 | ${FAIL_IF_ERROR} ${CS_ALLOC} -i hello_bc -o hello_bc -a ${ARCH} 16384 32 | 33 | echo PASS 34 | 35 | clean: 36 | rm -f hello hello2 hello_bc 37 | -------------------------------------------------------------------------------- /tests/test-cases/codesign_allocate_arm64_32/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: WATCHOS 2 | # 3 | # Unable to load framework in watch app due to dyld mmap error __LINKEDIT in Segment::map() 4 | 5 | PLATFORM = WATCHOS 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | all: 10 | $(CC) -arch arm64_32 -o hello ${TESTROOT}/src/hello.c 11 | $(CS_ALLOC) -i hello -a arm64_32 19136 -o hello.cstemp 12 | #$(CS_ALLOC) -i hello -A 33554444 1 19136 -o hello.cstemp 13 | $(VERIFY_ALIGN_16K) hello.cstemp | $(PASS_IFF_EMPTY) 14 | 15 | clean: 16 | rm -rf hello hello.cstemp 17 | -------------------------------------------------------------------------------- /tests/test-cases/codesign_allocate_debug/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # rdar://43732746 4 | 5 | PLATFORM = MACOS 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | all: 10 | CS_ALLOC_DEBUG=1 export CS_ALLOC_DEBUG; \ 11 | ${CS_ALLOC} -memento -mori 2>&1 | cat > csa.txt 12 | 13 | grep -- "-memento -mori" csa.txt | ${PASS_IFF_STDIN} 14 | 15 | clean: 16 | rm -rf csa.txt 17 | -------------------------------------------------------------------------------- /tests/test-cases/codesign_allocate_large/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # test large files rdar://43285000 4 | 5 | PLATFORM = MACOS 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | TMPDIR = /tmp/$(TEST).tmp 10 | 11 | all: 12 | # clean some local storage 13 | rm -rf $(TMPDIR) 14 | $(MKDIRS) $(TMPDIR) 15 | 16 | # make a big file of zeroes 17 | dd if=/dev/zero of=$(TMPDIR)/zeroes bs=1024000 count=1000 \ 18 | 2>&1 1>/dev/null 19 | 20 | # link our file 21 | $(CC) -arch $(ARCH) \ 22 | -Wl,-sectcreate,__ZERO,__zero1,$(TMPDIR)/zeroes \ 23 | -Wl,-sectcreate,__ZERO,__zero2,$(TMPDIR)/zeroes \ 24 | -Wl,-sectcreate,__ZERO,__zero3,$(TMPDIR)/zeroes \ 25 | -o $(TMPDIR)/hello ${TESTROOT}/src/hello.c 26 | 27 | $(PASS_IFF) $(CS_ALLOC) -i $(TMPDIR)/hello -o $(TMPDIR)/hello.cs \ 28 | -a $(ARCH) 1024 29 | 30 | clean: 31 | rm -rf $(TMPDIR) 32 | -------------------------------------------------------------------------------- /tests/test-cases/codesign_allocate_requirement/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # verify codesign_allocate was built with the following requirement: 4 | # 5 | # info["Application-Group"]="com.apple.tool.codesign_allocate 6 | # 7 | # locally built cctools is not Apple-signed, so we do not check that: 8 | # 9 | # anchor apple 10 | # 11 | # For more information, see the Security project's signerutils.cpp's 12 | # appleReq[] symbol 13 | 14 | PLATFORM = MACOS 15 | TESTROOT = ../.. 16 | include ${TESTROOT}/include/common.makefile 17 | 18 | all: 19 | ${PASS_IFF} codesign -v \ 20 | -R='info["Application-Group"]="com.apple.tool.codesign_allocate"' \ 21 | ${CS_ALLOC} 22 | 23 | clean: 24 | -------------------------------------------------------------------------------- /tests/test-cases/ctf_insert-no-text/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # ctf_insert can't find space for load commands when __TEXT has no sections 3 | 4 | PLATFORM = MACOS 5 | TESTROOT = ../.. 6 | include ${TESTROOT}/include/common.makefile 7 | 8 | .PHONY: all clean 9 | 10 | all: 11 | $(PASS_IFF) $(CTF_INSERT) in.exe -o in.out -arch x86_64 in.txt 12 | 13 | clean: 14 | rm -rf in.out 15 | 16 | -------------------------------------------------------------------------------- /tests/test-cases/ctf_insert-no-text/in.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/ctf_insert-no-text/in.exe -------------------------------------------------------------------------------- /tests/test-cases/ctf_insert-no-text/in.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /tests/test-cases/ctf_insert-split_seg-chained/preload.c: -------------------------------------------------------------------------------- 1 | int x = 0; 2 | int* g = &x; 3 | 4 | int start(void) 5 | { 6 | return *g; 7 | } 8 | -------------------------------------------------------------------------------- /tests/test-cases/ctf_insert-split_seg/preload.c: -------------------------------------------------------------------------------- 1 | int x = 0; 2 | int* g = &x; 3 | 4 | int start(void) 5 | { 6 | return *g; 7 | } 8 | -------------------------------------------------------------------------------- /tests/test-cases/install_name_tool-change/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | .PHONY: all clean 8 | 9 | CC_ARM := ${CC} -arch arm64 10 | 11 | all: 12 | # Build some dylibs and client 13 | ${CC_ARM} -dynamiclib -o one.dylib ${TESTSRC}/foo.c -DFOO=one 14 | ${CC_ARM} -dynamiclib -o two.dylib ${TESTSRC}/foo.c -DFOO=one 15 | ${CC_ARM} -o client client.c one.dylib 16 | 17 | # Verify the LC_ID_DYLIB load commands are set. 18 | ${OTOOLC} -lv one.dylib | grep LC_ID_DYLIB -A2 | ${CHECK} -p ONE 19 | # ONE: cmd LC_ID_DYLIB 20 | # ONE: cmdsize 40 21 | # ONE: name one.dylib (offset 24) 22 | ${OTOOLC} -lv two.dylib | grep LC_ID_DYLIB -A2 | ${CHECK} -p TWO 23 | # TWO: cmd LC_ID_DYLIB 24 | # TWO: cmdsize 40 25 | # TWO: name two.dylib (offset 24) 26 | 27 | # Verify the LC_LOAD_DYLIB load command is set. 28 | ${OTOOLC} -lv client | grep LC_LOAD_DYLIB -A2 | ${CHECK} -p ONE_LOAD 29 | # ONE_LOAD: cmd LC_LOAD_DYLIB 30 | # ONE_LOAD: cmdsize 40 31 | # ONE_LOAD: name one.dylib (offset 24) 32 | 33 | # Verify the code signature 34 | codesign --verify --verbose client 2>&1 35 | 36 | # Switch the dylib from one to two (note they have the same symbols). 37 | ${INSTALL_NAME_TOOL} -change one.dylib two.dylib client 38 | ${OTOOLC} -lv client | grep LC_LOAD_DYLIB -A2 | ${CHECK} -p TWO_LOAD 39 | # TWO_LOAD: cmd LC_LOAD_DYLIB 40 | # TWO_LOAD: cmdsize 40 41 | # TWO_LOAD: name two.dylib (offset 24) 42 | 43 | # Verify the code signature 44 | codesign --verify --verbose client 2>&1 45 | 46 | echo PASS 47 | 48 | clean: 49 | rm -f one.dylib two.dylib client 50 | 51 | -------------------------------------------------------------------------------- /tests/test-cases/install_name_tool-change/client.c: -------------------------------------------------------------------------------- 1 | extern int one(void); 2 | 3 | int main(void) 4 | { 5 | (void)one(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/test-cases/install_name_tool-id/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | .PHONY: all clean 8 | 9 | CC_ARM := ${CC} -arch arm64 10 | 11 | all: 12 | # Build a dylib 13 | ${CC_ARM} -dynamiclib -o one.dylib ${TESTSRC}/foo.c -DFOO=one 14 | 15 | # Verify the LC_ID_DYLIB load command is set. 16 | ${OTOOLC} -lv one.dylib | grep LC_ID_DYLIB -A2 | ${CHECK} -p ONE 17 | # ONE: cmd LC_ID_DYLIB 18 | # ONE: cmdsize 40 19 | # ONE: name one.dylib (offset 24) 20 | 21 | # Verify the code signature 22 | codesign --verify --verbose one.dylib 2>&1 23 | 24 | # Move the dylib 25 | cp one.dylib one_a.dylib 26 | ${INSTALL_NAME_TOOL} -id one_a.dylib one_a.dylib 27 | ${OTOOLC} -lv one_A.dylib | grep LC_ID_DYLIB -A2 | ${CHECK} -p ONEA 28 | # ONEA: cmd LC_ID_DYLIB 29 | # ONEA: cmdsize 40 30 | # ONEA: name one_a.dylib (offset 24) 31 | 32 | # Verify the code signature 33 | codesign --verify --verbose one_a.dylib 2>&1 34 | 35 | echo PASS 36 | 37 | clean: 38 | rm -f one.dylib one_a.dylib 39 | -------------------------------------------------------------------------------- /tests/test-cases/libstuff-unit-tests/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | ${PASS_IFF} ${STUFF_TESTS} 8 | 9 | clean: 10 | 11 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-atfile/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # This is a copy of the libtool-deterministic test rewritten to use "@file" 4 | # command-line options 5 | 6 | .PHONY: all clean 7 | 8 | PLATFORM = MACOS 9 | TESTROOT = ../.. 10 | include ${TESTROOT}/include/common.makefile 11 | 12 | all: 13 | # compile a library function 14 | ${CC} -arch $(ARCH) -o libfoo.o -c libfoo.c 15 | 16 | # build normal libraries, verify they differ (by time) 17 | # 18 | # verify libtool replaces @file references with text substitutions. 19 | # 20 | # verify libtool can handle more than one @file references on the 21 | # command line. 22 | ${LIBTOOL} @static.txt -o libfoo1.a @object.txt 23 | sleep 1 24 | ${LIBTOOL} @static.txt @object.txt -o libfoo2.a 25 | $(FAIL_IF_SUCCESS) cmp libfoo1.a libfoo2.a 26 | 27 | # build a deterministic library, verify its contents 28 | # 29 | # verify libtool can handle nested @file references 30 | ${LIBTOOL} @deterministic.txt -o libfoo1.a 31 | $(FAIL_IF_SUCCESS) cmp libfoo1.a libfoo2.a 32 | ${OTOOL} -av libfoo1.a | ${CHECK} 33 | #CHECK: Archive : libfoo1.a 34 | #CHECK: -rw-r--r-- 0/0 44 Wed Dec 31 \d+:00:00 1969 __.SYMDEF SORTED 35 | #CHECK: -rw-r--r-- 0/0 620 Wed Dec 31 \d+:00:00 1969 libfoo.o 36 | 37 | # build a second deterministic library, verify identity 38 | # 39 | # verify libtool can handle nested @file references again 40 | sleep 1 41 | ${LIBTOOL} @deterministic.txt -o libfoo2.a 42 | $(PASS_IF_SUCCESS) cmp libfoo1.a libfoo2.a 43 | 44 | # verify libtool fails on looping content 45 | ${PASS_IFF_ERROR} ${LIBTOOL} @deterministic.txt -o libfoo1.a \ 46 | @loop.txt 2>&1 47 | 48 | clean: 49 | rm -rf libfoo.o libfoo1.a libfoo2.a libfoo1.txt 50 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-atfile/deterministic.txt: -------------------------------------------------------------------------------- 1 | -D @static.txt 2 | @object.txt 3 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-atfile/libfoo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-atfile/loop.txt: -------------------------------------------------------------------------------- 1 | @loop.txt -------------------------------------------------------------------------------- /tests/test-cases/libtool-atfile/object.txt: -------------------------------------------------------------------------------- 1 | "libfoo.o" 2 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-atfile/static.txt: -------------------------------------------------------------------------------- 1 | 2 | -static 3 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-atomic/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # compile a library function 8 | ${CC} -arch $(ARCH) -o libfoo.o $(LOCAL_CC_FLAGS) -c libfoo.c 9 | 10 | # verify libtool works, for completeness ... 11 | ${FAIL_IF_ERROR} ${LIBTOOL} -static -o libfoo.a libfoo.o 12 | ${FAIL_IF_ERROR} test -f libfoo.a 13 | rm -f libfoo.a 14 | 15 | # force-fail libtool mid-write 16 | LIBTOOL_FORCE_FAIL=YES export LIBTOOL_FORCE_FAIL; \ 17 | ${FAIL_IF_SUCCESS} ${LIBTOOL} -static -o libfoo.a libfoo.o 2>&1 18 | ${PASS_IFF_ERROR} test -f libfoo.a 19 | 20 | clean: 21 | rm -rf libfoo.o libfoo.a libfoo.a.* 22 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-atomic/libfoo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-deterministic/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # compile a library function 8 | ${CC} -arch $(ARCH) -o libfoo.o $(LOCAL_CC_FLAGS) -c libfoo.c 9 | 10 | # build normal libraries, verify they differ (by time) 11 | ${LIBTOOL} -static -o libfoo1.a libfoo.o 12 | sleep 1 13 | ${LIBTOOL} -static -o libfoo2.a libfoo.o 14 | $(FAIL_IF_SUCCESS) cmp libfoo1.a libfoo2.a 15 | 16 | # build a deterministic library, verify its contents 17 | ${LIBTOOL} -static -D -o libfoo1.a libfoo.o 18 | $(FAIL_IF_SUCCESS) cmp libfoo1.a libfoo2.a 19 | ${OTOOL} -av libfoo1.a | ${CHECK} 20 | #CHECK: Archive : libfoo1.a 21 | # CHECK-NEXT: -rw-r--r-- 0/0 \s+\d+ Wed Dec 31 16:00:00 1969 __.SYMDEF SORTED 22 | # CHECK-NEXT: -rw-r--r-- 0/0 \s+\d+ Wed Dec 31 16:00:00 1969 libfoo.o 23 | 24 | # build a second deterministic library, verify identity 25 | sleep 1 26 | ${LIBTOOL} -static -D -o libfoo2.a libfoo.o 27 | $(PASS_IFF_SUCCESS) cmp libfoo1.a libfoo2.a 28 | 29 | clean: 30 | rm -rf libfoo.o libfoo1.a libfoo2.a libfoo1.txt 31 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-deterministic/libfoo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-filelist-commapath/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # compile a library function 8 | ${CC} -arch $(ARCH) -o libfoo.o $(LOCAL_CC_FLAGS) -c libfoo.c 9 | 10 | ${FAIL_IF_ERROR} ${LIBTOOL} -static -o libfoo.a -filelist "filelist, dir/filelist" 11 | ${PASS_IFF} true 12 | 13 | clean: 14 | rm -rf libfoo.o libfoo.a 15 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-filelist-commapath/filelist, dir/filelist: -------------------------------------------------------------------------------- 1 | libfoo.o 2 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-filelist-commapath/libfoo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-ldtrace-file/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS IOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # tools are expected to append to LC_TRACE_FILE, so start with a clean 8 | # out.txt file 9 | rm -rf out.txt 10 | 11 | # build some libraries to consume 12 | ${CC} -arch $(ARCH) -o foo.o -c ${TESTROOT}/src/foo.c 13 | ${CC} -arch $(ARCH) -o bar.o -c ${TESTROOT}/src/bar.c 14 | ${LIBTOOL} -static -o libfoo.a foo.o; 15 | ${LIBTOOL} -static -o libbar.a bar.o; 16 | 17 | # verify LD_TRACE_ARCHIVES writes to out.txt. 18 | LD_TRACE_ARCHIVES=1 export LD_TRACE_ARCHIVES; \ 19 | LD_TRACE_FILE=out.txt export LD_TRACE_FILE; \ 20 | ${LIBTOOL} -static -o libbaz.a libbar.a libfoo.a 21 | #$(FAIL_IF_ERROR) cmp out.txt expected.txt 22 | ${CHECK} -i out.txt -p EXPECTED1 23 | # EXPECTED1: [Logging for XBS] Used static archive: .*/libtool-ldtrace-file/libbar.a 24 | # EXPECTED1: [Logging for XBS] Used static archive: .*/libtool-ldtrace-file/libfoo.a 25 | 26 | # verify LD_TRACE_ARCHIVES appends to out.txt. 27 | LD_TRACE_ARCHIVES=1 export LD_TRACE_ARCHIVES; \ 28 | LD_TRACE_FILE=out.txt export LD_TRACE_FILE; \ 29 | ${LIBTOOL} -static -o libbaz.a libbar.a libfoo.a 30 | #$(PASS_IFF) cmp out.txt expected2.txt 31 | $(PASS_IFF) ${CHECK} -i out.txt -p EXPECTED2 32 | # EXPECTED2: [Logging for XBS] Used static archive: .*/libtool-ldtrace-file/libbar.a 33 | # EXPECTED2: [Logging for XBS] Used static archive: .*/libtool-ldtrace-file/libfoo.a 34 | # EXPECTED2: [Logging for XBS] Used static archive: .*/libtool-ldtrace-file/libbar.a 35 | # EXPECTED2: [Logging for XBS] Used static archive: .*/libtool-ldtrace-file/libfoo.a 36 | 37 | clean: 38 | rm -rf foo.o bar.o libfoo.a libbar.a libbaz.a out.txt 39 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-ldtrace-json-stderr/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS IOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | PASS_IFF_VALID_PYTHON = python -c \ 7 | "import sys,json ; json.loads ( sys.stdin.read ( ) ) ; print 'OK'" | \ 8 | grep "OK" | $(PASS_IFF_STDIN) 9 | 10 | all: 11 | # build some libraries to consume 12 | ${CC} -arch $(ARCH) -o foo.o -c ${TESTROOT}/src/foo.c 13 | ${CC} -arch $(ARCH) -o bar.o -c ${TESTROOT}/src/bar.c 14 | ${LIBTOOL} -static -o libfoo.a foo.o; 15 | ${LIBTOOL} -static -o libbar.a bar.o; 16 | 17 | # verify LD_TRACE_DEPENDENTS takes precedence over LD_TRACE_ARCHIVES 18 | # by turning both on and building a new library. 19 | LD_TRACE_DEPENDENTS=1 export LD_TRACE_DEPENDENTS; \ 20 | LD_TRACE_ARCHIVES=1 export LD_TRACE_ARCHIVES; \ 21 | ${LIBTOOL} -static -o libbaz.a libbar.a libfoo.a 2>out.txt 22 | #$(FAIL_IF_ERROR) cmp out.txt expected.txt 23 | ${CHECK} -i out.txt -p EXPECTED 24 | # EXPECTED: {"archives":[".*/libtool-ldtrace-json-stderr/libbar.a",".*/libtool-ldtrace-json-stderr/libfoo.a"]} 25 | 26 | cat out.txt | $(PASS_IFF_VALID_PYTHON) 27 | 28 | clean: 29 | rm -rf foo.o bar.o libfoo.a libbar.a libbaz.a out.txt 30 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-ldtrace-stderr/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS IOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # build some libraries to consume 8 | ${CC} -arch $(ARCH) -o foo.o -c ${TESTROOT}/src/foo.c 9 | ${CC} -arch $(ARCH) -o bar.o -c ${TESTROOT}/src/bar.c 10 | ${LIBTOOL} -static -o libfoo.a foo.o; 11 | ${LIBTOOL} -static -o libbar.a bar.o; 12 | 13 | # verify LD_TRACE_ARCHIVES logs to stderr 14 | LD_TRACE_ARCHIVES=1 export LD_TRACE_ARCHIVES; \ 15 | ${LIBTOOL} -static -o libbaz.a libbar.a libfoo.a 2>out.txt 16 | #$(PASS_IFF) cmp out.txt expected.txt 17 | $(PASS_IFF) ${CHECK} -i out.txt -p EXPECTED1 18 | # EXPECTED1: [Logging for XBS] Used static archive: .*/libtool-ldtrace-stderr/libbar.a 19 | # EXPECTED1: [Logging for XBS] Used static archive: .*/libtool-ldtrace-stderr/libfoo.a 20 | 21 | clean: 22 | rm -rf foo.o bar.o libfoo.a libbar.a libbaz.a out.txt 23 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-static/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS IOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | ${CC} -arch $(ARCH) -o libfoo.o $(LOCAL_CC_FLAGS) -c libfoo.c 8 | ${LIBTOOL} -static -o libfoo.a libfoo.o 9 | ${OTOOL} -av libfoo.a | ${CHECK} -p OTOOL 10 | # OTOOL: Archive : libfoo.a 11 | # OTOOL_NEXT: -rw-r--r--.* __.SYMDEF SORTED 12 | # OTOOL_NEXT: -rw-r--r--.* libfoo.o 13 | 14 | ls -l libfoo.a | ${CHECK} -p LS 15 | # LS: -rw-r--r-- 1 .* libfoo.a 16 | 17 | ${PASS_IFF_SUCCESS} true 18 | 19 | clean: 20 | rm -rf libfoo.o libfoo.a 21 | -------------------------------------------------------------------------------- /tests/test-cases/libtool-static/libfoo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-arch_blank/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | .PHONY: all clean 7 | 8 | all: 9 | ${CC} -dynamiclib -o thin.dylib ${TESTROOT}/src/foo.c 10 | ${FAIL_IFF} ${LIPO} -output fat.dylib \ 11 | -create -arch_blank arm64 thin.dylib 2>&1 12 | 13 | clean: 14 | rm -f fat.dylib thin.dylib 15 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-archs/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # verify lipo -archs prints values for fat binaries without extra whitespace 4 | 5 | .PHONY: all clean 6 | 7 | PLATFORM = MACOS 8 | TESTROOT = ../../ 9 | include ${TESTROOT}/include/common.makefile 10 | 11 | all: 12 | #compile a thin and fat file. 13 | ${CC} -o thin -arch x86_64 -c ${TESTROOT}/src/hello.c 14 | ${CC} -o fat -arch x86_64 -arch x86_64h -c ${TESTROOT}/src/hello.c 15 | 16 | ${LIPO} -archs thin | ${CHECK} -p THIN 17 | ${LIPO} -archs fat | ${CHECK} -p FAT 18 | # THIN-NOT: x86_64\[ \] 19 | # THIN: x86_64 20 | # FAT-NOT: x86_64 x86_64h\[ \] 21 | # FAT: x86_64 x86_64h 22 | 23 | echo PASS 24 | 25 | clean: 26 | rm -f thin fat 27 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-bigendian/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | .PHONY: all clean 8 | 9 | ARCH := `machine` 10 | 11 | all: 12 | # compile a host executable 13 | ${CC} -arch ${ARCH} -o hello.host ${TESTROOT}/src/hello.c 14 | 15 | # make something that looks like a Rhapsody PPC file. /shrug 16 | ${CC} -arch ${ARCH} -o hello.ppc ${TESTROOT}/src/hello.c \ 17 | -Wl,-segalign,0x2000 18 | ${TESTROOT}/bin/rewrite-macho.pl -a ppc -o hello.ppc hello.ppc 19 | 20 | # make a fat binary 21 | lipo -create -o hello hello.host hello.ppc 22 | 23 | echo PASS 24 | clean: 25 | rm -f hello hello.host hello.ppc 26 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-cpusubtype-order/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: IOS 2 | 3 | PLATFORM = IOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | all: 8 | for arch in armv7k arm64e arm64 arm64_32; \ 9 | do \ 10 | ofile="foo.$$arch"; \ 11 | $(CC) -arch $$arch -o $$ofile -dynamiclib foo.c > /dev/null 2>&1; \ 12 | files="$$files $$ofile"; \ 13 | done; \ 14 | ${LIPO} -create -output foo.dylib $$files; 15 | ${LIPO} -info foo.dylib | grep -e 'arm64 arm64e\s*$$' \ 16 | | ${FAIL_IF_EMPTY} 17 | ${PASS_IFF_SUCCESS} true 18 | 19 | clean: 20 | rm -rf foo.armv7k foo.arm64 foo.arm64e foo.arm64_32 foo.dylib 21 | 22 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-cpusubtype-order/foo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-hidden/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: WATCHOS 2 | 3 | PLATFORM = WATCHOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | all: 8 | # fail if hiding files that aren't MH_EXECUTE 9 | for arch in armv7k arm64e arm64 arm64_32; \ 10 | do \ 11 | ofile="empty.$$arch"; \ 12 | $(CC) -arch $$arch -o $$ofile -dynamiclib empty.c > /dev/null 2>&1;\ 13 | files="$$files $$ofile"; \ 14 | done; \ 15 | $(FAIL_IF_SUCCESS) ${LIPO} -create -output empty.dylib \ 16 | -hideARM64 $$files 2>&1; \ 17 | rm -f $$files 18 | 19 | # verify arm64 can be hidden 20 | # files=""; 21 | for arch in armv7k arm64e; \ 22 | do \ 23 | ofile="empty.$$arch"; \ 24 | $(CC) -arch $$arch -o $$ofile empty.c > /dev/null 2>&1; \ 25 | files="$$files $$ofile"; \ 26 | done; \ 27 | $(FAIL_IF_ERROR) ${LIPO} -create -output empty \ 28 | -hideARM64 $$files; 29 | ${LIPO} -info empty | grep -e 'armv7k arm64e' \ 30 | | ${FAIL_IF_EMPTY} 31 | ${LIPO} -detailed_info empty | grep -e 'arm64e (hidden)' \ 32 | | ${FAIL_IF_EMPTY} 33 | 34 | # verify arm64 isn't always hidden 35 | for arch in armv7k arm64e; \ 36 | do \ 37 | ofile="empty.$$arch"; \ 38 | files="$$files $$ofile"; \ 39 | done; \ 40 | $(FAIL_IF_ERROR) ${LIPO} -create -output empty $$files 41 | ${LIPO} -info empty | grep -e 'armv7k arm64e' \ 42 | | ${FAIL_IF_EMPTY} 43 | ${LIPO} -detailed_info empty | grep -e 'arm64e (hidden)' \ 44 | | ${FAIL_IF_STDIN} 45 | 46 | # verify 47 | ${PASS_IFF_SUCCESS} true 48 | 49 | clean: 50 | rm -rf empty.armv7k empty.arm64 empty.arm64e empty.arm64_32 \ 51 | empty.dylib empty 52 | 53 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-hidden/empty.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-info/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS IOS WATCHOS TVOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | THIN_ARCH_OPTION= $(patsubst %,-arch %,$($ARCH)) 7 | FAT_ARCH_OPTIONS= $(patsubst %,-arch %,$(VALID_ARCHS)) 8 | FAT_ARCH_COUNT = $(words $(VALID_ARCHS)) 9 | 10 | all: 11 | if [ $(FAT_ARCH_COUNT) -gt 1 ]; \ 12 | then \ 13 | $(CC) -arch $(ARCH) -o hello ${TESTROOT}/src/hello.c; \ 14 | ${LIPO} -info hello | \ 15 | grep "Non-fat file: hello is architecture: $(ARCH)" | \ 16 | ${FAIL_IF_EMPTY}; \ 17 | $(CC) $(FAT_ARCH_OPTIONS) -o hello ${TESTROOT}/src/hello.c; \ 18 | ${LIPO} -info hello | \ 19 | grep "Architectures in the fat file: hello are:" | \ 20 | grep "${FAT_ARCHS}" | ${FAIL_IF_EMPTY}; \ 21 | fi 22 | ${PASS_IFF_SUCCESS} true 23 | 24 | clean: 25 | rm -rf hello 26 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-large/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # test large files rdar://43285000 4 | 5 | PLATFORM = MACOS 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | TMPDIR = /tmp/$(TEST).tmp 10 | 11 | # we need to make sure the final binary is larger than 2GB. But due to 12 | # another issue we need to make sure the final binary is less than 4 GB. 13 | # so write out two files (x86_64, x86_64h) at 1.5 GB each. 14 | VALID_ARCHS := $(filter-out i386, $(VALID_ARCHS)) 15 | 16 | all: 17 | # clean some local storage 18 | rm -rf $(TMPDIR) 19 | $(MKDIRS) $(TMPDIR) 20 | 21 | # make a big file of zeroes 22 | dd if=/dev/zero of=$(TMPDIR)/zeroes bs=1024000 count=1500 \ 23 | 2>&1 1>/dev/null 24 | 25 | # link our file 26 | for arch in $(VALID_ARCHS); \ 27 | do \ 28 | ofile="$(TMPDIR)/hello.$$arch"; \ 29 | files="$$ofile $$files"; \ 30 | $(CC) -arch $$arch -o $$ofile ${TESTROOT}/src/hello.c \ 31 | -Wl,-sectcreate,__ZERO,__zero1,$(TMPDIR)/zeroes; \ 32 | done; \ 33 | \ 34 | $(PASS_IFF) $(LIPO) -create -output $(TMPDIR)/hello $$files 35 | 36 | clean: 37 | rm -rf $(TMPDIR) 38 | -------------------------------------------------------------------------------- /tests/test-cases/lipo-thin-times/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # test thining a fat file 4 | # 5 | # Regression tests include: 6 | # 7 | # rdar://49604334 verify lipo -thin doesn't zero out fractional seconds 8 | 9 | .PHONY: all clean 10 | 11 | TESTROOT = ../.. 12 | include ${TESTROOT}/include/common.makefile 13 | 14 | ARCHS_FAT := -arch x86_64 -arch arm64 15 | 16 | all: 17 | # build a tool for reporting fractional file times 18 | ${CC} -o times ${TESTROOT}/src/times.c 19 | codesign -s - times 20 | 21 | # compile a fat file, any fat file, yours 22 | #${CC} $(ARCHS_FAT) -o hello ${TESTROOT}/src/hello.c 23 | $(CC) $(ARCHS_FAT) -x c -c -o hello /dev/null 24 | 25 | # thin the file 26 | ${LIPO} -thin $(ARCH) -output hello.$(ARCH) hello 27 | 28 | # verify the file fractional seconds 29 | # 30 | # as a race condition, there is a sliiiight chance we'll get unlucky 31 | # and write a file exactly on a microsecond or nanosecond binary. not 32 | # really sure how to defend against that. 33 | ./times hello.$(ARCH) | ${CHECK} -p TIMES 34 | # TIMES: hello\..* 35 | # TIMES-NOT: atime: \d+ 0 36 | # TIMES-NEXT: atime: \d+ \d+ 37 | # TIMES-NOT: mtime: \d+ 0 38 | # TIMES-NEXT: mtime: \d+ \d+ 39 | 40 | echo PASS 41 | 42 | clean: 43 | rm -rf times hello hello.$(ARCH) 44 | -------------------------------------------------------------------------------- /tests/test-cases/mtor-bad-file/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | ${CC} -arch ${ARCH} -o hello -c ${TESTROOT}/src/hello.c 8 | ${MTOR} -output out hello 2>&1 | ${CHECK} -p NOTPRELOAD 9 | ${CC} -arch ${ARCH} -o hello ${TESTROOT}/src/hello.c 10 | ${MTOR} -output out hello 2>&1 | ${CHECK} -p NOTPRELOAD 11 | ${CC} -arch ${ARCH} -dynamiclib -o dylib ${TESTROOT}/src/foo.c 12 | ${MTOR} -output out hello 2>&1 | ${CHECK} -p NOTPRELOAD 13 | # NOTPRELOAD: fatal error: .*mtor: input file: .* must be an MH_PRELOAD file type 14 | 15 | echo PASS 16 | 17 | clean: 18 | rm -rf hello dylib out 19 | -------------------------------------------------------------------------------- /tests/test-cases/mtor-preload-bss/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | ${CC} -arch ${ARCH} -Wl,-preload,-segalign,0x1000 -nodefaultlibs \ 8 | -e _main -o preload ${TESTROOT}/src/preload_bss.c 9 | ${OTOOLC} -hv preload | ${CHECK} 10 | # CHECK: Mach header 11 | # CHECK-NEXT: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags 12 | # CHECK-NEXT: MH_MAGIC_64 .*\s+ALL 0x00 PRELOAD \d+\s+\d+\s+NOUNDEFS 13 | 14 | ${MTOR} -v -start 0 -o preload.out preload | ${CHECK} -p PRELOAD 15 | # PRELOAD: writing __TEXT at VMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ LMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ 16 | # PRELOAD: writing __DATA at VMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ LMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ 17 | 18 | ls -l preload.out | awk '{print $$5}' | ${CHECK} -p PRELOADSIZE 19 | # PRELOADSIZE: 4128 20 | 21 | ${MTOR} -v -no_bss -start 0 -o preload.out preload | ${CHECK} -p NOBSS 22 | # NOBSS: writing __TEXT at VMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ LMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ 23 | # NOBSS: writing __DATA at VMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ LMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ 24 | 25 | ls -l preload.out | awk '{print $$5}' | ${CHECK} -p NOBSSSIZE 26 | # NOBSSSIZE: 4096 27 | 28 | echo PASS 29 | clean: 30 | rm -f preload preload.out preload2.out 31 | 32 | -------------------------------------------------------------------------------- /tests/test-cases/mtor-preload/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | ${CC} -arch ${ARCH} -Wl,-preload -nodefaultlibs -e _main \ 8 | -o preload ${TESTROOT}/src/preload.c 9 | ${CC} -arch x86_64 -arch x86_64h -Wl,-preload -nodefaultlibs \ 10 | -e _main -o preload.fat ${TESTROOT}/src/preload.c 11 | ${OTOOLC} -hv preload | ${CHECK} 12 | # CHECK: Mach header 13 | # CHECK-NEXT: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags 14 | # CHECK-NEXT: MH_MAGIC_64 .*\s+ALL 0x00 PRELOAD \d+\s+\d+\s+NOUNDEFS 15 | 16 | ${MTOR} -n -o preload.bad preload.fat 2>&1 | ${CHECK} -p FAT 17 | # FAT: fatal error: .*mtor: file: preload.fat is a fat file (.*mtor only operates on Mach-O files, use lipo(1) on it to get a Mach-O file) 18 | 19 | ${MTOR} -n -o preload.out preload | ${CHECK} -p PRELOAD 20 | ${MTOR} -v -o preload.out preload | ${CHECK} -p PRELOAD 21 | # PRELOAD: writing __TEXT at VMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ LMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ 22 | # PRELOAD: writing __DATA at VMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ LMA: 0x\[\[:xdigit:\]\]+-0x\[\[:xdigit:\]\]+ 23 | 24 | ${MTOR} -o preload2.out preload 25 | ${FAIL_IF_ERROR} cmp preload.out preload2.out 26 | 27 | ${OTOOLC} -hv preload.out | ${CHECK} -p PRELOADOUT 28 | # PRELOADOUT: preload.out: is not an object file 29 | 30 | ${MTOR} -v -no_bss -o preload2.out preload | ${CHECK} -p PRELOAD -v 31 | ${FAIL_IF_SUCCESS} cmp preload.out preload2.out 2>&1 32 | 33 | echo PASS 34 | 35 | clean: 36 | rm -f preload preload.out preload2.out preload.fat 37 | -------------------------------------------------------------------------------- /tests/test-cases/mtor-usage/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | ${MTOR} 2>&1 | ${CHECK} -p USAGE 8 | ${MTOR} -h 2>&1 | ${CHECK} -p USAGE 9 | ${MTOR} -help 2>&1 | ${CHECK} -p USAGE 10 | # USAGE: usage: mtor [-nv] [-no_bss] [-start ] [-packdata ] -output 11 | # USAGE-NEXT: mtor -help [-version] 12 | # USAGE-NEXT: mtor -version 13 | 14 | ${MTOR} -version 2>&1 | ${CHECK} -p VERSION 15 | # VERSION: cctools.* 16 | # VERSION-NOT: usage.* 17 | 18 | ${MTOR} -start 2>&1 | ${CHECK} -p START 19 | # START: .*mtor: one start address must be specified for -start 20 | # START-NEXT: usage.* 21 | 22 | ${MTOR} -start g 2>&1 | ${CHECK} -p START2 23 | # START2: .*mtor: g not a proper hexadecimal number 24 | # START2-NOT: usage.* 25 | 26 | ${MTOR} -o 2>&1 | ${CHECK} -p OUTPUT 27 | ${MTOR} -output 2>&1 | ${CHECK} -p OUTPUT 28 | # OUTPUT: .*mtor: one output file must be specified 29 | # OUTPUT-NEXT: usage.* 30 | 31 | ${MTOR} -o output1 -o output2 2>&1 | ${CHECK} -p OUTPUT1 32 | # OUTPUT1: .*mtor: only one output file must be specified 33 | # OUTPUT1-NEXT: usage.* 34 | 35 | 36 | ${MTOR} -o output input1 input2 2>&1 | ${CHECK} -p INPUT 37 | # INPUT: .*mtor: only one input file must be specified 38 | # INPUT-NEXT: usage.* 39 | 40 | 41 | ${MTOR} -packdata 2>&1 | ${CHECK} -p PACKDATA1 42 | # PACKDATA1: .*mtor: data lma symbol name must be specified 43 | # PACKDATA1-NEXT: usage.* 44 | 45 | ${MTOR} -packdata lma 2>&1 | ${CHECK} -p PACKDATA2 46 | # PACKDATA2: .*mtor: data size symbol name must be specified 47 | # PACKDATA2-NEXT: usage.* 48 | 49 | echo PASS 50 | 51 | clean: 52 | 53 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-lto-weak-ref/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | .PHONY: all clean 8 | 9 | all: 10 | ${CC} -c weak-ref.cpp -O2 -o weak-ref.o 11 | ${CC} -c weak-ref.cpp -O2 -flto=full -o weak-ref.lto.o 12 | ${NMC} -m weak-ref.o | ${CHECK} -p MACHO 13 | ${NMC} -m weak-ref.lto.o | ${CHECK} -p BITCODE 14 | # MACHO: \[\[:xdigit:\]\]+ (__TEXT,__text) external __Z3barv 15 | # MACHO: \[\[:xdigit:\]\]+ (__TEXT,__text) weak external automatically hidden __Z3fooILi0EEvv 16 | # MACHO: (undefined) external _printf 17 | # BITCODE: ---------------- (LTO,CODE) external __Z3barv 18 | # BITCODE: ---------------- (LTO,CODE) weak external automatically hidden __Z3fooILi0EEvv 19 | # BITCODE: (undefined) external _printf 20 | 21 | echo PASS 22 | 23 | clean: 24 | rm -f weak-ref.o weak-ref.lto.o 25 | 26 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-lto-weak-ref/weak-ref.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | __attribute__((noinline)) 5 | void foo() { printf("%d\n", i); } 6 | 7 | void bar() { foo<0>(); } 8 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m-cold-func/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # We don't yet have compiler support for N_COLD_FUNC so we will 8 | # use a little utility to set the bit 9 | ${CC} -o symtool symtool.c 10 | codesign -s - symtool 11 | 12 | # compile a cold symbol 13 | ${CC} -o hello.o -c ${TESTROOT}/src/hello.c 14 | symtool -o hello.o hello.o 15 | 16 | ${NMC} -m hello.o | ${CHECK} -v 17 | # CHECK: 0000000000000000 (__TEXT,__text) external [cold func] _main 18 | 19 | echo PASS 20 | 21 | clean: 22 | rm -f hello.o symtool 23 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/atsPathVersSuffix.c: -------------------------------------------------------------------------------- 1 | void atsPathVersSuffix(void) {} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/atsVersSuffix.c: -------------------------------------------------------------------------------- 1 | void atsVersSuffix(void) {} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/foo.c: -------------------------------------------------------------------------------- 1 | void foo(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/fooPath.c: -------------------------------------------------------------------------------- 1 | void fooPath(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/fooPathSuffix.c: -------------------------------------------------------------------------------- 1 | void fooPathSuffix(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/fooPathVers.c: -------------------------------------------------------------------------------- 1 | void fooPathVers(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/fooSuffix.c: -------------------------------------------------------------------------------- 1 | void fooSuffix(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/fooVers.c: -------------------------------------------------------------------------------- 1 | void fooVers(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/foo_bar.c: -------------------------------------------------------------------------------- 1 | void foo_bar(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/foo_barSuffix.c: -------------------------------------------------------------------------------- 1 | void foo_barSuffix(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/main.c: -------------------------------------------------------------------------------- 1 | extern void foo(void); 2 | extern void fooSuffix(void); 3 | extern void fooPath(void); 4 | extern void fooPathSuffix(void); 5 | extern void fooVers(void); 6 | extern void fooPathVers(void); 7 | extern void x(void); 8 | extern void xSuffix(void); 9 | extern void xPathSuffix(void); 10 | extern void atsVersSuffix(void); 11 | extern void atsPathVersSuffix(void); 12 | extern void qt(void); 13 | extern void qtPath(void); 14 | extern void foo_bar(void); 15 | extern void foo_barSuffix(void); 16 | 17 | int 18 | main(){ 19 | foo(); 20 | fooSuffix(); 21 | fooPath(); 22 | fooPathSuffix(); 23 | fooVers(); 24 | fooPathVers(); 25 | x(); 26 | xSuffix(); 27 | xPathSuffix(); 28 | atsVersSuffix(); 29 | atsPathVersSuffix(); 30 | qt(); 31 | qtPath(); 32 | foo_bar(); 33 | foo_barSuffix(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/qt.c: -------------------------------------------------------------------------------- 1 | void qt(void) {} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/qtPath.c: -------------------------------------------------------------------------------- 1 | void qtPath(void) {} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/x.c: -------------------------------------------------------------------------------- 1 | void x(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/xPathSuffix.c: -------------------------------------------------------------------------------- 1 | void xPathSuffix(void) {} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nm-classic-m/xSuffix.c: -------------------------------------------------------------------------------- 1 | void xSuffix(void){} 2 | -------------------------------------------------------------------------------- /tests/test-cases/nmedit-D/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | all: 8 | # compile a library function 9 | ${CC} -o libfoo.o -c ${TESTROOT}/src/foo.c 10 | 11 | # build a deterministic library 12 | ${LIBTOOL} -static -D -o libfoo.a libfoo.o 13 | 14 | # modify the library 15 | ${NMEDIT} -D -s /dev/null libfoo.a 16 | 17 | # verify 18 | ${OTOOL} -av libfoo.a | ${CHECK} 19 | # CHECK: Archive : libfoo.a 20 | # CHECK-NEXT: -rw-r--r-- 0/0 \s+\d+ Wed Dec 31 16:00:00 1969 __.SYMDEF SORTED 21 | # CHECK-NEXT: -rw-r--r-- 0/0 \s+\d+ Wed Dec 31 16:00:00 1969 libfoo.o 22 | 23 | echo PASS 24 | 25 | clean: 26 | rm -f libfoo.o libfoo.a 27 | -------------------------------------------------------------------------------- /tests/test-cases/nmedit-reloc-bypass/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | .PHONY: all clean 8 | 9 | all: 10 | ${NMEDIT} -s ex.exp ex.a -o ex.a.edit 11 | ${NMC} ex.a | ${CHECK} -p BEFORE 12 | ${NMC} ex.a.edit | ${CHECK} -p AFTER 13 | # BEFORE: ex.a(ex.o): 14 | # BEFORE: 0000000000000010 T _main 15 | # BEFORE: 0000000000000000 T _my_extern 16 | # BEFORE: 0000000000000008 T _my_local 17 | # AFTER: ex.a.edit(ex.o): 18 | # AFTER: 0000000000000010 t _main 19 | # AFTER: 0000000000000000 T _my_extern 20 | # AFTER: 0000000000000008 t _my_local 21 | 22 | echo PASS 23 | 24 | clean: 25 | rm -f ex.o ex.a.edit 26 | 27 | ex.a: ex.o 28 | libtool -static -o $@ $^ 29 | 30 | ex.o: ex.c 31 | cc -arch arm64 -o $@ -c $^ 32 | -------------------------------------------------------------------------------- /tests/test-cases/nmedit-reloc-bypass/ex.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/nmedit-reloc-bypass/ex.a -------------------------------------------------------------------------------- /tests/test-cases/nmedit-reloc-bypass/ex.c: -------------------------------------------------------------------------------- 1 | int my_extern(void) 2 | { 3 | return 1; 4 | } 5 | 6 | int my_local(void) 7 | { 8 | return -1; 9 | } 10 | 11 | int main(void) 12 | { 13 | return my_extern() + my_local(); 14 | } 15 | -------------------------------------------------------------------------------- /tests/test-cases/nmedit-reloc-bypass/ex.exp: -------------------------------------------------------------------------------- 1 | _my_extern 2 | -------------------------------------------------------------------------------- /tests/test-cases/nmedit-usage/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # Verify nmedit and strip have different usage strings. I.e., that they aren't 4 | # the same tool (even though they are). 5 | 6 | PLATFORM = MACOS 7 | TESTROOT = ../.. 8 | include ${TESTROOT}/include/common.makefile 9 | 10 | NUSAGE="$(shell echo `${NMEDIT} -h 2>&1 |sed 's/nmedit/tool/'`)" 11 | 12 | all: 13 | nusage="$(shell echo `${NMEDIT} -h 2>&1 | sed 's/nmedit/tool/'`)"; \ 14 | susage="$(shell echo `${STRIP} -h 2>&1 | sed 's/strip/tool/'`)"; \ 15 | if [ "$$nusage" == "$$susage" ]; then \ 16 | echo FAIL; \ 17 | else \ 18 | echo PASS; \ 19 | fi 20 | 21 | clean: 22 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-L/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # ER: Add link type (weak, upward, normal) to otool -L 4 | 5 | PLATFORM = MACOS 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | .PHONY: all clean 10 | 11 | all: 12 | ${CC} -dynamiclib -DFOO=weak -o weak.dylib ${TESTROOT}/src/foo.c 13 | ${CC} -dynamiclib -DFOO=reexport -o reexport.dylib ${TESTROOT}/src/foo.c 14 | ${CC} -dynamiclib -DFOO=upward -o upward.dylib ${TESTROOT}/src/foo.c 15 | ${CC} -dynamiclib -DFOO=lazy -o lazy.dylib ${TESTROOT}/src/foo.c 16 | ${CC} -dynamiclib -DFOO=foo -o foo.dylib ${TESTROOT}/src/foo.c \ 17 | -Wl,-weak_library,weak.dylib \ 18 | -Wl,-reexport_library,reexport.dylib \ 19 | -Wl,-upward_library,upward.dylib \ 20 | -Wl,lazy.dylib 2>&1 21 | mangle.pl foo.dylib foo.dylib 22 | ${OTOOLC} -L foo.dylib | ${CHECK} 23 | # CHECK: foo.dylib: 24 | # CHECK: weak.dylib (compatibility version 0.0.0, current version 0.0.0, weak) 25 | # CHECK: reexport.dylib (compatibility version 0.0.0, current version 0.0.0, reexport) 26 | # CHECK: upward.dylib (compatibility version 0.0.0, current version 0.0.0, upward) 27 | # CHECK: lazy.dylib (compatibility version 0.0.0, current version 0.0.0, lazy) 28 | 29 | echo PASS 30 | 31 | clean: 32 | rm -rf weak.dylib reexport.dylib upward.dylib lazy.dylib foo.dylib 33 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-L/mangle.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | BEGIN { 4 | # preferred location for cctools perl modules 5 | unshift @INC, "../../include"; 6 | } 7 | 8 | use FileHandle; 9 | use MachO; 10 | 11 | exit &main(); 12 | 13 | sub main { 14 | # parse args 15 | my $input = shift @ARGV; 16 | my $output = shift @ARGV; 17 | return &usage("missing input") unless ($input); 18 | return &usage("missing output") unless ($output); 19 | die "file not found: $input\n" unless ( -e $input ); 20 | 21 | # open the mach-o 22 | my ($obj) = MachO->newWithPath($input); 23 | my ($perm) = (stat $input)[2] & 07777; 24 | return 1 unless ($obj); 25 | 26 | # find the load_dylib load commands 27 | my @cmds; 28 | foreach my $lc (@{$obj->{"loadcmds"}}) { 29 | if ($lc->{"cmd"} == MachO::LC_LOAD_DYLIB and 30 | $lc->{"name"} =~ /lazy\.dylib/) 31 | { 32 | push @cmds, $lc; 33 | print "modifying load command:\n" . $lc->description(); 34 | } 35 | } 36 | 37 | # modify the file data 38 | my $data = $obj->{"data"}; 39 | foreach my $lc (@cmds) { 40 | my $loc = $lc->location(); 41 | my $swap = $obj->{"swap"} ? "<" : ""; 42 | 43 | my $raw = pack ("L${swap}", MachO::LC_LAZY_LOAD_DYLIB); 44 | substr ($data, $loc, 4) = $raw; 45 | } 46 | 47 | # write out the file to a new location 48 | my $fh = FileHandle->new(">$output"); 49 | 50 | my $wrote = syswrite($fh, $data, length($data)); 51 | if ($wrote != length($data)) { 52 | print STDERR "can't write to $output: $!\n"; 53 | return 1; 54 | } 55 | chmod $perm, $output; 56 | 57 | return 0; 58 | } 59 | 60 | sub usage { 61 | my ($msg) = @_; 62 | (my $basename = $0) =~ s|.*/||; 63 | print "$0: $msg\n" if ($msg); 64 | print "usage: $basename \n"; 65 | return 1; 66 | } 67 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-S/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # compile a test program 8 | ${CC} -arch ${ARCH} -o foo.o -c ${TESTROOT}/src/foo.c 9 | ${LIBTOOL} -static -o foo.a foo.o 10 | 11 | ${OTOOLC} -S foo.a | ${CHECK} -v 12 | #CHECK: Archive : foo.a 13 | #CHECK-NEXT: Table of contents from: foo.a(__.SYMDEF SORTED) 14 | #CHECK-NEXT: size of ranlib structures: 8 (number 1) 15 | #CHECK-NEXT: object offset string index 16 | #CHECK-NEXT: 112 0 17 | 18 | ${PASS_IFF} true 19 | 20 | clean: 21 | rm -f foo.o foo.a 22 | 23 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-addr-slide/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # Compile a test program, and disassemble it using some kind of slide. 3 | 4 | PLATFORM = MACOS 5 | TESTROOT = ../.. 6 | include ${TESTROOT}/include/common.makefile 7 | 8 | .PHONY: all clean 9 | 10 | all: 11 | # compile a test program 12 | ${CC} ${TESTROOT}/src/objc_hi.m -framework Foundation -o hello 13 | 14 | # test missing slide 15 | ${OTOOLC} -t hello -addr_slide 2>&1 | ${CHECK} -p MISSING 16 | ${OTOOLC} -t hello -addr_slide= 2>&1 | ${CHECK} -p MISSING 17 | # MISSING: error: .* (amount to slide addresses when printing pointers) 18 | 19 | ${OTOOLC} -t hello -addr_slide 9870000 | ${CHECK} 20 | ${OTOOLC} -tv hello -addr_slide 9870000 | ${CHECK} 21 | ${OTOOLC} -tV hello -addr_slide 9870000 | ${CHECK} 22 | ${OTOOLC} -s __TEXT __unwind_info hello -addr_slide 9870000 | ${CHECK} 23 | ${OTOOLC} -v -s __TEXT __unwind_info hello -addr_slide 9870000 \ 24 | | ${CHECK} 25 | ${OTOOLC} -o hello -addr_slide 9870000 | ${CHECK} 26 | ${OTOOLC} -ov hello -addr_slide 9870000 | ${CHECK} 27 | # CHECK: .*\d*0987\d*.* 28 | 29 | echo PASS 30 | 31 | clean: 32 | rm -f hello 33 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-bind_info-chained-weak/weak-large-addends.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | __attribute__((weak)) 6 | int a = 0; 7 | 8 | const int arraySize = 1000000; 9 | 10 | __attribute__((weak)) 11 | int b[arraySize] = { 0 }; 12 | 13 | int* bPtr = &b[1]; 14 | int* bPtr2 = &b[arraySize - 1]; 15 | 16 | __attribute__((weak, visibility(("hidden")))) 17 | int c = 0; 18 | 19 | //int* freePtr = ((int*)&free) + 1; 20 | int* errnoPtr = ((int*)&errno) + 1; 21 | 22 | __attribute__((weak)) 23 | void* operator new(size_t size) { 24 | return malloc(size); 25 | } 26 | 27 | int main() { 28 | delete(new int()); 29 | return a + *bPtr + c + *bPtr2 + *errnoPtr + errno; 30 | } -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-bind_info-chained-weak/weak-no-addends.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | __attribute__((weak)) 6 | int a = 0; 7 | 8 | const int arraySize = 3; 9 | 10 | __attribute__((weak)) 11 | int b[arraySize] = { 0 }; 12 | 13 | int* bPtr = &b[0]; 14 | int* bPtr2 = &b[0]; 15 | 16 | __attribute__((weak, visibility(("hidden")))) 17 | int c = 0; 18 | 19 | //int* freePtr = ((int*)&free) + 0; 20 | int* errnoPtr = ((int*)&errno) + 0; 21 | 22 | __attribute__((weak)) 23 | void* operator new(size_t size) { 24 | return malloc(size); 25 | } 26 | 27 | int main() { 28 | delete(new int()); 29 | return a + *bPtr + c + *bPtr2 + *errnoPtr; 30 | } -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-bind_info-chained-weak/weak-small-addends.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | __attribute__((weak)) 6 | int a = 0; 7 | 8 | const int arraySize = 1000; 9 | 10 | __attribute__((weak)) 11 | int b[arraySize] = { 0 }; 12 | 13 | int* bPtr = &b[1]; 14 | int* bPtr2 = &b[arraySize - 1]; 15 | 16 | __attribute__((weak, visibility(("hidden")))) 17 | int c = 0; 18 | 19 | //int* freePtr = ((int*)&free) + 1; 20 | int* errnoPtr = ((int*)&errno) + 1; 21 | 22 | __attribute__((weak)) 23 | void* operator new(size_t size) { 24 | return malloc(size); 25 | } 26 | 27 | int main() { 28 | delete(new int()); 29 | return a + *bPtr + c + *bPtr2 + *errnoPtr; 30 | } -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-cpusubtype-flags/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # This test confirms otool-classic prints unknown cpu subtype flags. 4 | 5 | PLATFORM = MACOS 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | REWRITE = ${TESTROOT}/bin/rewrite-macho.pl 10 | 11 | .PHONY: all clean 12 | 13 | all: 14 | ${CC} -o foo.o -c ${TESTROOT}/src/foo.c 15 | subtype=`otool -h foo.o | tail -1 | awk '{print $$3}'`; \ 16 | subtype=$$(($$subtype | 0xFF000000)); \ 17 | ${REWRITE} foo.o -v -c :$$subtype -o foo2.o 18 | ${OTOOLC} -h foo2.o | ${CHECK} -p TERSE 19 | # TERSE: 0xfeedfac.\s+\d+\s+\d+\s+0xff.* 20 | ${OTOOLC} -hv foo2.o | ${CHECK} -p VERBOSE 21 | # VERBOSE: MH_MAGIC\S*\s+\S+\s+\S+\s+0xff.* 22 | 23 | echo PASS 24 | 25 | clean: 26 | rm -f foo.o foo2.o 27 | 28 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/hi-abs-32.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-o-rel32/hi-abs-32.dylib -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/hi-abs-64.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-o-rel32/hi-abs-64.dylib -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/hi-dir-32.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-o-rel32/hi-dir-32.dylib -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/hi-dir-64.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-o-rel32/hi-dir-64.dylib -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/hi-rel-32.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-o-rel32/hi-rel-32.dylib -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/hi-rel-64.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-o-rel32/hi-rel-64.dylib -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/hi.h: -------------------------------------------------------------------------------- 1 | #import 2 | @interface Hi : NSObject 3 | { 4 | int payload; 5 | } 6 | - (void)greetings; 7 | - (void)unused; 8 | @end 9 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/hi.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "hi.h" 3 | 4 | @implementation Hi 5 | - (void)greetings 6 | { 7 | printf("hello, Objective-C!\n"); 8 | } 9 | - (void)unused 10 | { 11 | } 12 | @end 13 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-rel32/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "hi.h" 3 | 4 | int main(void) 5 | { 6 | @autoreleasepool { 7 | Hi* hi = [[Hi alloc] init]; 8 | [hi greetings]; 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-selrefs/Dylib.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "Protocol.h" 4 | 5 | @interface Dylib : NSObject 6 | { 7 | int m_intProperty; 8 | } 9 | - (void)genericMethod; 10 | - (void)targetMethod:(id)sender; 11 | @end 12 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-selrefs/Dylib.m: -------------------------------------------------------------------------------- 1 | // cc -framework Foundation -dynamiclib -o Dylib.dylib Dylib.m 2 | 3 | #import "Dylib.h" 4 | 5 | @interface Dylib () 6 | @end 7 | 8 | @implementation Dylib 9 | 10 | - (void)genericMethod 11 | { 12 | NSLog(@"genericMethod"); 13 | } 14 | 15 | - (void)targetMethod:(id)sender 16 | { 17 | NSLog(@"verb"); 18 | } 19 | 20 | #pragma mark Protocol Verbing 21 | 22 | + (void)classVerb 23 | { 24 | NSLog(@"classVerb"); 25 | } 26 | 27 | - (void)verb 28 | { 29 | NSLog(@"verb"); 30 | } 31 | 32 | @synthesize intProperty = m_intProperty; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-selrefs/Protocol.h: -------------------------------------------------------------------------------- 1 | @protocol Verbing 2 | + (void)classVerb; 3 | - (void) verb; 4 | @property (nonatomic, readonly) int intProperty; 5 | 6 | @optional 7 | + (void)classOptionalVerb; 8 | - (void)optionalVerb; 9 | @end -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o-selrefs/Tool.m: -------------------------------------------------------------------------------- 1 | // cc -framework Foundation Tool.m Dylib.dylib 2 | 3 | #import 4 | #import "Dylib.h" 5 | 6 | @interface Dylib (Category) 7 | + (void)categoryClass; 8 | - (void)categoryAddition; 9 | - (void)genericMethod; 10 | @property (nonatomic, readonly) int categoryProperty; 11 | @end 12 | 13 | @implementation Dylib (Category) 14 | 15 | + (void)categoryClass 16 | { 17 | NSLog(@"categoryClass"); 18 | } 19 | 20 | - (void)categoryAddition 21 | { 22 | NSLog(@"categoryAddition"); 23 | } 24 | 25 | #pragma GCC diagnostic push 26 | #pragma GCC diagnostic ignored "-Wobjc-protocol-method-implementation" 27 | 28 | - (void)genericMethod 29 | { 30 | NSLog(@"genericMethod override"); 31 | } 32 | 33 | #pragma GCC diagnostic pop 34 | 35 | - (int)categoryProperty 36 | { 37 | return 0; 38 | } 39 | 40 | @end 41 | 42 | @interface DylibSubclass : Dylib 43 | @end 44 | 45 | @implementation DylibSubclass 46 | @end 47 | 48 | @interface Tool : NSObject 49 | { 50 | int m_intProperty; 51 | } 52 | @end 53 | 54 | @implementation Tool 55 | 56 | + (void)classVerb 57 | { 58 | NSLog(@"classVerb"); 59 | } 60 | 61 | - (void)verb 62 | { 63 | NSLog(@"verb"); 64 | } 65 | 66 | @synthesize intProperty = m_intProperty; 67 | 68 | @end 69 | 70 | int main(int argc, const char * argv[]) 71 | { 72 | @autoreleasepool { 73 | DylibSubclass* dylib = [[DylibSubclass alloc] init]; 74 | Tool* tool = [[Tool alloc] init]; 75 | [tool verb]; 76 | [Tool classVerb]; 77 | } 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o/Dylib.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "Protocol.h" 4 | 5 | @interface Dylib : NSObject 6 | { 7 | int m_intProperty; 8 | } 9 | - (void)genericMethod; 10 | - (void)targetMethod:(id)sender; 11 | @end 12 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o/Dylib.m: -------------------------------------------------------------------------------- 1 | // cc -framework Foundation -dynamiclib -o Dylib.dylib Dylib.m 2 | 3 | #import "Dylib.h" 4 | 5 | @interface Dylib () 6 | @end 7 | 8 | @implementation Dylib 9 | 10 | - (void)genericMethod 11 | { 12 | NSLog(@"genericMethod"); 13 | } 14 | 15 | - (void)targetMethod:(id)sender 16 | { 17 | NSLog(@"verb"); 18 | } 19 | 20 | #pragma mark Protocol Verbing 21 | 22 | + (void)classVerb 23 | { 24 | NSLog(@"classVerb"); 25 | } 26 | 27 | - (void)verb 28 | { 29 | NSLog(@"verb"); 30 | } 31 | 32 | @synthesize intProperty = m_intProperty; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o/Protocol.h: -------------------------------------------------------------------------------- 1 | @protocol Verbing 2 | + (void)classVerb; 3 | - (void) verb; 4 | @property (nonatomic, readonly) int intProperty; 5 | 6 | @optional 7 | + (void)classOptionalVerb; 8 | - (void)optionalVerb; 9 | @end -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-o/Tool.m: -------------------------------------------------------------------------------- 1 | // cc -framework Foundation Tool.m Dylib.dylib 2 | 3 | #import 4 | #import "Dylib.h" 5 | 6 | @interface Dylib (Category) 7 | + (void)categoryClass; 8 | - (void)categoryAddition; 9 | - (void)genericMethod; 10 | @property (nonatomic, readonly) int categoryProperty; 11 | @end 12 | 13 | @implementation Dylib (Category) 14 | 15 | + (void)categoryClass 16 | { 17 | NSLog(@"categoryClass"); 18 | } 19 | 20 | - (void)categoryAddition 21 | { 22 | NSLog(@"categoryAddition"); 23 | } 24 | 25 | #pragma GCC diagnostic push 26 | #pragma GCC diagnostic ignored "-Wobjc-protocol-method-implementation" 27 | 28 | - (void)genericMethod 29 | { 30 | NSLog(@"genericMethod override"); 31 | } 32 | 33 | #pragma GCC diagnostic pop 34 | 35 | - (int)categoryProperty 36 | { 37 | return 0; 38 | } 39 | 40 | @end 41 | 42 | @interface DylibSubclass : Dylib 43 | @end 44 | 45 | @implementation DylibSubclass 46 | @end 47 | 48 | @interface Tool : NSObject 49 | { 50 | int m_intProperty; 51 | } 52 | @end 53 | 54 | @implementation Tool 55 | 56 | + (void)classVerb 57 | { 58 | NSLog(@"classVerb"); 59 | } 60 | 61 | - (void)verb 62 | { 63 | NSLog(@"verb"); 64 | } 65 | 66 | @synthesize intProperty = m_intProperty; 67 | 68 | @end 69 | 70 | int main(int argc, const char * argv[]) 71 | { 72 | @autoreleasepool { 73 | DylibSubclass* dylib = [[DylibSubclass alloc] init]; 74 | } 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/firmware.c: -------------------------------------------------------------------------------- 1 | int x = 0; 2 | int* g = &x; 3 | 4 | int y[1000] = {1}; 5 | int* h = &y[1]; 6 | int* i = &y[999]; 7 | 8 | int start(void) 9 | { 10 | return *g; 11 | } 12 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/tool.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void _makestr(char** s) 7 | { 8 | const char* hw = "hello, world!"; 9 | size_t len = strlen(hw); 10 | *s = malloc(len + 1); 11 | snprintf(*s, len + 1, "%s", hw); 12 | } 13 | 14 | void _freestr(char** s) 15 | { 16 | assert(s); 17 | assert(*s); 18 | free(*s); 19 | } 20 | 21 | void _showstr(char** s) 22 | { 23 | assert(s); 24 | assert(*s); 25 | printf("%s\n", *s); 26 | } 27 | 28 | void (*funcs[])(char**) = { /* I had to look this syntax up :/ */ 29 | _makestr, 30 | _showstr, 31 | _freestr, 32 | }; 33 | 34 | FILE** unauth_bind = &stderr; 35 | void (*auth_rebase)(char**s) = &_makestr; 36 | int x = 0, *unauth_rebase = &x; 37 | 38 | int main (void) 39 | { 40 | int n = sizeof(funcs) / sizeof(*funcs); 41 | char* s; 42 | for (int i = 0; i < n; ++i) { 43 | funcs[i](&s); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/tool_ARM64E: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-pointer-formats/tool_ARM64E -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/tool_NONE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-pointer-formats/tool_NONE -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/tool_PTR_32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-pointer-formats/tool_PTR_32 -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/tool_PTR_32_FIRMWARE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-pointer-formats/tool_PTR_32_FIRMWARE -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/tool_PTR_64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-pointer-formats/tool_PTR_64 -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/tool_PTR_ARM64E_USERLAND24: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-pointer-formats/tool_PTR_ARM64E_USERLAND24 -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-pointer-formats/tool_THREADED: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/otool-classic-pointer-formats/tool_THREADED -------------------------------------------------------------------------------- /tests/test-cases/otool-classic-t/hello.s: -------------------------------------------------------------------------------- 1 | .section __TEXT,__text,regular,pure_instructions 2 | .build_version macos, 13, 0 sdk_version 13, 0 3 | .globl _main ## -- Begin function main 4 | .p2align 4, 0x90 5 | _main: ## @main 6 | ## %bb.0: 7 | pushq %rbp 8 | movq %rsp, %rbp 9 | subq $16, %rsp 10 | movl $0, -4(%rbp) 11 | leaq L_.str(%rip), %rdi 12 | movb $0, %al 13 | callq _printf 14 | xorl %eax, %eax 15 | addq $16, %rsp 16 | popq %rbp 17 | retq 18 | ## -- End function 19 | .section __TEXT,__cstring,cstring_literals 20 | L_.str: ## @.str 21 | .asciz "hello, world!\n" 22 | 23 | .subsections_via_symbols 24 | -------------------------------------------------------------------------------- /tests/test-cases/pagestuff-chained-binds/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # pagestuff prints basic statistics about how Mach-O structures are laid 4 | # out on a per-page basis. 5 | 6 | TESTROOT = ../.. 7 | include ${TESTROOT}/include/common.makefile 8 | 9 | all: 10 | ${CC} -Wl,-fixup_chains -o hello ${TESTROOT}/src/hello.c 11 | 12 | ${PAGESTUFF} hello -a | ${CHECK} -p OPTA 13 | # OPTA: File Page 0 contains Mach-O headers 14 | # OPTA: File Page \d+ contains dyld info for chained fixups 15 | # OPTA: File Page \d+ contains dyld info for exported symbols (TRIE) 16 | 17 | ${PAGESTUFF} hello -p | ${CHECK} -p OPTP 18 | # OPTP: FP_MACH_O 19 | # OPTP-NEXT: offset = 0 20 | # OPTP-NEXT: size = \d+ 21 | # OPTP: MP_DYLD_CHAINED_FIXUPS 22 | # OPTP-NEXT: offset = \d+ 23 | # OPTP-NEXT: size = \d+ 24 | # OPTP-NEXT: MP_DYLD_EXPORTS_TRIE 25 | # OPTP-NEXT: offset = \d+ 26 | # OPTP-NEXT: size = \d+ 27 | 28 | echo PASS 29 | 30 | clean: 31 | rm -f hello 32 | -------------------------------------------------------------------------------- /tests/test-cases/pagestuff-usage/testfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/pagestuff-usage/testfile -------------------------------------------------------------------------------- /tests/test-cases/ranlib-atomic/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # compile a library function 8 | ${CC} -arch $(ARCH) -o libfoo.o $(LOCAL_CC_FLAGS) -c libfoo.c 9 | 10 | # verify ranlib works, for completeness ... 11 | ${FAIL_IF_ERROR} ar r libfoo.a libfoo.o 2>&1 12 | ${FAIL_IF_ERROR} ${RANLIB} libfoo.a 13 | ${FAIL_IF_ERROR} test -f libfoo.a 14 | rm -f libfoo.a 15 | 16 | # force-fail ranlib mid-write. In this case, the .a file will still 17 | # exist, but it should be unmodified. 18 | ${FAIL_IF_ERROR} ar r libfoo.a libfoo.o 2>&1 19 | cp libfoo.a libfoo.a.orig 20 | RANLIB_FORCE_FAIL=YES export RANLIB_FORCE_FAIL; \ 21 | ${FAIL_IF_SUCCESS} ${RANLIB} libfoo.a 2>&1 22 | ${PASS_IFF_SUCCESS} cmp libfoo.a libfoo.a.orig 23 | 24 | clean: 25 | rm -rf libfoo.o libfoo.a libfoo1.a libfoo.a.* 26 | -------------------------------------------------------------------------------- /tests/test-cases/ranlib-atomic/libfoo.c: -------------------------------------------------------------------------------- 1 | int foo(void) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-cases/ranlib-t/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | .PHONY: all clean 8 | 9 | all: 10 | ${CC} -o file.o -c ${TESTROOT}/src/foo.c 11 | ${AR} -rc file.a file.o 12 | ${RANLIB} -t file.a 2>errs.txt 13 | cat errs.txt 14 | ${CHECK} -i errs.txt 15 | # CHECK: warning: .*ranlib: touch option (-t) ignored (table of contents rebuilt anyway) 16 | echo PASS 17 | 18 | clean: 19 | rm -f file.o file.a errs.txt 20 | 21 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-extract/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS IOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | $(CC) -arch $(ARCH) -Wl,-sectcreate,Memento,Mori,MementoMori1.txt \ 8 | -o main main.c 9 | if [ "$(ARCH)" == "x64_64" ]; \ 10 | then \ 11 | ./main | grep "Remember that you will die." | ${FAIL_IF_EMPTY}; \ 12 | fi 13 | ${SEGEDIT} -e Memento Mori MementoMori2.txt main 14 | ${PASS_IFF_SUCCESS} diff MementoMori1.txt MementoMori2.txt 15 | 16 | clean: 17 | rm -rf main MementoMori2.txt 18 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-extract/MementoMori1.txt: -------------------------------------------------------------------------------- 1 | Remember that you will die. 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-extract/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifdef __LP64__ 6 | #define MACH_HEADER mach_header_64 7 | #else 8 | #define MACH_HEADER mach_header 9 | #endif 10 | 11 | int main(void) 12 | { 13 | const struct MACH_HEADER* mhp = &_mh_execute_header; 14 | unsigned long size; 15 | const unsigned char* buf = getsectiondata(mhp, "Memento", "Mori", &size); 16 | if (buf) { 17 | printf("%s", buf); 18 | } 19 | return buf ? 0 : 1; 20 | } 21 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-bigendian/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | .PHONY: all clean 8 | 9 | all: 10 | # Build a test binary that contains a zero-length __DATA_DIRTY section 11 | # as well as a small (single page?) replacable section. Then, convert 12 | # that binary into something resembling a PowerPC tool. 13 | $(CC) -arch $(ARCH) -Wl,-sectcreate,Memento,Mori,MementoMori1.txt \ 14 | -Wl,-dirty_data_list,dirty_data.txt \ 15 | -o main main.c 16 | ${TESTROOT}/bin/rewrite-macho.pl -a ppc -o main main 17 | $(OTOOL) -lv main | grep __DATA_DIRTY -A4 -B2 | $(CHECK) 18 | # CHECK: cmd LC_SEGMENT_64 19 | # CHECK: segname __DATA_DIRTY 20 | # CHECK: fileoff 0 21 | # CHECK: filesize 0 22 | # CHECK-NEXT: -- 23 | 24 | # Replace a section without resizing. 25 | ${SEGEDIT} -r Memento Mori MementoMori2.txt -o main2 main 26 | 27 | # Attempt to resize a section 28 | $(CC) -arch $(ARCH) -Wl,-sectcreate,Memento,Mori,/dev/null \ 29 | -o main main.c 30 | ${TESTROOT}/bin/rewrite-macho.pl -a ppc -o main main 31 | ${FAIL_IF_SUCCESS} ${SEGEDIT} -r Memento Mori MementoMori2.txt \ 32 | -o main2 main 2>&1 33 | 34 | ${PASS_IFF_SUCCESS} true 35 | 36 | clean: 37 | rm -rf main main2 38 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-bigendian/MementoMori1.txt: -------------------------------------------------------------------------------- 1 | Remember that you will die. 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-bigendian/MementoMori2.txt: -------------------------------------------------------------------------------- 1 | Always remember that you will die. 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-bigendian/dirty_data.txt: -------------------------------------------------------------------------------- 1 | _gGlobal 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-bigendian/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifdef __LP64__ 6 | #define MACH_HEADER mach_header_64 7 | #else 8 | #define MACH_HEADER mach_header 9 | #endif 10 | 11 | int gGlobal = 0; 12 | 13 | int main(void) 14 | { 15 | const struct MACH_HEADER* mhp = &_mh_execute_header; 16 | unsigned long size; 17 | const unsigned char* buf = getsectiondata(mhp, "Memento", "Mori", &size); 18 | if (buf) { 19 | printf("%s", buf); 20 | } 21 | return buf ? gGlobal : 1; 22 | } 23 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-chained-binds/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS IOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # Build a test binary that contains a zero-length __DATA_DIRTY section 8 | # as well as a small (single page?) replacable section. 9 | $(CC) -arch $(ARCH) -Wl,-sectcreate,Memento,Mori,MementoMori1.txt \ 10 | -Wl,-dirty_data_list,dirty_data.txt \ 11 | -Wl,-fixup_chains \ 12 | -o main main.c 13 | $(OTOOL) -lv main | grep __DATA_DIRTY -A4 -B2 | $(CHECK) 14 | # CHECK: cmd LC_SEGMENT_64 15 | # CHECK: segname __DATA_DIRTY 16 | # CHECK: fileoff 0 17 | # CHECK: filesize 0 18 | # CHECK-NEXT: -- 19 | 20 | # Replace a section without resizing 21 | if [ "$(ARCH)" == "x64_64" ]; \ 22 | then \ 23 | ./main | grep "Remember that you will die." | ${FAIL_IF_EMPTY}; \ 24 | fi 25 | ${SEGEDIT} -r Memento Mori MementoMori2.txt -o main2 main 26 | if [ "$(ARCH)" == "x64_64" ]; \ 27 | then \ 28 | ./main2 | grep "Always remember that you will die." | \ 29 | ${FAIL_IF_EMPTY}; \ 30 | fi 31 | 32 | # Attempt to resize a zero-length segment 33 | $(CC) -arch $(ARCH) -Wl,-sectcreate,Memento,Mori,/dev/null \ 34 | -Wl,-fixup_chains \ 35 | -o main main.c 36 | ${FAIL_IF_SUCCESS} ${SEGEDIT} -r Memento Mori MementoMori2.txt \ 37 | -o main2 main 2>&1 38 | 39 | ${PASS_IFF_SUCCESS} true 40 | 41 | clean: 42 | rm -rf main main2 43 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-chained-binds/MementoMori1.txt: -------------------------------------------------------------------------------- 1 | Remember that you will die. 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-chained-binds/MementoMori2.txt: -------------------------------------------------------------------------------- 1 | Always remember that you will die. 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-chained-binds/dirty_data.txt: -------------------------------------------------------------------------------- 1 | _gGlobal 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace-chained-binds/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifdef __LP64__ 6 | #define MACH_HEADER mach_header_64 7 | #else 8 | #define MACH_HEADER mach_header 9 | #endif 10 | 11 | int gGlobal = 0; 12 | 13 | int main(void) 14 | { 15 | const struct MACH_HEADER* mhp = &_mh_execute_header; 16 | unsigned long size; 17 | const unsigned char* buf = getsectiondata(mhp, "Memento", "Mori", &size); 18 | if (buf) { 19 | printf("%s", buf); 20 | } 21 | return buf ? gGlobal : 1; 22 | } 23 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS IOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # Build a test binary that contains a zero-length __DATA_DIRTY section 8 | # as well as a small (single page?) replacable section. 9 | $(CC) -arch $(ARCH) -Wl,-sectcreate,Memento,Mori,MementoMori1.txt \ 10 | -Wl,-dirty_data_list,dirty_data.txt \ 11 | -o main main.c 12 | codesign -s - main 13 | $(OTOOL) -lv main | grep __DATA_DIRTY -A4 -B2 | $(CHECK) 14 | # CHECK: cmd LC_SEGMENT_64 15 | # CHECK: segname __DATA_DIRTY 16 | # CHECK: fileoff 0 17 | # CHECK: filesize 0 18 | # CHECK-NEXT: -- 19 | 20 | # Replace a section without resizing. 21 | if [ "$(ARCH)" == "x64_64" ]; \ 22 | then \ 23 | ./main | grep "Remember that you will die." | ${FAIL_IF_EMPTY}; \ 24 | fi 25 | ${SEGEDIT} -r Memento Mori MementoMori2.txt -o main2 main 2>&1 | \ 26 | ${CHECK} -p CS_WARN 27 | # CS_WARN: .*changes being made to the file will invalidate the code signature in:.* 28 | if [ "$(ARCH)" == "x64_64" ]; \ 29 | then \ 30 | ./main2 | grep "Always remember that you will die." | \ 31 | ${FAIL_IF_EMPTY}; \ 32 | fi 33 | 34 | # Attempt to resize a section 35 | $(CC) -arch $(ARCH) -Wl,-sectcreate,Memento,Mori,/dev/null \ 36 | -o main main.c 37 | ${FAIL_IF_SUCCESS} ${SEGEDIT} -r Memento Mori MementoMori2.txt \ 38 | -o main2 main 2>&1 39 | 40 | ${PASS_IFF_SUCCESS} true 41 | 42 | clean: 43 | rm -rf main main2 44 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace/MementoMori1.txt: -------------------------------------------------------------------------------- 1 | Remember that you will die. 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace/MementoMori2.txt: -------------------------------------------------------------------------------- 1 | Always remember that you will die. 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace/dirty_data.txt: -------------------------------------------------------------------------------- 1 | _gGlobal 2 | -------------------------------------------------------------------------------- /tests/test-cases/segedit-replace/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifdef __LP64__ 6 | #define MACH_HEADER mach_header_64 7 | #else 8 | #define MACH_HEADER mach_header 9 | #endif 10 | 11 | int gGlobal = 0; 12 | 13 | int main(void) 14 | { 15 | const struct MACH_HEADER* mhp = &_mh_execute_header; 16 | unsigned long size; 17 | const unsigned char* buf = getsectiondata(mhp, "Memento", "Mori", &size); 18 | if (buf) { 19 | printf("%s", buf); 20 | } 21 | return buf ? gGlobal : 1; 22 | } 23 | -------------------------------------------------------------------------------- /tests/test-cases/strings-stdin/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | echo testing > tmp.txt 8 | ${STRINGS} -a -t d tmp.txt | grep "0 testing" | ${FAIL_IF_EMPTY} 9 | ${STRINGS} -a -t d < tmp.txt | grep "0 testing" | ${FAIL_IF_EMPTY} 10 | echo testing | ${STRINGS} -a -t d | grep "0 testing" | ${FAIL_IF_EMPTY} 11 | ${PASS_IFF_SUCCESS} true 12 | clean: 13 | rm -rf tmp.txt 14 | -------------------------------------------------------------------------------- /tests/test-cases/strip-D/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | all: 8 | # compile a library function 9 | ${CC} -o libfoo.o -c ${TESTROOT}/src/foo.c 10 | 11 | # build a deterministic library 12 | ${LIBTOOL} -static -D -o libfoo.a libfoo.o 13 | 14 | # strip the library 15 | ${STRIP} -D libfoo.a 16 | 17 | # verify 18 | ${OTOOL} -av libfoo.a | ${CHECK} 19 | # CHECK: Archive : libfoo.a 20 | # CHECK-NEXT: -rw-r--r-- 0/0 \s+\d+ Wed Dec 31 16:00:00 1969 __.SYMDEF SORTED 21 | # CHECK-NEXT: -rw-r--r-- 0/0 \s+\d+ Wed Dec 31 16:00:00 1969 libfoo.o 22 | 23 | echo PASS 24 | 25 | clean: 26 | rm -f libfoo.o libfoo.a 27 | -------------------------------------------------------------------------------- /tests/test-cases/strip-R/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | LD_PATH := $(shell xcrun --toolchain ${TOOLCHAIN} -f ld 2>/dev/null) 7 | 8 | all: 9 | # compile a test library 10 | ${CC} -arch ${ARCH} -o foo.o -c ${TESTROOT}/src/foo.c 11 | ${CC} -arch ${ARCH} -o bar.o -c ${TESTROOT}/src/bar.c 12 | ${CC} -r -o lib.o foo.o bar.o 2>&1 13 | STRIP_LD=${LD_PATH} ${STRIP} -R list.txt -o lib2.o lib.o 14 | nm -m lib2.o | ${CHECK} 15 | # CHECK: .*(__TEXT,__text) private external _foo 16 | # CHECK-NOT: .*(__TEXT,__text) external _foo 17 | 18 | echo PASS 19 | clean: 20 | rm -f foo.o bar.o lib.o lib2.o 21 | -------------------------------------------------------------------------------- /tests/test-cases/strip-R/list.txt: -------------------------------------------------------------------------------- 1 | _foo 2 | -------------------------------------------------------------------------------- /tests/test-cases/strip-S-dice/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # 4 | # Verify stripping an object-file w/ a non-zero data-in-code payload works. 5 | # 6 | # The test file comes from cctools libstuff's own get_arch_from_host.o. 7 | 8 | PLATFORM = MACOS 9 | TESTROOT = ../.. 10 | include ${TESTROOT}/include/common.makefile 11 | 12 | LD := $(shell xcrun -f --toolchain $(TOOLCHAIN) ld) 13 | 14 | .PHONY: all clean 15 | 16 | all: 17 | STRIP_LD=$(LD) $(STRIP) -S -o stripped.o dice.o 2>stderr.out 18 | cat stderr.out 19 | $(OTOOLC) -lv stripped.o | $(CHECK) 20 | # CHECK: Load command 1 21 | # CHECK: cmd LC_SYMTAB 22 | # CHECK: cmdsize 24 23 | # CHECK: symoff 5432 24 | # CHECK: nsyms 63 25 | # CHECK: stroff 6440 26 | # CHECK: strsize 392 27 | 28 | echo PASS 29 | 30 | clean: 31 | rm -f stripped.o stderr.out 32 | -------------------------------------------------------------------------------- /tests/test-cases/strip-S-dice/dice.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/strip-S-dice/dice.o -------------------------------------------------------------------------------- /tests/test-cases/strip-S-nosyms/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # 4 | # Verify stripping a stripped file w/ symbolless strings preserves strings. 5 | # Yeah, I know. 6 | # 7 | # The test file was harvested from a swift project by Nick Kledzik. It is 8 | # not clear how to manually create a test file like this. 9 | 10 | PLATFORM = MACOS 11 | TESTROOT = ../.. 12 | include ${TESTROOT}/include/common.makefile 13 | 14 | LD := $(shell xcrun -f --toolchain $(TOOLCHAIN) ld) 15 | 16 | .PHONY: all clean 17 | 18 | all: 19 | STRIP_LD=$(LD) $(STRIP) -S -o stripped.o nosyms.o 2>stderr.out 20 | cat stderr.out 21 | $(OTOOLC) -lv stripped.o | $(CHECK) 22 | # CHECK: Load command 1 23 | # CHECK: cmd LC_SYMTAB 24 | # CHECK: cmdsize 24 25 | # CHECK: symoff 0 26 | # CHECK: nsyms 0 27 | # CHECK: stroff 192 28 | # CHECK: strsize 8 29 | 30 | echo PASS 31 | 32 | clean: 33 | rm -f stripped.o stderr.out 34 | -------------------------------------------------------------------------------- /tests/test-cases/strip-S-nosyms/nosyms.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/strip-S-nosyms/nosyms.o -------------------------------------------------------------------------------- /tests/test-cases/strip-T/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | .PHONY: all clean 4 | 5 | TESTROOT = ../.. 6 | include ${TESTROOT}/include/common.makefile 7 | 8 | all: hello 9 | # verify the stripped file has NLIST_OUTOFSYNC_WITH_DYLDINFO 10 | ${OTOOLC} -hv hello.sym | ${CHECK} -p NOFLAG 11 | ${OTOOLC} -hv hello | ${CHECK} -p HASFLAG 12 | # NOFLAG-NOT: .*NLIST_OUTOFSYNC_WITH_DYLDINFO.* 13 | # HASFLAG: .*NLIST_OUTOFSYNC_WITH_DYLDINFO.* 14 | 15 | # verify the unstripped binary has a function named "SayHelloTo" 16 | # and the stripped binary does not 17 | ${NMC} hello.sym | ${CHECK} -p HASHELLO 18 | ${NMC} hello | ${CHECK} -p NOHELLO 19 | # HASHELLO: .*SayHelloTo.* 20 | # NOHELLO-NOT: .*SayHelloTo.* 21 | 22 | echo PASS 23 | 24 | hello: 25 | # building hello 26 | swiftc -o hello.sym hello.swift 27 | ${STRIP} -ST -o hello hello.sym 28 | 29 | clean: 30 | rm -rf hello.sym hello 31 | -------------------------------------------------------------------------------- /tests/test-cases/strip-T/hello.swift: -------------------------------------------------------------------------------- 1 | func SayHelloTo(name: String) -> String 2 | { 3 | let greeting = "hello, " + name + "!" 4 | return greeting 5 | } 6 | 7 | func PrintHelloTo(name: String) 8 | { 9 | let greeting = SayHelloTo(name:name) 10 | print(greeting) 11 | } 12 | 13 | PrintHelloTo(name:"world") 14 | PrintHelloTo(name:"mike") 15 | -------------------------------------------------------------------------------- /tests/test-cases/strip-chained-binds/symbols.c: -------------------------------------------------------------------------------- 1 | #ifndef DYLIB 2 | int global_sym; 3 | #endif /* DYLIB */ 4 | 5 | extern int entry(void); 6 | 7 | static int private_sym(void) 8 | { 9 | return 1; 10 | } 11 | 12 | #ifdef DYLIB 13 | int entry(void) 14 | { 15 | #else 16 | int main(void) 17 | { 18 | global_sym = 19 | #endif /* DYLIB */ 20 | #ifdef DYLIB_CLIENT 21 | entry(); 22 | #else 23 | private_sym(); 24 | #endif /* DYLIB_CLIENT */ 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /tests/test-cases/strip-dylib-exports-trie/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # rdar://99566424 (SEED: Web: strip `-r -u` is inconsistent with default invocation) 4 | # Test dylib's exports trie isn't pruned even when using -ru. 5 | 6 | .PHONY: all clean 7 | 8 | TESTROOT = ../.. 9 | include ${TESTROOT}/include/common.makefile 10 | 11 | all: hello 12 | # verify the unstripped binary has a function named "foo_impl" 13 | # and the stripped binary does not in the symbol table 14 | ${NMC} libfoo.dylib.sym | ${CHECK} -p HASFOO 15 | ${NMC} libfoo.dylib | ${CHECK} -p NOFOO 16 | # verify the unstripped and stripped binary have a function named "foo_impl" 17 | # in the exports trie 18 | echo ${DYLD_INFO} 19 | ${DYLD_INFO} -exports libfoo.dylib.sym | ${CHECK} -p HASFOO 20 | ${DYLD_INFO} -exports libfoo.dylib | ${CHECK} -p HASFOO 21 | # HASFOO: .*foo_impl.* 22 | # NOFOO-NOT: .*foo_impl.* 23 | 24 | echo PASS 25 | 26 | hello: 27 | clang -shared -o libfoo.dylib.sym foo.c 28 | ${STRIP} -ru -o libfoo.dylib libfoo.dylib.sym 29 | 30 | clean: 31 | rm -rf libfoo.dylib.sym libfoo.dylib 32 | -------------------------------------------------------------------------------- /tests/test-cases/strip-dylib-exports-trie/foo.c: -------------------------------------------------------------------------------- 1 | int foo_impl() { return 0; } 2 | -------------------------------------------------------------------------------- /tests/test-cases/strip-indirectsym_pad/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | PLATFORM = MACOS 4 | TESTROOT = ../.. 5 | include ${TESTROOT}/include/common.makefile 6 | 7 | .PHONY: all clean 8 | 9 | all: 10 | $(STRIP) -x -c -o dylib dylib.sym 11 | ls -ld dylib | $(CHECK) 12 | # CHECK: .* 4096 .* 13 | 14 | echo PASS 15 | 16 | clean: 17 | rm -f dylib.dylib 18 | 19 | LD64_606_3 := /SWE/release/Software/Azul/BuildRecords/ld64/ld64-606.3\#10/install/Root/Applications/Xcode.app/Contents/Developer/Toolchains/iOS15.0.xctoolchain/usr/bin/ld 20 | XCODE_LIB := /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib 21 | 22 | dylib.sym: dylib.o 23 | DYLD_LIBRARY_PATH=$(XCODE_LIB) \ 24 | $(LD64_606_3) -dylib -o $@ $^ \ 25 | -framework System -framework CoreFoundation 26 | rm -f dylib.o 27 | -------------------------------------------------------------------------------- /tests/test-cases/strip-indirectsym_pad/dylib.sym: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keith/cctools/675c0644a2c90af04a075b048a438af35dfd7b4f/tests/test-cases/strip-indirectsym_pad/dylib.sym -------------------------------------------------------------------------------- /tests/test-cases/strip-resign/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # ER: Change "strip" tool to ad-hoc sign 3 | 4 | PLATFORM = MACOS 5 | TESTROOT = ../.. 6 | include ${TESTROOT}/include/common.makefile 7 | SRC = ${TESTROOT}/src 8 | DATA = ${TESTROOT}/data 9 | 10 | .PHONY: all clean 11 | 12 | all: 13 | # test re-signing an apple signed binary 14 | ${STRIP} ${DATA}/echo.fat -o echo 2>&1 | ${CHECK} -p APPLE 15 | # APPLE: .*strip: warning: changes being made to the file will invalidate the code signature in: .* (for architecture x86_64) 16 | # APPLE: .*strip: warning: changes being made to the file will invalidate the code signature in: .* (for architecture arm64e) 17 | 18 | # test re-signing a linker-signed binary 19 | ${CC} -o hello ${SRC}/hello.c 20 | ${STRIP} hello 2>&1 | ${CHECK} -p ADHOC 21 | # ADHOC-NOT: .*strip: warning: changes being made to the file will invalidate the code signature.* 22 | ./hello | ${CHECK} -p HELLO 23 | # HELLO: hello, world! 24 | 25 | echo PASS 26 | 27 | clean: 28 | rm -f echo hello 29 | 30 | -------------------------------------------------------------------------------- /tests/test-cases/strip-uniq/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | LD ?= ld 6 | 7 | all: 8 | # build an app with duplicate local static symbols 9 | ${CC} -arch $(ARCH) -g -o foo.o -c foo.c 10 | ${CC} -arch $(ARCH) -g -o bar.o -c bar.c 11 | ${CC} -arch $(ARCH) -g -o main.o -c main.c 12 | ${LD} -lSystem -o main foo.o bar.o main.o 2>&1 13 | 14 | # verify the linker uniqed the local strings, and if so, 15 | # strip the binary and verify the strings are still unqiued 16 | uniq=`nm -px main | awk '{ print $$2 " " $$5 " " $$6 }' | \ 17 | grep '^0e ' | uniq | wc -l | tr -d " "`; \ 18 | if [ "$$uniq" = "1" ]; \ 19 | then \ 20 | ${STRIP} -S main; \ 21 | nm -px main | awk '{ print $$2 " " $$5 " " $$6 }' | grep '^0e ' | \ 22 | uniq | wc -l | grep 1 | $(FAIL_IF_EMPTY); \ 23 | else \ 24 | echo WARNING: ld did not uniq the strings; \ 25 | echo WARNING: silently giving up; \ 26 | fi 27 | 28 | $(PASS_IFF) true 29 | 30 | clean: 31 | rm -rf foo.o bar.o main.o main 32 | -------------------------------------------------------------------------------- /tests/test-cases/strip-uniq/bar.c: -------------------------------------------------------------------------------- 1 | static int debug(void) 2 | { 3 | return 0; 4 | } 5 | 6 | int bar(void) 7 | { 8 | debug(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/test-cases/strip-uniq/foo.c: -------------------------------------------------------------------------------- 1 | static int debug(void) 2 | { 3 | return 0; 4 | } 5 | 6 | int foo(void) 7 | { 8 | debug(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/test-cases/strip-uniq/main.c: -------------------------------------------------------------------------------- 1 | extern int foo(void); 2 | extern int bar(void); 3 | 4 | int main(void) 5 | { 6 | if (0 == foo() && 0 == bar()) 7 | return 0; 8 | 9 | return 1; 10 | } -------------------------------------------------------------------------------- /tests/test-cases/strip-zero-ar-date/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | # 3 | # test zeroing ar dates when stripping an archive. 4 | # 5 | # With ZERO_AR_DATE, strip will zero the .a time, libtool will not 6 | 7 | .PHOHY: all clean 8 | 9 | PLATFORM = MACOS 10 | TESTROOT = ../.. 11 | include ${TESTROOT}/include/common.makefile 12 | 13 | all: 14 | # build an archive 15 | ${CC} -o foo.o -c ${TESTROOT}/src/foo.c 16 | ${LIBTOOL} -static -o foo.a foo.o 17 | 18 | # verify the archive has two components in it 19 | ${OTOOL} -av foo.a | ${CHECK} -p TOC 20 | # TOC: Archive : foo.a 21 | # TOC: .* __.SYMDEF SORTED 22 | # TOC: .* foo.o 23 | 24 | # verify the archive is newer than the .o file 25 | ls -1tr foo.o foo.a | ${CHECK} -p LS 26 | # LS: foo.o 27 | # LS: foo.a 28 | 29 | # strip the archive without zeroing dates. 30 | ${STRIP} foo.a 2>&1 31 | ${OTOOL} -av foo.a | ${CHECK} -p NOZERO 32 | # NOZERO: Archive : foo.a 33 | # NOZERO-NOT: .* Wed Dec 31 \d+:00:00 1969 __.SYMDEF SORTED 34 | # NOZERO: .* __.SYMDEF SORTED 35 | # NOZERO-NOT: .* Wed Dec 31 \d+:00:00 1969 foo.o 36 | # NOZERO: .* foo.o 37 | 38 | # verify the archive is still newer than the .o file 39 | ls -1tr foo.o foo.a | ${CHECK} -p LS 40 | 41 | # strip the archive and zero dates. 42 | ZERO_AR_DATE=YES ${STRIP} foo.a 2>&1 43 | ${OTOOL} -av foo.a | ${CHECK} -p ZERO 44 | # ZERO: Archive : foo.a 45 | # ZERO: .* Wed Dec 31 \d+:00:00 1969 __.SYMDEF SORTED 46 | # ZERO: .* Wed Dec 31 \d+:00:00 1969 foo.o 47 | 48 | # verify the archive is still newer than the .o file 49 | ls -1tr foo.o foo.a | ${CHECK} -p LS 50 | 51 | echo PASS 52 | 53 | clean: 54 | rm -rf foo.o foo.a 55 | -------------------------------------------------------------------------------- /tests/test-cases/verify-build-version/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int foo(void) 4 | { 5 | printf("hello, world!\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/test-cases/verify-iosmac-backdeploy/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # build the vers tool, for now 8 | $(CC) -o verstool ${TESTROOT}/src/verstool.c 9 | codesign -s - verstool 10 | 11 | # compile a dylib 12 | $(CC) -dynamiclib -o foo.dylib foo.c 13 | 14 | # check version-min + build-version 15 | ./verstool foo.dylib write \ 16 | version-min macos 10.13 10.13 \ 17 | build-version iosmac 12 12 \ 18 | foo2.dylib 19 | $(FAIL_IF_ERROR) $(CS_ALLOC) -i foo2.dylib -a x86_64 4096 \ 20 | -o foo3.dylib 2>&1 21 | 22 | # check build-version + version-min 23 | ./verstool foo.dylib write \ 24 | build-version iosmac 12 12 \ 25 | version-min macos 10.13 10.13 \ 26 | foo2.dylib 27 | $(FAIL_IF_ERROR) $(CS_ALLOC) -i foo2.dylib -a x86_64 4096 \ 28 | -o foo3.dylib 2>&1 29 | 30 | # verify you can't mix other things. 31 | ./verstool foo.dylib write \ 32 | build-version iosmac 12 12 \ 33 | version-min ios 12 12 \ 34 | foo2.dylib 35 | $(FAIL_IF_SUCCESS) $(CS_ALLOC) -i foo2.dylib -a x86_64 4096 \ 36 | -o foo3.dylib 2>&1 37 | 38 | ./verstool foo.dylib write \ 39 | version-min ios 12 12 \ 40 | build-version iosmac 12 12 \ 41 | foo2.dylib 42 | $(FAIL_IF_SUCCESS) $(CS_ALLOC) -i foo2.dylib -a x86_64 4096 \ 43 | -o foo3.dylib 2>&1 44 | 45 | ./verstool foo.dylib write \ 46 | build-version iosmac 12 12 \ 47 | build-version ios 12 12 \ 48 | foo2.dylib 49 | $(FAIL_IF_SUCCESS) $(CS_ALLOC) -i foo2.dylib -a x86_64 4096 \ 50 | -o foo3.dylib 2>&1 51 | 52 | $(PASS_IFF) true 53 | 54 | clean: 55 | rm -rf foo.dylib foo2.dylib foo3.dylib verstool 56 | -------------------------------------------------------------------------------- /tests/test-cases/verify-iosmac-backdeploy/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int foo(void) 4 | { 5 | printf("hello, world!\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/test-cases/verify-iosmac/Makefile: -------------------------------------------------------------------------------- 1 | # PLATFORM: MACOS 2 | 3 | TESTROOT = ../.. 4 | include ${TESTROOT}/include/common.makefile 5 | 6 | all: 7 | # build the vers tool, for now 8 | $(CC) -o verstool ${TESTROOT}/src/verstool.c 9 | codesign -s - verstool 10 | 11 | # compile a dylib 12 | $(CC) -dynamiclib -o foo.dylib foo.c 13 | 14 | # verify iosmac load commands 15 | ./verstool foo.dylib write \ 16 | build-version macos 10.14 10.14 \ 17 | build-version iosmac 12 12 \ 18 | foo2.dylib 19 | $(FAIL_IF_ERROR) $(CS_ALLOC) -i foo2.dylib -a x86_64 4096 \ 20 | -o foo3.dylib 2>&1 21 | 22 | $(PASS_IFF) true 23 | 24 | clean: 25 | rm -rf foo.dylib foo2.dylib foo3.dylib verstool 26 | -------------------------------------------------------------------------------- /tests/test-cases/verify-iosmac/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int foo(void) 4 | { 5 | printf("hello, world!\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | if [[ $# -ne 1 ]]; then 6 | echo "usage: $0 URL" >&2 7 | exit 1 8 | fi 9 | 10 | readonly url=$1 11 | 12 | rm -rf ./APPLE_LICENSE ./ar ./as ./cbtlibs ./cctools.xcodeproj ./efitools ./gprof ./include ./ld ./libmacho ./libstuff ./libstuff_test ./man ./misc ./otool ./tests ./xcode 13 | 14 | curl -L --fail "$url" -o /tmp/ld.tar.gz 15 | tar xf /tmp/ld.tar.gz --strip-components=1 -C . 16 | -------------------------------------------------------------------------------- /xcode/as_license.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # install as OpenSource license files into /usr/local 4 | 5 | install_files() { 6 | src_dir=$1; shift 7 | dst_dir=$1; shift 8 | files=$* 9 | 10 | ( 11 | cd ${src_dir} 12 | mkdir -p ${dst_dir} 13 | install -c -m 444 ${files} ${dst_dir} 14 | ) 15 | } 16 | 17 | src=${SRCROOT}/as 18 | dst=${DSTROOT}/${CCTOOLS_USRLOCAL} 19 | 20 | install_files ${src} ${dst}/OpenSourceVersions cctools.plist 21 | install_files ${src} ${dst}/OpenSourceLicenses COPYING 22 | mv ${dst}/OpenSourceLicenses/COPYING ${dst}/OpenSourceLicenses/cctools.txt 23 | -------------------------------------------------------------------------------- /xcode/codesign_allocate.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // codesign_allocate.xcconfig 3 | // cctools 4 | // 5 | // Created by Michael Trent on 12/24/18. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | #include "public_tool.xcconfig" 12 | 13 | PRODUCT_NAME = codesign_allocate 14 | 15 | // embed an info plist into codesign_allocate for codesign's use. Details 16 | // can be found here: 17 | // 18 | // codesign_allocate should be a member of com.apple.tool.codesign_allocate 19 | 20 | 21 | OTHER_LDFLAGS = ${inherited} -sectcreate __TEXT __info_plist ${SRCROOT}/misc/codesign_allocate-Info.plist 22 | -------------------------------------------------------------------------------- /xcode/copy_if.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # copy_if copies a file into a directory if a condition is true. 4 | # 5 | # Currently copy_if assumes 'src-file' is a plain file that can be copied with 6 | # the cp command. The file cannot be renamed in-flight. the 'dst-dir' directory 7 | # will be created if necessary, and any pre-existing file will be removed from 8 | # the destination before the copy is attempted. 9 | # 10 | # The condition is considered true iff the condition parameter is present and 11 | # it has a non-NULL value. So: 12 | # 13 | # condition=NULL == FALSE 14 | # condition="" == FALSE 15 | # condition="YES" == TRUE 16 | # condition="NO" == TRUE 17 | # 18 | # Why such a weird usage? This is working around Xcode's inability to drive 19 | # whole targets and whole build phases conditionally, something that's trivial 20 | # in a Makefile. 21 | 22 | usage() { 23 | echo `basename $0`: error: $* 1>&2 24 | echo usage: `basename $0` 'src-file' 'dst-dir' 'condition' 1>&2 25 | exit 1 26 | } 27 | 28 | [ $# -gt 3 -o $# -lt 2 ] && usage "wrong number of arguments" 29 | 30 | src_file=$1; shift 31 | dst_dir=$1; shift 32 | condition=$1; shift 33 | src_base=`basename ${src_file}` 34 | 35 | if [ "${INSTALL_MODE_FLAG}" != "" ]; then 36 | mode=${INSTALL_MODE_FLAG} 37 | else 38 | mode="u+w,go-w,a+rX" 39 | fi 40 | 41 | if [ "${condition}" != "" ]; then 42 | echo "copying ${src_file} to ${dst_dir}" 43 | 44 | mkdir -p ${dst_dir}; 45 | rm -f ${dst_dir}/${src_base} 46 | cp ${src_file} ${dst_dir}/ 47 | chmod ${mode} ${dst_dir}/${src_base} 48 | fi 49 | -------------------------------------------------------------------------------- /xcode/create_symlink.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # create_symlink creates a symlink in 'dir' pointing to 'src-file' 4 | # 5 | # Currently create_symlink will create 'dir' if necessary. It does not require 6 | # 'src-file' to exist (see ln -s usage). Any pre-existing 'dst-file' will be 7 | # removed from 'dir' before the link is made. 8 | 9 | usage() { 10 | echo `basename $0`: error: $* 1>&2 11 | echo usage: `basename $0` 'dir' 'src-file' 'dst-file' 1>&2 12 | exit 1 13 | } 14 | 15 | [ $# -gt 3 -o $# -lt 3 ] && usage "wrong number of arguments" 16 | 17 | dir=$1; shift 18 | src_file=$1; shift 19 | dst_file=$1; shift 20 | 21 | mkdir -p $dir 22 | ( cd $dir; rm -f $dst_file; ln -s $src_file $dst_file ) 23 | -------------------------------------------------------------------------------- /xcode/libstuff.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // libstuff.xcconfig 3 | // stuff 4 | // 5 | // Created by Michael Trent on 12/20/18. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | // HEADER_SEARCH_PATHS includes the local toolchain headers in order to find 12 | // "llvm-c/lto.h" 13 | HEADER_SEARCH_PATHS = ${inherited} ${TOOLCHAIN_DIR}/usr/local/include 14 | 15 | // libstuff currently requires the LTO_SUPPORT macro to be defined in order to 16 | // compile support for LTO. This is built non-conditionally, and can probably 17 | // be factored out of the source code at some future point. 18 | LIBSTUFF_C_FLAGS_LTO = -DLTO_SUPPORT 19 | 20 | // libstuff builds an "apple_version.c" file that stamps the current project 21 | // version into the archive. Various cctools commands will print this version 22 | // upon request. To support this, libstuff passes the value of the 23 | // CURRENT_PROJECT_VERSION setting into apple_version.c as a #define 24 | LIBSTUFF_C_FLAGS_VERS = -DCURRENT_PROJECT_VERSION=\"${CURRENT_PROJECT_VERSION}\" 25 | 26 | // MacOS and Xcode default toolchain binaries are built with support for 27 | // re-signing binaries via libcodedirectory. 28 | CCTOOLS_C_FLAGS_CODEDIR_YES = -DCODEDIRECTORY_SUPPORT 29 | CCTOOLS_C_FLAGS_CODEDIR = ${CCTOOLS_C_FLAGS_CODEDIR_${CCTB_MACOS}${CCTB_XCODE}} 30 | 31 | OTHER_CFLAGS = ${inherited} ${LIBSTUFF_C_FLAGS_LTO} ${LIBSTUFF_C_FLAGS_VERS} ${CCTOOLS_C_FLAGS_CODEDIR} 32 | -------------------------------------------------------------------------------- /xcode/macho_headers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Install extra content along with the libmacho headers. 4 | # 5 | # This used to include the architecture-specific mach-o headers. Currently, 6 | # it is only used to install the mach-o module. 7 | 8 | install_files() { 9 | src_dir=$1; shift 10 | dst_dir=$1; shift 11 | files=$* 12 | 13 | ( 14 | cd ${src_dir} 15 | mkdir -p ${dst_dir} 16 | install -c -m 444 ${files} ${dst_dir} 17 | ) 18 | } 19 | 20 | # The following logic has been removed as part of the following: 21 | # cctools_ofiles does not install during installhdrs 22 | # This script remains, as we'll need to reenable the module workflow that 23 | # follows below. 24 | # 25 | # src=${SRCROOT}/include/mach-o 26 | # dst=${DSTROOT}/usr/include/mach-o 27 | # 28 | # install_files ${src} ${dst} ldsyms.h nlist.h 29 | # install_files ${src}/arm ${dst}/arm reloc.h 30 | # install_files ${src}/arm64 ${dst}/arm64 reloc.h 31 | # install_files ${src}/i386 ${dst}/i386 swap.h 32 | # install_files ${src}/x86_64 ${dst}/x86_64 reloc.h 33 | # 34 | # dst=${DSTROOT}/usr/local/include/mach-o 35 | # 36 | # install_files ${src}/hppa ${dst}/hppa reloc.h swap.h 37 | # install_files ${src}/i860 ${dst}/i860 reloc.h swap.h 38 | # install_files ${src}/m68k ${dst}/m68k swap.h 39 | # install_files ${src}/m88k ${dst}/m88k reloc.h swap.h 40 | # install_files ${src}/sparc ${dst}/sparc reloc.h swap.h 41 | # install_files ${src}/ppc ${dst}/ppc reloc.h swap.h 42 | # 43 | # src=${SRCROOT}/include/stuff 44 | # dst=${DSTROOT}/usr/local/include/dyld 45 | # 46 | # install_files ${src} ${dst} bool.h 47 | -------------------------------------------------------------------------------- /xcode/macho_static.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // macho_dynamic.xcconfig 3 | // cctools 4 | // 5 | // Created by Michael Trent on 12/21/18. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | // libmacho static archives are installed in /usr/local/lib/system 12 | INSTALL_PATH = /usr/local/lib/system 13 | 14 | // XCODE defaults to not installing .a files 15 | SKIP_INSTALL=NO 16 | 17 | // differenciate between libmacho.dylib and libmacho.a 18 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) STATIC_LIBMACHO=1 19 | -------------------------------------------------------------------------------- /xcode/otool.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // otool.xcconfig 3 | // cctools 4 | // 5 | // Created by Michael Trent on 1/17/19. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | #include "public_tool.xcconfig" 12 | 13 | OTHER_CFLAGS = ${inherited} -DOTOOL 14 | -------------------------------------------------------------------------------- /xcode/private_efi.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // private_efi.xcconfig 3 | // cctools 4 | // 5 | // Created by Michael Trent on 12/21/18. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | // EFI utilities install in /usr/local/efi/bin 12 | INSTALL_PATH = ${CCTOOLS_EFI}/bin 13 | -------------------------------------------------------------------------------- /xcode/private_test.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // private_test.xcconfig 3 | // cctools 4 | // 5 | // Created by Michael Trent on 1/19/19. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | // private test utilities install in /usr/local/bin/cctools, where the are 12 | // don't appear in anyone's toolchain. 13 | INSTALL_PATH = ${CCTOOLS_USRLOCALBIN}/cctools 14 | 15 | // some tools currently require the LTO_SUPPORT macro to be defined in order to 16 | // compile support for LTO. This is built non-conditionally, and can probably 17 | // be factored out of the source code at some future point. 18 | CCTOOLS_C_FLAGS_LTO = -DLTO_SUPPORT 19 | 20 | // MacOS and Xcode default toolchain binaries are built with support for 21 | // re-signing binaries via libcodedirectory. 22 | // Don't use -lcodedirectory because that may find the one in the OS 23 | CCTOOLS_C_FLAGS_CODEDIR_YES = -DCODEDIRECTORY_SUPPORT -I"${TOOLCHAIN_DIR}/usr/include" 24 | CCTOOLS_C_FLAGS_CODEDIR = ${CCTOOLS_C_FLAGS_CODEDIR_${CCTB_MACOS}${CCTB_XCODE}} 25 | CCTOOLS_LDFLAGS_CODEDIR_YES = ${TOOLCHAIN_DIR}/usr/lib/libcodedirectory.dylib -rpath @executable_path/../../../lib 26 | CCTOOLS_LDFLAGS_CODEDIR = ${CCTOOLS_LDFLAGS_CODEDIR_${CCTB_MACOS}${CCTB_XCODE}} 27 | 28 | OTHER_CFLAGS = ${inherited} ${CCTOOLS_C_FLAGS_LTO} ${CCTOOLS_C_FLAGS_CODEDIR} 29 | OTHER_LDFLAGS = ${inherited} ${CCTOOLS_LDFLAGS_CODEDIR} 30 | -------------------------------------------------------------------------------- /xcode/private_tool.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // private_tool.xcconfig 3 | // cctools 4 | // 5 | // Created by Michael Trent on 12/21/18. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | // private utilities install in /usr/local/bin 12 | INSTALL_PATH = ${CCTOOLS_USRLOCALBIN} 13 | 14 | // some tools currently require the LTO_SUPPORT macro to be defined in order to 15 | // compile support for LTO. This is built non-conditionally, and can probably 16 | // be factored out of the source code at some future point. 17 | CCTOOLS_C_FLAGS_LTO = -DLTO_SUPPORT 18 | 19 | OTHER_CFLAGS = ${inherited} ${CCTOOLS_C_FLAGS_LTO} 20 | 21 | // MacOS and Xcode default toolchain binaries are built with support for 22 | // re-signing binaries via libcodedirectory. 23 | CCTOOLS_LDFLAGS_CODEDIR_YES = ${TOOLCHAIN_DIR}/usr/lib/libcodedirectory.dylib -rpath @executable_path/../../lib 24 | CCTOOLS_LDFLAGS_CODEDIR = ${CCTOOLS_LDFLAGS_CODEDIR_${CCTB_MACOS}${CCTB_XCODE}} 25 | OTHER_LDFLAGS = ${inherited} ${CCTOOLS_LDFLAGS_CODEDIR} 26 | -------------------------------------------------------------------------------- /xcode/public_tool.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // public_tool.xconfig.xcconfig 3 | // cctools 4 | // 5 | // Created by Michael Trent on 12/20/18. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | // some tools currently require the LTO_SUPPORT macro to be defined in order to 12 | // compile support for LTO. This is built non-conditionally, and can probably 13 | // be factored out of the source code at some future point. 14 | CCTOOLS_C_FLAGS_LTO = -DLTO_SUPPORT 15 | 16 | // MacOS and Xcode default toolchain binaries are built with support for 17 | // re-signinging binaries via libcodedirectory. 18 | CCTOOLS_C_FLAGS_CODEDIR_YES = -DCODEDIRECTORY_SUPPORT -I"${TOOLCHAIN_DIR}/usr/include" 19 | CCTOOLS_C_FLAGS_CODEDIR = ${CCTOOLS_C_FLAGS_CODEDIR_${CCTB_MACOS}${CCTB_XCODE}} 20 | 21 | CCTOOLS_LDFLAGS_CODEDIR_YES = ${TOOLCHAIN_DIR}/usr/lib/libcodedirectory.dylib -rpath @executable_path/../lib 22 | CCTOOLS_LDFLAGS_CODEDIR = ${CCTOOLS_LDFLAGS_CODEDIR_${CCTB_MACOS}${CCTB_XCODE}} 23 | 24 | OTHER_CFLAGS = ${inherited} ${CCTOOLS_C_FLAGS_LTO} 25 | OTHER_LDFLAGS = ${inherited} 26 | 27 | // public utilities install in /usr/bin 28 | INSTALL_PATH = ${CCTOOLS_USRBIN} 29 | -------------------------------------------------------------------------------- /xcode/strip.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // strip.xcconfig 3 | // cctools 4 | // 5 | // Created by Michael Trent on 12/21/18. 6 | // 7 | 8 | // Configuration settings file format documentation can be found at: 9 | // https://help.apple.com/xcode/#/dev745c5c974 10 | 11 | #include "public_tool.xcconfig" 12 | 13 | // when compiling in RC_MACOS and RC_DEVTOOLS build trains, strip builds with 14 | // TRIE_SUPPORT enabled. This involves three settings: 15 | // 16 | // Adding the local tool chain to HEADER_SEARCH_PATHS in order to include 17 | // "mach-o/prune_trie.h" 18 | // 19 | // Adding -DTRIE_SUPPORT when to OTHER_CLFAGS 20 | // 21 | // Adding c++ and the prune_trie library to OTHER_LDFLAGS 22 | // 23 | // Because Xcode doesn't directly support conditionalizing build settings 24 | // against environment variables, this needs to be done in a round-about way 25 | // using nested variable expansion. 26 | STRIP_HEADER_SEARCH_PATHS = ${TOOLCHAIN_DIR}/usr/local/include 27 | STRIP_OTHER_CFLAGS = -DTRIE_SUPPORT ${CCTOOLS_C_FLAGS_CODEDIR} 28 | STRIP_OTHER_LDFLAGS = -lc++ -stdlib=libc++ -L${TOOLCHAIN_DIR}/usr/local/lib -lcctoolshelper ${CCTOOLS_LDFLAGS_CODEDIR} 29 | 30 | STRIP_HEADER_SEARCH_PATHS_MACOS_XOR_XCODE_YES = ${STRIP_HEADER_SEARCH_PATHS} 31 | STRIP_OTHER_CFLAGS_MACOS_XOR_XCODE_YES = ${STRIP_OTHER_CFLAGS} 32 | STRIP_OTHER_LDFLAGS_MACOS_XOR_XCODE_YES = ${STRIP_OTHER_LDFLAGS} 33 | 34 | HEADER_SEARCH_PATHS = ${inherited} ${STRIP_HEADER_SEARCH_PATHS_MACOS_XOR_XCODE_${CCTB_MACOS}${CCTB_XCODE}} 35 | OTHER_CFLAGS = ${inherited} ${CCTOOLS_C_FLAGS_LTO} ${STRIP_OTHER_CFLAGS_MACOS_XOR_XCODE_${CCTB_MACOS}${CCTB_XCODE}} 36 | OTHER_LDFLAGS = ${inherited} ${STRIP_OTHER_LDFLAGS_MACOS_XOR_XCODE_${CCTB_MACOS}${CCTB_XCODE}} 37 | 38 | DEAD_CODE_STRIPPING = YES 39 | 40 | --------------------------------------------------------------------------------