94 lines · plain
1# REQUIRES: x862 3## NOTE: Here we check that the first non-header section -- __text -- appears4## *exactly* `-headerpad` bytes from the end of the header. ld64 actually5## starts laying out the non-header sections in the __TEXT segment from the end6## of the (page-aligned) segment rather than the front, so its binaries7## typically have more than `-headerpad` bytes of actual padding. `-headerpad`8## just enforces a lower bound. We should consider implementing the same9## alignment behavior.10 11# RUN: rm -rf %t; mkdir -p %t12 13################ Check default behavior14# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o15# RUN: %lld -o %t/test %t/test.o16# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s --check-prefix=PADx17#18# PADx: magic {{.+}} ncmds sizeofcmds flags19# PADx-NEXT: MH_MAGIC_64 {{.+}} [[#]] [[#%u, CMDSIZE:]] {{.*}}20# PADx: sectname __text21# PADx-NEXT: segname __TEXT22# PADx-NEXT: addr23# PADx-NEXT: size24# PADx-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0x20]]25 26################ Zero pad, no LCDylibs27# RUN: %no-lsystem-lld -o %t/test %t/test.o -headerpad 028# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s --check-prefix=PAD029# RUN: %no-lsystem-lld -o %t/test %t/test.o -headerpad 0 -headerpad_max_install_names30# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s --check-prefix=PAD031#32# PAD0: magic {{.+}} ncmds sizeofcmds flags33# PAD0-NEXT: MH_MAGIC_64 {{.+}} [[#]] [[#%u, CMDSIZE:]] {{.*}}34# PAD0: sectname __text35# PAD0-NEXT: segname __TEXT36# PAD0-NEXT: addr37# PAD0-NEXT: size38# PAD0-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0]]39 40################ Each lexical form of a hex number, no LCDylibs41# RUN: %no-lsystem-lld -o %t/test %t/test.o -headerpad 1142# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s --check-prefix=PAD1143# RUN: %no-lsystem-lld -o %t/test %t/test.o -headerpad 0x1144# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s --check-prefix=PAD1145# RUN: %no-lsystem-lld -o %t/test %t/test.o -headerpad 0X11 -headerpad_max_install_names46# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s --check-prefix=PAD1147#48# PAD11: magic {{.+}} ncmds sizeofcmds flags49# PAD11-NEXT: MH_MAGIC_64 {{.+}} [[#]] [[#%u, CMDSIZE:]] {{.*}}50# PAD11: sectname __text51# PAD11-NEXT: segname __TEXT52# PAD11-NEXT: addr53# PAD11-NEXT: size54# PAD11-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0x11]]55 56################ Each & all 3 kinds of LCDylib57# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/null.o58# RUN: %lld -o %t/libnull.dylib %t/null.o -dylib \59# RUN: -headerpad_max_install_names60# RUN: llvm-objdump --macho --all-headers %t/libnull.dylib | FileCheck %s --check-prefix=PADMAX61# RUN: %lld -o %t/libnull.dylib %t/null.o -dylib \62# RUN: -headerpad_max_install_names -lSystem63# RUN: llvm-objdump --macho --all-headers %t/libnull.dylib | FileCheck %s --check-prefix=PADMAX64# RUN: %lld -o %t/libnull.dylib %t/null.o -dylib \65# RUN: -headerpad_max_install_names \66# RUN: -lSystem -sub_library libSystem67# RUN: llvm-objdump --macho --all-headers %t/libnull.dylib | FileCheck %s --check-prefix=PADMAX68#69# PADMAX: magic {{.+}} ncmds sizeofcmds flags70# PADMAX-NEXT: MH_MAGIC_64 {{.+}} [[#%u, N:]] [[#%u, CMDSIZE:]] {{.*}}71# PADMAX: sectname __text72# PADMAX-NEXT: segname __TEXT73# PADMAX-NEXT: addr74# PADMAX-NEXT: size75# PADMAX-NEXT: offset [[#%u, CMDSIZE + 0x20 + mul(0x400, N - 9)]]76 77################ All 3 kinds of LCDylib swamped by a larger override78# RUN: %lld -o %t/libnull.dylib %t/null.o -dylib \79# RUN: -headerpad_max_install_names -headerpad 0x1001 \80# RUN: -lSystem -sub_library libSystem81# RUN: llvm-objdump --macho --all-headers %t/libnull.dylib | FileCheck %s --check-prefix=PADOVR82#83# PADOVR: magic {{.+}} ncmds sizeofcmds flags84# PADOVR-NEXT: MH_MAGIC_64 {{.+}} [[#%u, N:]] [[#%u, CMDSIZE:]] {{.*}}85# PADOVR: sectname __text86# PADOVR-NEXT: segname __TEXT87# PADOVR-NEXT: addr88# PADOVR-NEXT: size89# PADOVR-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0x1001]]90 91.globl _main92_main:93 ret94