[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
Mon Jul 17 12:40:22 PDT 2023


oontvoo created this revision.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Detail:
LD64 uses the name provided via  -[dylib]install_name as "Identifier", when available.
For compatiblity, LLD should do that too.

Note: I couldn't write a good test because codesign isn't really available on the build-bots.
Does anyone have suggestion for llvm-base tools that could be use to verify this?
(llvm-objdump isn't sufficient to verify this change)


Repository:
  rG LLVM Github Monorepo

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,6 +77,12 @@
 # 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
 
+## FIXME: enable this test when we have tools similar to codesign
+# RUN: %lld -arch x86_64 -dylib  -o %t/out_installname.dylib -install_name @rpath/out_MyInstallName %t/foo-x86_64-macos.o
+# RUN codesign -dv %t/out_installname.dylib | FileCheck --check-prefix=CS-ID %s
+## Previously, LLD would use the output binary name. LD64, OTOH, uses [dylib]_install_name, if available.
+# CS-ID: Identifier=out_MyInstallName
+
 # ADHOC:          cmd LC_CODE_SIGNATURE
 # ADHOC-NEXT: cmdsize 16
 
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.541189.patch
Type: text/x-patch
Size: 1799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230717/891c35d5/attachment.bin>


More information about the llvm-commits mailing list