[PATCH] D155508: [lld-macho]Use install_name as Identifier for code-sign, if available.

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 18 12:43:08 PDT 2023


oontvoo updated this revision to Diff 541678.
oontvoo added a comment.

updated test to verify the Identifier field


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155508/new/

https://reviews.llvm.org/D155508

Files:
  lld/MachO/SyntheticSections.cpp
  lld/test/MachO/adhoc-codesign.s


Index: lld/test/MachO/adhoc-codesign.s
===================================================================
--- lld/test/MachO/adhoc-codesign.s
+++ lld/test/MachO/adhoc-codesign.s
@@ -77,11 +77,30 @@
 # RUN: %no-arg-lld -arch arm64 -platform_version ios-simulator 14.0 15.0 -bundle  -no_adhoc_codesign -o %t/out %t/foo-arm64-sim.o
 # RUN: llvm-objdump --macho --all-headers %t/out| FileCheck --check-prefix=NO-ADHOC %s
 
+# RUN: %lld -arch x86_64 -dylib -o %t/out_installname.dylib -install_name @rpath/MyInstallName %t/foo-x86_64-macos.o -adhoc_codesign
+# RUN: %lld -arch x86_64 -dylib -o %t/out_no_installname.dylib %t/foo-x86_64-macos.o -adhoc_codesign
+
+## Smoke check to verify the dataoff and datasize value before using them with code-signature-check.py
+# RUN: llvm-objdump --macho --all-headers %t/out_installname.dylib | FileCheck %s --check-prefix CS-ID-PRE -D#DATA_OFFSET=4176 -D#DATA_SIZE=192 
+# RUN: llvm-objdump --macho --all-headers %t/out_no_installname.dylib | FileCheck %s --check-prefix CS-ID-PRE -D#DATA_OFFSET=4176 -D#DATA_SIZE=208 
+
+## Verify that the 'Identifier' (aka 'Code Directory ID') field are set to the install-name, if available.
+# RUN: %python %p/Inputs/code-signature-check.py %t/out_installname.dylib 4176 192 0 4176 | FileCheck %s --check-prefix CS-ID-INSTALL
+# RUN:  %python %p/Inputs/code-signature-check.py %t/out_no_installname.dylib 4176 208 0 4176 | FileCheck %s --check-prefix CS-ID-NO-INSTALL
+
 # ADHOC:          cmd LC_CODE_SIGNATURE
 # ADHOC-NEXT: cmdsize 16
 
 # NO-ADHOC-NOT:          cmd LC_CODE_SIGNATURE
 
+# CS-ID-PRE: cmd LC_CODE_SIGNATURE
+# CS-ID-PRE-NEXT: cmdsize 16
+# CS-ID-PRE-NEXT: dataoff [[#DATA_OFFSET]]
+# CS-ID-PRE-NEXT: datasize [[#DATA_SIZE]]
+
+# CS-ID-INSTALL: Code Directory ID: MyInstallName
+# CS-ID-NO-INSTALL: Code Directory ID: out_no_installname.dylib
+
 #--- foo.s
 .globl _foo
 _foo:
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -1460,8 +1460,15 @@
 CodeSignatureSection::CodeSignatureSection()
     : LinkEditSection(segment_names::linkEdit, section_names::codeSignature) {
   align = 16; // required by libstuff
-  // FIXME: Consider using finalOutput instead of outputFile.
-  fileName = config->outputFile;
+
+  // XXX: This mimics LD64, where it uses the install-name as codesign
+  // identifier, if available.
+  if (!config->installName.empty())
+    fileName = config->installName;
+  else
+    // FIXME: Consider using finalOutput instead of outputFile.
+    fileName = config->outputFile;
+
   size_t slashIndex = fileName.rfind("/");
   if (slashIndex != std::string::npos)
     fileName = fileName.drop_front(slashIndex + 1);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155508.541678.patch
Type: text/x-patch
Size: 2762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230718/b1b7d236/attachment.bin>


More information about the llvm-commits mailing list