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