Skip to content

Commit d911ed1

Browse files
[llvm-objcopy] Add ability to copy MachO object files
This diff implements first bits for copying (without modification) MachO object files. Test plan: make check-all Differential revision: https://reviews.llvm.org/D54674 llvm-svn: 352944
1 parent ae02943 commit d911ed1

16 files changed

+1542
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.build_version macos, 10, 14
3+
.globl __Z1fi ## -- Begin function _Z1fi
4+
.p2align 4, 0x90
5+
__Z1fi: ## @_Z1fi
6+
.cfi_startproc
7+
## %bb.0:
8+
pushl %ebp
9+
.cfi_def_cfa_offset 8
10+
.cfi_offset %ebp, -8
11+
movl %esp, %ebp
12+
.cfi_def_cfa_register %ebp
13+
pushl %eax
14+
calll L0$pb
15+
L0$pb:
16+
popl %eax
17+
movl 8(%ebp), %ecx
18+
movl _x-L0$pb(%eax), %eax
19+
addl 8(%ebp), %eax
20+
movl %ecx, -4(%ebp) ## 4-byte Spill
21+
addl $4, %esp
22+
popl %ebp
23+
retl
24+
.cfi_endproc
25+
## -- End function
26+
.globl _main ## -- Begin function main
27+
.p2align 4, 0x90
28+
_main: ## @main
29+
.cfi_startproc
30+
## %bb.0:
31+
pushl %ebp
32+
.cfi_def_cfa_offset 8
33+
.cfi_offset %ebp, -8
34+
movl %esp, %ebp
35+
.cfi_def_cfa_register %ebp
36+
subl $24, %esp
37+
movl $2, %eax
38+
movl $0, -4(%ebp)
39+
movl $2, (%esp)
40+
movl %eax, -8(%ebp) ## 4-byte Spill
41+
calll __Z1fi
42+
addl $24, %esp
43+
popl %ebp
44+
retl
45+
.cfi_endproc
46+
## -- End function
47+
.section __DATA,__data
48+
.globl _x ## @x
49+
.p2align 2
50+
_x:
51+
.long 1 ## 0x1
52+
53+
54+
.subsections_via_symbols
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.build_version macos, 10, 14
3+
.globl __Z1fi ## -- Begin function _Z1fi
4+
.p2align 4, 0x90
5+
__Z1fi: ## @_Z1fi
6+
.cfi_startproc
7+
## %bb.0:
8+
pushq %rbp
9+
.cfi_def_cfa_offset 16
10+
.cfi_offset %rbp, -16
11+
movq %rsp, %rbp
12+
.cfi_def_cfa_register %rbp
13+
movl %edi, -4(%rbp)
14+
movl _x(%rip), %edi
15+
addl -4(%rbp), %edi
16+
movl %edi, %eax
17+
popq %rbp
18+
retq
19+
.cfi_endproc
20+
## -- End function
21+
.globl _main ## -- Begin function main
22+
.p2align 4, 0x90
23+
_main: ## @main
24+
.cfi_startproc
25+
## %bb.0:
26+
pushq %rbp
27+
.cfi_def_cfa_offset 16
28+
.cfi_offset %rbp, -16
29+
movq %rsp, %rbp
30+
.cfi_def_cfa_register %rbp
31+
subq $16, %rsp
32+
movl $2, %edi
33+
movl $0, -4(%rbp)
34+
callq __Z1fi
35+
addq $16, %rsp
36+
popq %rbp
37+
retq
38+
.cfi_endproc
39+
## -- End function
40+
.section __DATA,__data
41+
.globl _x ## @x
42+
.p2align 2
43+
_x:
44+
.long 1 ## 0x1
45+
46+
47+
.subsections_via_symbols
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# RUN: yaml2obj %s > %t
2+
# RUN: llvm-objcopy %t %t2
3+
# RUN: cmp %t %t2
4+
5+
--- !mach-o
6+
IsLittleEndian: false
7+
FileHeader:
8+
magic: 0xFEEDFACE
9+
cputype: 0x00000007
10+
cpusubtype: 0x00000003
11+
filetype: 0x00000001
12+
ncmds: 4
13+
sizeofcmds: 380
14+
flags: 0x00002000
15+
LoadCommands:
16+
- cmd: LC_SEGMENT
17+
cmdsize: 260
18+
segname: ''
19+
vmaddr: 0
20+
vmsize: 184
21+
fileoff: 408
22+
filesize: 184
23+
maxprot: 7
24+
initprot: 7
25+
nsects: 3
26+
flags: 0
27+
Sections:
28+
- sectname: __text
29+
segname: __TEXT
30+
addr: 0x0000000000000000
31+
size: 61
32+
offset: 0x00000198
33+
align: 4
34+
reloff: 0x00000250
35+
nreloc: 1
36+
flags: 0x80000400
37+
reserved1: 0x00000000
38+
reserved2: 0x00000000
39+
reserved3: 0x00000000
40+
- sectname: __compact_unwind
41+
segname: __LD
42+
addr: 0x0000000000000040
43+
size: 40
44+
offset: 0x000001D8
45+
align: 2
46+
reloff: 0x00000258
47+
nreloc: 2
48+
flags: 0x02000000
49+
reserved1: 0x00000000
50+
reserved2: 0x00000000
51+
reserved3: 0x00000000
52+
- sectname: __eh_frame
53+
segname: __TEXT
54+
addr: 0x0000000000000068
55+
size: 80
56+
offset: 0x00000200
57+
align: 2
58+
reloff: 0x00000000
59+
nreloc: 0
60+
flags: 0x6800000B
61+
reserved1: 0x00000000
62+
reserved2: 0x00000000
63+
reserved3: 0x00000000
64+
- cmd: LC_VERSION_MIN_MACOSX
65+
cmdsize: 16
66+
version: 658688
67+
sdk: 0
68+
- cmd: LC_SYMTAB
69+
cmdsize: 24
70+
symoff: 616
71+
nsyms: 2
72+
stroff: 640
73+
strsize: 16
74+
- cmd: LC_DYSYMTAB
75+
cmdsize: 80
76+
ilocalsym: 0
77+
nlocalsym: 0
78+
iextdefsym: 0
79+
nextdefsym: 2
80+
iundefsym: 2
81+
nundefsym: 0
82+
tocoff: 0
83+
ntoc: 0
84+
modtaboff: 0
85+
nmodtab: 0
86+
extrefsymoff: 0
87+
nextrefsyms: 0
88+
indirectsymoff: 0
89+
nindirectsyms: 0
90+
extreloff: 0
91+
nextrel: 0
92+
locreloff: 0
93+
nlocrel: 0
94+
LinkEditData:
95+
NameList:
96+
- n_strx: 1
97+
n_type: 0x0F
98+
n_sect: 1
99+
n_desc: 0
100+
n_value: 0
101+
- n_strx: 8
102+
n_type: 0x0F
103+
n_sect: 1
104+
n_desc: 0
105+
n_value: 32
106+
StringTable:
107+
- ''
108+
- __Z1fv
109+
- _main
110+
- ''
111+
- ''
112+
...
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# RUN: yaml2obj %s > %t
2+
# RUN: llvm-objcopy %t %t2
3+
# RUN: cmp %t %t2
4+
5+
--- !mach-o
6+
IsLittleEndian: false
7+
FileHeader:
8+
magic: 0xFEEDFACF
9+
cputype: 0x01000007
10+
cpusubtype: 0x00000003
11+
filetype: 0x00000001
12+
ncmds: 4
13+
sizeofcmds: 512
14+
flags: 0x00002000
15+
reserved: 0x00000000
16+
LoadCommands:
17+
- cmd: LC_SEGMENT_64
18+
cmdsize: 392
19+
segname: ''
20+
vmaddr: 0
21+
vmsize: 240
22+
fileoff: 544
23+
filesize: 240
24+
maxprot: 7
25+
initprot: 7
26+
nsects: 4
27+
flags: 0
28+
Sections:
29+
- sectname: __text
30+
segname: __TEXT
31+
addr: 0x0000000000000000
32+
size: 93
33+
offset: 0x00000220
34+
align: 4
35+
reloff: 0x00000310
36+
nreloc: 3
37+
flags: 0x80000400
38+
reserved1: 0x00000000
39+
reserved2: 0x00000000
40+
reserved3: 0x00000000
41+
- sectname: __cstring
42+
segname: __TEXT
43+
addr: 0x000000000000005D
44+
size: 48
45+
offset: 0x0000027D
46+
align: 0
47+
reloff: 0x00000000
48+
nreloc: 0
49+
flags: 0x00000002
50+
reserved1: 0x00000000
51+
reserved2: 0x00000000
52+
reserved3: 0x00000000
53+
- sectname: __compact_unwind
54+
segname: __LD
55+
addr: 0x0000000000000090
56+
size: 32
57+
offset: 0x000002B0
58+
align: 3
59+
reloff: 0x00000328
60+
nreloc: 1
61+
flags: 0x02000000
62+
reserved1: 0x00000000
63+
reserved2: 0x00000000
64+
reserved3: 0x00000000
65+
- sectname: __eh_frame
66+
segname: __TEXT
67+
addr: 0x00000000000000B0
68+
size: 64
69+
offset: 0x000002D0
70+
align: 3
71+
reloff: 0x00000000
72+
nreloc: 0
73+
flags: 0x6800000B
74+
reserved1: 0x00000000
75+
reserved2: 0x00000000
76+
reserved3: 0x00000000
77+
- cmd: LC_VERSION_MIN_MACOSX
78+
cmdsize: 16
79+
version: 658432
80+
sdk: 0
81+
- cmd: LC_SYMTAB
82+
cmdsize: 24
83+
symoff: 816
84+
nsyms: 2
85+
stroff: 848
86+
strsize: 36
87+
- cmd: LC_DYSYMTAB
88+
cmdsize: 80
89+
ilocalsym: 0
90+
nlocalsym: 0
91+
iextdefsym: 0
92+
nextdefsym: 1
93+
iundefsym: 1
94+
nundefsym: 1
95+
tocoff: 0
96+
ntoc: 0
97+
modtaboff: 0
98+
nmodtab: 0
99+
extrefsymoff: 0
100+
nextrefsyms: 0
101+
indirectsymoff: 0
102+
nindirectsyms: 0
103+
extreloff: 0
104+
nextrel: 0
105+
locreloff: 0
106+
nlocrel: 0
107+
LinkEditData:
108+
NameList:
109+
- n_strx: 24
110+
n_type: 0x0F
111+
n_sect: 1
112+
n_desc: 0
113+
n_value: 0
114+
- n_strx: 1
115+
n_type: 0x01
116+
n_sect: 0
117+
n_desc: 0
118+
n_value: 0
119+
StringTable:
120+
- ''
121+
- _compilerrt_abort_impl
122+
- ___absvdi2
123+
- ''
124+
...

0 commit comments

Comments
 (0)