[lld] 48e5f70 - [lld-macho] Remove linking bitcode support

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Tue May 30 14:49:21 PDT 2023


Author: Keith Smiley
Date: 2023-05-30T14:47:11-07:00
New Revision: 48e5f704c55f406e0bdbd989434c8b3777b27fe4

URL: https://github.com/llvm/llvm-project/commit/48e5f704c55f406e0bdbd989434c8b3777b27fe4
DIFF: https://github.com/llvm/llvm-project/commit/48e5f704c55f406e0bdbd989434c8b3777b27fe4.diff

LOG: [lld-macho] Remove linking bitcode support

Apple deprecated bitcode in the deployment process in Xcode 14.0. Last
month Apple started requiring Xcode 14.1+ to submit apps to the App
Store. Since there isn't a use for bundling bitcode outside of
submitting to the App Store we should be safe to delete this handling
entirely from LLD.

Differential Revision: https://reviews.llvm.org/D150697

Added: 
    lld/test/MachO/invalid/no-bitcode-support.ll

Modified: 
    lld/CMakeLists.txt
    lld/MachO/CMakeLists.txt
    lld/MachO/Config.h
    lld/MachO/Driver.cpp
    lld/MachO/Options.td
    lld/MachO/SyntheticSections.cpp
    lld/MachO/SyntheticSections.h
    lld/MachO/Writer.cpp
    lld/test/CMakeLists.txt
    lld/test/lit.cfg.py
    lld/test/lit.site.cfg.py.in

Removed: 
    lld/test/MachO/bitcode-bundle.ll
    lld/test/MachO/invalid/no-libxar.ll


################################################################################
diff  --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt
index a24330d2f18e9..518289a6328b6 100644
--- a/lld/CMakeLists.txt
+++ b/lld/CMakeLists.txt
@@ -99,10 +99,6 @@ if(LLD_BUILT_STANDALONE)
       set(LLVM_INCLUDE_TESTS OFF)
     endif()
   endif()
