[llvm-lipo] Implement -replace
Replaces specified architecture in universal binary input file with
slice from the file_name argument passed into the replace command.
Differential Revision: https://reviews.llvm.org/D65247
llvm-svn: 367248
diff --git a/llvm/test/tools/llvm-lipo/Inputs/armv7-slice-big.yaml b/llvm/test/tools/llvm-lipo/Inputs/armv7-slice-big.yaml
new file mode 100644
index 0000000..9c32895
--- /dev/null
+++ b/llvm/test/tools/llvm-lipo/Inputs/armv7-slice-big.yaml
@@ -0,0 +1,934 @@
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACE
+ cputype: 0x0000000C
+ cpusubtype: 0x00000009
+ filetype: 0x00000002
+ ncmds: 27
+ sizeofcmds: 2176
+ flags: 0x00200085
+LoadCommands:
+ - cmd: LC_SEGMENT
+ cmdsize: 56
+ segname: __PAGEZERO
+ vmaddr: 0
+ vmsize: 16384
+ fileoff: 0
+ filesize: 0
+ maxprot: 0
+ initprot: 0
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT
+ cmdsize: 260
+ segname: __TEXT
+ vmaddr: 16384
+ vmsize: 32768
+ fileoff: 0
+ filesize: 32768
+ maxprot: 5
+ initprot: 5
+ nsects: 3
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x000000000000BBA0
+ size: 804
+ offset: 0x00007BA0
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __picsymbolstub4
+ segname: __TEXT
+ addr: 0x000000000000BEC4
+ size: 160
+ offset: 0x00007EC4
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000408
+ reserved1: 0x00000000
+ reserved2: 0x00000010
+ reserved3: 0x00000000
+ - sectname: __stub_helper
+ segname: __TEXT
+ addr: 0x000000000000BF64
+ size: 156
+ offset: 0x00007F64
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_SEGMENT
+ cmdsize: 600
+ segname: __DATA
+ vmaddr: 49152
+ vmsize: 16384
+ fileoff: 32768
+ filesize: 16384
+ maxprot: 3
+ initprot: 3
+ nsects: 8
+ flags: 0
+ Sections:
+ - sectname: __nl_symbol_ptr
+ segname: __DATA
+ addr: 0x000000000000C000
+ size: 12
+ offset: 0x00008000
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000006
+ reserved1: 0x0000000A
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __la_symbol_ptr
+ segname: __DATA
+ addr: 0x000000000000C00C
+ size: 40
+ offset: 0x0000800C
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000007
+ reserved1: 0x0000000D
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __mod_init_func
+ segname: __DATA
+ addr: 0x000000000000C034
+ size: 4
+ offset: 0x00008034
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000009
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __const
+ segname: __DATA
+ addr: 0x000000000000C038
+ size: 36
+ offset: 0x00008038
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __cfstring
+ segname: __DATA
+ addr: 0x000000000000C05C
+ size: 160
+ offset: 0x0000805C
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __objc_imageinfo
+ segname: __DATA
+ addr: 0x000000000000C0FC
+ size: 8
+ offset: 0x000080FC
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __objc_selrefs
+ segname: __DATA
+ addr: 0x000000000000C104
+ size: 44
+ offset: 0x00008104
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x10000005
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __objc_classrefs
+ segname: __DATA
+ addr: 0x000000000000C130
+ size: 20
+ offset: 0x00008130
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x10000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_SEGMENT
+ cmdsize: 192
+ segname: __RODATA
+ vmaddr: 65536
+ vmsize: 16384
+ fileoff: 49152
+ filesize: 16384
+ maxprot: 1
+ initprot: 1
+ nsects: 2
+ flags: 0
+ Sections:
+ - sectname: __cstring
+ segname: __RODATA
+ addr: 0x0000000000010000
+ size: 191
+ offset: 0x0000C000
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000002
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __objc_methname
+ segname: __RODATA
+ addr: 0x00000000000100BF
+ size: 243
+ offset: 0x0000C0BF
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000002
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_SEGMENT
+ cmdsize: 56
+ segname: __LINKEDIT
+ vmaddr: 81920
+ vmsize: 32768
+ fileoff: 65536
+ filesize: 22592
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_DYLD_INFO_ONLY
+ cmdsize: 48
+ rebase_off: 65536
+ rebase_size: 16
+ bind_off: 65552
+ bind_size: 316
+ weak_bind_off: 0
+ weak_bind_size: 0
+ lazy_bind_off: 65868
+ lazy_bind_size: 260
+ export_off: 66128
+ export_size: 60
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 66220
+ nsyms: 29
+ stroff: 66660
+ strsize: 708
+ - cmd: LC_DYSYMTAB
+ cmdsize: 80
+ ilocalsym: 0
+ nlocalsym: 7
+ iextdefsym: 7
+ nextdefsym: 3
+ iundefsym: 10
+ nundefsym: 19
+ tocoff: 0
+ ntoc: 0
+ modtaboff: 0
+ nmodtab: 0
+ extrefsymoff: 0
+ nextrefsyms: 0
+ indirectsymoff: 66568
+ nindirectsyms: 23
+ extreloff: 0
+ nextrel: 0
+ locreloff: 0
+ nlocrel: 0
+ - cmd: LC_LOAD_DYLINKER
+ cmdsize: 28
+ name: 12
+ PayloadString: '/usr/lib/dyld'
+ ZeroPadBytes: 3
+ - cmd: LC_UUID
+ cmdsize: 24
+ uuid: D36E4B66-CF78-37EC-B274-9DDADEECE4C1
+ - cmd: LC_VERSION_MIN_IPHONEOS
+ cmdsize: 16
+ version: 589824
+ sdk: 786944
+ - cmd: LC_SOURCE_VERSION
+ cmdsize: 16
+ version: 0
+ - cmd: LC_MAIN
+ cmdsize: 24
+ entryoff: 31913
+ stacksize: 0
+ - cmd: LC_ENCRYPTION_INFO
+ cmdsize: 20
+ cryptoff: 16384
+ cryptsize: 16384
+ cryptid: 0
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 48
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 26216708
+ compatibility_version: 65536
+ PayloadString: '/usr/lib/libc++.1.dylib'
+ ZeroPadBytes: 1
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 68
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 0
+ compatibility_version: 0
+ PayloadString: '@rpath/MobileConfig.framework/MobileConfig'
+ ZeroPadBytes: 2
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 84
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 102895360
+ compatibility_version: 19660800
+ PayloadString: '/System/Library/Frameworks/Foundation.framework/Foundation'
+ ZeroPadBytes: 2
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 76
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 917504
+ compatibility_version: 65536
+ PayloadString: '/System/Library/Frameworks/MapKit.framework/MapKit'
+ ZeroPadBytes: 2
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 84
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 68352
+ compatibility_version: 66048
+ PayloadString: '/System/Library/Frameworks/QuartzCore.framework/QuartzCore'
+ ZeroPadBytes: 2
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 76
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 3997696000
+ compatibility_version: 65536
+ PayloadString: '/System/Library/Frameworks/UIKit.framework/UIKit'
+ ZeroPadBytes: 4
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 52
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 14942208
+ compatibility_version: 65536
+ PayloadString: '/usr/lib/libobjc.A.dylib'
+ ZeroPadBytes: 4
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 52
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 82115073
+ compatibility_version: 65536
+ PayloadString: '/usr/lib/libSystem.B.dylib'
+ ZeroPadBytes: 2
+ - cmd: LC_LOAD_DYLIB
+ cmdsize: 92
+ dylib:
+ name: 24
+ timestamp: 2
+ current_version: 102895360
+ compatibility_version: 9830400
+ PayloadString: '/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation'
+ ZeroPadBytes: 2
+ - cmd: LC_RPATH
+ cmdsize: 28
+ path: 12
+ PayloadString: '/usr/lib/swift'
+ ZeroPadBytes: 2
+ - cmd: LC_RPATH
+ cmdsize: 40
+ path: 12
+ PayloadString: '@executable_path/Frameworks'
+ ZeroPadBytes: 1
+ - cmd: LC_DATA_IN_CODE
+ cmdsize: 16
+ dataoff: 66188
+ datasize: 32
+ - cmd: LC_CODE_SIGNATURE
+ cmdsize: 16
+ dataoff: 67376
+ datasize: 20752
+LinkEditData:
+ RebaseOpcodes:
+ - Opcode: REBASE_OPCODE_SET_TYPE_IMM
+ Imm: 1
+ - Opcode: REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ExtraData:
+ - 0x000000000000000C
+ - Opcode: REBASE_OPCODE_DO_REBASE_IMM_TIMES
+ Imm: 11
+ - Opcode: REBASE_OPCODE_ADD_ADDR_IMM_SCALED
+ Imm: 2
+ - Opcode: REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB
+ Imm: 0
+ ExtraData:
+ - 0x0000000000000010
+ - Opcode: REBASE_OPCODE_DO_REBASE_IMM_TIMES
+ Imm: 2
+ - Opcode: REBASE_OPCODE_ADD_ADDR_IMM_SCALED
+ Imm: 2
+ - Opcode: REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB
+ Imm: 0
+ ExtraData:
+ - 0x000000000000000A
+ - 0x000000000000000C
+ - Opcode: REBASE_OPCODE_DO_REBASE_IMM_TIMES
+ Imm: 11
+ - Opcode: REBASE_OPCODE_DONE
+ Imm: 0
+ BindOpcodes:
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 3
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: '_OBJC_CLASS_$_NSBundle'
+ - Opcode: BIND_OPCODE_SET_TYPE_IMM
+ Imm: 1
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x0000000000000140
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: '_OBJC_CLASS_$_NSJSONSerialization'
+ - Opcode: BIND_OPCODE_ADD_ADDR_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0xFFFFFFFFFFFFFFF0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 7
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _objc_release
+ - Opcode: BIND_OPCODE_ADD_ADDR_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0xFFFFFFFFFFFFFED0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 8
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: __NSConcreteGlobalBlock
+ - Opcode: BIND_OPCODE_ADD_ADDR_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0x000000000000003C
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: dyld_stub_binder
+ - Opcode: BIND_OPCODE_ADD_ADDR_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0xFFFFFFFFFFFFFFB4
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 9
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: '_OBJC_CLASS_$_NSData'
+ - Opcode: BIND_OPCODE_ADD_ADDR_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0x000000000000012C
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: '_OBJC_CLASS_$_NSMutableArray'
+ - Opcode: BIND_OPCODE_ADD_ADDR_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0x0000000000000008
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: '_OBJC_CLASS_$_NSUserDefaults'
+ - Opcode: BIND_OPCODE_ADD_ADDR_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0xFFFFFFFFFFFFFFF8
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: ___CFConstantStringClassReference
+ - Opcode: BIND_OPCODE_ADD_ADDR_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0xFFFFFFFFFFFFFF20
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
+ Imm: 0
+ ULEBExtraData:
+ - 0x0000000000000009
+ - 0x000000000000000C
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ LazyBindOpcodes:
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x000000000000000C
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 3
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _NSClassFromString
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x0000000000000010
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 6
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _UIApplicationMain
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x0000000000000014
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 7
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _objc_autoreleasePoolPop
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x0000000000000018
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 7
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _objc_autoreleasePoolPush
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x000000000000001C
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 7
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _objc_autoreleaseReturnValue
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x0000000000000020
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 7
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _objc_msgSend
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x0000000000000024
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 7
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _objc_release
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x0000000000000028
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 7
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _objc_retainAutoreleasedReturnValue
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x000000000000002C
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 8
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _strcmp
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
+ Imm: 2
+ ULEBExtraData:
+ - 0x0000000000000030
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
+ Imm: 8
+ Symbol: ''
+ - Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
+ Imm: 0
+ Symbol: _strlen
+ - Opcode: BIND_OPCODE_DO_BIND
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ - Opcode: BIND_OPCODE_DONE
+ Imm: 0
+ Symbol: ''
+ ExportTrie:
+ TerminalSize: 0
+ NodeOffset: 0
+ Name: ''
+ Flags: 0x0000000000000000
+ Address: 0x0000000000000000
+ Other: 0x0000000000000000
+ ImportName: ''
+ Children:
+ - TerminalSize: 0
+ NodeOffset: 5
+ Name: _
+ Flags: 0x0000000000000000
+ Address: 0x0000000000000000
+ Other: 0x0000000000000000
+ ImportName: ''
+ Children:
+ - TerminalSize: 2
+ NodeOffset: 41
+ Name: _mh_execute_header
+ Flags: 0x0000000000000000
+ Address: 0x0000000000000000
+ Other: 0x0000000000000000
+ ImportName: ''
+ - TerminalSize: 4
+ NodeOffset: 45
+ Name: main
+ Flags: 0x0000000000000000
+ Address: 0x0000000000007CA9
+ Other: 0x0000000000000000
+ ImportName: ''
+ - TerminalSize: 4
+ NodeOffset: 51
+ Name: MNMain
+ Flags: 0x0000000000000000
+ Address: 0x0000000000007E45
+ Other: 0x0000000000000000
+ ImportName: ''
+ NameList:
+ - n_strx: 461
+ n_type: 0x0E
+ n_sect: 1
+ n_desc: 8
+ n_value: 48032
+ - n_strx: 487
+ n_type: 0x0E
+ n_sect: 1
+ n_desc: 8
+ n_value: 48776
+ - n_strx: 540
+ n_type: 0x1E
+ n_sect: 1
+ n_desc: 8
+ n_value: 48812
+ - n_strx: 559
+ n_type: 0x1E
+ n_sect: 1
+ n_desc: 8
+ n_value: 48824
+ - n_strx: 593
+ n_type: 0x1E
+ n_sect: 3
+ n_desc: 0
+ n_value: 48996
+ - n_strx: 607
+ n_type: 0x0E
+ n_sect: 7
+ n_desc: 0
+ n_value: 49208
+ - n_strx: 656
+ n_type: 0x0E
+ n_sect: 7
+ n_desc: 0
+ n_value: 49224
+ - n_strx: 4
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 8
+ n_value: 48708
+ - n_strx: 12
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 16
+ n_value: 16384
+ - n_strx: 32
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 8
+ n_value: 48296
+ - n_strx: 38
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 768
+ n_value: 0
+ - n_strx: 57
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 768
+ n_value: 0
+ - n_strx: 80
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2304
+ n_value: 0
+ - n_strx: 101
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 768
+ n_value: 0
+ - n_strx: 135
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2304
+ n_value: 0
+ - n_strx: 164
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2304
+ n_value: 0
+ - n_strx: 193
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 1536
+ n_value: 0
+ - n_strx: 212
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2048
+ n_value: 0
+ - n_strx: 236
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2304
+ n_value: 0
+ - n_strx: 270
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2048
+ n_value: 0
+ - n_strx: 284
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 1792
+ n_value: 0
+ - n_strx: 309
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 1792
+ n_value: 0
+ - n_strx: 335
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 1792
+ n_value: 0
+ - n_strx: 364
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 1792
+ n_value: 0
+ - n_strx: 378
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 1792
+ n_value: 0
+ - n_strx: 392
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 1792
+ n_value: 0
+ - n_strx: 428
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2048
+ n_value: 0
+ - n_strx: 436
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2048
+ n_value: 0
+ - n_strx: 444
+ n_type: 0x01
+ n_sect: 0
+ n_desc: 2048
+ n_value: 0
+ StringTable:
+ - ''
+ - ''
+ - ''
+ - ''
+ - _MNMain
+ - __mh_execute_header
+ - _main
+ - _NSClassFromString
+ - '_OBJC_CLASS_$_NSBundle'
+ - '_OBJC_CLASS_$_NSData'
+ - '_OBJC_CLASS_$_NSJSONSerialization'
+ - '_OBJC_CLASS_$_NSMutableArray'
+ - '_OBJC_CLASS_$_NSUserDefaults'
+ - _UIApplicationMain
+ - __NSConcreteGlobalBlock
+ - ___CFConstantStringClassReference
+ - ___truncdfhf2
+ - _objc_autoreleasePoolPop
+ - _objc_autoreleasePoolPush
+ - _objc_autoreleaseReturnValue
+ - _objc_msgSend
+ - _objc_release
+ - _objc_retainAutoreleasedReturnValue
+ - _strcmp
+ - _strlen
+ - dyld_stub_binder
+ - _FBParseCommandLineParams
+ - ___MNMain_block_invoke_7636.llvm.6232502296855065941
+ - '_objc_release$shim'
+ - '_objc_autoreleaseReturnValue$shim'
+ - ' stub helpers'
+ - ___block_descriptor_tmp.llvm.6232502296855065941
+ - ___block_literal_global.llvm.6232502296855065941
+ - ''
+ - ''
+ - ''
+...
diff --git a/llvm/test/tools/llvm-lipo/Inputs/armv7_i386_non_default_alignment.yaml b/llvm/test/tools/llvm-lipo/Inputs/armv7_i386_non_default_alignment.yaml
new file mode 100644
index 0000000..2005b56
--- /dev/null
+++ b/llvm/test/tools/llvm-lipo/Inputs/armv7_i386_non_default_alignment.yaml
@@ -0,0 +1,191 @@
+--- !fat-mach-o
+FatHeader:
+ magic: 0xCAFEBABE
+ nfat_arch: 2
+FatArchs:
+ - cputype: 0x0000000C
+ cpusubtype: 0x00000009
+ offset: 0x0000000000000030
+ size: 432
+ align: 4
+ - cputype: 0x00000007
+ cpusubtype: 0x00000003
+ offset: 0x0000000000001000
+ size: 432
+ align: 12
+Slices:
+ - !mach-o
+ FileHeader:
+ magic: 0xFEEDFACE
+ cputype: 0x0000000C
+ cpusubtype: 0x00000009
+ filetype: 0x00000001
+ ncmds: 4
+ sizeofcmds: 312
+ flags: 0x00002000
+ LoadCommands:
+ - cmd: LC_SEGMENT
+ cmdsize: 192
+ segname: ''
+ vmaddr: 0
+ vmsize: 72
+ fileoff: 340
+ filesize: 72
+ maxprot: 7
+ initprot: 7
+ nsects: 2
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ size: 18
+ offset: 0x00000154
+ align: 4
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __eh_frame
+ segname: __TEXT
+ addr: 0x0000000000000014
+ size: 52
+ offset: 0x00000168
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x6800000B
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_VERSION_MIN_MACOSX
+ cmdsize: 16
+ version: 656384
+ sdk: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 412
+ nsyms: 1
+ stroff: 424
+ strsize: 8
+ - cmd: LC_DYSYMTAB
+ cmdsize: 80
+ ilocalsym: 0
+ nlocalsym: 0
+ iextdefsym: 0
+ nextdefsym: 1
+ iundefsym: 1
+ nundefsym: 0
+ tocoff: 0
+ ntoc: 0
+ modtaboff: 0
+ nmodtab: 0
+ extrefsymoff: 0
+ nextrefsyms: 0
+ indirectsymoff: 0
+ nindirectsyms: 0
+ extreloff: 0
+ nextrel: 0
+ locreloff: 0
+ nlocrel: 0
+ LinkEditData:
+ NameList:
+ - n_strx: 1
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ StringTable:
+ - ''
+ - _main
+ - ''
+ - !mach-o
+ FileHeader:
+ magic: 0xFEEDFACE
+ cputype: 0x00000007
+ cpusubtype: 0x00000003
+ filetype: 0x00000001
+ ncmds: 4
+ sizeofcmds: 312
+ flags: 0x00002000
+ LoadCommands:
+ - cmd: LC_SEGMENT
+ cmdsize: 192
+ segname: ''
+ vmaddr: 0
+ vmsize: 72
+ fileoff: 340
+ filesize: 72
+ maxprot: 7
+ initprot: 7
+ nsects: 2
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ size: 18
+ offset: 0x00000154
+ align: 4
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __eh_frame
+ segname: __TEXT
+ addr: 0x0000000000000014
+ size: 52
+ offset: 0x00000168
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x6800000B
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_VERSION_MIN_MACOSX
+ cmdsize: 16
+ version: 656384
+ sdk: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 412
+ nsyms: 1
+ stroff: 424
+ strsize: 8
+ - cmd: LC_DYSYMTAB
+ cmdsize: 80
+ ilocalsym: 0
+ nlocalsym: 0
+ iextdefsym: 0
+ nextdefsym: 1
+ iundefsym: 1
+ nundefsym: 0
+ tocoff: 0
+ ntoc: 0
+ modtaboff: 0
+ nmodtab: 0
+ extrefsymoff: 0
+ nextrefsyms: 0
+ indirectsymoff: 0
+ nindirectsyms: 0
+ extreloff: 0
+ nextrel: 0
+ locreloff: 0
+ nlocrel: 0
+ LinkEditData:
+ NameList:
+ - n_strx: 1
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ StringTable:
+ - ''
+ - _main
+ - ''
+...
diff --git a/llvm/test/tools/llvm-lipo/Inputs/i386-x86_64-armv7-arm64-universal.yaml b/llvm/test/tools/llvm-lipo/Inputs/i386-x86_64-armv7-arm64-universal.yaml
new file mode 100644
index 0000000..f0070b5
--- /dev/null
+++ b/llvm/test/tools/llvm-lipo/Inputs/i386-x86_64-armv7-arm64-universal.yaml
@@ -0,0 +1,377 @@
+--- !fat-mach-o
+FatHeader:
+ magic: 0xCAFEBABE
+ nfat_arch: 4
+FatArchs:
+ - cputype: 0x00000007
+ cpusubtype: 0x00000003
+ offset: 0x0000000000001000
+ size: 432
+ align: 12
+ - cputype: 0x01000007
+ cpusubtype: 0x00000003
+ offset: 0x0000000000002000
+ size: 488
+ align: 12
+ - cputype: 0x0000000C
+ cpusubtype: 0x00000009
+ offset: 0x0000000000004000
+ size: 304
+ align: 14
+ - cputype: 0x0100000C
+ cpusubtype: 0x00000000
+ offset: 0x0000000000008000
+ size: 516
+ align: 14
+Slices:
+ - !mach-o
+ FileHeader:
+ magic: 0xFEEDFACE
+ cputype: 0x00000007
+ cpusubtype: 0x00000003
+ filetype: 0x00000001
+ ncmds: 4
+ sizeofcmds: 312
+ flags: 0x00002000
+ LoadCommands:
+ - cmd: LC_SEGMENT
+ cmdsize: 192
+ segname: ''
+ vmaddr: 0
+ vmsize: 72
+ fileoff: 340
+ filesize: 72
+ maxprot: 7
+ initprot: 7
+ nsects: 2
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ size: 18
+ offset: 0x00000154
+ align: 4
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __eh_frame
+ segname: __TEXT
+ addr: 0x0000000000000014
+ size: 52
+ offset: 0x00000168
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x6800000B
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_VERSION_MIN_MACOSX
+ cmdsize: 16
+ version: 656384
+ sdk: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 412
+ nsyms: 1
+ stroff: 424
+ strsize: 8
+ - cmd: LC_DYSYMTAB
+ cmdsize: 80
+ ilocalsym: 0
+ nlocalsym: 0
+ iextdefsym: 0
+ nextdefsym: 1
+ iundefsym: 1
+ nundefsym: 0
+ tocoff: 0
+ ntoc: 0
+ modtaboff: 0
+ nmodtab: 0
+ extrefsymoff: 0
+ nextrefsyms: 0
+ indirectsymoff: 0
+ nindirectsyms: 0
+ extreloff: 0
+ nextrel: 0
+ locreloff: 0
+ nlocrel: 0
+ LinkEditData:
+ NameList:
+ - n_strx: 1
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ StringTable:
+ - ''
+ - _main
+ - ''
+ - !mach-o
+ FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x00000003
+ filetype: 0x00000001
+ ncmds: 4
+ sizeofcmds: 352
+ flags: 0x00002000
+ reserved: 0x00000000
+ LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 232
+ segname: ''
+ vmaddr: 0
+ vmsize: 80
+ fileoff: 384
+ filesize: 80
+ maxprot: 7
+ initprot: 7
+ nsects: 2
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ size: 15
+ offset: 0x00000180
+ align: 4
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __eh_frame
+ segname: __TEXT
+ addr: 0x0000000000000010
+ size: 64
+ offset: 0x00000190
+ align: 3
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x6800000B
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_VERSION_MIN_MACOSX
+ cmdsize: 16
+ version: 656384
+ sdk: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 464
+ nsyms: 1
+ stroff: 480
+ strsize: 8
+ - cmd: LC_DYSYMTAB
+ cmdsize: 80
+ ilocalsym: 0
+ nlocalsym: 0
+ iextdefsym: 0
+ nextdefsym: 1
+ iundefsym: 1
+ nundefsym: 0
+ tocoff: 0
+ ntoc: 0
+ modtaboff: 0
+ nmodtab: 0
+ extrefsymoff: 0
+ nextrefsyms: 0
+ indirectsymoff: 0
+ nindirectsyms: 0
+ extreloff: 0
+ nextrel: 0
+ locreloff: 0
+ nlocrel: 0
+ LinkEditData:
+ NameList:
+ - n_strx: 1
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ StringTable:
+ - ''
+ - _main
+ - ''
+ - !mach-o
+ FileHeader:
+ magic: 0xFEEDFACE
+ cputype: 0x0000000C
+ cpusubtype: 0x00000009
+ filetype: 0x00000001
+ ncmds: 4
+ sizeofcmds: 244
+ flags: 0x00002000
+ LoadCommands:
+ - cmd: LC_SEGMENT
+ cmdsize: 124
+ segname: ''
+ vmaddr: 0
+ vmsize: 10
+ fileoff: 272
+ filesize: 10
+ maxprot: 7
+ initprot: 7
+ nsects: 1
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ size: 10
+ offset: 0x00000110
+ align: 1
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_VERSION_MIN_IPHONEOS
+ cmdsize: 16
+ version: 327680
+ sdk: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 284
+ nsyms: 1
+ stroff: 296
+ strsize: 8
+ - cmd: LC_DYSYMTAB
+ cmdsize: 80
+ ilocalsym: 0
+ nlocalsym: 0
+ iextdefsym: 0
+ nextdefsym: 1
+ iundefsym: 1
+ nundefsym: 0
+ tocoff: 0
+ ntoc: 0
+ modtaboff: 0
+ nmodtab: 0
+ extrefsymoff: 0
+ nextrefsyms: 0
+ indirectsymoff: 0
+ nindirectsyms: 0
+ extreloff: 0
+ nextrel: 0
+ locreloff: 0
+ nlocrel: 0
+ LinkEditData:
+ NameList:
+ - n_strx: 1
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 8
+ n_value: 0
+ StringTable:
+ - ''
+ - _main
+ - ''
+ - !mach-o
+ FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x0100000C
+ cpusubtype: 0x00000000
+ filetype: 0x00000001
+ ncmds: 4
+ sizeofcmds: 352
+ flags: 0x00002000
+ reserved: 0x00000000
+ LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 232
+ segname: ''
+ vmaddr: 0
+ vmsize: 56
+ fileoff: 384
+ filesize: 56
+ maxprot: 7
+ initprot: 7
+ nsects: 2
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ size: 20
+ offset: 0x00000180
+ align: 2
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - sectname: __compact_unwind
+ segname: __LD
+ addr: 0x0000000000000018
+ size: 32
+ offset: 0x00000198
+ align: 3
+ reloff: 0x000001B8
+ nreloc: 1
+ flags: 0x02000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ - cmd: LC_VERSION_MIN_IPHONEOS
+ cmdsize: 16
+ version: 327680
+ sdk: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 448
+ nsyms: 3
+ stroff: 496
+ strsize: 20
+ - cmd: LC_DYSYMTAB
+ cmdsize: 80
+ ilocalsym: 0
+ nlocalsym: 2
+ iextdefsym: 2
+ nextdefsym: 1
+ iundefsym: 3
+ nundefsym: 0
+ tocoff: 0
+ ntoc: 0
+ modtaboff: 0
+ nmodtab: 0
+ extrefsymoff: 0
+ nextrefsyms: 0
+ indirectsymoff: 0
+ nindirectsyms: 0
+ extreloff: 0
+ nextrel: 0
+ locreloff: 0
+ nlocrel: 0
+ LinkEditData:
+ NameList:
+ - n_strx: 13
+ n_type: 0x0E
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ - n_strx: 7
+ n_type: 0x0E
+ n_sect: 2
+ n_desc: 0
+ n_value: 24
+ - n_strx: 1
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 0
+ n_value: 0
+ StringTable:
+ - ''
+ - _main
+ - ltmp1
+ - ltmp0
+ - ''
+...
diff --git a/llvm/test/tools/llvm-lipo/replace-invalid-input.test b/llvm/test/tools/llvm-lipo/replace-invalid-input.test
new file mode 100644
index 0000000..8c0f7ce
--- /dev/null
+++ b/llvm/test/tools/llvm-lipo/replace-invalid-input.test
@@ -0,0 +1,30 @@
+# RUN: yaml2obj %p/Inputs/i386-slice.yaml > %t-32.o
+# RUN: yaml2obj %p/Inputs/arm64-slice.yaml > %t-arm64.o
+# RUN: yaml2obj %p/Inputs/i386-x86_64-universal.yaml > %t-universal.o
+
+# RUN: not llvm-lipo %t-universal.o -replace %t-32.o 2>&1 | FileCheck --check-prefix=MISSING_ARG %s
+# MISSING_ARG: error: replace is missing an argument: expects -replace arch_type file_name
+
+# RUN: not llvm-lipo %t-universal.o -replace %t-32.o i386 2>&1 | FileCheck --check-prefix=OUTPUT_FILE %s
+# OUTPUT_FILE: error: replace expects a single output file to be specified
+
+# RUN: not llvm-lipo %t-universal.o %t-universal.o -replace %t-32.o i386 -o %t.o 2>&1 | FileCheck --check-prefix=INPUT_ARGS %s
+# INPUT_ARGS: error: replace expects a single input file
+
+# RUN: not llvm-lipo %t-universal.o -replace %t-32.o i386 -o %t.o 2>&1 | FileCheck --check-prefix=INVALID_FILE %s
+# INVALID_FILE: error: 'i386': No such file or directory
+
+# RUN: not llvm-lipo %t-universal.o -replace i3866 %t-32.o -o %t.o 2>&1 | FileCheck --check-prefix=INVALID_ARCH %s
+# INVALID_ARCH: error: Invalid architecture: i3866
+
+# RUN: not llvm-lipo %t-universal.o -replace arm64 %t-32.o -o %t.o 2>&1 | FileCheck --check-prefix=ARCH_NOT_MATCHED %s
+# ARCH_NOT_MATCHED: error: specified architecture: arm64 for replacement file: {{.*}} does not match the file's architecture
+
+# RUN: not llvm-lipo %t-universal.o -replace arm64 %t-arm64.o -o %t.o 2>&1 | FileCheck --check-prefix=ARCH_NOT_IN_INPUT %s
+# ARCH_NOT_IN_INPUT: error: -replace arm64 <file_name> specified but fat file: {{.*}} does not contain that architecture
+
+# RUN: not llvm-lipo %t-universal.o -replace i386 %t-32.o -replace arm64 %t-universal.o -o %t.o 2>&1 | FileCheck --check-prefix=REPLACE_UNIVERSAL %s
+# REPLACE_UNIVERSAL: replacement file: {{.*}} is a fat file (must be a thin file)
+
+# RUN: not llvm-lipo %t-universal.o -replace i386 %t-32.o -replace i386 %t-32.o -o %t.o 2>&1 | FileCheck --check-prefix=ARCH_DUPLICATE %s
+# ARCH_DUPLICATE: error: -replace i386 <file_name> specified multiple times:
diff --git a/llvm/test/tools/llvm-lipo/replace-universal-binary.test b/llvm/test/tools/llvm-lipo/replace-universal-binary.test
new file mode 100644
index 0000000..f9419ef
--- /dev/null
+++ b/llvm/test/tools/llvm-lipo/replace-universal-binary.test
@@ -0,0 +1,35 @@
+# RUN: yaml2obj %p/Inputs/armv7-slice-big.yaml > %t-armv7big.o
+# RUN: yaml2obj %p/Inputs/i386-x86_64-armv7-arm64-universal.yaml > %t-universal.o
+
+# RUN: llvm-lipo %t-universal.o -replace armv7 %t-armv7big.o -o %t.o
+# RUN: llvm-objdump %t.o -m --universal-headers | FileCheck --check-prefix=ARMV7_BIG %s
+# RUN: llvm-lipo %t.o -thin armv7 -o %t-armv7-out.o
+# RUN: cmp %t-armv7big.o %t-armv7-out.o
+# ARMV7_BIG: architecture i386
+# ARMV7_BIG: offset 4096
+# ARMV7_BIG: align 2^12 (4096)
+# ARMV7_BIG-NEXT: architecture x86_64
+# ARMV7_BIG: offset 8192
+# ARMV7_BIG: align 2^12 (4096)
+# ARMV7_BIG-NEXT: architecture armv7
+# ARMV7_BIG: offset 16384
+# ARMV7_BIG: size 88128
+# ARMV7_BIG: align 2^14 (16384)
+# ARMV7_BIG-NEXT: architecture arm64
+# ARMV7_BIG: offset 114688
+# ARMV7_BIG: size 516
+# ARMV7_BIG: align 2^14 (16384)
+
+# RUN: yaml2obj %p/Inputs/armv7-slice.yaml > %t-armv7.o
+# RUN: yaml2obj %p/Inputs/armv7_i386_non_default_alignment.yaml > %t-universal-align.o
+
+# RUN: llvm-lipo %t-universal-align.o -replace armv7 %t-armv7.o -o %t2.o
+# RUN: llvm-objdump %t2.o -m --universal-headers | FileCheck --check-prefix=ARMV7_ALIGN_SWAP %s
+# RUN: llvm-lipo %t2.o -thin armv7 -o %t-armv7-out2.o
+# RUN: cmp %t-armv7.o %t-armv7-out2.o
+# ARMV7_ALIGN_SWAP: architecture i386
+# ARMV7_ALIGN_SWAP: offset 4096
+# ARMV7_ALIGN_SWAP: align 2^12 (4096)
+# ARMV7_ALIGN_SWAP-NEXT: architecture armv7
+# ARMV7_ALIGN_SWAP: offset 16384
+# ARMV7_ALIGN_SWAP: align 2^14 (16384)
diff --git a/llvm/tools/llvm-lipo/LipoOpts.td b/llvm/tools/llvm-lipo/LipoOpts.td
index 44515fe..7e38cb5 100644
--- a/llvm/tools/llvm-lipo/LipoOpts.td
+++ b/llvm/tools/llvm-lipo/LipoOpts.td
@@ -34,6 +34,12 @@
HelpText<"Create a universal binary output file from the input "
"files. Requires -output option">;
+def replace
+ : MultiArg<["-", "--"], "replace", 2>,
+ Group<action_group>,
+ HelpText<"Replace the specified arch type with the contents of the "
+ "input_file in a universal binary. Requires -output option">;
+
def output : Option<["-", "--"], "output", KIND_SEPARATE>,
HelpText<"Create output file with specified name">;
def o : JoinedOrSeparate<["-"], "o">, Alias<output>;
diff --git a/llvm/tools/llvm-lipo/llvm-lipo.cpp b/llvm/tools/llvm-lipo/llvm-lipo.cpp
index 8716767..060fe7c 100644
--- a/llvm/tools/llvm-lipo/llvm-lipo.cpp
+++ b/llvm/tools/llvm-lipo/llvm-lipo.cpp
@@ -82,11 +82,18 @@
VerifyArch,
ThinArch,
CreateUniversal,
+ ReplaceArch,
+};
+
+struct Replacement {
+ StringRef ArchType;
+ StringRef FileName;
};
struct Config {
SmallVector<std::string, 1> InputFiles;
SmallVector<std::string, 1> VerifyArchList;
+ SmallVector<Replacement, 1> Replacements;
std::string ThinArchType;
std::string OutputFile;
LipoAction ActionToPerform;
@@ -158,7 +165,14 @@
SmallVector<opt::Arg *, 1> ActionArgs(InputArgs.filtered(LIPO_action_group));
if (ActionArgs.empty())
reportError("at least one action should be specified");
- if (ActionArgs.size() > 1) {
+ // errors if multiple actions specified other than replace
+ // multiple replace flags may be specified, as long as they are not mixed with
+ // other action flags
+ auto ReplacementArgsRange = InputArgs.filtered(LIPO_replace);
+ if (ActionArgs.size() > 1 &&
+ ActionArgs.size() !=
+ static_cast<size_t>(std::distance(ReplacementArgsRange.begin(),
+ ReplacementArgsRange.end()))) {
std::string Buf;
raw_string_ostream OS(Buf);
OS << "only one of the following actions can be specified:";
@@ -206,6 +220,23 @@
C.ActionToPerform = LipoAction::CreateUniversal;
return C;
+ case LIPO_replace:
+ for (auto Action : ActionArgs) {
+ if (!Action->getValue(1))
+ reportError(
+ "replace is missing an argument: expects -replace arch_type "
+ "file_name");
+ C.Replacements.push_back(
+ Replacement{Action->getValue(0), Action->getValue(1)});
+ }
+
+ if (C.OutputFile.empty())
+ reportError("replace expects a single output file to be specified");
+ if (C.InputFiles.size() > 1)
+ reportError("replace expects a single input file");
+ C.ActionToPerform = LipoAction::ReplaceArch;
+ return C;
+
default:
reportError("llvm-lipo action unspecified");
}
@@ -557,6 +588,81 @@
exit(EXIT_SUCCESS);
}
+static StringMap<Slice>
+buildReplacementSlices(ArrayRef<OwningBinary<Binary>> ReplacementBinaries,
+ ArrayRef<Replacement> Replacements) {
+ assert(ReplacementBinaries.size() == Replacements.size() &&
+ "Number of replacment binaries does not match the number of "
+ "replacements");
+ StringMap<Slice> Slices;
+ // populates StringMap of slices to replace with; error checks for mismatched
+ // replace flag args, fat files, and duplicate arch_types
+ for (size_t Index = 0, Size = Replacements.size(); Index < Size; ++Index) {
+ StringRef ReplacementArch = Replacements[Index].ArchType;
+ const Binary *ReplacementBinary = ReplacementBinaries[Index].getBinary();
+ validateArchitectureName(ReplacementArch);
+
+ auto O = dyn_cast<MachOObjectFile>(ReplacementBinary);
+ if (!O)
+ reportError("replacement file: " + ReplacementBinary->getFileName() +
+ " is a fat file (must be a thin file)");
+
+ if (O->getArch() != Triple(ReplacementArch).getArch())
+ reportError("specified architecture: " + ReplacementArch +
+ " for replacement file: " + ReplacementBinary->getFileName() +
+ " does not match the file's architecture");
+
+ auto Entry =
+ Slices.try_emplace(ReplacementArch, Slice{O, calculateAlignment(O)});
+ if (!Entry.second)
+ reportError("-replace " + ReplacementArch +
+ " <file_name> specified multiple times: " +
+ Entry.first->second.ObjectFile->getFileName() + ", " +
+ O->getFileName());
+ }
+ return Slices;
+}
+
+LLVM_ATTRIBUTE_NORETURN
+static void replaceSlices(ArrayRef<OwningBinary<Binary>> InputBinaries,
+ StringRef OutputFileName,
+ ArrayRef<Replacement> Replacements) {
+ assert(InputBinaries.size() == 1 && "Incorrect number of input binaries");
+ assert(!OutputFileName.empty() && "Replace expects a single output file");
+
+ if (InputBinaries.front().getBinary()->isMachO())
+ reportError("input file " +
+ InputBinaries.front().getBinary()->getFileName() +
+ " must be a fat file when the -replace option is specified");
+
+ SmallVector<std::string, 1> ReplacementFiles;
+ for (const auto &R : Replacements)
+ ReplacementFiles.push_back(R.FileName);
+ SmallVector<OwningBinary<Binary>, 1> ReplacementBinaries =
+ readInputBinaries(ReplacementFiles);
+
+ StringMap<Slice> ReplacementSlices =
+ buildReplacementSlices(ReplacementBinaries, Replacements);
+ SmallVector<std::unique_ptr<MachOObjectFile>, 2> ExtractedObjects;
+ SmallVector<Slice, 2> Slices = buildSlices(InputBinaries, ExtractedObjects);
+
+ for (auto &Slice : Slices) {
+ auto It = ReplacementSlices.find(getArchString(*Slice.ObjectFile));
+ if (It != ReplacementSlices.end()) {
+ Slice = It->second;
+ ReplacementSlices.erase(It); // only keep remaining replacing arch_types
+ }
+ }
+
+ if (!ReplacementSlices.empty())
+ reportError("-replace " + ReplacementSlices.begin()->first() +
+ " <file_name> specified but fat file: " +
+ InputBinaries.front().getBinary()->getFileName() +
+ " does not contain that architecture");
+ createUniversalBinary(Slices, OutputFileName);
+ exit(EXIT_SUCCESS);
+}
+
int main(int argc, char **argv) {
InitLLVM X(argc, argv);
Config C = parseLipoOptions(makeArrayRef(argv + 1, argc));
@@ -579,6 +685,9 @@
case LipoAction::CreateUniversal:
createUniversalBinary(InputBinaries, C.OutputFile);
break;
+ case LipoAction::ReplaceArch:
+ replaceSlices(InputBinaries, C.OutputFile, C.Replacements);
+ break;
}
return EXIT_SUCCESS;
}