mirror of
https://github.com/intel/llvm.git
synced 2026-01-18 07:57:36 +08:00
[lld/mac] ad-hoc sign dylibs and bundles on arm64 by default, support -(no_)adhoc_codesign flags
Previously, lld/mac only ad-hoc codesigned executables on arm64. Matches ld64 behavior. Part of PR49443. Fixes 14 of 17 failures when running check-llvm with lld as host linker on an M1 MBP. Differential Revision: https://reviews.llvm.org/D97994
This commit is contained in:
@@ -61,6 +61,7 @@ struct Configuration {
|
||||
bool printWhyLoad = false;
|
||||
bool searchDylibsFirst = false;
|
||||
bool saveTemps = false;
|
||||
bool adhocCodesign = false;
|
||||
uint32_t headerPad;
|
||||
uint32_t dylibCompatibilityVersion = 0;
|
||||
uint32_t dylibCurrentVersion = 0;
|
||||
|
||||
@@ -845,6 +845,11 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
|
||||
|
||||
config->saveTemps = args.hasArg(OPT_save_temps);
|
||||
|
||||
config->adhocCodesign =
|
||||
args.hasFlag(OPT_adhoc_codesign, OPT_no_adhoc_codesign,
|
||||
config->target.Arch == AK_arm64 ||
|
||||
config->target.Arch == AK_arm64e);
|
||||
|
||||
if (args.hasArg(OPT_v)) {
|
||||
message(getLLDVersion());
|
||||
message(StringRef("Library search paths:") +
|
||||
|
||||
@@ -566,11 +566,10 @@ def v : Flag<["-"], "v">,
|
||||
HelpText<"Print the linker version and search paths in addition to linking">,
|
||||
Group<grp_rare>;
|
||||
def adhoc_codesign : Flag<["-"], "adhoc_codesign">,
|
||||
HelpText<"Write an ad-hoc code signature to the output file.">,
|
||||
Flags<[HelpHidden]>,
|
||||
HelpText<"Write an ad-hoc code signature to the output file (default for arm64 binaries)">,
|
||||
Group<grp_rare>;
|
||||
def no_adhoc_codesign : Flag<["-"], "no_adhoc_codesign">,
|
||||
HelpText<"Do not write an ad-hoc code signature to the output file.">,
|
||||
HelpText<"Do not write an ad-hoc code signature to the output file (default for x86_64 binaries)">,
|
||||
Group<grp_rare>;
|
||||
def version_details : Flag<["-"], "version_details">,
|
||||
HelpText<"Print the linker version in JSON form">,
|
||||
|
||||
@@ -725,8 +725,7 @@ void Writer::createOutputSections() {
|
||||
unwindInfoSection = make<UnwindInfoSection>(); // TODO(gkm): only when no -r
|
||||
symtabSection = make<SymtabSection>(*stringTableSection);
|
||||
indirectSymtabSection = make<IndirectSymtabSection>();
|
||||
if (config->outputType == MH_EXECUTE &&
|
||||
(config->target.Arch == AK_arm64 || config->target.Arch == AK_arm64e))
|
||||
if (config->adhocCodesign)
|
||||
codeSignatureSection = make<CodeSignatureSection>();
|
||||
|
||||
switch (config->outputType) {
|
||||
|
||||
71
lld/test/MachO/adhoc-codesign.s
Normal file
71
lld/test/MachO/adhoc-codesign.s
Normal file
@@ -0,0 +1,71 @@
|
||||
# REQUIRES: x86, aarch64
|
||||
|
||||
# RUN: rm -rf %t
|
||||
# RUN: split-file %s %t
|
||||
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o %t/main-arm64.o %t/main.s
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/main-x86_64.o %t/main.s
|
||||
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o %t/foo-arm64.o %t/foo.s
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/foo-x86_64.o %t/foo.s
|
||||
|
||||
# Exhaustive test for:
|
||||
# (x86_64, arm64) x (default, -adhoc_codesign, -no_adhoc-codesign) x (execute, dylib, bundle)
|
||||
|
||||
# RUN: %lld -lSystem -arch x86_64 -execute -o %t/out %t/main-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out | FileCheck --check-prefix=NO-ADHOC %s
|
||||
# RUN: %lld -arch x86_64 -dylib -o %t/out %t/foo-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
|
||||
# RUN: %lld -arch x86_64 -bundle -o %t/out %t/foo-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
|
||||
|
||||
# RUN: %lld -lSystem -arch x86_64 -execute -adhoc_codesign -o %t/out %t/main-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=ADHOC %s
|
||||
# RUN: %lld -arch x86_64 -dylib -adhoc_codesign -o %t/out %t/foo-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=ADHOC %s
|
||||
# RUN: %lld -arch x86_64 -bundle -adhoc_codesign -o %t/out %t/foo-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=ADHOC %s
|
||||
|
||||
# RUN: %lld -lSystem -arch x86_64 -execute -no_adhoc_codesign -o %t/out %t/main-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
|
||||
# RUN: %lld -arch x86_64 -dylib -no_adhoc_codesign -o %t/out %t/foo-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
|
||||
# RUN: %lld -arch x86_64 -bundle -no_adhoc_codesign -o %t/out %t/foo-x86_64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
|
||||
|
||||
|
||||
# RUN: %lld -lSystem -arch arm64 -execute -o %t/out %t/main-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out | FileCheck --check-prefix=ADHOC %s
|
||||
# RUN: %lld -arch arm64 -dylib -o %t/out %t/foo-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=ADHOC %s
|
||||
# RUN: %lld -arch arm64 -bundle -o %t/out %t/foo-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=ADHOC %s
|
||||
|
||||
# RUN: %lld -lSystem -arch arm64 -execute -adhoc_codesign -o %t/out %t/main-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=ADHOC %s
|
||||
# RUN: %lld -arch arm64 -dylib -adhoc_codesign -o %t/out %t/foo-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=ADHOC %s
|
||||
# RUN: %lld -arch arm64 -bundle -adhoc_codesign -o %t/out %t/foo-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=ADHOC %s
|
||||
|
||||
# RUN: %lld -lSystem -arch arm64 -execute -no_adhoc_codesign -o %t/out %t/main-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
|
||||
# RUN: %lld -arch arm64 -dylib -no_adhoc_codesign -o %t/out %t/foo-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
|
||||
# RUN: %lld -arch arm64 -bundle -no_adhoc_codesign -o %t/out %t/foo-arm64.o
|
||||
# RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
|
||||
|
||||
# ADHOC: cmd LC_CODE_SIGNATURE
|
||||
# ADHOC-NEXT: cmdsize 16
|
||||
|
||||
# NO-ADHOC-NOT: cmd LC_CODE_SIGNATURE
|
||||
|
||||
#--- foo.s
|
||||
.globl _foo
|
||||
_foo:
|
||||
ret
|
||||
|
||||
#--- main.s
|
||||
.globl _main
|
||||
_main:
|
||||
ret
|
||||
Reference in New Issue
Block a user