-
-  if(LLVM_HAVE_LIBXAR)
-    set(XAR_LIB xar)
-  endif()
 endif() # standalone
 
 set(LLD_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH

diff  --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt
index 91b34f14b7a8a..0b92488b00bea 100644
--- a/lld/MachO/CMakeLists.txt
+++ b/lld/MachO/CMakeLists.txt
@@ -54,13 +54,8 @@ add_lld_library(lldMachO
   LINK_LIBS
   lldCommon
   ${LLVM_PTHREAD_LIB}
-  ${XAR_LIB}
 
   DEPENDS
   MachOOptionsTableGen
   ${tablegen_deps}
   )
-
-if(LLVM_HAVE_LIBXAR)
-  target_link_libraries(lldMachO PRIVATE ${XAR_LIB})
-endif()

diff  --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index feb502d0630d5..762f5a1edd134 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -131,7 +131,6 @@ struct Configuration {
   bool saveTemps = false;
   bool adhocCodesign = false;
   bool emitFunctionStarts = false;
-  bool emitBitcodeBundle = false;
   bool emitDataInCodeInfo = false;
   bool emitEncryptionInfo = false;
   bool emitInitOffsets = false;

diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index d614df678080a..687a8b7c6e18f 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1614,7 +1614,6 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
   config->implicitDylibs = !args.hasArg(OPT_no_implicit_dylibs);
   config->emitFunctionStarts =
       args.hasFlag(OPT_function_starts, OPT_no_function_starts, true);
-  config->emitBitcodeBundle = args.hasArg(OPT_bitcode_bundle);
   config->emitDataInCodeInfo =
       args.hasFlag(OPT_data_in_code_info, OPT_no_data_in_code_info, true);
   config->emitChainedFixups = shouldEmitChainedFixups(args);
@@ -1654,11 +1653,6 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
       args.hasFlag(OPT_encryptable, OPT_no_encryption,
                    is_contained(encryptablePlatforms, config->platform()));
 
-#ifndef LLVM_HAVE_LIBXAR
-  if (config->emitBitcodeBundle)
-    error("-bitcode_bundle unsupported because LLD wasn't built with libxar");
-#endif
-
   if (const Arg *arg = args.getLastArg(OPT_install_name)) {
     if (config->warnDylibInstallName && config->outputType != MH_DYLIB)
       warn(

diff  --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index 4d4181471c3e8..9108d68205799 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -644,21 +644,6 @@ def add_ast_path : Separate<["-"], "add_ast_path">,
     HelpText<"AST paths will be emitted as STABS">,
     Group<grp_symtab>;
 
-def grp_bitcode : OptionGroup<"bitcode">, HelpText<"BITCODE BUILD FLOW">;
-
-def bitcode_bundle : Flag<["-"], "bitcode_bundle">,
-    HelpText<"Generate an embedded bitcode bundle in the __LLVM,__bundle section of the output">,
-    Group<grp_bitcode>;
-def bitcode_hide_symbols : Flag<["-"], "bitcode_hide_symbols">,
-    HelpText<"With -bitcode_bundle, hide all non-exported symbols from output bitcode bundle.">,
-    Flags<[HelpHidden]>,
-    Group<grp_bitcode>;
-def bitcode_symbol_map : Separate<["-"], "bitcode_symbol_map">,
-    MetaVarName<"<path>">,
-    HelpText<"Write the bitcode symbol reverse mapping to file <path>, or if a directory, to <path>/UUID.bcsymbolmap">,
-    Flags<[HelpHidden]>,
-    Group<grp_bitcode>;
-
 def grp_rare : OptionGroup<"rare">, HelpText<"RARELY USED">;
 
 def v : Flag<["-"], "v">,
@@ -1200,6 +1185,28 @@ def slow_stubs : Flag<["-"], "slow_stubs">,
     Flags<[HelpHidden]>,
     Group<grp_obsolete>;
 
+def bitcode_bundle : Flag<["-"], "bitcode_bundle">,
+    HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
+    Flags<[HelpHidden]>,
+    Group<grp_obsolete>;
+def bitcode_hide_symbols : Flag<["-"], "bitcode_hide_symbols">,
+    HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
+    Flags<[HelpHidden]>,
+    Group<grp_obsolete>;
+def bitcode_symbol_map : Separate<["-"], "bitcode_symbol_map">,
+    MetaVarName<"<path>">,
+    HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
+    Flags<[HelpHidden]>,
+    Group<grp_obsolete>;
+def bitcode_process_mode : Separate<["-"], "bitcode_process_mode">,
+    HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
+    Flags<[HelpHidden]>,
+    Group<grp_obsolete>;
+def bitcode_verify : Flag<["-"], "bitcode_verify">,
+    HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
+    Flags<[HelpHidden]>,
+    Group<grp_obsolete>;
+
 def grp_undocumented : OptionGroup<"undocumented">, HelpText<"UNDOCUMENTED">;
 
 def add_linker_option : Flag<["-"], "add_linker_option">,
@@ -1226,14 +1233,6 @@ def allow_simulator_linking_to_macosx_dylibs : Flag<["-"], "allow_simulator_link
     HelpText<"This option is undocumented in ld64">,
     Flags<[HelpHidden]>,
     Group<grp_undocumented>;
-def bitcode_process_mode : Separate<["-"], "bitcode_process_mode">,
-    HelpText<"This option is undocumented in ld64">,
-    Flags<[HelpHidden]>,
-    Group<grp_undocumented>;
-def bitcode_verify : Flag<["-"], "bitcode_verify">,
-    HelpText<"This option is undocumented in ld64">,
-    Flags<[HelpHidden]>,
-    Group<grp_undocumented>;
 def classic_linker : Flag<["-"], "classic_linker">,
     HelpText<"This option is undocumented in ld64">,
     Flags<[HelpHidden]>,

diff  --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 9aadc29278ff9..f7cad7345fc86 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -35,13 +35,6 @@
 #include "llvm/Support/SHA256.h"
 #endif
 
-#ifdef LLVM_HAVE_LIBXAR
-#include <fcntl.h>
-extern "C" {
-#include <xar/xar.h>
-}
-#endif
-
 using namespace llvm;
 using namespace llvm::MachO;
 using namespace llvm::support;
@@ -1553,62 +1546,6 @@ void CodeSignatureSection::writeTo(uint8_t *buf) const {
   memset(id + fileName.size(), 0, fileNamePad);
 }
 
-BitcodeBundleSection::BitcodeBundleSection()
-    : SyntheticSection(segment_names::llvm, section_names::bitcodeBundle) {}
-
-class ErrorCodeWrapper {
-public:
-  explicit ErrorCodeWrapper(std::error_code ec) : errorCode(ec.value()) {}
-  explicit ErrorCodeWrapper(int ec) : errorCode(ec) {}
-  operator int() const { return errorCode; }
-
-private:
-  int errorCode;
-};
-
-#define CHECK_EC(exp)                                                          \
-  do {                                                                         \
-    ErrorCodeWrapper ec(exp);                                                  \
-    if (ec)                                                                    \
-      fatal(Twine("operation failed with error code ") + Twine(ec) + ": " +    \
-            #exp);                                                             \
-  } while (0);
-
-void BitcodeBundleSection::finalize() {
-#ifdef LLVM_HAVE_LIBXAR
-  using namespace llvm::sys::fs;
-  CHECK_EC(createTemporaryFile("bitcode-bundle", "xar", xarPath));
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-  xar_t xar(xar_open(xarPath.data(), O_RDWR));
-#pragma clang diagnostic pop
-  if (!xar)
-    fatal("failed to open XAR temporary file at " + xarPath);
-  CHECK_EC(xar_opt_set(xar, XAR_OPT_COMPRESSION, XAR_OPT_VAL_NONE));
-  // FIXME: add more data to XAR
-  CHECK_EC(xar_close(xar));
-
-  file_size(xarPath, xarSize);
-#endif // defined(LLVM_HAVE_LIBXAR)
-}
-
-void BitcodeBundleSection::writeTo(uint8_t *buf) const {
-  using namespace llvm::sys::fs;
-  file_t handle =
-      CHECK(openNativeFile(xarPath, CD_OpenExisting, FA_Read, OF_None),
-            "failed to open XAR file");
-  std::error_code ec;
-  mapped_file_region xarMap(handle, mapped_file_region::mapmode::readonly,
-                            xarSize, 0, ec);
-  if (ec)
-    fatal("failed to map XAR file");
-  memcpy(buf, xarMap.const_data(), xarSize);
-
-  closeFile(handle);
-  remove(xarPath);
-}
-
 CStringSection::CStringSection(const char *name)
     : SyntheticSection(segment_names::text, name) {
   flags = S_CSTRING_LITERALS;

diff  --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h
index 83321889fdde1..e9d564f3c8361 100644
--- a/lld/MachO/SyntheticSections.h
+++ b/lld/MachO/SyntheticSections.h
@@ -533,18 +533,6 @@ class CodeSignatureSection final : public LinkEditSection {
   void writeHashes(uint8_t *buf) const;
 };
 
-class BitcodeBundleSection final : public SyntheticSection {
-public:
-  BitcodeBundleSection();
-  uint64_t getSize() const override { return xarSize; }
-  void finalize() override;
-  void writeTo(uint8_t *buf) const override;
-
-private:
-  llvm::SmallString<261> xarPath;
-  uint64_t xarSize;
-};
-
 class CStringSection : public SyntheticSection {
 public:
   CStringSection(const char *name);

diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index fe7cd39d2db88..68b22bf10c354 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -978,8 +978,6 @@ template <class LP> void Writer::createOutputSections() {
     dataInCodeSection = make<DataInCodeSection>();
   if (config->emitFunctionStarts)
     functionStartsSection = make<FunctionStartsSection>();
-  if (config->emitBitcodeBundle)
-    make<BitcodeBundleSection>();
 
   switch (config->outputType) {
   case MH_EXECUTE:

diff  --git a/lld/test/CMakeLists.txt b/lld/test/CMakeLists.txt
index d290533ada5ad..042bfd9140b6b 100644
--- a/lld/test/CMakeLists.txt
+++ b/lld/test/CMakeLists.txt
@@ -4,7 +4,6 @@ llvm_canonicalize_cmake_booleans(
   LLVM_ENABLE_ZSTD
   LLVM_ENABLE_LIBXML2
   LLD_DEFAULT_LD_LLD_IS_MINGW
-  LLVM_HAVE_LIBXAR
   LLVM_BUILD_EXAMPLES
   LLVM_ENABLE_PLUGINS
   LLVM_BYE_LINK_INTO_TOOLS

diff  --git a/lld/test/MachO/bitcode-bundle.ll b/lld/test/MachO/bitcode-bundle.ll
deleted file mode 100644
index 5deedbfb7b952..0000000000000
--- a/lld/test/MachO/bitcode-bundle.ll
+++ /dev/null
@@ -1,69 +0,0 @@
-; REQUIRES: x86, xar
-; RUN: rm -rf %t; split-file %s %t
-; RUN: opt -module-summary %t/test.ll -o %t/test.o
-; RUN: opt -module-summary %t/foo.ll -o %t/foo.o
-; RUN: %lld -lSystem -bitcode_bundle %t/test.o %t/foo.o -o %t/test
-; RUN: llvm-objdump --macho --section=__LLVM,__bundle %t/test | FileCheck %s
-; RUN: llvm-readobj --macho-segment %t/test | FileCheck %s --check-prefix=SEGMENT
-
-; CHECK:      Contents of (__LLVM,__bundle) section
-; CHECK-NEXT: For (__LLVM,__bundle) section: xar header
-; CHECK-NEXT:                   magic XAR_HEADER_MAGIC
-; CHECK-NEXT:                    size 28
-; CHECK-NEXT:                 version 1
-; CHECK-NEXT:   toc_length_compressed
-; CHECK-NEXT: toc_length_uncompressed
-; CHECK-NEXT:               cksum_alg XAR_CKSUM_SHA1
-; CHECK-NEXT: For (__LLVM,__bundle) section: xar table of contents:
-; CHECK-NEXT: <?xml version="1.0" encoding="UTF-8"?>
-; CHECK-NEXT: <xar>
-; CHECK-NEXT:  <toc>
-; CHECK-NEXT:   <checksum style="sha1">
-; CHECK-NEXT:    <size>20</size>
-; CHECK-NEXT:    <offset>0</offset>
-; CHECK-NEXT:   </checksum>
-; CHECK-NEXT:   <creation-time>{{.*}}</creation-time>
-; CHECK-NEXT:  </toc>
-; CHECK-NEXT: </xar>
-
-;; __LLVM must directly precede __LINKEDIT.
-; SEGMENT:        Name: __LLVM
-; SEGMENT-NEXT:   Size: 152
-; SEGMENT-NEXT:   vmaddr: 0x[[#%X,LLVM_ADDR:]]
-; SEGMENT-NEXT:   vmsize: 0x[[#%X,LLVM_VMSIZE:]]
-; SEGMENT-NEXT:   fileoff: [[#LLVM_OFF:]]
-; SEGMENT-NEXT:   filesize: [[#LLVM_FILESIZE:]]
-; SEGMENT-NEXT:   maxprot: rw-
-; SEGMENT-NEXT:   initprot: rw-
-; SEGMENT-NEXT:   nsects: 1
-; SEGMENT-NEXT:   flags: 0x0
-; SEGMENT-NEXT: }
-; SEGMENT-NEXT: Segment {
-; SEGMENT-NEXT:   Cmd: LC_SEGMENT_64
-; SEGMENT-NEXT:   Name: __LINKEDIT
-; SEGMENT-NEXT:   Size: 72
-; SEGMENT-NEXT:   vmaddr: 0x[[#LLVM_ADDR + LLVM_VMSIZE]]
-; SEGMENT-NEXT:   vmsize:
-; SEGMENT-NEXT:   fileoff: [[#LLVM_OFF + LLVM_FILESIZE]]
-; SEGMENT-NEXT:   filesize:
-; SEGMENT-NEXT:   maxprot: r--
-; SEGMENT-NEXT:   initprot: r--
-; SEGMENT-NEXT:   nsects: 0
-; SEGMENT-NEXT:   flags: 0x0
-; SEGMENT-NEXT: }
-
-;--- foo.ll
-target triple = "x86_64-apple-darwin"
-target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-
-define void @foo() {
-  ret void
-}
-
-;--- test.ll
-target triple = "x86_64-apple-darwin"
-target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-
-define void @main() {
-  ret void
-}

diff  --git a/lld/test/MachO/invalid/no-libxar.ll b/lld/test/MachO/invalid/no-bitcode-support.ll
similarity index 75%
rename from lld/test/MachO/invalid/no-libxar.ll
rename to lld/test/MachO/invalid/no-bitcode-support.ll
index 62a2599c62e2f..466441dcd2cb0 100644
--- a/lld/test/MachO/invalid/no-libxar.ll
+++ b/lld/test/MachO/invalid/no-bitcode-support.ll
@@ -1,8 +1,7 @@
 ; REQUIRES: x86
-; UNSUPPORTED: xar
 ; RUN: opt -module-summary %s -o %t.o
 ; RUN: not %lld -lSystem -bitcode_bundle %t.o -o /dev/null 2>&1 | FileCheck %s
-; CHECK: error: -bitcode_bundle unsupported because LLD wasn't built with libxar
+; CHECK: error: Option `-bitcode_bundle' is obsolete. Please modernize your usage.
 
 target triple = "x86_64-apple-darwin"
 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

diff  --git a/lld/test/lit.cfg.py b/lld/test/lit.cfg.py
index 2e60d9fef7dfa..e03a6dcf47fd9 100644
--- a/lld/test/lit.cfg.py
+++ b/lld/test/lit.cfg.py
@@ -125,9 +125,6 @@
 if config.enable_backtrace:
     config.available_features.add("backtrace")
 
-if config.have_libxar:
-    config.available_features.add("xar")
-
 if config.have_libxml2:
     config.available_features.add("libxml2")
 

diff  --git a/lld/test/lit.site.cfg.py.in b/lld/test/lit.site.cfg.py.in
index c324b53021a17..39b54924f4a19 100644
--- a/lld/test/lit.site.cfg.py.in
+++ b/lld/test/lit.site.cfg.py.in
@@ -20,7 +20,6 @@ config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
 config.have_zstd = @LLVM_ENABLE_ZSTD@
-config.have_libxar = @LLVM_HAVE_LIBXAR@
 config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
 config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
 config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@


        


More information about the llvm-commits mailing list