headerpad.s
3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# REQUIRES: x86
## NOTE: Here we check that the first non-header section -- __text -- appears
## *exactly* `-headerpad` bytes from the end of the header. ld64 actually
## starts laying out the non-header sections in the __TEXT segment from the end
## of the (page-aligned) segment rather than the front, so its binaries
## typically have more than `-headerpad` bytes of actual padding. `-headerpad`
## just enforces a lower bound. We should consider implementing the same
## alignment behavior.
################ Check default behavior
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: %lld -o %t %t.o
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PADx
#
# PADx: magic {{.+}} ncmds sizeofcmds flags
# PADx-NEXT: MH_MAGIC_64 {{.+}} 9 [[#%u, CMDSIZE:]] {{.*}}
# PADx: sectname __text
# PADx-NEXT: segname __TEXT
# PADx-NEXT: addr
# PADx-NEXT: size
# PADx-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0x20]]
################ Zero pad, no LCDylibs
# RUN: %lld -o %t %t.o -headerpad 0
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD0
# RUN: %lld -o %t %t.o -headerpad 0 -headerpad_max_install_names
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD0
#
# PAD0: magic {{.+}} ncmds sizeofcmds flags
# PAD0-NEXT: MH_MAGIC_64 {{.+}} 9 [[#%u, CMDSIZE:]] {{.*}}
# PAD0: sectname __text
# PAD0-NEXT: segname __TEXT
# PAD0-NEXT: addr
# PAD0-NEXT: size
# PAD0-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0]]
################ Each lexical form of a hex number, no LCDylibs
# RUN: %lld -o %t %t.o -headerpad 11
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11
# RUN: %lld -o %t %t.o -headerpad 0x11
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11
# RUN: %lld -o %t %t.o -headerpad 0X11 -headerpad_max_install_names
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11
#
# PAD11: magic {{.+}} ncmds sizeofcmds flags
# PAD11-NEXT: MH_MAGIC_64 {{.+}} 9 [[#%u, CMDSIZE:]] {{.*}}
# PAD11: sectname __text
# PAD11-NEXT: segname __TEXT
# PAD11-NEXT: addr
# PAD11-NEXT: size
# PAD11-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0x11]]
################ Each & all 3 kinds of LCDylib
# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %T/null.o
# RUN: %lld -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names
# RUN: llvm-objdump --macho --all-headers %T/libnull.dylib | FileCheck %s --check-prefix=PADMAX
# RUN: %lld -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names -lSystem
# RUN: llvm-objdump --macho --all-headers %T/libnull.dylib | FileCheck %s --check-prefix=PADMAX
# RUN: %lld -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names \
# RUN: -lSystem -sub_library libSystem
# RUN: llvm-objdump --macho --all-headers %T/libnull.dylib | FileCheck %s --check-prefix=PADMAX
#
# PADMAX: magic {{.+}} ncmds sizeofcmds flags
# PADMAX-NEXT: MH_MAGIC_64 {{.+}} [[#%u, N:]] [[#%u, CMDSIZE:]] {{.*}}
# PADMAX: sectname __text
# PADMAX-NEXT: segname __TEXT
# PADMAX-NEXT: addr
# PADMAX-NEXT: size
# PADMAX-NEXT: offset [[#%u, CMDSIZE + 0x20 + mul(0x400, N - 6)]]
################ All 3 kinds of LCDylib swamped by a larger override
# RUN: %lld -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names -headerpad 0x1001 \
# RUN: -lSystem -sub_library libSystem
# RUN: llvm-objdump --macho --all-headers %T/libnull.dylib | FileCheck %s --check-prefix=PADOVR
#
# PADOVR: magic {{.+}} ncmds sizeofcmds flags
# PADOVR-NEXT: MH_MAGIC_64 {{.+}} [[#%u, N:]] [[#%u, CMDSIZE:]] {{.*}}
# PADOVR: sectname __text
# PADOVR-NEXT: segname __TEXT
# PADOVR-NEXT: addr
# PADOVR-NEXT: size
# PADOVR-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0x1001]]
.globl _main
_main:
ret